////////////////////////////////// // Barbarian Camp Code // // by Pedrunn // ////////////////////////////////// int_t MAX_BARB_CAMP_NUM; int_t OldBarbCityOwner; city_t BarbarianCamp[]; city_t ClosestToBarbCity; city_t BarbTribe; location_t BarbArmyOrgLoc[]; int_f IsLandTerrain(location_t tmpLoc) { int_t TType; TType = TerrainType(tmpLoc); if (TType == TerrainDB(TERRAIN_GRASSLAND) || TType == TerrainDB(TERRAIN_PLAINS) || TType == TerrainDB(TERRAIN_DESERT) || TType == TerrainDB(TERRAIN_TUNDRA) || TType == TerrainDB(TERRAIN_GLACIER) || TType == TerrainDB(TERRAIN_HILL) || TType == TerrainDB(TERRAIN_BROWN_HILL) || TType == TerrainDB(TERRAIN_WHITE_HILL) || TType == TerrainDB(TERRAIN_FOREST) || TType == TerrainDB(TERRAIN_JUNGLE) || TType == TerrainDB(TERRAIN_MOUNTAIN) || TType == TerrainDB(TERRAIN_BROWN_MOUNTAIN) || TType == TerrainDB(TERRAIN_WHITE_MOUNTAIN) || TType == TerrainDB(TERRAIN_SWAMP) || TType == TerrainDB(TERRAIN_DEAD)){ return 1; } return 0; } int_f GetGameBestLandUnit() { int_t BestUnit; BestUnit = UnitDB(UNIT_WARRIOR); return BestUnit; } int_f GetGameBestSeaUnit() { int_t BestUnit; BestUnit = UnitDB(UNIT_CATAMARAN); return BestUnit; } int_f IsCoastalCity(city_t theCity) { int_t sucess; int_t i; city_t tmpCity; location_t tmpLoc; location_t cityLoc; tmpCity = theCity; cityLoc = tmpCity.location; sucess = 0; while(i < 8 && sucess == 0) { GetNeighbor(cityLoc, i, tmpLoc); if(TerrainType(tmpLoc) == TerrainDB(TERRAIN_WATER_BEACH)) { sucess = 1; } i = i + 1; } return sucess; } int_f CreateEncampment(int_t c) { int_t i; int_t minDist; int_t j; int_t h; int_t sucess; int_t cityDist; int_t CityCount; int_t xcoord; int_t ycoord; city_t tmpCity2; city_t tmpCity; location_t tmpLoc; location_t tmpLoc2; int_t tmpPlayer; minDist = 30; h = 0; while(i < 30) { xcoord = Random(GetMapWidth()); ycoord = Random(GetMapHeight()); MakeLocation(tmpLoc, xcoord, ycoord); if(IsLandTerrain(tmpLoc) == 1 && CellOwner(tmpLoc) == -1) { CreateCity(0, tmpLoc, 0); GetCityByLocation(tmpLoc, tmpCity); BarbarianCamp[c] = tmpCity; BarbTribe = tmpCity; while(h < 8) { GetNeighbor(tmpLoc, h, tmpLoc2); if(IsLandTerrain(tmpLoc2) == 1) { BarbArmyOrgLoc[c] = tmpLoc2; sucess = 1; } h = h + 1; } for(tmpPlayer = 1; tmpPlayer <= 32; tmpPlayer = tmpPlayer + 1) { if(IsPlayerAlive(tmpPlayer)) { CityCount = PlayerCityCount(tmpPlayer); for(j = 0; j < CityCount; j = j + 1) { GetCityByIndex(tmpPlayer, j, tmpCity2); if(CityIsValid(tmpCity2)) { cityDist = distance(tmpLoc, tmpCity2.location); if(cityDist < minDist) { minDist = cityDist; ClosestToBarbCity = tmpCity2; } } } } } if(minDist < 30) { message(ClosestToBarbCity.owner, 'BarbEncampmentNearYou'); } return 1; } i = i + 1; } return 0; } HandleEvent(BeginTurn) 'SetGlobalVariable' pre { int_t c; int_t u; int_t i; int_t j; int_t randNum; int_t Count; int_t BestUnit; int_t minDist; city_t BarbCity; army_t tmpArmy; MAX_BARB_CAMP_NUM = GetMapHeight()/15; if(player[0] == 0) { Count = PlayerCityCount(player[0]); // Add unit to Build List for (u = 0; u < Count; u = u + 1){ GetCityByIndex(player[0], u, BarbCity); if(CityIsValid(BarbCity) && BarbCity.buildqueuelength < 6) { if(!IsCoastalCity(BarbCity)) { BestUnit = GetGameBestLandUnit; AddUnitToBuildList(BarbCity, BestUnit); } else{ randNum = Random(4); if(randNum == 0) { BestUnit = GetGameBestLandUnit(); AddUnitToBuildList(BarbCity, BestUnit); } else{ BestUnit = GetGameBestSeaUnit(); AddUnitToBuildList(BarbCity, BestUnit); } } } } // Check and Create if ok the Barb Camps // if(Random(15) == 0 // && g.year > 30) { if(MAX_BARB_CAMP_NUM > BarbarianCamp.#) { CreateEncampment(BarbarianCamp.#); } else{ while(c < BarbarianCamp.#) { if(!CityIsValid(BarbarianCamp[c])) { CreateEncampment(c); } c = c + 1; } } // } // Find a place to make armies for(i = 0; i < player[0].armies; i = i + 1) { GetArmyByIndex(player[0], i, tmpArmy); if(ArmyIsValid(tmpArmy) && tmpArmy.size < 4){ for(j = 0; j < BarbarianCamp.#; j = j + 1) { if(CityIsValid(BarbarianCamp[j])) { minDist = distance(BarbarianCamp[j].location, tmpArmy.location); if(minDist < 10) { Event: MovePathOrder(tmpArmy, BarbArmyOrgLoc[j]); } } } } } } } HandleEvent(MakePop) 'BarbCampsCantGrow' pre { int_t i; for(i = 0; i < BarbarianCamp.#; i = i + 1){ if(city[0] == BarbarianCamp[i] && city[0].population == 1) { return STOP; } } } int_t GoldFromBarbCamp; int_t PWFromBarbCamp; HandleEvent(CaptureCity) 'BarbCityCaptured' pre { int_t c; OldBarbCityOwner = city[0].owner; for(c = 0; c < BarbarianCamp.#; c = c + 1) { if(CityIsValid(BarbarianCamp[c]) && BarbarianCamp[c] == city[0]) { GoldFromBarbCamp = Random(100); PWFromBarbCamp = Random(100); setPW(player[0], (player[0].publicworkslevel + PWFromBarbCamp)); AddGold(player[0], GoldFromBarbCamp); message(player[0], 'BarbCampWasCaptured'); } } } HandleEvent(CaptureCity) 'BarbCapturingCities' post { int_t randNum; int_t randNum2; int_t InitialPW; int_t FinalPW; int_t TotalGold; int_t p; int_t c; int_t i; int_t j; int_t u; int_t h; int_t num; int_t GiveCount; int_t sucess; int_t GiveArmyCount; int_t cityCount; int_t tmpDist; int_t ToBeGivenType[]; unit_t tmpUnit; army_t tmpArmy; city_t dummyCity; location_t tmpLoc; if(player[0] == 0) { player[1] = OldBarbCityOwner; randNum = Random(4); if(randNum == 0) { // Nothing } elseif(randNum == 1) { GiveCount = 0; for (p = 0; p <= 32; p = p + 1){ if(!IsPlayerAlive(p)) { player[3] = p; tmpLoc = city[0].location; num = GetUnitsAtLocation(tmpLoc); for(i = 0; i < num; i = i + 1){ GetUnitFromCell(tmpLoc, i, tmpUnit); ToBeGivenType[GiveCount] = tmpUnit.type; GiveCount = GiveCount + 1; Event:DisbandUnit(tmpUnit); } Event: GiveCity(city[0], p); for(j = 0; j < GiveArmyCount; j = j + 1) { CreateUnit(p, ToBeGivenType[j], city[0].location, 0); } for(c = 0; c < BarbarianCamp.#; c = c + 1) { if(CityIsValid(BarbarianCamp[c])) { tmpDist = distance(city[0].location, BarbarianCamp[c].location); if(tmpDist < 20) { Event: GiveCity(BarbarianCamp[c], p); BarbarianCamp[c] = dummyCity; } } } message(player[1], 'BarbsBecameCivilization'); return STOP; } } } else{ for(i = 0; i < 80; i = i + 1) { randnum2 = random(5); if(randnum == 0) { DestroyBuilding(city[0], i); } } cityCount = PlayerCityCount(OldBarbCityOwner); TotalGold = PlayerGold(OldBarbCityOwner); AddGold(OldBarbCityOwner, -(TotalGold/cityCount/(1 + Random(4)))); InitialPW = player[1].publicworkslevel; FinalPW = InitialPW - ((InitialPW)/(cityCount)/(1 + Random(4))); setPW(OldBarbCityOwner, FinalPW); message(OldBarbCityOwner, 'CityWasPlunderedByBarbs'); Event: KillPop(city[0]); h = 8; while(h > 0 && sucess == 0) { GetUnitFromCell(city[0].location, 0, tmpUnit); GetArmyFromUnit(tmpUnit, tmpArmy); GetNeighbor(city[0].location, h, tmpLoc); if(IsLandTerrain(tmpLoc) == 1) { Event: Teleport(tmpArmy, tmpLoc); sucess = 1; } h = h - 1; } Event: GiveCity(city[0], OldBarbCityOwner); } } } HandleEvent(MovePathOrder) 'BarbStackGrowsUp' post { int_t tmpPlayer; army_t tmpArmy; if (ArmyIsValid(army[0])){ tmpArmy = army[0]; tmpPlayer = tmpArmy.owner; if(tmpPlayer == 0){ Event: GroupOrder(tmpArmy); } } } messagebox 'BarbEncampmentNearYou' { Show(); Title(ID_BE_AWARE); text(ID_BARB_ENCAMPMENT_NEAR_YOU); } messagebox 'BarbsBecameCivilization' { Show(); Title(ID_BAD_NEWS); text(ID_BARB_BECAME_CIV); } messagebox 'CityWasPlunderedByBarbs' { Show(); Title(ID_BARB_PARTY); text(ID_BARB_PLUNDERED_CITY); } messagebox 'BarbCampWasCaptured' { Show(); Title(ID_CONGRATULATONS); text(ID_BARB_CAMP_CAPTURED); }