C2C AI discussion - Animal Units

Joined
Jul 5, 2004
Messages
23,562
Location
Canberra, Australia
Purpose: This thread is here to discuss the AI for all animal units.

I am dividing the units into Wild, Subdued and Domesticated. Where Domesticated units are those animal units built, subdued are those animal units captured and wild are those spawned.

Assumptions:-
  1. It is possible for the AI to know is a unit has orders or not.
  2. First priority is to get the unit safely back to the owner's cities
  3. Second priority is to use the unit, if possible, to build a building.
  4. Otherwise store the animals until some event e.g. acquire technology, build a city or city borders expand.

Some of this will sound like a cross between English and program speak. It is just the way I am.

As far as I can tell the order things happen in a game turn are
  • onBeginGameTurn event
  • other events
  • onEndGameTurn event (check name)
  • give orders units without any
  • move all units which already have orders.



Get the unit safely home
If the unit is in cultural boarders or one move from cultural boarders then move to nearest city.
If unit is wounded heal. Note: if unit is "in the wild" it would be nice to use the worker wake when in danger AI to wake and move the unit to safety.
If unit can't get to a city set to Explore. (see events Open Borders and Build City)​

Mammoth
Mammoth units are special because of the wonder. It affects everything about what we do with these units.

If player has built the Mammoth Wonder go to that city and "upgrade unit".
If there are any player cities with tundra in the vicinity (now or potential) with out Ivory in the vicinity and without a Mammoth Herd. Go to biggest and build Mammoth Herd.
If biggest three (five if Military?) cities don't have a Master Hunter go to biggest and build Master Hunter.
If have too many Mammoths build (priority order
  • Master Hunter in this city or nearest city without one.
  • Carnival in this city or nearest unhappy city without one
  • Exotic Herbivores in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
Otherwise "sleep".

Camel
If player has built the Camel Trainer go to that city and "upgrade unit".
If the Myth building for the unit has not been built go to capital city and build it.
If there are any player cities with desert in the vicinity (now or potential) with out Camels in the vicinity. Go to biggest and build Camel Herd.
If have too many Camels build
  • Carnival in this city or nearest unhappy city without one
  • Exotic Herbivores in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
    Otherwise "sleep".

Horse and Elephant
If player has built the Horse Trainer go to that city and "upgrade unit".
If the Myth building for the unit has not been built go to capital city and build it.
If have too many Horses/Elephants build
  • Find biggest city without horses/ivory in the vicinity, go there and build Horse/Elephant Herd. (Note: try an not build the elephant herd near tundra?)
  • Carnival in this city or nearest unhappy city without one
  • Exotic Herbivores in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
    Otherwise "sleep".

Cheetah and Lion (not Cave Lion or Lion Pack)
Cheetahs are made to be pets. given the current game (Subdue Animals mod) set up single lions are also designed to be pets.

If the Myth building for the unit has not been built go to capital city and build it.
Find most unhappy city which does not have Governor Pets or Governor Menagerie go there and build the building.
If to many units Big Cat Cage or Animal Standard(Totem) in best city.
Otherwise "sleep"

Cave Lion, Lion Pack, Cave Bear and Polar Bear
The sign of a good hunter, these units are designed to build Master Hunter buildings

If the Myth building for the unit has not been built go to capital city and build it.
If biggest three (five if Military?) cities don't have a Master Hunter go to biggest without and build Master Hunter.
If biggest three (five if Military?) cities don't have a Animal Standard(Totem) go to biggest without and build Animal Standard(Totem).
If to many units build
  • Master Hunter in this city or nearest city without one.
  • Big Cat/Bear Cage in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
  • Find most unhappy city which does not have Governor Pets or Governor Menagerie go there and build the building.
Otherwise "sleep"

Bear and Panda Bear
As with Cave Bear except build Dancing Bear before trying to build Bear Cage.​

Hyena
If biggest three (five if Military?) cities don't have a Animal Standard(Totem) go to biggest without and build Animal Standard(Totem).
If to many units build
  • Wolf Cage in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
  • Find most unhappy city which does not have Governor Pets or Governor Menagerie go there and build the building.
Otherwise "sleep"

Dire Wolves
The sign of a good hunter, these units are designed to build Master Hunter buildings

If the Myth building for the unit has not been built go to capital city and build it.
If biggest three (five if Military?) cities don't have a Master Hunter go to biggest without and build Master Hunter.
If biggest three (five if Military?) cities don't have a Kennels go to biggest without and build Kennels.
If biggest three (five if Military?) cities don't have a Animal Standard(Totem) go to biggest without and build Animal Standard(Totem).
If to many units build
  • Master Hunter in this city or nearest city without one.
  • Kennels in this city or nearest city without one.
  • Wolf Cage in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
  • Upgrade
  • Find most unhappy city which does not have Governor Pets or Governor Menagerie go there and build the building.
Otherwise "sleep"

Wolves
If biggest three (five if Military?) cities don't have a Kennels go to biggest without and build Kennels.
If biggest three (five if Military?) cities don't have a Animal Standard(Totem) go to biggest without and build Animal Standard(Totem).
If to many units build
  • Kennels in this city or nearest city without one.
  • Wolf Cage in this city or nearest unhappy city with carnival but without one
  • Animal Standard(Totem) in this city or nearest city without one.
  • Upgrade
  • Find most unhappy city which does not have Governor Pets or Governor Menagerie go there and build the building.
Otherwise "sleep"

Crocodiles
A bit special since their Myth building may not be able to be built because it is not on the coast.​

Gorilla and Orangutan
Myth and Pets.​


Event: On city work radius expands
If work radius now contains tundra wake all Subdued Mammoth units.
If work radius now contains desert wake all Subdued Camel units.

Waking the unit removes orders so that the AI will apply the correct actions to the unit.​

Event: On build city
If potential work radius contains tundra wake all Subdued Mammoth units.
If potential work radius contains desert wake all Subdued Camel units.

If any units are on Explore and can get to this city change their orders to go to this city.

Waking the unit removes orders so that the AI will apply the correct actions to the unit.​

Event: Open Boarders agreement made
If any subdued animal units are on Explore wake them.

Waking the unit removes orders so that the AI will apply the correct actions to the unit.​

Event: Acquire Technology Trade
Starting with Subdued Giraffe units build Carnivals.

How many cities are there? If there are more Giraffes than cities send a Giraffe to each city and build a Carnival.​

Event: OnEndgameTurn
Check if there are too many animal units and activate extras. The number that is to many is based on techs so that by Trade+ any subdued animal is to many.
  • at Tech Trade + one: All subdued animal units are surplus
  • at start of game 3 except for herd units and units that will later upgrade then 5
  • at Dog Domestication herd only animals become to many at 3
 
Upgrade subdue animals to fighting units

Do we need a special function to do this if the player does not have enough money?

E.g. unit goes to city to be upgraded. When there it is replaced with the upgrade unit but can't move for 2-5 turns like the events that stop units moving, bandits and repair ship.



Wild animals and Barbarian Subdued animals

Nothing needs to be done for wild animals but barbarian subdued animals may require some actions.

Should they go back and build a "Mater Hunter" building so that the barbarians can build those extra units?

Should the Subdue Animals mod not create subdued animals for the barbarian player, ie only capture as wild instead?
 
Tracker, Hunter and Ranger units

Do we need to add AI to recon units that are on explore and hunt to make them escort wounded subdued animals back to safety? Especially, if the animal caught can build a Master Hunter and one does not yet exist in the civ.

For recon units should we move them back to be upgraded?

Domesticated units - i.e. trained animal units

Does the current AI work? I think so. As Hydromancerx says it may work with standard BtS but not to the best with C2C. The Dog units are the best counter to the Thief/Rouge/Assassin/Ambush units so it would be better if they stayed close to home.

Current Suggestion

The AI should try and build the Dog units in cities with kennels. They should keep 3 per city on "Defend Cities" or "Patrol Boarders" any extras can be used as they are now.
 
A few things ...

1. It should be Wild, Subdued and ... "Domesticated" or "Tame". saying "Dog" just confuses things.

2. I like then things are done in lists or "program speak". its much easier to sort out then a huge paragraph. Thus I appreciate you doing it this way.

3. I don't know enough to comment about "Assumptions".

4. Sounds good.

5. That seems logical for the mammoth code.

6. This seems logical however what about when saving units for the Carnival? Do they become active again once you get the appropriate tech.

7. Sounds good.

8. Looks like this answered #6.

9. Cool.

10. Yes and they should be upgraded if there are too few units. Such as when a city has been attacked and is low on units.

11. I am not sure what to do about barbarians. It seems that they are all about battle and I would think they would use units to attack you rather than saving them up for buildings.

12. Yes that would be helpful. However I think it should not be for every unit they get. Perhaps after 5 units are traveling with him he will bring them back to the city. This means more exploration time and a buffed stack of tracker with subdued animals helping out.

13. Yes, but I think the "Canine" units should stick to the city more and act like guard dogs to look for thieves/rogues/assassins.

14. How would this automation work?
 
A few things ...

1. It should be Wild, Subdued and ... "Domesticated" or "Tame". saying "Dog" just confuses things.

2. I like then things are done in lists or "program speak". its much easier to sort out then a huge paragraph. Thus I appreciate you doing it this way.

3. I don't know enough to comment about "Assumptions".

4. Sounds good.

5. That seems logical for the mammoth code.

6. This seems logical however what about when saving units for the Carnival? Do they become active again once you get the appropriate tech.

7. Sounds good.

8. Looks like this answered #6.

9. Cool.

10. Yes and they should be upgraded if there are too few units. Such as when a city has been attacked and is low on units.

11. I am not sure what to do about barbarians. It seems that they are all about battle and I would think they would use units to attack you rather than saving them up for buildings.

12. Yes that would be helpful. However I think it should not be for every unit they get. Perhaps after 5 units are traveling with him he will bring them back to the city. This means more exploration time and a buffed stack of tracker with subdued animals helping out.

13. Yes, but I think the "Canine" units should stick to the city more and act like guard dogs to look for thieves/rogues/assassins.

14. How would this automation work?

I started writing that at 4am because I could not sleep thinking about it. Once I had gotten a good start I could sleep. :)

