From cca702e7db9018015f7e47c7929d66eec7a9fbb8 Mon Sep 17 00:00:00 2001 From: Andy <1780327+andythenorth@users.noreply.github.com> Date: Sat, 10 Jan 2015 21:19:17 +0000 Subject: [PATCH] Feature: display news for goal won and new goal --- company.nut | 22 ++++++++++++++++++---- lang/english.txt | 19 +++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/company.nut b/company.nut index 5b3a29e..1e327cc 100644 --- a/company.nut +++ b/company.nut @@ -49,24 +49,29 @@ class CompanyGoal { // Construct goal if a company id was provided. if (comp_id != null) { - local destination, destination_string, goal_type; + local destination, destination_string, destination_string_news, goal_type; if ("town" in this.accept) { destination = accept.town; destination_string = GSText(GSText.STR_TOWN_NAME, destination); + destination_string_news = GSText(GSText.STR_TOWN_NAME_NEWS, destination); goal_type = GSGoal.GT_TOWN; } else { destination = accept.ind; destination_string = GSText(GSText.STR_INDUSTRY_NAME, destination); + destination_string_news = GSText(GSText.STR_INDUSTRY_NAME_NEWS, destination); goal_type = GSGoal.GT_INDUSTRY; } local goal_text = GSText(GSText.STR_COMPANY_GOAL, cargo.cid, this.wanted_amount, destination_string); this.goal_id = GSGoal.New(comp_id, goal_text, goal_type, destination); + local goal_news_text = GSText(GSText.STR_COMPANY_GOAL_NEWS, cargo.cid, + this.wanted_amount, destination_string_news); + GSNews.Create(GSNews.NT_GENERAL, goal_news_text, comp_id); } } function AddMonitorElement(mon); - function UpdateDelivered(mon); + function UpdateDelivered(mon, comp_id); function UpdateTimeout(step); function CheckFinished(); function FinalizeGoal(); @@ -116,7 +121,7 @@ function CompanyGoal::AddMonitorElement(mon) } // Update the delivered amount from the monitored amounts. -function CompanyGoal::UpdateDelivered(mon) +function CompanyGoal::UpdateDelivered(mon, comp_id) { local delivered; if ("ind" in this.accept) { @@ -132,6 +137,15 @@ function CompanyGoal::UpdateDelivered(mon) if (this.delivered_amount >= this.wanted_amount) { perc = 100; GSGoal.SetCompleted(this.goal_id, true); + local destination_string_news; + if ("town" in this.accept) { + destination_string_news = GSText(GSText.STR_TOWN_NAME_NEWS, accept.town); + } else { + destination_string_news = GSText(GSText.STR_INDUSTRY_NAME_NEWS, accept.ind); + } + local goal_won_news = GSText(GSText.STR_COMPANY_GOAL_WON_NEWS, cargo.cid, + this.wanted_amount, destination_string_news); + GSNews.Create(GSNews.NT_GENERAL, goal_won_news, comp_id); } else { perc = 100 * this.delivered_amount / this.wanted_amount; if (perc > 100) perc = 100; @@ -437,7 +451,7 @@ function CompanyData::UpdateDelivereds(cmon) if (this.comp_id in cmon) { foreach (num, goal in this.active_goals) { if (goal == null) continue; - goal.UpdateDelivered(cmon[this.comp_id]); + goal.UpdateDelivered(cmon[this.comp_id], this.comp_id); if (goal.CheckFinished()) finished = true; } } diff --git a/lang/english.txt b/lang/english.txt index 96933ec..c9e3eeb 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -1,10 +1,13 @@ ##plural 0 -STR_GOAL_NEWS : -STR_COMPANY_GOAL :Deliver {GOLD}{CARGO_LONG} {ORANGE}to {STRING} -STR_PROGRESS :{YELLOW}{NUM}% {ORANGE}done -STR_TIMEOUT_YEARS :{GOLD}{NUM} {ORANGE}year{P "" s} remaining -STR_TIMEOUT_MONTHS :{GOLD}{NUM} {ORANGE}month{P "" s} remaining -STR_TIMEOUT_DAYS :{GOLD}{NUM} {ORANGE}day{P "" s} remaining -STR_TOWN_NAME :{WHITE}{TOWN} -STR_INDUSTRY_NAME :{YELLOW}{INDUSTRY} +STR_COMPANY_GOAL :Deliver {GOLD}{CARGO_LONG} {ORANGE}to {STRING} +STR_COMPANY_GOAL_NEWS :New goal! Deliver {CARGO_LONG} to {STRING} +STR_PROGRESS :{YELLOW}{NUM}% {ORANGE}done +STR_COMPANY_GOAL_WON_NEWS :Goal won! {CARGO_LONG} delivered to {STRING} +STR_TIMEOUT_YEARS :{GOLD}{NUM} {ORANGE}year{P "" s} remaining +STR_TIMEOUT_MONTHS :{GOLD}{NUM} {ORANGE}month{P "" s} remaining +STR_TIMEOUT_DAYS :{GOLD}{NUM} {ORANGE}day{P "" s} remaining +STR_TOWN_NAME :{WHITE}{TOWN} +STR_TOWN_NAME_NEWS :{TOWN} +STR_INDUSTRY_NAME :{YELLOW}{INDUSTRY} +STR_INDUSTRY_NAME_NEWS :{INDUSTRY}