////////////////////////////////////////////////////////////////////////////// /// SLIC code for Medieval Pack II by Wouter Snijders /// //////////////////////////////////////////////////////////////////////////// // Author: Wouter Snijders (aka Locutus) // E-mail: locutus-of-borg@hetnet.nl // Last update: 2001 may 29 by: Wouter Snijders // // For: Medieval Mod II (by Wes Whitaker et al) // // Legal stuff, technical problems, questions, etc: see MedMod readmes // // Current contents of this file: // 0) Miscellaneous code - Code to set up the constants and // other stuff that is needed in the // rest of the file // 3) Unit repair code - Makes unit repair in cities cost PW // and if insufficent PW is available // slows it down // 4) Clear orders code - Clears orders of all units of every // AI civ once every 3 turns, to get the // AI to rethink his actions more often // 7) Slavery code - Kills all units with slaving powers // once slave age is over // // Any changes modmakers would like to make (e.g. what militia units are // available, how much repair costs, etc) can be made in the function // MM2_SetUp(), currently starting at line 70. //////// Declarations //////// // contstants int_t MM2_UNIT_REPAIR_NUM; // store the numerator of the fraction in the unit repair trigger that determines the multiplier of the pw cost of unit repair int_t MM2_UNIT_REPAIR_DENOM; // store the denominator of the fraction in the unit repair trigger that determines the multiplier of the pw cost of unit repair ////////////////////////////////// //// 0. Miscellaneous Code //// //////////////////////////////// // set up all the contstants void_f MM2_SetUp() { // Unit Repair MM2_UNIT_REPAIR_NUM = 4; // so fraction is 3/4 and cost of repair will be (3/4 * damage), where 'damage' is the amount of MM2_UNIT_REPAIR_DENOM = 5; // production (i.e. pw) needed to repair the unit //// variables //// } //int_t MM2_pwtax[32]; // //HandleEvent(BeginTurn) 'MM2_Strat' post { // if (player[0].publicworkstax != MM2_pwtax[player[0]]) { // MM2_pwtax[player[0]] = player[0].publicworkstax; // Message(1, 'MM2_GotHere'); // send message if pw-tax changed // } //} Messagebox 'MM2_GotHere' { Text(ID_MM2_GOT_HERE); } // executes at the beginning of the game to set everything up (initialize constants & variables, set flags, etc) HandleEvent(BeginTurn) 'MM2_GameStart' pre { // 'pre' because it has to trigger before 'MM2_EveryTurn' and set things up for the rest of the code MM2_SetUp(); DisableTrigger('MM2_GameStart'); // execute this trigger only once int_t i; for (i = 0; i < 32; i = i + 1) { // MM2_pwtax[i] = 0; } } ////////////////////////////// //// 3. Unit Repair Code //// //////////////////////////// // Description: // This code takes over the part of the ... // movement? timing? HandleEvent(BeginTurn) 'MM2_UnitRepair' post { city_t tmpCity; unit_t tmpUnit; int_t i; int_t j; int_t pw; int_t hpOld; int_t hpDif; int_t hpAffordable; int_t pwCost; int_t pwPerHp; int_t notEnough; int_t tmpPlayer; tmpPlayer = player[0]; notEnough = 0; player[5] = tmpPlayer; for (i = 0; i < player[5].cities; i = i + 1) { // cycle through all cities GetCityByIndex(tmpPlayer, i, tmpCity); for (j = 0; j < GetUnitsAtLocation(tmpCity.location); j = j + 1) { // cycle through all units in this city GetUnitFromCell(tmpCity.location, j, tmpUnit); // in other words: cycle through all units that are in a city hpOld = tmpUnit.hp; // store hp of unit Heal(tmpUnit); // repair unit completely hpDif = tmpUnit.hp - hpOld; // determine difference in hp before and after repair if (hpDif != 0) { // if unit actually needed repair pwPerHp = UnitDB(tmpUnit.type).ShieldCost / UnitDB(tmpUnit.type).MaxHP; pwPerHp = (pwPerHp * MM2_UNIT_REPAIR_NUM) / MM2_UNIT_REPAIR_DENOM; // calculate how many pw is needed to repair 1 hp of unit pwCost = hpDif * pwPerHp; // calculate amount of pw needed to fully repair unit pw = player[5].publicworkslevel; // determine how much pw player has if (pwCost <= pw) { // if player has enough pw SetPW(tmpPlayer, (pw - pwCost)); // subtract amount of pw needed to fully repair unit } elseif (pw > 0) { // if player doesn't have enough pw but at least some notEnough = 1; hpAffordable = pw / pwPerHp; // only enough pw to restore this many hp pwCost = hpAffordable * pwPerHp; // calculate cost of this repair (rounding down guarantees correct numbers) DamageUnit(tmpUnit, (hpDif - hpAffordable)); // damage unit for the part of the repair the player can't afford SetPW(tmpPlayer, (pw - pwCost)); // subtract amount of pw needed to repair this unit with this amount } else { // if (pw == 0) { // if no PW at all notEnough = 1; DamageUnit(tmpUnit, hpDif); // no healing happens at all, reparation is undone } } } } if (IsHumanPlayer(tmpPlayer) && notEnough == 1) { // if not enough pw and player is human player[5] = tmpPlayer; Message(1, 'MM2_NotEnoughPW_M'); // give message that more pw is needed } } Messagebox 'MM2_NotEnoughPW_M' { Text(ID_MM2_NOT_ENOUGH_PW); } /////////////////////////////// //// 4. Clear Orders Code //// ///////////////////////////// // Description: // This clears the orders of all units of 1/3 of all players every turn. The // next turn another (different) 1/3 of all players get all their unit's orders // cleared. The next turn the a last 1/3 of players gets all their unit's // orders cleared. The following turn this process starts all over again. The // practical effect of this is that every player has all it's unit's orders // cleared once every three turns. This gives the AI more oppurtunities to // rethink it's orders and redeploy it's units if the situation has changed // since the orders were given in the first place. // Clear all orders of all units of thePlayer void_f MM2_ClearOrders(int_t thePlayer) { unit_t tmpUnit; int_t i; int_t tmpPlayer; tmpPlayer = thePlayer; player[3] = tmpPlayer; for (i = 0; i < player[3].units; i = i + 1) { GetUnitByIndex(tmpPlayer, i, tmpUnit); // cycle through all units of this player ClearOrders(tmpUnit); // clear order of unit } } // every turn, clear all orders of 1/3 of the AIs (one particular AI will have his orders cleared every third turn) // (this spreads any slowdown caused by this trigger to be spread over // all turns instead of being concentrated in 1/3 of the turns) HandleEvent(BeginTurn) 'MM2_SetupClearOrders' post { int_t tmpPlayer; tmpPlayer = player[0]; if (!IsHumanPlayer(tmpPlayer)) { // this only applies to AI players if (g.year/3 == (g.year + 2)/3) { // if the year is part of the first partition if (tmpPlayer/3 == (tmpPlayer + 2)/3) { // and if the player is part of first partition MM2_ClearOrders(tmpPlayer); // clear orders of all this player's units } } elseif (g.year/3 == (g.year + 1)/3) { // if the year is part of the second partition if (tmpPlayer/3 != (tmpPlayer + 2)/3 && tmpPlayer/3 == (tmpPlayer + 1)/3) { // and the player is as well MM2_ClearOrders(tmpPlayer); // clear orders of all this player's units } } else { // if the year is part of the third and final partition if (tmpPlayer/3 != (tmpPlayer + 2)/3 && tmpPlayer/3 != (tmpPlayer + 1)/3) { // and the player is as well MM2_ClearOrders(tmpPlayer); // clear orders of all this player's units } } } } /////////////////////////////// //// 7. Slavery Code //// ///////////////////////////// // Description: Kill all units with slaving capabilities when era of slaves is over HandleEvent(BeginTurn) 'MM2_EndOfSlavery' post { unit_t tmpUnit; int_t i; int_t j; if (g.year == 400) { // if year is 400 for (i = 0; i < 32; i = i + 1) { // cycle through civs player[0] = i; for (j = 0; j < player[0].units; j = j + 1) { // cycle though units GetUnitByIndex(i, j, tmpUnit); if ( tmpUnit.type == UnitDB(UNIT_PRAETORIANS) || tmpUnit.type == UnitDB(UNIT_SLAVEMASTER) || tmpUnit.type == UnitDB(UNIT_SLAVER) || tmpUnit.type == UnitDB(UNIT_HAMMURABI) || tmpUnit.type == UnitDB(UNIT_RAMSES) || tmpUnit.type == UnitDB(UNIT_NEBUCHADNEZZER) || tmpUnit.type == UnitDB(UNIT_ALEXANDER_THE_GREAT) || tmpUnit.type == UnitDB(UNIT_CAESAR) || tmpUnit.type == UnitDB(UNIT_MUHAMMAD) || tmpUnit.type == UnitDB(UNIT_CHARLEMANGE) || tmpUnit.type == UnitDB(UNIT_HERNAN_CORTES) ) { // if unit of any of the above types, KillUnit(tmpUnit); // kill it } } } } }