//////////////////////////////////////////////////////////////////////////// // // Diplomod script to make AI do diplomacy with itself. // // Diplomacy by Dale // // Version 3.6 - 14-July-2001 // // See readme-diplomod.txt for teaser, and history-diplomod.txt for version changes. // // IMPROVED BY: player1 // Date: 15-Oct-2001 // Version 1.15 // Added: // -Embassies more often (3x times) // -Diplomatic personality chage 30% more often // -WarOver script: AI vs AI wars end after some time // 11-20 turns in war: 2% end war chance (per turn) // 21-30 turns in war: 4% end war chance // 31-40 turns in war: 6% end war chance // 41-50 turns in war: 8% end war chance // 51 turns or more in war: 10% end war chance // -Ending War sets regard between AIs to +250 // (so AIs wont declare war on each other next turn) // //////////////////////////////////////////////////////////////////////////// /////////////////////////////////// // Global variables /////////////////////////////////// int_t DIP_NumOfPlayers; // Der! int_t DIP_random; // Random roller int_t DIP_random2; // Random roller 2 int_t DIP_random3; // Random roller 3 int_t DIP_civ; // Foreigner civ int_t DIP_requestpriority; // Request priority int_t DIP_request; // Request number int_t DIP_tmpcity; // City holding variable int_t DIP_tmpadvance; // Advance holding variable int_t DIP_tmpgold; // Gold holding variable int_t DIP_turns; // Turns in game int_t DIP_tmpvalue; // Int holder int_t DIP_tmpvalue2; // Int holder 2 int_t DIP_diplostate; // Diplo state holder unit_t DIP_tmpunit; // Unit holder city_t DIP_diplocity; // City diplomat heads for location_t DIP_tmploc; // Location holder int_t DIP_hasemb[]; // Has embassy array int_t DIP_hademb[]; // Had embassy array int_t DIP_hascontact[]; // Has Contact array /////////////////////////////////// // Diplomod messages /////////////////////////////////// messagebox 'DIP_start' { Show(); Title(ID_DIPLOMOD_START_TITLE); Text(ID_DIPLOMOD_START); } messagebox 'DIP_diplostance_1' { Show(); Text(ID_DIPLOSTANCE_CHANGE_1); } messagebox 'DIP_diplostance_2' { Show(); Text(ID_DIPLOSTANCE_CHANGE_2); } messagebox 'DIP_diplostance_3' { Show(); Text(ID_DIPLOSTANCE_CHANGE_3); } /////////////////////////////////// // Greeting message /////////////////////////////////// MessageBox 'DIPLOMACY_POPUP_GREETING' { Text(ID_ACTION_STRING); Show(); } /////////////////////////////////// // Declare war message /////////////////////////////////// MessageBox 'DIPLOMACY_POPUP_DECLARE_WAR' { Text(ID_POPUP_DECLARE_WAR_ANNC); Show(); } /////////////////////////////////// // Begin game initialisations /////////////////////////////////// HandleEvent(BeginTurn) 'DIP_BeginGame' pre { if(IsHumanPlayer(g.player)) { // Message (1, 'DIP_start'); DIP_NumOfPlayers = preference("NumPlayers"); DIP_hasemb[(DIP_NumOfPlayers * DIP_NumOfPlayers) + DIP_NumOfPlayers] = 0; DIP_hademb[(DIP_NumOfPlayers * DIP_NumOfPlayers) + DIP_NumOfPlayers] = 0; DIP_hascontact[(DIP_NumOfPlayers * DIP_NumOfPlayers) + DIP_NumOfPlayers] = 0; DisableTrigger('DIP_BeginGame'); DIP_turns = 0; } } /////////////////////////////////// // Ensure AI -> AI Diplo state /////////////////////////////////// HandleEvent(InitDiplomaticState) 'DIP_InitDiploState' pre { int_t tmpPer; tmpPer = 0; tmpPer = GetPersonalityType(player[0]); if(!(IsHumanPlayer(player[0])) && !(IsHumanPlayer(player[1])) && player[0] != 0 && player[1] != 0) { if(tmpPer == 1) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_SUCKUP); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 2) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_WARMONGER); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 3) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_WARMONGER); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 4) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_WARMONGER); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 5) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_NORMAL); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 6) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_NORMAL); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 7) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_NORMAL); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 8) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_NORMAL); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } if(tmpPer == 9) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_WARMONGER); ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); } } } HandleEvent(NextDiplomaticState) 'DIP_NextDiploState' pre { int_t randNum; randNum = random(100); //chaged from 150 by player1 if(randNum == 50) { int_t tmpPer; tmpPer = 0; tmpPer = random(3); if(!(IsHumanPlayer(player[0])) && player[0] != 0 && player[1] != 0) { if(tmpPer == 1) { if(!(IsHumanPlayer(player[1]))) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_SUCKUP); } else { DIP_diplostate = DiplomacyDB(DIPLOMACY_MAKE_FRIEND); } ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); if(player[1] == 1) { Message (1, 'DIP_diplostance_1'); } } if(tmpPer == 2) { if(!(IsHumanPlayer(player[1]))) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_WARMONGER); } else { DIP_diplostate = DiplomacyDB(DIPLOMACY_PROVOKE_WAR); } ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); if(player[1] == 1) { Message (1, 'DIP_diplostance_2'); } } if(tmpPer == 3) { if(!(IsHumanPlayer(player[1]))) { DIP_diplostate = DiplomacyDB(DIPLOMACY_AI_AI_NORMAL); } else { DIP_diplostate = DiplomacyDB(DIPLOMACY_DEFAULT); } ConsiderDiplomaticState(player[0], player[1], 9999, DIP_diplostate, -1,-1,-1); ChangeDiplomaticState(player[0], player[1]); if(player[1] == 1) { Message (1, 'DIP_diplostance_3'); } } } } } /////////////////////////////////// // Create embassy routine /////////////////////////////////// void_f DIP_EstablishEmbassyFunc(int_t recipient) { int_t civ; int_t civ2; city_t tmpcity; location_t tmploc; unit_t tmpunit; civ2 = recipient; civ = g.player; if(HasAdvance(civ, ID_ADVANCE_BUREAUCRACY) && IsPlayerAlive(civ2) && DIP_hascontact[(DIP_NumOfPlayers * civ) + civ2] == 1 && civ2 != 0 && !(AtWarWith(civ, civ2))) { GetCityByIndex(civ2, 0, tmpcity); if(CityIsValid(tmpcity)) { GetRandomNeighbor(tmpcity.location, tmploc); if(GetUnitsAtLocation(tmploc) == 0) { if(TerrainType(tmploc) < 10 || TerrainType(tmploc) > 17 && TerrainType(tmploc) != 23 && TerrainType(tmploc) != 24) { CreateUnit(civ, UnitDB(UNIT_DIPLOMAT), tmploc, 0, tmpunit); Event: EstablishEmbassyUnit(tmpunit, tmpcity); Event: DisbandUnit(tmpunit); DIP_hasemb[(DIP_NumOfPlayers * civ) + civ2] = 1; DIP_hademb[(DIP_NumOfPlayers * civ) + civ2] = 0; } } } } } /////////////////////////////////// // Check embassy routine /////////////////////////////////// HandleEvent(BeginTurn) 'DIP_EmbassyCheck' pre { int_t civ; int_t civ2; civ = g.player; for(civ2 = 1; civ2 < DIP_NumOfPlayers; civ2 = civ2 + 1) { if((AtWarWith(civ, civ2)) && DIP_hasemb[(DIP_NumOfPlayers * civ) + civ2] == 1) { DIP_hasemb[(DIP_NumOfPlayers * civ) + civ2] = 0; DIP_hademb[(DIP_NumOfPlayers * civ) + civ2] = 1; } if(DIP_hasemb[(DIP_NumOfPlayers * civ) + civ2] == 0 && DIP_hademb[(DIP_NumOfPlayers * civ) + civ2] == 1 && !(AtWarWith(civ, civ2)) && DIP_hascontact[(DIP_NumOfPlayers * civ) + civ2] == 1) { DIP_EstablishEmbassyFunc(civ2); } } } /////////////////////////////////// // Main routine /////////////////////////////////// HandleEvent(BeginTurn) 'DIP_MainRoutine' post { if(g.player == 1) { DIP_turns = DIP_turns + 1; } player[0] = g.player; if(!(IsHumanPlayer(player[0]))) { for(DIP_civ = 0; DIP_civ < DIP_NumOfPlayers; DIP_civ = DIP_civ + 1) { player[1] = DIP_civ; ////////////////////////////////////////////////// //War Over script for DiploMOD int_t my_warturn; int_t my_rnd; int_t my_regard01; int_t my_regard10; my_regard01 = GetEffectiveRegard(player[0], player[1]); my_regard10 = GetEffectiveRegard(player[1], player[0]); if(!IsHumanPlayer(player[1])) { my_warturn = TurnsAtWar(player[0], player[1]); my_rnd = random(100); if((my_warturn > 10) && (my_warturn <= 20)) { if (my_rnd >= 1 && my_rnd <= 2) { //2% chance CancelAgreement(player[0], player[1], 31); LogRegardEvent(player[0], player[1], 250 - my_regard01, 0, ID_REGARD_EVENT_POSITIVE_SENDER_DIPLOMACY_RESULT, 0); LogRegardEvent(player[1], player[0], 250 - my_regard10, 0, ID_REGARD_EVENT_POSITIVE_RECEIVER_DIPLOMACY_RESULT, 0); Message (1, '401WarOver'); } } if((my_warturn > 20) && (my_warturn <= 30)) { if (my_rnd >= 1 && my_rnd <= 4) { //4% chance CancelAgreement(player[0], player[1], 31); LogRegardEvent(player[0], player[1], 250 - my_regard01, 0, ID_REGARD_EVENT_POSITIVE_SENDER_DIPLOMACY_RESULT, 0); LogRegardEvent(player[1], player[0], 250 - my_regard10, 0, ID_REGARD_EVENT_POSITIVE_RECEIVER_DIPLOMACY_RESULT, 0); Message (1, '401WarOver'); } } if((my_warturn > 30) && (my_warturn <= 40)) { if (my_rnd >= 1 && my_rnd <= 6) { //6% chance CancelAgreement(player[0], player[1], 31); LogRegardEvent(player[0], player[1], 250 - my_regard01, 0, ID_REGARD_EVENT_POSITIVE_SENDER_DIPLOMACY_RESULT, 0); LogRegardEvent(player[1], player[0], 250 - my_regard10, 0, ID_REGARD_EVENT_POSITIVE_RECEIVER_DIPLOMACY_RESULT, 0); Message (1, '401WarOver'); } } if((my_warturn > 40) && (my_warturn <= 50)) { if (my_rnd >= 1 && my_rnd <= 8) { //8% chance CancelAgreement(player[0], player[1], 31); LogRegardEvent(player[0], player[1], 250 - my_regard01, 0, ID_REGARD_EVENT_POSITIVE_SENDER_DIPLOMACY_RESULT, 0); LogRegardEvent(player[1], player[0], 250 - my_regard10, 0, ID_REGARD_EVENT_POSITIVE_RECEIVER_DIPLOMACY_RESULT, 0); Message (1, '401WarOver'); } } if(my_warturn > 50) { if (my_rnd >= 1 && my_rnd <= 10) { //10% chance CancelAgreement(player[0], player[1], 31); LogRegardEvent(player[0], player[1], 250 - my_regard01, 0, ID_REGARD_EVENT_POSITIVE_SENDER_DIPLOMACY_RESULT, 0); LogRegardEvent(player[1], player[0], 250 - my_regard10, 0, ID_REGARD_EVENT_POSITIVE_RECEIVER_DIPLOMACY_RESULT, 0); Message (1, '401WarOver'); } } } ////////////////////////////////////////////////// if(player[1] != 0 && player[0] != 0 && DIP_hascontact[(DIP_NumOfPlayers * player[0]) + player[1]] == 1) { DIP_requestpriority = 1500; for(DIP_request = 1; DIP_request < 39; DIP_request = DIP_request + 1) { if(DIP_request == 2) { DIP_tmpcity = player[1].largestcity; if(CityIsValid(DIP_tmpcity)) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 2, DIP_tmpcity, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } } if(DIP_request == 10) { GetStopResearchingAdvance(player[0], player[1], DIP_tmpadvance); if(DIP_tmpadvance != 0) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 10, DIP_tmpadvance, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } } if(DIP_request == 3) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 3, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 4) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 4, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 5) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 5, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 6) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 6, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } // Request 11 -> 16 are "Reduce weapon" requests if(DIP_request == 23) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 23, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 24) { if(!(IsHumanPlayer(player[1])) && player[1] != 0 && DIP_hascontact[(DIP_NumOfPlayers * player[0]) + player[1]] == 1) { if(DIP_turns <= 500) { DIP_tmpvalue = 600 - DIP_turns; } else { DIP_tmpvalue = 100; } DIP_random2 = random(DIP_tmpvalue); if(DIP_random2 == 5) { Event:GiveMap(player[0], player[1]); Event:GiveMap(player[1], player[0]); } } else { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 24, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } } if(DIP_request == 29) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 29, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 30) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 30, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } // Request 31 is covered by "Declare War" button if(DIP_request == 32) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 32, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 33) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 33, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 34) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 34, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } if(DIP_request == 36) { ConsiderNewProposal(player[0], player[1], DIP_requestpriority, 36, 0, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS, ID_AIS_LOVE_AIS); } } } } } } /////////////////////////////////// // Flag when contact is made /////////////////////////////////// HandleEvent(BeginTurn) 'DIP_FlagContactMade' pre { int_t civ; int_t civ2; int_t x; int_t y; int_t z; int_t numCities; int_t owner; int_t cityowner; unit_t tmpUnit1; unit_t tmpUnit2; city_t tmpCity; location_t cityLoc; location_t tmpLoc1; location_t tmpLoc2; civ = g.player; player[0] = g.player; for(civ2 = 0; civ2 < DIP_NumOfPlayers; civ2 = civ2 + 1) { player[1] = civ2; for(x = 0; x < player[0].units; x = x + 1) { GetUnitByIndex(civ, x, tmpUnit1); tmpLoc1 = tmpUnit1.location; for(y = 0; y < 8; y = y + 1) { GetNeighbor(tmpLoc1, y, tmpLoc2); if(GetUnitsAtLocation(tmpLoc2) != 0) { GetUnitFromCell(tmpLoc2, 0, tmpUnit2); owner = tmpUnit2.owner; if(civ != owner) { DIP_hascontact[(DIP_NumOfPlayers * civ) + owner] = 1; DIP_hascontact[(DIP_NumOfPlayers * owner) + civ] = 1; } } numCities = player[1].cities; for(z = 0; z < numCities; z = z + 1) { GetCityByIndex(civ2, z, tmpCity); if(CityIsValid(tmpCity)) { cityLoc = tmpCity.location; if(cityLoc == tmpLoc2) { DIP_hascontact[(DIP_NumOfPlayers * civ) + civ2] = 1; DIP_hascontact[(DIP_NumOfPlayers * civ2) + civ] = 1; } } } } } } } /////////////////////////////////// // Flag when embassy is made /////////////////////////////////// HandleEvent(EstablishEmbassy) 'DIP_FlagEmbassyMade' pre { int_t civ; int_t civ2; civ = g.player; civ2 = player[1]; DIP_hasemb[(DIP_NumOfPlayers * civ) + civ2] = 1; } /////////////////////////////////// // Turn flag on to create embassy /////////////////////////////////// HandleEvent(BeginTurn) 'DIP_EstabEmb' pre { DIP_civ = g.player; if(HasAdvance(DIP_civ, ID_ADVANCE_BUREAUCRACY) && !(IsHumanPlayer(DIP_civ))) { DIP_random = random(10); //changed from 30 by player1 if(DIP_random == 5) { //changed form 15 by player1 DIP_random3 = random(DIP_NumOfPlayers); player[1] = DIP_random3; if(IsPlayerAlive(player[1]) && player[1] != 0 && !(AtWarWith(DIP_civ, player[1])) && DIP_hasemb[(DIP_NumOfPlayers * DIP_civ) + DIP_random3] == 0 && DIP_hascontact[(DIP_NumOfPlayers * DIP_civ) + DIP_random3] == 1) { DIP_hademb[(DIP_NumOfPlayers * DIP_civ) + DIP_random3] = 1; DIP_EstablishEmbassyFunc(player[1]); } } } } /////////////////////////////////// // diplomacy.slc routines /////////////////////////////////// HandleEvent(NewProposal) 'DIP_ProposalResponseEvent' pre { if(IsHumanPlayer(player[0])) { if(!(AtWarWith(player[0], player[1]))) { ConsiderResponse(player[0].owner, player[1].owner, 50, 2); } } else { if(DIP_request == 2) { ConsiderResponse(player[0].owner, player[1].owner, 100, 1); } elseif(DIP_request == 3) { ConsiderResponse(player[0], player[1], 1500, 2); } elseif(DIP_request == 4) { Accept(player[0], player[1]); } elseif(DIP_request >= 33 && DIP_request <= 37) { ConsiderResponse(player[0], player[1], 1500, 2); } else { ConsiderResponse(player[0].owner, player[1].owner, 1500, 2); } } } HandleEvent(Counter) 'DIP_CounterResponseEvent' pre { if(IsHumanPlayer(player[0])) { ConsiderResponse(player[0].owner, player[1].owner, 10, 1, 1, 1, 1); } else { ConsiderResponse(player[0].owner, player[1].owner, 1500, 2); } } HandleEvent(Threaten) 'DIP_ThreatResponseEvent' pre { ConsiderResponse(player[0].owner, player[1].owner, 10, 1, 1, 1, 1); } HandleEvent(Reject) 'DIP_ThreatResponseEvent' pre { ConsiderResponse(player[0].owner, player[1].owner, 10, 1, 1, 1, 1); } //////////////////////////////////////////////////////////////////////////// // // Withdraw script to make AI withdraw troops on agreement // // Withdraw by Dale // // Version 1.3 - 14-May-2001 // // See readme-withdraw.txt for teaser, and history-withdraw.txt for version changes. // //////////////////////////////////////////////////////////////////////////// /////////////////////////////////// // Global variables /////////////////////////////////// int_t WDT_civ; // Civ holder int_t WDT_NumOfPlayers; // Der! int_t WDT_numoftroops; // Number of troops int_t WDT_count; // Counter int_t WDT_count2; // Counter 2 int_t WDT_waterunit; // Water unit flag int_t WDT_tmptype; // Unit type holder int_t WDT_veteran; // Veteran flag unit_t WDT_tmpunit; // Unit holder unit_t WDT_tmpunit2; // Unit holder 2 army_t WDT_tmparmy; // Army holder location_t WDT_tmploc; // Location holder location_t WDT_tmploc2; // Location holder 2 /////////////////////////////////// // Begin Game stuff /////////////////////////////////// HandleEvent(BeginTurn) 'WDT_BeginGame' pre { if(IsHumanPlayer(g.player)) { WDT_NumOfPlayers = preference("NumPlayers"); DisableTrigger('WDT_BeginGame'); } } /////////////////////////////////// // Find nearest home city /////////////////////////////////// int_f WDT_GetDistanceNearestCity(location_t theLoc, int_t thePlayer) { location_t tmpLoc; city_t tmpCity; int_t i; int_t min; int_t city; int_t cities; int_t val; int_t tmpPlayer; tmpPlayer = thePlayer; tmpLoc = theLoc; min = 10000; city = 0; // If no other city is closer put it near the capital cities = Cities(tmpPlayer); for(i = 0; i < cities; i = i + 1) { GetCityByIndex(tmpPlayer, i, tmpCity); val = SquaredDistance(tmpCity.location, tmpLoc); if(val < min) { min = val; city = i; } } return city; } /////////////////////////////////// // The magic art of withdrawing /////////////////////////////////// HandleEvent(BeginTurn) 'WDT_MainRoutine' pre { int_t tmpVal; city_t tmpCity; location_t tmploc2; location_t tmploc3; tmpVal = 0; player[0] = g.player; for(WDT_civ = 0; WDT_civ < WDT_NumOfPlayers; WDT_civ = WDT_civ + 1) { player[1] = WDT_civ; if(!(IsHumanPlayer(player[0])) && player[1] != player[0] && HasAgreement(player[0], player[1], 3)) { WDT_numoftroops = player[0].units; for(WDT_count = 0; WDT_count < WDT_numoftroops; WDT_count = WDT_count + 1) { GetUnitByIndex(player[0], WDT_count, WDT_tmpunit); tmploc2 = WDT_tmpunit.location; if(CellOwner(tmploc2) == WDT_civ && GetAgreementDuration(player[0], WDT_civ, 3) >= 5) { AddCenter(tmploc2); WDT_waterunit = 0; if(TerrainType(tmploc2) >= 10 && TerrainType(tmploc2) <= 17) { WDT_waterunit = 1; } WDT_veteran = 0; if(IsVeteran(WDT_tmpunit)) { WDT_veteran = 1; } if(!(IsCivilian(WDT_tmpunit)) && WDT_waterunit != 1) { tmpVal = WDT_GetDistanceNearestCity(tmploc2, player[0]); GetCityByIndex(player[0], tmpVal, tmpCity); tmploc3 = tmpCity.location; AddEffect(WDT_tmpunit.location, "SPECEFFECT_DIPLOMATIC", "SOUND_ID_EXPEL"); WDT_tmptype = WDT_tmpunit.type; Event:DisbandUnit(WDT_tmpunit); CreateUnit(player[0], WDT_tmptype, tmploc3, 2, WDT_tmpunit2); if(WDT_veteran == 1) { ToggleVeteran(WDT_tmpunit2, 1); } } } } } } }