[GS] Getting AI to use customized builder unit

NotThatOneGuy

Chieftain
Joined
May 4, 2019
Messages
4
I made a builder identical to the vanilla Builder, except he only has 1 build charge. I gift him to players (human and AI) with a lua script. Everything is working fine, except the AI refuses to use the custom Builder unless he is both able to be trained in a city and cheaper than the vanilla Builder. When I give them it at the start when they refuse to use it, all the AI's send the custom Builders to a random point on the map (I assume it is point (0, 0)?), and just builds a vanilla Builder to improve the first tiles instead.

I don't want the custom Builder to show up in the UI for building new units in cities. If I mark it with CanTrain="false" in the Units table while creating the unit, it works fine for me and doesn't show up as a buildable unit (as I wanted). However, the AI refuses to use it. The (useless) price of the custom Builder makes no difference.

If I leave the custom Builder in the UI for building new units in cities, but put their cost at 55 gold (+5 from the vanilla Builder), the AI refuses to use it again.

However, if I leave the custom Builder in the UI for building new units in cities, but put their cost at 45 gold (-5 from the vanilla Builder), the AI uses it immediately just fine. However, it will also build that custom Builder instead of the regular Builder, despite that it has only 1 charge.

Anybody know what might be going on or how to fix it?

Below are the properties/data used for the custom Builder (with price = 1, CanTrain=false):

Spoiler Code :

INSERT INTO Types (Type , Kind )
VALUES ('UNIT_FREEBUILDER' , 'KIND_UNIT' );

INSERT INTO Units (UnitType , Cost, BaseMoves , BaseSightRange , ZoneOfControl , Domain , FormationClass , AdvisorType , Name , Description , CanCapture , CostProgressionModel , CostProgressionParam1 , CanTrain , PurchaseYield , BuildCharges)
VALUES ('UNIT_FREEBUILDER' , '1', '2' , '2' , 0 , 'DOMAIN_LAND' , 'FORMATION_CLASS_CIVILIAN' , 'ADVISOR_GENERIC' , 'LOC_UNIT_BUILDER_NAME' , 'LOC_UNIT_BUILDER_DESCRIPTION' , 0 , 'COST_PROGRESSION_PREVIOUS_COPIES' , '4' , 0 , 'YIELD_GOLD' , '1' );


INSERT INTO UnitAiInfos (UnitType , AiType )
VALUES ('UNIT_FREEBUILDER' , 'UNITAI_BUILD' ),
('UNIT_FREEBUILDER' , 'UNITTYPE_CIVILIAN' );

INSERT INTO UnitCaptures(CapturedUnitType , BecomesUnitType )
VALUES ('UNIT_FREEBUILDER' , 'UNIT_FREEBUILDER' );

INSERT INTO TypeTags(Type , Tag )
VALUES ('UNIT_FREEBUILDER' , 'CLASS_LANDCIVILIAN' ),
('UNIT_FREEBUILDER' , 'CLASS_BUILDER' );

INSERT INTO Units_XP2 (UnitType , CanEarnExperience , CanFormMilitaryFormation )
VALUES ('UNIT_FREEBUILDER' , 0 , 0 );
 
You are likely running into issues with how the game's controlling DLL is programmed to "run" AI units. The AI is going to build the least expensive unit it can that has Builder Charges when it decides it needs to do "infrastructure", regardless of the actual cost-benefit of the number of production-cogs vs the number of build charges. Having the CanTrain column set to false appears to acts as an additional signal within the game's DLL that the unit is a Great Person instead of a regular-type unit, especially given that the only base-game units that have CanTrain set to false are great people units. The DLL probably also looks for the least-expensive unit-type to do Builder stuff from those it currently has or can have, when giving existing units instructions on what to do.
 
You are likely running into issues with how the game's controlling DLL is programmed to "run" AI units. The AI is going to build the least expensive unit it can that has Builder Charges when it decides it needs to do "infrastructure", regardless of the actual cost-benefit of the number of production-cogs vs the number of build charges. Having the CanTrain column set to false appears to acts as an additional signal within the game's DLL that the unit is a Great Person instead of a regular-type unit, especially given that the only base-game units that have CanTrain set to false are great people units. The DLL probably also looks for the least-expensive unit-type to do Builder stuff from those it currently has or can have, when giving existing units instructions on what to do.

That's odd. I do have it labelled as a builder unit for the AI under UnitAiInfos. Is there another way to prevent it from being produced in a city without using CanTrain, so it still recognizes it as a Builder? If there's another way to disable it like that, I can just leave the price at 1 to make sure it uses it when I gift it to them.

I tried looking for UnitManager functions that could just change the build charges on the vanilla Builder, but I couldn't find any.
 
Back
Top Bottom