Do AI combat units found cities if settleAI and right flag?

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,753
Location
Calgary, Canada
I am looking at creating a Viking longswordsman unit that would be able to raze cities and settle the area right away... so I would give it an ability similar to the conquistador (except for the different continent flag).

My question is, if I give the unit an AI role similar to conquistador, will the AI settle with this combat unit? Does the AI use the conquistador properly? Or is it just the player who uses the ability.

Further to my question, I would give the "no settlers" part of the Venice trait to the vikings. As Venice gets a Merchant of Venice instead of a settler in the liberty policy tree, how can I adjust the vikings to be gifted a non-settler unit... I can find in neither Policies nor Units where this is done.

I always wonder about when the AI has units with these special abilities whether it actually uses them. The legion, for instance, can build roads... has anyone seen it? (I know it did not build forts previous to BNW because of hard-coding which has since been changed, but it ought to always have built roads).

Thank-you.
 
I don't think the AI settles cities at all with combat units, but I haven't investigated enough to tell for sure.

The code for giving Merchant of Venice is a bit here, a bit there, because it has to be in every place where you can get a settler. It's all the in the DLL though. Basically if you have a trait which sets IsNoAnnexing to true the game will try to give the player a unit with IsCanBuyCityState. If it can't find such a unit (that is valid for that civilization) then you will sometimes end up with a settler anyway and sometimes with no unit at all, depending on how the code is written for that particular case. (In the case of policy it gives nothing.)

Even if you end up with a settler you can't build more than one city with that trait, so your extra settler(s) will be useless.
 
As Venice gets a Merchant of Venice instead of a settler in the liberty policy tree, how can I adjust the vikings to be gifted a non-settler unit...

Like a lot of the "special abilities" added in G&K/BNW it's hard-coded in the DLL (in this case CvPlayer.cpp)