1. but there are only Dog units the rest have humans in them:mischief:.

11. Currently Barbarian Subdued animals only occur when a barbarian unit successfully captures a subdued unit. It can enter your territory and attack your workers!

I was suggesting that either the captured unit should be wild or given orders to go to the nearest barbarian city and build a Master Hunter so that that city can now build trackers etc.

12. Is going to be awkward anyway because when I am escorting units back I will use the "hunter" to attack and maybe capture a wild animal if I can then move the accompanying units to the hunter for safety.

13. I agree. Basically what I thought. they should be given the "Defend Cities" or "Patrol Boarders" command. Also the civ should try and build them where there are Kennels and only have dogs numbering 3 (or 5) times the number of cities.

14. Basically the same as this but for the player.
 
I will come back with much more to say on the process of implementing these in-depth ai adjustments. It can be done but will take a lot of time to program correctly I think. And some of the process must be made more generic - I'll explain more on how we can do this later.

I believe that automation is simply asking the game to consider the actions of the unit as if you were any other AI. (at least I believe automation buttons commonly ask the unit to follow the same routines the ai would use). Thus when the advisor suggests a building, you get to see what the computer would have done if it were YOU. (or would have at least strongly considered doing vs its other top suggestions also shown.)

Cloned portions of existing coding may be able to be pieced together create a faster proxy and a template from which adjustments can be made, which would allow us to tinker towards a final goal while initiating something that generally covers the idea. This may be the way to begin such a project.
 
