Ticket #2160: regicide_early_attack_v2.patch
File regicide_early_attack_v2.patch, 30.1 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/gamesetup/gamesetup.js
function initRadioButtons() 496 496 let options = { 497 497 "RevealMap": "revealMap", 498 498 "ExploreMap": "exploreMap", 499 499 "DisableTreasures": "disableTreasures", 500 500 "LockTeams": "lockTeams", 501 "LastManStanding" : "lastManStanding", 501 "LastManStanding": "lastManStanding", 502 "RegicideEarlyAttack": "regicideEarlyAttack", 502 503 "CheatsEnabled": "enableCheats" 503 504 }; 504 505 505 506 Object.keys(options).forEach(attribute => { 506 507 Engine.GetGUIObjectByName(options[attribute]).onPress = function() { … … function selectMap(name) 1181 1182 1182 1183 if (g_GameAttributes.mapType == "scenario") 1183 1184 { 1184 1185 delete g_GameAttributes.settings.WonderDuration; 1185 1186 delete g_GameAttributes.settings.LastManStanding; 1187 delete g_GameAttributes.settings.RegicideEarlyAttack; 1186 1188 } 1187 1189 1188 1190 if (mapSettings.PlayerData) 1189 1191 sanitizePlayerData(mapSettings.PlayerData); 1190 1192 … … function updateGUIObjects() 1378 1380 setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); 1379 1381 setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap); 1380 1382 setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); 1381 1383 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1382 1384 setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding); 1385 setGUIBoolean("regicideEarlyAttack", "regicideEarlyAttackText", !!mapSettings.RegicideEarlyAttack); 1383 1386 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1384 1387 1385 1388 Engine.GetGUIObjectByName("optionWonderDuration").hidden = 1386 1389 g_GameAttributes.settings.GameType && 1387 1390 g_GameAttributes.settings.GameType != "wonder"; 1388 1391 Engine.GetGUIObjectByName("optionLastManStanding").hidden = mapSettings.LockTeams; 1392 Engine.GetGUIObjectByName("optionRegicideEarlyAttack").hidden = 1393 g_GameAttributes.settings.GameType && 1394 g_GameAttributes.settings.GameType != "regicide"; 1389 1395 1390 1396 Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; 1391 1397 1392 1398 Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; 1393 1399 Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; … … function updateGUIObjects() 1401 1407 1402 1408 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1403 1409 1404 1410 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1405 1411 "startingResources", "ceasefire", "revealMap", 1406 "exploreMap", "disableTreasures", "lockTeams", "lastManStanding"]) 1412 "exploreMap", "disableTreasures", "lockTeams", 1413 "lastManStanding", "regicideEarlyAttack"]) 1407 1414 hideControl(ctrl, ctrl + "Text", notScenario); 1408 1415 1409 1416 Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario; 1410 1417 Engine.GetGUIObjectByName("teamResetButton").hidden = !notScenario; 1411 1418 -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
333 333 <object name="wonderDuration" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 334 334 <translatableAttribute id="tooltip">Number of minutes that the player has to keep the wonder in order to win.</translatableAttribute> 335 335 </object> 336 336 </object> 337 337 338 <object name="optionPopulationCap" size="14 98 94% 126"> 338 <object name="optionRegicideEarlyAttack" size="14 98 94% 126"> 339 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 340 <translatableAttribute id="caption">Early Hero Attack:</translatableAttribute> 341 </object> 342 <object name="regicideEarlyAttackText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 343 <object name="regicideEarlyAttack" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 344 <translatableAttribute id="tooltip">Toggle whether heroes can attack from the start of the game, or from City Phase.</translatableAttribute> 345 </object> 346 </object> 347 348 <object name="optionPopulationCap" size="14 128 94% 156"> 339 349 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 340 350 <translatableAttribute id="caption">Population Cap:</translatableAttribute> 341 351 </object> 342 352 <object name="populationCapText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> 343 353 <object name="populationCap" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 344 354 <translatableAttribute id="tooltip">Select population cap.</translatableAttribute> 345 355 </object> 346 356 </object> 347 357 348 <object name="optionStartingResources" size="14 1 28 94% 156">358 <object name="optionStartingResources" size="14 158 94% 186"> 349 359 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 350 360 <translatableAttribute id="caption">Starting Resources:</translatableAttribute> 351 361 </object> 352 362 <object name="startingResourcesText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> 353 363 <object name="startingResources" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 354 364 <translatableAttribute id="tooltip">Select the game's starting resources.</translatableAttribute> 355 365 </object> 356 366 </object> 357 367 358 <object name="optionCeasefire" size="14 1 58 94% 186">368 <object name="optionCeasefire" size="14 188 94% 216"> 359 369 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 360 370 <translatableAttribute id="caption">Ceasefire:</translatableAttribute> 361 371 </object> 362 372 <object name="ceasefireText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> 363 373 <object name="ceasefire" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> … … 438 448 <!-- Hide More Options Button --> 439 449 <object 440 450 name="hideMoreOptions" 441 451 type="button" 442 452 style="StoneButton" 443 size="50%-70 4 28 50%+70 456"453 size="50%-70 458 50%+70 486" 444 454 tooltip_style="onscreenToolTip" 445 455 hotkey="cancel" 446 456 > 447 457 <translatableAttribute id="caption">OK</translatableAttribute> 448 458 <translatableAttribute id="tooltip">Close more game options window</translatableAttribute> -
binaries/data/mods/public/gui/session/selection_panels.js
g_SelectionPanels.Training = { 990 990 tooltips.push( 991 991 "[color=\"" + g_HotkeyColor + "\"]" + 992 992 formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch) + 993 993 "[/color]"); 994 994 995 let productionQueueEnabled = Engine.GuiInterfaceCall("GetProductionQueueEnabled", { 996 "player": data.unitEntState.player, 997 "ents": data.selection 998 }); 999 1000 if (!productionQueueEnabled) 1001 tooltips.push(sprintf(translate("The Production Queue is disabled for this entity"))); 1002 995 1003 if (!technologyEnabled) 996 1004 tooltips.push(sprintf(translate("Requires %(technology)s"), { 997 1005 "technology": getEntityNames(GetTechnologyData(template.requiredTechnology)) 998 1006 })); 999 1007 … … g_SelectionPanels.Training = { 1001 1009 tooltips.push(getNeededResourcesTooltip(neededResources)); 1002 1010 1003 1011 data.button.tooltip = tooltips.filter(tip => tip).join("\n"); 1004 1012 1005 1013 let modifier = ""; 1006 if (!technologyEnabled || limits.canBeAddedCount == 0 )1014 if (!technologyEnabled || limits.canBeAddedCount == 0 || !productionQueueEnabled) 1007 1015 { 1008 1016 data.button.enabled = false; 1009 1017 modifier = "color:0 0 0 127:grayscale:"; 1010 1018 } 1011 1019 else if (neededResources) -
binaries/data/mods/public/maps/scripts/Regicide.js
Trigger.prototype.InitRegicideGame = fun 47 47 return 0; 48 48 }; 49 49 50 50 // Attempt to spawn one hero per player 51 51 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 52 let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 53 this.regicideEarlyAttack = cmpEndGameManager.GetGameTypeSettings().regicideEarlyAttack; 54 52 55 for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) 53 56 { 54 57 let spawnPoints = cmpRangeManager.GetEntitiesByPlayer(playerID).sort((entity1, entity2) => 55 58 getSpawnPreference(entity2) - getSpawnPreference(entity1)); 56 59 57 60 this.regicideHeroes[playerID] = this.SpawnRegicideHero(playerID, heroTemplates[playersCivs[playerID]], spawnPoints); 61 62 if (!this.regicideEarlyAttack) 63 this.SetRegicideEarlyAttack(this.regicideHeroes[playerID], false); 58 64 } 59 65 }; 60 66 61 67 /** 62 68 * Spawn a random hero at one of the given locations (which are checked in order). … … Trigger.prototype.SpawnRegicideHero = fu 100 106 101 107 error("Couldn't spawn hero for player " + playerID); 102 108 return undefined; 103 109 }; 104 110 111 Trigger.prototype.CheckRegicideCityPhase = function(data) 112 { 113 if (data.tech.indexOf("phase_city") == -1 || this.regicideEarlyAttack) 114 return; 115 116 this.SetRegicideEarlyAttack(this.regicideHeroes[data.player], true); 117 }; 118 119 Trigger.prototype.SetRegicideEarlyAttack(hero, enabled) 120 { 121 let cmpAttack = Engine.QueryInterface(heor, IID_Attack); 122 if (cmpAttack) 123 cmpAttack.SetEnabled(enabled); 124 125 let cmpAuras = Engine.QueryInterface(hero, IID_Auras); 126 if (cmpAuras) 127 cmpAuras.SetEnabled(enabled); 128 129 let cmpProductionQueue = Engine.QueryInterface(hero, IID_ProductionQueue); 130 if (cmpProductionQueue) 131 cmpProductionQueue.SetEnabled(enabled); 132 }; 133 105 134 let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 106 135 cmpTrigger.regicideHeroes = []; 136 cmpTrigger.regicideEarlyAttack = false; 107 137 cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {}); 108 138 cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true }); 139 cmpTrigger.RegisterTrigger("OnResearchFinished", "CheckRegicideCityPhase", { "enabled": true }); -
binaries/data/mods/public/simulation/components/Attack.js
Attack.prototype.Schema = 200 200 "</element>" + 201 201 "</optional>"; 202 202 203 203 Attack.prototype.Init = function() 204 204 { 205 this.enabled = true; 205 206 }; 206 207 207 208 Attack.prototype.Serialize = null; // we have no dynamic state to save 208 209 210 Attack.prototype.GetEnabled = function() 211 { 212 return this.enabled; 213 }; 214 215 Attack.prototype.SetEnabled = function(enabled) 216 { 217 this.enabled = enabled; 218 }; 219 209 220 Attack.prototype.GetAttackTypes = function() 210 221 { 211 222 return ["Melee", "Ranged", "Capture"].filter(type => !!this.template[type]); 212 223 }; 213 224 … … Attack.prototype.GetRestrictedClasses = 229 240 return []; 230 241 }; 231 242 232 243 Attack.prototype.CanAttack = function(target) 233 244 { 245 if (!this.enabled) 246 return false; 247 234 248 let cmpFormation = Engine.QueryInterface(target, IID_Formation); 235 249 if (cmpFormation) 236 250 return true; 237 251 238 252 let cmpThisPosition = Engine.QueryInterface(this.entity, IID_Position); … … Attack.prototype.GetBestAttackAgainst = 339 353 // check if the target is capturable 340 354 let captureIndex = types.indexOf("Capture"); 341 355 if (captureIndex != -1) 342 356 { 343 357 let cmpCapturable = QueryMiragedInterface(target, IID_Capturable); 344 345 358 let cmpPlayer = QueryOwnerInterface(this.entity); 359 346 360 if (allowCapture && cmpPlayer && cmpCapturable && cmpCapturable.CanCapture(cmpPlayer.GetPlayerID())) 347 361 return "Capture"; 362 348 363 // not captureable, so remove this attack 349 364 types.splice(captureIndex, 1); 350 365 } 351 366 352 367 let isPreferred = className => attack.GetPreferredClasses(className).some(isTargetClass); -
binaries/data/mods/public/simulation/components/Auras.js
Auras.prototype.Schema = 6 6 "</attribute>" + 7 7 "<text a:help='A whitespace-separated list of aura files, placed under simulation/data/auras/'/>"; 8 8 9 9 Auras.prototype.Init = function() 10 10 { 11 this.enabled = true; 11 12 let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); 12 13 this.auras = {}; 13 14 this.affectedPlayers = {}; 14 15 let auraNames = this.GetAuraNames(); 15 16 for (let name of auraNames) … … Auras.prototype.Init = function() 20 21 // In case of autogarrisoning, this component can be called before ownership is set. 21 22 // So it needs to be completely initialised from the start. 22 23 this.Clean(); 23 24 }; 24 25 26 Auras.prototype.GetEnabled = function() 27 { 28 return this.enabled; 29 }; 30 31 Auras.prototype.SetEnabled = function(enabled) 32 { 33 this.enabled = enabled; 34 this.Clean(); 35 }; 36 25 37 // We can modify identifier if we want stackable auras in some case. 26 38 Auras.prototype.GetModifierIdentifier = function(name) 27 39 { 28 40 if (this.auras[name].stackable) 29 41 return name + this.entity; … … Auras.prototype.CalculateAffectedPlayers 107 119 } 108 120 }; 109 121 110 122 Auras.prototype.CanApply = function(name) 111 123 { 124 if (!this.enabled) 125 return false; 112 126 if (!this.auras[name].requiredTechnology) 113 127 return true; 114 128 let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); 115 129 if (!cmpTechnologyManager) 116 130 return false; -
binaries/data/mods/public/simulation/components/Formation.js
Formation.prototype.SetMembers = functio 302 302 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 303 303 cmpUnitAI.SetFormationController(this.entity); 304 304 cmpUnitAI.SetLastFormationTemplate(templateName); 305 305 306 306 var cmpAuras = Engine.QueryInterface(ent, IID_Auras); 307 if (cmpAuras && cmpAuras.HasFormationAura() )307 if (cmpAuras && cmpAuras.HasFormationAura() && cmpAuras.GetEnabled()) 308 308 { 309 309 this.formationMembersWithAura.push(ent); 310 310 cmpAuras.ApplyFormationBonus(ents); 311 311 } 312 312 } … … Formation.prototype.AddMembers = functio 385 385 { 386 386 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 387 387 cmpUnitAI.SetFormationController(this.entity); 388 388 389 389 var cmpAuras = Engine.QueryInterface(ent, IID_Auras); 390 if (cmpAuras && cmpAuras.HasFormationAura() )390 if (cmpAuras && cmpAuras.HasFormationAura() && cmpAuras.GetEnabled()) 391 391 { 392 392 this.formationMembersWithAura.push(ent); 393 393 cmpAuras.ApplyFormationBonus(ents); 394 394 } 395 395 } -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
GarrisonHolder.prototype.PerformGarrison 273 273 var cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); 274 274 if (cmpProductionQueue) 275 275 cmpProductionQueue.PauseProduction(); 276 276 277 277 var cmpAura = Engine.QueryInterface(entity, IID_Auras); 278 if (cmpAura && cmpAura.HasGarrisonAura() )278 if (cmpAura && cmpAura.HasGarrisonAura() && cmpAura.GetEnabled()) 279 279 cmpAura.ApplyGarrisonBonus(this.entity); 280 280 281 281 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [entity], "removed": [] }); 282 282 283 283 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); … … GarrisonHolder.prototype.Eject = functio 346 346 var cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); 347 347 if (cmpProductionQueue) 348 348 cmpProductionQueue.UnpauseProduction(); 349 349 350 350 var cmpAura = Engine.QueryInterface(entity, IID_Auras); 351 if (cmpAura && cmpAura.HasGarrisonAura() )351 if (cmpAura && cmpAura.HasGarrisonAura() && cmpAura.GetEnabled()) 352 352 cmpAura.RemoveGarrisonBonus(this.entity); 353 353 354 354 355 355 cmpNewPosition.JumpTo(pos.x, pos.z); 356 356 cmpNewPosition.SetHeightOffset(0); -
binaries/data/mods/public/simulation/components/GuiInterface.js
GuiInterface.prototype.GetTimeNotificati 755 755 let time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime(); 756 756 // filter on players and time, since the delete timer might be executed with a delay 757 757 return this.timeNotifications.filter(n => n.players.indexOf(player) != -1 && n.endTime > time); 758 758 }; 759 759 760 GuiInterface.prototype.GetProductionQueueEnabled = function(player, data) 761 { 762 for (let ent of data.ents) 763 { 764 let cmpProductionQueue = Engine.QueryInterface(ent, IID_ProductionQueue); 765 if (!cmpProductionQueue) 766 continue; 767 else 768 return cmpProductionQueue.GetEnabled(); 769 } 770 return false; 771 }; 772 760 773 GuiInterface.prototype.PushNotification = function(notification) 761 774 { 762 775 if (!notification.type || notification.type == "text") 763 776 this.AddTimeNotification(notification); 764 777 else … … let exposedFunctions = { 1959 1972 "GetBattleState": 1, 1960 1973 "GetIncomingAttacks": 1, 1961 1974 "GetNeededResources": 1, 1962 1975 "GetNotifications": 1, 1963 1976 "GetTimeNotifications": 1, 1977 "GetProductionQueueEnabled": 1, 1964 1978 1965 1979 "GetAvailableFormations": 1, 1966 1980 "GetFormationRequirements": 1, 1967 1981 "CanMoveEntsIntoFormation": 1, 1968 1982 "IsFormationSelected": 1, -
binaries/data/mods/public/simulation/components/ProductionQueue.js
ProductionQueue.prototype.Schema = 40 40 "</interleave>" + 41 41 "</element>"; 42 42 43 43 ProductionQueue.prototype.Init = function() 44 44 { 45 this.enabled = true; 45 46 this.nextID = 1; 46 47 47 48 this.queue = []; 48 49 // Queue items are: 49 50 // { … … ProductionQueue.prototype.Init = functio 76 77 this.spawnNotified = false; 77 78 78 79 this.alertRaiser = undefined; 79 80 }; 80 81 82 ProductionQueue.prototype.GetEnabled = function() 83 { 84 return this.enabled; 85 }; 86 87 ProductionQueue.prototype.SetEnabled = function(enabled) 88 { 89 this.enabled = enabled; 90 }; 91 81 92 ProductionQueue.prototype.PutUnderAlert = function(raiser) 82 93 { 83 94 this.alertRaiser = raiser; 84 95 }; 85 96 … … ProductionQueue.prototype.IsTechnologyRe 258 269 ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadata) 259 270 { 260 271 // TODO: there should probably be a limit on the number of queued batches 261 272 // TODO: there should be a way for the GUI to determine whether it's going 262 273 // to be possible to add a batch (based on resource costs and length limits) 274 if (!this.enabled) 275 return; 263 276 var cmpPlayer = QueryOwnerInterface(this.entity); 264 277 265 278 if (this.queue.length < MAX_QUEUE_SIZE) 266 279 { 267 280 … … ProductionQueue.prototype.SpawnUnits = f 656 669 "entities": createdEnts, 657 670 "owner": cmpOwnership.GetOwner(), 658 671 "metadata": metadata, 659 672 }); 660 673 661 if (this.alertRaiser && spawnedEnts.length > 0)674 if (this.alertRaiser && spawnedEnts.length > 0) 662 675 { 663 676 var cmpAlertRaiser = Engine.QueryInterface(this.alertRaiser, IID_AlertRaiser); 664 if (cmpAlertRaiser)677 if (cmpAlertRaiser) 665 678 cmpAlertRaiser.UpdateUnits(spawnedEnts); 666 679 } 667 680 } 668 681 669 682 return createdEnts.length; -
binaries/data/mods/public/simulation/components/tests/test_Attack.js
1 Engine.LoadHelperScript("Player.js"); 2 Engine.LoadHelperScript("ValueModification.js"); 3 Engine.LoadComponentScript("interfaces/Auras.js"); 4 Engine.LoadComponentScript("interfaces/AuraManager.js"); 5 Engine.LoadComponentScript("interfaces/Capturable.js"); 6 Engine.LoadComponentScript("interfaces/TechnologyManager.js"); 7 Engine.LoadComponentScript("interfaces/Formation.js"); 8 Engine.LoadComponentScript("Formation.js"); 9 Engine.LoadComponentScript("interfaces/Attack.js"); 10 Engine.LoadComponentScript("Attack.js"); 11 12 function TS_ASSERT_EQUAL_OBJECTS(obj1, obj2) 13 { 14 TS_ASSERT_EQUALS(typeof obj1, typeof obj2); 15 16 if (typeof obj1 == "object") 17 { 18 TS_ASSERT_EQUALS(Object.keys(obj1).toString(), Object.keys(obj2).toString()); 19 20 for (let prop in obj1) 21 TS_ASSERT_EQUAL_OBJECTS(obj1[prop], obj2[prop]); 22 } 23 else 24 TS_ASSERT_EQUALS(obj1, obj2); 25 } 26 27 // Initialize player 28 { 29 let playerEnt1 = 5; 30 31 AddMock(SYSTEM_ENTITY, IID_PlayerManager, { 32 "GetPlayerByID": () => playerEnt1 33 }); 34 35 AddMock(playerEnt1, IID_Player, { 36 "GetPlayerID": () => 1 37 }); 38 } 39 40 // Create attacker 41 let entityID = 903; 42 let attacker = ++entityID; 43 44 AddMock(attacker, IID_Position, { 45 "IsInWorld": () => true, 46 "GetHeightOffset": () => 5 47 }); 48 49 AddMock(attacker, IID_Ownership, { 50 "GetOwner": owner => 1 51 }); 52 53 let cmpAttack = ConstructComponent(attacker, "Attack", { 54 "Melee" : { 55 "Hack": 11, 56 "Pierce": 5, 57 "Crush": 0, 58 "MinRange": 3, 59 "MaxRange": 5, 60 "PreferredClasses": { 61 "_string": "Female" 62 }, 63 "RestrictedClasses": { 64 "_string": "Elephant Archer" 65 } 66 }, 67 "Ranged" : { 68 "Hack": 0, 69 "Pierce": 10, 70 "Crush": 0, 71 "MinRange": 10, 72 "MaxRange": 80, 73 "PrepareTime": 300, 74 "RepeatTime": 500, 75 "PreferredClasses": { 76 "_string": "Archer" 77 }, 78 "RestrictedClasses": { 79 "_string": "Elephant" 80 } 81 }, 82 "Capture" : { 83 "Value": 8, 84 "MaxRange": 10, 85 }, 86 "Slaughter": {} 87 }); 88 89 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetAttackTypes(), ["Melee", "Ranged", "Capture"]); 90 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetPreferredClasses("Melee"), ["Female"]); 91 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetRestrictedClasses("Melee"), ["Elephant", "Archer"]); 92 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetFullAttackRange(), { "min": 0, "max": 80 }); 93 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetAttackStrengths("Capture"), { "value": 8 }); 94 95 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetAttackStrengths("Ranged"), { 96 "hack": 0, 97 "pierce": 10, 98 "crush": 0, 99 }); 100 101 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetTimers("Ranged"), { 102 "prepare": 300, 103 "repeat": 500, 104 "recharge": 200 105 }); 106 107 TS_ASSERT_EQUAL_OBJECTS(cmpAttack.GetTimers("Capture"), { 108 "prepare": 0, 109 "repeat": 1000, 110 "recharge": 1000 111 }); 112 113 // Create elephant to ensure CanAttack takes restricted classes into account and rejects 114 { 115 let innocentElephant = ++entityID; 116 117 AddMock(innocentElephant, IID_Identity, { 118 "GetClassesList": () => ["Elephant"] 119 }); 120 121 AddMock(innocentElephant, IID_Position, { 122 "IsInWorld": () => true, 123 "GetHeightOffset": () => 8 124 }); 125 126 TS_ASSERT_EQUALS(cmpAttack.CanAttack(innocentElephant), false); 127 128 cmpAttack.SetEnabled(true); 129 TS_ASSERT_EQUALS(cmpAttack.CanAttack(innocentElephant), false); 130 } 131 132 // Create woman to test SetEnabled, GetEnabled, CanAttack and GetBestAttackAgainst 133 { 134 let helplessWoman = ++entityID; 135 136 AddMock(helplessWoman, IID_Identity, { 137 "GetClassesList": () => ["Female"] 138 }); 139 140 AddMock(helplessWoman, IID_Position, { 141 "IsInWorld": () => true, 142 "GetHeightOffset": () => 2 143 }); 144 145 TS_ASSERT_EQUALS(cmpAttack.GetEnabled(helplessWoman), true); 146 TS_ASSERT_EQUALS(cmpAttack.CanAttack(helplessWoman), true); 147 TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(helplessWoman), "Melee"); 148 149 for (let value of [true, false, true]) 150 { 151 cmpAttack.SetEnabled(value); 152 TS_ASSERT_EQUALS(cmpAttack.GetEnabled(helplessWoman), value); 153 TS_ASSERT_EQUALS(cmpAttack.CanAttack(helplessWoman), value); 154 } 155 } 156 157 // Create archer to test CanAttack and GetBestAttackAgainst 158 { 159 let archer = ++entityID; 160 161 AddMock(archer, IID_Identity, { 162 "GetClassesList": () => ["Archer"] 163 }); 164 165 AddMock(archer, IID_Position, { 166 "IsInWorld": () => true, 167 "GetHeightOffset": () => 4 168 }); 169 170 TS_ASSERT_EQUALS(cmpAttack.CanAttack(archer), true); 171 TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(archer), "Ranged"); 172 } 173 174 // Create building to test CanAttack and GetBestAttackAgainst with capturing 175 { 176 let darkFortress = ++entityID; 177 178 AddMock(darkFortress, IID_Identity, { 179 "GetClassesList": () => ["Structure"] 180 }); 181 182 AddMock(darkFortress, IID_Position, { 183 "IsInWorld": () => true, 184 "GetHeightOffset": () => 4 185 }); 186 187 AddMock(darkFortress, IID_Capturable, { 188 "CanCapture": playerID => { 189 TS_ASSERT_EQUALS(playerID, 1); 190 return true; 191 } 192 }); 193 194 TS_ASSERT_EQUALS(cmpAttack.CanAttack(darkFortress), true); 195 TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(darkFortress, true), "Capture"); 196 } 197 198 // Slaughter sheep 199 { 200 let sheep = ++entityID; 201 202 AddMock(sheep, IID_Identity, { 203 "GetClassesList": () => ["Domestic"] 204 }); 205 206 AddMock(sheep, IID_Position, { 207 "IsInWorld": () => true, 208 "GetHeightOffset": () => 2 209 }); 210 211 TS_ASSERT_EQUALS(cmpAttack.CanAttack(sheep), true); 212 TS_ASSERT_EQUALS(cmpAttack.GetBestAttackAgainst(sheep, true), "Slaughter"); 213 } -
binaries/data/mods/public/simulation/components/tests/test_Auras.js
Property changes on: binaries/data/mods/public/simulation/components/tests/test_Attack.js ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
AddMock(SYSTEM_ENTITY, IID_RangeManager, 21 21 }, 22 22 EnableActiveQuery: function(id) { }, 23 23 ResetActiveQuery: function(id) { if (mode == 0) return []; else return [enemy]; }, 24 24 DisableActiveQuery: function(id) { }, 25 25 GetEntityFlagMask: function(identifier) { }, 26 "DestroyActiveQuery": () => {} 26 27 }); 27 28 28 29 AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, { 29 30 GetAuraTemplate: function(name) { 30 31 if (name == "test1") … … var auras = ConstructComponent(auraEnt, 71 72 72 73 // send the rangeManager message 73 74 auras.OnRangeUpdate({"tag": 1, "added": [30], "removed": []}); 74 75 75 76 TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 2); 77 TS_ASSERT_EQUALS(auras.GetEnabled(), true); 78 79 auras.SetEnabled(false) 80 TS_ASSERT_EQUALS(auras.GetEnabled(), false); 81 82 auras.SetEnabled(true) 83 TS_ASSERT_EQUALS(auras.GetEnabled(), true); -
binaries/data/mods/public/simulation/components/tests/test_GarrisonHolder.js
1 Engine.LoadHelperScript("Player.js"); 2 Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); 3 Engine.LoadComponentScript("interfaces/Health.js"); 4 Engine.LoadComponentScript("GarrisonHolder.js"); 5 Engine.LoadComponentScript("Identity.js"); 6 7 let garrisonEnt = 15; 8 let unitEnt = 33; 9 let entHP = 1000; 10 11 AddMock(garrisonEnt, IID_Health, { 12 "GetHitpoints": () => entHP, 13 "Decrease": hp => { 14 entHP = Math.max(entHP - hp, 0); 15 }, 16 }); 17 18 let cmpGarrisonHolder = ConstructComponent(garrisonEnt, "GarrisonHolder", { 19 "LoadingRange": "2.0", 20 "Max": "20", 21 "List": "Support" 22 }); 23 24 TS_ASSERT_EQUALS(cmpGarrisonHolder.GetGarrisonedEntitiesCount(), 0); 25 TS_ASSERT_EQUALS(cmpGarrisonHolder.entities.length, 0); 26 TS_ASSERT_EQUALS(cmpGarrisonHolder.visibleGarrisonPoints.length, 0); 27 TS_ASSERT_EQUALS(+cmpGarrisonHolder.template.Max, 20); 28 TS_ASSERT_EQUALS(cmpGarrisonHolder.GetLoadingRange().max, 2.0); -
binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Property changes on: binaries/data/mods/public/simulation/components/tests/test_GarrisonHolder.js ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 Engine.LoadHelperScript("Player.js"); 2 Engine.LoadHelperScript("ValueModification.js"); 3 Engine.LoadComponentScript("interfaces/ProductionQueue.js"); 4 Engine.LoadComponentScript("interfaces/TechnologyManager.js"); 5 Engine.LoadComponentScript("interfaces/Player.js"); 6 Engine.LoadComponentScript("ProductionQueue.js"); 7 Engine.LoadComponentScript("TechnologyManager.js"); 8 Engine.LoadComponentScript("Player.js"); 9 10 let playerEntity = 1; 11 let productionEnt = 31; 12 let trainTemplate = "units/athen_infantry_spearman_b"; 13 14 AddMock(SYSTEM_ENTITY, IID_PlayerManager, { 15 "GetPlayerByID": id => playerEntity, 16 "GetCheatTimeMultiplier": () => 20, 17 }); 18 19 AddMock(SYSTEM_ENTITY, IID_TemplateManager, { 20 "GetTemplate": trainTemplate => trainTemplate, 21 }); 22 23 let cmpProductionQueue = ConstructComponent(productionEnt, "ProductionQueue", { 24 "BatchTimeModifier": "0.7", 25 "Entities": "units/athen_infantry_spearman_b" 26 }); 27 28 TS_ASSERT_EQUALS(cmpProductionQueue.GetEnabled(), true); 29 30 cmpProductionQueue.SetEnabled(false); 31 TS_ASSERT_EQUALS(cmpProductionQueue.GetEnabled(), false); 32 33 cmpProductionQueue.SetEnabled(true); 34 TS_ASSERT_EQUALS(cmpProductionQueue.GetEnabled(), true); 35 36 cmpProductionQueue.PutUnderAlert(productionEnt); 37 TS_ASSERT_EQUALS(cmpProductionQueue.alertRaiser, productionEnt); 38 39 cmpProductionQueue.ResetAlert(); 40 TS_ASSERT_EQUALS(cmpProductionQueue.alertRaiser, undefined); 41 TS_ASSERT_EQUALS(cmpProductionQueue.GetQueue().length, 0);