diff server/unittools.c server/unittools.c --- server/unittools.c Sat Dec 30 16:18:06 2000 +++ server/unittools.c Sat Jan 6 18:01:55 2001 @@ -307,7 +307,32 @@ ct++; if (unit_can_defend_here(punit)) { unit_d = rate_unit_d(punit, aunit); - if (unit_d > bestvalue) { + + if (unit_d > bestvalue || (unit_d == bestvalue && + + /* If some special defense skill (F_PIKEMEN, F_AEGIS) has + no effect in this battle and there is equally good + defender without special skills, try to save unit + with special skills for future use. -- Caz */ + + ((unit_flag(bestdef->type, F_PIKEMEN) && + !unit_flag(punit->type, F_PIKEMEN) && + !unit_flag(aunit->type, F_HORSE)) || + (unit_flag(bestdef->type, F_AEGIS) && + !unit_flag(punit->type, F_AEGIS) && + !is_air_unit(aunit) && !is_heli_unit(aunit)) || + + /* If, thanks to special skills, usually weaker unit + is in this battle equally strong, try to save + usually stronger unit for future use. -- Caz */ + + (unit_flag(punit->type, F_PIKEMEN) && + !unit_flag(bestdef->type, F_PIKEMEN) && + unit_flag(aunit->type, F_HORSE)) || + (unit_flag(punit->type, F_AEGIS) && + !unit_flag(bestdef->type, F_AEGIS) && + (is_air_unit(aunit) || (is_heli_unit)))))) { + bestvalue = unit_d; bestdef = punit; }