////////////////////////////////////////////////////////////////////////////// /// 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 // 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 CSK2_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 CSK2_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 CSK2_SetUp() { // Unit Repair CSK2_UNIT_REPAIR_NUM = 4; // so fraction is 3/4 and cost of repair will be (3/4 * damage), where 'damage' is the amount of CSK2_UNIT_REPAIR_DENOM = 5; // production (i.e. pw) needed to repair the unit //// variables //// } //int_t CSK2_pwtax[32]; // //HandleEvent(BeginTurn) 'CSK2_Strat' post { // if (player[0].publicworkstax != CSK2_pwtax[player[0]]) { // CSK2_pwtax[player[0]] = player[0].publicworkstax; // Message(1, 'CSK2_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) 'CSK2_GameStart' pre { // 'pre' because it has to trigger before 'MM2_EveryTurn' and set things up for the rest of the code CSK2_SetUp(); DisableTrigger('CSK2_GameStart'); // execute this trigger only once int_t i; for (i = 0; i < 32; i = i + 1) { // CSK2_pwtax[i] = 0; } } ////////////////////////////// //// 3. Unit Repair Code //// //////////////////////////// // Description: // This code takes over the part of the ... // movement? timing? HandleEvent(BeginTurn) 'CSK2_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; //if(IsHumanPlayer(tmpPlayer)){ //ie human player only 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 * CSK2_UNIT_REPAIR_NUM) / CSK2_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 pw = pw - pwCost; SetPW(tmpPlayer, pw ); // 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 pw = pw - pwCost; SetPW(tmpPlayer, pw); // 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); }