Ticket #3102: t3102_survival_3.diff

File t3102_survival_3.diff, 11.9 KB (added by bb, 3 years ago)

more cleanup

  • binaries/data/mods/public/maps/random/survivalofthefittest.js

     
    198198    );
    199199    createArea(placer, [terrainPainter, elevationPainter, paintClass(clWater)], null);
    200200   
    201     //creating female citizens
     201    // Creating seeker woman, these need to have a lower ID number than other starting woman
    202202    var femaleLocation = getTIPIADBON([ix, iz], [mapSize / 2, mapSize / 2], [-3 , 3.5], 1, 3);
    203203    if (femaleLocation !== undefined)
    204204    {
  • 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
     5var treasures = [
    36    "gaia/special_treasure_food_barrel",
    47    "gaia/special_treasure_food_bin",
    58    "gaia/special_treasure_food_crate",
     
    1013    "gaia/special_treasure_wood",
    1114    "gaia/special_treasure_wood"
    1215];
    13 var attackerEntityTemplates =
    14 [
     16
     17var treasureTime = 3; // Time in minutes when treasures are distributed periodically without random offset.
     18
     19var provideResourcesCount = 0;
     20
     21var provideResourcesTime = 1.25; // Time in minutes when resources are distributed periodically without random offset.
     22var provideResourcesOffset = 14 + 2 * Math.random(); // Time in minutes after which resources are distributed periodically.
     23
     24// These are the templates of the attacking units, sorted by civ
     25var attackerEntityTemplates = [
    1526    [
    1627        "units/athen_champion_infantry",
    1728        "units/athen_champion_marine",
    1829        "units/athen_champion_ranged",
    19         "units/athen_siege_lithobolos_packed",
    20         "units/athen_siege_oxybeles_packed",
     30        "units/athen_mechanical_siege_lithobolos_packed",
     31        "units/athen_mechanical_siege_oxybeles_packed"
    2132    ],
    2233    [
    2334        "units/brit_champion_cavalry",
    2435        "units/brit_champion_infantry",
    25         "units/brit_mechanical_siege_ram",
     36        "units/brit_mechanical_siege_ram"
    2637    ],
    2738    [
    2839        "units/cart_champion_cavalry",
    2940        "units/cart_champion_elephant",
    3041        "units/cart_champion_infantry",
    31         "units/cart_champion_pikeman",
     42        "units/cart_champion_pikeman"
    3243    ],
    3344    [
    3445        "units/gaul_champion_cavalry",
    3546        "units/gaul_champion_fanatic",
    3647        "units/gaul_champion_infantry",
    37         "units/gaul_mechanical_siege_ram",
     48        "units/gaul_mechanical_siege_ram"
    3849    ],
    3950    [
    4051        "units/iber_champion_cavalry",
    4152        "units/iber_champion_infantry",
    42         "units/iber_mechanical_siege_ram",
     53        "units/iber_mechanical_siege_ram"
    4354    ],
    4455    [
    4556        "units/mace_champion_cavalry",
     
    4657        "units/mace_champion_infantry_a",
    4758        "units/mace_champion_infantry_e",
    4859        "units/mace_mechanical_siege_lithobolos_packed",
    49         "units/mace_mechanical_siege_oxybeles_packed",
     60        "units/mace_mechanical_siege_oxybeles_packed"
    5061    ],
    5162    [
    5263        "units/maur_champion_chariot",
     
    5364        "units/maur_champion_elephant",
    5465        "units/maur_champion_infantry",
    5566        "units/maur_champion_maiden",
    56         "units/maur_champion_maiden_archer",
     67        "units/maur_champion_maiden_archer"
    5768    ],
    5869    [
    5970        "units/pers_champion_cavalry",
    60         "units/pers_champion_infantry",
    6171        "units/pers_champion_elephant",
     72        "units/pers_champion_infantry"
    6273    ],
    6374    [
    6475        "units/ptol_champion_cavalry",
    65         "units/ptol_champion_elephant",
     76        "units/ptol_champion_elephant"
    6677    ],
    6778    [
    6879        "units/rome_champion_cavalry",
    6980        "units/rome_champion_infantry",
    7081        "units/rome_mechanical_siege_ballista_packed",
    71         "units/rome_mechanical_siege_scorpio_packed",
     82        "units/rome_mechanical_siege_scorpio_packed"
    7283    ],
    7384    [
    7485        "units/sele_champion_cavalry",
     
    7586        "units/sele_champion_chariot",
    7687        "units/sele_champion_elephant",
    7788        "units/sele_champion_infantry_pikeman",
    78         "units/sele_champion_infantry_swordsman",
     89        "units/sele_champion_infantry_swordsman"
    7990    ],
    8091    [
    8192        "units/spart_champion_infantry_pike",
    8293        "units/spart_champion_infantry_spear",
    8394        "units/spart_champion_infantry_sword",
    84         "units/spart_mechanical_siege_ram",
     95        "units/spart_mechanical_siege_ram"
    8596    ],
    8697];
    8798
     
    93104    let nextTime = Math.round(120000 + Math.random() * 60000);
    94105    let attackerCount = Math.round(cmpTimer.GetTime() / nextTime / attackerEntities.length);
    95106
    96     // spawn attackers
    97     let attackers =  [];
     107    // Spawn attackers
     108    let attackers = [];
    98109    for (let attackerEntity of attackerEntities)
    99110        attackers.push(TriggerHelper.SpawnUnitsFromTriggerPoints("A", attackerEntity, attackerCount, 0));
    100111
     
    103114        for (let origin in entityType)
    104115        {
    105116            let cmpPlayer = QueryOwnerInterface(+origin, IID_Player);
    106             if (cmpPlayer.GetState() != "active")
     117            if (!cmpPlayer || !cmpTrigger.playerCivicCenter[cmpPlayer.GetPlayerID()])
    107118                continue;
    108119
    109             let cmpPosition =  Engine.QueryInterface(this.playerCivicCenter[cmpPlayer.GetPlayerID()], IID_Position);
    110             // this shouldn't happen if the player is still active
     120            let cmpPosition = Engine.QueryInterface(cmpTrigger.playerCivicCenter[cmpPlayer.GetPlayerID()], IID_Position);
     121            // This shouldn't happen if the player is still active
    111122            if (!cmpPosition || !cmpPosition.IsInWorld)
    112123                continue;
    113124
    114             // store the x and z coordinates in the command
     125            // Store the x and z coordinates in the command
    115126            let cmd = cmpPosition.GetPosition();
    116127            cmd.type = "attack-walk";
    117128            cmd.entities = entityType[origin];
    118129            cmd.queued = true;
    119130            cmd.targetClasses = undefined;
    120             // send the attack-walk command
     131            // Send the attack-walk command
    121132            ProcessCommand(0, cmd);
    122133        }
    123134    }
     
    130141    cmpTrigger.DoAfterDelay(nextTime, "StartAnEnemyWave", {}); // The next wave will come in 3 minutes
    131142};
    132143
     144/*
     145 * The main init function, called at the start
     146 */
    133147Trigger.prototype.InitGame = function()
    134148{
    135149    let numberOfPlayers = TriggerHelper.GetNumberOfPlayers();
    136     // Find all of the civic centers, disable some structures
     150    // Find all of the civic centers and females, disable some structures, setup activity watch
    137151    for (let i = 1; i < numberOfPlayers; ++i)
    138152    {
    139153        let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    140154        let playerEntities = cmpRangeManager.GetEntitiesByPlayer(i); // Get all of each player's entities
    141155
     156        let seekersNumber = 1;  // Only 1 seeker woman per player
     157        let seekers = 0;
    142158        for (let entity of playerEntities)
     159        {
    143160            if (TriggerHelper.EntityHasClass(entity, "CivilCentre"))
    144161                cmpTrigger.playerCivicCenter[i] = entity;
     162            if (TriggerHelper.EntityHasClass(entity, "Female") && seekers < seekersNumber)
     163            {
     164                ++seekers;
     165                let cmpDamageReceiver = Engine.QueryInterface(entity, IID_DamageReceiver);
     166                cmpDamageReceiver.SetInvulnerability(true);
     167
     168                let cmpHealth = Engine.QueryInterface(entity, IID_Health);
     169                cmpHealth.SetUndeletability(true);
     170            }
     171        }
    145172    }
    146173
    147174    // Fix alliances
     
    183210    let triggerPoints = cmpTrigger.GetTriggerPoints(point);
    184211    for (let point of triggerPoints)
    185212    {
    186         let template = treasures[Math.floor(Math.random() * treasures.length)]
    187         TriggerHelper.SpawnUnits(point, template, 1, 0);
     213        let template = treasures[Math.floor(Math.random() * treasures.length)];
     214        let cmpPosition = Engine.QueryInterface(point, IID_Position);
     215        let ent = Engine.AddEntity(template);
     216
     217        let cmpEntOwnership = Engine.QueryInterface(ent, IID_Ownership);
     218        let cmpEntPosition = Engine.QueryInterface(ent, IID_Position);
     219
     220        if (cmpEntOwnership)
     221            cmpEntOwnership.SetOwner(0);
     222
     223        let xOffset = RandomInt(0, 23);
     224        let zOffset = RandomInt(0, 23);
     225
     226        if (Math.random() >= 0.8)
     227        {
     228            xOffset += RandomInt(5, 8);
     229            zOffset += RandomInt(5, 8);
     230        }
     231
     232        if (Math.round(Math.random()) == 1)
     233            xOffset = -xOffset;
     234
     235        if (Math.round(Math.random()) == 1)
     236            zOffset = -zOffset;
     237
     238        cmpEntPosition.JumpTo(cmpPosition.GetPosition().x + xOffset, cmpPosition.GetPosition().z - zOffset);
    188239    }
    189     cmpTrigger.DoAfterDelay(4*60*1000, "PlaceTreasures", {}); //Place more treasures after 4 minutes
     240
     241    cmpTrigger.DoAfterDelay((treasureTime + Math.random()) * 60 * 1000, "PlaceTreasures", {});
     242
     243    let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     244    cmpGUIInterface.PushNotification({
     245        "message": markForTranslation("New treasures have been placed!"),
     246        "translateMessage": true
     247    });
    190248};
    191249
    192250Trigger.prototype.InitializeEnemyWaves = function()
     
    193251{
    194252    let time = (5 + Math.round(Math.random() * 10)) * 60 * 1000;
    195253    let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     254    cmpGUIInterface.PushNotification({
     255        "message": markForTranslation("Welcome to Survival of the Fittest"),
     256        "translateMessage": true
     257    });
     258    cmpGUIInterface.PushNotification({
     259        "message": markForTranslation("Collect treasures with your woman to prepare for the enemies."),
     260        "translateMessage": true
     261    });
    196262    cmpGUIInterface.AddTimeNotification({
    197263        "message": markForTranslation("The first wave will start in %(time)s!"),
    198264        "translateMessage": true
    199265    }, time);
     266
    200267    cmpTrigger.DoAfterDelay(time, "StartAnEnemyWave", {});
    201268};
    202269
     
    203270Trigger.prototype.DefeatPlayerOnceCCIsDestroyed = function(data)
    204271{
    205272    // Defeat a player that has lost his civic center
    206     if (data.entity == cmpTrigger.playerCivicCenter[data.from])
     273    if (data.entity == cmpTrigger.playerCivicCenter[data.from] && data.to == -1)
    207274    {
    208275        TriggerHelper.DefeatPlayer(data.from);
    209276
     
    224291    }
    225292};
    226293
     294/*
     295 * This function is constantly looping and provides resources to all players.
     296 * It starts after provideResourcesOffset
     297 */
     298Trigger.prototype.provideResources = function(data)
     299{
     300    ++provideResourcesCount;
     301
     302    if (provideResourcesCount == 1)
     303    {
     304        let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     305        cmpGUIInterface.PushNotification({
     306            "message": markForTranslation("From now on, all players will receive some resources from time to time."),
     307            "translateMessage": true
     308        });
     309    }
     310
     311    let resources = {
     312        "food": 50 + Math.round(Math.random() * 100),
     313        "wood": 50 + Math.round(Math.random() * 100),
     314        "stone": 50 + Math.round(Math.random() * 100),
     315        "metal": 50 + Math.round(Math.random() * 100)
     316    }
     317
     318    let numberOfPlayers = TriggerHelper.GetNumberOfPlayers();
     319    for (let i = 1; i < numberOfPlayers; ++i)
     320    {
     321        let cmpPlayer = QueryPlayerIDInterface(i);
     322        cmpPlayer.AddResources(resources);
     323    }
     324    cmpTrigger.DoAfterDelay((provideResourcesTime + Math.random() / 2) * 60 * 1000, "provideResources" , {});
     325};
     326
    227327var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
    228328cmpTrigger.playerCivicCenter = {};
     329
    229330cmpTrigger.DoAfterDelay(0, "InitGame", {});
    230331cmpTrigger.DoAfterDelay(1000, "InitializeEnemyWaves", {});
     332cmpTrigger.DoAfterDelay(provideResourcesOffset * 60 * 1000, "provideResources" , {});
    231333
    232334cmpTrigger.RegisterTrigger("OnOwnershipChanged", "DefeatPlayerOnceCCIsDestroyed", { "enabled": true });
  • binaries/data/mods/public/simulation/components/Health.js

     
    6363    this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints());
    6464    this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
    6565    this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
     66    this.undeletable = this.template.Undeletable;
    6667    this.CheckRegenTimer();
    6768    this.UpdateActor();
    6869};
     
    123124
    124125Health.prototype.IsUndeletable = function()
    125126{
    126     return this.template.Undeletable == "true";
     127    return this.undeletable;
    127128};
    128129
     130Health.prototype.SetUndeletability = function(undeletability)
     131{
     132    this.undeletable = undeletability;
     133};
     134
    129135Health.prototype.GetIdleRegenRate = function()
    130136{
    131137    return this.idleRegenRate;