// Test 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_t MAX_BARB_CAMP_NUM; city_t BarbarianCamp[]; HandleEvent(BeginTurn) 'SetGlobalVariable' pre { int_t xcoord; int_t ycoord; int_t i; int_t c; int_t p; int_t j; int_t u; int_t randNum; int_t Count; int_t TType; int_t sucess; int_t minDist; int_t cityDist; int_t CityCount; int_t BestUnit; int_t ClosestPlayer; city_t tmpCity; city_t tmpCity2; city_t ClosestCity; city_t BarbCity; location_t tmpLoc; minDist = 30; MAX_BARB_CAMP_NUM = GetMapWidth()/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(2); if(randNum == 0) { BestUnit = GetGameBestLandUnit(); AddUnitToBuildList(BarbCity, BestUnit); } else{ BestUnit = GetGameBestSeaUnit(); AddUnitToBuildList(BarbCity, BestUnit); } } } } // Check and Create if ok the Barb Camps for(c = 0; c < MAX_BARB_CAMP_NUM; c = c + 1) { if(!CityIsValid(BarbarianCamp[c])) { // if(Random(15) == 0 // && g.year > 30) { while(sucess == 0 && i < 30) { xcoord = Random(GetMapWidth()); ycoord = Random(GetMapHeight()); MakeLocation(tmpLoc, xcoord, ycoord); if(IsLandTerrain(tmpLoc) == 1 && CellOwner(tmpLoc) == -1) { CreateCity(0, tmpLoc, 0, tmpCity); BarbarianCamp[c] = tmpCity; sucess = 1; for(p = 1; p <= 32; p = p + 1) { if(IsPlayerAlive(p)) { CityCount = PlayerCityCount(p); for(j = 0; j < CityCount; j = j + 1) { GetCityByIndex(p, j, tmpCity2); if(CityIsValid(tmpCity2)) { cityDist = distance(tmpLoc, tmpCity2.location); if(cityDist < minDist) { minDist = cityDist; ClosestCity = tmpCity; ClosestPlayer = p; } } } } } } i = i + 1; } if(sucess == 1 && minDist < 30) { message(ClosestPlayer, 'BarbUprisingNearYou'); } // } } } } } HandleEvent(MakePop) 'BarbCampsCantGrow' pre { int_t i; for(i = 0; i < BarbarianCamp.#; i = i + 1){ if(city[0] == BarbarianCamp[i]) { return STOP; } } } HandleEvent(KillPop) 'BarbCampsCantStarve' pre { int_t i; for(i = 0; i < BarbarianCamp.#; i = i + 1){ if(city[0] == BarbarianCamp[i]) { return STOP; } } } HandleEvent(CaptureCity) 'BarbCapturingCities' pre { int_t randNum; int_t randNum2; int_t InitialPW; int_t FinalPW; int_t p; int_t c; int_t i; int_t tmpDist; if(player[0] == 0) { player[1] = city[0].owner; randNum = Random(4); if(randNum == 0) { // Nothing } elseif(randNum == 1) { for (p = 0; p <= 32; p = p + 1 ){ if(!IsPlayerAlive(p)) { Event: GiveCity(city[0], p); for(c = 0; c < BarbarianCamp.#; c = c + 1) { if(CityIsValid(BarbarianCamp[c])) { tmpDist = distance(city[0].location, BarbarianCamp[c].location); if(tmpDist < 15) { Event: GiveCity(BarbarianCamp[c], p); } } } 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); } } AddGold(player[1], -(PlayerGold(player[1]))/(Player[1].cities/(1 + Random(4)))); InitialPW = player[1].publicworkslevel; FinalPW = InitialPW - ((InitialPW)/(Player[1].cities/(1 + Random(4)))); setPW(player[1], FinalPW); message(player[1], 'CityWasPlunderedByBarbs'); Event: KillPop(city[0]); return STOP; } } } HandleEvent(CaptureCity) 'BarbCityCaptured' post { int_t c; for(c = 0; c < BarbarianCamp.#; c = c + 1) { if(CityIsValid(BarbarianCamp[c]) && BarbarianCamp[c] == city[0]) { AddGold(player[0], (Random(30) + 50)); message(player[1], 'BarbCampWasCaptured'); } } } alertbox 'BarbUprisingNearYou' { Show(); Title(ID_BAD_NEWS); text(ID_BARB_UPRISING_NEAR_YOU); } alertbox 'BarbsBecameCivilization' { Show(); Title(ID_BAD_NEWS); text(ID_BARB_BECAME_CIV); } alertbox 'CityWasPlunderedByBarbs' { Show(); Title(ID_BAD_NEWS); text(ID_BARB_PLUNDERED_CITY); } alertbox 'BarbCampWasCaptured' { Show(); Title(ID_GOOD_NEWS); text(ID_BARB_CAMP_CAPTURED); }