Differential D270 Diff 12733 ps/trunk/binaries/data/mods/public/simulation/components/AIInterface.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/AIInterface.js
function AIInterface() {} | function AIInterface() {} | ||||
AIInterface.prototype.Schema = | AIInterface.prototype.Schema = | ||||
"<a:component type='system'/><empty/>"; | "<a:component type='system'/><empty/>"; | ||||
AIInterface.prototype.EventNames = [ | AIInterface.prototype.EventNames = [ | ||||
"Create", | "Create", | ||||
"Destroy", | "Destroy", | ||||
"Attacked", | "Attacked", | ||||
"ConstructionFinished", | "ConstructionFinished", | ||||
"DiplomacyChanged", | "DiplomacyChanged", | ||||
"TrainingStarted", | "TrainingStarted", | ||||
"TrainingFinished", | "TrainingFinished", | ||||
"AIMetadata", | "AIMetadata", | ||||
"PlayerDefeated", | "PlayerDefeated", | ||||
"EntityRenamed", | "EntityRenamed", | ||||
"ValueModification", | |||||
"OwnershipChanged", | "OwnershipChanged", | ||||
"Garrison", | "Garrison", | ||||
"UnGarrison", | "UnGarrison", | ||||
"TerritoriesChanged", | "TerritoriesChanged", | ||||
"TerritoryDecayChanged", | "TerritoryDecayChanged", | ||||
"TributeExchanged", | "TributeExchanged", | ||||
"AttackRequest", | "AttackRequest", | ||||
"CeasefireEnded", | "CeasefireEnded", | ||||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | for (let valName of msg.valueNames) | ||||
if (item !== undefined && item[str] !== undefined) | if (item !== undefined && item[str] !== undefined) | ||||
item = item[str]; | item = item[str]; | ||||
else | else | ||||
ended = false; | ended = false; | ||||
} | } | ||||
if (!ended) | if (!ended) | ||||
continue; | continue; | ||||
// item now contains the template value for this. | // item now contains the template value for this. | ||||
let oldValue = +item; | let oldValue = +item == item ? +item : item; | ||||
let newValue = ApplyValueModificationsToTemplate(valName, oldValue, msg.player, template); | let newValue = ApplyValueModificationsToTemplate(valName, oldValue, msg.player, template); | ||||
// Apply the same roundings as in the components | // Apply the same roundings as in the components | ||||
if (valName === "Player/MaxPopulation" || valName === "Cost/Population" || | if (valName === "Player/MaxPopulation" || valName === "Cost/Population" || | ||||
valName === "Cost/PopulationBonus") | valName === "Cost/PopulationBonus") | ||||
newValue = Math.round(newValue); | newValue = Math.round(newValue); | ||||
// TODO in some cases, we can have two opposite changes which bring us to the old value, | // TODO in some cases, we can have two opposite changes which bring us to the old value, | ||||
// and we should keep it. But how to distinguish it ? | // and we should keep it. But how to distinguish it ? | ||||
if(newValue == oldValue) | if(newValue == oldValue) | ||||
continue; | continue; | ||||
if (!this.changedTemplateInfo[msg.player]) | if (!this.changedTemplateInfo[msg.player]) | ||||
this.changedTemplateInfo[msg.player] = {}; | this.changedTemplateInfo[msg.player] = {}; | ||||
if (!this.changedTemplateInfo[msg.player][name]) | if (!this.changedTemplateInfo[msg.player][name]) | ||||
this.changedTemplateInfo[msg.player][name] = [{ "variable": valName, "value": newValue }]; | this.changedTemplateInfo[msg.player][name] = [{ "variable": valName, "value": newValue }]; | ||||
else | else | ||||
this.changedTemplateInfo[msg.player][name].push({ "variable": valName, "value": newValue }); | this.changedTemplateInfo[msg.player][name].push({ "variable": valName, "value": newValue }); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
AIInterface.prototype.OnGlobalValueModification = function(msg) | AIInterface.prototype.OnGlobalValueModification = function(msg) | ||||
{ | { | ||||
this.events.ValueModification.push(msg); | |||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
for (let ent of msg.entities) | for (let ent of msg.entities) | ||||
{ | { | ||||
let templateName = cmpTemplateManager.GetCurrentTemplateName(ent); | let templateName = cmpTemplateManager.GetCurrentTemplateName(ent); | ||||
// if there's no template name, the unit is probably killed, ignore it. | // if there's no template name, the unit is probably killed, ignore it. | ||||
if (!templateName || !templateName.length) | if (!templateName || !templateName.length) | ||||
continue; | continue; | ||||
let template = cmpTemplateManager.GetTemplateWithoutValidation(templateName); | let template = cmpTemplateManager.GetTemplateWithoutValidation(templateName); | ||||
Show All 10 Lines | for (let valName of msg.valueNames) | ||||
if (item !== undefined && item[str] !== undefined) | if (item !== undefined && item[str] !== undefined) | ||||
item = item[str]; | item = item[str]; | ||||
else | else | ||||
ended = false; | ended = false; | ||||
} | } | ||||
if (!ended) | if (!ended) | ||||
continue; | continue; | ||||
// "item" now contains the unmodified template value for this. | // "item" now contains the unmodified template value for this. | ||||
let oldValue = +item; | let oldValue = +item == item ? +item : item; | ||||
let newValue = ApplyValueModificationsToEntity(valName, oldValue, ent); | let newValue = ApplyValueModificationsToEntity(valName, oldValue, ent); | ||||
// Apply the same roundings as in the components | // Apply the same roundings as in the components | ||||
if (valName === "Player/MaxPopulation" || valName === "Cost/Population" || | if (valName === "Player/MaxPopulation" || valName === "Cost/Population" || | ||||
valName === "Cost/PopulationBonus") | valName === "Cost/PopulationBonus") | ||||
newValue = Math.round(newValue); | newValue = Math.round(newValue); | ||||
// TODO in some cases, we can have two opposite changes which bring us to the old value, | // TODO in some cases, we can have two opposite changes which bring us to the old value, | ||||
// and we should keep it. But how to distinguish it ? | // and we should keep it. But how to distinguish it ? | ||||
if (newValue == oldValue) | if (newValue == oldValue) | ||||
Show All 10 Lines |
Wildfire Games · Phabricator