Ticket #4142: petra_regicide_support_v1.2.patch

File petra_regicide_support_v1.2.patch, 3.2 KB (added by Sandarac, 8 years ago)

Petra will not add the hero to an army if its destination is across water, or if the hero is hurt. The hero will retreat if there are more than six enemy units surrounding it.

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

     
    643643            continue;
    644644        if (ent.hasClass("Ship") || ent.hasClass("Support") || ent.attackTypes() === undefined)
    645645            continue;
     646        if (gameState.getGameType() === "regicide" && ent.hasClass("Hero") && (this.overseas || ent.isHurt()))
     647            continue;
    646648        ent.setMetadata(PlayerID, "plan", plan);
    647649        this.unitCollection.updateEnt(ent);
    648650        added = true;
  • binaries/data/mods/public/simulation/ai/petra/defenseManager.js

     
    388388            return;
    389389        if (ent.getMetadata(PlayerID, "transport") !== undefined || ent.getMetadata(PlayerID, "transporter") !== undefined)
    390390            return;
     391        if (gameState.getGameType() === "regicide" && ent.hasClass("Hero") && ent.isHurt())
     392            return;
    391393        if (ent.getMetadata(PlayerID, "plan") !== undefined && ent.getMetadata(PlayerID, "plan") !== -1)
    392394        {
    393395            let subrole = ent.getMetadata(PlayerID, "subrole");
     
    475477        if (target.hasClass("Ship"))    // TODO integrate ships later   need to be sure it is accessible
    476478            continue;
    477479
     480        let plan = target.getMetadata(PlayerID, "plan");
     481
     482        if (gameState.getGameType() == "regicide" && target.hasClass("Hero") &&
     483            (target.healthLevel() < 0.6 && target.hasClass("Infantry") || target.healthLevel() < 0.3 && target.hasClass("Cavalry") ||
     484            target.healthLevel() < 0.95 && !target.attackTypes() || target.healthLevel() < 0.7 && target.hasClass("Elephant")) ||
     485            gameState.getEnemyUnits().filter(ent => ent.position() && ent.attackTypes() &&
     486            API3.SquareVectorDistance(target.position(), ent.position()) < 50).length > 6)
     487        {
     488            target.stopMoving();
     489
     490            if (plan >= 0)
     491            {
     492                let attackPlan = gameState.ai.HQ.attackManager.getPlan(target.getMetadata(PlayerID, "plan"));
     493                if (attackPlan)
     494                    attackPlan.removeUnit(target, true);
     495            }
     496            if (target.getMetadata(PlayerID, "PartOfArmy"))
     497            {
     498                let army = gameState.ai.HQ.defenseManager.getArmy(target.getMetadata(PlayerID, "PartOfArmy"));
     499                if (army)
     500                    army.removeOwn(gameState, target.id());
     501            }
     502
     503            this.garrisonUnitForHealing(gameState, target);
     504
     505            if (plan >= 0) // couldn't find a place to garrison, so the hero will flee from attacks
     506            {
     507                target.setStance("passive");
     508                let accessIndex = gameState.ai.accessibility.getAccessValue(target.position());
     509                let basePos = m.getBestBase(gameState, target);
     510                if (basePos && basePos.accessIndex == accessIndex)
     511                    target.move(basePos.anchor.position()[0], basePos.anchor.position()[1]);
     512            }
     513            continue;
     514        }
     515
    478516        // If inside a started attack plan, let the plan deal with this unit
    479         let plan = target.getMetadata(PlayerID, "plan");
    480517        if (plan !== undefined && plan >= 0)
    481518        {
    482519            let attack = gameState.ai.HQ.attackManager.getPlan(plan);