Ticket #52: Triggers.8.patch

File Triggers.8.patch, 52.4 KB (added by sanderd17, 10 years ago)

Fix simple typos style stuff.

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

     
     1// Contains standardized functions suitable for using in trigger scripts.
     2// Do not use them in any other simulation script.
     3
     4var TriggerHelper = {};
     5
     6TriggerHelper.GetPlayerIDFromEntity = function(ent)
     7{
     8    var cmpPlayer = Engine.QueryInterface(ent, IID_Player);
     9    if (cmpPlayer)
     10        return cmpPlayer.GetPlayerID();
     11    return -1;
     12}
     13
     14TriggerHelper.GetOwner = function(ent)
     15{
     16    var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
     17    if (cmpOwnership)
     18        return cmpOwnership.GetOwner();
     19    return -1;
     20}
     21
     22/**
     23 * Can be used to "force" a building to spawn a group of entities.
     24 * Only works for buildings that can already train units.
     25 * @param source Entity id of the point where they will be spawned from
     26 * @param template Name of the template
     27 * @param count Number of units to spawn
     28 * @param owner Player id of the owner of the new units. By default, the owner
     29 * of the source entity.
     30 */
     31TriggerHelper.SpawnUnits = function(source, template, count, owner)
     32{
     33    var r = []; // array of entities to return;
     34    var cmpFootprint = Engine.QueryInterface(source, IID_Footprint);
     35    var cmpPosition = Engine.QueryInterface(source, IID_Position);
     36    if (!cmpPosition || !cmpPosition.IsInWorld())
     37    {
     38        error("tried to create entity from a source without position");
     39        return r;
     40    }
     41    if (owner == null)
     42        owner = TriggerHelper.GetOwner(source);
     43
     44    for (var i = 0; i < count; i++)
     45    {
     46        var ent = Engine.AddEntity(template);
     47        var cmpEntPosition = Engine.QueryInterface(ent, IID_Position);
     48        if (!cmpEntPosition)
     49        {
     50            error("tried to create entity without position");
     51            continue;
     52        }
     53        var cmpEntOwnership = Engine.QueryInterface(ent, IID_Ownership);
     54        if (cmpEntOwnership)
     55            cmpEntOwnership.SetOwner(owner);
     56        r.push(ent);
     57        var pos;
     58        if (cmpFootprint)
     59            pos = cmpFootprint.PickSpawnPoint(ent);
     60        // TODO this can happen if the player build on the place
     61        // where our trigger point is
     62        // We should probably warn the trigger maker in some way,
     63        // but not interrupt the game for the player
     64        if (!pos || pos.y < 0)
     65            pos = cmpPosition.GetPosition();
     66        cmpEntPosition.JumpTo(pos.x, pos.z);
     67    }
     68    return r;
     69}
     70
     71/**
     72 * Spawn units from all trigger points with this reference
     73 * If player is defined, only spaw units from the trigger points
     74 * that belong to that player
     75 * @param ref Trigger point reference name to spawn units from
     76 * @param template Template name
     77 * @param count Number of spawned entities per Trigger point
     78 * @param owner Owner of the spawned units. Default: the owner of the origins
     79 * @return A list of new entities per origin like
     80 * {originId1: [entId1, entId2], originId2: [entId3, entId4], ...}
     81 */
     82TriggerHelper.SpawnUnitsFromTriggerPoints = function(ref, template, count, owner)         
     83{
     84    var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     85    var triggerPoints = cmpTrigger.GetTriggerPoints(ref);
     86    var r = {};
     87    for (var point of triggerPoints)
     88        r[point] = TriggerHelper.SpawnUnits(point, template, count, owner || null);
     89    return r;
     90}
     91
     92/**
     93 * Returs a function that can be used to filter an array of entities by player
     94 */
     95TriggerHelper.GetPlayerFilter = function(playerID)
     96{
     97    return function(entity) {
     98        var cmpOwnership = Engine.QueryInterface(entity, IID_Ownership);
     99        return cmpOwnership && cmpOwnership.GetOwner() == playerID;
     100    }
     101};
     102
     103/**
     104 * Shows a message in the top center of the screen
     105 */
     106TriggerHelper.PushGUINotification = function(player, message)
     107{
     108    var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     109    cmpGUIInterface.PushNotification({"player": player, "message": message});
     110}
     111
     112/**
     113 * Returns the resource type that can be gathered from an entity
     114 */
     115TriggerHelper.GetResourceType = function(entity)
     116{
     117    var cmpResourceSupply = Engine.QueryInterface(entity, IID_ResourceSupply);
     118    if (!cmpResourceSupply)
     119        return undefined;
     120    return cmpResourceSupply.GetType();
     121}
     122
     123/**
     124 * Wins the game for a player
     125 */
     126TriggerHelper.SetPlayerWon = function(playerID)
     127{
     128    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
     129    cmpEndGameManager.MarkPlayerAsWon(playerID);
     130}
     131
     132/**
     133 * Defeats a player
     134 */
     135TriggerHelper.DefeatPlayer = function(playerID)
     136{
     137    var playerEnt = GetPlayerEntityByID(playerID);
     138    Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": playerID } );
     139}
     140
     141Engine.RegisterGlobal("TriggerHelper", TriggerHelper);
  • binaries/data/mods/public/maps/skirmishes/Gallic

     
     1Trigger.prototype.InitGame = function()
     2{
     3    this.attackSize = 1; // attack with 1 soldier
     4    this.attackTime = 60*1000; // attack in 1 minute
     5    this.DoAfterDelay(this.attackTime, "SpawnAndAttack", {});
     6};
     7
     8Trigger.prototype.SpawnAndAttack = function()
     9{
     10    var rand = Math.random();
     11    // randomize spawn points
     12    var spawnPoint = rand > 0.5 ? "B" : "C";
     13    var intruders = TriggerHelper.SpawnUnitsFromTriggerPoints(spawnPoint, "units/rome_legionnaire_marian", this.attackSize, 4);
     14    for (var origin in intruders)
     15    {
     16        var playerID = TriggerHelper.GetOwner(+origin);
     17        var cmd = null;
     18        warn(uneval(this.GetTriggerPoints("A")));
     19        for (var target of this.GetTriggerPoints("A"))
     20        {
     21            if (TriggerHelper.GetOwner(target) == playerID)
     22            {
     23                var cmpPosition = Engine.QueryInterface(target, IID_Position);
     24                if (!cmpPosition || !cmpPosition.IsInWorld)
     25                    continue;
     26                cmd = cmpPosition.GetPosition();
     27                break;
     28            }
     29        }
     30        if (!cmd)
     31            continue;
     32        cmd.type = "attack-walk";
     33        cmd.entities = intruders[origin];
     34        cmd.queued = true;
     35        ProcessCommand(4, cmd);
     36    }
     37    // enlarge the attack time and size
     38    // multiply with a number between 1 and 3
     39    rand = rand * 2 + 1;
     40    this.attackTime *= rand; //
     41    this.attackSize = Math.round(this.attackSize * rand);
     42    this.DoAfterDelay(this.attackTime, "SpawnAndAttack", {});
     43};
  • binaries/data/mods/public/maps/skirmishes/Gallic

     
    1818                <Type>default</Type>
    1919                <Colour r="0.219608" g="0.247059" b="0.356863"/>
    2020                <Height>21.0885</Height>
    21                 <Shininess>250</Shininess>
    2221                <Waviness>0.830078</Waviness>
    2322                <Murkiness>0.871094</Murkiness>
    2423                <Tint r="0.592157" g="0.639216" b="0.756863"/>
     
    3130            <Contrast>1.03906</Contrast>
    3231            <Saturation>1.05859</Saturation>
    3332            <Bloom>0.1999</Bloom>
    34             <PostEffect>hdr</PostEffect>
     33            <PostEffect>default</PostEffect>
    3534        </Postproc>
    3635    </Environment>
    3736    <Camera>
    38         <Position x="319.998" y="82.8692" z="281.119"/>
     37        <Position x="317.2" y="94.8147" z="272.543"/>
    3938        <Rotation angle="0"/>
    4039        <Declination angle="0.610865"/>
    4140    </Camera>
     
    4241    <ScriptSettings><![CDATA[
    4342{
    4443  "CircularMap": true,
    45   "Description": "Defend your Gallic outpost against attacks from your treacherous neighbors!\u000a\u000aEach player begins the match with a wooden palisade and some guard towers atop a low embankment.",
     44  "Description": "Defend your Gallic outpost against attacks from your treacherous neighbors!\n\nEach player begins the match with a wooden palisade and some guard towers atop a low embankment.",
    4645  "GameType": "conquest",
    4746  "Keywords": [],
    4847  "LockTeams": false,
     
    9291          "z": 0
    9392        }
    9493      }
     94    },
     95    {
     96      "AI": "",
     97      "Civ": "rome",
     98      "Colour": {
     99        "b": 0,
     100        "g": 0,
     101        "r": 0
     102      },
     103      "Name": "Roman Intruders"
    95104    }
    96105  ],
    97106  "Preview": "gallic_fields.png",
    98   "RevealMap": false
     107  "RevealMap": false,
     108  "TriggerScripts": [
     109    "scripts/TriggerHelper.js",
     110    "skirmishes/Gallic Fields (3).js"
     111  ]
    99112}
    100113]]></ScriptSettings>
    101114    <Entities>
     
    102115        <Entity uid="11">
    103116            <Template>other/palisades_rocks_end</Template>
    104117            <Player>1</Player>
    105             <Position x="295.88685" z="356.25528"/>
     118            <Position x="294.88245" z="356.23978"/>
    106119            <Orientation y="0.798"/>
    107120        </Entity>
    108121        <Entity uid="12">
     
    121134        <Entity uid="14">
    122135            <Template>other/palisades_rocks_straight</Template>
    123136            <Player>1</Player>
    124             <Position x="292.38743" z="360.26392"/>
     137            <Position x="291.22764" z="360.21152"/>
    125138            <Orientation y="2.35621"/>
    126139        </Entity>
    127140        <Entity uid="15">
     
    168181        <Entity uid="22">
    169182            <Template>other/palisades_rocks_end</Template>
    170183            <Player>1</Player>
    171             <Position x="303.05506" z="348.4564"/>
     184            <Position x="303.45963" z="346.65308"/>
    172185            <Orientation y="0.78141"/>
    173186        </Entity>
    174187        <Entity uid="23">
    175188            <Template>other/palisades_rocks_straight</Template>
    176189            <Player>1</Player>
    177             <Position x="307.17038" z="344.4105"/>
     190            <Position x="307.9816" z="343.59192"/>
    178191            <Orientation y="-0.85848"/>
    179192            <Obstruction group="25"/>
    180193        </Entity>
     
    11101123        </Entity>
    11111124        <Entity uid="204">
    11121125            <Template>actor|props/special/eyecandy/campfire.xml</Template>
    1113             <Position x="234.88781" z="354.48206"/>
     1126            <Position x="314.00892" z="344.64301"/>
    11141127            <Orientation y="-0.68833"/>
    11151128        </Entity>
    11161129        <Entity uid="207">
     
    11371150        <Entity uid="211">
    11381151            <Template>other/palisades_rocks_straight</Template>
    11391152            <Player>2</Player>
    1140             <Position x="659.87806" z="317.39954"/>
     1153            <Position x="659.07789" z="317.60355"/>
    11411154            <Orientation y="2.35621"/>
    11421155        </Entity>
    11431156        <Entity uid="212">
    11441157            <Template>other/palisades_rocks_straight</Template>
    11451158            <Player>2</Player>
    1146             <Position x="675.45868" z="302.58637"/>
     1159            <Position x="676.4245" z="301.6601"/>
    11471160            <Orientation y="2.35621"/>
    11481161        </Entity>
    11491162        <Entity uid="213">
     
    11551168        <Entity uid="214">
    11561169            <Template>other/palisades_rocks_end</Template>
    11571170            <Player>2</Player>
    1158             <Position x="663.99408" z="312.55082"/>
     1171            <Position x="662.63178" z="313.97724"/>
    11591172            <Orientation y="0.85485"/>
    11601173        </Entity>
    11611174        <Entity uid="215">
    11621175            <Template>other/palisades_rocks_end</Template>
    11631176            <Player>2</Player>
    1164             <Position x="671.18451" z="306.51273"/>
     1177            <Position x="672.49067" z="304.99943"/>
    11651178            <Orientation y="0.98328"/>
    11661179        </Entity>
    11671180        <Entity uid="216">
     
    66516664        <Entity uid="1183">
    66526665            <Template>gaia/geology_metal_temperate_slabs</Template>
    66536666            <Player>0</Player>
    6654             <Position x="465.51719" z="895.96827"/>
     6667            <Position x="465.05253" z="896.6153"/>
    66556668            <Orientation y="-2.38521"/>
    66566669        </Entity>
    66576670        <Entity uid="1186">
     
    66636676        <Entity uid="1187">
    66646677            <Template>gaia/geology_metal_temperate_slabs</Template>
    66656678            <Player>0</Player>
    6666             <Position x="308.97324" z="519.42872"/>
     6679            <Position x="308.34995" z="518.51514"/>
    66676680            <Orientation y="0.52384"/>
    66686681        </Entity>
    66696682        <Entity uid="1188">
     
    67106723        </Entity>
    67116724        <Entity uid="1195">
    67126725            <Template>actor|props/special/eyecandy/campfire.xml</Template>
    6713             <Position x="749.89032" z="252.34638"/>
     6726            <Position x="682.956" z="303.30494"/>
    67146727            <Orientation y="2.35621"/>
    67156728        </Entity>
    67166729        <Entity uid="1196">
    67176730            <Template>actor|props/special/eyecandy/campfire.xml</Template>
    6718             <Position x="552.42939" z="833.2547"/>
     6731            <Position x="521.8979" z="722.24482"/>
    67196732            <Orientation y="2.35621"/>
    67206733        </Entity>
    67216734        <Entity uid="1199">
     
    67796792        <Entity uid="1208">
    67806793            <Template>other/palisades_rocks_end</Template>
    67816794            <Player>3</Player>
    6782             <Position x="510.82416" z="726.23407"/>
     6795            <Position x="511.0652" z="724.964"/>
    67836796            <Orientation y="0.70745"/>
    67846797        </Entity>
    67856798        <Entity uid="1209">
     
    1653316546        <Entity uid="2847">
    1653416547            <Template>other/palisades_angle_spike</Template>
    1653516548            <Player>2</Player>
    16536             <Position x="660.00635" z="309.53974"/>
     16549            <Position x="659.4004" z="310.76008"/>
    1653716550            <Orientation y="-1.15148"/>
    1653816551        </Entity>
    1653916552        <Entity uid="2848">
     
    1737417387            <Position x="753.04261" z="99.05979"/>
    1737517388            <Orientation y="1.04381"/>
    1737617389        </Entity>
    17377         <Entity uid="2999">
    17378             <Template>units/rome_legionnaire_marian</Template>
    17379             <Player>0</Player>
    17380             <Position x="970.68488" z="556.81086"/>
    17381             <Orientation y="3.03232"/>
    17382         </Entity>
    17383         <Entity uid="3000">
    17384             <Template>units/rome_legionnaire_marian</Template>
    17385             <Player>0</Player>
    17386             <Position x="972.51838" z="558.22272"/>
    17387             <Orientation y="2.35621"/>
    17388         </Entity>
    17389         <Entity uid="3001">
    17390             <Template>units/rome_legionnaire_marian</Template>
    17391             <Player>0</Player>
    17392             <Position x="973.98511" z="559.8733"/>
    17393             <Orientation y="2.35621"/>
    17394         </Entity>
    17395         <Entity uid="3002">
    17396             <Template>units/rome_legionnaire_marian</Template>
    17397             <Player>0</Player>
    17398             <Position x="975.47876" z="561.45289"/>
    17399             <Orientation y="2.35621"/>
    17400         </Entity>
    17401         <Entity uid="3003">
    17402             <Template>units/rome_legionnaire_marian</Template>
    17403             <Player>0</Player>
    17404             <Position x="977.06482" z="563.13013"/>
    17405             <Orientation y="2.35621"/>
    17406         </Entity>
    17407         <Entity uid="3004">
    17408             <Template>units/rome_legionnaire_marian</Template>
    17409             <Player>0</Player>
    17410             <Position x="978.44092" z="564.00824"/>
    17411             <Orientation y="2.35621"/>
    17412         </Entity>
    17413         <Entity uid="3005">
    17414             <Template>units/rome_legionnaire_marian</Template>
    17415             <Player>0</Player>
    17416             <Position x="980.35376" z="565.84992"/>
    17417             <Orientation y="2.35621"/>
    17418         </Entity>
    17419         <Entity uid="3006">
    17420             <Template>units/rome_legionnaire_marian</Template>
    17421             <Player>0</Player>
    17422             <Position x="972.39826" z="554.17463"/>
    17423             <Orientation y="2.35621"/>
    17424         </Entity>
    17425         <Entity uid="3007">
    17426             <Template>units/rome_legionnaire_marian</Template>
    17427             <Player>0</Player>
    17428             <Position x="973.7862" z="555.21351"/>
    17429             <Orientation y="2.35621"/>
    17430         </Entity>
    17431         <Entity uid="3008">
    17432             <Template>units/rome_legionnaire_marian</Template>
    17433             <Player>0</Player>
    17434             <Position x="975.35413" z="556.52253"/>
    17435             <Orientation y="2.35621"/>
    17436         </Entity>
    17437         <Entity uid="3009">
    17438             <Template>units/rome_legionnaire_marian</Template>
    17439             <Player>0</Player>
    17440             <Position x="977.14277" z="557.90491"/>
    17441             <Orientation y="2.35621"/>
    17442         </Entity>
    17443         <Entity uid="3010">
    17444             <Template>units/rome_legionnaire_marian</Template>
    17445             <Player>0</Player>
    17446             <Position x="979.14362" z="560.13013"/>
    17447             <Orientation y="2.35621"/>
    17448         </Entity>
    17449         <Entity uid="3011">
    17450             <Template>units/rome_legionnaire_marian</Template>
    17451             <Player>0</Player>
    17452             <Position x="981.0542" z="562.00068"/>
    17453             <Orientation y="2.35621"/>
    17454         </Entity>
    17455         <Entity uid="3012">
    17456             <Template>units/rome_legionnaire_marian</Template>
    17457             <Player>0</Player>
    17458             <Position x="77.18448" z="734.07874"/>
    17459             <Orientation y="2.35621"/>
    17460         </Entity>
    17461         <Entity uid="3013">
    17462             <Template>units/rome_legionnaire_marian</Template>
    17463             <Player>0</Player>
    17464             <Position x="81.05483" z="729.54395"/>
    17465             <Orientation y="2.35621"/>
    17466         </Entity>
    17467         <Entity uid="3014">
    17468             <Template>units/rome_legionnaire_marian</Template>
    17469             <Player>0</Player>
    17470             <Position x="84.24665" z="726.56165"/>
    17471             <Orientation y="2.35621"/>
    17472         </Entity>
    17473         <Entity uid="3015">
    17474             <Template>units/rome_legionnaire_marian</Template>
    17475             <Player>0</Player>
    17476             <Position x="87.00104" z="723.6255"/>
    17477             <Orientation y="2.35621"/>
    17478         </Entity>
    17479         <Entity uid="3016">
    17480             <Template>units/rome_legionnaire_marian</Template>
    17481             <Player>0</Player>
    17482             <Position x="89.71207" z="721.23298"/>
    17483             <Orientation y="2.35621"/>
    17484         </Entity>
    17485         <Entity uid="3017">
    17486             <Template>units/rome_legionnaire_marian</Template>
    17487             <Player>0</Player>
    17488             <Position x="92.41475" z="718.40687"/>
    17489             <Orientation y="2.35621"/>
    17490         </Entity>
    17491         <Entity uid="3018">
    17492             <Template>units/rome_legionnaire_marian</Template>
    17493             <Player>0</Player>
    17494             <Position x="76.13277" z="728.19819"/>
    17495             <Orientation y="2.35621"/>
    17496         </Entity>
    17497         <Entity uid="3019">
    17498             <Template>units/rome_legionnaire_marian</Template>
    17499             <Player>0</Player>
    17500             <Position x="79.16231" z="724.68097"/>
    17501             <Orientation y="2.35621"/>
    17502         </Entity>
    17503         <Entity uid="3020">
    17504             <Template>units/rome_legionnaire_marian</Template>
    17505             <Player>0</Player>
    17506             <Position x="82.15836" z="722.10785"/>
    17507             <Orientation y="2.35621"/>
    17508         </Entity>
    17509         <Entity uid="3021">
    17510             <Template>units/rome_legionnaire_marian</Template>
    17511             <Player>0</Player>
    17512             <Position x="84.53042" z="719.02094"/>
    17513             <Orientation y="2.35621"/>
    17514         </Entity>
    17515         <Entity uid="3022">
    17516             <Template>units/rome_legionnaire_marian</Template>
    17517             <Player>0</Player>
    17518             <Position x="86.45192" z="717.38465"/>
    17519             <Orientation y="2.35621"/>
    17520         </Entity>
    17521         <Entity uid="3023">
    17522             <Template>units/rome_legionnaire_marian</Template>
    17523             <Player>0</Player>
    17524             <Position x="89.43009" z="714.60633"/>
    17525             <Orientation y="2.35621"/>
    17526         </Entity>
    17527         <Entity uid="3024">
    17528             <Template>units/rome_centurio_imperial</Template>
    17529             <Player>0</Player>
    17530             <Position x="92.5489" z="711.15864"/>
    17531             <Orientation y="2.35621"/>
    17532         </Entity>
    1753317390        <Entity uid="3025">
    1753417391            <Template>actor|props/flora/grass_temp_field.xml</Template>
    1753517392            <Position x="141.20521" z="450.51584"/>
     
    2134121198        <Entity uid="3811">
    2134221199            <Template>skirmish/structures/default_civil_centre</Template>
    2134321200            <Player>1</Player>
    21344             <Position x="239.23588" z="381.94343"/>
    21345             <Orientation y="2.35621"/>
     21201            <Position x="315.77839" z="370.3028"/>
     21202            <Orientation y="-2.36886"/>
    2134621203            <Actor seed="16580"/>
    2134721204        </Entity>
    2134821205        <Entity uid="3812">
    2134921206            <Template>skirmish/structures/default_civil_centre</Template>
    2135021207            <Player>3</Player>
    21351             <Position x="527.66474" z="848.21656"/>
    21352             <Orientation y="2.35621"/>
     21208            <Position x="523.39856" z="748.0907"/>
     21209            <Orientation y="-2.34481"/>
    2135321210            <Actor seed="17534"/>
    2135421211        </Entity>
    2135521212        <Entity uid="3816">
    2135621213            <Template>skirmish/structures/default_civil_centre</Template>
    2135721214            <Player>2</Player>
    21358             <Position x="767.4936" z="271.0109"/>
    21359             <Orientation y="2.35621"/>
     21215            <Position x="685.83143" z="328.27808"/>
     21216            <Orientation y="-2.35285"/>
    2136021217            <Actor seed="55570"/>
    2136121218        </Entity>
    2136221219        <Entity uid="3817">
    2136321220            <Template>skirmish/units/default_support_female_citizen</Template>
    2136421221            <Player>1</Player>
    21365             <Position x="316.14179" z="361.27659"/>
    21366             <Orientation y="2.35621"/>
     21222            <Position x="286.50174" z="351.76655"/>
     21223            <Orientation y="-2.43998"/>
    2136721224            <Actor seed="30368"/>
    2136821225        </Entity>
    2136921226        <Entity uid="3818">
    2137021227            <Template>skirmish/units/default_support_female_citizen</Template>
    2137121228            <Player>1</Player>
    21372             <Position x="319.06141" z="362.49521"/>
    21373             <Orientation y="2.35621"/>
     21229            <Position x="288.83237" z="348.57682"/>
     21230            <Orientation y="-2.39516"/>
    2137421231            <Actor seed="60030"/>
    2137521232        </Entity>
    2137621233        <Entity uid="3819">
    2137721234            <Template>skirmish/units/default_support_female_citizen</Template>
    2137821235            <Player>1</Player>
    21379             <Position x="321.54096" z="365.64322"/>
    21380             <Orientation y="2.35621"/>
     21236            <Position x="291.62256" z="345.56531"/>
     21237            <Orientation y="-2.19112"/>
    2138121238            <Actor seed="47546"/>
    2138221239        </Entity>
    2138321240        <Entity uid="3820">
    2138421241            <Template>skirmish/units/default_support_female_citizen</Template>
    2138521242            <Player>1</Player>
    21386             <Position x="323.98121" z="367.75641"/>
    21387             <Orientation y="2.35621"/>
     21243            <Position x="294.58683" z="343.1308"/>
     21244            <Orientation y="-2.32752"/>
    2138821245            <Actor seed="1760"/>
    2138921246        </Entity>
    2139021247        <Entity uid="3821">
    2139121248            <Template>skirmish/units/default_infantry_ranged_b</Template>
    2139221249            <Player>1</Player>
    21393             <Position x="314.0546" z="367.51511"/>
    21394             <Orientation y="2.35621"/>
     21250            <Position x="288.53586" z="342.8498"/>
     21251            <Orientation y="-2.52224"/>
    2139521252            <Actor seed="55684"/>
    2139621253        </Entity>
    2139721254        <Entity uid="3822">
    2139821255            <Template>skirmish/units/default_infantry_ranged_b</Template>
    2139921256            <Player>1</Player>
    21400             <Position x="317.72864" z="371.85798"/>
    21401             <Orientation y="2.35621"/>
     21257            <Position x="291.71335" z="339.68445"/>
     21258            <Orientation y="-2.46946"/>
    2140221259            <Actor seed="1248"/>
    2140321260        </Entity>
    2140421261        <Entity uid="3823">
    2140521262            <Template>skirmish/units/default_infantry_melee_b</Template>
    2140621263            <Player>1</Player>
    21407             <Position x="309.72019" z="372.82026"/>
    21408             <Orientation y="2.35621"/>
     21264            <Position x="282.46702" z="348.87024"/>
     21265            <Orientation y="-2.15017"/>
    2140921266            <Actor seed="54924"/>
    2141021267        </Entity>
    2141121268        <Entity uid="3824">
    2141221269            <Template>skirmish/units/default_infantry_melee_b</Template>
    2141321270            <Player>1</Player>
    21414             <Position x="314.19504" z="376.1663"/>
    21415             <Orientation y="2.35621"/>
     21271            <Position x="285.23688" z="345.27958"/>
     21272            <Orientation y="-2.3676"/>
    2141621273            <Actor seed="47532"/>
    2141721274        </Entity>
    2141821275        <Entity uid="3825">
    2141921276            <Template>skirmish/units/default_cavalry</Template>
    2142021277            <Player>1</Player>
    21421             <Position x="309.51676" z="363.01691"/>
     21278            <Position x="301.85553" z="330.77414"/>
    2142221279            <Orientation y="2.35621"/>
    2142321280            <Actor seed="29612"/>
    2142421281        </Entity>
     
    2142521282        <Entity uid="3826">
    2142621283            <Template>skirmish/units/special_starting_unit</Template>
    2142721284            <Player>1</Player>
    21428             <Position x="323.20731" z="377.55848"/>
    21429             <Orientation y="2.35621"/>
     21285            <Position x="299.36615" z="337.60267"/>
     21286            <Orientation y="-2.3836"/>
    2143021287            <Actor seed="1602"/>
    2143121288        </Entity>
    2143221289        <Entity uid="3827">
    2143321290            <Template>skirmish/units/special_starting_unit</Template>
    2143421291            <Player>2</Player>
    21435             <Position x="693.55298" z="336.7509"/>
    21436             <Orientation y="2.35621"/>
     21292            <Position x="668.57801" z="280.49256"/>
     21293            <Orientation y="-2.54137"/>
    2143721294            <Actor seed="25036"/>
    2143821295        </Entity>
    2143921296        <Entity uid="3828">
    2144021297            <Template>skirmish/units/default_support_female_citizen</Template>
    2144121298            <Player>2</Player>
    21442             <Position x="694.90522" z="326.74988"/>
    21443             <Orientation y="2.35621"/>
     21299            <Position x="661.33979" z="286.86234"/>
     21300            <Orientation y="-2.47521"/>
    2144421301            <Actor seed="32418"/>
    2144521302        </Entity>
    2144621303        <Entity uid="3829">
    2144721304            <Template>skirmish/units/default_support_female_citizen</Template>
    2144821305            <Player>2</Player>
    21449             <Position x="691.91431" z="323.88428"/>
    21450             <Orientation y="2.35621"/>
     21306            <Position x="657.65174" z="289.3094"/>
     21307            <Orientation y="-2.48824"/>
    2145121308            <Actor seed="35654"/>
    2145221309        </Entity>
    2145321310        <Entity uid="3830">
    2145421311            <Template>skirmish/units/default_support_female_citizen</Template>
    2145521312            <Player>2</Player>
    21456             <Position x="689.04792" z="321.44837"/>
    21457             <Orientation y="2.35621"/>
     21313            <Position x="654.4134" z="291.68458"/>
     21314            <Orientation y="-2.5247"/>
    2145821315            <Actor seed="36594"/>
    2145921316        </Entity>
    2146021317        <Entity uid="3831">
    2146121318            <Template>skirmish/units/default_support_female_citizen</Template>
    2146221319            <Player>2</Player>
    21463             <Position x="686.10358" z="318.28064"/>
    21464             <Orientation y="2.35621"/>
     21320            <Position x="664.43836" z="284.97123"/>
     21321            <Orientation y="-2.40302"/>
    2146521322            <Actor seed="47756"/>
    2146621323        </Entity>
    2146721324        <Entity uid="3832">
    2146821325            <Template>skirmish/units/default_infantry_ranged_b</Template>
    2146921326            <Player>2</Player>
    21470             <Position x="685.26685" z="324.64563"/>
    21471             <Orientation y="2.35621"/>
     21327            <Position x="659.04743" z="284.47364"/>
     21328            <Orientation y="-2.3304"/>
    2147221329            <Actor seed="17548"/>
    2147321330        </Entity>
    2147421331        <Entity uid="3833">
    2147521332            <Template>skirmish/units/default_infantry_ranged_b</Template>
    2147621333            <Player>2</Player>
    21477             <Position x="688.90973" z="328.2623"/>
    21478             <Orientation y="2.35621"/>
     21334            <Position x="661.84583" z="282.5123"/>
     21335            <Orientation y="-2.25824"/>
    2147921336            <Actor seed="57312"/>
    2148021337        </Entity>
    2148121338        <Entity uid="3834">
    2148221339            <Template>skirmish/units/default_infantry_melee_b</Template>
    2148321340            <Player>2</Player>
    21484             <Position x="682.29615" z="327.98316"/>
    21485             <Orientation y="2.35621"/>
     21341            <Position x="650.94666" z="289.72001"/>
     21342            <Orientation y="-2.43978"/>
    2148621343            <Actor seed="14636"/>
    2148721344        </Entity>
    2148821345        <Entity uid="3835">
    2148921346            <Template>skirmish/units/default_infantry_melee_b</Template>
    2149021347            <Player>2</Player>
    21491             <Position x="685.56696" z="331.46177"/>
    21492             <Orientation y="2.35621"/>
     21348            <Position x="654.04712" z="286.56611"/>
     21349            <Orientation y="-2.34855"/>
    2149321350            <Actor seed="31084"/>
    2149421351        </Entity>
    2149521352        <Entity uid="3836">
    2149621353            <Template>skirmish/units/default_cavalry</Template>
    2149721354            <Player>2</Player>
    21498             <Position x="678.50678" z="321.68516"/>
    21499             <Orientation y="2.35621"/>
     21355            <Position x="647.3246" z="294.96366"/>
     21356            <Orientation y="-0.79264"/>
    2150021357            <Actor seed="18606"/>
    2150121358        </Entity>
    2150221359        <Entity uid="3837">
    2150321360            <Template>skirmish/units/default_cavalry</Template>
    2150421361            <Player>3</Player>
    21505             <Position x="516.73243" z="741.3246"/>
     21362            <Position x="484.73737" z="727.24762"/>
    2150621363            <Orientation y="2.35621"/>
    2150721364            <Actor seed="59048"/>
    2150821365        </Entity>
     
    2150921366        <Entity uid="3838">
    2151021367            <Template>skirmish/units/special_starting_unit</Template>
    2151121368            <Player>3</Player>
    21512             <Position x="531.98261" z="755.25342"/>
    21513             <Orientation y="2.35621"/>
     21369            <Position x="503.17258" z="711.00068"/>
     21370            <Orientation y="-2.29906"/>
    2151421371            <Actor seed="27278"/>
    2151521372        </Entity>
    2151621373        <Entity uid="3839">
    2151721374            <Template>skirmish/units/default_support_female_citizen</Template>
    2151821375            <Player>3</Player>
    21519             <Position x="524.79883" z="739.31244"/>
    21520             <Orientation y="2.35621"/>
     21376            <Position x="489.29926" z="723.40064"/>
     21377            <Orientation y="-2.40946"/>
    2152121378            <Actor seed="59166"/>
    2152221379        </Entity>
    2152321380        <Entity uid="3840">
    2152421381            <Template>skirmish/units/default_support_female_citizen</Template>
    2152521382            <Player>3</Player>
    21526             <Position x="527.6792" z="741.84394"/>
    21527             <Orientation y="2.35621"/>
     21383            <Position x="492.23334" z="720.72028"/>
     21384            <Orientation y="-2.35325"/>
    2152821385            <Actor seed="64072"/>
    2152921386        </Entity>
    2153021387        <Entity uid="3841">
    2153121388            <Template>skirmish/units/default_support_female_citizen</Template>
    2153221389            <Player>3</Player>
    21533             <Position x="529.89551" z="744.12824"/>
    21534             <Orientation y="2.35621"/>
     21390            <Position x="494.82197" z="717.45392"/>
     21391            <Orientation y="-2.43023"/>
    2153521392            <Actor seed="43676"/>
    2153621393        </Entity>
    2153721394        <Entity uid="3842">
    2153821395            <Template>skirmish/units/default_support_female_citizen</Template>
    2153921396            <Player>3</Player>
    21540             <Position x="531.95746" z="746.8393"/>
    21541             <Orientation y="2.35621"/>
     21397            <Position x="497.54026" z="714.9253"/>
     21398            <Orientation y="-2.3855"/>
    2154221399            <Actor seed="1922"/>
    2154321400        </Entity>
    2154421401        <Entity uid="3843">
    2154521402            <Template>skirmish/units/default_infantry_ranged_b</Template>
    2154621403            <Player>3</Player>
    21547             <Position x="523.41059" z="746.25391"/>
    21548             <Orientation y="2.35621"/>
     21404            <Position x="490.90238" z="713.38813"/>
     21405            <Orientation y="-2.38874"/>
    2154921406            <Actor seed="13916"/>
    2155021407        </Entity>
    2155121408        <Entity uid="3844">
    2155221409            <Template>skirmish/units/default_infantry_ranged_b</Template>
    2155321410            <Player>3</Player>
    21554             <Position x="526.80774" z="749.2635"/>
    21555             <Orientation y="2.35621"/>
     21411            <Position x="493.89939" z="710.90583"/>
     21412            <Orientation y="-2.30419"/>
    2155621413            <Actor seed="12714"/>
    2155721414        </Entity>
    2155821415        <Entity uid="3845">
    2155921416            <Template>skirmish/units/default_infantry_melee_b</Template>
    2156021417            <Player>3</Player>
    21561             <Position x="519.40992" z="749.89112"/>
    21562             <Orientation y="2.35621"/>
     21418            <Position x="485.82453" z="718.97492"/>
     21419            <Orientation y="-2.51786"/>
    2156321420            <Actor seed="4366"/>
    2156421421        </Entity>
    2156521422        <Entity uid="3846">
    2156621423            <Template>skirmish/units/default_infantry_melee_b</Template>
    2156721424            <Player>3</Player>
    21568             <Position x="522.232" z="753.85303"/>
    21569             <Orientation y="2.35621"/>
     21425            <Position x="488.66263" z="715.99323"/>
     21426            <Orientation y="-2.11153"/>
    2157021427            <Actor seed="11530"/>
    2157121428        </Entity>
    2157221429        <Entity uid="3847">
     
    2182821685            <Orientation y="-2.44382"/>
    2182921686            <Actor seed="8060"/>
    2183021687        </Entity>
     21688        <Entity uid="3884">
     21689            <Template>gaia/geology_metal_alpine_slabs</Template>
     21690            <Player>0</Player>
     21691            <Position x="621.19056" z="674.04084"/>
     21692            <Orientation y="2.35621"/>
     21693            <Actor seed="12993"/>
     21694        </Entity>
     21695        <Entity uid="3885">
     21696            <Template>gaia/geology_metal_alpine_slabs</Template>
     21697            <Player>0</Player>
     21698            <Position x="409.23316" z="284.92985"/>
     21699            <Orientation y="2.35621"/>
     21700            <Actor seed="15772"/>
     21701        </Entity>
     21702        <Entity uid="3886">
     21703            <Template>gaia/geology_metal_alpine_slabs</Template>
     21704            <Player>0</Player>
     21705            <Position x="810.04609" z="415.72138"/>
     21706            <Orientation y="2.35621"/>
     21707            <Actor seed="25542"/>
     21708        </Entity>
     21709        <Entity uid="3887">
     21710            <Template>special/trigger_point_A</Template>
     21711            <Player>1</Player>
     21712            <Position x="292.92002" z="368.14585"/>
     21713            <Orientation y="2.35621"/>
     21714            <Actor seed="26096"/>
     21715        </Entity>
     21716        <Entity uid="3888">
     21717            <Template>special/trigger_point_A</Template>
     21718            <Player>2</Player>
     21719            <Position x="662.54566" z="323.72318"/>
     21720            <Orientation y="2.35621"/>
     21721            <Actor seed="18425"/>
     21722        </Entity>
     21723        <Entity uid="3889">
     21724            <Template>special/trigger_point_A</Template>
     21725            <Player>3</Player>
     21726            <Position x="523.7657" z="723.42896"/>
     21727            <Orientation y="2.35621"/>
     21728            <Actor seed="37001"/>
     21729        </Entity>
     21730        <Entity uid="3890">
     21731            <Template>special/trigger_point_B</Template>
     21732            <Player>1</Player>
     21733            <Position x="75.07139" z="728.80024"/>
     21734            <Orientation y="2.35621"/>
     21735            <Actor seed="24830"/>
     21736        </Entity>
     21737        <Entity uid="3891">
     21738            <Template>special/trigger_point_B</Template>
     21739            <Player>1</Player>
     21740            <Position x="386.49943" z="977.79816"/>
     21741            <Orientation y="2.92797"/>
     21742            <Actor seed="38620"/>
     21743        </Entity>
     21744        <Entity uid="3892">
     21745            <Template>special/trigger_point_B</Template>
     21746            <Player>2</Player>
     21747            <Position x="999.63575" z="573.85212"/>
     21748            <Orientation y="-2.25284"/>
     21749            <Actor seed="19865"/>
     21750        </Entity>
     21751        <Entity uid="3893">
     21752            <Template>special/trigger_point_C</Template>
     21753            <Player>3</Player>
     21754            <Position x="674.91651" z="973.77472"/>
     21755            <Orientation y="3.08518"/>
     21756            <Actor seed="27478"/>
     21757        </Entity>
     21758        <Entity uid="3894">
     21759            <Template>special/trigger_point_C</Template>
     21760            <Player>1</Player>
     21761            <Position x="134.2328" z="198.3071"/>
     21762            <Orientation y="0.8109"/>
     21763            <Actor seed="20758"/>
     21764        </Entity>
     21765        <Entity uid="3895">
     21766            <Template>special/trigger_point_C</Template>
     21767            <Player>2</Player>
     21768            <Position x="823.534" z="126.00896"/>
     21769            <Orientation y="2.35621"/>
     21770            <Actor seed="7871"/>
     21771        </Entity>
    2183121772    </Entities>
    2183221773    <Paths/>
    21833 </Scenario>
    21834  No newline at end of file
     21774</Scenario>
  • binaries/data/mods/public/simulation/components/Foundation.js

     
    202202            // (via CCmpTemplateManager). Now we need to remove that temporary
    203203            // blocker-disabling, so that we'll perform standard unit blocking instead.
    204204            cmpObstruction.SetDisableBlockMovementPathfinding(false, false, -1);
     205           
     206            // Call the related trigger event
     207            var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     208            cmpTrigger.CallEvent("ConstructionStarted", {"foundation": this.entity, "template": this.finalTemplateName});
    205209        }
    206210
    207211        // Switch foundation to scaffold variant
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

     
    288288                "timeTotal": time*1000,
    289289                "timeRemaining": time*1000,
    290290            });
     291           
     292            // Call the related trigger event
     293            var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     294            cmpTrigger.CallEvent("TrainingQueued", {"playerid": cmpPlayer.GetPlayerID(), "unitTemplate": templateName, "count": count, "metadata": metadata, "trainerEntity": this.entity});
    291295        }
    292296        else if (type == "technology")
    293297        {
     
    324328                "timeTotal": time*1000,
    325329                "timeRemaining": time*1000,
    326330            });
     331           
     332            // Call the related trigger event
     333            var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     334            cmpTrigger.CallEvent("ResearchQueued", {"playerid": cmpPlayer.GetPlayerID(), "technologyTemplate": templateName, "researcherEntity": this.entity});
    327335        }
    328336        else
    329337        {
  • binaries/data/mods/public/simulation/components/TechnologyManager.js

     
    348348    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    349349    var ents = cmpRangeManager.GetEntitiesByPlayer(playerID);
    350350
     351    // Call the related trigger event
     352    var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     353    cmpTrigger.CallEvent("ResearchFinished", {"player": playerID, "tech": tech});
     354   
    351355    for (var component in modifiedComponents)
    352356    {
    353357        Engine.PostMessage(SYSTEM_ENTITY, MT_TemplateModification, { "player": playerID, "component": component, "valueNames": modifiedComponents[component]});
  • binaries/data/mods/public/simulation/components/Trigger.js

     
     1function Trigger() {};
     2
     3Trigger.prototype.Schema =
     4    "<a:component type='system'/><empty/>";
     5
     6/**
     7 * Events we're able to receive and call handlers for
     8 */
     9Trigger.prototype.eventNames =
     10[
     11    "StructureBuilt", 
     12    "ConstructionStarted", 
     13    "TrainingFinished", 
     14    "TrainingQueued", 
     15    "ResearchFinished", 
     16    "ResearchQueued", 
     17    "PlayerCommand",
     18    "Interval",
     19    "Range",
     20];
     21
     22Trigger.prototype.Init = function()
     23{
     24    this.triggerPoints = {};
     25
     26    // Each event has its own set of actions determined by the map maker.
     27    for each (var eventName in this.eventNames)
     28        this["On" + eventName + "Actions"] = {};
     29     
     30    // To prevent the lose of trigger variables after a save, they "should" be defined in "InitTriggers" function, which is the starting point of a trigger script
     31    this.DoAfterDelay(0, "InitGame", {});
     32};
     33
     34Trigger.prototype.InitGame = function()
     35{
     36};
     37
     38Trigger.prototype.RegisterTriggerPoint = function(ref, ent)
     39{
     40    if (!this.triggerPoints[ref])
     41        this.triggerPoints[ref] = [];
     42    this.triggerPoints[ref].push(ent);
     43};
     44
     45Trigger.prototype.RemoveRegisteredTriggerPoint = function(ref, ent)
     46{
     47    if (!this.triggerPoints[ref])
     48        return;
     49    var i = this.triggerPoints[ref].indexOf(ent);
     50    if (i != -1)
     51         this.triggerPoints[ref].splice(i, 1);
     52};
     53
     54Trigger.prototype.GetTriggerPoints = function(ref)
     55{
     56    return this.triggerPoints[ref] || [];
     57};
     58
     59/**  Binds the "action" function to one of the implemented events.
     60 *
     61 * @param event Name of the event (see the list in init) 
     62 * @param action Functionname of a function available under this object
     63 * @param Extra Data for the trigger (enabled or not, delay for timers, range for range triggers ...)
     64 *
     65 * Interval triggers example:
     66 * data = {enabled: true, interval: 1000, delay: 500}
     67 *
     68 * Range trigger:
     69 * data.entities = [id1, id2] * Ids of the source
     70 * data.players = [1,2,3,...] * list of player ids
     71 * data.minRange = 0          * Minimum range for the query
     72 * data.maxRange = -1         * Maximum range for the query (-1 = no maximum)
     73 * data.requiredComponent = 0 * Required component id the entities will have
     74 * data.enabled = false       * If the query is enabled by default
     75 */
     76Trigger.prototype.RegisterTrigger = function(event, action, data)
     77{
     78    var eventString = event + "Actions";
     79    if (!this[eventString])
     80    {
     81        warn("Trigger.js: Invalid trigger event \"" + event + "\".")
     82        return;
     83    }
     84    if (this[eventString][action])
     85    {
     86        warn("Trigger.js: Trigger has been registered before. Aborting...");
     87        return;
     88    }
     89    // clone the data to be sure it's only modified locally
     90    // We could run into triggers overwriting each other's data otherwise.
     91    // F.e. getting the wrong timer tag
     92    data = data || {"enabled": false};
     93    var newData = {};
     94    for (var key in data)
     95        newData[key] = data[key];
     96    data = newData
     97
     98    this[eventString][action] = data;
     99
     100    // setup range query
     101    if (event == "OnRange")
     102    {
     103        if (!data.entities)
     104        {
     105            warn("Trigger.js: Range triggers should carry extra data");
     106            return;
     107        }
     108        data.queries = [];
     109        for (var ent of data.entities)
     110        {
     111            var cmpTriggerPoint = Engine.QueryInterface(ent, IID_TriggerPoint);
     112            if (!cmpTriggerPoint)
     113            {
     114                warn("Trigger.js: Range triggers must be defined on trigger points");
     115                continue;
     116            }
     117            data.queries.push(cmpTriggerPoint.RegisterRangeTrigger(action, data));
     118        }
     119    }
     120
     121    if (data.enabled)
     122        this.EnableTrigger(event, action);
     123};
     124
     125// Disable trigger
     126Trigger.prototype.DisableTrigger = function(event, action)
     127{
     128    var eventString = event + "Actions";
     129    if (!this[eventString][action])
     130    {
     131        warn("Trigger.js: Disabling unknown trigger");
     132        return;
     133    }
     134    var data = this[eventString][action];
     135    // special casing interval and range triggers for performance
     136    if (event == "OnInterval")
     137    {
     138        if (!data.timer) // don't disable it a second time
     139            return;
     140        var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     141        cmpTimer.CancelTimer(data.timer);
     142        data.timer = null;
     143    }
     144    else if (event == "OnRange")
     145    {
     146        if (!data.queries)
     147        {
     148            warn("Trigger.js: Range query wasn't set up before trying to disable it.");
     149            return;
     150        }
     151        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     152        for (var query of data.queries)
     153            cmpRangeManager.DisableActiveQuery(query);
     154    }
     155
     156    data.enabled = false;
     157};
     158
     159// Enable trigger
     160Trigger.prototype.EnableTrigger = function(event, action)
     161{
     162    var eventString = event + "Actions";
     163    if (!this[eventString][action])
     164    {
     165        warn("Trigger.js: Enabling unknown trigger");
     166        return;
     167    }
     168    var data = this[eventString][action];
     169    // special casing interval and range triggers for performance
     170    if (event == "OnInterval")
     171    {
     172        if (data.timer) // don't enable it a second time
     173            return;
     174        if (!data.interval)
     175        {
     176            warn("Trigger.js: An interval trigger should have an intervel in its data")
     177            return;
     178        }
     179        var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     180        var timer = cmpTimer.SetInterval(this.entity, IID_Trigger, "DoAction", data.delay || 0, data.interval, {"action" : action});
     181        data.timer = timer;
     182    }
     183    else if (event == "OnRange")
     184    {
     185        if (!data.queries)
     186        {
     187            warn("Trigger.js: Range query wasn't set up before");
     188            return;
     189        }
     190        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     191        for (var query of data.queries)
     192            cmpRangeManager.EnableActiveQuery(query);
     193    }
     194
     195    data.enabled = true;
     196};
     197
     198/**
     199 * This function executes the actions bound to the events
     200 * It's either called directlty from other simulation scripts, 
     201 * or from message listeners in this file
     202 *
     203 * @param event Name of the event (see the list in init)
     204 * @param data Data object that will be passed to the actions
     205 */
     206Trigger.prototype.CallEvent = function(event, data)
     207{
     208    var eventString = "On" + event + "Actions";
     209   
     210    if (!this[eventString])
     211    {
     212        warn("Trigger.js: Unknown trigger event called:\"" + event + "\".");
     213        return;
     214    }
     215   
     216    for (var action in this[eventString])
     217    {
     218        if (this[eventString][action].enabled)
     219            this.DoAction({"action": action, "data":data});
     220    }
     221};
     222
     223// Handles "OnStructureBuilt" event.
     224Trigger.prototype.OnGlobalConstructionFinished = function(msg)
     225{
     226    this.CallEvent("StructureBuilt", {"building": msg.newentity}); // The data for this one is {"building": constructedBuilding}
     227};
     228
     229// Handles "OnTrainingFinished" event.
     230Trigger.prototype.OnGlobalTrainingFinished = function(msg)
     231{
     232    this.CallEvent("TrainingFinished", msg);
     233    // The data for this one is {"entities": createdEnts,
     234    //                           "owner": cmpOwnership.GetOwner(),
     235    //                           "metadata": metadata}
     236    // See function "SpawnUnits" in ProductionQueue for more details
     237};
     238
     239/**
     240 * Execute a function after a certain delay
     241 * @param time The delay expressed in milleseconds
     242 * @param action Name of the action function
     243 * @param data Data object that will be passed to the action function
     244 */
     245Trigger.prototype.DoAfterDelay = function(miliseconds, action, data)
     246{
     247    var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
     248    return cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_Trigger, "DoAction", miliseconds, {"action": action, "data": data});
     249};
     250
     251/**
     252 * Called by the trigger listeners to exucute the actual action. Including sanity checks.
     253 */
     254Trigger.prototype.DoAction = function(msg)
     255{
     256    if (this[msg.action])
     257        this[msg.action](msg.data || null);
     258    else
     259        warn("Trigger.js: called a trigger action '" + msg.action + "' that wasn't found");
     260};
     261
     262Engine.RegisterSystemComponentType(IID_Trigger, "Trigger", Trigger);
  • binaries/data/mods/public/simulation/components/TriggerPoint.js

     
     1function TriggerPoint() {};
     2
     3TriggerPoint.prototype.Schema =
     4    "<optional>" +
     5        "<element name='Reference'>" +
     6            "<text/>" +
     7        "</element>" +
     8    "</optional>";
     9
     10TriggerPoint.prototype.Init = function()
     11{
     12    if (this.template && this.template.Reference)
     13    {
     14        var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     15        cmpTrigger.RegisterTriggerPoint(this.template.Reference, this.entity);
     16    }
     17    this.currentCollections = {};
     18    this.actions = {};
     19};
     20
     21TriggerPoint.prototype.OnDestroy = function()
     22{
     23    if (this.template && this.template.EntityReference)
     24    {
     25        var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     26        cmpTrigger.RemoveRegisteredTriggerPoint(this.template.Reference, this.entity);
     27    }
     28};
     29
     30/**
     31 * @param action Name of the action function defined under Trigger
     32 * @param data The data is an object containing information for the range query
     33 * Some of the data has sendible defaults (mentionned next to the object)
     34 * data.players = [1,2,3,...]  * list of player ids
     35 * data.minRange = 0           * Minimum range for the query
     36 * data.maxRange = -1          * Maximum range for the query (-1 = no maximum)
     37 * data.requiredComponent = -1 * Required component id the entities will have
     38 * data.enabled = false        * If the query is enabled by default
     39 */
     40TriggerPoint.prototype.RegisterRangeTrigger = function(action, data)
     41{
     42   
     43    if (data.players)
     44        var players = data.players;
     45    else
     46    {
     47        var numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers();
     48        var players = [];
     49        for (var i = 0; i < numPlayers; i++)
     50            players.push(i);
     51    }
     52    var minRange = data.minRange || 0;
     53    var maxRange = data.maxRange || -1;
     54    var cid = data.requiredComponent || -1;
     55   
     56    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     57    var tag = cmpRangeManager.CreateActiveQuery(this.entity, minRange, maxRange, players, cid, cmpRangeManager.GetEntityFlagMask("normal"));
     58
     59    this.currentCollections[tag] = [];
     60    this.actions[tag] = action;
     61    return tag;
     62};
     63
     64TriggerPoint.prototype.OnRangeUpdate = function(msg)
     65{
     66    var collection = this.currentCollections[msg.tag];
     67    if (!collection)
     68        return;
     69
     70    for (var ent of msg.removed)
     71    {
     72        var index = collection.indexOf(ent);
     73        if (index > -1)
     74            collection.splice(index, 1);
     75    }
     76       
     77    for each (var entity in msg.added)
     78        collection.push(entity);
     79
     80    var r = {"currentCollection": collection.slice()};
     81    r.added = msg.added;
     82    r.removed = msg.removed;
     83    var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     84    cmpTrigger.DoAction({"action":this.actions[msg.tag], "data": r});
     85};
     86
     87
     88Engine.RegisterComponentType(IID_TriggerPoint, "TriggerPoint", TriggerPoint);
  • binaries/data/mods/public/simulation/components/interfaces/Trigger.js

     
     1Engine.RegisterInterface("Trigger");
  • binaries/data/mods/public/simulation/components/interfaces/TriggerPoint.js

     
     1Engine.RegisterInterface("TriggerPoint");
     2
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    3131
    3232    // Now handle various commands
    3333    if (commands[cmd.type])
     34    {
     35        var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     36        if (cmpTrigger)
     37            cmpTrigger.CallEvent("PlayerCommand", {"player": player, "cmd": cmd});
    3438        commands[cmd.type](player, cmd, data);
     39    }
    3540    else
    3641        error("Invalid command: unknown command type: "+uneval(cmd));
    3742}
  • binaries/data/mods/public/simulation/templates/special/trigger_point_A.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>A</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_a.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_B.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>B</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_b.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_C.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>C</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_c.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_D.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>D</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_d.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_E.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>E</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_e.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_F.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>F</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_f.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_G.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>G</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_g.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_H.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>H</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_h.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_I.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>I</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_i.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_J.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>J</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_j.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/special/trigger_point_K.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_trigger_point">
     3  <TriggerPoint>
     4    <Reference>K</Reference>
     5  </TriggerPoint>
    36  <VisualActor>
    47    <Actor>props/special/common/marker_object_char_k.xml</Actor>
    58  </VisualActor>
  • binaries/data/mods/public/simulation/templates/template_trigger_point.xml

  • source/simulation2/Simulation2.cpp

    Property changes on: binaries/data/mods/public/simulation/templates/template_trigger_point.xml
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/xml
    \ No newline at end of property
     
    702702
    703703    if (!m->m_StartupScript.empty())
    704704        GetScriptInterface().LoadScript(L"map startup script", m->m_StartupScript);
     705   
     706    // Load the trigger script after we have loaded the simulation and the map.
     707    if (GetScriptInterface().HasProperty(m->m_MapSettings.get(), "TriggerScripts"))
     708    {
     709        std::vector<std::string> scriptNames;
     710        GetScriptInterface().GetProperty(m->m_MapSettings.get(), "TriggerScripts", scriptNames);
     711        for (u32 i = 0; i < scriptNames.size(); i++)
     712        {
     713            std::string scriptName = "maps/" + scriptNames[i];
     714            LOGMESSAGE(L"Loading trigger script '%s'", scriptName.c_str());
     715            m->m_ComponentManager.LoadScript(scriptName.data());
     716        }
     717    }
    705718}
    706719
    707720int CSimulation2::ProgressiveLoad()