How can I teach the AI to...

Ninja2

Great Engineer
Joined
Nov 17, 2005
Messages
1,142
Location
Denmarkia
...send workers to overseas unclaimed territory? I want the AI to send a worker along with a settler, so it will start improving a new city right away.
 
It should already do this provided the transport ship has at least three cargo slots (settler, worker, defensive unit). The code is there for it, anyway.
 
I see. Where should I look in the code for this? I am on a mission to clone this behaviour for something else... ;)
 
The AI_workerMove method in CvUnitAI.cpp has code for loading workers onto ships.

Code:
	if (!isHuman())
	{
		if (plot()->getOwnerINLINE() == getOwnerINLINE())
		{
			if (AI_load(UNITAI_SETTLER_SEA, MISSIONAI_LOAD_SETTLER, UNITAI_SETTLE, 2, -1, -1, 0, MOVE_SAFE_TERRITORY))
			{
				return;
			}
		}
	}

For reference, the definition of AI_load looks like:

Code:
bool CvUnitAI::AI_load(UnitAITypes eUnitAI, MissionAITypes eMissionAI, UnitAITypes eTransportedUnitAI, int iMinCargo, int iMinCargoSpace, int iMaxCargoSpace, int iMaxCargoOurUnitAI, int iFlags, int iMaxPath)

So, from my understanding, it'll load workers provided:

- There are at least two units already on the ship
- At least one of those is a settler
- There are no workers currently on the ship
 
Thanks a lot, I will start by studying that bit of the code. I expect that I can limit my work with this to the CvUnitAI files.
 
Top Bottom