Loading

Paste #patuuafpd

  1. diff -r 721cafc243c6 company.nut
  2. --- a/company.nut   Sun Jul 12 15:12:28 2015 +0100
  3. +++ b/company.nut   Sat Sep 26 16:14:11 2015 +0100
  4. @@ -128,9 +128,18 @@
  5.  }
  6.  
  7.  // Update the delivered amount from the monitored amounts.
  8. -function CompanyGoal::UpdateDelivered(mon, comp_id)
  9. +function CompanyGoal::UpdateDelivered(mon, cdata)
  10.  {
  11.      local delivered;
  12. +    local comp_id = cdata.comp_id
  13. +    foreach (key, value in cdata.won_goals["towns"]) {
  14. +        GSLog.Info(key);
  15. +        GSLog.Info(value);
  16. +    }
  17. +    foreach (key, value in cdata.won_goals["industries"]) {
  18. +        GSLog.Info(key);
  19. +        GSLog.Info(value);
  20. +    }
  21.      if ("ind" in this.accept) {
  22.          delivered = mon[this.cargo.cid].ind[this.accept.ind];
  23.      } else {
  24. @@ -148,8 +157,20 @@
  25.                  local destination_string_news;
  26.                  if ("town" in this.accept) {
  27.                      destination_string_news = GSText(GSText.STR_TOWN_NAME_NEWS, this.accept.town);
  28. +                    if (this.accept.town in cdata.won_goals["towns"]) {
  29. +                        // key already exists, don't need to create it
  30. +                    } else {
  31. +                        cdata.won_goals["towns"][this.accept.town] <- {};
  32. +                    }
  33. +                    cdata.won_goals["towns"][this.accept.town][this.cargo.cid] <- true;
  34.                  } else {
  35.                      destination_string_news = GSText(GSText.STR_INDUSTRY_NAME_NEWS, this.accept.ind);
  36. +                    if (this.accept.ind in cdata.won_goals["industries"]) {
  37. +                        // key already exists, don't need to create it
  38. +                    } else {
  39. +                        cdata.won_goals["industries"][this.accept.ind] <- {};
  40. +                    }
  41. +                    cdata.won_goals["industries"][this.accept.ind][this.cargo.cid] <- true;
  42.                  }
  43.                  local goal_won_news = GSText(GSText.STR_COMPANY_GOAL_WON_NEWS, cargo.cid,
  44.                                           this.wanted_amount, destination_string_news);
  45. @@ -317,10 +338,14 @@
  46.      comp_id = null;
  47.  
  48.      active_goals = null;
  49. +    won_goals = null;
  50.  
  51.      constructor(comp_id)
  52.      {
  53.          this.active_goals = {};
  54. +        this.won_goals = {};
  55. +        this.won_goals["industries"] <- {}
  56. +        this.won_goals["towns"] <- {}
  57.          this.comp_id = comp_id;
  58.  
  59.          local num_goals = GSController.GetSetting("num_goals");
  60. @@ -490,7 +515,7 @@
  61.      if (this.comp_id in cmon) {
  62.          foreach (num, goal in this.active_goals) {
  63.              if (goal == null) continue;
  64. -            goal.UpdateDelivered(cmon[this.comp_id], this.comp_id);
  65. +            goal.UpdateDelivered(cmon[this.comp_id], this);
  66.              if (goal.CheckFinished()) finished = true;
  67.          }
  68.      }

Comments