Advertisement
Guest User

civdos ai wonders (fix 3)

a guest
Apr 17th, 2020
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.00 KB | None | 0 0
  1. //CIVDOS AI WONDERS RULES v4.0
  2.  
  3. #define W_DARWINS_VOYAGE    0x0E
  4. #define W_MANHATTAN_PROJECT 0x11
  5.  
  6. #define T_ROCKETRY 0x2E
  7.  
  8. void FUN_global_warming_and_ai_wonders()
  9. {
  10.     //skip some global warming code here...
  11.    
  12.     counter = 0;
  13.     do
  14.     {
  15.         if (counter > difficulty)
  16.             return;
  17.         wond = 1+random(21); //21 - number of wonders
  18.         //for some reason wonders are counting from 1 and not from 0... (1 = pyramids, 2 = gardens etc.)
  19.        
  20.         if (difficulty != 0 || check_civ_advance(human_player_civ,city_imrpovement_tech[wond]) == 1)
  21.         //on Chieftain difficulty comp. player can build a wonder only if human player
  22.         //has a civ advance to build a city improvement with the same number as this wonder...
  23.         //this can be a bug and intentional behavior was 'if human player has a civ advance to
  24.         //build this wonder', but who knows (except for Sid maybe)...
  25.         {
  26.             if (difficulty < 2) //Chieftain or Warlord
  27.             {
  28.                 //this loop prohibits AI to build a wonder if human already is building one...
  29.                 //but only if it's not Manhattan Project...
  30.                 city = 0;
  31.                 do
  32.                 {
  33.                     if (city_civ[city] == human_player_civ
  34.                     && city_flags[city] != -1 //city exists
  35.                     && city_production[city] == -(24+wond)) //0 is settler, > 0 are units, -1..-24 are used for buildings and SS parts.
  36.                     {
  37.                         wond = W_MANHATTAN_PROJECT;
  38.                         //why not break here though?
  39.                     }
  40.                     city++;
  41.                 }
  42.                 while (city < 128);
  43.             }
  44.             city = random(128);
  45.             cit_civ = city_civ[city];
  46.             if (city_flags[city] != -1 //city exists
  47.             && (diplomacy_status[cit_civ][0])&4 == 0 //The civilization is not in anarchy. (third ('ALLY') bit of cit_civ diplomacy with 'barbarians' is 0).
  48.             && (wond != W_MANHATTAN_PROJECT || check_civ_advance(cit_civ,T_ROCKETRY) == 1)) //AI will build Manhattan Proj. only if it can build nukes...
  49.             {
  50.                 if (counter == 0
  51.                 && check_civ_advance(cit_civ,T_ROCKETRY) == 1 //rocketry is hardcoded, it will not change here if you change prerequisite tech for Nuclear unit...
  52.                 && check_civ_advance(human_player_civ,T_ROCKETRY) == 0
  53.                 && wonder_city[W_MANHATTAN_PROJECT] == -1) //Manh. Proj. has never been built before...
  54.                 {
  55.                     wond = W_MANHATTAN_PROJECT;
  56.                 }
  57.                 if ((wond != W_MANHATTAN_PROJECT
  58.                 || check_civ_advance(human_player_civ,T_ROCKETRY) == 0
  59.                 || military_power[cit_civ] <= military_power[human_player_civ]) //if AI is weaker than the player, it can build MP even if the player knows the rocketry...
  60.                 &&
  61.                 (cit_civ != -1 && cit_civ != human_player_civ
  62.                 && wonder_city[wond] == -1)) //wonder never was built before...
  63.                 {
  64.                     if (city_size[city] > wonder_shield_rows_cost[wond]/10  //for example: you need 30 rows for Pyramids (300 shields), so AI can build Pyramids only in city with size 4 or more
  65.                     && check_civ_advance(cit_civ,city_improvement_tech[24+wond]) == 1) //after civ advances for city improvements there are civ advances for wonders
  66.                     {
  67.                         city_shields_count[city] = 0;
  68.                         write_replay_entry(10,2,cit_civ,wond); //10 - event type (wonder). 2 - record length.
  69.                        
  70.                         //concatenate some strings for "City (Civilization) builds a wonder" message here...
  71.                        
  72.                         var_B = normalize_min_max(civ_gold[cit_civ]/3,0,wonder_shield_rows_cost[wond]*10-city_shields_count[city]);
  73.                         //AI actually pays for wonders! But not more than 1/3 of the treasury!
  74.                         civ_gold[cit_civ] -= var_B;
  75.                         if (gl_debug_flag_A == 1) //some debug flag: no message about wonder and no civ jingle...
  76.                         {
  77.                             goto LAB_AI_WONDER_ACTIONS;
  78.                         }
  79.                         play_sound(civ_jingle);
  80.                         if ((diplomacy_status[human_player_civ][cit_civ]&0x40)==0) //you don't have an embassy for cit_civ...
  81.                         {
  82.                             var_C = 2; //Travellers report:
  83.                         }
  84.                         else
  85.                         {
  86.                             var_C = 5; //Foreign Minister:
  87.                         }
  88.                         gl_message_type = var_C;
  89.                         var_C = 80;
  90.                         goto LAB_WONDER_MESSAGE;
  91.                     }
  92.                 }
  93.             }
  94.         }
  95.         counter++;
  96.     }
  97.     while (1);
  98.    
  99.     //actually these labels are within some IF block in global warming logic.
  100.     LAB_WONDER_MESSAGE:
  101.     draw_message_function(curr_string,100,var_C); //draw message x: 100, y: 80?
  102.    
  103.     //software interruption 0x3f here... I think it used to transfer control to graphics exe when game needs to draw something?
  104.     //or/and to check mouse click/key press?..
  105.    
  106.     black_screen_update_graphics(); //screen fadeout? -> go to civilopedia?..
  107.     play_sound(1); //stop current sound?..
  108.     LAB_AI_WONDER_ACTIONS:
  109.     if (wond == W_DARWINS_VOYAGE)
  110.     {
  111.         get_some_civ_advance(civ,0); //0 - source (discovered by civ itself). Always 0 for every call of this function within the program, so this param is useless...
  112.         get_some_civ_advance(civ,0);
  113.     }
  114.     city = 0;
  115.     while (city < 128)
  116.     {
  117.         if (city_flags[city] != -1 //city exists
  118.         && city_civ[city] == human_player_civ
  119.         && city_production[city] == -(24+wond)) //city is building this wonder...
  120.         {
  121.             goto_city_screen(human_player_civ,city); //you should change it...
  122.         }
  123.         city++;
  124.     }
  125.     return;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement