MissionAI's

TheLadiesOgre

Aspiring Codesmith
Joined
Jan 16, 2009
Messages
505
Where the bloody hell do I find how they are defined. I have been all through the sdk by "Find in Files-- MissionAI" and I've found a whole lot of stuff that is very informative, though not what I need right now. What I need to know is how does the AI determine what to do on each MissionAI. Where does it say "if this unit has MISSIONAI_BLAH_BLAH then behave like this". Does it not say this anywhere? If it doesn't, which of the MISSIONAI's correlates to "go over there to so-and-so's city on the other side of the same continent and attack it either until you take it or die" If there isn't one like that can I just plug a new one in like this:

Spoiler :
Code:
enum MissionAITypes		// Exposed to Python
{
	NO_MISSIONAI = -1,

	MISSIONAI_SHADOW,
	MISSIONAI_GROUP,
	MISSIONAI_LOAD_ASSAULT,
	MISSIONAI_LOAD_SETTLER,
	MISSIONAI_LOAD_SPECIAL,
	MISSIONAI_GUARD_CITY,
	MISSIONAI_GUARD_BONUS,
	MISSIONAI_GUARD_TRADE_NET,
	MISSIONAI_GUARD_SPY,
	MISSIONAI_ATTACK_SPY,
	MISSIONAI_SPREAD,
	MISSIONAI_SPREAD_CORPORATION,
	MISSIONAI_CONSTRUCT,
	MISSIONAI_HURRY,
	MISSIONAI_GREAT_WORK,
	MISSIONAI_EXPLORE,
	MISSIONAI_BLOCKADE,
	MISSIONAI_PILLAGE,
	MISSIONAI_FOUND,
	MISSIONAI_BUILD,
	MISSIONAI_ASSAULT,
	MISSIONAI_CARRIER,
	//TLO: AI Land Transport Usage Start
	MISSIONAI_PICKUP,
	MISSIONAI_ASSAULT_LAND
	//TLO: AI Land Transport Usage End
};

and then plug it into all of the relevant places in my additions? Would I then be able to do something like this following pseudocode:

Spoiler :
Code:
if (pLoopUnit == (UNITAI_ATTACK || UNITAI_PILLAGE))
{
	if (AREAAI != (AREAAI_DEFENSIVE || AREAAI_NEUTRAL))
	{
		if ((kPlayer.getNUMUnitInfos(UNIT_TRANSPORT_CHOPPER) > 0) && (bLandWar))
		{
			pLoopUnit->setMissionAI(MISSIONAI_ASSAULT_LAND)

I know that there is enough combined C++ genius on this forum to get this accomplished right and working beautifully. I know it may be a lot of work and I am willing to do it, if the community if willing to bear with me and my question (and lend suggestions, tips, pointers)
 
Unfortunately the MissionAI code (ie - What actions a unit actually takes during a turn) is scattered all over the place. There is no single "Choose your actions" function anywhere. The closest to that would be CvUnitAI::AI_update(), which links to UnitAI. But it is the UnitAI which dictates the Mission which is pushed, and it is when you push a mission that you assign a MissionAI. Then the mission AI does its thing everywhere that is required to manage to get the job done. If it takes multiple turns, then the unit flags on some type of AUTOMATE status so it doesn't try to return to human control or AI decision processing.

I suppose CvSelectionGroup::continueMission nearly does what you are looking for, but first you still have to have processed through UnitAI to get the Mission assigned in the first place.

So basically, to teach the AI new tricks, start with UnitAI, work up from there.
 
Top Bottom