Loading

Paste #pgd6yvzjo

  1. //On the Company Value GS code:
  2. //-------------------------------
  3.  
  4. function SCPManager::ReceivedSettingCommand(message, self)
  5. {
  6.     if (!self._scp_enabled) return;
  7.  
  8.     GSLog.Info("Received Setting Command with data: " + DataToStr(message.Data));
  9.  
  10.     // Get setting string
  11.     local setting = message.GetStringData(0);
  12.     local response_value = null;
  13.     if (setting != null) {
  14.         if (setting == "goal_mode") {
  15.             response_value = self._main_ptr.goal_mode;
  16.         } else if (setting == "goal_value") {
  17.             if (self._main_ptr.goal_mode == true) {
  18.                 GSLog.Info("response_value = " + ((self._main_ptr.best_value / 1000).tostring()));
  19.                 response_value = (self._main_ptr.best_value / 1000).tostring();
  20.             } else {
  21.                 if (self._main_ptr.rankings[1].c_id != null) {
  22.                     GSLog.Info("response_value = " + self._main_ptr.rankings[1].c_id);
  23.                     response_value = self._main_ptr.rankings[1].c_id;
  24.                 } else {
  25.                     GSLog.Info("response_value = " + GSCompany.COMPANY_INVALID);
  26.                     response_value = GSCompany.COMPANY_INVALID;
  27.                 }
  28.             }
  29.         } else {
  30.             GSLog.Info("AI company " + GSCompany.GetName(message.SenderID) + " asked for unknown setting \"" + setting + "\"");
  31.         }
  32.  
  33.     GSLog.Info(GSCompany.GetName(message.SenderID) + " asked for setting value of \"" + setting + "\" which has the value: " + response_value);
  34.     }
  35.  
  36.     // Answer with the setting value
  37.     SCPLib.Answer(message, setting, response_value);
  38. }
  39.  
  40.  
  41.  
  42. //On the SCPClient_CompanyValue side
  43. ------------------------------------
  44.  
  45. function SCPClient_CompanyValue::AskForGoals()
  46. {
  47.     if (this._scp == null) return;
  48.  
  49.     this.GetCurrentGoal(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF));
  50.  
  51.     // Tell GS to send monthly goal updates
  52. //  this._scp.QueryServer("Setting", COMMAND_SET, "goal_mode", 1);
  53.     this._scp.QueryServer("Setting", COMMAND_SET, "goal_value", 1);
  54. }
  55.  
  56. function SCPClient_CompanyValue::ReceivedSettingCommand(message, self)
  57. {
  58.     self._company_value_gs_game = true;
  59.  
  60.     local setting = message.GetStringData(0);
  61.     AILog.Info("setting = " + setting);
  62.     if (setting != null) {
  63.  
  64.         if (setting == "goal_mode") {
  65.             local value = message.GetIntData(1);
  66.             AILog.Info("Received Setting Command: [" + setting + ": " + value + "]");
  67.             self._goal_mode = value;
  68.         } else if (setting == "goal_value") {
  69.             if (self._goal_mode == true) {
  70.                 // Goal Mode, the value received is a number divided by 1000, passed as a string.
  71.                 // Convert to integer, then multiply by 1000 to get the exact value.
  72.            
  73.                 local value = message.GetStringData(1).tointeger() * 1000;
  74.                 AILog.Info("Received Setting Command: [" + setting + ": " + value + "]");
  75.                 self._goal_value = value;
  76.             } else {
  77.                 // Ranking Mode, the value received is the company id of the company with the current best value */
  78.                 // Try to get the company value of the company id received, if it's still valid, or check which
  79.                 // company has the current best value ourselves.
  80.            
  81.                 local value = message.GetIntData(1);
  82.                 AILog.Info("Received Setting Command: [" + setting + ": " + value + "]");
  83.                 if (AICompany.ResolveCompanyID(value) != AICompany.COMPANY_INVALID) {
  84.                     self._goal_value = AICompany.GetQuarterlyCompanyValue(value, AICompany.CURRENT_QUARTER);
  85.                 } else {
  86.                     self._goal_value = 1;
  87.                     for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) {
  88.                         if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) {
  89.                             local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER);
  90.                             if (c_value > self._goal_value) {
  91.                                 self._goal_value = c_value;
  92.                             }
  93.                         }
  94.                     }
  95.                 }
  96.             }  
  97.         }
  98.     }
  99. }

Comments