Ticket #3102: t3102_survival_2.diff
File t3102_survival_2.diff, 11.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js
1 var treasures = 2 [ 1 /* 2 * This is the Script containing all the Triggers for the "Survival of the Fittest" Map. 3 */ 4 5 var treasures = [ 3 6 "gaia/special_treasure_food_barrel", 4 7 "gaia/special_treasure_food_bin", 5 8 "gaia/special_treasure_food_crate", … … 10 13 "gaia/special_treasure_wood", 11 14 "gaia/special_treasure_wood" 12 15 ]; 13 var attackerEntityTemplates = 14 [ 16 17 var resourceLoopCount = 0; 18 19 var resourceLoopTime = 1.25; // Time in minutes when resources are distributed periodically without random offset. 20 var resourceLoopOffset = 14 + 2 * Math.random(); // Time in minutes after which resources are distributed periodically. 21 22 // These are the templates of the attacking units, sorted by civ 23 var attackerEntityTemplates = [ 15 24 [ 16 25 "units/athen_champion_infantry", 17 26 "units/athen_champion_marine", 18 27 "units/athen_champion_ranged", 19 "units/athen_ siege_lithobolos_packed",20 "units/athen_ siege_oxybeles_packed",28 "units/athen_mechanical_siege_lithobolos_packed", 29 "units/athen_mechanical_siege_oxybeles_packed" 21 30 ], 22 31 [ 23 32 "units/brit_champion_cavalry", 24 33 "units/brit_champion_infantry", 25 "units/brit_mechanical_siege_ram" ,34 "units/brit_mechanical_siege_ram" 26 35 ], 27 36 [ 28 37 "units/cart_champion_cavalry", 29 38 "units/cart_champion_elephant", 30 39 "units/cart_champion_infantry", 31 "units/cart_champion_pikeman" ,40 "units/cart_champion_pikeman" 32 41 ], 33 42 [ 34 43 "units/gaul_champion_cavalry", 35 44 "units/gaul_champion_fanatic", 36 45 "units/gaul_champion_infantry", 37 "units/gaul_mechanical_siege_ram" ,46 "units/gaul_mechanical_siege_ram" 38 47 ], 39 48 [ 40 49 "units/iber_champion_cavalry", 41 50 "units/iber_champion_infantry", 42 "units/iber_mechanical_siege_ram" ,51 "units/iber_mechanical_siege_ram" 43 52 ], 44 53 [ 45 54 "units/mace_champion_cavalry", … … 46 55 "units/mace_champion_infantry_a", 47 56 "units/mace_champion_infantry_e", 48 57 "units/mace_mechanical_siege_lithobolos_packed", 49 "units/mace_mechanical_siege_oxybeles_packed" ,58 "units/mace_mechanical_siege_oxybeles_packed" 50 59 ], 51 60 [ 52 61 "units/maur_champion_chariot", … … 53 62 "units/maur_champion_elephant", 54 63 "units/maur_champion_infantry", 55 64 "units/maur_champion_maiden", 56 "units/maur_champion_maiden_archer" ,65 "units/maur_champion_maiden_archer" 57 66 ], 58 67 [ 59 68 "units/pers_champion_cavalry", 60 "units/pers_champion_infantry",61 69 "units/pers_champion_elephant", 70 "units/pers_champion_infantry" 71 62 72 ], 63 73 [ 64 74 "units/ptol_champion_cavalry", 65 "units/ptol_champion_elephant" ,75 "units/ptol_champion_elephant" 66 76 ], 67 77 [ 68 78 "units/rome_champion_cavalry", 69 79 "units/rome_champion_infantry", 70 80 "units/rome_mechanical_siege_ballista_packed", 71 "units/rome_mechanical_siege_scorpio_packed" ,81 "units/rome_mechanical_siege_scorpio_packed" 72 82 ], 73 83 [ 74 84 "units/sele_champion_cavalry", … … 75 85 "units/sele_champion_chariot", 76 86 "units/sele_champion_elephant", 77 87 "units/sele_champion_infantry_pikeman", 78 "units/sele_champion_infantry_swordsman" ,88 "units/sele_champion_infantry_swordsman" 79 89 ], 80 90 [ 81 91 "units/spart_champion_infantry_pike", 82 92 "units/spart_champion_infantry_spear", 83 93 "units/spart_champion_infantry_sword", 84 "units/spart_mechanical_siege_ram" ,94 "units/spart_mechanical_siege_ram" 85 95 ], 86 96 ]; 87 97 … … 93 103 let nextTime = Math.round(120000 + Math.random() * 60000); 94 104 let attackerCount = Math.round(cmpTimer.GetTime() / nextTime / attackerEntities.length); 95 105 96 // spawn attackers97 let attackers = 106 // Spawn attackers 107 let attackers = []; 98 108 for (let attackerEntity of attackerEntities) 99 109 attackers.push(TriggerHelper.SpawnUnitsFromTriggerPoints("A", attackerEntity, attackerCount, 0)); 100 110 … … 103 113 for (let origin in entityType) 104 114 { 105 115 let cmpPlayer = QueryOwnerInterface(+origin, IID_Player); 106 if ( cmpPlayer.GetState() != "active")116 if (!cmpPlayer || !cmpTrigger.playerCivicCenter[cmpPlayer.GetPlayerID()]) 107 117 continue; 108 118 109 let cmpPosition = Engine.QueryInterface(this.playerCivicCenter[cmpPlayer.GetPlayerID()], IID_Position);110 // this shouldn't happen if the player is still active119 let cmpPosition = Engine.QueryInterface(cmpTrigger.playerCivicCenter[cmpPlayer.GetPlayerID()], IID_Position); 120 // This shouldn't happen if the player is still active 111 121 if (!cmpPosition || !cmpPosition.IsInWorld) 112 122 continue; 113 123 114 // store the x and z coordinates in the command124 // Store the x and z coordinates in the command 115 125 let cmd = cmpPosition.GetPosition(); 116 126 cmd.type = "attack-walk"; 117 127 cmd.entities = entityType[origin]; 118 128 cmd.queued = true; 119 129 cmd.targetClasses = undefined; 120 // send the attack-walk command130 // Send the attack-walk command 121 131 ProcessCommand(0, cmd); 122 132 } 123 133 } … … 130 140 cmpTrigger.DoAfterDelay(nextTime, "StartAnEnemyWave", {}); // The next wave will come in 3 minutes 131 141 }; 132 142 143 /* 144 * The main init function, called at the start 145 */ 133 146 Trigger.prototype.InitGame = function() 134 147 { 135 148 let numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); 136 // Find all of the civic centers , disable some structures149 // Find all of the civic centers and females, disable some structures, setup activity watch 137 150 for (let i = 1; i < numberOfPlayers; ++i) 138 151 { 152 /*// At first, determine how many players are actually playing (humans) 153 let cmpPlayer = TriggerHelper.GetPlayerComponent(i); 154 warn(cmpPlayer.GetState());*/ 155 156 // Now handle the other stuff 139 157 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 140 158 let playerEntities = cmpRangeManager.GetEntitiesByPlayer(i); // Get all of each player's entities 141 159 142 160 for (let entity of playerEntities) 161 { 143 162 if (TriggerHelper.EntityHasClass(entity, "CivilCentre")) 144 163 cmpTrigger.playerCivicCenter[i] = entity; 164 if (TriggerHelper.EntityHasClass(entity, "Female")) 165 { 166 let cmpDamageReceiver = Engine.QueryInterface(entity, IID_DamageReceiver); 167 cmpDamageReceiver.SetInvulnerability(true); 168 169 let cmpHealth = Engine.QueryInterface(entity, IID_Health); 170 cmpHealth.SetUndeletability(true); 171 } 172 } 145 173 } 146 174 147 175 // Fix alliances … … 183 211 let triggerPoints = cmpTrigger.GetTriggerPoints(point); 184 212 for (let point of triggerPoints) 185 213 { 186 let template = treasures[Math.floor(Math.random() * treasures.length)] 187 TriggerHelper.SpawnUnits(point, template, 1, 0); 214 let template = treasures[Math.floor(Math.random() * treasures.length)]; 215 let cmpPosition = Engine.QueryInterface(point, IID_Position); 216 let ent = Engine.AddEntity(template); 217 218 let cmpEntOwnership = Engine.QueryInterface(ent, IID_Ownership); 219 let cmpEntPosition = Engine.QueryInterface(ent, IID_Position); 220 221 if (cmpEntOwnership) 222 cmpEntOwnership.SetOwner(0); 223 224 let xOffset = RandomInt(0,23); 225 let zOffset = RandomInt(0,23); 226 227 if (Math.random() >= 0.8 ) 228 { 229 xOffset += RandomInt(5,8); 230 zOffset += RandomInt(5,8); 231 } 232 233 if (Math.round(Math.random()) == 1) 234 xOffset = xOffset * -1; 235 236 if (Math.round(Math.random()) == 1) 237 zOffset = zOffset * -1; 238 239 cmpEntPosition.JumpTo(cmpPosition.GetPosition().x + xOffset, cmpPosition.GetPosition().z - zOffset); 188 240 } 189 cmpTrigger.DoAfterDelay(4*60*1000, "PlaceTreasures", {}); //Place more treasures after 4 minutes 241 let time = (3 + Math.random()) * 60 * 1000; // Place more treasures after 3-4 minutes 242 cmpTrigger.DoAfterDelay(time, "PlaceTreasures", {}); 243 244 let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 245 cmpGUIInterface.PushNotification({ 246 "message": markForTranslation("New treasures have been placed!"), 247 "translateMessage": true 248 }); 190 249 }; 191 250 251 /* 252 * This function starts the timer for the waves 253 */ 192 254 Trigger.prototype.InitializeEnemyWaves = function() 193 255 { 194 256 let time = (5 + Math.round(Math.random() * 10)) * 60 * 1000; 195 257 let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 258 cmpGUIInterface.PushNotification({ 259 "message": markForTranslation("Welcome to Survival of the Fittest"), 260 "translateMessage": true 261 }); 262 cmpGUIInterface.PushNotification({ 263 "message": markForTranslation("Collect treasures with your woman to prepare for the enemies."), 264 "translateMessage": true 265 }); 196 266 cmpGUIInterface.AddTimeNotification({ 197 267 "message": markForTranslation("The first wave will start in %(time)s!"), 198 268 "translateMessage": true 199 269 }, time); 270 200 271 cmpTrigger.DoAfterDelay(time, "StartAnEnemyWave", {}); 201 272 }; 202 273 274 /* 275 * DefeatPlayerOnceCCIsDestroyed occurs when a unit dies, and checks for anything to be done in case its a civic center 276 */ 203 277 Trigger.prototype.DefeatPlayerOnceCCIsDestroyed = function(data) 204 278 { 205 279 // Defeat a player that has lost his civic center 206 if (data.entity == cmpTrigger.playerCivicCenter[data.from] )280 if (data.entity == cmpTrigger.playerCivicCenter[data.from] && data.to == -1) 207 281 { 208 282 TriggerHelper.DefeatPlayer(data.from); 209 283 … … 224 298 } 225 299 }; 226 300 301 /* 302 * This function is constantly Looping and provides resources to all players. 303 * It starts after resourceLoopOffset 304 */ 305 Trigger.prototype.ResourceLoop = function(data) 306 { 307 ++resourceLoopCount; 308 309 if (resourceLoopCount == 1) 310 { 311 let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 312 cmpGUIInterface.PushNotification({ 313 "message": markForTranslation("From now on, all players will receive some resources from time to time"), 314 "translateMessage": true 315 }); 316 } 317 318 let numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); 319 for (let i = 1; i < numberOfPlayers; ++i) 320 { 321 let cmpPlayer = QueryPlayerIDInterface(i); 322 cmpPlayer.AddResources({ 323 "wood": 100, 324 "stone": 100, 325 "metal": 100, 326 "food": 100 327 }); 328 } 329 cmpTrigger.DoAfterDelay((resourceLoopTime + Math.random() / 2) * 60 * 1000, "ResourceLoop" , {}); 330 }; 331 227 332 var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 228 333 cmpTrigger.playerCivicCenter = {}; 334 229 335 cmpTrigger.DoAfterDelay(0, "InitGame", {}); 230 336 cmpTrigger.DoAfterDelay(1000, "InitializeEnemyWaves", {}); 337 cmpTrigger.DoAfterDelay(resourceLoopOffset * 60 * 1000, "ResourceLoop" , {}); 231 338 232 339 cmpTrigger.RegisterTrigger("OnOwnershipChanged", "DefeatPlayerOnceCCIsDestroyed", { "enabled": true }); -
binaries/data/mods/public/simulation/components/Health.js
63 63 this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints()); 64 64 this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity); 65 65 this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity); 66 this.undeletable = this.template.Undeletable; 66 67 this.CheckRegenTimer(); 67 68 this.UpdateActor(); 68 69 }; … … 123 124 124 125 Health.prototype.IsUndeletable = function() 125 126 { 126 return this. template.Undeletable == "true";127 return this.undeletable; 127 128 }; 128 129 130 Health.prototype.SetUndeletability = function(undeletability) 131 { 132 this.undeletable = undeletability; 133 }; 134 129 135 Health.prototype.GetIdleRegenRate = function() 130 136 { 131 137 return this.idleRegenRate;