1
0
forked from 0ad/0ad

[Gameplay] Let the mauryan worker elephant build again

and also patch the AI by partly reverting 87ec9457c3

based on a patch by @Langbart
Fixes #6309

accepted by : @Freagarach

conceptual agreement from @chrstgtr @borg- @Stan

Differential revision: https://code.wildfiregames.com/D4249
This was SVN commit r26898.
This commit is contained in:
marder 2022-05-22 07:06:59 +00:00
parent 0f99c79dad
commit ddb54bfe84
3 changed files with 20 additions and 7 deletions

View File

@ -548,6 +548,8 @@ PETRA.BaseManager.prototype.assignRolelessUnits = function(gameState, roleless)
{
if (ent.hasClasses(["Worker", "CitizenSoldier", "FishingBoat"]))
ent.setMetadata(PlayerID, "role", PETRA.Worker.ROLE_WORKER);
else if (ent.hasClass("Support") && ent.hasClass("Elephant"))
ent.setMetadata(PlayerID, "role", "worker");
}
};
@ -652,6 +654,12 @@ PETRA.BaseManager.prototype.reassignIdleWorkers = function(gameState, idleWorker
// Check that the worker isn't garrisoned
if (!ent.position())
continue;
// Support elephant can only be builders
if (ent.hasClass("Support") && ent.hasClass("Elephant"))
{
ent.setMetadata(PlayerID, "subrole", "idle");
continue;
}
if (ent.hasClass("Worker"))
{
@ -874,10 +882,15 @@ PETRA.BaseManager.prototype.assignToFoundations = function(gameState, noRepair)
let time = target.buildTime();
nonBuilderWorkers.sort((workerA, workerB) => {
let coeffA = API3.SquareVectorDistance(target.position(), workerA.position());
if (workerA.getMetadata(PlayerID, "gather-type") == "food")
// elephant moves slowly, so when far away they are only useful if build time is long
if (workerA.hasClass("Elephant"))
coeffA *= 0.5 * (1 + Math.sqrt(coeffA)/5/time);
else if (workerA.getMetadata(PlayerID, "gather-type") == "food")
coeffA *= 3;
let coeffB = API3.SquareVectorDistance(target.position(), workerB.position());
if (workerB.getMetadata(PlayerID, "gather-type") == "food")
if (workerB.hasClass("Elephant"))
coeffB *= 0.5 * (1 + Math.sqrt(coeffB)/5/time);
else if (workerB.getMetadata(PlayerID, "gather-type") == "food")
coeffB *= 3;
return coeffA - coeffB;
});

View File

@ -348,7 +348,10 @@ PETRA.Worker.prototype.update = function(gameState, ent)
{
ent.setMetadata(PlayerID, "subrole", PETRA.Worker.SUBROLE_IDLE);
ent.setMetadata(PlayerID, "target-foundation", undefined);
if (this.baseID != gameState.ai.HQ.basesManager.baselessBase().ID)
// If worker elephant, move away to avoid being trapped in between constructions
if (ent.hasClass("Elephant"))
this.moveToGatherer(gameState, ent, true);
else if (this.baseID != gameState.ai.HQ.basesManager.baselessBase().ID)
{
// reassign it to something useful
this.base.reassignIdleWorkers(gameState, [ent]);

View File

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Entity parent="template_unit_support">
<Auras datatype="tokens">
units/elephant_worker
</Auras>
<Entity parent="builder|template_unit_support">
<Cost>
<BuildTime>15</BuildTime>
<Resources>