//////////////////////////////////////////////////////////////////////////// // Religion Code by Pedrunn and Mapfi //////////////////////////////////////////////////////////////////////////// city_t ConvertedCity[]; int_t ConvertorCiv[]; int_t ReligiousCount; int_t PlayerReligion[]; // What is inside the brackets is the player who has been converted // and the value of the variable equal the player who converted int_t ConvertNum; // To Prevent Loop HandleEvent(BeginTurn) 'SaveReligionsArrays' post { // At the Begginning of the game int_t tmpPlayer; for(tmpPlayer = 0; tmpPlayer <= 32; tmpPlayer = tmpPlayer + 1) { // For all if(IsPlayerAlive(tmpPlayer)) { // alive player PlayerReligion[tmpPlayer] = tmpPlayer; // Given them a religion } } DisableTrigger('SaveReligionsArrays'); } HandleEvent(CreateCity) 'StoreCityReligionAccordingToTheCiv' post { if(CityIsValid(city[0])) { player[0] = city[0].owner; ConvertorCiv[ReligiousCount] = city[0]; // Store the converted city ConvertedCity[ReligiousCount] = player[0]; // and the player who converted ReligiousCount = ReligiousCount + 1; } } int_f GetCityConvertor(city_t tmpCity) { // Get wich player converted the city int_t tmpPlayer; int_t i; if(CityIsValid(tmpCity)) { for(i = 0; i <= ReligiousCount; i = i + 1) { if(tmpCity == ConvertedCity[i]) { tmpPlayer = ConvertorCiv[i]; } } } return tmpPlayer; // if GetCityConvertor = 0, means city is not converted } int_f GetCityReligion(city_t tmpCity) { // Get for what religion the city was converted int_t tmpPlayer; int_t i; int_t Religion; if(CityIsValid(tmpCity)) { for(i = 0; i <= ReligiousCount; i = i + 1) { if(tmpCity == ConvertedCity[i]) { tmpPlayer = ConvertorCiv[i]; Religion = PlayerReligion[tmpPlayer]; } } } return Religion; } void_f AddCityToReligionCount (city_t tmpCity, int_t tmpConvertor) { ConvertorCiv[ReligiousCount] = tmpCity; // Store the converted city ConvertedCity[ReligiousCount] = tmpConvertor; // and the player who converted ReligiousCount = ReligiousCount + 1; } HandleEvent(ConvertCity) 'ConvertCityAccordingToReligion' post { // When a city was converted int_t i; int_t tmpplayer; int_t religion; if(CityIsValid(city[0])) { // See who is converting ConvertNum = ConvertNum + 1; tmpplayer = player[0]; religion = PlayerReligion[tmpplayer]; AddCityToReligionCount(city[0], PlayerReligion[player[0]]); if (ConvertNum==1) { Event:ConvertCity(city[0], religion, 0); //actual conversion with the civ's state religion } else { ConvertNum = 0; //this ConvertNum stuff is needed to prevent an } //endless loop, anybody got a better idea? } } int_t PlayerConverting; //ConvertCity(city_t, int_t, int_t) //ConvertCityOrder(army_t, location_t) //ConvertCityUnit(unit_t, city_t) HandleEvent(ConvertCityUnit) 'DoYouWantToConvert' pre { // Also when a city is being converted int_t i; int_t CityCount; int_t TotalCityCount; int_t ConvertedCitiesChance; int_t theReligion; city_t tmpCity; int_t k; int_t j; int_t CityReligion; city_t tmpCity2; if(CityIsValid(city[0])) { // See who is converting player[0] = unit[0].owner; player[1] = city[0].owner; // the player who owns the city, if(IsHumanPlayer(player[1])) { // If he is a human player message(player[1], 'DoYouWantToConvertCiv'); // Send him a message MessageAllBut(player[1], 'PlayerHasConverted'); } else { // if the player who is converting isnt human TotalCityCount = PlayerCityCount(player[1]); // Get its total number of cities for(i=0; i <= player[1].cities; i = i + 1) { GetCityByIndex(player[1], i, tmpCity); // Check all of its cities theReligion = GetCityReligion(tmpCity); // their conversion religion (if is converted) if(theReligion == PlayerReligion[player[1]]) { CityCount = CityCount + 1; // and get how many cities the convertor civ has converted in this cities } } ConvertedCitiesChance = 12 - (CityCount*10)/TotalCityCount; // Get how likely the civ accepts being conveted if(Random(ConvertedCitiesChance) == 0 && player[1].cities > 5) { // if half of its cities has been converted by the convertor civ MessageAllBut(player[0], 'PlayerHasConverted'); PlayerReligion[player[1]] = PlayerReligion[player[0]]; for(k=0; k <= player[1].cities; k = k + 1) { // And all of his cities get convertedF GetCityByIndex(player[1], k, tmpCity); CityReligion = GetCityReligion(tmpCity); if(CityReligion != PlayerReligion[player[0]]) { ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(tmpCity, PlayerReligion[player[0]], 0); Event:AddHappyTimer(tmpCity, 1, -4, 14); AddCityToReligionCount(tmpCity, PlayerReligion[player[0]]); } else{ Event:AddHappyTimer(tmpCity, 1, 4, 14); } for(j = 0; j <= ReligiousCount; j = j + 1) { // Also the cities that he converted are converted by the convertor if(ConvertorCiv[j] == player[1]) { tmpCity2 = ConvertedCity[j]; ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(tmpCity2, PlayerReligion[player[0]], 0); ConvertedCity[j] = 0; ConvertorCiv[j] = 0; AddCityToReligionCount(tmpCity2, PlayerReligion[player[0]]); } } } } } } } // This has to be added in the info_str.txt // DONT_CONVERT "Dont Convert" // CONVERT "Convert" // WILL_WE_CONVERT_TITLE " Citizens of {city[0].name} claims civ conversion! // WILL_WE_CONVERT_TEXT "{player[0].leader_name}, the {player[0].civ_name_singular} religion is spresding in // our empire. The conversion of {city[0].name} has lead to protests to have all of our cities // to this religion, wich they claim to be the true faith. Shall we convert all of our cities? alertbox 'PlayerHasConverted' { Text(ID_PLAYER_HAS_CONVERTED); Show(); } AlertBox 'DoYouWantToConvertCiv' { // If the converted player is human he gets this message int_t k; int_t j; int_t CityReligion; city_t tmpCity; city_t tmpCity2; Title(ID_WILL_WE_CONVERT_TITLE); Text(ID_WILL_WE_CONVERT_TEXT); Show(); Button(ID_DONT_CONVERT) { // If the player doesnt accept Event:AddHappyTimer(city[0], 1, -1, 14); // The city wich has been recently converted gets -2 happiness for 1 turn Kill(); } Button(ID_CONVERT) { // if the player do accept PlayerReligion[player[1]] = PlayerReligion[player[0]]; // His religion changes Kill(); for(k=0; k <= player[1].cities; k = k + 1) { // And all of his cities get convertedF GetCityByIndex(player[1], k, tmpCity); CityReligion = GetCityReligion(tmpCity); if(CityReligion != PlayerReligion[player[0]]) { ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(tmpCity, PlayerReligion[player[0]], 0); Event:AddHappyTimer(tmpCity, 1, -2, 14); AddCityToReligionCount(tmpCity, PlayerReligion[player[0]]); } else{ Event:AddHappyTimer(tmpCity, 1, 2, 14); } for(j = 0; j <= ReligiousCount; j = j + 1) { // Also the cities that he converted are converted by the convertor if(ConvertorCiv[j] == player[1]) { tmpCity2 = ConvertedCity[j]; ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(tmpCity2, PlayerReligion[player[0]], 0); ConvertedCity[j] = 0; ConvertorCiv[j] = 0; AddCityToReligionCount(tmpCity2, PlayerReligion[player[0]]); } } } } } city_t UnconvertedCity; HandleEvent(UnconvertCity) 'NewUncovertCity' pre { //reformation by city owner int_t Religion; int_t CityReligion; city_t tmpCity; int_t CivReligion; UnconvertedCity = city[0]; player[1] = city[0].owner; Religion = PlayerReligion[player[1]]; player[0] = Religion; CityReligion = GetCityReligion(city[0]); // Check wich religion converted the player if(CityReligion == Religion // and If the religion is the same as yours && player[1] != Religion) { // And you are not the religion founder. message(player[1], 'NewUncovertCityMessage1'); // Send this message } elseif(CityReligion != Religion) { // if is another ones religion // Otherwise if it is another civ religion message(player[1], 'NewUncovertCityMessage2'); } } // This has to be added in the info_str.txt // //CONVERT_OR_NOT "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[1].civ_name_singular} religious influence. But if we rescue the old religion we may // lost strategic conditions, our civiliztion may have diplomatic problems with {player[1].civ_name_singular} and the people of {city[0].name} will became unhappy with the change. So What should we do?" //CREATE_RELIGION "Rescue Old Religion" //CANCEL_UNCONVERSION "Cancel Order" //CONVERT_TO_RELIGION "Convert to our Religion" // AlertBox 'NewUncovertCityMessage1' { int_t j; text(ID_CONVERT_OR_NOT); show(); Button(ID_CANCEL_UNCONVERSION) { ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(player[1], PlayerReligion[player[1]], 0); Kill(); } Button(ID_CREATE_RELIGION) { PlayerReligion[player[1]] = player[1]; ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(UnconvertedCity, player[1], 0); for(j = 0; j <= ReligiousCount; j = j + 1) { // Also the cities that he converted are converted by the convertor if(ConvertedCity[j] == UnconvertedCity) { ConvertedCity[j] = 0; ConvertorCiv[j] = 0; AddCityToReligionCount(UnconvertedCity, PlayerReligion[player[1]]); } } Kill(); } } AlertBox 'NewUncovertCityMessage2' { int_t j; text(ID_CONVERT_OR_NOT); show(); Button(ID_CONVERT_TO_RELIGION) { ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(UnconvertedCity, PlayerReligion[player[1]], 0); for(j = 0; j <= ReligiousCount; j = j + 1) { // Also the cities that he converted are converted by the convertor if(ConvertedCity[j] == UnconvertedCity) { ConvertedCity[j] = 0; ConvertorCiv[j] = 0; AddCityToReligionCount(UnconvertedCity, PlayerReligion[player[1]]); } } Kill(); } Button(ID_CREATE_RELIGION) { PlayerReligion[player[1]] = player[1]; ConvertNum = 1; // avoiding a second conversions in a loop Event: ConvertCity(UnconvertedCity, player[1], 0); for(j = 0; j <= ReligiousCount; j = j + 1) { // Also the cities that he converted are converted by the convertor if(ConvertedCity[j] == UnconvertedCity) { ConvertedCity[j] = 0; ConvertorCiv[j] = 0; AddCityToReligionCount(UnconvertedCity, PlayerReligion[player[1]]); } } Kill(); } } //int_t TheCivReligion; HandleEvent(BeginTurn) 'ConvertorTakesTheMoneyPerTurn' post { // Every Turn int_t SinfulCiv; int_t k; int_t theReligion; int_t theTenth; int_t i; int_t CityCount; // Religious info msg player[0] = g.player; player[1] = PlayerReligion[player[0]]; message(player[0], 'ReligionInfo'); value[0] = g.year_str; // The Tenth CityCount = PlayerCityCount(SinfulCiv); for(SinfulCiv = 1; SinfulCiv < 32; i = i + 1) { if(IsPlayerAlive(SinfulCiv)) { for(i=0; i <= CityCount; i = i + 1) { // If it is converted by GetCityByIndex(SinfulCiv, i, city[0]); theReligion = GetCityReligion(city[0]); // Check all the cities of player if(theReligion == PlayerReligion[SinfulCiv] // If it has the same religion of the player who converted && PlayerReligion[SinfulCiv] != SinfulCiv) { // and the city who converted isnt himself theTenth = 1 + city[0].population/2; // it only take 1 gold per pop population. yet he take at least one. AddGold(SinfulCiv, - theTenth); AddGold(theReligion, theTenth); } elseif(theReligion != PlayerReligion[SinfulCiv]){ // Else if it is another player religion who converte the civ theTenth = city[0].population*3; // 3 golds per pop is taken to the religion owner AddGold(SinfulCiv, - theTenth); AddGold(theReligion, theTenth); } } } } } messagebox 'ReligionInfo' { text(ID_RELIGIOUS_INFO); } HandleEvent(IndulgenceSaleMade) 'ConvertorTakesTheMoneyFromIndulgences' pre { // Sell indulgence order int_t SinfulCiv; int_t PriestCiv; int_t ConvertorCiv; int_t theTenth; unit_t GodsUnit; PriestCiv = GodsUnit.owner; // ConvertorCiv = GetCityReligion(city[0]); SinfulCiv = City[0].owner; if(PlayerReligion[SinfulCiv] == PlayerReligion[PriestCiv]) { // If city has been converted by a civ with his own religion theTenth = 1 + city[0].population/2; // He gets 1 gold per 2 city pop (yet it gets at least one) AddGold(SinfulCiv, - theTenth); AddGold(PriestCiv, theTenth); } else{ // if city has been coverted by a civ with another religion theTenth = city[0].population*3; // he take 3 gold per pop AddGold(SinfulCiv, - theTenth); AddGold(PriestCiv, theTenth); } }