I will come back with much more to say on the process of implementing these in-depth ai adjustments. It can be done but will take a lot of time to program correctly I think. And some of the process must be made more generic - I'll explain more on how we can do this later.

I believe that automation is simply asking the game to consider the actions of the unit as if you were any other AI. (at least I believe automation buttons commonly ask the unit to follow the same routines the ai would use). Thus when the advisor suggests a building, you get to see what the computer would have done if it were YOU. (or would have at least strongly considered doing vs its other top suggestions also shown.)

Cloned portions of existing coding may be able to be pieced together create a faster proxy and a template from which adjustments can be made, which would allow us to tinker towards a final goal while initiating something that generally covers the idea. This may be the way to begin such a project.

Oh, yes. If I had more time to write it I would have said that the priority for the buildings should be based on the priority of the buildings taking into account the civ traits and flavors.

However it is not all buildings and not all buildings/upgrades may be available when you get the unit so we need to build in both some wait for latter use and lets get rid of these ASAP as they should be "obsolete".;)

Anyway as I know from experience, getting something/anything written down to start with is almost as hard as getting the final stuff programmed. People haven't even started on their wish lists yet.

Edit: All subdue units have AIs of UNITAI_ENGINEER. They currently sometimes build the master Hunter building but they don't seem to build any other buildings. Note that none of the buildings will be chosen to be built by the city AI because they can't be built in the normal manner but must be created by destroying a unit.
 
