SDK Force Unit to Attack City

tkunze

Chieftain
Joined
Dec 5, 2015
Messages
2
Location
Germany
Hello,

i am working on an enhanced AI mod for Civ4 BTS using the SDK. I figured out how i can sent the units to a destination - so currently AI units move to cities at the border
and do not stay idle somwhere far away, like they do with the default AI.

This works fine with the code below.

Code:
unit->getGroup()->pushMission(MISSION_MOVE_TO, target->getX_INLINE(), target->getY_INLINE());
unit->getGroup()->setActivityType(ACTIVITY_MISSION);

But now i want ot force some of the units to attack enemy cities. There is now mission i could find for this. And if i just move the units close to an enemy city it appears they behave unpredictable.

Any help on this would be highly appreciated.
 
From what little I know about the Unit AI: Units that are supposed to attack cities should have their m_eUnitAIType set to UNITAI_ATTACK_CITY. This leads to CvUnitAI::AI_attackCityMove getting called. attackCityMove then calls stackAttackCity, bombardCity or goToTargetCity, the target city being selected by pickTargetCity. The selection in pickTargetCity is based on opportunity and CvArea::m_aTargetCities – A->getTargetCity(P) says which city CvPlayerAI P wishes to conquer most on continent A.

In terms of missions, as far as I can tell, both goToTargetCity and stackAttackCity push MISSION_MOVE_TO; bombardCity pushes MISSION_BOMBARD.
 
Thanks a lot for you're help on this - I have not thought about the Area at all - but it seems this has an heavy influence. I will also play around with the UNITAI parameter.

Also the stackAttackCity you mentioned above looks promising. I will play around with this.

At the moment i implemented a per unit logic. But it seems quite a lot is build on a stack logic.
So i have the guess that the AI does not attack because my single unit is not considered strong
enough to attack (there is a power treshould in the stackAttackCity method).
 
Back
Top Bottom