Code:
  // slewis
  // If we're Venice
  if (GetPlayerTraits()->IsNoAnnexing()) {
    // if we're trying to drop a settler
    if((eUnitAI == UNITAI_SETTLE) || (pkUnitInfo->GetDefaultUnitAIType() == UNITAI_SETTLE)) {
      // if we already have a settler
      if(GetNumUnitsWithUnitAI(UNITAI_SETTLE) >= 1) {
        // drop a merchant of venice instead
...

so you'd need some Lua to watch for settlers being "created" by that player, delete them and then add the replacement unit
 
I did some testing. I gave the Spanish the ability to survive without cities and did a test map. Removed their starting settler. Placed 8 conquistadors on map I made. None used the found city ability.

Just occured to me that the not on same continent as capital requirement may have caused a problem even though they did not have a city...

Incidentally, also test legions for Rome by not allowing them workers... they did not build roads or forts.

Makes me suspect the Samurai sea resource improvement ability will also be human player only.
 
I did some testing. I gave the Spanish the ability to survive without cities and did a test map. Removed their starting settler. Placed 8 conquistadors on map I made. None used the found city ability.

Just occured to me that the not on same continent as capital requirement may have caused a problem even though they did not have a city...

Incidentally, also test legions for Rome by not allowing them workers... they did not build roads or forts.

Makes me suspect the Samurai sea resource improvement ability will also be human player only.
If that is indeed so, that's really sad game making from Firaxis.
 
When looking for a civilian unit (settler, worker, merchant, etc), the AI only considers the unit's primary UNITAI_ type (which in most cases is the DefaultUnitAI value in the <Units> table entry) and not the secondary values (in the <Unit_AITypes> table), so the AI won't use combat units as civilians (eg for road building or settling new cities) if they have nothing better to do. If you try setting UNIT_SPANISH_CONQUISTADOR to default to UNITAI_SETTLE I suspect the reverse will happen - it will never use that unit for combat - and I also think the AI will get very confused as it tries to assign a combat unit as an escort for it!
 
When looking for a civilian unit (settler, worker, merchant, etc), the AI only considers the unit's primary UNITAI_ type (which in most cases is the DefaultUnitAI value in the <Units> table entry) and not the secondary values (in the <Unit_AITypes> table), so the AI won't use combat units as civilians (eg for road building or settling new cities) if they have nothing better to do. If you try setting UNIT_SPANISH_CONQUISTADOR to default to UNITAI_SETTLE I suspect the reverse will happen - it will never use that unit for combat - and I also think the AI will get very confused as it tries to assign a combat unit as an escort for it!
I then stand by my sentiment that it's really sad game making from Firaxis ...
 
Could lua or some other method be used to change the default AI in some random or logiceal way... for instance, every 50 turns, there might be a random choice based upon the AI flavor. So the default AI type would not be static

Probably not, as the database is already set.

Perhaps one could create two conquistadors, identical except for default AI. You could use some logic in lua to kill and replace the unit.

For example, an "explore" conquistador could be replaced by a settle conquistador if a natural wonder is discovered... or a worker legion replace an attack legion when no enemy unit near by...
 
How does unit AI relate to Mission assignment. I am a little ignorant about this whole thing... I presume the game engine looks at the default AI and selects from a subset of allowable missions weighed against various criteria.

If so, could a build or settle type mission be added to the attack AI for instance? And become a viable strategy to be chosen by th AI player for units with that default AI. And might that mission choice be restricted to those units with default attack AI that have settle or build abilities enabled. Would not want a unit with no builds to be assigned a build mission...

And how are missions assigned...are they static once assigned? If not, what causes changes in missions by the AI? If they change, then perhaps it does not matter if a unit is temperarily assigned a mission it cannot accomplish... its confused most of the time anyway :).

Anyhow just some questions I have to determine if the learning curve in pursuing this is too steep or not.

Ps I suppose lua could correct for when a unit gets a build mission, for example, but has no build ability...

Check mission, if build mission, check for unit build, if not build then push mission attack.
 
Can new default AI types be added ...

Not without adding code to the DLL that would understand what to do with those UNITAI_ types

However, some progress

that's an AI Roman Legion building a fort, and the one top left is heading to the wheat field to start building a road to Rome.

Still lots of issues to resolve (like stopping combat units running all over the place trying to build things - need to keep them close to where they are stationed) but it's a good start :D
 

Attachments

  • AiCombatWorkers.jpg
    AiCombatWorkers.jpg
    137 KB · Views: 349
As always, whoward, you are managing fantastic progress. I have a question, with the modifications you are doing, what's your approach? Are you writing these things in only for those units, are you changing the existing general AI options to check for these actions also, or are you allowing for secondary AI assignments, so that a unit can have both a combat AI label and a worker AI label and use either when appropriate?
 
Are you writing these things in only for those units
are you changing the existing general AI options to check for these actions also
or are you allowing for secondary AI assignments, so that a unit can have both a combat AI label and a worker AI label and use either when appropriate?
Which do you think ;)

The AI divides it's units by operation - settle, offense, defence, workers, patrol/explore, garrison, sentry. It only considers civilians when looking for workers. I've modified that code so I can control if it looks for civilians or combat units (but not both) and changed the operation sequence to - settle, offense, defence, workers(civilian), patrol/explore, garrison, workers(combat), sentry. Which makes any combat unit capable of doing a relevant task that is otherwise on sentry duty (ie running from hill to hill) perform that task. Combat workers are limited to looking for tasks within three tiles of themselves (configured in XML as it may need to be two or even one) - this is to stop all the units supposedly on homeland defence piling into one area and leaving the borders undefended. The changes should also work for the Samurai's new ability, but I've not tested that. Combat workers won't dedicate themselves to a task - they may half build a fort, leave it if something more important comes their way, and then come back to it later. Workers will also remove forts in they need to build farms, etc.

W
 
If I could see a conquistador settle, my life would be complete :).

Looking into it, but it's not as "simple" as getting combat units to do work!
 
I'm sure I've seen my Pioneer units settle on Terra maps, if only since Firaxis upped the the AIs efforts to settle new lands.
 
There's nothing I can find in the code that treats units with a secondary UNITAI_SETTLE value, ie not their DefaultUnitAi value, as settlers. Certainly when the AI gained Population (units with a low combat value to survive capture and a secondary settle ability) via my "Units - Population" mod (ie refugees from cities being razed) they used to just stand around doing nothing (so the mod now adds Settlers or Workers randomly for the AI instead of Population units). And having done some tests, if you give Spain 20 Conquistadors scattered across the map as starting units, it will build a settler to found the second city and not use a Conquistador - even on a map where the capital is on an island so small you can't put a second city on it - the settler will sail to an island with a Conquistador and settle there!
 
If I could see a conquistador settle, my life would be complete :).

Code:
PlotOpportunisticSettlementMoves for Isabella
  ... 1 possible units
    ... for unit at (63, 45)
    ... found 29 possible plots
    ... possible city plot at (63, 47)
      ... is 1 moves away
      ... here comes the city!
Trying to found a city with combat unit Conquistador at (63, 47)
  ... success!  They founded Salamanca

;)
 
Top Bottom