Some finetuning to the combat changes (better weapon selection)

This commit is contained in:
Enno Rehling 2002-10-04 21:37:35 +00:00
parent 38e3799362
commit e9c40d9495
3 changed files with 30 additions and 30 deletions

View File

@ -630,30 +630,38 @@ riding(const troop t) {
} }
static weapon * static weapon *
select_weapon(const troop t, boolean attacking, boolean missile) preferred_weapon(const troop t, boolean attacking)
{
weapon * missile = t.fighter->person[t.index].missile;
weapon * melee = t.fighter->person[t.index].melee;
if (attacking) {
if (melee==NULL || (missile && missile->attackskill>melee->attackskill)) {
return missile;
}
} else {
if (melee==NULL || (missile && missile->defenseskill>melee->defenseskill)) {
return missile;
}
}
return melee;
}
static weapon *
select_weapon(const troop t, boolean attacking, boolean ismissile)
/* select the primary weapon for this trooper */ /* select the primary weapon for this trooper */
{ {
weapon * weapon = NULL;
if (attacking) { if (attacking) {
if (!missile) { if (ismissile) {
/* try your best weapon if it's melee */ /* from the back rows, have to use your missile weapon */
weapon = t.fighter->person[t.index].preferred; return t.fighter->person[t.index].missile;
} else {
/* from the back rows, use your missile weapon */
weapon = t.fighter->person[t.index].missile;
} }
} else { } else {
if (!missile) { if (!ismissile) {
/* have to use your melee weapon if it's melee */ /* have to use your melee weapon if it's melee */
weapon = t.fighter->person[t.index].melee; return t.fighter->person[t.index].melee;
} else {
/* from the back rows, use your best skill */
weapon = t.fighter->person[t.index].preferred;
} }
} }
return weapon; return preferred_weapon(t, attacking);
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -1923,8 +1931,8 @@ attack(battle *b, troop ta, const att *a)
* konventionell weiter */ * konventionell weiter */
do_combatspell(ta, row); do_combatspell(ta, row);
} else { } else {
weapon * wp = ta.fighter->person[ta.index].preferred; weapon * wp = ta.fighter->person[ta.index].missile;
if (row!=FIGHT_ROW) wp = ta.fighter->person[ta.index].missile; if (row==FIGHT_ROW) wp = preferred_weapon(ta, true);
/* Sonderbehandlungen */ /* Sonderbehandlungen */
if (getreload(ta)) { if (getreload(ta)) {
@ -2877,7 +2885,6 @@ make_fighter(battle * b, unit * u, boolean attack)
if (weapon_weight(fig->weapons+owp[oi], false)<=wpless) { if (weapon_weight(fig->weapons+owp[oi], false)<=wpless) {
continue; /* we fight better with bare hands */ continue; /* we fight better with bare hands */
} }
fig->person[i].preferred = fig->person[i].melee = &fig->weapons[owp[oi]];
++fig->weapons[owp[oi]].used; ++fig->weapons[owp[oi]].used;
} }
/* hand out missile weapons (from back to front, in case of mixed troops). */ /* hand out missile weapons (from back to front, in case of mixed troops). */
@ -2890,11 +2897,6 @@ make_fighter(battle * b, unit * u, boolean attack)
fig->person[i].missile = &fig->weapons[dwp[di]]; fig->person[i].missile = &fig->weapons[dwp[di]];
++fig->weapons[dwp[di]].used; ++fig->weapons[dwp[di]].used;
} }
if (fig->person[i].missile && (fig->person[i].melee==NULL ||
weapon_weight(fig->person[i].missile, true) >
weapon_weight(fig->person[i].melee, false))) {
fig->person[i].preferred = fig->person[i].missile;
}
} }
} }

View File

@ -157,7 +157,6 @@ typedef struct fighter {
int reload : 4; /* Anzahl Runden, die die Waffe x noch laden muss. int reload : 4; /* Anzahl Runden, die die Waffe x noch laden muss.
* dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */ * dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */
int last_action : 8; /* In welcher Runde haben wir zuletzt etwas getan */ int last_action : 8; /* In welcher Runde haben wir zuletzt etwas getan */
struct weapon * preferred; /* weapon with best skill */
struct weapon * missile; /* missile weapon */ struct weapon * missile; /* missile weapon */
struct weapon * melee; /* melee weapon */ struct weapon * melee; /* melee weapon */
} * person; } * person;

View File

@ -335,14 +335,12 @@ sp_combatrosthauch(fighter * fi, int level, int power, spell * sp)
i_change(&df->unit->items, wp->type->itype, -n); i_change(&df->unit->items, wp->type->itype, -n);
for (p=0;n && p!=df->unit->number;++p) { for (p=0;n && p!=df->unit->number;++p) {
if (df->person[p].missile==wp) { if (df->person[p].missile==wp) {
df->person[p].preferred = df->person[p].melee;
df->person[p].missile = NULL; df->person[p].missile = NULL;
--n; --n;
} }
} }
for (p=0;n && p!=df->unit->number;++p) { for (p=0;n && p!=df->unit->number;++p) {
if (df->person[p].melee==wp) { if (df->person[p].melee==wp) {
df->person[p].preferred = df->person[p].missile;
df->person[p].melee = NULL; df->person[p].melee = NULL;
--n; --n;
} }
@ -1286,7 +1284,8 @@ sp_windshield(fighter * fi, int level, int power, spell * sp)
break; break;
assert(!helping(fi->side, df->side)); assert(!helping(fi->side, df->side));
if (df->person[dt.index].preferred && df->person[dt.index].preferred==df->person[dt.index].missile) { if (df->person[dt.index].missile) {
/* this suxx... affects your melee weapon as well. */
df->person[dt.index].attack -= at_malus; df->person[dt.index].attack -= at_malus;
--force; --force;
} }