1
0
forked from mirrors/0ad

petra: improve the way units capturing a structure react when attacked by enemy units + some code cleanup

This was SVN commit r20072.
This commit is contained in:
mimo
2017-08-29 18:23:16 +00:00
parent c17f379513
commit 9e96bca85e
4 changed files with 26 additions and 9 deletions
@@ -251,7 +251,7 @@ m.Accessibility.prototype.floodFill = function(startIndex, value, onWater)
return false;
}
if ((!onWater && this.landPassMap[startIndex] !== 0) || (onWater && this.navalPassMap[startIndex] !== 0) )
if (!onWater && this.landPassMap[startIndex] !== 0 || onWater && this.navalPassMap[startIndex] !== 0 )
return false; // already painted.
let floodFor = "land";
@@ -1274,7 +1274,26 @@ m.AttackPlan.prototype.update = function(gameState, events)
}
}
else
{ // if units are attacked, abandon their target (if it was a structure or a support) and retaliate
{
// Look first for nearby units to help us if possible
let collec = this.unitCollection.filterNearest(ourUnit.position(), 2);
for (let ent of collec.values())
{
if (m.isSiegeUnit(ent))
continue;
let orderData = ent.unitAIOrderData();
if (orderData && orderData.length && orderData[0].target)
{
if (orderData[0].target === attacker.id())
continue;
let target = gameState.getEntityById(orderData[0].target);
if (target && !target.hasClass("Structure") && !target.hasClass("Support"))
continue;
}
ent.attack(attacker.id(), m.allowCapture(gameState, ent, attacker));
ent.setMetadata(PlayerID, "lastAttackPlanUpdateTime", time);
}
// Then the unit under attack: abandon its target (if it was a structure or a support) and retaliate
// also if our unit is attacking a range unit and the attacker is a melee unit, retaliate
let orderData = ourUnit.unitAIOrderData();
if (orderData && orderData.length && orderData[0].target)
@@ -1444,8 +1444,6 @@ m.HQ.prototype.buildWonder = function(gameState, queues, force = false)
return;
}
if (this.Config.debug > 0)
API3.warn(" civ " + gameState.getPlayerCiv() + " starts a plan for Wonder");
queues.wonder.addPlan(new m.ConstructionPlan(gameState, "structures/{civ}_wonder"));
};
@@ -2253,7 +2251,7 @@ m.HQ.prototype.updateCaptureStrength = function(gameState)
let orderData = ent.unitAIOrderData();
if (!orderData || !orderData.length || !orderData[0].attackType)
continue;
if ((orderData[0].attackType === "Capture") !== allowCapture)
if (orderData[0].attackType === "Capture" !== allowCapture)
ent.attack(targetId, allowCapture);
}
}
@@ -55,8 +55,8 @@ m.TradeManager.prototype.trainMoreTraders = function(gameState, queues)
}
});
if (numTraders >= this.targetNumTraders &&
((!this.tradeRoute.sea && numLandTraders >= Math.floor(this.targetNumTraders/2)) ||
(this.tradeRoute.sea && numSeaTraders >= Math.floor(this.targetNumTraders/2))))
(!this.tradeRoute.sea && numLandTraders >= Math.floor(this.targetNumTraders/2) ||
this.tradeRoute.sea && numSeaTraders >= Math.floor(this.targetNumTraders/2)))
return;
let template;
@@ -536,8 +536,8 @@ m.TradeManager.prototype.checkTrader = function(gameState, ent)
let possibleRoute = this.checkRoutes(gameState, access);
// Warning: presentRoute is from metadata, so contains entity ids
if (!possibleRoute ||
(possibleRoute.source.id() != presentRoute.source && possibleRoute.source.id() != presentRoute.target) ||
(possibleRoute.target.id() != presentRoute.source && possibleRoute.target.id() != presentRoute.target))
possibleRoute.source.id() != presentRoute.source && possibleRoute.source.id() != presentRoute.target ||
possibleRoute.target.id() != presentRoute.source && possibleRoute.target.id() != presentRoute.target)
{
// Trader will be assigned in updateTrader
ent.setMetadata(PlayerID, "route", undefined);