//////////////////////////////////////////////////////////////////////////// // 9) Religion Code by Pedrunn and Mapfi //////////////////////////////////////////////////////////////////////////// city_t allCities[]; //array of all cities int_t CityReligion[]; //corresponding array with the religion of those cities int_t PlayerReligion[]; //array of the players chosen state religion int_t ConvertNum; //counting the convertcity process, see below int_t CityRel; //for storing then intended religion of the city in the loop process int_t tmpPlayer1; int_t tmpPlayer2; int_t ReformerPlayer; //used for code in messages of ReformingCity int_t ReligionCodeConversion; // Prevent do you want to convert messages int_t NewReformCost; int_t ReligionLevel; unit_t ReligiousSettler[]; int_t SettlerReligion[]; location_t ReligiousLocation; int_t LocationReligion; //setting the religion as player number HandleEvent(BeginTurn) 'settingreligion' pre { int_t i; for (i = 0; i <= 33; i = i + 1) { if(IsPlayerAlive(i)) { PlayerReligion[i] = i ; // setting the religion of all players to theirs as standard } } DisableTrigger('settingreligion'); // just doing this the very first turn } // New Functions int_f GetCityReligion(city_t tmpCity) { int_t i; int_t tmpReligion; tmpReligion = tmpCity.owner; // default value for (i = 0; i < allCities.#; i = i + 1) { // then you test all the Cities if (CityIsValid(allCities[i])) { if (tmpCity == allCities[i]) { tmpReligion = CityReligion[i]; } } } return tmpReligion; } int_f CheckforCity(city_t tmpCity) { //returns place of city in array, or next free place int_t i; int_t num; city_t thecity; thecity = tmpCity; for (i = 0; i < allCities.#; i = i + 1) { if (CityIsValid(allCities[i])) { if (thecity == allCities[i]) { return i; } } else{ return i; } } return allCities.#; } void_f StoreCity(city_t tmpCity, int_t tmpreligion) { //stores city in allCities array int_t i; city_t thecity; int_t thereligion; thecity = tmpCity; thereligion = tmpreligion; i = CheckforCity(thecity); allCities[i] = thecity; CityReligion[i] = thereligion; } int_f GetCitiesWithReligion(int_t tmpPlayer, int_t tmpreligion) { int_t i; city_t tmpCity; int_t count; int_t religion; int_t theplayer; theplayer = tmpPlayer; religion = tmpreligion; for (i = 0; i < allCities.#; i = i + 1) { tmpCity = allCities[i]; if (CityIsValid(tmpCity)) { if (tmpCity.owner == theplayer) { if (CityReligion[i] == religion) { count = count + 1; } } } } return count; } int_f GetReligionLevel(int_t Religion) { int_t i; int_t ConvertedPop; city_t tmpCity; int_t WorldPop; int_t Level; WorldPop = 0; ConvertedPop = 0; for(i = 0; i < allCities.#; i = i + 1) { if(CityIsValid(allCities[i])) { tmpCity = allCities[i]; WorldPop = WorldPop + tmpCity.population; if(CityReligion[i] == Religion) { ConvertedPop = ConvertedPop + tmpCity.population; } } } Level = (ConvertedPop*100)/WorldPop; //percentage return Level; } //ConvertCity(city_t, int_t, int_t) //ConvertCityOrder(army_t, location_t) //ConvertCityUnit(unit_t, city_t) // Settler gets the City Religion in which he was created void_f StoreSettlerReligion(unit_t theUnit, int_t theReligion) { int_t i; int_t tmpReligion; int_t success; unit_t testUnit; unit_t tmpUnit; army_t tmpArmy; tmpUnit = theUnit; tmpReligion = theReligion; while(i < ReligiousSettler.# && success == 0) { if(ReligiousSettler[i].valid == 0) { ReligiousSettler[i] = tmpUnit; SettlerReligion[i] = tmpReligion; success = 1; } if(tmpUnit == ReligiousSettler[i]) { // prevents a settler from being assigned a new religion by just passing a turn in a city, the settler is already in the Religious settler array success = 1; } i = i + 1; } if(success == 0) { i = ReligiousSettler.#; ReligiousSettler[i] = tmpUnit; SettlerReligion[i] = tmpReligion; } } HandleEvent(CreateUnit) 'SetSettlersAtLoction' post { int_t unitNum; int_t i; unit_t tmpUnit; city_t tmpcity; location_t tmpLoc; if(CityIsValid(city[0])) { tmpcity = city[0]; tmpLoc = tmpcity.location; unitNum = GetUnitsAtLocation(tmpLoc); for(i = 0; i < unitNum; i = i + 1) { GetUnitFromCell(tmpLoc, i, tmpUnit); if(tmpUnit.type == UnitDB(UNIT_SETTLER) || tmpUnit.type == UnitDB(UNIT_URBAN_PLANNER) || tmpUnit.type == UnitDB(UNIT_SEA_ENGINEER)){ CityRel = GetCityReligion(tmpcity); StoreSettlerReligion(tmpUnit, CityRel); } } } } HandleEvent(Settle) 'ReligiousCityLocation' post { int_t i; int_t j; unit_t tmpUnit; army_t tmpArmy; for(i = 0; i < ReligiousSettler.#; i = i + 1) { if(ReligiousSettler[i].valid == 1) { // thanks Martin! tmpUnit = ReligiousSettler[i]; GetArmyFromUnit(tmpUnit, tmpArmy); if(tmpArmy == army[0]) { ReligiousLocation = army[0].location; LocationReligion = SettlerReligion[i]; } } } } HandleEvent(CreateCity) 'NewCreateCity' post { city_t tmpCity; int_t religion; int_t i; tmpCity = city[0]; religion = PlayerReligion[tmpCity.owner]; if (ReligiousLocation == tmpcity.location) { religion = LocationReligion; } StoreCity(tmpCity, religion); } HandleEvent(ConvertCityUnit) 'ControlConversion' pre { int_t Convertor; int_t Converted; Convertor = unit[0].owner; Converted = city[0].owner; if(!IsHumanPlayer(Convertor)) { if(PlayerReligion[Convertor] == PlayerReligion[Converted]) { Event: IndulgenceSaleMade(unit[0], city[0]); return STOP; } } else{ if(PlayerReligion[Convertor] == PlayerReligion[Converted]) { message(Convertor, 'NothingToReformHere'); return STOP; } } } HandleEvent(ConvertCity) 'DoYouWantToConvert' pre { // also when a city is being converted int_t c; int_t u; int_t CityCount; int_t CityRel; int_t unitNum; city_t tmpCity; city_t tmpCity2; unit_t tmpUnit; if(ReligionCodeConversion == 0) { tmpCity = city[0]; if (CityIsValid(tmpCity)) { // See who is converting tmpPlayer1 = player[0]; tmpPlayer2 = tmpCity.owner; if (IsHumanPlayer(tmpPlayer2) && PlayerReligion[tmpPlayer1] != PlayerReligion[tmpPlayer2]) { // If he is a human player and has another state religion message(tmpPlayer2, 'DoYouWantToConvertCiv'); // let him choose if he wants to try to convert his empire } else{ if(GetReligionLevel(PlayerReligion[tmpPlayer1]) > 2*GetReligionLevel(PlayerReligion[tmpPlayer2])) { PlayerReligion[tmpPlayer2] = PlayerReligion[tmpPlayer1]; } } } } else{ ReligionCodeConversion = 0; } } HandleEvent(ConvertCity) 'newConvertCity' post { int_t i; city_t tmpCity; ConvertNum = ConvertNum + 1; if (ConvertNum == 1) { tmpCity = city[0]; CityRel = PlayerReligion[player[0]]; Event:ConvertCity(tmpCity, CityRel, 0); //actual conversion with the civ's state religion StoreCity(tmpCity, CityRel); } else { ConvertNum = 0; //this ConvertNum stuff is needed to prevent an } //endless loop } // ReformCityUnit(unit_t, city_t) // ReformCityOrder(army_t) // UnconvertCity(city_t) HandleEvent(ReformCityUnit) 'NewUncovertCity' pre { //reformation by city owner, note: at the end of turn city will display no religion because of the action, new/old religion displayed at the beginning of the next turn int_t Religion; int_t CityReligion; int_t CityReligionLevel; int_t cityPop; if(CityIsValid(city[0])) { cityPop = city[0].population; ReformerPlayer = g.player; Religion = PlayerReligion[ReformerPlayer]; CityReligion = GetCityReligion(city[0]); // Check wich religion converted the player CityReligionLevel = GetReligionLevel(CityReligion); NewReformCost = CityReligionLevel*cityPop*10; if(PlayerGold(ReformerPlayer) > NewReformCost) { if(IsHumanPlayer(ReformerPlayer)){ if(CityReligion != Religion && ReformerPlayer != Religion) { message(ReformerPlayer, 'NewUncovertCityMessage1'); } elseif(CityReligion == Religion && ReformerPlayer != Religion) { message(ReformerPlayer, 'NewUncovertCityMessage2'); // Send this message } elseif(CityReligion != Religion && ReformerPlayer == Religion) { message(ReformerPlayer, 'NewUncovertCityMessage3'); // Send this message } else{ message(ReformerPlayer, 'NothingToReformHere'); } } else{ if(PlayerGold(ReformerPlayer) > 4*NewReformCost && CityReligion != Religion && GetReligionLevel(Religion) > CityReligionLevel/3) { StoreCity(city[0], Religion); AddGold(g.player, - NewReformCost); ReligionCodeConversion = 1; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(city[0], Religion, 0); AddEffect(city[0].location, "SPECEFFECT_REFORMCITY", "SOUND_ID_REFORM_CITY"); AddMovement(unit[0], -100); Event:AddHappyTimer(city[0], 1, -2, 14); } } } else{ if(IsHumanPlayer(ReformerPlayer)){ message(ReformerPlayer, 'DontHaveEnoughMoneyToReform'); } return STOP; } return STOP; } } //when a city is captured the converted sign dissappears if //city's religion is the same as capturer's player number, but that turns out ok at he beginning of the next turn HandleEvent(IndulgenceSaleMade) 'newSellIndulgences' post { int_t SinfulCiv; int_t SinfulReligion; int_t PriestCiv; int_t PriestReligion; int_t religion; int_t theTenth; PriestCiv = unit[0].owner; PriestReligion = PlayerReligion[PriestCiv]; religion = GetCityReligion(city[0]); SinfulCiv = city[0].owner; if(!IsHumanPlayer(PriestCiv)) { if(PriestReligion != religion) { Event: ConvertCityUnit(unit[0], city[0]); return STOP; } } if (PriestReligion == religion) { // If city has same religion as cleric owner theTenth = city[0].population*5; // How much gold does he get? 1 gold per pop times 5 AddGold(SinfulCiv, - theTenth); AddGold(PriestCiv, theTenth); } elseif (PriestReligion != religion) { // if city has other religion theTenth = city[0].population; // How much gold does he get? 1 gold per pop AddGold(SinfulCiv, - theTenth); // or shall we have a mob kill the blasphemic cleric???? AddGold(PriestCiv, theTenth); } } HandleEvent(BeginTurn) 'ConvertorTakesTheMoneyPerTurn' post { // Every Turn int_t tmpPlayer; int_t tmpReligion; int_t theTenth; int_t PopNum; int_t PlayerNum; int_t HappyBonus; int_t j; int_t i; int_t c; int_t p; int_t u; int_t t; int_t CurrentRound; int_t Level; int_t HappyMod; int_t CityCount; int_t CityCount2; int_t WorldPopCount; int_t CityReligionLevel; int_t unitNum; city_t tmpCity; city_t tmpCity2; city_t FirstCity; unit_t tmpUnit; CurrentRound = GetCurrentRound(); tmpPlayer = g.player; tmpReligion = PlayerReligion[tmpPlayer]; ReligionLevel = GetReligionLevel(tmpReligion); for(t = 1; t < 200; t = t + 1) { if(tmpPlayer == tmpReligion && CurrentRound == (5*t)){ message(tmpPlayer, 'ReligionInfo'); } } // Reconvert all cities, Happiness Modifier and AI reform its cities CityCount = PlayerCityCount(tmpPlayer); for (c = 0; c < CityCount; c = c + 1) { GetCityByIndex(tmpPlayer, c, tmpCity); if(CityIsValid(tmpCity)) { CityRel = GetCityReligion(tmpCity); ReligionCodeConversion = 1; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(tmpCity, CityRel, 0); CityReligionLevel = GetReligionLevel(CityRel); HappyMod = CityReligionLevel * PlayerReligion.#; if(HappyMod < 10) { HappyBonus = -4; } elseif(HappyMod >= 10 && CityReligionLevel < 25) { HappyBonus = -3; } elseif(HappyMod >= 25 && CityReligionLevel < 50) { HappyBonus = -2; } elseif(HappyMod >= 50 && CityReligionLevel < 100) { HappyBonus = -1; } elseif(HappyMod >= 100 && CityReligionLevel < 150) { HappyBonus = 0; } elseif(HappyMod >= 150 && CityReligionLevel < 200) { HappyBonus = 1; } elseif(HappyMod >= 200 && CityReligionLevel < 300) { HappyBonus = 2; } elseif(HappyMod >= 300 && CityReligionLevel < 400) { HappyBonus = 3; } elseif(HappyMod >= 500) { HappyBonus = 4; } Event:AddHappyTimer(tmpCity, 1, HappyBonus, 14); if(!IsHumanPlayer(tmpPlayer) && CityRel != tmpReligion){ unitNum = GetUnitsAtLocation(tmpCity.location); for(u = 0; u < unitNum; u = u + 1) { GetUnitFromCell(tmpCity.location, u, tmpUnit); if(!IsCivilian(tmpUnit)) { Event:ReformCityUnit(tmpUnit, tmpCity); } } } } } // The Tenth and diplomacy and search new players and Religious Info. for(p = 0; p <= 33; p = p + 1) { if (tmpPlayer != p && IsPlayerAlive(p) && p > 0) { if(PlayerReligion[p] == 0) { j = 0; CityCount2 = PlayerCityCount(p); while(j < CityCount2 && PlayerReligion[p] == 0) { GetCityByIndex(p, j, FirstCity); CityRel = GetCityReligion(FirstCity); if(CityRel > 0) { PlayerReligion[p] = CityRel; } j = j + 1; } } elseif(tmpReligion != PlayerReligion[p]) { LogRegardEvent(tmpPlayer, p, -2, 0, ID_NONE, 0); //wrong type of argument and computer freezes for (i = 0; i < allCities.#; i = i + 1) { if(CityIsValid(allCities[i])) { tmpCity = allCities[i]; if (tmpCity.owner == p) { if (CityReligion[i] == tmpReligion) { PopNum = PopNum + tmpCity.Population; AddGold(p, - tmpCity.Population); } } } } } elseif (IsPlayerAlive(p)) { PlayerNum = PlayerNum + 1; for(t = 1; t < 200; t = t + 1) { if(GetCurrentRound() == (5*t)){ message(p, 'ReligionInfo'); } } LogRegardEvent(tmpPlayer, p, 5, 0, ID_NONE, 0); //wrong type of argument and computer freezes } } } theTenth = PopNum/PlayerNum; AddGold(tmpPlayer, theTenth); } // // when a player dies his religion would dissappear, this code tries to merge the religion with that of the victorious player. HandleEvent(CaptureCity) 'PlayerDiedReligionIsAssimilated' pre { // Dead players int_t i; int_t KillerPlayer; int_t DeadPlayer; int_t CityReligion; int_t NewReligion; int_t DeadReligion; int_t religion; city_t tmpCity; KillerPlayer = g.player; DeadPlayer = city[0].owner; NewReligion = PlayerReligion[KillerPlayer]; DeadReligion = PlayerReligion[DeadPlayer]; PlayerReligion[DeadPlayer] = 0; if (NewReligion == DeadPlayer) { PlayerReligion[KillerPlayer] = KillerPlayer; NewReligion = KillerPlayer; } for (i=0; i < allCities.#; i = i + 1) { if(CityIsValid(allCities[i])) { tmpCity = allCities[i]; CityReligion = GetCityReligion(tmpCity); if (CityReligion == DeadPlayer) { religion = NewReligion; StoreCity(tmpCity, religion); } } } } ////////////////////////// // Messages // ////////////////////////// messagebox 'ReligionInfo' { text(ID_RELIGIOUS_INFO); // "Current Religion: Religion of Player {Global} Religion Level: {ReligionLevel}% (percent of world pop converted)" show(); } AlertBox 'DoYouWantToConvertCiv' { // If the converted player is human he gets this message int_t i; int_t CityReligion; int_t religion; city_t tmpCity; Title(ID_WILL_WE_CONVERT_TITLE); Text(ID_WILL_WE_CONVERT_TEXT); Show(); Button(ID_DONT_CONVERT) { // If the player doesn't accept Event:AddHappyTimer(city[0], 1, -2, 14); // The city wich has been recently converted gets -2 happiness for 1 turn Kill(); } Button(ID_CONVERT) { // if the player does accept PlayerReligion[tmpPlayer2] = PlayerReligion[tmpPlayer1]; // His religion changes Kill(); } } messagebox 'NothingToReformHere' { int_t j; text(ID_NOTHING_TO_REFORM_HERE); // "The city of {city[0].name} is already converted to our empire official religion." show(); Button(ID_OK) { Kill(); } } messagebox 'DontHaveEnoughMoneyToReform' { int_t j; text(ID_NOT_ENOUGH_MONEY_TO_REFORM); // "Sir, the reformation of this city will cost you {NewReformCost} gold. Unfortunetly our funds dont have enough money." show(); Button(ID_OK) { Kill(); } } messagebox 'NewUncovertCityMessage1' { int_t j; int_t Religion; text(ID_CONVERT_OR_NOT1); // "You sent our troops to unconvert this city. But you can either convert the city to our religion or rescue the old religion created by our people hundreds of years ago an be free of the {player[0].civ_name_singular} religious influence. But if we rescue the old religion we may lost strategic conditions and the people of {city[0].name} will became unhappy with the change. So What should we do?" show(); Button(ID_CANCEL_UNCONVERSION) { // "Cancel Order" Kill(); } Button(ID_CONVERT_TO_RELIGION) { // "Convert to our Religion" Religion = PlayerReligion[ReformerPlayer]; StoreCity(city[0], Religion); AddGold(g.player, - NewReformCost); ReligionCodeConversion = 1; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(city[0], Religion, 0); AddEffect(city[0].location, "SPECEFFECT_REFORMCITY", "SOUND_ID_REFORM_CITY"); AddMovement(unit[0], -100); Event:AddHappyTimer(city[0], 1, -2, 14); Kill(); } Button(ID_CREATE_RELIGION) { // "Rescue Old Religion" PlayerReligion[ReformerPlayer] = ReformerPlayer; StoreCity(city[0], ReformerPlayer); AddGold(g.player, - NewReformCost); ReligionCodeConversion = 1; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(city[0], ReformerPlayer, 0); AddEffect(city[0].location, "SPECEFFECT_REFORMCITY", "SOUND_ID_REFORM_CITY"); AddMovement(unit[0], -100); Event:AddHappyTimer(city[0], 1, -2, 14); Kill(); } } messagebox 'NewUncovertCityMessage2' { int_t j; text(ID_CONVERT_OR_NOT2); // "You sent our troops to unconvert this city wich has the same religion of our empire. So you can rescue the old religion created by our people hundreds of years ago an be free of the {player[0].civ_name_singular} religious influence. But if we rescue the old religion we may lost strategic conditions and the people of {city[0].name} will became unhappy with the change. So What should we do?" show(); Button(ID_CANCEL_UNCONVERSION) { // "Cancel Order" Kill(); } Button(ID_CREATE_RELIGION) { // "Rescue Old Religion" PlayerReligion[ReformerPlayer] = ReformerPlayer; StoreCity(city[0], ReformerPlayer); AddGold(g.player, - NewReformCost); ReligionCodeConversion = 1; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(city[0], ReformerPlayer, 0); AddEffect(city[0].location, "SPECEFFECT_REFORMCITY", "SOUND_ID_REFORM_CITY"); AddMovement(unit[0], -100); Event:AddHappyTimer(city[0], 1, -2, 14); Kill(); } } messagebox 'NewUncovertCityMessage3' { int_t j; int_t Religion; text(ID_CONVERT_OR_NOT3); // "You sent our troops to unconvert this city wich has the same religion of our empire. So shall we convert this city to our empire official religion even though the people of {city[0].name} will became unhappy with the change?" show(); Button(ID_CANCEL_UNCONVERSION) { // "Cancel Order" Kill(); } Button(ID_CONVERT_TO_RELIGION) { // "Convert to our Religion" Religion = PlayerReligion[ReformerPlayer]; StoreCity(city[0], Religion); AddGold(g.player, - NewReformCost); ReligionCodeConversion = 1; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(city[0], Religion, 0); AddEffect(city[0].location, "SPECEFFECT_REFORMCITY", "SOUND_ID_REFORM_CITY"); AddMovement(unit[0], -100); Event:AddHappyTimer(city[0], 1, -2, 14); Kill(); } }