I've noticed that and had put the portion of the engineer ai into the animal ai IF the animal is not a barbarian for that reason.

It would just take a bit of tinkering with that portion of the code to get them to want to use it for that purpose a bit more than they would want to if it were actually an engineer (which they'd only use on an extremely long build).

Also... aren't you putting a slaughter button in place too?
 
I've noticed that and had put the portion of the engineer ai into the animal ai IF the animal is not a barbarian for that reason.

It would just take a bit of tinkering with that portion of the code to get them to want to use it for that purpose a bit more than they would want to if it were actually an engineer (which they'd only use on an extremely long build).

Also... aren't you putting a slaughter button in place too?

Afforess wrote some AI to automate caravans to go to a city and help build the building there. May be that is a better starting point. Maybe we need a new UNITAI also.

The slaughter button will be implemented but maybe not for the next release. It requires changes to the same bit of code that is being modified for the Galactic Era ie CvMainInterface.py.

For a more generic approach perhaps the logic goes something like
  • Can I upgrade to a fighting unit
  • what type of buildings can I (the animal) build - cultural, revolutionary, military...
  • which ones can I build now and which ones can I build later
  • are there too many units like me waiting for a tech to be discovered
  • are there any cities about that need one of my buildings
  • are there any cities around that can use my building...
  • choose what to do
 
Just an update: I have started working on a simplified version of this, in Python. Currently all it does is heal the unit and move it to the nearest city.:) I have not yet figured out the code to get the unit to build a building. It may be possible to do it using the "great works" stuff. Not sure.
 
You know... since this is the overall animal thread now, I'm going to come back later with a LOT to say on some suggested adjustments here. Some of those require the creation of some new promotion buttons but that'll be half the fun :)
 
You know... since this is the overall animal thread now, I'm going to come back later with a LOT to say on some suggested adjustments here. Some of those require the creation of some new promotion buttons but that'll be half the fun :)

I have noticed that the slave unit is also not being used properly by the AI.

the last time I tried to add promotions the game started to CTD at start up :(
 
Well The camel only had Arctic Combat I and not Desert Combat I (which as a desert animal it should have). So when i would subdue it in the middle of the desert it dies before it can get out of the desert.

Post your logs, (PythonDbg.log) I put traces in there to make sure it all did. Did it have the desert promotion before I wonder and my second setting of it turn it off?
 
I hope this is the right thread but i wanted to discuss your Megafauna Units as well as mounted units in general. First a layout of the current strengths of the mounted units.

War Rhino = 4
Chariot = 4
Horseman = 5
Deer Rider = 5
Bear Rider = 6
Rhino Rider = 6
Mammoth Rider = 6
Mounted Infantry = 6
Camel Rider = 7
Camel Archer = 7
Bandit Rider = 8
Light Calvary = 8
Deer Archer = 8
Giraffe Archer = 8
Horse Archer = 8
Batista Elephant = 8
War Mammoth = 9
Camel Knight = 10
Knight = 11
Heavy Calvary = 13
Mailed Knight = 14
Cuirassier = 21
Calvary = 27

Overall I think these look good. However there are a couple thing I think should be changed ...

1. The bear rider seems to have pink graphics in my game. In addition I am not sure how well a bear would like to be "ridden". I can understand a herbivore like a deer or even a rhino, but a bear may be a bit too far fetched as a mount. But that aside the graphics seem to be the major factor in my request to remove it.

2. Since the Rhino Rider comes so late I think it should be a bit stronger. Possibly on par with the War Mammoth, so maybe Strength 9. Either that or have it not come so late in the game like the Mammoth Rider. Personally i wish it went ...

War Rhino -> Rhino Rider -> Rhino Knight -> Cuirassier

With the Rhinos being mounted units rather than Melee.
 
Back
Top Bottom