//////////////////////////////////////////////////////////////////////////// // // Diplomod, Destroy buildings and Air units triggers, by Dale Kent. // // Diplomod // // Version 3.6 - 14-July-2001 // // See readme-diplomod.txt for teaser, and history-diplomod.txt for version changes. // //////////////////////////////////////////////////////////////////////////// /////////////////////////////////// // 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_diplostance_1' { Text(ID_DIPLOSTANCE_CHANGE_1); Show(); } messagebox 'DIP_diplostance_2' { Text(ID_DIPLOSTANCE_CHANGE_2); Show(); } messagebox 'DIP_diplostance_3' { Text(ID_DIPLOSTANCE_CHANGE_3); Show(); } /////////////////////////////////// // 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)) { 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 { ///////////////////////////////// // Multiplayer AI personality bug fix! - 18-4-2002 ///////////////////////////////// if(g.year > 1) { DisableTrigger('DIP_InitDiploState'); } else { ///////////////////////////////// // End bug fix! - 18-4-2002 ///////////////////////////////// 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(150); 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_ARISTOCRACY) && IsPlayerAlive(civ2) && civ2 != 0 && DIP_hascontact[(DIP_NumOfPlayers * civ) + civ2] == 1 && !(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_NOBLE), 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; 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_ARISTOCRACY) && !(IsHumanPlayer(DIP_civ))) { DIP_random = random(30); if(DIP_random == 15) { 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 - 1-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; tmpVal = 0; // Line 500 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); if(CellOwner(WDT_tmpunit.location) == player[1] && GetAgreementDuration(player[0], player[1], 3) >= 5) { WDT_tmploc = WDT_tmpunit.location; AddCenter(WDT_tmploc); WDT_waterunit = 0; if(TerrainType(WDT_tmploc) >= 10 && TerrainType(WDT_tmploc) <= 17) { WDT_waterunit = 1; } if(TerrainType(WDT_tmploc) == 23 || TerrainType(WDT_tmploc) == 24) { WDT_waterunit = 1; } WDT_veteran = 0; if(IsVeteran(WDT_tmpunit)) { WDT_veteran = 1; } if(!(IsCivilian(WDT_tmpunit)) && WDT_waterunit != 1) { tmpVal = WDT_GetDistanceNearestCity(WDT_tmploc, player[0]); GetCityByIndex(player[0], tmpVal, tmpCity); WDT_tmploc = 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, WDT_tmploc, 2, WDT_tmpunit2); if(WDT_veteran == 1) { ToggleVeteran(WDT_tmpunit2, 1); } } } } } } } //////////////////////////////////////////////////////////////////////////// // // Destroy buildings script to allow for destruction of buildings due to conquest. // // By Dale // // Version 1.1 5-May-2001 // //////////////////////////////////////////////////////////////////////////// /////////////////////////////////// // Capture City event /////////////////////////////////// HandleEvent(CaptureCity) 'MM2_DestroyBuildsOnCapture' pre { city_t tmpcity; int_t tmpbuilding; int_t i; int_t randnum; tmpcity = city[0]; if(CityIsValid(tmpcity)) { for(i = 0; i < 55; i = i + 1) { randnum = random(100); if(randnum < 50) { DestroyBuilding(tmpcity, i); } } } } /////////////////////////////////// // Nuke City event /////////////////////////////////// HandleEvent(NukeCity) 'MM2_DestroyBuildsOnNuke' pre { city_t tmpcity; int_t tmpbuilding; int_t i; int_t randnum; tmpcity = city[0]; if(CityIsValid(tmpcity)) { for(i = 0; i < 55; i = i + 1) { randnum = random(100); if(randnum < 75) { DestroyBuilding(tmpcity, i); } } } } // Line 600 //////////////////////////////////////////////////////////////////////////// // // Air Unit script to make AI move air units back to base. // // By Dale // // Version 1.0 27-Mar-2001 // //////////////////////////////////////////////////////////////////////////// /////////////////////////////////// // Global variables /////////////////////////////////// int_t AIR_TYPE[]; // Array to hold air unit DB values int_t LANDING_TYPE[]; // Array to hold valid landing sites /////////////////////////////////// // Begin Game event /////////////////////////////////// HandleEvent(BeginTurn) 'MM2_AirGameStart' pre { AIR_TYPE[0] = UnitDB(UNIT_ATTACK_HELICOPTER); AIR_TYPE[1] = UnitDB(UNIT_BRITISH_FIGHTER); AIR_TYPE[2] = UnitDB(UNIT_CARGO_HELICOPTER); AIR_TYPE[3] = UnitDB(UNIT_DIVE_BOMBER); AIR_TYPE[4] = UnitDB(UNIT_INTERCEPTOR); AIR_TYPE[5] = UnitDB(UNIT_JET_BOMBER); AIR_TYPE[6] = UnitDB(UNIT_SPACE_PLANE); // AIR_TYPE[7] = UnitDB(UNIT_SPY_PLANE); AIR_TYPE[8] = UnitDB(UNIT_STEALTH_BOMBER); AIR_TYPE[9] = UnitDB(UNIT_STEALTH_FIGHTER); // AIR_TYPE[10] = UnitDB(UNIT_NUKE); // AIR_TYPE[11] = UnitDB(UNIT_CRUISE_MISSILE); LANDING_TYPE[0] = UnitDB(UNIT_AIRCRAFT_CARRIER); LANDING_TYPE[1] = UnitDB(UNIT_CARRIER); LANDING_TYPE[2] = TerrainImprovementDB(TILEIMP_AIR_BASES); DisableTrigger('MM2_AirGameStart'); } /////////////////////////////////// // Check if air unit /////////////////////////////////// int_f MM2_IsAir(int_t theType) { int_t i; int_t typeOfUnit; typeOfUnit = theType; for (i = 0; i < AIR_TYPE.#; i = i + 1) { if (typeOfUnit == AIR_TYPE[i]) { return 1; } } return 0; } /////////////////////////////////// // Check for landing unit /////////////////////////////////// int_f MM2_IsLandingUnit(location_t theLoc) { int_t i; int_t units; unit_t tmpland; location_t thesite; thesite = theLoc; units = GetUnitsAtLocation(thesite); if(units > 0) { for(i = 0; i < units; i = i + 1) { GetUnitFromCell(thesite, i, tmpland); if(tmpland.type == LANDING_TYPE[0] || tmpland.type == LANDING_TYPE[1]) { return 1; } } } if(TileHasImprovement(thesite, LANDING_TYPE[2])) { return 1; } return 0; } /////////////////////////////////// // Move Unit event /////////////////////////////////// HandleEvent(MoveOrder) 'MM2_AirMove' pre { int_t i; int_t j; int_t h; int_t x; int_t y; int_t numcities; int_t armycounter; city_t tmpcity; unit_t tmpUnit; // Line 700 army_t tmpArmy; army_t tmpArmy1; location_t tmploc; location_t tmploc1; location_t tmploc3; location_t tmploc4; location_t armyloc; armycounter = 0; tmpArmy = army[0]; armyloc = tmpArmy.location; tmploc3 = armyloc; player[3] = g.player; if(!(IsHumanPlayer(player[3]))) { for (i = 0; i < tmpArmy.size; i = i + 1) { GetUnitFromCell(armyloc, i, tmpUnit); if(MM2_IsAir(tmpUnit.type)) { numcities = player[3].cities; GetCityByIndex(player[3], 0, tmpcity); tmploc = tmpcity.location; for(h = 0; h < numcities; h = h + 1) { GetCityByIndex(player[3], h, tmpcity); tmploc1 = tmpcity.location; if(CityIsValid(tmpcity) && Distance(tmpUnit.location, tmploc1) < Distance(tmpUnit.location, tmploc)) { tmploc = tmploc1; } } for(j = 0; j < 10; j = j + 1) { GetNeighbor(tmploc3, 3, tmploc4); tmploc3 = tmploc4; } if(MM2_IsLandingUnit(tmploc3)) { if(Distance(tmpUnit.location, tmploc3) < Distance(tmpUnit.location, tmploc)) { tmploc = tmploc3; } } for(x = 0; x < 10; x = x + 1) { for(y = 0; y < 21; y = y + 1) { GetNeighbor(tmploc3, 2, tmploc4); tmploc3 = tmploc4; if(MM2_IsLandingUnit(tmploc3)) { if(Distance(tmpUnit.location, tmploc3) < Distance(tmpUnit.location, tmploc)) { tmploc = tmploc3; } } } GetNeighbor(tmploc3, 7, tmploc4); tmploc3 = tmploc4; if(MM2_IsLandingUnit(tmploc3)) { if(Distance(tmpUnit.location, tmploc3) < Distance(tmpUnit.location, tmploc)) { tmploc = tmploc3; } } for(y = 0; y < 21; y = y + 1) { GetNeighbor(tmploc3, 5, tmploc4); tmploc3 = tmploc4; if(MM2_IsLandingUnit(tmploc3)) { if(Distance(tmpUnit.location, tmploc3) < Distance(tmpUnit.location, tmploc)) { tmploc = tmploc3; } } } GetNeighbor(tmploc3, 7, tmploc4); tmploc3 = tmploc4; if(MM2_IsLandingUnit(tmploc3)) { if(Distance(tmpUnit.location, tmploc3) < Distance(tmpUnit.location, tmploc)) { tmploc = tmploc3; } } } if(armyloc != tmploc) { Event: UngroupOrder(tmpArmy); ClearOrders(tmpUnit); Event: AddUnitToArmy(tmpUnit, tmpArmy1, armycounter); armycounter = armycounter + 1; Event: MovePathOrder(tmpArmy1, tmploc); } } } } }