// Unit Updater Globals int_t UPDATE_TYPES_ARRAY[]; // an array of types of obsolete units that we find int_t NUM_UPDATE_TYPES; // the number of types in UPDATE_TYPES_ARRAY[] int_t UPDATE_TYPES_INDEX;// an index for UPDATE_TYPES_ARRAY unit_t OBS_UNIT_ARRAY[];//an array of obsolete units that we find int_t NUM_OBS_UNITS;// the number of units in OBS_UNIT_ARRAY[] used in messages int_t OBS_UNIT_INDEX;// an index for OBS_UNIT_ARRAY int_t OLD_UNIT_TYPE[];// the UnitDB index of the unit that's become obsolete int_t NEW_UNIT_TYPE[];// the UnitDB index of the unit that's become available int_t PER_UNIT_UPDATE_COST[];// How much it costs to update a unit of type OLD_UNIT_TYPE // to a unit of NEW_UNIT_TYPE[] int_t TOTAL_COST;// Total Cost of updating a bunch of units of some given type //////// //CODE HandleEvent(GrantAdvance)'UnitUpdater' post { int_t theAdvance; int_t i; int_t j; int_t k; int_t enadv[]; // the AdvanceDB index of the enabling advance army_t tmpArmy; unit_t tmpUnit; city_t tmpCity; //DATA ARRAYS: here's where you fill in the above arrays enadv[0]=AdvanceDB(ADVANCE_FEUDALISM); OLD_UNIT_TYPE[0]=UnitDB(UNIT_HOPLITE); NEW_UNIT_TYPE[0]=UnitDB(UNIT_PIKEMEN); PER_UNIT_UPDATE_COST[0]=205; enadv[1]=AdvanceDB(ADVANCE_FEUDALISM); OLD_UNIT_TYPE[1]=UnitDB(UNIT_WARRIOR); NEW_UNIT_TYPE[1]=UnitDB(UNIT_PIKEMEN); PER_UNIT_UPDATE_COST[1]=230; enadv[2]=AdvanceDB(ADVANCE_GUNPOWDER); OLD_UNIT_TYPE[2]=UnitDB(UNIT_ARCHER); NEW_UNIT_TYPE[2]=UnitDB(UNIT_INFANTRYMAN); PER_UNIT_UPDATE_COST[2]=850; enadv[3]=AdvanceDB(ADVANCE_GUNPOWDER); OLD_UNIT_TYPE[3]=UnitDB(UNIT_PIKEMEN); NEW_UNIT_TYPE[3]=UnitDB(UNIT_INFANTRYMAN); PER_UNIT_UPDATE_COST[3]=620; enadv[4]=AdvanceDB(ADVANCE_GUNPOWDER); OLD_UNIT_TYPE[4]=UnitDB(UNIT_SWORDSMAN);//SAMURAI NEW_UNIT_TYPE[4]=UnitDB(UNIT_INFANTRYMAN); PER_UNIT_UPDATE_COST[4]=540; enadv[5]=AdvanceDB(ADVANCE_CANNON_MAKING); OLD_UNIT_TYPE[5]=UnitDB(UNIT_CATAPULT); NEW_UNIT_TYPE[5]=UnitDB(UNIT_CANNON); PER_UNIT_UPDATE_COST[5]=460; enadv[6]=AdvanceDB(ADVANCE_CAVALRY_TACTICS); OLD_UNIT_TYPE[6]=UnitDB(UNIT_MOUNTED_ARCHER); NEW_UNIT_TYPE[6]=UnitDB(UNIT_CAVALRY); PER_UNIT_UPDATE_COST[6]=860; enadv[7]=AdvanceDB(ADVANCE_HULL_MAKING); OLD_UNIT_TYPE[7]=UnitDB(UNIT_CATAMARAN);//CORACLE NEW_UNIT_TYPE[7]=UnitDB(UNIT_LONGSHIP); PER_UNIT_UPDATE_COST[7]=405; enadv[8]=AdvanceDB(ADVANCE_OCEAN_FARING); OLD_UNIT_TYPE[8]=UnitDB(UNIT_LONGSHIP); NEW_UNIT_TYPE[8]=UnitDB(UNIT_CARRACK); PER_UNIT_UPDATE_COST[8]=290; enadv[9]=AdvanceDB(ADVANCE_CAVALRY_TACTICS); OLD_UNIT_TYPE[9]=UnitDB(UNIT_KNIGHT); NEW_UNIT_TYPE[9]=UnitDB(UNIT_CAVALRY); PER_UNIT_UPDATE_COST[9]=460; enadv[10]=AdvanceDB(ADVANCE_OCEAN_FARING); OLD_UNIT_TYPE[10]=UnitDB(UNIT_FIRE_TRIREME); NEW_UNIT_TYPE[10]=UnitDB(UNIT_CARRACK); PER_UNIT_UPDATE_COST[10]=470; enadv[11]=AdvanceDB(ADVANCE_INDUSTRIAL_REVOLUTION); OLD_UNIT_TYPE[11]=UnitDB(UNIT_INFANTRYMAN); NEW_UNIT_TYPE[11]=UnitDB(UNIT_MACHINE_GUNNER); PER_UNIT_UPDATE_COST[11]=200; enadv[12]=AdvanceDB(ADVANCE_EXPLOSIVES); OLD_UNIT_TYPE[12]=UnitDB(UNIT_CANNON); NEW_UNIT_TYPE[12]=UnitDB(UNIT_ARTILLERY); PER_UNIT_UPDATE_COST[12]=300; enadv[13]=AdvanceDB(ADVANCE_MASS_PRODUCTION); OLD_UNIT_TYPE[13]=UnitDB(UNIT_IRONCLAD); NEW_UNIT_TYPE[13]=UnitDB(UNIT_FRIGATE);// PT BOAT PER_UNIT_UPDATE_COST[13]=500; enadv[14]=AdvanceDB(ADVANCE_MASS_PRODUCTION); OLD_UNIT_TYPE[14]=UnitDB(UNIT_SHIP_OF_THE_LINE); NEW_UNIT_TYPE[14]=UnitDB(UNIT_DESTROYER); PER_UNIT_UPDATE_COST[14]=1000; enadv[15]=AdvanceDB(ADVANCE_ADV_INFANTRY_TACTICS); OLD_UNIT_TYPE[15]=UnitDB(UNIT_MACHINE_GUNNER); NEW_UNIT_TYPE[15]=UnitDB(UNIT_MARINE); PER_UNIT_UPDATE_COST[15]=200; enadv[16]=AdvanceDB(ADVANCE_TANK_WARFARE); OLD_UNIT_TYPE[16]=UnitDB(UNIT_CAVALRY); NEW_UNIT_TYPE[16]=UnitDB(UNIT_TANK); PER_UNIT_UPDATE_COST[16]=800; enadv[17]=AdvanceDB(ADVANCE_NAVAL_TACTICS); OLD_UNIT_TYPE[17]=UnitDB(UNIT_CARRACK); NEW_UNIT_TYPE[17]=UnitDB(UNIT_SHIP_OF_THE_LINE); PER_UNIT_UPDATE_COST[17]=280; // Templates for adding more data: //enadv[]=AdvanceDB(ADVANCE_); //OLD_UNIT_TYPE[]=UnitDB(UNIT_); //NEW_UNIT_TYPE[]=UnitDB(UNIT_); //PER_UNIT_UPDATE_COST[]= ; //enadv[]=AdvanceDB(ADVANCE_); //OLD_UNIT_TYPE[]=UnitDB(UNIT_); //NEW_UNIT_TYPE[]=UnitDB(UNIT_); //PER_UNIT_UPDATE_COST[]=; // CODE theAdvance=value[0]; if(UPDATE_TYPES_ARRAY.#>0){ // re-initialize UPDATE_TYPES_ARRAY for (k=0; k 0) {// re-initialize OBS_UNIT_ARRAY for(k = 0; k < OBS_UNIT_ARRAY.#; k = k + 1) { OBS_UNIT_ARRAY[k] = 0; } } //find all of the player's (obsolete) units of type OLD_UNIT_TYPE[i] // and put them in an array NUM_OBS_UNITS=0; for(j = 0; j < player[0].armies; j = j + 1) { GetArmyByIndex(player[0], j, tmpArmy); for(k = 0; k < tmpArmy.size; k = k + 1) { if(GetUnitFromArmy(tmpArmy, k, tmpUnit)) { if(tmpUnit.type == OLD_UNIT_TYPE[i]) { OBS_UNIT_ARRAY[NUM_OBS_UNITS] = tmpUnit; NUM_OBS_UNITS = NUM_OBS_UNITS + 1; } } } } // now check and update all buildqueues for(k=0; k0) { message(player[0], 'FoundObsUnits'); } } messagebox 'FoundObsUnits' { int_t k; // now we've got to do it all over again, //this time giving the human player choices Show(); Text (ID_MObsUnitsFirst) ; // Great news, Sire! Our recent discovery will allow us to re-train and re-equip some of //our military units. We have already switched production to the new units but we have some // old units in use. Shall I proceed? Button(ID_NO){ Kill(); } Button(ID_YES){// base clause for obsolete unit TYPES Kill(); UPDATE_TYPES_INDEX=0; message(player[0], 'ObsUnitsTypesNext'); } } messagebox 'ObsUnitsTypesNext' { int_t k; int_t j; army_t tmpArmy; unit_t tmpUnit; Abort(); if(OBS_UNIT_ARRAY.# > 0) {// re-initialize OBS_UNIT_ARRAY for(k = 0; k < OBS_UNIT_ARRAY.#; k = k + 1) { OBS_UNIT_ARRAY[k] = 0; } } //find all of the player's obsolete units of type // OLD_UNIT_TYPE[UPDATE_TYPES_ARRAY[UPDATE_TYPES_INDEX]] and put them in an array NUM_OBS_UNITS=0; for(j = 0; j < player[0].armies; j = j + 1) { GetArmyByIndex(player[0], j, tmpArmy); for(k = 0; k < tmpArmy.size; k = k + 1) { if(GetUnitFromArmy(tmpArmy, k, tmpUnit)) { if(tmpUnit.type == OLD_UNIT_TYPE[UPDATE_TYPES_ARRAY[UPDATE_TYPES_INDEX]]) { OBS_UNIT_ARRAY[NUM_OBS_UNITS] = tmpUnit; NUM_OBS_UNITS = NUM_OBS_UNITS + 1; } } } } TOTAL_COST=((NUM_OBS_UNITS)*PER_UNIT_UPDATE_COST[UPDATE_TYPES_ARRAY[UPDATE_TYPES_INDEX]]); if (TOTAL_COST <= PlayerGold(player[0]) && (NUM_OBS_UNITS ==1) ){ //special case: slightly different message and text message(player[0], 'ObsUnitsCostOKand1unit'); } elseif (TOTAL_COST <= PlayerGold(player[0]) && (OBS_UNIT_ARRAY.# >1) ){ message(player[0], 'ObsUnitsCostOK'); } else { message(player[0], 'ObsUnitsCostNotEnoughGold'); } } messagebox 'ObsUnitsCostOKand1unit' { army_t tmpArmy; // if it's in an army, get it out first if (GetArmyFromUnit(OBS_UNIT_ARRAY[0],tmpArmy) ){ Event:UngroupOrder(tmpArmy); } SelectUnit(OBS_UNIT_ARRAY[0]); AddCenter(OBS_UNIT_ARRAY[0].location); Text (ID_MObsUnitsCostOKand1unit) ; // We have {NUM_OBS_UNITS} {OBS_UNIT_ARRAY[0].name} unit who is pleading for //more modern equipment. It will cost {TOTAL_COST} gold to provide them with it and we have enough gold in // the treasury. Shall we re-train and re-equip them? Button(ID_YES){ CreateUnit(player[0],NEW_UNIT_TYPE[UPDATE_TYPES_ARRAY[UPDATE_TYPES_INDEX]],OBS_UNIT_ARRAY[0].location,0); Event:DisbandUnit(OBS_UNIT_ARRAY[0]); AddGold(player[0], -TOTAL_COST); Kill(); UPDATE_TYPES_INDEX=UPDATE_TYPES_INDEX+1; if (UPDATE_TYPES_INDEX