Ticket #5106: patch.patch

File patch.patch, 6.2 KB (added by wraitii, 4 years ago)

test setup using a demo map and trigger & a little modding

  • new file inaries/data/mods/public/maps/scenarios/test.js

    diff --git a/binaries/data/mods/public/maps/scenarios/test.js b/binaries/data/mods/public/maps/scenarios/test.js
    new file mode 100644
    index 0000000000..1aa1034717
    - +  
     1const UNIT_TEMPLATE = "units/athen_infantry_marine_archer_b";
     2const FAST_UNIT_TEMPLATE = "units/athen_cavalry_swordsman_a";
     3
     4var QuickSpawn = function(x, z, template, owner = 1)
     5{
     6    let ent = Engine.AddEntity(template);
     7
     8    let cmpEntOwnership = Engine.QueryInterface(ent, IID_Ownership);
     9    if (cmpEntOwnership)
     10        cmpEntOwnership.SetOwner(owner);
     11
     12    let cmpEntPosition = Engine.QueryInterface(ent, IID_Position);
     13    cmpEntPosition.JumpTo(x, z);
     14    return ent;
     15};
     16
     17var Rotate = function(angle, ent)
     18{
     19    let cmpEntPosition = Engine.QueryInterface(ent, IID_Position);
     20    cmpEntPosition.SetYRotation(angle);
     21    return ent;
     22};
     23
     24var WalkTo = function(x, z, ent, player)
     25{
     26    ProcessCommand(player, {
     27        "type": "walk",
     28        "entities": Array.isArray(ent) ? ent : [ent],
     29        "x": x,
     30        "z": z,
     31        "queued": false
     32    });
     33    return ent;
     34};
     35
     36var Attack = function(target, ent, player)
     37{
     38    ProcessCommand(player, {
     39        "type": "attack",
     40        "entities": Array.isArray(ent) ? ent : [ent],
     41        "target": target,
     42        "queued": false
     43    });
     44    return ent;
     45};
     46
     47var Do = function(name, data, ent, player)
     48{
     49    let comm = {
     50        "type": name,
     51        "entities": Array.isArray(ent) ? ent : [ent],
     52        "queued": false
     53    };
     54    for (let k in data)
     55        comm[k] = data[k];
     56    ProcessCommand(player, comm);
     57};
     58
     59function setupExperiment(x, y, distance, modifiers = {})
     60{
     61    let target = QuickSpawn(x, y, FAST_UNIT_TEMPLATE, 2);
     62    Do("stance", {
     63        "name": "standground"
     64    }, target, 2);
     65
     66    Do("patrol", {
     67        "x": x,
     68        "z": y-10,
     69        "force": true,
     70        "targetClasses": [],
     71    }, target, 2);
     72
     73    for (let i = 0; i < 5; ++i)
     74    {
     75        let attacker = QuickSpawn(x+distance, y + i * 2, UNIT_TEMPLATE, 1);
     76
     77        let cmpModif = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager);
     78        cmpModif.AddModifiers("triggerdtest", modifiers, attacker);
     79        Attack(target, attacker, 1);
     80    }
     81}
     82
     83var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
     84
     85Trigger.prototype.SetupUnits = function()
     86{
     87    setupExperiment(250, 250, 40);
     88    setupExperiment(350, 250, 40, {
     89        "Attack/Ranged/Spread": [{ "affects": [["Unit"]], "multiply": 0.01 }],
     90    });
     91    setupExperiment(450, 250, 40, {
     92        "Attack/Ranged/Speed": [{ "affects": [["Unit"]], "multiply": 2 }],
     93    });
     94    setupExperiment(250, 350, 40, {
     95        "Attack/Ranged/Speed": [{ "affects": [["Unit"]], "multiply": 4 }],
     96    });
     97};
     98
     99cmpTrigger.DoAfterDelay(1000, "SetupUnits", {});
  • new file inaries/data/mods/public/maps/scenarios/test.xml

    diff --git a/binaries/data/mods/public/maps/scenarios/test.xml b/binaries/data/mods/public/maps/scenarios/test.xml
    new file mode 100644
    index 0000000000..fe22b11378
    - +  
     1<?xml version="1.0" encoding="UTF-8"?>
     2
     3<Scenario version="6">
     4    <Terrain patches="20" texture="blackness" priority="0" height="16384"/>
     5    <Environment>
     6        <SkySet>default</SkySet>
     7        <SunColor r="0.74902" g="0.74902" b="0.74902"/>
     8        <SunElevation angle="0.785398"/>
     9        <SunRotation angle="-0.785396"/>
     10        <TerrainAmbientColor r="0.501961" g="0.501961" b="0.501961"/>
     11        <UnitsAmbientColor r="0.501961" g="0.501961" b="0.501961"/>
     12        <Fog>
     13            <FogFactor>0</FogFactor>
     14            <FogThickness>0.5</FogThickness>
     15            <FogColor r="0.8" g="0.8" b="0.898039"/>
     16        </Fog>
     17        <Water>
     18            <WaterBody>
     19                <Type>ocean</Type>
     20                <Color r="0.298039" g="0.34902" b="0.698039"/>
     21                <Tint r="0.278431" g="0.298039" b="0.588235"/>
     22                <Height>5</Height>
     23                <Waviness>4</Waviness>
     24                <Murkiness>0.45</Murkiness>
     25                <WindAngle>0</WindAngle>
     26            </WaterBody>
     27        </Water>
     28        <Postproc>
     29            <Brightness>0</Brightness>
     30            <Contrast>1</Contrast>
     31            <Saturation>0.99</Saturation>
     32            <Bloom>0.1999</Bloom>
     33            <PostEffect>default</PostEffect>
     34        </Postproc>
     35    </Environment>
     36    <Camera>
     37        <Position x="300" y="77.5248" z="306.255"/>
     38        <Rotation angle="0"/>
     39        <Declination angle="0.610865"/>
     40    </Camera>
     41    <ScriptSettings><![CDATA[
     42{
     43  "CircularMap": true,
     44  "Description": "This map is designed to test some basic unit movement cases. It will involve unitAI, unitMotion and the relevant pathfinders and thus acts as an integrated test map. Look for things such as stuck units, wrong animations, and weird pathing.",
     45  "Keywords": [
     46    "trigger",
     47    "demo"
     48  ],
     49  "Name": "TestMap",
     50  "PlayerData": [
     51    {
     52      "Civ": "athen"
     53    },
     54    {
     55      "AI": "",
     56      "Civ": "athen"
     57    }
     58  ],
     59  "RevealMap": true,
     60  "TriggerScripts": [
     61    "scripts/TriggerHelper.js",
     62    "scenarios/test.js"
     63  ],
     64  "VictoryConditions": []
     65}
     66]]></ScriptSettings>
     67    <Entities>
     68    </Entities>
     69    <Paths/>
     70</Scenario>
  • binaries/data/mods/public/simulation/components/Attack.js

    diff --git a/binaries/data/mods/public/simulation/components/Attack.js b/binaries/data/mods/public/simulation/components/Attack.js
    index 4be1e97f8b..9298942983 100644
    a b Attack.prototype.PerformAttack = function(type, target)  
    469469        //  * Obstacles like trees could reduce the probability of the target being hit
    470470        //  * Obstacles like walls should block projectiles entirely
    471471
    472         let horizSpeed = +this.template[type].Projectile.Speed;
     472        let horizSpeed = ApplyValueModificationsToEntity("Attack/Ranged/Speed", +this.template[type].Projectile.Speed, this.entity);
    473473        let gravity = +this.template[type].Projectile.Gravity;
    474474        // horizSpeed /= 2; gravity /= 2; // slow it down for testing
    475475
    Attack.prototype.PerformAttack = function(type, target)  
    486486        let targetVelocity = Vector3D.sub(targetPosition, previousTargetPosition).div(turnLength);
    487487
    488488        let timeToTarget = this.PredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity);
    489         let predictedPosition = (timeToTarget !== false) ? Vector3D.mult(targetVelocity, timeToTarget).add(targetPosition) : targetPosition;
     489        let predictedPosition = (timeToTarget !== false && Math.random() < 0.4) ? Vector3D.mult(targetVelocity, timeToTarget).add(targetPosition) : targetPosition;
    490490
    491491        // Add inaccuracy based on spread.
    492492        let distanceModifiedSpread = ApplyValueModificationsToEntity("Attack/Ranged/Spread", +this.template[type].Projectile.Spread, this.entity) *