////////////////////////////////////////////////////////////////////////// // 3) Leaders Code // by Pedrunn // based on a Immortal Wombat's code ////////////////////////////////////////////////////////////////////////// HandleEvent(MoveUnits) 'MakeUnitsVeteran' pre { int_t i; int_t tmpNum; location_t tmpLoc; unit_t tmpunit; army_t tmpArmy; for (i=0;i < army[0].size;i=i+1 ){ // Scroll over the army that moves GetUnitFromArmy(army[0], i, tmpunit); // Get the units of it unit[0]=tmpunit; if ((unit[0].type == UnitDB(UNIT_ANCIENT_LEADER)) // if there are one of the leaders units ||(unit[0].type == UnitDB(UNIT_CLASSICAL_LEADER)) //... ||(unit[0].type == UnitDB(UNIT_MEDIEVAL_LEADER)) ||(unit[0].type == UnitDB(UNIT_MODERN_LEADER)) ||(unit[0].type == UnitDB(UNIT_INDUSTRIAL_LEADER)) ||(unit[0].type == UnitDB(UNIT_INFORMATION_LEADER)) ||(unit[0].type == UnitDB(UNIT_CYBERNETIC_LEADER)) ||(unit[0].type == UnitDB(UNIT_DIAMOND_LEADER)) ||(unit[0].type == UnitDB(UNIT_INDUSTRIAL_AIR_LEADER)) ||(unit[0].type == UnitDB(UNIT_INFORMATION_AIR_LEADER)) ||(unit[0].type == UnitDB(UNIT_CYBERNETIC_AIR_LEADER)) ||(unit[0].type == UnitDB(UNIT_DIAMOND_AIR_LEADER))) { //... tmpLoc = unit[0].location; tmpNum = GetUnitsAtLocation(tmpLoc); // Get the location of this leader for (i = 0; i < tmpNum; i = i + 1) { // Scroll over all units GetUnitFromCell(tmpLoc, i, tmpUnit); // that share the same location with the leader ToggleVeteran(tmpUnit, 1); // And make them veteran } } } } unit_t LeaderUnit[]; int_t LeaderRound[]; int_t LeaderCount; city_t LeaderCity; HandleEvent(BeginTurn) 'KillTheLeaderUnitTurn' post { int_t i; int_t DeathTurn; int_t tmpValue; tmpValue = GetCurrentRound(); for (i = 0; i < LeaderRound.#; i = i + 1){ DeathTurn = LeaderRound[i] + 30; if(tmpValue == DeathTurn) { Event: KillUnit(LeaderUnit[i], 0, LeaderUnit[i].owner); } } } HandleEvent(KillUnit) 'KillTheLeaderUnit' post { int_t i; int_t k; int_t tmpPlayer; int_t CityCount; city_t tmpCity; for (i = 0; i < LeaderCount; i = i + 1){ if(unit[0] == LeaderUnit[i]) { tmpPlayer = LeaderUnit[i].owner; CityCount = PlayerCityCount(tmpPlayer); for(k = 0; k < CityCount; k = k + 1) { GetCityByIndex(tmpPlayer, k, tmpCity); if(CityIsValid(tmpCity)) { Event: AddHappyTimer(tmpCity, 1, -2, 14); } } } } } HandleEvent(DisbandArmyOrder) 'DisbandLeaderUnit' post { int_t i; int_t j; int_t k; int_t tmpPlayer; int_t CityCount; unit_t tmpUnit; city_t tmpCity; for(i = 0; i < army[0].size; i = i + 1){ GetUnitFromArmy(army[0], i, tmpUnit); for (j = 0; j < LeaderCount; j = j + 1){ if(tmpUnit == LeaderUnit[j]) { tmpPlayer = LeaderUnit[j].owner; CityCount = PlayerCityCount(tmpPlayer); for(k=0; k < CityCount; k = k + 1) { GetCityByIndex(tmpPlayer, k, tmpCity); if(CityIsValid(tmpCity)) { Event: AddHappyTimer(tmpCity, 1, -2, 14); } } } } } } int_f CreateLeader(city_t tmpCity) { // new funtion to create a army depending on a city variable int_t direction; int_t tmpPlayer; int_t sucess; location_t tmpLoc; location_t tmpLoc2; unit_t tmpUnit; LeaderCity = tmpCity; sucess = 0; direction = 0; tmpLoc = LeaderCity.location; tmpPlayer = LeaderCity.owner; while(sucess == 0 && direction < 8) { if(GetUnitsAtLocation(tmpLoc) < 12){ if (HasAdvance(tmpPlayer, ID_ADVANCE_SMART_MATERIALS)) { if(random(2) == 0) { CreateUnit(tmpPlayer, UnitDB(UNIT_DIAMOND_AIR_LEADER), tmpLoc, 0, tmpUnit); } else{ CreateUnit(tmpPlayer, UnitDB(UNIT_DIAMOND_LEADER), tmpLoc, 0, tmpUnit); } SelectUnit(tmpUnit); sucess = 1; } elseif (HasAdvance(tmpPlayer, ID_ADVANCE_CYBERNETICS)) { if(random(2) == 0) { CreateUnit(tmpPlayer, UnitDB(UNIT_CYBERNETIC_AIR_LEADER), tmpLoc, 0, tmpUnit); } else{ CreateUnit(tmpPlayer, UnitDB(UNIT_CYBERNETIC_LEADER), tmpLoc, 0, tmpUnit); } SelectUnit(tmpUnit); sucess = 1; } elseif (HasAdvance(tmpPlayer, ID_ADVANCE_GUIDED_WEAPON_SYSTEMS)) { if(random(2) == 0) { CreateUnit(tmpPlayer, UnitDB(UNIT_INFORMATION_AIR_LEADER), tmpLoc, 0, tmpUnit); } else{ CreateUnit(tmpPlayer, UnitDB(UNIT_INFORMATION_LEADER), tmpLoc, 0, tmpUnit); } SelectUnit(tmpUnit); sucess = 1; } elseif (HasAdvance(tmpPlayer, ID_ADVANCE_REPEATING_RIFLES)) { if(random(2) == 0) { CreateUnit(tmpPlayer, UnitDB(UNIT_INDUSTRIAL_AIR_LEADER), tmpLoc, 0, tmpUnit); } else{ CreateUnit(tmpPlayer, UnitDB(UNIT_INDUSTRIAL_LEADER), tmpLoc, 0, tmpUnit); } SelectUnit(tmpUnit); sucess = 1; } elseif (HasAdvance(tmpPlayer, ID_ADVANCE_CONSCRIPTION)) { CreateUnit(tmpPlayer, UnitDB(UNIT_MODERN_LEADER), tmpLoc, 0); SelectUnit(tmpUnit); sucess = 1; } elseif (HasAdvance(tmpPlayer, ID_ADVANCE_JOINERY)) { CreateUnit(tmpPlayer, UnitDB(UNIT_MEDIEVAL_LEADER), tmpLoc, 0, tmpUnit); SelectUnit(tmpUnit); sucess = 1; } elseif (HasAdvance(tmpPlayer, ID_ADVANCE_IRON_WORKING)) { CreateUnit(tmpPlayer, UnitDB(UNIT_CLASSICAL_LEADER), tmpLoc, 0, tmpUnit); SelectUnit(tmpUnit); sucess = 1; } else { CreateUnit(tmpPlayer, UnitDB(UNIT_ANCIENT_LEADER), tmpLoc, 0, tmpUnit); SelectUnit(tmpUnit); sucess = 1; } if(sucess == 1) { LeaderRound[LeaderCount] = GetCurrentRound(); LeaderUnit[LeaderCount] = tmpUnit; LeaderCount = LeaderCount + 1; Message(tmpPlayer, 'GotLeaderUs'); // send messages to the player // MessageAllBut(tmpPlayer, 'GotLeaderThem'); // and the others players } } else{ tmpLoc = LeaderCity.location; GetNeighbor(tmpLoc, direction, tmpLoc2); tmpLoc = tmpLoc2; } direction = direction + 1; } } //------------------------// // Create Leader Chance // //------------------------// HandleEvent(CaptureCity) 'CreateLeaderWhenLoosesCity' pre { int_t tmpPlayer; city_t tmpCity; int_t CityCount; int_t i; if(CityIsValid(city[0])){ tmpPlayer = city[0].owner; CityCount = PlayerCityCount(tmpPlayer); if(Random(20) == 0){ for(i=0; i < CityCount; i = i + 1) { GetCityByIndex(tmpPlayer, i, tmpCity); if(CityIsValid(tmpCity) && CityHasBuilding(tmpCity, "IMPROVE_CAPITOL")) { CreateLeader(tmpCity); } } } } } HandleEvent(KillCity) 'CreateLeaderWhenCityIsKilled' pre { int_t tmpPlayer; city_t tmpCity; int_t CityCount; int_t i; tmpPlayer = city[0].owner; CityCount = PlayerCityCount(tmpPlayer); if(Random(2) == 0){ for(i=0; i < CityCount; i = i + 1) { GetCityByIndex(tmpPlayer, i, tmpCity); if(CityIsValid(tmpCity) && CityHasBuilding(tmpCity, "IMPROVE_CAPITOL")) { CreateLeader(tmpCity); } } } } HandleEvent(CreateWonder) 'CreateLeaderWhenFinishWonder' post { if(CityIsValid(city[0]) && Random(3) == 0){ CreateLeader(city[0]); } } HandleEvent(NukeCity) 'CreateLeaderWhenCityIsNuked' post { if(CityIsValid(city[0]) && Random(2) == 0){ CreateLeader(city[0]); } } HandleEvent(AccomplishFeat) 'CreateLeaderWhenAccomplishFeat' post { int_t tmpPlayer; city_t tmpCity; int_t CityCount; int_t i; tmpPlayer = player[0]; CityCount = PlayerCityCount(tmpPlayer); if(Random(3) == 0){ for(i=0; i < CityCount; i = i + 1) { GetCityByIndex(tmpPlayer, i, tmpCity); if(CityIsValid(tmpCity) && CityHasBuilding(tmpCity, "IMPROVE_CAPITOL")) { CreateLeader(tmpCity); } } } } messagebox 'GotLeaderUs' { location[0] = LeaderCity.location; title(ID_GREAT_NEWS); text(ID_GOT_LEADER_US); EyePoint(location[0]); show(); } messagebox 'GotLeaderThem' { title(ID_BAD_NEWS); text(ID_GOT_LEADER_THEM); show(); }