//On the Company Value GS code:
//-------------------------------
function SCPManager::ReceivedSettingCommand(message, self)
{
if (!self._scp_enabled) return;
GSLog.Info("Received Setting Command with data: " + DataToStr(message.Data));
// Get setting string
local setting = message.GetStringData(0);
local response_value = null;
if (setting != null) {
if (setting == "goal_mode") {
response_value = self._main_ptr.goal_mode;
} else if (setting == "goal_value") {
if (self._main_ptr.goal_mode == true) {
GSLog.Info("response_value = " + ((self._main_ptr.best_value / 1000).tostring()));
response_value = (self._main_ptr.best_value / 1000).tostring();
} else {
if (self._main_ptr.rankings[1].c_id != null) {
GSLog.Info("response_value = " + self._main_ptr.rankings[1].c_id);
response_value = self._main_ptr.rankings[1].c_id;
} else {
GSLog.Info("response_value = " + GSCompany.COMPANY_INVALID);
response_value = GSCompany.COMPANY_INVALID;
}
}
} else {
GSLog.Info("AI company " + GSCompany.GetName(message.SenderID) + " asked for unknown setting \"" + setting + "\"");
}
GSLog.Info(GSCompany.GetName(message.SenderID) + " asked for setting value of \"" + setting + "\" which has the value: " + response_value);
}
// Answer with the setting value
SCPLib.Answer(message, setting, response_value);
}
//On the SCPClient_CompanyValue side
------------------------------------
function SCPClient_CompanyValue::AskForGoals()
{
if (this._scp == null) return;
this.GetCurrentGoal(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF));
// Tell GS to send monthly goal updates
// this._scp.QueryServer("Setting", COMMAND_SET, "goal_mode", 1);
this._scp.QueryServer("Setting", COMMAND_SET, "goal_value", 1);
}
function SCPClient_CompanyValue::ReceivedSettingCommand(message, self)
{
self._company_value_gs_game = true;
local setting = message.GetStringData(0);
AILog.Info("setting = " + setting);
if (setting != null) {
if (setting == "goal_mode") {
local value = message.GetIntData(1);
AILog.Info("Received Setting Command: [" + setting + ": " + value + "]");
self._goal_mode = value;
} else if (setting == "goal_value") {
if (self._goal_mode == true) {
// Goal Mode, the value received is a number divided by 1000, passed as a string.
// Convert to integer, then multiply by 1000 to get the exact value.
local value = message.GetStringData(1).tointeger() * 1000;
AILog.Info("Received Setting Command: [" + setting + ": " + value + "]");
self._goal_value = value;
} else {
// Ranking Mode, the value received is the company id of the company with the current best value */
// Try to get the company value of the company id received, if it's still valid, or check which
// company has the current best value ourselves.
local value = message.GetIntData(1);
AILog.Info("Received Setting Command: [" + setting + ": " + value + "]");
if (AICompany.ResolveCompanyID(value) != AICompany.COMPANY_INVALID) {
self._goal_value = AICompany.GetQuarterlyCompanyValue(value, AICompany.CURRENT_QUARTER);
} else {
self._goal_value = 1;
for (local c_id = AICompany.COMPANY_FIRST; c_id < AICompany.COMPANY_LAST; c_id++) {
if (AICompany.ResolveCompanyID(c_id) != AICompany.COMPANY_INVALID) {
local c_value = AICompany.GetQuarterlyCompanyValue(c_id, AICompany.CURRENT_QUARTER);
if (c_value > self._goal_value) {
self._goal_value = c_value;
}
}
}
}
}
}
}
}