Accessing AI attack planning information

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
I've been adding a lot of my own AI for some special units in my mod (I can move them around and make them do special actions). I'm just starting to add some combat function for these. I need to know:
  1. When an AI civilization is planning an attack, and on who.
  2. Any other info on that attack: where (an area? a city?), when, etc.
  3. Is a particular unit headed to that attack?
I'm not sure which of these pieces of information are accessible to us through Lua. I'm hoping that #1 might be available since the new espionage system is using this information. I'm not sure if #2 and 3 really exist (whether accessible or not). Does the AI have a target city? Does it have specific units assigned to an attack, or is it just any unit with AI_ATTACK?

I'd appreciate any tips here, no matter how small.
 
I was just browsing screenshots for DonQuiche's new api and noticed this function:

unknown pArea:GetTargetCity(int playerID)

Is it what I hope it is? A way to get the city that an AI is currently targeting for conquest? If so, perhaps it will even work before DoW when the AI is massing forces. I'll definitely investigate.
 
I've been adding a lot of my own AI for some special units in my mod (I can move them around and make them do special actions). I'm just starting to add some combat function for these. I need to know:
  1. When an AI civilization is planning an attack, and on who.
  2. Any other info on that attack: where (an area? a city?), when, etc.
  3. Is a particular unit headed to that attack?
I do not think any of those are accessible through Lua since it would make cheating in multiplayer very easy: you could just get a list of the ongoing unit moves your opponent ordered and their destinations

Now, regarding pArea:GetTargetCity, it's worth a try but I think it probably just returns the "default city" for that player on this continent (area). Even if it's probably not used in civ5 since units in enemy territory are teleported the their borders rather than into your capital.
 
I guess cheating in multiplayer scores very low on my priority list compared to being able to mod. But that's just me.

I can write a function to look for clustered enemy units and treat that as a hot spot for attention. That's fine for determining enemy focus, and necessary for AI defending against human. But it is very annoying to have to infer a particular AI's intent to control that AI's own units.

All I can say for pArea:GetTargetCity(iPlayer) so far is that it returns nil for all players for all areas. But I've been troubleshooting other issues through the first 30 turns and have not seen or staged a war yet.
 
Just wondering if anyone has info on this from the dll. First question is: is pArea:GetTargetCity(int playerID) related to the thread title? If not, can anyone point me in the right general direction in the dll? (I'm new to C++)
 
pArea:GetTargetCity(int playerID) doesn't appear to do anything.

One place to start is CvTemporaryZone in CvTacticalAI.h. It is used to set (temporary) targets for the AI.
 
I don't know about lua but from the c++ end (in the expansion dll), with a bit of speculation it looks like this:

-Each CvPlayer instance holds a set of CvAIOperation objects (AI missions, basically), which are cycled through with getFirstAIOperation() and getNextAIOperation()
-Each CvAIOperation has a type accessed with GetOperationType()
-The list of types is located in CvAIOperation.h line 21. Several of them are city attacks (AI_OPERATION_BASIC_CITY_ATTACK, AI_OPERATION_SNEAK_CITY_ATTACK...)
-If the operation is a city attack, then you can read the target plot with GetTargetPlot() (also works for any other operation that has a clear target plot)
-The CvPlot class defines the isCity() and getAdjacentCity() methods to get the actual instance of CvCity

However, I'm not sure that the plot returned by GetTargetPlot() is necessarily the plot of the city itself. At some point in the code, a dev added in some comments:
// Reset our destination to be a few plots shy of the final target
// See if reached our target, if so give control of these units to the tactical AI
It may well be that the target plot is only in the vicinity of the target city and that the AI just dumps its army there and it will in turn attack everything surrounding it, including the city. If that is the case, you will have to scan nearby plots for a city.
 
Back
Top Bottom