diff -r 721cafc243c6 company.nut
--- a/company.nut Sun Jul 12 15:12:28 2015 +0100
+++ b/company.nut Sat Sep 26 16:14:11 2015 +0100
@@ -128,9 +128,18 @@
}
// Update the delivered amount from the monitored amounts.
-function CompanyGoal::UpdateDelivered(mon, comp_id)
+function CompanyGoal::UpdateDelivered(mon, cdata)
{
local delivered;
+ local comp_id = cdata.comp_id
+ foreach (key, value in cdata.won_goals["towns"]) {
+ GSLog.Info(key);
+ GSLog.Info(value);
+ }
+ foreach (key, value in cdata.won_goals["industries"]) {
+ GSLog.Info(key);
+ GSLog.Info(value);
+ }
if ("ind" in this.accept) {
delivered = mon[this.cargo.cid].ind[this.accept.ind];
} else {
@@ -148,8 +157,20 @@
local destination_string_news;
if ("town" in this.accept) {
destination_string_news = GSText(GSText.STR_TOWN_NAME_NEWS, this.accept.town);
+ if (this.accept.town in cdata.won_goals["towns"]) {
+ // key already exists, don't need to create it
+ } else {
+ cdata.won_goals["towns"][this.accept.town] <- {};
+ }
+ cdata.won_goals["towns"][this.accept.town][this.cargo.cid] <- true;
} else {
destination_string_news = GSText(GSText.STR_INDUSTRY_NAME_NEWS, this.accept.ind);
+ if (this.accept.ind in cdata.won_goals["industries"]) {
+ // key already exists, don't need to create it
+ } else {
+ cdata.won_goals["industries"][this.accept.ind] <- {};
+ }
+ cdata.won_goals["industries"][this.accept.ind][this.cargo.cid] <- true;
}
local goal_won_news = GSText(GSText.STR_COMPANY_GOAL_WON_NEWS, cargo.cid,
this.wanted_amount, destination_string_news);
@@ -317,10 +338,14 @@
comp_id = null;
active_goals = null;
+ won_goals = null;
constructor(comp_id)
{
this.active_goals = {};
+ this.won_goals = {};
+ this.won_goals["industries"] <- {}
+ this.won_goals["towns"] <- {}
this.comp_id = comp_id;
local num_goals = GSController.GetSetting("num_goals");
@@ -490,7 +515,7 @@
if (this.comp_id in cmon) {
foreach (num, goal in this.active_goals) {
if (goal == null) continue;
- goal.UpdateDelivered(cmon[this.comp_id], this.comp_id);
+ goal.UpdateDelivered(cmon[this.comp_id], this);
if (goal.CheckFinished()) finished = true;
}
}