Ticket #3102: ai-survival.patch

File ai-survival.patch, 4.3 KB (added by mimo, 7 years ago)
  • binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js

     
    189189        let cmpPlayer = QueryPlayerIDInterface(i);
    190190        let civ = cmpPlayer.GetCiv();
    191191        cmpPlayer.SetDisabledTemplates(disabledTemplates(civ));
     192
     193        cmpPlayer.AddTriggerScriptEvent({ "type": "attackWaves", "value": "strong" });
    192194    }
    193195};
    194196
  • binaries/data/mods/public/simulation/ai/common-api/gamestate.js

     
    288288    return this.playerData.popCount;
    289289};
    290290
    291 m.GameState.prototype.getPopulationLimit = function() {
     291m.GameState.prototype.getPopulationLimit = function()
     292{
    292293    return this.playerData.popLimit;
    293294};
    294295
    295 m.GameState.prototype.getPopulationMax = function() {
     296m.GameState.prototype.getPopulationMax = function()
     297{
    296298    return this.playerData.popMax;
    297299};
    298300
     301m.GameState.prototype.GetTriggerScriptEvent = function(type)
     302{
     303    for (let event of this.playerData.triggerScriptEvents)
     304        if (event.type === type)
     305            return event.value;
     306
     307    return undefined;
     308};
     309
    299310m.GameState.prototype.getPlayerID = function()
    300311{
    301312    return this.player;
  • binaries/data/mods/public/simulation/ai/petra/headquarters.js

     
    496496        return;
    497497
    498498    // Choose whether we want soldiers or support units.
    499     let supportRatio = gameState.isTemplateDisabled(gameState.applyCiv("structures/{civ}_field")) ? Math.min(this.supportRatio, 0.1) : this.supportRatio;
     499    let strongAttackWaves = gameState.GetTriggerScriptEvent("attackWaves") === "strong";
     500    let disabledFields = gameState.isTemplateDisabled(gameState.applyCiv("structures/{civ}_field"));
     501    let supportRatio = this.supportRatio;
     502    if (disabledFields && strongAttackWaves)
     503        supportRatio = 0.;
     504    else if (disabledFields)
     505        supportRatio = Math.min(supportRatio, 0.1);
     506    else if (strongAttackWaves)
     507        supportRatio = Math.min(supportRatio, 0.2);
    500508    let supportMax = supportRatio * this.targetNumWorkers;
    501509    let supportNum = supportMax * Math.atan(numberTotal/supportMax) / 1.570796;
    502510
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    108108            "disabledTemplates": cmpPlayer.GetDisabledTemplates(),
    109109            "hasSharedDropsites": cmpPlayer.HasSharedDropsites(),
    110110            "hasSharedLos": cmpPlayer.HasSharedLos(),
     111            "triggerScriptEvents": cmpPlayer.GetTriggerScriptEvents(),
    111112            "phase": phase,
    112113            "isAlly": allies,
    113114            "isMutualAlly": mutualAllies,
  • binaries/data/mods/public/simulation/components/Player.js

     
    3838    this.disabledTemplates = {};
    3939    this.disabledTechnologies = {};
    4040    this.startingTechnologies = [];
     41    this.triggerScriptEvents = [];
    4142
    4243    // Initial resources and trading goods probability in steps of 5
    4344    let resCodes = Resources.GetCodes();
     
    861862    this.startingTechnologies = techs;
    862863};
    863864
     865/**
     866 * Trigger script events of the form { "type": "attackWaves", "value": "strong" }
     867 * used by the AIs
     868 */
     869Player.prototype.AddTriggerScriptEvent = function(data)
     870{
     871    for (let event of this.triggerScriptEvents)
     872        if (event.type == data.type)
     873        {
     874            event.value = data.value;
     875            return;
     876        }
     877
     878    this.triggerScriptEvents.push(data);
     879};
     880
     881Player.prototype.GetTriggerScriptEvents = function()
     882{
     883    return this.triggerScriptEvents;
     884};
     885
    864886Engine.RegisterComponentType(IID_Player, "Player", Player);