Guest User

civdos diplomacy v.1.2

a guest
Oct 2nd, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 45.29 KB | Source Code | 0 0
  1. //civdos diplomacy version 1.2
  2.  
  3. FUN_big_diplomacy_func(int par_civ, int par_x, int par_y, int par_human_called_ai)
  4. //last param is 0 if AI called the talks and 1 if your diplomat did that
  5. {
  6.     //mz6:050400
  7.     int loc_player_dominance;
  8.    
  9.     FUN_reveal_map_in_xy(par_x, par_y);
  10.     FUN_drawMapTerrainSquare_B(par_x, par_y);
  11.     int loc_next_turn_to_talk = next_turn_for_talk_with_player[par_civ];
  12.    
  13.     //mz_6::050430
  14.     if (civ_number_and_pair[par_civ] == 0xE) //0x6(pink)+0x8 (2nd civ from pair): english
  15.     {
  16.         FUN_strcpy(civ_leader_title[6][1],"empress");
  17.         FUN_strcpy(civ_leader_title[6][2],"queen");
  18.     }
  19.    
  20.     //mz_6::050457
  21.     if (par_human_called_ai == 0)
  22.     {
  23.         next_turn_for_talk_with_player[par_civ] = game_turn; //next talks: 16 turns later...
  24.     }
  25.     gl_diplomacy_started_flag = 0;
  26.     int loc_AI_wants_to_attack = 0;
  27.     menu_selection_result = par_human_called_ai;
  28.     int loc_fear_give_you_something = 0;
  29.     int loc_money_demand = 0;
  30.     int loc_ai_wants_some_tribute = 1;
  31.     end_of_main_talk_flag_mb = 0;
  32.    
  33.     for (int cont = 1; cont < 15; cont++) //loop: continents
  34.     {
  35.         int cities_AX = 0; //AX
  36.         if (civ_cities[par_civ] > 1)
  37.         {
  38.             cities_AX = 1;
  39.         }
  40.        
  41.         //mz_6::050491
  42.         if (cities_per_continent[cont][par_civ] > cities_AX)
  43.         {
  44.             if (FUN_get_civ_attack_power_on_cont(player_civ,cont) > FUN_get_civ_defence_power_on_cont(par_civ,cont)) //AX > SI
  45.             //FUN_get_civ_attack_power_on_cont uses 3rd PUSH here: par_civ, but this func does not have 3rd parameter...
  46.             {
  47.                 int diff_mult_AX = 2; //AX
  48.                 if (difficulty == 0)
  49.                 {
  50.                     diff_mult_AX = 4;
  51.                 }
  52.                 loc_fear_give_you_something += (diff_mult_AX*FUN_get_civ_attack_power_on_cont(player_civ,cont))/(FUN_get_civ_defence_power_on_cont(par_civ,cont)+1); //(AX*DI)/SI, DI == CX
  53.                 //again, FUN_get_civ_attack_power_on_cont uses 3rd PUSH here: par_civ, but this func doesn't have 3rd parameter...
  54.             }
  55.         }
  56.         else //mz_6::05050c
  57.         {
  58.             if (defence_per_cont[cont][player_civ] != 0)
  59.             {
  60.                 if (defence_per_cont[cont][par_civ] != 0)
  61.                     loc_AI_wants_to_attack = 1;
  62.             }
  63.             //mz_6::050531
  64.             if (cities_per_continent[cont][player_civ] != 0)
  65.             {
  66.                 if (cities_per_continent[cont][par_civ] > 1)
  67.                 {
  68.                     loc_money_demand += attack_per_cont[cont][par_civ]-FUN_get_civ_attack_power_on_cont(player_civ,cont); //+= CX end: jump -> mz_6::0505d7
  69.                     //again, FUN_get_civ_attack_power_on_cont uses 3rd PUSH here: par_civ, but this func doesn't have 3rd parameter...
  70.                 }
  71.                 else
  72.                 {
  73.                     loc_money_demand += attack_per_cont[cont][par_civ];
  74.                 }
  75.             }
  76.             else //mz_6::050582
  77.             {
  78.                 int temp_power_AX = 0; //AX
  79.                 if (cities_per_continent[cont][par_civ] != 0)
  80.                 {
  81.                     temp_power_AX = ((defence_per_cont[cont][par_civ]-attack_per_cont[cont][player_civ]) >> 1);
  82.                 }
  83.                 else
  84.                 {
  85.                     temp_power_AX = ((attack_per_cont[cont][par_civ]-attack_per_cont[cont][player_civ])>>2);
  86.                 }
  87.                 //mz_6::0505d4
  88.                 loc_money_demand += temp_power_AX;
  89.             }
  90.         }
  91.     } //loop: 15 continents
  92.    
  93.     //mz_6::0505f5 (LAB_mz6_check_player_dominance)
  94.     if (civilization_powgraph_place[player_civ] == 7 //human player is numbah one.
  95.     && civ_cities[player_civ] > 4
  96.     && civ_cities[par_civ] > 1
  97.     && unit_counter[player_civ][U_NUCLEAR] == 0
  98.     && game_turn > 200)
  99.     {
  100.         loc_player_dominance = 1;
  101.     }
  102.     else
  103.     {
  104.         loc_player_dominance = 0;
  105.     }
  106.    
  107.     //mz_6::05063a
  108.     if (loc_player_dominance != 0 //(OR AX,AX) else (flow) -> mz_6::050641 dominance of the player - always set money demand...
  109.     //mz_6::050641
  110.     || ((diplomacy_status[par_civ][player_civ]&0x8) != 0 //else -> mz_6::0506a0. vendetta or... par_civ: 16, player_civ: 2
  111.     //mz_6::050655
  112.     && 3*civ_military_power[par_civ] > civ_military_power[player_civ])) //else -> mz_6::0506a0 AI civ is not too weak (AI > player/3)
  113.     {
  114.         //mz_6::050667
  115.         if (FUN_return_numb_of_nukes(player_civ) == 0)) //and player doesn't have any nukes...
  116.         {
  117.             loc_AI_wants_to_attack = 1; //AI want to declare war...
  118.             loc_money_demand = FUN_minmax(loc_money_demand,10*civilization_powgraph_place[par_civ],9999); //basic value of money demand is defined by AI powergraph place...
  119.             loc_fear_give_you_something = 0;
  120.         }
  121.     }
  122.    
  123.     //mz_6::0506a0
  124.     if (unit_counter[par_civ][U_NUCLEAR] != 0)
  125.     {
  126.         diplomacy[par_civ][player_civ] |= 0x80; //nuclear stance par_civ: 16, player_civ: 2
  127.     }
  128.    
  129.     //mz_6::0506c1
  130.     if (unit_counter[par_civ][U_NUCLEAR] != 0) //else -> mz_6::0506fb
  131.     {
  132.         if (FUN_return_numb_of_nukes(player_civ) == 0) //(OR AX,AX)
  133.         {
  134.             loc_AI_wants_to_attack = 1;
  135.             loc_money_demand = FUN_minmax(loc_money_demand,100,9999); //if AI has nukes and you don't, then min basic value of demanded money is set to 100$...
  136.         }
  137.     }
  138.    
  139.     //mz_6::0506fb
  140.     if (unit_counter[player_civ][U_NUCLEAR] != 0)
  141.     {
  142.         if (FUN_return_numb_of_nukes(par_civ) == 0)
  143.         {
  144.             loc_fear_give_you_something = 4;
  145.         }
  146.         else
  147.         {
  148.             loc_money_demand = (unit_counter[par_civ][U_NUCLEAR]*(loc_money_demand/2))/unit_counter[player_civ][U_NUCLEAR];
  149.             //if both you and AI has some nukes, basic value of money demand is divided by 2,
  150.             //and then if AI has more nukes than you, it will increase, and if you have more nukes - then it will decrease...
  151.         }
  152.     }
  153.     //mz_6::05074c
  154.     if (loc_fear_give_you_something != 0)
  155.     {
  156.         loc_AI_wants_to_attack = 0;
  157.         loc_ai_wants_some_tribute = 0;
  158.     }
  159.     //mz_6::05075c
  160.     if (FUN_check_wonder_eff(player_civ,7) != 0 //great wall
  161.     || FUN_check_wonder_eff(player_civ,0x12) != 0) //United Nations
  162.     {
  163.         loc_player_dominance = 0;
  164.         loc_AI_wants_to_attack = 0;
  165.        
  166.         if (loc_next_turn_to_talk == -2)
  167.         {
  168.             loc_next_turn_to_talk = -1;
  169.         }
  170.     }
  171.    
  172.     //mz_6::050797
  173.     if ((diplomacy[par_civ][player_civ]&8) != 0) //vendetta. par_civ: 16 player_civ: 2
  174.     {
  175.         loc_money_demand = loc_money_demand<<1; //if vendetta, double money demand...
  176.     }
  177.     else
  178.     {
  179.         //mz_6::0507b0
  180.         if (loc_next_turn_to_talk == -2) //after you captured AI city or after AI nuked you...
  181.         {
  182.             loc_money_demand = loc_money_demand/4;
  183.         }
  184.     }
  185.    
  186.     //mz_6::0507c2
  187.     loc_money_demand = FUN_minmax((loc_money_demand*(difficulty+1))>>5,0,20)*50; //modify money demand by game difficulty...
  188.    
  189.     //mz_6::0507fc
  190.     if (loc_money_demand > civ_treasury[player_civ]) // CMP AX,SI  //if player doesn't have enough money to pay...
  191.     {
  192.         if (loc_money_demand <= (civ_treasury[player_civ]<<1)) //but demanded money is less than player_treasury*2...
  193.         {
  194.             if (civ_treasury[player_civ] >= 50)
  195.             {
  196.                 //then demand as much as possible...
  197.                 loc_money_demand = (civ_treasury[player_civ]/50)*50;
  198.             }
  199.         }
  200.     }
  201.     //mz_6::050817
  202.     if (unit_counter[par_civ][U_NUCLEAR] != 0)
  203.     {
  204.         //mz_6::050833
  205.         //NEVER happens: see 0506c1. Nuclear stance flag is already set!..
  206.         if ((diplomacy[par_civ][player_civ]&0x80) == 0) //there was no nucl. stance before. else -> mz_6::050852 par_civ: 16 player_civ: 2
  207.         {
  208.             //mz_6::05083d
  209.             if (civ_treasury[player_civ] < loc_money_demand)
  210.             {
  211.                 loc_money_demand = (civ_treasury[player_civ]/50)*50; //if demand was too much, set it to the possible max (nuclear blackmail?)
  212.             }
  213.         }
  214.         //mz_6::050852
  215.         diplomacy[par_civ][player_civ] |= 0x80; //set "nuclear stance" diplomacy bit... actually, it's always already set at the time...
  216.     }
  217.     //mz_6::050864
  218.     if (loc_money_demand == 0 //AI don't want to demand any money...
  219.     || 3*civ_military_power[par_civ] < civ_military_power[player_civ]) //or AI is too weak...
  220.     {
  221.         loc_AI_wants_to_attack = 0;
  222.     }
  223.     //mz_6::050887
  224.     if (loc_AI_wants_to_attack != 0)
  225.     {
  226.         loc_ai_wants_some_tribute = 2;
  227.     }
  228.     //mz_6::050892
  229.     if (loc_AI_wants_to_attack == 0)
  230.     {
  231.         if (diplomacy[par_civ][player_civ]&4) != 0) //ALLY. It actually kinda works! par_civ: 16 player_civ: 2
  232.         {
  233.             loc_ai_wants_some_tribute = 0; //when ALLY doesn't want to attack you, it will never demand anything from you...
  234.         }
  235.     }
  236.     //mz_6::0508b1
  237.     loc_AI_wants_to_att_old = loc_AI_wants_to_attack;
  238.     int loc_fear_of_others = 0;
  239.     //mz_6::0508c9
  240.     if ((diplomacy[par_civ][player_civ]&8) != 0) //vendetta.
  241.     {
  242.         loc_fear_of_others = -2; //if vendetta, AI want to attack the player even if AI already at war with some other civs...
  243.     }
  244.     //mz_6::0508d5
  245.     int loc_demand_break_peace_civ = -1;
  246.     for (int civ = 1; civ < MAX_CIVS; civ++)
  247.     {
  248.         if (civ != player_civ
  249.         && (diplomacy[par_civ][civ]&3) == 1) //contact+war else -> mz_6::050944
  250.         {
  251.             if (civ_military_power[par_civ] < (civ_military_power[civ]<<2)) //if (other_ai_civ_pow*4 > our_ai_civ_pow)
  252.             {
  253.                 loc_fear_of_others++; //add point, if 3rd civ's power is 1/4 of "our" AI civ power or more...
  254.             }
  255.             //mz_6::050913
  256.             if (civ_military_power[civ] > civ_military_power[par_civ])
  257.             {
  258.                 loc_fear_of_others++; //add another point, if 3rd civ is stronger than our AI civ...
  259.             }
  260.             //mz_6::05092a
  261.             if ((diplomacy[player_civ][civ]&2) != 0) //human is in peace with this 3rd civ. else -> mz_6::050944
  262.             {
  263.                 loc_demand_break_peace_civ = civ; //demand break peace with which civ?
  264.             }
  265.         }
  266.         //mz_6::050944
  267.     } //loop: civs
  268.    
  269.     //mz_6::05094d
  270.     loc_fear_of_others -= leader_aggress[civ_number_and_pair[par_civ]]; //aggressive leader tends to not make peace with the player even if this leader wages many wars already
  271.    
  272.     if (civ_military_power[player_civ] < civ_military_power[par_civ])
  273.     {
  274.         loc_fear_of_others--; //AI civ can smash us pretty easily, so they don't care about other wars this much...
  275.     }
  276.     //mz_6::050975
  277.     war = (diplomacy[par_civ][player_civ]&2); //AL. not used?..
  278.     //3c  01           CMP        AL ,0x1 <- not used! AL at the moment can be 0 or 2
  279.     //1b  c9           SBB        CX ,CX  <- why? -CFlag now in CX?..
  280.     //f7  d9           NEG        CX      <- why? CFlag now in CX?..
  281.  
  282.     //maybe some info here: https://reverseengineering.stackexchange.com/questions/14128/x86-sbb-with-same-register-as-first-and-second-operand/14133
  283.  
  284.     //also compare with the code for "exchange ambassadors" (in this case, ghidra doesn't decompile it as it presumes flow does not goes here)
  285.  
  286.     //according to ghidra decompilation, here should be (but why?):
  287.     //if (((diplomacy[par_civ][player_civ]&2) == 0) < loc_fear_of_others)
  288.        
  289.     //mz_6::05098e  3b  4e  d6       CMP        CX ,word ptr [BP  + loc_fear_of_others ]
  290.  
  291.     //mz_6::05098e my version:
  292.     if (loc_fear_of_others > 0) //because CX should be 0, I think...
  293.     //Ghidra version:
  294.     if (loc_fear_of_others > ((diplomacy[par_civ][player_civ]&2) == 0)) //i.e. > 0 if peace and > 1 if war
  295.     {
  296.         if (loc_player_dominance == 0) //With dominant position of player, AI will be aggressive anyway...
  297.         {
  298.             loc_AI_wants_to_attack = 0;
  299.            
  300.             if (FUN_random(2) != 0) //(OR AX,AX) else -> mz_6::0509b3
  301.             {
  302.                 loc_money_demand = 0; //in this case, 1/2 chance for AI to cancel any of its money demands from you...
  303.             }
  304.         }
  305.     }
  306.    
  307.     //mz_6::0509b3
  308.     if (civ_govt[par_civ] >= 4) //AI Republic (or Democracy - never happens)
  309.     {
  310.         //mz_6::0509bf
  311.         if (loc_AI_wants_to_attack != 0) //AI want to attack you...
  312.         {
  313.             if ((diplomacy[par_civ][player_civ]&8) == 0) //but not in vendetta with you... else -> mz_6::050a06
  314.             {
  315.                 if (3*civ_military_power[player_civ] <= civ_military_power[par_civ]<<1  //AI*2 >= player*3 AI is very strong...
  316.                 || loc_player_dominance != 0) //or player dominance...
  317.                 {
  318.                     FUN_civ_changes_govt(par_civ,2); //change govt to monarchy (even if we don't know the tech...)
  319.                 }
  320.                 else
  321.                     loc_AI_wants_to_attack = 0; //possible meaning: so Republican AI will not declare the war (except if vendetta)...
  322.             }
  323.         }
  324.     }
  325.     //mz_6::050a06
  326.     int loc_ready_to_cancel_peace = 0;
  327.     int loc_dip_status = (diplomacy[par_civ][player_civ]&2); //2: peace 0: war
  328.     //mz_6::050a23
  329.     if ((loc_dip_status&2) != 0) //(i.e. peace)
  330.     {
  331.         //mz_6::050a25
  332.         if (loc_AI_wants_to_attack != 0)
  333.         {
  334.             //mz_6::050a34
  335.             if (civ_military_power[par_civ] < civ_military_power[player_civ]
  336.             || (loc_dip_status&8) != 0) //vendetta
  337.             {
  338.                 loc_AI_wants_to_attack = 0;
  339.                 loc_ready_to_cancel_peace = 1;
  340.                 loc_ai_wants_some_tribute = 0;
  341.             }
  342.         }
  343.     }
  344.    
  345.     int loc_best_tech;
  346.     int loc_tech_for_you; //what tech AI can give to you as tribute
  347.     int loc_best_tech_desire; //So AI not always demands tech, if you have some, but only if its desire is high enough...
  348.     int loc_tot_ai_tech;
  349.     int loc_tot_player_tech;
  350.     int loc_tech_civ_count;
  351.    
  352.     while (1) //endless loop: tech exchange...
  353.     {
  354.         //mz_6::050a4f
  355.         //what tech to demand? (with max AI desire, without any randomization)
  356.         //also counters for player's and AI civ advances
  357.         loc_best_tech = -1;
  358.         loc_tech_for_you = -1;
  359.         loc_best_tech_desire = 0; //So AI not always demands tech, if you have some, but only if its desire is high enough...
  360.         loc_tot_ai_tech = 0;
  361.         loc_tot_player_tech = 0;
  362.         loc_tech_civ_count = 0;
  363.        
  364.         do
  365.         {
  366.             //mz_6::050a66
  367.             if (civ_has_tech_check(player_civ,loc_tech_civ_count) != 0)
  368.             {
  369.                 loc_tot_player_tech++;
  370.             }
  371.             //mz_6::050a7c
  372.             if (civ_has_tech_check(par_civ,loc_tech_civ_count) != 0)
  373.             {
  374.                 loc_tot_ai_tech++;
  375.             }
  376.             //mz_6::050a91
  377.             if (civ_has_tech_check(player_civ,loc_tech_civ_count) == 0)
  378.             {
  379.                 if (civ_has_tech_check(par_civ,loc_tech_civ_count) != 0)
  380.                 {
  381.                     loc_tech_for_you = loc_tech_civ_count; //what tech AI can give to you
  382.                 }
  383.             }
  384.             //mz_6::050abc
  385.             if (civ_has_tech_check(player_civ,loc_tech_civ_count) != 0)
  386.             {
  387.                 if (civ_has_tech_check(par_civ,loc_tech_civ_count) == 0)
  388.                 {
  389.                     if (FUN_ai_tech_desire(par_civ,loc_tech_civ_count) >= loc_best_tech_desire)
  390.                     {
  391.                         //mz_6::050af7
  392.                         loc_best_tech = loc_tech_civ_count; //what tech AI will demand from you
  393.                         loc_best_tech_desire = FUN_ai_tech_desire(par_civ,loc_best_tech);
  394.                     }
  395.                 }
  396.             }
  397.             //mz_6::050b09
  398.             loc_tech_civ_count++;
  399.         }
  400.         //mz_6::050b0c
  401.         while (loc_tech_civ_count < 72);
  402.        
  403.         //mz_6::050b15
  404.         //0x20: you attacked AI before or AI attacked you before...
  405.         if ((((diplomacy[par_civ][player_civ]&0x20) != 0 || loc_AI_wants_to_attack != 0) //AI not gonna trade techs with you: some mil. actions happened before OR AI wants war
  406.         && loc_tot_ai_tech > 6) //but if AI has less than 7 tech, then it wants to exchange anyway...
  407.         ||
  408.         (loc_tot_player_tech < loc_tot_ai_tech || loc_tech_for_you == -1)) //or: if player has less techs than AI OR AI doesn't have any tech to give to player
  409.         {
  410.             break;
  411.         }
  412.        
  413.         //mz_6::050b4c
  414.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) == -1)
  415.             break;
  416.         //mz_6::050b62
  417.         science_or_diplomacy_special_screen = 1;
  418.         main_string[0] = 0;
  419.         FUN_strcpy(str_insert_b,tech_names[local_tech2]);
  420.         FUN_read_from_king_txt_and_some_string_stuff("*EXCHANGE"); //We note that your primitive civilization...
  421.         sci_or_dip_flag_b = 0xc;
  422.         //mz_6::050ba8
  423.         if (FUN_message_on_dip_screen(main_string,20,139) != 1) //*str, x, y answer: NO!
  424.             break;
  425.         FUN_common_func_mb_black_screen_A();
  426.         FUN_clear_screen_mb_B();
  427.         FUN_update_screen_mb();
  428.         science_or_diplomacy_special_screen = -1;
  429.         cpedia_from_city_screen_flag = 1;
  430.         FUN_get_tech_from_city_capture(par_civ,player_civ);
  431.         //SKIPPED! something-something...
  432.         FUN_get_tech_from_city_capture(player_civ,par_civ);
  433.         FUN_triple_little_black_magic_A();
  434.         //SKIPPED! something-something...
  435.         loc_AI_wants_to_attack = 0;
  436.         science_or_diplomacy_special_screen = 1;
  437.         FUN_common_func_mb_black_screen_A();
  438.         FUN_clear_all_screen_mb();
  439.         FUN_update_screen_mb();
  440.     } //endless loop: tech exchange...
  441.    
  442.     //mz_6::050c22
  443.     if (loc_AI_wants_to_attack == 0)
  444.     {
  445.         if (par_human_called_ai == 0)
  446.         {
  447.             if ((diplomacy[par_civ][player_civ]&2) == 2) //(peace)
  448.             {
  449.                 if (loc_fear_give_you_something > 2)
  450.                 {
  451.                     //goto: mz_6::051a5d !!
  452.                     goto: LAB_end_of_diplomacy;
  453.                 }
  454.             }
  455.         }
  456.     }
  457.    
  458.     //mz_6::050c4e
  459.     if ((global_debug_flags&1)==0)
  460.     {
  461.         loc_AI_wants_to_attack = 0;
  462.         loc_ai_wants_some_tribute = 0;
  463.         loc_fear_give_you_something = 0;
  464.         loc_ready_to_cancel_peace = 0;
  465.     }
  466.    
  467.     //mz_6::050c69
  468.     //request or demand break peace with some civ...
  469.     if (loc_demand_break_peace_civ != -1)
  470.     {
  471.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  472.         {
  473.             //mz_6::050c88
  474.             if (loc_ai_wants_some_tribute != 0)
  475.             {
  476.                 main_string[0] = '\0';
  477.                 FUN_strcpy(str_insert_c_mb,civ_name_plural[loc_demand_break_peace_civ]);
  478.                 if (loc_AI_wants_to_attack == 0)
  479.                     FUN_strcpy(str_insert_b,'request');
  480.                 else
  481.                     FUN_strcpy(str_insert_b,'demand');
  482.                
  483.                 FUN_read_from_king_txt_and_some_string_stuff("*CANCEL"); //"You have made peace with our evil neighbors..."
  484.                 //mz_6::050cd2
  485.                 if (loc_AI_wants_to_attack == 0)
  486.                     science_or_diplomacy_special_screen = 1;
  487.                 else
  488.                     science_or_diplomacy_special_screen = 2;
  489.                 SCI_OR_DIP_FLAG_B = 0xc;
  490.                
  491.                 if (loc_AI_wants_to_attack != 0)
  492.                 {
  493.                     FUN_play_sound(0x21); //threat sound
  494.                 }
  495.                 //mz_6::050cfb
  496.                 if (FUN_message_on_dip_screen(main_string,20,139) == 1) //show "You have made peace..." message and dialog (yes/no)
  497.                 {
  498.                     //your answer is "yes"
  499.                     loc_AI_wants_to_attack = 0;
  500.                     if (FUN_random(2) != 0) //50% chance
  501.                     {
  502.                         loc_money_demand = 0;
  503.                     }
  504.                    
  505.                     FUN_cancel_diplomacy_status(player_civ,loc_demand_break_peace_civ,2); //cancel "peace" bit...
  506.                     diplomacy[loc_demand_break_peace_civ][player_civ] |= 8; //vendetta with this 3rd civ!
  507.                 }
  508.             } //AI want to demand something from you...
  509.         }
  510.     } //AI want you to cancel peace with some civ...
  511.    
  512.     //mz_6::050d52
  513.     if (loc_money_demand != 0 && loc_ai_wants_some_tribute == 2)
  514.     {
  515.         //mz_6::050d64
  516.         if (civ_treasury[player_civ] > loc_money_demand)
  517.         {
  518.             //mz_6::050d76
  519.             if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  520.             {
  521.                 main_string[0] = '\0';
  522.                 char* str = FUN_number_to_string(loc_money_demand,inserted_string_1,10); //10 - decimal notation
  523.                 FUN_strcat(main_string,str);
  524.                 FUN_strcpy(str_insert_d_mb,main_string);
  525.                 main_string[0] = '\0';
  526.                 FUN_read_from_king_txt_and_some_string_stuff("*TRIBUTE");
  527.                 end_of_main_talk_flag_mb = 0;
  528.                 science_or_diplomacy_special_screen = 2;
  529.                 sci_or_dip_flag_b = 0xc;
  530.                 FUN_play_sound(0x21); //threating
  531.                
  532.                 if (FUN_message_on_dip_screen(main_string,20,139) == 1)
  533.                 {
  534.                     //mz_6::050e08
  535.                     //you agreed to give them some money...
  536.                     civ_treasury[player_civ] -= loc_money_demand;
  537.                     civ_treasury[par_civ] += loc_money_demand;
  538.                     loc_AI_wants_to_attack = 0;
  539.                 }
  540.                
  541.                 loc_money_demand = 999; //flag: AI demanded something from you...
  542.             } //we continue talks OR this is beginning of talks and we agree to speak...
  543.         } //we have enough money to pay...
  544.     }
  545.    
  546.     //mz_6::050e28
  547.     if (loc_ai_wants_some_tribute != 0
  548.     && loc_best_tech != -1
  549.     && loc_money_demand != 999)
  550.     {
  551.         //mz_6::050e44
  552.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  553.         {
  554.             //mz_6::050e57
  555.             main_string[0] = '\0';
  556.             FUN_strcpy(str_insert_b,tech_names[loc_best_tech]);
  557.             FUN_read_from_king_txt_and_some_string_stuff("*TAKECIV");
  558.             end_of_main_talk_flag_mb = 0;
  559.             science_or_diplomacy_special_screen = 2;
  560.             sci_or_dip_flag_b = 0xc;
  561.             FUN_play_sound(0x21); //threat: tech demand
  562.             if (FUN_message_on_dip_screen(main_string,20,139) == 1) //draw "Your civilization makes us laugh..." dialog
  563.             {
  564.                 FUN_civ_advance_discovery(par_civ,loc_best_tech,player_civ); //source: player_civ
  565.                 loc_AI_wants_to_attack = 0;
  566.             }
  567.            
  568.             loc_money_demand = 999; //flag: AI demanded something from you
  569.         }
  570.     }
  571.    
  572.     //mz_6::050ed0
  573.     if (loc_AI_wants_to_attack == 0
  574.     || ((diplomacy[par_civ][player_civ]) & 2) == 0 //at war
  575.     || loc_money_demand <= 50)
  576.     {
  577.         //mz_6::050f5f
  578.         if (loc_AI_wants_to_attack == 0
  579.         || loc_money_demand != 999)
  580.         {
  581.             //mz_6::050f98
  582.             if (loc_AI_wants_to_attack != 0
  583.             && ((diplomacy[par_civ][player_civ] & 1) == 0 || par_human_called_ai != 0) //no contact or you called AI with your diplomat
  584.             {
  585.                 //mz_6::050fbb
  586.                 s16 res = FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y);
  587.                 if (res == -1) //you don't want to even talk with them...
  588.                 {
  589.                     main_string[0] = '\0';
  590.                     AX = "*RID"; //We have decided to rid the world of your worthless civilization.
  591.                     goto LAB_goto_A;
  592.                 }
  593.                 FUN_play_sound(0x21);
  594.                 main_string[0] = '\0';
  595.                 AX = "*RID";
  596.                 //mz_6::050fe2
  597.                 goto LAB_goto_B; //same message, but on the diplomacy screen after greetings...
  598.             }
  599.         }
  600.         else
  601.         {
  602.             //mz_6::050f6c
  603.             if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  604.             {
  605.                 //mz_6::050f82
  606.                 FUN_play_sound(0x21);
  607.                 main_string[0] = '\0';
  608.                 AX = "*REJECT"; //You reject our generous offer? Your insolence must be punished. Prepare for WAR!
  609.                
  610.                 //mz_6::050f1a
  611.                 LAB_goto_B:
  612.                
  613.                 FUN_read_from_king_txt_and_some_string_stuff(AX);
  614.                 FUN_string_func_unknown(0x28);
  615.                 end_of_main_talk_flag_mb = 1;
  616.                 science_or_diplomacy_special_screen = 2;
  617.                 sci_or_dip_flag_b = 0xc;
  618.                 FUN_message_on_dip_screen(main_string,20,139);
  619.                 goto LAB_goto_cancel_peace;
  620.             }
  621.         }
  622.     }
  623.     else
  624.     {
  625.         //mz_6::050ef3
  626.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  627.         {
  628.             FUN_play_sound(0x21);
  629.             main_string[0] = '\0';
  630.             AX = "*PROVOKE";
  631.             goto LAB_goto_B;
  632.         }
  633.         main_string[0] = '\0';
  634.         AX = "*PROVOKE";
  635.        
  636.         //mz_6::050fed
  637.         LAB_goto_A:
  638.        
  639.         FUN_read_from_king_txt_and_some_string_stuff(AX);
  640.         FUN_string_func_unknown(0x28);
  641.         FUN_draw_some_message_A(main_string,40,100); //message "We have decide to rid the world of your worthless civ..." on the normal, map screen
  642.         //mz_6::051013
  643.         LAB_goto_cancel_peace:
  644.         FUN_cancel_diplomacy_status(player_civ,par_civ,2); //cancel peace status
  645.     }
  646.    
  647.     //mz_6::051029
  648.     if (loc_AI_wants_to_attack == 0
  649.     && ((diplomacy[par_civ][player_civ]&2) == 0 || par_human_called_ai != 0))
  650.     {
  651.         //mz_6::05104f
  652.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  653.         {
  654.             //mz_6::051065
  655.             main_string[0] = '\0';
  656.             FUN_read_from_king_txt_and_some_string_stuff("*PEACE");
  657.             end_of_main_talk_flag_mb = 0;
  658.             science_or_diplomacy_special_screen = 0;
  659.             sci_or_dip_flag_b = 0xc;
  660.             s16 res = FUN_message_on_dip_screen(main_string,20,139);
  661.             if (res == 1) //yes
  662.             {
  663.                 FUN_show_treaty_message(par_civ);
  664.                 FUN_set_peace_and_disband_units_on_chieftain(par_civ);
  665.                 next_turn_for_talk_with_player[par_civ] = game_turn+16;
  666.             }
  667.             else //no, reject peace
  668.             {
  669.                 //mz_6::0510c6
  670.                 if (civ_govt[player_civ] < 4) //not Republic or Democracy
  671.                 {
  672.                     //mz_6::051103
  673.                     if ((diplomacy[par_civ][player_civ]&2)!=0) //we were at peace before...
  674.                     {
  675.                         FUN_cancel_diplomacy_status(player_civ,par_civ,2); //cancel peace
  676.                     }
  677.                    
  678.                    
  679.                     //mz_6::05112a
  680.                     if (loc_fear_give_you_something > 3
  681.                     && local_tech2 != -1
  682.                     && (diplomacy[par_civ][player_civ]&0xa) == 0) //0x10+0x2: we never meet before + still not peace
  683.                     {
  684.                         //mz_6::051153
  685.                         FUN_strcpy(str_insert_b,tech_names[local_tech2]);
  686.                         main_string[0] = '\0';
  687.                         FUN_read_from_king_txt_and_some_string_stuff("*GIVECIV"); //In exchange for peace we will share with you the secret of $RPLC1.
  688.                         science_or_diplomacy_special_screen = 0;
  689.                         sci_or_dip_flag_b = 0xc;
  690.                         if (FUN_message_on_dip_screen(main_string,20,139) == 1) //1: yes, give me your tech for peace...
  691.                         {
  692.                             //mz_6::05119e
  693.                             FUN_common_func_mb_black_screen_A();
  694.                             FUN_clear_screen_mb_B();
  695.                             FUN_update_screen_mb();
  696.                             FUN_triple_little_black_magic_A();
  697.                             science_or_diplomacy_special_screen = -1;
  698.                             cpedia_from_city_screen_flag = 1;
  699.                             FUN_civ_advance_discovery(player_civ,local_tech2,par_civ);
  700.                             //skipped: something-something...
  701.                             FUN_triple_little_black_magic_A();
  702.                             science_or_diplomacy_special_screen = 0;
  703.                             FUN_common_func_mb_black_screen_A();
  704.                             FUN_clear_all_screen_mb();
  705.                             FUN_update_screen_mb();
  706.                             FUN_show_treaty_message(par_civ);
  707.                             FUN_set_peace_and_disband_units_on_chieftain(par_civ);
  708.                             loc_next_turn_to_talk = game_turn;
  709.                         } //yes, give me your tech for peace...
  710.                     } //conditions for: 1 tech tribute from AI to you (for peace)
  711.                    
  712.                     //mz_6::05120e
  713.                     if ((diplomacy[par_civ][player_civ]&0xa)==0) //0x10+0x2: we never meet before + still not peace
  714.                     {
  715.                         //mz_6::051225
  716.                         loc_merc_cost = FUN_minmax((loc_fear_give_you_something<<1)-4,0,civ_treasury[par_civ]/50);
  717.                         loc_merc_cost *= 50;
  718.                        
  719.                         if (loc_merc_cost != 0) //here: how much AI is ready to pay for peace...
  720.                         {
  721.                             //mz_6::05125a
  722.                             char* str = FUN_number_to_string(loc_merc_cost,inserted_string_1,10);
  723.                             FUN_strcat(main_string,str);
  724.                             FUN_strcpy(str_insert_d_mb,main_string);
  725.                             main_string[0] = '\0';
  726.                             FUN_read_from_king_txt_and_some_string_stuff("*GIVECASH"); //In exchange for peace we offer you $BUCKS$
  727.                             science_or_diplomacy_special_screen = 0;
  728.                             sci_or_dip_flag_b = 0xc;
  729.                            
  730.                             if (FUN_message_on_dip_screen(main_string,20,139) == 1) //yes, give me your money for peace...
  731.                             {
  732.                                 //mz_6::0512c4
  733.                                 FUN_show_treaty_message(par_civ);
  734.                                 FUN_set_peace_and_disband_units_on_chieftain(par_civ);
  735.                                 civ_treasury[player_civ] += loc_merc_cost;
  736.                                 civ_treasury[par_civ] -= loc_merc_cost;
  737.                                 loc_next_turn_to_talk = game_turn;
  738.                             } //yes, give me your money for peace...
  739.                         }
  740.                     } //conditions for: AI gives you money for peace
  741.                    
  742.                     //mz_6::0512ed
  743.                     if (loc_fear_give_you_something != 0 && civ_cities[par_civ] < 2
  744.                     && (diplomacy[par_civ][player_civ]&0xa) == 0) //0x10+0x2: we never meet before + still not peace
  745.                     {
  746.                         main_string[0] = '\0';
  747.                         char* str = FUN_number_to_string(civ_money[par_civ],inserted_string_1,10);
  748.                         FUN_strcat(main_string,str);
  749.                         FUN_strcpy(str_insert_d_mb,main_string);
  750.                         main_string[0] = '\0';
  751.                         FUN_read_from_king_txt_and_some_string_stuff("*GROVEL");
  752.                         science_or_diplomacy_special_screen = 0;
  753.                         sci_or_dip_flag_b = 0xc;
  754.                        
  755.                         if (FUN_message_on_dip_screen(main_string,20,139) == 1)
  756.                         {
  757.                             //mz_6::05138a
  758.                             FUN_show_treaty_message(par_civ);
  759.                             FUN_set_peace_and_disband_units_on_chieftain(par_civ);
  760.                             civ_treasury[player_civ] += civ_treasury[par_civ];
  761.                             civ_treasury[par_civ] = 0;
  762.                             FUN_common_func_mb_black_screen_A();
  763.                             FUN_clear_screen_mb_B();
  764.                             FUN_update_screen_mb();
  765.                             FUN_triple_little_black_magic_A();
  766.                             science_or_diplomacy_special_screen = -1;
  767.                             loc_tech_civ_count = 0;
  768.                             do
  769.                             {
  770.                                 //mz_6::0513d1
  771.                                 if (civ_has_tech_check(player_civ,loc_tech_civ_count) == 0)
  772.                                 {
  773.                                     if (civ_has_tech_check(par_civ,loc_tech_civ_count) == 1)
  774.                                     {
  775.                                         cpedia_from_city_screen_flag = 1;
  776.                                         FUN_civ_advance_discovery(player_civ,loc_tech_civ_count,par_civ);
  777.                                        
  778.                                     }
  779.                                 }
  780.                                 loc_tech_civ_count++;
  781.                             }
  782.                             while (loc_tech_civ_count < 72);
  783.                             //mz_6::051417
  784.                             //something-something...
  785.                             FUN_triple_little_black_magic_A();
  786.                             science_or_diplomacy_special_screen = 0;
  787.                             FUN_common_func_mb_black_screen_A();
  788.                             FUN_clear_all_screen_mb();
  789.                             FUN_update_screen_mb();
  790.                             loc_next_turn_to_talk = game_turn;
  791.                         }
  792.                     } //conditions for *GROVEL response
  793.                    
  794.                     //mz_6::051453
  795.                     if ((diplomacy[par_civ][player_civ]&2) == 0) //peace had not been reached...
  796.                     {
  797.                         //mz_6::051455
  798.                         FUN_play_sound(0x21); //very well! prepare for war!
  799.                         main_string[0] = '\0';
  800.                         FUN_read_from_king_txt_and_some_string_stuff("*MOBILIZE");
  801.                         end_of_main_talk_flag_mb = 1;
  802.                         science_or_diplomacy_special_screen = 2;
  803.                         sci_or_dip_flag_b = 4;
  804.                         FUN_message_on_dip_screen(main_string,20,139);
  805.                     }
  806.                 }
  807.                 else //republic or democracy
  808.                 {
  809.                     FUN_strcpy(main_string,"You are overruled bla-bla-bla"); //senate
  810.                     FUN_message_on_dip_screen(main_string,20,139);
  811.                     FUN_set_peace_and_disband_units_on_chieftain(par_civ);
  812.                 }
  813.             } //reject peace offer
  814.         } //you continue talks or you agreed to start talks...
  815.     }
  816.    
  817.     //mz_6::051497
  818.     //actually, not used here?..
  819.     if (civ_number_and_pair[par_civ] == 0xe) //English
  820.     {
  821.         FUN_strcpy(civ_leader_title[6][1],"empress");
  822.         FUN_strcpy(civ_leader_title[6][2],"queen");
  823.     }
  824.     main_string[0] = '\0';
  825.     //mz_6::0514c9
  826.     if (loc_AI_wants_to_attack == 0
  827.     && (diplomacy[par_civ][player_civ] & 2) == 2) //already peace..
  828.     {
  829.         //mz_6::0514ec
  830.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  831.         {
  832.             if (loc_ai_wants_some_tribute == 0 || loc_money_demand == 999)
  833.             {
  834.                 //mz_6::05152f
  835.                 FUN_strcpy(main_string, "We welcome friendship...");
  836.                 FUN_strcat(main_string, civ_name_adjective[player_civ]);
  837.                 FUN_strcat(main_string, "people and their most...");
  838.                 FUN_strcat(main_string, civ_leader_title[player_civ][civ_govt[player_civ]]);
  839.                 FUN_strcat(main_string, str_welcome_end);
  840.                 FUN_strcat(main_string, leader_name[player_civ]);
  841.                 FUN_strcat(main_string, str_welcome_end_period);
  842.             }
  843.             else
  844.             {
  845.                 //mz_6::05150f
  846.                 science_or_diplomacy_special_screen = 1;
  847.                 sci_or_dip_flag_b = 4;
  848.                 main_string[0] = '\0';
  849.                 FUN_read_from_king_txt_and_some_string_stuff("*ATTITUDE");
  850.             }
  851.             FUN_message_on_dip_screen(main_string,20,139);
  852.         }
  853.     }
  854.    
  855.     //mz_6::0515d6
  856.     if ((diplomacy[par_civ][player_civ] & 2) != 0) //peace
  857.     {
  858.         if (FUN_dipl_create_diplomacy_dialog_mb(par_civ,par_x,par_y) != -1)
  859.         {
  860.             while (1)
  861.             {
  862.                 //mz_6::051609
  863.                 FUN_strcpy(str_insert_b, civ_name_plural[par_civ]);
  864.                 main_string[0] = '\0';
  865.                 FUN_read_from_king_txt_and_some_string_stuff("*THREAT");
  866.                 if (game_turn - loc_next_turn_to_talk < 16
  867.                 || civ_govt[player_civ] >= 4)
  868.                     gl_blocked_menu_items_bits = 4; //block 3rd menu item of responce (1st: 1, 2nd: 2, 3rd: 4)
  869.                 //mz_6::05164d
  870.                 if ((1<<par_civ) | (1<<player_civ) == civ_activity_flags) //only you and AI civ are active...
  871.                 {
  872.                     gl_blocked_menu_items_bits = 2; //block 2nd menu item of responce
  873.                 }
  874.                
  875.                 int res = FUN_message_on_dip_screen(main_string,20,139);
  876.                 if (res == 2) //we demand money...
  877.                 {
  878.                     //mz_6::051689
  879.                     loc_merc_cost = FUN_minmax(loc_fear_give_you_something,0,civ_treasury[par_civ]/50);
  880.                     loc_merc_cost *= 50;
  881.                     if (loc_merc_cost == 0)
  882.                     {
  883.                         if (loc_AI_wants_to_att_old == 0)
  884.                         {
  885.                             FUN_strcpy(main_string, "We ignore your threats bla-bla");
  886.                             science_or_diplomacy_special_screen = 1;
  887.                             sci_or_dip_flag_b = 4;
  888.                         }
  889.                         else
  890.                         {
  891.                             //mz_6::051738
  892.                             FUN_play_sound(0x21);
  893.                             main_string[0] = '\0';
  894.                             FUN_read_from_king_txt_and_some_string_stuff("*PROVOKE");
  895.                             FUN_cancel_diplomacy_status(player_civ,par_civ,2); //cancel peace
  896.                             science_or_diplomacy_special_screen = 2;
  897.                             sci_or_dip_flag_b = 0xc;
  898.                         }
  899.                         FUN_message_on_dip_screen(main_string,20,139);
  900.                     }
  901.                     else
  902.                     {
  903.                         //mz_6::0516b3
  904.                         main_string[0] = '\0';
  905.                         char* str = FUN_number_to_string(loc_merc_cost,inserted_string_1,10);
  906.                         FUN_strcat(main_string,str);
  907.                         FUN_strcpy(str_insert_d_mb,main_string);
  908.                         main_string[0] = '\0';
  909.                         FUN_read_from_king_txt_and_some_string_stuff("*GIVEMOVE");
  910.                         science_or_diplomacy_special_screen = 0;
  911.                         sci_or_dip_flag_b = 0xc;
  912.                         FUN_message_on_dip_screen(main_string,20,139);
  913.                         civ_treasury[player_civ] += loc_merc_cost;
  914.                         civ_treasury[par_civ] -= loc_merc_cost;
  915.                         next_turn_for_talk_with_player[par_civ] = game_turn;
  916.                     }
  917.                 } //we demand money from AI...
  918.                
  919.                 if (res != 1) //not mercenary routine...
  920.                     goto LAB_goto_D; //goto -> mz_6::0519e2
  921.                 FUN_strcpy(main_string, "You must attack evil:");
  922.                 //mz_6::0517be
  923.                 int loc_list_counter = 0;
  924.                 for (int i = 1; i < MAX_CIVS; i++)
  925.                 {
  926.                     if (i != player_civ && i != par_civ && civ_activity_flags&(1<<i) != 0)
  927.                     {
  928.                         loc_civs_array[loc_list_counter] = i; //position in list -> civ
  929.                         loc_list_counter++; //position in list
  930.                         FUN_strcat(main_string,civ_name_plural[i]);
  931.                         FUN_strcat(main_string,str_mz6_ret_merc_att_list);
  932.                     }
  933.                 }
  934.                 //mz_6::051826
  935.                 loc_merc_cost = FUN_message_on_dip_screen(main_string,20,139);
  936.                 science_or_diplomacy_special_screen = 1;
  937.                 //mz_6::051842
  938.                 if (loc_merc_cost == -1)
  939.                 {
  940.                     goto LAB_goto_D;
  941.                 }
  942.                 att_civ = loc_civs_array[loc_merc_cost]; //position->civ
  943.                 FUN_strcpy(str_insert_b,civ_name_plural[att_civ]);
  944.                 sci_or_dip_flag_b = 4;
  945.                 if ((diplomacy[att_civ][par_civ]&1) == 0) //no contact
  946.                 {
  947.                     main_string[0] = '\0';
  948.                     AX = "*NOCONTACT";
  949.                     goto LAB_show_nocontact_or_unfortunate_mess;
  950.                 }
  951.                
  952.                 //mz_6::051887
  953.                 if ((diplomacy[par_civ][[att_civ]&2) != 0) //they are at peace with this 3rd civ...
  954.                     break;
  955.                 main_string[0] = '\0';
  956.                 FUN_read_from_king_txt_and_some_string_stuff("*ATWAR");
  957.                 FUN_message_on_dip_screen(main_string,20,139);
  958.             } //endless loop
  959.            
  960.             //mz_6::0518c1
  961.             loc_merc_cost = (((civ_military_power[att_civ])>>1)*(civ_treasury[par_civ]/100))/50;
  962.             loc_merc_cost = FUN_minmax(loc_merc_cost, 2, 9999);
  963.             loc_merc_cost *= 50;
  964.             main_string[0] = '\0';
  965.             char* str = FUN_number_to_string(loc_merc_cost,inserted_string_1,10);
  966.             FUN_strcat(main_string,str);
  967.             FUN_strcpy(str_insert_d_mb,main_string);
  968.             main_string[0] = '\0';
  969.             FUN_read_from_king_txt_and_some_string_stuff("*MERCENARY");
  970.            
  971.             if (FUN_message_on_dip_screen(main_string,20,139) == 1)
  972.             {
  973.                 //loc_dip_status_and_money = civ_treasury[player_civ]; //BX
  974.                 if (civ_treasury[player_civ] < loc_merc_cost)
  975.                 {
  976.                     //mz_6::0519be
  977.                     main_string[0] = '\0';
  978.                     AX = "*UNFORTUNATE";
  979.                     LAB_show_nocontact_or_unfortunate_mess:
  980.                     FUN_read_from_king_txt_and_some_string_stuff(AX);
  981.                 }
  982.                 else
  983.                 {
  984.                     //mz_6::051976
  985.                     civ_treasury[par_civ] += loc_merc_cost;
  986.                     civ_treasury[par_civ] -= loc_merc_cost;
  987.                     FUN_strcpy(main_string,civ_name_plural[par_civ]);
  988.                     FUN_strcat(main_string, "declare war at the");
  989.                     FUN_strcat(main_string,civ_name_plural[att_civ]);
  990.                     FUN_strcat(main_string,str_declare_war_at_end);
  991.                     //actually doesn't declare war!! cunning AI.
  992.                 }
  993.                
  994.                 FUN_message_on_dip_screen(main_string,20,139);
  995.             } //"yes" to mercenary proposal
  996.         } //we continue talks or we started talks...
  997.     } //if peace: We respond... dialog etc.
  998.    
  999.     //mz_6::0519e2
  1000.     LAB_goto_D:
  1001.    
  1002.     if (loc_ready_to_cancel_peace != 0)
  1003.     {
  1004.         diplomacy_flags_next_byte[par_civ][player_civ] |= 0x1; //i.e. 0x100 for normal diplomacy byte, 0xe498 instead of 0xe499
  1005.         //25% chance at the beginning of turn to cancel peace one-way... when it happens, 0x200 flag is set...
  1006.     }
  1007.     //mz_6::0519fa
  1008.     diplomacy[par_civ][player_civ] &= 0xdf; //1101 1111, cancel 6th bit (5th from 0) - 0x20
  1009.     //cancel "previous attacks" flag...
  1010.     loc_dip_status_and_money = diplomacy[par_civ][player_civ];
  1011.     diplomacy[par_civ][player_civ] &= 0xdf; //cancel 0x20 bit also "in other direction"
  1012.    
  1013.     if (menu_selection_result != -1
  1014.     && civ_cities[par_civ] > 4 //DI: par_civ, SI: player_civ
  1015.     && civ_place[player_civ]+1 < civ_place[par_civ]
  1016.     && (loc_dip_status_and_money)&2 == 0) //at war
  1017.     {
  1018.         FUN_strcpy(str_insert_c_mb, civ_name_plural[par_civ]);
  1019.         INT_04(0x02d3, "*SCHISM"); //show help message from HELP.TXT, if before A.D. and if instance advice is set to "ON"
  1020.     }
  1021.    
  1022.     //mz_6::051a5d
  1023.     LAB_end_of_diplomacy:
  1024.     if (menu_selection_result != -1)
  1025.     {
  1026.         FUN_mz6_maybe_end_of_diplomacy_talks();
  1027.     }
  1028.     //mz_6::051a68
  1029.     if (civ_number_and_pair[par_civ] == 0xe) //English
  1030.     //set it back to normal...
  1031.     {
  1032.         FUN_strcpy(civ_leader_title[6][1],civ_leader_global_title[1]); //0x19b4, 0x33aa -> Emperor
  1033.         FUN_strcpy(civ_leader_title[6][2],civ_leader_global_title[2]); // ->King
  1034.     }
  1035.     gl_diplomacy_started_flag = 0;
  1036.     menu_selection_result = -1;
  1037.     science_or_diplomacy_special_screen = -1;
  1038.     return;
  1039. }
  1040.  
  1041. void FUN_cancel_diplomacy_status(int par_civ1, int par_civ2, int par_status)
  1042. {
  1043.     if (par_status == 2 //peace
  1044.     && (diplomacy[par_civ1][par_civ2]&2) != 0)
  1045.     {
  1046.         FUN_write_replay_entry(2,1,par_civ1*16+par_civ2);
  1047.     }
  1048.     diplomacy[par_civ1][par_civ2] &= ~par_status;
  1049.     diplomacy[par_civ2][par_civ1] &= ~par_status;
  1050.     if ((par_status&2) != 0) //we canceled peace...
  1051.     {
  1052.         diplomacy[par_civ1][par_civ2] &= 0xfb; //cancel 0x04 (ALLY) status
  1053.         diplomacy[par_civ2][par_civ1] &= 0xfb; //cancel 0x04 (ALLY) status
  1054.     }
  1055. }
  1056.  
  1057. void FUN_set_diplomacy_status(int par_civ1, int par_civ2, int par_status)
  1058. {
  1059.     if (par_status == 2 //peace
  1060.     && (diplomacy[par_civ1][par_civ2]&2) == 0) //were at war...
  1061.     {
  1062.         FUN_write_replay_entry(3,1,par_civ1*16+par_civ2);
  1063.     }
  1064.     diplomacy[par_civ1][par_civ2] |= par_status;
  1065.     diplomacy[par_civ2][par_civ1] |= par_status;
  1066.     if (par_status == 2) //peace
  1067.     {
  1068.         diplomacy[par_civ1][par_civ2] &= 0xdf; //cancel 0x20 (some actual military actions before) status
  1069.         diplomacy[par_civ2][par_civ1] &= 0xdf; //cancel 0x20 (some actual military actions before) status
  1070.     }
  1071. }
  1072.  
  1073. FUN_dipl_create_diplomacy_dialog_mb(int civ, int x, int y)
  1074. {
  1075.     if (gl_diplomacy_started_flag == 0) //diplomacy dialog "will you talk with him?.." was not called yet...
  1076.     {
  1077.         gl_diplomacy_started_flag = 1;
  1078.        
  1079.         if (menu_selection_result == 0) //not not from diplomat menu
  1080.         {
  1081.             if (x != -1)
  1082.             {
  1083.                 FUN_mb_change_map_view_position(player_civ,x,y):
  1084.             }
  1085.            
  1086.             while (1)
  1087.             {
  1088.                 //create string: an emissary from... bla-bla-bla
  1089.                 if (diplomacy[player_civ][civ] & 0x40) != 0) //embassy //player_civ: 16 civ: 2
  1090.                 {
  1091.                     //add "Check embassy" string
  1092.                 }
  1093.                
  1094.                 FUN_play_sound(leader_jingle[civ]);
  1095.                 FUN_update_screen_in_some_cases();
  1096.                 menu_selection_result = FUN_draw_some_message_A(main_string,100,80);
  1097.                 thunk_FUN_11a8_029a(); //??
  1098.                 if (menu_selection_result == -2)
  1099.                 {
  1100.                     INT_0E_1164(civ); //call intelligence report screen...
  1101.                 }
  1102.                 else
  1103.                     break;
  1104.             }
  1105.            
  1106.             if (menu_selection_result != -1) //yes, let's talk...
  1107.             {
  1108.                 FUN_common_func_mb_black_screen_A();
  1109.                 FUN_prepare_dip_scr_king_and_advisors(civ,5,1); //actually func uses only 1 param...
  1110.                 FUN_play_sound(leader_melody[civ]);
  1111.                 FUN_update_screen_mb();
  1112.                 gl_some_dip_scr_anim_graphics = civ_1_or_2_same_color[civ]+8;
  1113.                
  1114.                 if (gl_some_dip_scr_anim_graphics == 10) // 1 0000 barbarians (???)
  1115.                 {
  1116.                     gl_some_dip_scr_anim_graphics = 3; //???
  1117.                 }
  1118.                 //something-something...
  1119.                 (*0xd2dc) = 1; //??
  1120.                 science_or_diplomacy_special_screen = 1;
  1121.                 draw_advisor_faces_a = -1;
  1122.                 advisor_face_mb = 0;
  1123.                 sci_or_dip_flag_b = 0xc;
  1124.                 FUN_dipl_greetings_message(civ); //create greatings message (check vendetta ("O untruthworthy...", 4 random greatings, check if at least 1 nuke -> BACKED BY)
  1125.                 FUN_message_on_dip_screen(main_string,20,139); //show this message
  1126.             }
  1127.         } //menu_selection_result == 0, i.e. not from diplomat menu
  1128.     } //diplomacy is not started yet
  1129.    
  1130.     return menu_selection_result;
  1131. }
  1132.  
  1133. FUN_show_treaty_message(int par_civ)
  1134. {
  1135.     FUN_strcpy(str_insert_b,civ_name_adjective[par_civ]);
  1136.     FUN_strcpy(str_insert_a,civ_name_adjective[player_civ]);
  1137.     sci_or_dip_flag_b = 0xc;
  1138.     main_string[0] = '\0';
  1139.     FUN_read_from_king_txt_and_some_string_stuff("*TREATY");
  1140.     FUN_message_on_dip_screen(main_string,20,139);
  1141. }
  1142.  
  1143. FUN_set_peace_and_disband_units_on_chieftain(int par_civ)
  1144. {
  1145.     FUN_set_diplomacy_status(player_civ,par_civ,2); //set "peace" bit
  1146.     next_turn_for_talk_with_player[par_civ] = game_turn + 16; //next talks: 32 turns later...
  1147.     if (difficulty == 0)
  1148.     {
  1149.         (for int i = 0; i < 128; i++)
  1150.         {
  1151.             if (unit_list[par_civ][i] != -1)
  1152.             {
  1153.                 int cit = FUN_find_closest_city(unit_list[par_civ][i].x,unit_list[par_civ][i].y); //this function also change gl_distance (i.e. distance from founded city)
  1154.                 if (citie[cit].civ == player_civ
  1155.                 && gl_distance <= 2)
  1156.                 {
  1157.                     disband_unit(par_civ,i);
  1158.                 }
  1159.             }
  1160.         }
  1161.     }
  1162. }
  1163.  
  1164. FUN_mz6_maybe_end_of_diplomacy_talks()
  1165. {
  1166.     FUN_dipl_mb_memory_error_and_sound();
  1167.     //something-something...
  1168.     FUN_screen_fadeout_work();
  1169.     science_or_diplomacy_special_screen = -1;
  1170.     menu_selection_result = 0;
  1171.     gl_diplomacy_started_flag = 0;
  1172. }
  1173.  
  1174. //END OF OVERLAY MZ 6----------------------------------------------------------------
  1175.  
  1176. FUN_main_diplomacy(int par_civ1, int par_civ2, int par_x, int par_y)
  1177. //when 2 units meet...
  1178. {
  1179.     if (par_civ1 != 0 && par_civ2 != 0)
  1180.     {
  1181.         if (par_civ1 == player_civ)
  1182.         {
  1183.             if ((diplomacy_status[par_civ1][par_civ2]&1) == 0
  1184.             || game_turn-diplomacy_timer[par_civ2] >= 16)
  1185.             {
  1186.                 FUN_big_diplomacy_func(par_civ2,par_x,par_y);
  1187.                
  1188.             }
  1189.         }
  1190.        
  1191.         if (par_civ2 == player_civ)
  1192.         {
  1193.             if (diplomacy_status[par_civ1][par_civ2]&1) == 0
  1194.             || game_turn-diplomacy_timer[] >= 16)
  1195.             {
  1196.                 FUN_big_diplomacy_func(par_civ1,par_x,par_y);
  1197.             }
  1198.         }
  1199.        
  1200.         int loc_dip_status = diplomacy_status[par_civ1][par_civ2];
  1201.         diplomacy_status[par_civ1][par_civ2] |= 0x11; //contact + first contact
  1202.         diplomacy_status[par_civ2][par_civ1] |= 0x11; //contact + first contact
  1203.        
  1204.         if (par_civ1 != player_civ && par_civ2 != player_civ)
  1205.         {
  1206.             if ((((par_civ1 + par_civ2 + game_turn)&3) == 0) //"magic year"
  1207.             || loc_dip_status&1 == 0) //no contact
  1208.             &&
  1209.             (
  1210.                 ((diplomacy_status[par_civ1][par_civ2])&8) == 0
  1211.                 && ((diplomacy_status[par_civ2][par_civ1])&8) == 0 //no vendetta between AIs...
  1212.             )
  1213.             {
  1214.                 int res1 = FUN_some_comparison_ai_civs_milit_power(par_civ1,par_civ2);
  1215.                 int res2 = FUN_some_comparison_ai_civs_milit_power(par_civ2,par_civ1);
  1216.                
  1217.                 if ((res1 == 0 || FUN_check_wonder_eff(par_civ2,7) != 0 || civ_govt[par_civ1] >= G_REPUBLIC) //7 - great wall
  1218.                 &&
  1219.                 (res2 == 0 || FUN_check_wonder_eff(par_civ1,7) != 0 || civ_govt[par_civ2] >= G_REPUBLIC)) //7 - great wall
  1220.                 {
  1221.                     FUN_2_ai_civs_exchange_tech(par_civ1,par_civ2);
  1222.                    
  1223.                     if ((diplomacy_status[par_civ1][par_civ2]&2)==0) //war
  1224.                     {
  1225.                         if ((diplomacy_status[player_civ][par_civ1]&0x40)!=0
  1226.                         || diplomacy_status[player_civ][par_civ2]&0x40)!=0) //embassy
  1227.                         {
  1228.                             FUN_strcpy(main_string,civ_name_plural[par_civ1]);
  1229.                             FUN_strcat(main_string,0x2a13); //" and "
  1230.                             FUN_strcat(main_string,civ_name_plural[par_civ2]);
  1231.                             FUN_strcat(main_string,0x2a19); //" sign a peace treaty."
  1232.                             message_type = 1; //diplomats report...
  1233.                             FUN_draw_some_message_A(main_string,100,80);
  1234.                         }
  1235.                         FUN_set_diplomacy_status(par_civ1,par_civ2,2); //set peace status
  1236.                     }
  1237.                 }
  1238.                 else //time for war!
  1239.                 {
  1240.                     if (((diplomacy_status[par_civ1][par_civ2])&2)!=0 //peace
  1241.                     || (loc_dip_status&1) == 0) //no contact
  1242.                     {
  1243.                         if ((diplomacy_status[player_civ][par_civ1]&0x40) != 0
  1244.                         || (diplomacy_status[player_civ][par_civ2]&0x40) != 0)
  1245.                         {
  1246.                             FUN_strcpy(main_string,civ_name_plural[par_civ1]);
  1247.                             FUN_strcat(main_string,0x2a30);
  1248.                             FUN_strcat(main_string,civ_name_plural[par_civ2]);
  1249.                            
  1250.                             if ((diplomacy_status[par_civ1][par_civ2]&2) == 0)
  1251.                                 AX = 0x2a4d; //" declared war on each other."
  1252.                             else
  1253.                                 AX = 0x2a36; //" cancel peace treaty."
  1254.                             FUN_strcat(main_string,AX);
  1255.                             message_type = 1; //diplomats report...
  1256.                             FUN_draw_some_message_A(main_string,100,80);
  1257.                         }
  1258.                         FUN_cancel_diplomacy_status(par_civ1,par_civ2,2);//cancel peace status
  1259.                     }
  1260.                 }
  1261.             }
  1262.         }
  1263.     } //not barbarians
  1264. }
  1265.  
  1266. int FUN_some_comparison_ai_civs_milit_power(par_civ1, par_civ2)
  1267. {
  1268.     if ((global_debug_flags&1) == 0)
  1269.     {
  1270.         return 1; //wants war
  1271.     }
  1272.    
  1273.     if ((((diplomacy_status[par_civ1][player_civ]&3) != 1 //no "contact+no peace" (no war) //peace with player -> time to war with other AI...
  1274.     || civ_military_power[player_civ] <= civ_military_power[par_civ2]
  1275.     || (diplomacy_status[par_civ2][player_civ]&4) != 0) //ALLY
  1276.     &&
  1277.     ((diplomacy_status[par_civ2][player_civ]&3) != 1
  1278.     || civ_military_power[player_civ] <= civ_military_power[par_civ1]
  1279.     || (diplomacy_status[par_civ1][player_civ]&4) != 0))
  1280.     &&
  1281.     FUN_return_numb_of_nukes(par_civ2) <= unit_counter[par_civ1][U_NUCLEAR])
  1282.     {
  1283.         int loc_tot_civs = 0;
  1284.         for (int civ = 1; civ < 8; civ++)
  1285.         {
  1286.             if (civ != par_civ1 && civ != par_civ2
  1287.             && (diplomacy_status[par_civ1][civ]&3) == 1) //contact+no peace = war
  1288.             {
  1289.                 loc_tot_civs++;
  1290.             }
  1291.         }
  1292.        
  1293.         if (diplomacy_status[par_civ1][par_civ2]&2) != 0) //if peace, we want to start war less...
  1294.         {
  1295.             loc_tot_civs++;
  1296.         }
  1297.        
  1298.         int aggr_AX = leader_aggress[civ_number_and_pair[par_civ1]];
  1299.        
  1300.         int loc_tot_cities = 0;
  1301.         int loc_tot_attack = 0;
  1302.         int loc_tot_def_and_half_att = 0;
  1303.         for (int cont = 1; cont < 15; cont++)
  1304.         {
  1305.             if (cities_per_continent[par_civ1][cont] != 0
  1306.             && attack_per_cont[par_civ1][cont]/2 + defence_per_cont[par_civ1][cont] < FUN_get_civ_attack_power_on_cont(par_civ2,cont,par_civ1))
  1307.             //3rd param actually is not used
  1308.                 return 0; //wants peace
  1309.             if (attack_per_cont[par_civ1][cont] != 0)
  1310.             {
  1311.                 int loc_def_per_cont = defence_per_cont[par_civ2][cont];
  1312.                 if (loc_def_per_cont != 0)
  1313.                 {
  1314.                     loc_tot_attack += attack_per_cont[par_civ1][cont];
  1315.                     loc_tot_def_and_half_att += FUN_get_civ_attack_power_on_cont(par_civ2,cont,par_civ1)/2 + loc_def_per_cont;
  1316.                     //3rd param in get_civ_attack_power is not used
  1317.                     loc_tot_cities += cities_per_continent[par_civ1][cont];
  1318.                 }
  1319.             }
  1320.         }
  1321.         if ((loc_tot_civs-aggr_AX+4 <= (loc_tot_attack << 2) / loc_tot_def_and_half_att)
  1322.         || loc_tot_cities == 0)
  1323.         {
  1324.             return 1; //wants war
  1325.         }
  1326.     }
  1327.     return 0; //wants peace
  1328. }
  1329.  
  1330. FUN_2_ai_civs_exchange_tech(par_civ1, par_civ2)
  1331. {
  1332.     u16 loc_exchange_tech_flags = 0x0000;
  1333.     int loc_selected_tech12;
  1334.     int loc_selected_tech21;
  1335.     for (int tech = 0; tech < 72; tech++)
  1336.     {
  1337.             if (civ_has_tech_check(par_civ1,tech) == 0
  1338.             && civ_has_tech_check(par_civ2,tech) != 0)
  1339.             {
  1340.                 loc_exchange_tech_flags |= 1;
  1341.                 loc_selected_tech12 = tech;
  1342.             }
  1343.             if (civ_has_tech_check(par_civ2,tech) == 0
  1344.             && civ_has_tech_check(par_civ1,tech) != 0)
  1345.             {
  1346.                 loc_exchange_tech_flags |= 2;
  1347.                 loc_selected_tech21 = tech;
  1348.             }
  1349.     }
  1350.     if (loc_exchange_tech_flags == 3)
  1351.     {
  1352.         FUN_civ_advance_discovery(par_civ1,loc_selected_tech12,par_civ2);
  1353.         FUN_civ_advance_discovery(par_civ2,loc_selected_tech21,par_civ1);
  1354.         return 1;
  1355.     }
  1356.     return 0;
  1357. }
Advertisement
Add Comment
Please, Sign In to add comment