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

AI logic: revolutions/government change

Discussion in 'Civ1 - General Discussions' started by tupi, May 11, 2020.

  1. tupi

    tupi Chieftain

    Joined:
    Jun 25, 2011
    Messages:
    60
    Location:
    Russia
    So, how and when AI civs changes their government.

    1) every turn (after main city loop) AI checks if anarchy flag (diplomacy bit 'ALLY' with barbarians) is 1. If it's so, it calls 'change govt' function which in this case just sets anarchy flag to 0. This means that AI revolution always takes 1 turn. If you have embassy, you will get 'AI government changes to X!' message here.

    2) human player, on the other hand, doesn't use this anarchy flag and instead changes its government to ANARCHY (0) during revolution. AI never goes through the anarchy as government number 0, it sets new govt immediately and instead of 'true anarchy' it just sets 'anarchy flag' to 1. Game uses 'anarchy flag' for human player only for 'democratic government collapsed' event. In this case, when game should give you a new govt selection menu it instead just sets 'anarchy flag' to 0. That's why in this case the anarchy period is much longer (8 turns max instead of 4).

    3) AI tries to change its govt every 8th turn, if remainder of (civ_number+game_turn)/8 is 0 (also if civ is not barbarians and not with bit flag 'human player'). If AI chose some govt, it will call 'change govt' function. If 'new' govt is different from the old one, you will get message 'The AI government has been overthrown!' and anarchy flag will be set to 1. Replay entry is also recorded here (when AI goes into anarchy state, not when it goes from it!). But even if 'new' govt is the same, AI will still change its tax rate (see https://forums.civfanatics.com/thre...ogic-tax-science-luxuries-distribution.657037). This basically means AI usually resets its tax rate every 8 turns.
    Logic to change goverment here is following:
    Code:
    IF despotism_desire < 1
    THEN
        IF civ DOESN'T know REPUBLIC advance OR republic_desire < 0
            THEN
            IF civ DOESN'T know COMMUNISM advance or number of cities < 11
                THEN IF civ DOESN'T know MONARCHY advance
                    DON'T DO ANYTHING;
                ELSE
                    SET GOVT TO MONARCHY;
            ELSE
                SET GOVT TO COMMUNISM;
        ELSE
            SET GOVT TO REPUBLIC;
    ELSE
        SET GOVT TO DESPOTISM;
    
    As you can see, there's no Pyramids in these rules. Pyramids are useless for AI. Also (as expected, because no one in 30 years has ever seen that) AI can't choose Democracy.
    And about these 'despotism_desire' and 'republic_desire' variables and how they are calculated - in the next post...

    4) when AI changes it's govt (goes to anarchy) it forgets all vendettas, means it will no more be upset about your (and others AIs) previous sneak attacks.
     
    Last edited: May 11, 2020
  2. tupi

    tupi Chieftain

    Joined:
    Jun 25, 2011
    Messages:
    60
    Location:
    Russia
    'republic desire'.
    1) set it to 0 at the beginning of city loop

    2) for every cultvated square in every city, if it produces at least 1 trade arrow: increase it by 1.

    3) for every city, decrease it by
    (marketplace_bonus-leader_temper)*units_outside_home_city
    where
    units_outside_home_city - same rules as for unhappy faces under republic (aircraft always +1, units with 0 attack always ignored)
    marketplace_bonus is 5 if city has a marketplace and 7 otherwise
    leader_temper is -1 for militaristic, +1 for civilized and 0 otherwise

    4) for every city, check next conditions:
    IF city total shields >= shields used for units support
    AND gl_ai_handicap_flag == 1
    AND number of techs of AI civ < number of techs of human player
    THEN
    set republic desire to -999

    gl_ai_handicap_flag is 1 if human player is the best civ in the world and has more than 4 cities and don't have any nuclear bombs and game turn > 200 (see https://pastebin.com/kexMnwH6)
     
    Last edited: May 28, 2020
  3. tupi

    tupi Chieftain

    Joined:
    Jun 25, 2011
    Messages:
    60
    Location:
    Russia
    'despotism desire':

    1) set it to 0 at the beginning of city loop

    2) for every cultivated city square in every city and for every type of resource (food/shields/trade): if production of this resouce is more than 2 (without despotism penalty/republic bonus) and there's no We Love The Leader parade in the city: decrease despotism_desire by 2

    3) for every city:
    IF city_size > city_supported_units THEN increase despotism_desire by city_supported_units
    ELSE increase despotism_desire by city_size.

    4) for every city:
    IF supported_units > city_total_shields THEN increase despotism_desire by (supported_units - city_total_shields)*5
     
    Last edited: May 11, 2020

Share This Page