Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#4870 closed enhancement (fixed)

petra AI queueplanBuilding error when starting with entities of a different civ

Reported by: elexis Owned by:
Priority: If Time Permits Milestone: Alpha 23
Component: AI Keywords:
Cc: Patch:

Description

In this fortress replay (but not every fortress replay) with r20511 I get the following error spammed:

ERROR: JavaScript error: simulation/ai/petra/queueplanBuilding.js line 91
TypeError: builder is undefined
  m.ConstructionPlan.prototype.start@simulation/ai/petra/queueplanBuilding.js:91:3
  m.Queue.prototype.startNext@simulation/ai/petra/queue.js:60:3
  m.QueueManager.prototype.startNextItems@simulation/ai/petra/queueManager.js:374:6
  m.QueueManager.prototype.update@simulation/ai/petra/queueManager.js:407:2
  m.PetraBot.prototype.OnUpdate@simulation/ai/petra/_petrabot.js:121:3
  m.BaseAI.prototype.HandleMessage@simulation/ai/common-api/baseAI.js:64:2

Attachments (2)

commands.txt (4.4 KB ) - added by elexis 6 years ago.
ticket4870.patch (3.1 KB ) - added by mimo 6 years ago.

Download all attachments as: .zip

Change History (9)

by elexis, 6 years ago

Attachment: commands.txt added

comment:1 by elexis, 6 years ago

Hold on, actually not triggered with clean svn.

comment:2 by elexis, 6 years ago

Cc: mimo removed
Milestone: Alpha 23Backlog
Priority: Should HaveIf Time Permits
Summary: builder undefined in simulation/ai/petra/queueplanBuilding.jspetra AI queueplanBuilding error when starting with entities of a different civ
Type: defectenhancement

It was an off by 1 in my upcoming rmgen diff. It placed starting units and the starting walls for all civs on that Fortress map for a wrong owner.

The error can be reproduced on any map by spawning a unit of a different civ than the player civ. For instance using this:

Index: binaries/data/mods/public/maps/random/rmgen/player.js
===================================================================
--- binaries/data/mods/public/maps/random/rmgen/player.js	(revision 20512)
+++ binaries/data/mods/public/maps/random/rmgen/player.js	(working copy)
@@ -5,11 +5,11 @@
 /**
  * Gets the default starting entities for the civ of the given player, as defined by the civ file.
  */
 function getStartingEntities(playerID)
 {
-	return g_CivData[getCivCode(playerID)].StartEntities;
+	return g_CivData.brit.StartEntities;
 }
 
 /**
  * Places the given entities at the given location (typically a civic center and starting units).
  * @param civEntities - An array of objects with the Template property and optionally a Count property.

So it's not urgent at all but only a nice-to-have for weird maps or mods.

Since petra can already deal with owning things of other civs, it could be able to handle starting units of different civs too (unless there is some catch).

comment:3 by mimo, 6 years ago

Rather a simulation problem than an ai one: we should decide what is allowed to be built in that case (specially if we ever implement some unit capture). As i don't think that when capturing a unit we should have access to all structures of the captured unit but rather conversion of the captured unit to its new culture, we must change the replacement in Builder.js from the Identity civ to the player civ (as is done in ProductionQueue). If going that way, here is a patch with the needed changes in the ai (i've put the changes in rmgen from elexis to allow easy test of the patch). I'll add it to phabricator when the Builder.js change is agreed.

by mimo, 6 years ago

Attachment: ticket4870.patch added

comment:4 by elexis, 6 years ago

I'd love to hear sanderd17 and fatherbushidos opinion on the diff, but I guess that won't happen.

Other than that the diff should be in accordance with our current design idea that units can only build buildings of the civ they own, not buildings of the civs of the units the player owns.

Building buildings of other civs was only useful in cheat games for testing purposes with the "salad bowl" cheat. Perhaps there could be some mod that wants to allow this however (Delenda Est?).

We could make that design decision a template boolean in Builder of the three template_unit_* files: OnlyPlayerCiv or AllowUnitCivBuildings.

(Linting: Only one comment line in queueplanBuilding.js needs change, doesn't really matter though)

in reply to:  4 comment:5 by mimo, 6 years ago

OK see phab:D1065

Replying to elexis:

Perhaps there could be some mod that wants to allow this however (Delenda Est?).

We could make that design decision a template boolean in Builder of the three template_unit_* files: OnlyPlayerCiv or AllowUnitCivBuildings.

AI is not yet able to cope with such changes: nothing difficult to do a priori, but it would need somebody to do it

Edit: And such a behaviour in mods can be obtained by replacing the {civ} directly in the unit template.

Last edited 6 years ago by mimo (previous) (diff)

comment:6 by mimo, 6 years ago

Milestone: BacklogAlpha 23
Resolution: fixed
Status: newclosed

Fixed by r20521

comment:7 by elexis, 6 years ago

In 20527:

Fix Builder test following rP20521, refs #4870.
Also fix confusion of playerID and playerEntityID in that test following rP19488.

Differential Revision: https://code.wildfiregames.com/D1067
Reviewed By: bb, Itms
Comments By: Stan

Note: See TracTickets for help on using tickets.