Ticket #2757: 2757.4.patch

File 2757.4.patch, 3.7 KB (added by maveric, 9 years ago)
  • binaries/data/mods/public/simulation/ai/petra/chatHelper.js

     
    106106    Engine.PostCommand(PlayerID, chat);
    107107};
    108108
     109m.chatNewPhase = function(gameState, phase, started)
     110{
     111    if (started)
     112        var message = "/allies " + markForTranslation("I am advancing to the %(phase)s.");
     113    else
     114        var message = "/allies " + markForTranslation("I have reached the %(phase)s.");
     115   
     116    var chat = {
     117        "type": "aichat",
     118        "message": message,
     119        "translateMessage": true,
     120        "translateParameters": ["phase"],
     121        "parameters": { "phase": phase }
     122    };
     123    Engine.PostCommand(PlayerID, chat);
     124};
     125
     126
    109127return m;
    110128}(PETRA);
  • binaries/data/mods/public/simulation/ai/petra/headquarters.js

     
    1919    this.Config = Config;
    2020   
    2121    this.econState = "growth";  // existing values: growth, townPhasing.
    22     this.phaseStarted = undefined;
     22    this.currentPhase = undefined;
    2323
    2424    // cache the rates.
    2525    this.wantedRates = { "food": 0, "wood": 0, "stone":0, "metal": 0 };
     
    7171        return false;
    7272    });
    7373    this.treasures.registerUpdates();
     74    this.currentPhase = gameState.currentPhase();
    7475};
    7576
    7677/**
     
    279280{
    280281    if (this.Config.difficulty > 2 && this.femaleRatio > 0.4)
    281282        this.femaleRatio = 0.4;
    282 
    283     this.phaseStarted = 2;
     283   
     284    var phaseName = gameState.getTemplate(gameState.townPhase()).name();
     285    m.chatNewPhase(gameState, phaseName, true);
    284286};
    285287
    286288// Called by the "city phase" research plan once it's started
     
    288290{
    289291    if (this.Config.difficulty > 2 && this.femaleRatio > 0.3)
    290292        this.femaleRatio = 0.3;
    291 
    292     this.phaseStarted = 3;
     293       
     294    var phaseName = gameState.getTemplate(gameState.cityPhase()).name();   
     295    m.chatNewPhase(gameState, phaseName, true);
    293296};
    294297
    295298// This code trains females and citizen workers, trying to keep close to a ratio of females/CS
     
    17221725m.HQ.prototype.update = function(gameState, queues, events)
    17231726{
    17241727    Engine.ProfileStart("Headquarters update");
     1728   
     1729    if (this.currentPhase != gameState.currentPhase())
     1730    {
     1731        this.currentPhase = gameState.currentPhase();
     1732       
     1733        if (this.currentPhase == 2)
     1734        {
     1735            var phaseName = gameState.getTemplate(gameState.townPhase()).name();
     1736            m.chatNewPhase(gameState, phaseName, false);
     1737        }
     1738        else if (this.currentPhase == 3)
     1739        {
     1740            var phaseName = gameState.getTemplate(gameState.cityPhase()).name();
     1741            m.chatNewPhase(gameState, phaseName, false);
     1742        }
     1743        this.updateTerritories(gameState);
     1744    }
     1745    else if (gameState.ai.playedTurn - this.lastTerritoryUpdate > 100)
     1746        this.updateTerritories(gameState);
    17251747
    17261748    this.territoryMap = m.createTerritoryMap(gameState);
    17271749
     
    17511773
    17521774    this.researchManager.checkPhase(gameState, queues);
    17531775
    1754     // TODO find a better way to update
    1755     if (this.phaseStarted && gameState.currentPhase() == this.phaseStarted)
    1756     {
    1757         this.phaseStarted = undefined;
    1758         this.updateTerritories(gameState);
    1759     }
    1760     else if (gameState.ai.playedTurn - this.lastTerritoryUpdate > 100)
    1761         this.updateTerritories(gameState);
    1762 
    17631776    if (gameState.getGameType() === "wonder")
    17641777        this.buildWonder(gameState, queues);
    17651778
     
    18251838{
    18261839    let properties = {
    18271840        "econState": this.econState,
    1828         "phaseStarted": this.phaseStarted,
     1841        "currentPhase": this.currentPhase,
    18291842        "wantedRates": this.wantedRates,
    18301843        "currentRates": this.currentRates,
    18311844        "lastFailedGather": this.lastFailedGather,