This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Ticket #2160: Regicide_v0.3.patch

File Regicide_v0.3.patch, 4.5 KB (added by Sandarac, 8 years ago)

Some fixes after mimo's review. Now checks for Hero class.

  • binaries/data/mods/public/maps/scripts/Regicide.js

     
     1Trigger.prototype.CheckRegicideDefeat = function(data)
     2{
     3    if (data.entity == this.heroes[data.from])
     4        TriggerHelper.DefeatPlayer(data.from);
     5};
     6
     7Trigger.prototype.InitRegicideGame = function(msg)
     8{
     9    let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     10    let unitTemplates = cmpTemplateManager.FindAllTemplates(false).filter(temp => temp.substring(0,6) == "units/");
     11    let heroTemplates = [];
     12
     13    for (let temp of unitTemplates)
     14    {
     15        let tempClasses = GetIdentityClasses(cmpTemplateManager.GetTemplate(temp).Identity);
     16        if (tempClasses.indexOf("Hero") != -1 && tempClasses.indexOf("Elephant") == -1)
     17            heroTemplates.push(temp);
     18    }
     19
     20    for (let i = 1; i < TriggerHelper.GetNumberOfPlayers(); ++i)
     21    {
     22        let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     23        let playerEntities = cmpRangeManager.GetEntitiesByPlayer(i);
     24        let spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "CivilCentre"));
     25
     26        if (!spawnPoints.length)
     27            spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "Structure"));
     28
     29        if (!spawnPoints.length)
     30            spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "Ship"));
     31
     32        if (!spawnPoints.length)
     33            spawnPoints = playerEntities;
     34
     35        let cmpPlayer = QueryPlayerIDInterface(i);
     36        let civHeros = heroTemplates.filter(hero => hero.indexOf(cmpPlayer.GetCiv()) != -1);
     37
     38        this.heroes[i] = TriggerHelper.SpawnUnits(spawnPoints[0], civHeros[Math.floor(Math.random() * civHeros.length)], 1, i);
     39
     40        if (!this.heroes[i].length)
     41            error("Couldn't spawn hero for player " + i);
     42
     43        if (TriggerHelper.EntityHasClass(spawnPoints[0], "Ship"))
     44        {
     45            let cmpGarrisonHolder = Engine.QueryInterface(spawnPoints[0], IID_GarrisonHolder);
     46            let cmpUnitAI = Engine.QueryInterface(this.heroes[i], IID_UnitAI);
     47
     48            if (!cmpGarrisonHolder.IsFull())
     49                cmpUnitAI.Garrison(spawnPoints[0]);
     50        }
     51    }
     52};
     53
     54let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     55cmpTrigger.heroes = [];
     56cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {});
     57
     58cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true });
  • binaries/data/mods/public/maps/scripts/TriggerHelper.js

     
    2222};
    2323
    2424/**
    25  * Can be used to "force" a building to spawn a group of entities.
    26  * Only works for buildings that can already train units.
     25 * Can be used to "force" a building/unit to spawn a group of entities.
     26 * A default position is returned if no valid position is found.
    2727 * @param source Entity id of the point where they will be spawned from
    2828 * @param template Name of the template
    2929 * @param count Number of units to spawn
  • binaries/data/mods/public/simulation/data/settings/victory_conditions/regicide.json

     
     1{
     2    "TranslatedKeys": ["Title", "Description"],
     3    "Data":
     4    {
     5        "Title": "Regicide",
     6        "Description": "Keep your Hero alive to win",
     7        "Scripts":
     8        [
     9            "scripts/TriggerHelper.js",
     10            "scripts/ConquestCommon.js",
     11            "scripts/Conquest.js",
     12            "scripts/Regicide.js"
     13        ]
     14    }
     15}
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    148148    gameTypes.Add(_T("conquest_units"));
    149149    gameTypes.Add(_T("wonder"));
    150150    gameTypes.Add(_T("endless"));
     151    gameTypes.Add(_T("regicide"));
    151152
    152153    wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5);
    153154    gridSizer->AddGrowableCol(1);