I'm sick of having to laboriously replace all my obsolete units with new ones so I'm writing a mod that automatically updates any units fortified inside my cities to the latest technology. My first effort worked nicely only I used KillUnit to remove the old units which generated several minutes of unwanted sound effects of the units dying. I thought I'd try grouping the obsolete units into armies & then disbanding them but I just can't get them to disband. Here's part of the code I'm using (please don't laugh - I'm new to all this!). Can anyone tell me where I'm going wrong?
int_t p_counter;
int_t k_counter;
int_t counter;
army_t UAR_disarmy;
army_t UAR_tmparmy;
unit_t UAR_tmpunit;
city_t UAR_tmpcity;
int_t UAR_citycount;
int_t UAR_whilecount;
int_t UAR_forcount;
int_t UAR_tmploc;
int_t UAR_inf_type;
void_f UAR_ME_Routine() {
UAR_citycount = player[0].cities+1;
for (UAR_whilecount = 0; UAR_whilecount < UAR_citycount; UAR_whilecount = UAR_whilecount +1) {
GetCityByIndex(player[0], UAR_whilecount, UAR_tmpcity);
UAR_tmploc = UAR_tmpcity.location;
if(CityIsValid(UAR_tmpcity)) {
UAR_unitcount = GetUnitsAtLocation(UAR_tmploc);
Event:CreatedArmy(UAR_disarmy);
for (UAR_forcount = 0; UAR_forcount < UAR_unitcount; UAR_forcount = UAR_forcount + 1) {
GetUnitFromCell(UAR_tmploc, UAR_forcount, UAR_tmpunit);
if (UAR_tmpunit.valid) {
UAR_inf_type = UAR_tmpunit.type;
if (UAR_inf_type == UnitDB(UNIT_HOPLITE)
| | UAR_inf_type == UnitDB(UNIT_WARRIOR)) {
p_counter = p_counter + 1;
GetArmyFromUnit(UAR_tmpunit, UAR_tmparmy);
Event:UngroupOrder(UAR_tmparmy);
Event:GroupUnitOrder(UAR_disarmy, UAR_tmpunit);
counter = counter + 1;
} elseif (UAR_inf_type == UnitDB(UNIT_SWORDSMAN)) {
k_counter = k_counter + 1;
GetArmyFromUnit(UAR_tmpunit, UAR_tmparmy);
Event:UngroupOrder(UAR_tmparmy);
Event:GroupUnitOrder(UAR_disarmy, UAR_tmpunit);
counter = counter + 1;
}
}
Event isbandArmyOrder(UAR_disarmy); //doesn't work
if (counter > 0) {
while (k_counter > 0) {
CreateUnit(player[0],UnitDB(UNIT_KNIGHT),UAR_tmploc,0,UAR_tmpunit);
Event:EntrenchUnit(UAR_tmpunit);
k_counter = k_counter - 1;
}
while (p_counter > 0) {
CreateUnit(player[0],UnitDB(UNIT_PIKEMEN),UAR_tmploc,0,UAR_tmpunit);
Event:EntrenchUnit(UAR_tmpunit);
p_counter = p_counter - 1;
}
}
}
}
}
}
int_t p_counter;
int_t k_counter;
int_t counter;
army_t UAR_disarmy;
army_t UAR_tmparmy;
unit_t UAR_tmpunit;
city_t UAR_tmpcity;
int_t UAR_citycount;
int_t UAR_whilecount;
int_t UAR_forcount;
int_t UAR_tmploc;
int_t UAR_inf_type;
void_f UAR_ME_Routine() {
UAR_citycount = player[0].cities+1;
for (UAR_whilecount = 0; UAR_whilecount < UAR_citycount; UAR_whilecount = UAR_whilecount +1) {
GetCityByIndex(player[0], UAR_whilecount, UAR_tmpcity);
UAR_tmploc = UAR_tmpcity.location;
if(CityIsValid(UAR_tmpcity)) {
UAR_unitcount = GetUnitsAtLocation(UAR_tmploc);
Event:CreatedArmy(UAR_disarmy);
for (UAR_forcount = 0; UAR_forcount < UAR_unitcount; UAR_forcount = UAR_forcount + 1) {
GetUnitFromCell(UAR_tmploc, UAR_forcount, UAR_tmpunit);
if (UAR_tmpunit.valid) {
UAR_inf_type = UAR_tmpunit.type;
if (UAR_inf_type == UnitDB(UNIT_HOPLITE)
| | UAR_inf_type == UnitDB(UNIT_WARRIOR)) {
p_counter = p_counter + 1;
GetArmyFromUnit(UAR_tmpunit, UAR_tmparmy);
Event:UngroupOrder(UAR_tmparmy);
Event:GroupUnitOrder(UAR_disarmy, UAR_tmpunit);
counter = counter + 1;
} elseif (UAR_inf_type == UnitDB(UNIT_SWORDSMAN)) {
k_counter = k_counter + 1;
GetArmyFromUnit(UAR_tmpunit, UAR_tmparmy);
Event:UngroupOrder(UAR_tmparmy);
Event:GroupUnitOrder(UAR_disarmy, UAR_tmpunit);
counter = counter + 1;
}
}
Event isbandArmyOrder(UAR_disarmy); //doesn't work
if (counter > 0) {
while (k_counter > 0) {
CreateUnit(player[0],UnitDB(UNIT_KNIGHT),UAR_tmploc,0,UAR_tmpunit);
Event:EntrenchUnit(UAR_tmpunit);
k_counter = k_counter - 1;
}
while (p_counter > 0) {
CreateUnit(player[0],UnitDB(UNIT_PIKEMEN),UAR_tmploc,0,UAR_tmpunit);
Event:EntrenchUnit(UAR_tmpunit);
p_counter = p_counter - 1;
}
}
}
}
}
}
Comment