count_enemies ist verflucht lahm. Ich werde mal sehen, ob ich das shcneller machen kann.

This commit is contained in:
Enno Rehling 2004-04-18 21:44:24 +00:00
parent 619a2ff69c
commit 1e9538b8d8
4 changed files with 316 additions and 321 deletions

View File

@ -175,8 +175,7 @@ attack_firesword(const troop * at, int *casualties, int row)
int force = 1+rand()%10;
if (row==FIGHT_ROW) {
enemies = count_enemies(fi->side->battle, fi->side, FS_ENEMY,
minrow, maxrow);
enemies = count_enemies(fi->side->battle, fi->side, minrow, maxrow);
}
if (!enemies) {
if (casualties) *casualties = 0;
@ -243,7 +242,7 @@ attack_catapult(const troop * at, int * casualties, int row)
minrow = FIGHT_ROW;
maxrow = FIGHT_ROW;
n = min(CATAPULT_ATTACKS, count_enemies(b, af->side, FS_ENEMY, minrow, maxrow));
n = min(CATAPULT_ATTACKS, count_enemies(b, af->side, minrow, maxrow));
#if CATAPULT_AMMUNITION
new_use_pooled(au, &rt_catapultammo, GET_SLACK|GET_RESERVE|GET_POOLED_SLACK, 1);

View File

@ -502,7 +502,7 @@ hpflee(int status)
}
int
get_unitrow(fighter * af)
get_unitrow(const fighter * af)
{
static boolean * counted = NULL;
static size_t csize = 0;
@ -1297,10 +1297,29 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
return true;
}
/* ------------------------------------------------------------- */
int
count_enemies(battle * b, side * as, int mask, int minrow, int maxrow)
static int
count_side(const side * s, int minrow, int maxrow)
{
void **fi;
int people = 0;
for (fi = s->fighters.begin; fi != s->fighters.end; ++fi) {
const fighter *fig = *fi;
int row;
if (fig->alive - fig->removed <= 0) continue;
row = get_unitrow(fig);
if (row >= minrow && row <= maxrow) {
people += fig->alive - fig->removed;
}
}
return people;
}
/* new implementation of count_enemies ignores mask, since it was never used */
int
count_enemies(battle * b, side * as, int minrow, int maxrow)
{
int i = 0;
void **si;
@ -1309,28 +1328,13 @@ count_enemies(battle * b, side * as, int mask, int minrow, int maxrow)
for (si = b->sides.begin; si != b->sides.end; ++si) {
side *side = *si;
if (as==NULL || enemy(side, as))
{
void **fi;
for (fi = side->fighters.begin; fi != side->fighters.end; ++fi) {
fighter *fig = *fi;
int row;
if (fig->alive - fig->removed <= 0)
continue;
else
row = get_unitrow(fig);
if (row >= minrow && row <= maxrow)
i += fig->alive - fig->removed;
}
if (as==NULL || enemy(side, as)) {
i += count_side(side, minrow, maxrow);
}
}
return i;
}
/* ------------------------------------------------------------- */
troop
select_enemy(battle * b, fighter * af, int minrow, int maxrow)
{
@ -1347,7 +1351,7 @@ select_enemy(battle * b, fighter * af, int minrow, int maxrow)
}
minrow = max(minrow, FIGHT_ROW);
enemies = count_enemies(b, as, FS_ENEMY, minrow, maxrow);
enemies = count_enemies(b, as, minrow, maxrow);
if (!enemies)
return dt; /* Niemand ist in der angegebenen Entfernung */
@ -2115,7 +2119,7 @@ do_attack(fighter * af)
while (ta.index--) {
/* Wir suchen eine beliebige Feind-Einheit aus. An der können
* wir feststellen, ob noch jemand da ist. */
int enemies = count_enemies(b, af->side, FS_ENEMY, FIGHT_ROW, LAST_ROW);
int enemies = count_enemies(b, af->side, FIGHT_ROW, LAST_ROW);
if (!enemies) break;
for (apr=attacks_per_round(ta); apr > 0; apr--) {

View File

@ -214,7 +214,7 @@ extern void do_battle(void);
/* for combar spells and special attacks */
extern int damage_unit(struct unit *u, const char *dam, boolean armor, boolean magic);
extern troop select_enemy(struct battle * b, struct fighter * af, int minrow, int maxrow);
extern int count_enemies(struct battle * b, struct side * as, int mask, int minrow, int maxrow);
extern int count_enemies(struct battle * b, struct side * as, int minrow, int maxrow);
extern boolean terminate(troop dt, troop at, int type, const char *damage, boolean missile);
extern void battlemsg(battle * b, struct unit * u, const char * s);
extern void battlerecord(battle * b, const char *s);
@ -222,7 +222,7 @@ extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg, int damage_abs);
extern struct cvector * fighters(struct battle *b, struct fighter *af, int minrow, int maxrow, int mask);
extern int countallies(struct side * as);
extern int get_unitrow(struct fighter * af);
extern int get_unitrow(const struct fighter * af);
extern boolean helping(struct side * as, struct side * ds);
extern void rmfighter(fighter *df, int i);
extern struct region * fleeregion(const struct unit * u);

View File

@ -139,8 +139,7 @@ sp_kampfzauber(fighter * fi, int level, double power, spell * sp)
force = lovar(get_force(power,10));
}
enemies = count_enemies(b, fi->side, FS_ENEMY,
minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
@ -181,8 +180,7 @@ sp_versteinern(fighter * fi, int level, double power, spell * sp)
force = lovar(get_force(power,0));
enemies = count_enemies(b, fi->side, FS_ENEMY,
minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
@ -241,7 +239,7 @@ sp_stun(fighter * fi, int level, double power, spell * sp)
assert(0);
}
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
@ -297,7 +295,7 @@ sp_combatrosthauch(fighter * fi, int level, double power, spell * sp)
force = lovar(power * 15);
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
battlemsg(b, fi->unit, msgt[0]);
return 0;
@ -383,7 +381,7 @@ sp_sleep(fighter * fi, int level, double power, spell * sp)
sprintf(buf, "%s zaubert %s", unitname(mage),
spell_name(sp, default_locale));
force = lovar(power * 25);
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
@ -530,7 +528,7 @@ sp_mindblast(fighter * fi, int level, double power, spell * sp)
spell_name(sp, default_locale));
force = lovar(power * 25);
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
@ -615,8 +613,7 @@ sp_dragonodem(fighter * fi, int level, double power, spell * sp)
/* Jungdrache 3->54, Drache 6->216, Wyrm 12->864 Treffer */
force = lovar(get_force(level,6));
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow,
maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
@ -665,8 +662,7 @@ sp_immolation(fighter * fi, int level, double power, spell * sp)
/* Betrifft alle Gegner */
force = 99999;
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow,
maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
@ -715,8 +711,7 @@ sp_drainodem(fighter * fi, int level, double power, spell * sp)
/* Jungdrache 3->54, Drache 6->216, Wyrm 12->864 Treffer */
force = lovar(get_force(level,6));
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow,
maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
@ -924,7 +919,7 @@ sp_chaosrow(fighter * fi, int level, double power, spell * sp)
break;
}
enemies = count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
@ -1021,7 +1016,7 @@ sp_flee(fighter * fi, int level, double power, spell * sp)
force = (int)get_force(power,10);
}
if (!count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow)) {
if (!count_enemies(b, fi->side, minrow, maxrow)) {
scat(", aber es gab niemanden mehr, der beeinflusst werden konnte.");
battlerecord(b, buf);
return 0;
@ -1200,8 +1195,7 @@ sp_frighten(fighter * fi, int level, double power, spell * sp)
sprintf(buf, "%s zaubert %s", unitname(mage),
spell_name(sp, default_locale));
enemies = count_enemies(b, fi->side, FS_ENEMY,
minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
@ -1250,8 +1244,7 @@ sp_tiredsoldiers(fighter * fi, int level, double power, spell * sp)
sprintf(buf, "%s zaubert %s", unitname(mage),
spell_name(sp, default_locale));
if (!count_enemies(b, fi->side, FS_ENEMY, FIGHT_ROW,
BEHIND_ROW)) {
if (!count_enemies(b, fi->side, FIGHT_ROW, BEHIND_ROW)) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
return 0;
@ -1311,8 +1304,7 @@ sp_windshield(fighter * fi, int level, double power, spell * sp)
force = (int)power;
at_malus = 2;
}
enemies = count_enemies(b, fi->side, FS_ENEMY,
minrow, maxrow);
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);