//////////////////////////////////////////////////////////////////////////// // Religion Code by Pedrunn and Mapfi //////////////////////////////////////////////////////////////////////////// city_t allCities[]; //array of all cities int_t CityReligion[]; //corresponding array with the religion of those cities, 0=atheist int_t PlayerReligion[]; //array of the players chosen 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 //this handler just for testing, setting the religion will be done by the player (or randomly if ai) as explained before HandleEvent(BeginTurn) 'settingreligion' pre { int_t i; for (i = 0; i <= 33; i = i + 1) { PlayerReligion[i] = i ; // setting the religion of all players to theirs as standard } DisableTrigger('settingreligion'); // just doing this the very first turn } int_f GetCityReligion(city_t tmpCity) { // if GetCityReligion = 0, means city is atheist or nature religion whatever you like int_t i; int_t tmpReligion; for (i = 0; i < allCities.#; i = i + 1) { if (tmpCity == allCities[i]) { tmpReligion = CityReligion[i]; } else{ tmpReligion = tmpCity.owner; } } 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; num = allCities.#; for (i = 0; i < allCities.#; i = i + 1) { if (thecity == allCities[i]) { num = i; } } return num; } void_f StoreCity(city_t tmpCity, int_t tmpreligion) { 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; } //ConvertCity(city_t, int_t, int_t) //ConvertCityOrder(army_t, location_t) //ConvertCityUnit(unit_t, city_t) int_t tmpPlayer1; int_t tmpPlayer2; HandleEvent(ConvertCityUnit) 'DoYouWantToConvert' pre { // also when a city is being converted int_t i; int_t CityCount; int_t TotalCityCount; int_t ConvertedCitiesChance; city_t tmpCity; int_t CityReligion; if (CityIsValid(city[0])) { // See who is converting tmpPlayer1 = unit[0].owner; tmpPlayer2 = city[0].owner; TotalCityCount = Cities(tmpPlayer2); CityCount = GetCitiesWithReligion(tmpPlayer2, PlayerReligion[tmpPlayer1]); if (IsHumanPlayer(city[0].owner)) { // If he is a human player if ((CityCount*10)/TotalCityCount >= 0) { // if 30% are already converted message(city[0].owner, 'DoYouWantToConvertCiv'); // let him choose if he wants to convert his empire } } else { // if he's not a human player ConvertedCitiesChance = 11 - (CityCount*10)/TotalCityCount; // Get how likely the civ accepts being conveted if (Random(ConvertedCitiesChance) <= 11 && ConvertedCitiesChance < 11) { // converting chance mathematically: 2/(int(ConvertedCitiesChance)+1) if I understand this right // and at least 30% converted PlayerReligion[tmpPlayer2] = PlayerReligion[tmpPlayer1]; for (i=0; i < allCities.#; i = i + 1) { // all of his cities get converted tmpCity = allCities[i]; if (CityIsValid(tmpCity)) { if (tmpCity.owner == tmpPlayer2) { CityReligion = GetCityReligion(tmpCity); if (CityReligion != PlayerReligion[tmpPlayer1]) { if (Random(9) >= 2) { ConvertNum = 1; // avoiding a second conversion in a loop CityRel = PlayerReligion[tmpPlayer1]; Event:ConvertCity(tmpCity, CityRel, 0); Event:AddHappyTimer(tmpCity, 1, -2, 14); } else { Event:AddHappyTimer(tmpCity, 1, -2, 14); } } else { Event:AddHappyTimer(tmpCity, 1, 2, 14); } } } } } } } } AlertBox 'DoYouWantToConvertCiv' { // If the converted player is human he gets this message int_t i; int_t CityReligion; 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(); for (i=0; i < allCities.#; i = i + 1) { // And all of his cities get converted tmpCity = allCities[i]; if (CityIsValid(tmpCity)) { if (tmpCity.owner == tmpPlayer2) { CityReligion = GetCityReligion(tmpCity); if (CityReligion != PlayerReligion[tmpPlayer1]) { if (Random(9) >= 2) { ConvertNum = 1; // avoiding a second conversion in a loop CityRel = PlayerReligion[tmpPlayer1]; Event:ConvertCity(tmpCity, CityRel, 0); Event:AddHappyTimer(tmpCity, 1, -2, 14); } else { Event:AddHappyTimer(tmpCity, 1, -2, 14); } } else { Event:AddHappyTimer(tmpCity, 1, 2, 14); } } } } } } // //HandleEvent(CreateCity) 'StoreCityReligionAccordingToTheCiv' post { //city_t tmpCity; // tmpCity = city[0]; // CityRel = PlayerReligion[player[0]]; // StoreCity(city[0], CityRel); // ConvertNum = 1; // avoid loop // Event:ConvertCity(tmpCity, CityRel, 0); //Donest Work for the human player //} // HandleEvent(ConvertCity) 'newConvertCity' post { int_t i; city_t tmpCity; ConvertNum = ConvertNum + 1; tmpCity = city[0]; if (ConvertNum == 1) { 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 } HandleEvent(UnconvertCity) 'newUncovertCity' post { //reformation by city owner city_t tmpCity; int_t i; tmpCity = city[0]; CityRel = PlayerReligion[tmpCity.owner]; ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(tmpCity, CityRel, 0); //actual conversion with the civ's state religion StoreCity(tmpCity, CityRel); } //when a city is captured the converted sign dissappears if //city's religion is the same as capturer's player number, so we need a new conversion event. //if the religions are not equal though, the conversion remains and in my opinion it shouldn't be changed //since the capturer can always reform the city HandleEvent(CaptureCity) 'reconversion' post { int_t captureReligion; city_t tmpCity; tmpCity = city[0]; CityRel = GetCityReligion(tmpCity); captureReligion = player[0]; if (CityRel == captureReligion) { ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(tmpCity, CityRel, 0); } } 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 (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); } } // LogRegardEvent(int_t, int_t, int_t, int_t, ID string, int_t); HandleEvent(BeginTurn) 'ConvertorTakesTheMoneyPerTurn' post { // Every Turn int_t tmpPlayer; int_t Religion; int_t CityRel; int_t theTenth; int_t PopNum; int_t PlayerNum; int_t j; int_t k; int_t i; int_t CityCount; int_t CityCount2; city_t tmpCity; city_t tmpCity2; // Religious info msg player[0] = g.player; value[0] = GetCurrentYear(); player[1] = PlayerReligion[player[0]]; message(player[0], 'ReligionInfo'); // Reconvert all cities tmpPlayer = player[0]; Religion = player[1]; CityCount = PlayerCityCount(tmpPlayer); for(i=0; i <= CityCount; i = i + 1) { GetCityByIndex(tmpPlayer, i, tmpCity); CityRel = GetCityReligion(tmpCity); ConvertNum = 1; // avoiding a second conversion in a loop Event:ConvertCity(tmpCity, CityRel, 0); } // The Tenth and diplomacy for(k = 0; k <= 33; k = k + 1) { if(IsPlayerAlive(k) && Religion != PlayerReligion[k]) { LogRegardEvent(tmpPlayer, k, -5, 4, ID_NONE, 0); CityCount2 = PlayerCityCount(k); for(j=0; j <= CityCount2; j = j + 1) { GetCityByIndex(k, i, tmpCity2); CityRel = GetCityReligion(tmpCity2); if(CityRel == Religion) { PopNum = PopNum + tmpCity.Population; AddGold(k, - tmpCity.Population); } } } else { PlayerNum = PlayerNum + 1; LogRegardEvent(tmpPlayer, k, 5, 4, ID_NONE, 0); } } theTenth = PopNum/PlayerNum; AddGold(tmpPlayer, theTenth); } messagebox 'ReligionInfo' { text(ID_RELIGIOUS_INFO); // "{value[0]} - Current Religion: {player[1].civ_name_singular}" }