Ticket #4142: petra_regicide_support_v1.1.patch

File petra_regicide_support_v1.1.patch, 2.0 KB (added by Sandarac, 8 years ago)

Petra will try to return the hero to a base (and garrison the hero if it can) using class specific health thresholds.

  • binaries/data/mods/public/simulation/ai/petra/defenseManager.js

     
    475475        if (target.hasClass("Ship"))    // TODO integrate ships later   need to be sure it is accessible
    476476            continue;
    477477
     478        let plan = target.getMetadata(PlayerID, "plan");
     479
     480        if (gameState.getGameType() == "regicide" && target.hasClass("Hero") &&
     481            target.healthLevel() < 0.5 && target.hasClass("Infantry") || target.healthLevel() < 0.3 && target.hasClass("Cavalry") ||
     482            target.healthLevel() < 0.95 && !target.attackTypes() || target.healthLevel() < 0.7 && target.hasClass("Elephant") &&
     483            plan !== -2 && plan !== -3)
     484        {
     485            if (plan >= 0)
     486            {
     487                let attackPlan = gameState.ai.HQ.attackManager.getPlan(target.getMetadata(PlayerID, "plan"));
     488                if (attackPlan)
     489                    attackPlan.removeUnit(target, true);
     490            }
     491            if (target.getMetadata(PlayerID, "PartOfArmy"))
     492            {
     493                let army = gameState.ai.HQ.defenseManager.getArmy(target.getMetadata(PlayerID, "PartOfArmy"));
     494                if (army)
     495                    army.removeOwn(gameState, target.id());
     496            }
     497
     498            this.garrisonUnitForHealing(gameState, target);
     499
     500            if (plan >= 0) // couldn't find a place to garrison, so the hero will flee from attacks
     501            {
     502                target.setStance("passive");
     503                let accessIndex = gameState.ai.accessibility.getAccessValue(target.position());
     504                let basePos = m.getBestBase(gameState, target);
     505                if (basePos && basePos.accessIndex == accessIndex)
     506                    target.move(basePos.anchor.position()[0], basePos.anchor.position()[1]);
     507            }
     508            continue;
     509        }
     510
    478511        // If inside a started attack plan, let the plan deal with this unit
    479         let plan = target.getMetadata(PlayerID, "plan");
    480512        if (plan !== undefined && plan >= 0)
    481513        {
    482514            let attack = gameState.ai.HQ.attackManager.getPlan(plan);