1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

CivOne Request: AI City building Logic

Discussion in 'Civ1 - General Discussions' started by fire-eggs, Jul 31, 2019.

  1. fire-eggs

    fire-eggs Chieftain

    Joined:
    Jun 19, 2019
    Messages:
    33
    TLDR: seeking detailed "what should this city build next" logic for AI players in CivOne

    I've been working on moving SWY's CivOne re-creation forward, fixing bugs and adding missing features. [You can find the releases on Github here]. I've started writing the AI players' unit movement logic, mostly thanks to darkpanda's reverse-engineering.

    A blockage I have is what logic to use for the AI city production. SWY has simple build logic in place, but isn't very close to Microprose's behavior [which I'm aiming for, initially]. darkpanda's reverse engineering has a reference to a function selectCityProduction , but no code for said function.

    I'm looking for some detailed ideas for how the AI City production logic would work, ideally approaching the original Microprose logic. Since it is tied to available advances, the AI logic for which advance to research should be included [right now is pure random].

    The Civilization behaviors need to be taken into account: Aggression, Development, and Militarism. Essentially a 9-value matrix to dictate which research / unit the civilization would likely target. You can see all the values at the bottom of this : https://www.civfanatics.com/civ1/cia/allcivs.htm

    [If you have questions or comments on CivOne in general, please go to this topic.]

    My thanks in advance!
     
  2. tupi

    tupi Chieftain

    Joined:
    Jun 25, 2011
    Messages:
    60
    Location:
    Russia
    So I should post in this topic when it will be ready. For now I can say only that
    1) Ghidra cannot decompile this function (at least at my machine and from .05 version of civ), so I'm trying to understand it from disassembly only, which is much harder
    2) this function is enourmous. It consists of 'draw selection menu'/what AI can build part and 'ai chooses what to build' part (also used for AUTO regime). First of them is pretty simple, but nothing interesting is here. But I found that game indeed has an additional check for nuclear fission tech for Nuclear unit. All these years I thought that 'and Nuclear Fission' in Civilopedia is an allude to Manhattan Project and nothing more.
    3) there're many still unknown flags/variables, some of them with pretty abstract meaning, like 'despotism desire' or 'republic desire'.
     
    Last edited: Apr 19, 2020
  3. fire-eggs

    fire-eggs Chieftain

    Joined:
    Jun 19, 2019
    Messages:
    33
    My thanks for the update, and sorry for the late reply. I started poking at the disassembly, but was dragged away by other priorities. I'm looking forward to any and all updates!
     
  4. tupi

    tupi Chieftain

    Joined:
    Jun 25, 2011
    Messages:
    60
    Location:
    Russia
    Here we go again.
    https://pastebin.com/1X7AvpkP
    I think that code to select a city which should build a new palace exists in game, but somewhere else. Also probably game uses some other code to build SS components and SS modules (and it probably's cheating hard with them). But apart from that, everything is here.

    Some simplest rules from it:
    1) AI doesn't build Carriers
    2) AI doesn't build Militias if government's not despotism
    3) AI doesn't build nukes, if it already has 4 of them or 2 under construction
    4) if AI has 0 units and its government is despotism, it always builds militia (even if it's obsolete!). This rule doesn't seem to work, because when city is founded, settler is not destroyed immidiately (for example, you can see it on city screen).
    5) AI cannot build air and sea units if its total defence power on continent is less than 8 (hello, English on Earth map)
     
    Last edited: Jun 6, 2020
  5. Mize

    Mize Warlord

    Joined:
    Jun 17, 2011
    Messages:
    292
    But... I've seen an AI carrier! True, it happened only once in over 25 years of playing, and it probably was some sort of overflow, which caused the AI to build one.
     
  6. fire-eggs

    fire-eggs Chieftain

    Joined:
    Jun 19, 2019
    Messages:
    33
    Wonderful! Another step forward!

    Re: your comment on the usage of DX:
    //1ade:06d4 MOV DX,word ptr [BX + CITIES_BUILDINGS2]

    First, we might be looking at slightly different apples. The line you mention is at
    1ADE:06CF in my disassembly, which is from Civ.01 (which matches DarkPanda).
    But I think it's all close enough that the differences won't matter.

    Second, I think what we're seeing is the compiler using AX,DX as a pair of
    registers in order to handle a 32-bit value. I.e. the registers are set from a pair
    of 2-byte addresses, read into a pair of 2-byte addresses and so on.
     
  7. tupi

    tupi Chieftain

    Joined:
    Jun 25, 2011
    Messages:
    60
    Location:
    Russia
    Well, I use Civ.05 (as I more interested in its 'final' rules), so it should be different.

    Thank you for your suggestion about AX/DX pair. It looks more clear for me now. I don't understand assembly quite well, so for me it was just some very strange code. I mostly use decompiled c code in Ghidra, but whenever some, how to name it... "table jumps" happen (probably when switch was in original code) it cannot decompile anything and even skip such parts in disassembly (they should be 'manually' disassembled, which means I just need to press D key, but anyway). Probably free version of IDA is better in such cases, for disassembly only.

    BTW, I still did not find any code for palace building (very unlikely that it's in overlays or in not disassembled skipped parts). It can be that AI doesn't care if it does not have a palace and only can build it by chance, when all other options are less preferred. I only have found that if AI finished palace construction, it immidiately changes production to barracks, so it can select new production (without that, AI city would continue to build a palace endlessly).
     

Share This Page