Ticket #2048: auras_json_2.2.diff
File auras_json_2.2.diff, 31.7 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/AuraManager.js
1 function AuraManager() {} 2 3 AuraManager.prototype.Schema = 4 "<a:component type='system'/><empty/>"; 5 6 AuraManager.prototype.Init = function() 7 { 8 this.modificationCache = {}; 9 this.modifications = {}; 10 this.templateModificationCache = {}; 11 this.templateModifications = {}; 12 }; 13 14 AuraManager.prototype.ensureExists = function(property, value, ent, key, defaultValue) 15 { 16 if (!this[property][value]) 17 { 18 this[property][value] = {}; 19 this[property + 'Cache'][value] = {}; 20 } 21 22 if (!this[property][value][ent]) 23 { 24 this[property][value][ent] = {}; 25 this[property + 'Cache'][value][ent] = defaultValue; 26 } 27 28 if (!this[property][value][ent][key]) 29 this[property][value][ent][key] = []; 30 }; 31 32 AuraManager.prototype.ApplyBonus = function(value, ent, data, key) 33 { 34 this.ensureExists('modifications', value, ent, key, { "add": 0, "multiply": 1 }); 35 this.modifications[value][ent][key].push(data); 36 37 if (this.modifications[value][ent][key].length > 1) 38 return; 39 // first time added this aura 40 if (data.multiply) 41 this.modificationCache[value][ent].multiply *= data.multiply; 42 43 if (data.add) 44 this.modificationCache[value][ent].add += data.add; 45 46 // post message to the entity to notify it about the change 47 // TODO MT_TechnologyModification expects a player ID, so we have to provide something. 48 // Use -1 until this is changed not to require one. 49 var component = value.split("/")[0]; 50 Engine.PostMessage(ent, MT_TechnologyModification, { "component": component, "player": -1 }); 51 }; 52 53 AuraManager.prototype.ApplyTemplateBonus = function(value, player, classes, data, key) 54 { 55 this.ensureExists('templateModifications', value, player, key, {}); 56 this.templateModifications[value][player][key].push(data); 57 58 if (this.templateModifications[value][player][key].length > 1) 59 return; 60 61 // first time added this aura 62 for each (var c in classes) 63 { 64 if (!this.templateModificationCache[value][player][c]) 65 this.templateModificationCache[value][player][c] = []; 66 67 if (!this.templateModificationCache[value][player][c][key]) 68 this.templateModificationCache[value][player][c][key] = { "add": 0, "multiply": 1, "numberOfAuras": 1 }; 69 70 if (data.multiply) 71 this.templateModificationCache[value][player][c][key].multiply *= data.multiply; 72 73 if (data.add) 74 this.templateModificationCache[value][player][c][key].add += data.add; 75 76 // post message to notify about the change 77 var component = value.split("/")[0]; 78 Engine.BroadcastMessage(MT_TechnologyModification, { "component": component, "player": player}); 79 } 80 }; 81 82 AuraManager.prototype.RemoveBonus = function(value, ent, key) 83 { 84 if (!this.modifications[value] || 85 !this.modifications[value][ent] || 86 !this.modifications[value][ent][key] || 87 !this.modifications[value][ent][key].length) 88 return; 89 90 // get the applied data to remove again 91 var data = this.modifications[value][ent][key].pop(); 92 93 if (this.modifications[value][ent][key].length > 0) 94 return; 95 96 // out of last aura of this kind, remove modifications 97 if (data.add) 98 this.modificationCache[value][ent].add -= data.add; 99 100 if (data.multiply) 101 this.modificationCache[value][ent].multiply /= data.multiply; 102 103 // post message to the entity to notify it about the change 104 // TODO MT_TechnologyModification expects a player ID, so we have to provide something. 105 // Use -1 until this is changed not to require one. 106 var component = value.split("/")[0]; 107 Engine.PostMessage(ent, MT_TechnologyModification, { "component": component, "player": -1 }); 108 }; 109 110 AuraManager.prototype.RemoveTemplateBonus = function(value, player, classes, key) 111 { 112 if (!this.templateModifications[value] || 113 !this.templateModifications[value][player] || 114 !this.templateModifications[value][player][key] || 115 !this.templateModifications[value][player][key].length) 116 return; 117 118 this.templateModifications[value][player][key].pop(); 119 120 if (this.templateModifications[value][player][key].length > 0) 121 return; 122 123 for each (var c in classes) 124 { 125 this.templateModificationCache[value][player][c][key].multiply = 1; 126 this.templateModificationCache[value][player][c][key].add = 0; 127 128 // post message to notify about the change 129 var component = value.split("/")[0]; 130 Engine.BroadcastMessage(MT_TechnologyModification, { "component": component, "player": player }); 131 } 132 }; 133 134 AuraManager.prototype.ApplyModifications = function(valueName, value, ent) 135 { 136 if (!this.modificationCache[valueName] || !this.modificationCache[valueName][ent]) 137 return value; 138 139 value *= this.modificationCache[valueName][ent].multiply; 140 value += this.modificationCache[valueName][ent].add; 141 return value; 142 }; 143 144 AuraManager.prototype.ApplyTemplateModifications = function(valueName, value, player, template) 145 { 146 if (!this.templateModificationCache[valueName] || !this.templateModificationCache[valueName][player]) 147 return value; 148 149 var classes = template.Identity.Classes._string.split(/\s+/); 150 151 var keyList = []; 152 153 for (var c in this.templateModificationCache[valueName][player]) 154 { 155 if (classes.indexOf(c) == -1) 156 continue; 157 158 for (var key in this.templateModificationCache[valueName][player][c]) 159 { 160 // don't add an aura with the same key twice 161 if (keyList.indexOf(key) != -1) 162 continue; 163 164 value *= this.templateModificationCache[valueName][player][c][key].multiply; 165 value += this.templateModificationCache[valueName][player][c][key].add; 166 keyList.push(key); 167 } 168 } 169 return value; 170 }; 171 172 Engine.RegisterComponentType(IID_AuraManager, "AuraManager", AuraManager); -
binaries/data/mods/public/simulation/components/Auras.js
2 2 3 3 Auras.prototype.Schema = 4 4 "<oneOrMore>" + 5 "<element>" + 6 "<choice>" + 7 "<name>Allure</name>" + 8 "<name>Infidelity</name>" + 9 "<name>Heal</name>" + 10 "<name>Courage</name>" + 11 "<name>Fear</name>" + 12 "</choice>" + 13 "<interleave>" + 14 "<element name='Radius'>" + 5 "<element a:help='Name of the aura JSON file to use, case-insensitive'>" + 6 "<anyName/>" + 7 "<optional>" + 8 "<element name='Radius' a:help='Define the radius this aura affects, if it is a range aura'>" + 15 9 "<data type='nonNegativeInteger'/>" + 16 10 "</element>" + 17 "<optional>" + 18 "<element name='Bonus'>" + 19 "<data type='positiveInteger'/>" + 20 "</element>" + 21 "</optional>" + 22 "<optional>" + 23 "<element name='Time'>" + 24 "<data type='nonNegativeInteger'/>" + 25 "</element>" + 26 "</optional>" + 27 "<optional>" + 28 "<element name='Speed'>" + 29 "<data type='positiveInteger'/>" + 30 "</element>" + 31 "</optional>" + 32 "</interleave>" + 11 "</optional>" + 12 "<element name='Type' a:help='Controls how this aura affects nearby units'>" + 13 "<choice>" + 14 "<value a:help='Affects units in the same formation'>formation</value>" + 15 "<value a:help='Affects units in a certain range'>range</value>" + 16 "<value a:help='Affects the structure or unit this unit is garrisoned in'>garrison</value>" + 17 "<value a:help='Affects all units while this unit is alive'>global</value>" + 18 "</choice>" + 19 "</element>" + 33 20 "</element>" + 34 21 "</oneOrMore>"; 35 22 36 /* 37 * TODO: this all needs to be designed and implemented 23 Auras.prototype.Init = function() 24 { 25 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 26 this.templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); 27 var auraNames = this.GetAuraNames(); 28 this.auras = {}; 29 var cmpTechnologyTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager); 30 for each (var name in auraNames) 31 this.auras[name] = cmpTechnologyTemplateManager.GetAuraTemplate(name); 32 }; 33 34 Auras.prototype.GetAuraNames = function() 35 { 36 return Object.keys(this.template); 37 }; 38 39 Auras.prototype.GetRange = function(name) 40 { 41 if (!this.IsRangeAura(name)) 42 return undefined; 43 if (this.IsGlobalAura(name)) 44 return -1; // -1 is infinite range 45 return +this.template[name].Radius; 46 }; 47 48 Auras.prototype.GetClasses = function(name) 49 { 50 return this.auras[name].affects; 51 }; 52 53 Auras.prototype.GetModifications = function(name) 54 { 55 return this.auras[name].modifications; 56 }; 57 58 Auras.prototype.GetAffectedPlayers = function(name) 59 { 60 if (this.auras[name].affectedPlayers) 61 var affectedPlayers = this.auras[name].affectedPlayers; 62 else 63 var affectedPlayers = ["Player"]; 64 65 var ret = []; 66 67 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 68 69 if (!cmpPlayer) 70 return ret; 71 72 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 73 var numPlayers = cmpPlayerManager.GetNumPlayers(); 74 75 for (var i = 0; i < numPlayers; ++i) 76 { 77 for each (var p in affectedPlayers) 78 { 79 if (p == "Player" ? cmpPlayer.GetPlayerID() == i : cmpPlayer["Is" + p](i)) 80 { 81 ret.push(i); 82 break; 83 } 84 } 85 } 86 return ret; 87 }; 88 89 Auras.prototype.HasFormationAura = function() 90 { 91 return this.GetAuraNames().some(this.IsFormationAura.bind(this)); 92 }; 93 94 Auras.prototype.HasGarrisonAura = function() 95 { 96 return this.GetAuraNames().some(this.IsGarrisonAura.bind(this)); 97 }; 98 99 Auras.prototype.GetType = function(name) 100 { 101 return this.template[name].Type; 102 }; 103 104 Auras.prototype.IsFormationAura = function(name) 105 { 106 return this.GetType(name) == "Formation"; 107 }; 108 109 Auras.prototype.IsGarrisonAura = function(name) 110 { 111 return this.GetType(name) == "GarrisoningStructure"; 112 }; 113 114 Auras.prototype.IsRangeAura = function(name) 115 { 116 // A global aura is also treated as a range aura with infinite range. 117 return ["range", "global"].indexOf(this.GetType(name)) != -1; 118 }; 119 120 Auras.prototype.IsGlobalAura = function(name) 121 { 122 return this.GetType(name) == "global"; 123 }; 124 125 /** 126 * clean all bonuses. Remove the old ones and re-apply the new ones 38 127 */ 128 Auras.prototype.Clean = function() 129 { 130 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 131 var auraNames = this.GetAuraNames(); 132 // remove all bonuses 133 for each (var name in auraNames) 134 { 135 if (!this[name]) 136 continue; 39 137 40 Auras.prototype.Serialize = null; // we have no dynamic state to save 138 if (this.IsGlobalAura(name)) 139 this.RemoveTemplateBonus(name); 41 140 141 for each(var ent in this[name].targetUnits) 142 this.RemoveBonus(name, ent); 143 144 if (this[name].rangeQuery) 145 cmpRangeManager.DestroyActiveQuery(this[name].rangeQuery); 146 } 147 148 for each (var name in auraNames) 149 { 150 // initialise range query 151 this[name] = {}; 152 this[name].targetUnits = []; 153 var affectedPlayers = this.GetAffectedPlayers(name); 154 155 if (!affectedPlayers.length) 156 continue; 157 158 if (this.IsGlobalAura(name)) 159 this.ApplyTemplateBonus(name, affectedPlayers); 160 161 if (!this.IsRangeAura(name)) 162 continue; 163 this[name].rangeQuery = cmpRangeManager.CreateActiveQuery( 164 this.entity, 165 0, 166 this.GetRange(name), 167 affectedPlayers, 168 IID_Identity, 169 cmpRangeManager.GetEntityFlagMask("normal") 170 ); 171 cmpRangeManager.EnableActiveQuery(this[name].rangeQuery); 172 // Add self to your own query for consistency with templates. 173 this.OnRangeUpdate({"tag":this[name].rangeQuery, "added":[this.entity], "removed":[]}); 174 } 175 }; 176 177 Auras.prototype.GiveMembersWithValidClass = function(auraName, entityList) 178 { 179 var validClasses = this.GetClasses(auraName); 180 var r = []; 181 for each (var ent in entityList) 182 { 183 var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 184 var targetClasses = cmpIdentity.GetClassesList(); 185 for each (var classCollection in validClasses) 186 { 187 if (classCollection.split(/\s+/).every(function(c) {return targetClasses.indexOf(c) > -1})) 188 { 189 r.push(ent); 190 break; 191 } 192 } 193 } 194 return r; 195 } 196 197 Auras.prototype.OnRangeUpdate = function(msg) 198 { 199 var auraNames = this.GetAuraNames(); 200 for each (var n in auraNames) 201 { 202 if (msg.tag == this[n].rangeQuery) 203 { 204 var name = n; 205 break; 206 } 207 } 208 209 if (!name) 210 return; 211 212 var targetUnits = this[name].targetUnits; 213 var classes = this.GetClasses(name); 214 215 if (msg.added.length > 0) 216 { 217 var validList = this.GiveMembersWithValidClass(name, msg.added); 218 for each (var e in validList) 219 { 220 targetUnits.push(e); 221 this.ApplyBonus(name, e); 222 } 223 } 224 225 if (msg.removed.length > 0) 226 { 227 for each (var e in msg.removed) 228 { 229 targetUnits.splice(targetUnits.indexOf(e), 1); 230 this.RemoveBonus(name, e); 231 } 232 } 233 234 }; 235 236 Auras.prototype.ApplyFormationBonus = function(memberList) 237 { 238 var auraNames = this.GetAuraNames(); 239 for each (var name in auraNames) 240 { 241 if (!this.IsFormationAura(name)) 242 continue; 243 244 var validList = this.GiveMembersWithValidClass(name, memberList); 245 for each (var ent in validList) 246 { 247 targetUnits.push(e); 248 this.ApplyBonus(name,e); 249 } 250 } 251 }; 252 253 Auras.prototype.ApplyGarrisonBonus = function(structure) 254 { 255 var auraNames = this.GetAuraNames(); 256 for each (var name in auraNames) 257 { 258 if (!this.IsGarrisonAura(name)) 259 continue; 260 261 var validList = this.GiveMembersWithValidClass(name, [structure]); 262 if (validList.length) 263 { 264 targetUnits.push(validList[0]); 265 this.ApplyBonus(name,validList[0]); 266 } 267 } 268 }; 269 270 Auras.prototype.ApplyTemplateBonus = function(name, players) 271 { 272 if (!this.IsGlobalAura(name)) 273 return; 274 var modifications = this.GetModifications(name); 275 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 276 var classes = this.GetClasses(name); 277 278 for each (var mod in modifications) 279 for each (var player in players) 280 cmpAuraManager.ApplyTemplateBonus(mod.value, player, classes, mod, this.templateName + "/" + name + "/" + mod.value); 281 }; 282 283 Auras.prototype.RemoveFormationBonus = function(memberList) 284 { 285 var auraNames = this.GetAuraNames(); 286 for each (var name in auraName) 287 { 288 if (!this.IsFormationAura(name)) 289 continue; 290 291 for each (var ent in memberList) 292 { 293 this.RemoveBonus(name,ent); 294 this[name].targetUnits.splice(this[name].targetUnits.indexOf(ent), 1); 295 } 296 } 297 }; 298 299 Auras.prototype.RemoveGarrisonBonus = function(structure) 300 { 301 var auraNames = this.GetAuraNames(); 302 for each (var name in auraNames) 303 { 304 if (!this.IsGarrisonAura(name)) 305 continue; 306 307 this.RemoveBonus(name,structure); 308 this[name].targetUnits.splice(this[name].targetUnits.indexOf(structure), 1); 309 } 310 }; 311 312 Auras.prototype.RemoveTemplateBonus = function(name) 313 { 314 if (!this.IsGlobalAura(name)) 315 return; 316 317 var modifications = this.GetModifications(name); 318 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 319 var classes = this.GetClasses(name); 320 321 for each (var mod in modifications) 322 for each (var player in this.GetAffectedPlayers()) 323 cmpAuraManager.RemoveTemplateBonus(mod.value, player, classes, this.templateName + "/" + name + "/" + mod.value); 324 }; 325 326 Auras.prototype.ApplyBonus = function(name, ent) 327 { 328 var modifications = this.GetModifications(name); 329 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 330 331 for each (mod in modifications) 332 cmpAuraManager.ApplyBonus(mod.value, ent, mod, this.templateName + "/" + name + "/" + mod.value); 333 334 }; 335 336 Auras.prototype.RemoveBonus = function(name, ent) 337 { 338 var modifications = this.GetModifications(name); 339 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 340 341 for each (mod in modifications) 342 cmpAuraManager.RemoveBonus(mod.value, ent, this.templateName + "/" + name + "/" + mod.value); 343 }; 344 345 Auras.prototype.OnOwnershipChanged = function(msg) 346 { 347 this.Clean(); 348 }; 349 350 Auras.prototype.OnDiplomacyChanged = function(msg) 351 { 352 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 353 if (cmpOwnership && cmpOwnership.GetOwner() == msg.player) 354 this.Clean(); 355 }; 356 357 Auras.prototype.OnTechnologyModification = function(msg) 358 { 359 if (msg.component =="Auras") 360 this.Clean(); 361 }; 362 42 363 Engine.RegisterComponentType(IID_Auras, "Auras", Auras); -
binaries/data/mods/public/simulation/components/EndGameManager.js
19 19 // Allied victory means allied players can win if victory conditions are met for each of them 20 20 // Would be false for a "last man standing" game (when diplomacy is fully implemented) 21 21 this.alliedVictory = true; 22 this.activePlayers = []; 22 23 }; 23 24 24 25 EndGameManager.prototype.SetGameType = function(newGameType) … … 31 32 this.alliedVictory = flag; 32 33 }; 33 34 34 /** 35 * Begin checking the end-game conditions. 36 * Must be called once, after calling SetGameType. 37 */ 38 EndGameManager.prototype.Start = function() 35 EndGameManager.prototype.OnUpdate = function() 39 36 { 40 if (this.gameType != "endless") 37 if (this.gameType == "endless") 38 return; 39 // initialise the activePlayers array on the start of the game 40 if (!this.activePlayers.length) 41 41 { 42 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);43 this.timer = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "ProgressTimeout", g_ProgressInterval, {});42 this.UpdatePlayerStates(); 43 return; 44 44 } 45 };46 45 47 EndGameManager.prototype.OnDestroy = function() 48 { 49 if (this.timer) 50 { 51 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 52 cmpTimer.CancelTimer(this.timer); 53 } 54 }; 46 if (!this.activePlayers.every(function(v){return v.GetConquestCriticalEntitiesCount()})) 47 this.UpdatePlayerStates(); 48 } 55 49 56 EndGameManager.prototype. ProgressTimeout = function(data)50 EndGameManager.prototype.UpdatePlayerStates = function() 57 51 { 58 this.UpdatePlayerStates(); 59 60 // Repeat the timer 61 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 62 this.timer = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "ProgressTimeout", g_ProgressInterval, data); 63 }; 52 if (this.gameType == "endless") 53 return; 64 54 65 EndGameManager.prototype.UpdatePlayerStates = function()66 {67 55 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 68 switch (this.gameType) 56 var numPlayers = cmpPlayerManager.GetNumPlayers(); 57 this.activePlayers = []; 58 59 // get all the active players (or won). Defeat players without the needed entities 60 for (var i = 1; i < numPlayers; ++i) 69 61 { 70 case "conquest": 62 var playerEntity = cmpPlayerManager.GetPlayerByID(i); 63 var cmpPlayer = Engine.QueryInterface(playerEntity, IID_Player); 64 if (cmpPlayer.GetState() == "defeated") 65 continue; 66 if (cmpPlayer.GetConquestCriticalEntitiesCount()) 67 this.activePlayers.push(cmpPlayer); 68 else 69 Engine.PostMessage(playerEntity, MT_PlayerDefeated); 70 } 71 71 72 // Ignore gaia 73 var numPlayers = cmpPlayerManager.GetNumPlayers() - 1; 74 var cmpPlayers = new Array(numPlayers); 75 76 // If a player is currently active but has no suitable units left, 77 // mark that player as defeated 78 for (var i = 0; i < numPlayers; i++) 79 { 80 var playerEntityId = cmpPlayerManager.GetPlayerByID(i+1); 81 cmpPlayers[i] = Engine.QueryInterface(playerEntityId, IID_Player); 82 if (cmpPlayers[i].GetState() == "active") 83 { 84 if (cmpPlayers[i].GetConquestCriticalEntitiesCount() == 0) 85 { // Defeated - notify AIs by sending playerId 86 Engine.PostMessage(playerEntityId, MT_PlayerDefeated, { "playerId": i } ); 87 } 88 } 89 } 72 if (!this.alliedVictory && this.activePlayers.length > 1) 73 return; 90 74 91 var onlyAlliesLeft = true; 92 var allies = []; 93 for (var i = 0; i < numPlayers && onlyAlliesLeft; i++) 94 { 95 if (cmpPlayers[i].GetState() == "active") 96 { //Active player 97 for (var j = 0; j < numPlayers && onlyAlliesLeft; j++) 98 { 99 if (cmpPlayers[j].GetState() == "active" 100 && (cmpPlayers[i].IsEnemy(j+1) || cmpPlayers[j].IsEnemy(i+1) 101 || cmpPlayers[i].IsNeutral(j+1) || cmpPlayers[j].IsNeutral(i+1))) 102 { // Only need to find an active non-allied player 103 onlyAlliesLeft = false; 104 } 105 } 106 107 if (onlyAlliesLeft) 108 allies.push(i); 109 } 110 } 75 for each (var cmpPlayer in this.activePlayers) 76 { 77 if (!this.activePlayers.every(function(v){return cmpPlayer == v || cmpPlayer.IsMutualAlly(v.GetPlayerID())})) 78 return; 79 } 111 80 112 // If only allies left and allied victory set (or only one player left) 113 if (onlyAlliesLeft && (this.alliedVictory || allies.length == 1)) 114 { 115 for each (var p in allies) 116 { 117 cmpPlayers[p].SetState("won"); 118 } 119 120 // Reveal the map to all players 121 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 122 cmpRangeManager.SetLosRevealAll(-1, true); 123 } 124 125 break; 126 127 default: 128 error("Invalid game type "+this.gameType); 129 break; 130 } 81 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 82 cmpRangeManager.SetLosRevealAll(-1, true); 83 for each (var cmpPlayer in this.activePlayers) 84 cmpPlayer.SetState("won"); 131 85 }; 132 86 133 87 Engine.RegisterComponentType(IID_EndGameManager, "EndGameManager", EndGameManager); -
binaries/data/mods/public/simulation/components/Formation.js
12 12 this.columnar = false; // whether we're travelling in column (vs box) formation 13 13 this.formationName = "Line Closed"; 14 14 this.rearrange = true; // whether we should rearrange all formation members 15 this.formationMemebersWithAura = []; // Members with a formation aura 15 16 }; 16 17 17 18 Formation.prototype.GetMemberCount = function() … … 86 87 { 87 88 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 88 89 cmpUnitAI.SetFormationController(this.entity); 90 91 var cmpAuras = Engine.QueryInterface(ent, IID_Auras); 92 if (cmpAuras && cmpAuras.HasFormationAura()) 93 { 94 this.formationMemebersWithAura.push(ent); 95 cmpAuras.ApplyFormationBonus(ents); 96 } 89 97 } 90 98 91 99 // Locate this formation controller in the middle of its members … … 92 100 this.MoveToMembersCenter(); 93 101 94 102 this.ComputeMotionParameters(); 103 95 104 }; 96 105 97 106 /** … … 109 118 cmpUnitAI.SetFormationController(INVALID_ENTITY); 110 119 } 111 120 121 for each (var ent in this.formationMemebersWithAura) 122 { 123 var cmpAuras = Engine.QueryInterface(ent, IID_Auras); 124 cmpAuras.RemoveFormationBonus(ents); 125 126 // the unit with the aura is also removed from the formation 127 if (ents.indexOf(ent) !== -1) 128 cmpAuras.RemoveFormationBonus(this.members); 129 } 130 131 this.formationMemebersWithAura = this.formationMemebersWithAura.filter(function(e) { return ents.indexOf(e) == -1; }); 132 112 133 // If there's nobody left, destroy the formation 113 134 if (this.members.length == 0) 114 135 { … … 155 176 cmpUnitAI.SetFormationController(INVALID_ENTITY); 156 177 } 157 178 179 for each (var ent in this.formationMemebersWithAura) 180 { 181 var cmpAuras = Engine.QueryInterface(ent, IID_Auras); 182 cmpAuras.RemoveFormationBonus(this.members); 183 } 184 185 158 186 this.members = []; 159 187 this.inPosition = []; 188 this.formationMemebersWithAura = []; 160 189 161 190 Engine.DestroyEntity(this.entity); 162 191 }; -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
185 185 if (cmpProductionQueue) 186 186 cmpProductionQueue.PauseProduction(); 187 187 188 var cmpAura = Engine.QueryInterface(entity, IID_Auras); 189 if (cmpAura && cmpAura.HasGarrisonAura()) 190 { 191 cmpAura.ApplyGarrisonBonus(this.entity); 192 } 193 188 194 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {}); 189 195 return true; 190 196 }; … … 228 234 var cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); 229 235 if (cmpProductionQueue) 230 236 cmpProductionQueue.UnpauseProduction(); 237 238 var cmpAura = Engine.QueryInterface(entity, IID_Auras); 239 if (cmpAura && cmpAura.HasGarrisonAura()) 240 { 241 cmpAura.RemoveGarrisonBonus(this.entity); 242 } 243 231 244 232 245 var cmpNewPosition = Engine.QueryInterface(entity, IID_Position); 233 246 cmpNewPosition.JumpTo(pos.x, pos.z); -
binaries/data/mods/public/simulation/components/TechnologyTemplateManager.js
9 9 TechnologyTemplateManager.prototype.Init = function() 10 10 { 11 11 this.allTechs = {}; 12 this.allAuras = {}; 12 13 var techNames = this.ListAllTechs(); 13 14 for (var i in techNames) 14 15 this.GetTemplate(techNames[i]); … … 26 27 return this.allTechs[template]; 27 28 }; 28 29 30 TechnologyTemplateManager.prototype.GetAuraTemplate = function(template) 31 { 32 if (!this.allAuras[template]) 33 { 34 this.allAuras[template] = Engine.ReadJSONFile("auras/" + template + ".json"); 35 if (! this.allAuras[template]) 36 error("Failed to load aura \"" + template + "\""); 37 } 38 39 return this.allAuras[template]; 40 }; 41 29 42 TechnologyTemplateManager.prototype.ListAllTechs = function() 30 43 { 31 44 return Engine.FindJSONFiles("technologies", true); -
binaries/data/mods/public/simulation/components/interfaces/AuraManager.js
1 Engine.RegisterInterface("AuraManager"); -
binaries/data/mods/public/simulation/components/tests/test_UnitAI.js
2 2 Engine.LoadHelperScript("Entity.js"); 3 3 Engine.LoadHelperScript("Player.js"); 4 4 Engine.LoadComponentScript("interfaces/Attack.js"); 5 Engine.LoadComponentScript("interfaces/Auras.js"); 5 6 Engine.LoadComponentScript("interfaces/DamageReceiver.js"); 6 7 Engine.LoadComponentScript("interfaces/Formation.js"); 7 8 Engine.LoadComponentScript("interfaces/Heal.js"); -
binaries/data/mods/public/simulation/helpers/Setup.js
41 41 { 42 42 cmpEndGameManager.SetGameType(settings.GameType); 43 43 } 44 cmpEndGameManager.Start();45 44 } 46 45 47 46 Engine.RegisterGlobal("LoadMapSettings", LoadMapSettings); -
binaries/data/mods/public/simulation/helpers/Technology.js
3 3 function ApplyTechModificationsToEntity(tech_type, current_value, entity) 4 4 { 5 5 var cmpTechMan = QueryOwnerInterface(entity, IID_TechnologyManager); 6 if (cmpTechMan) 7 var value = cmpTechMan.ApplyModificationsTemplate(tech_type, current_value, entity); 8 else 9 var value = current_value; 6 10 7 if (!cmpTechMan)8 return current_value;9 10 return cmp TechMan.ApplyModifications(tech_type, current_value, entity);11 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 12 if (!cmpAuraManager) 13 return value; 14 return cmpAuraManager.ApplyModifications(tech_type, value, entity); 11 15 } 12 16 13 17 function ApplyTechModificationsToPlayer(tech_type, current_value, player_entity) … … 23 27 function ApplyTechModificationsToTemplate(tech_type, current_value, playerID, template) 24 28 { 25 29 var cmpTechMan = QueryPlayerIDInterface(playerID, IID_TechnologyManager); 30 if (cmpTechMan) 31 var value = cmpTechMan.ApplyModificationsTemplate(tech_type, current_value, template); 32 else 33 var value = current_value; 26 34 27 if (!cmpTechMan)28 return current_value;29 30 return cmp TechMan.ApplyModificationsTemplate(tech_type, current_value, template);35 var cmpAuraManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AuraManager); 36 if (!cmpAuraManager) 37 return value; 38 return cmpAuraManager.ApplyTemplateModifications(tech_type, value, playerID, template); 31 39 } 32 40 33 41 Engine.RegisterGlobal("ApplyTechModificationsToEntity", ApplyTechModificationsToEntity); -
binaries/data/mods/public/simulation/templates/gaia/fauna_chicken.xml
15 15 <ResourceSupply> 16 16 <Amount>40</Amount> 17 17 <Type>food.meat</Type> 18 18 <MaxGatherers>5</MaxGatherers> 19 19 </ResourceSupply> 20 20 <Sound> 21 21 <SoundGroups> -
binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_structure_civic"> 3 3 <Auras> 4 < Heal>5 < Radius>40</Radius>6 < Speed>1000</Speed>7 </ Heal>4 <heal> 5 <Type>range</Type> 6 <Radius>10</Radius> 7 </heal> 8 8 </Auras> 9 9 <BuildRestrictions> 10 10 <Category>Temple</Category> -
binaries/data/mods/public/simulation/templates/template_unit_fauna_herd.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_unit_fauna"> 3 <Auras>4 <Infidelity>5 <Radius>20</Radius>6 <Time>0</Time>7 </Infidelity>8 </Auras>9 3 <Health> 10 4 <DeathType>remain</DeathType> 11 5 </Health> -
binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
16 16 <MaxRange>4.0</MaxRange> 17 17 </Slaughter> 18 18 </Attack> 19 <Auras>20 <Allure>21 <Radius>25</Radius>22 </Allure>23 <Infidelity>24 <Radius>10</Radius>25 <Time>10</Time>26 </Infidelity>27 </Auras>28 19 <Builder> 29 20 <Rate>1.0</Rate> 30 21 <Entities datatype="tokens"> -
source/simulation2/Simulation2.cpp
125 125 LOGERROR(L"Can't find component type " L##name); \ 126 126 componentManager.AddComponent(systemEntity, cid, noParam) 127 127 128 LOAD_SCRIPTED_COMPONENT("AuraManager"); 128 129 LOAD_SCRIPTED_COMPONENT("AIInterface"); 129 130 LOAD_SCRIPTED_COMPONENT("Barter"); 130 131 LOAD_SCRIPTED_COMPONENT("EndGameManager");