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

View File

@ -502,7 +502,7 @@ hpflee(int status)
} }
int int
get_unitrow(fighter * af) get_unitrow(const fighter * af)
{ {
static boolean * counted = NULL; static boolean * counted = NULL;
static size_t csize = 0; static size_t csize = 0;
@ -1297,10 +1297,29 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
return true; return true;
} }
/* ------------------------------------------------------------- */ static int
int count_side(const side * s, int minrow, int maxrow)
count_enemies(battle * b, side * as, int mask, 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 */ /* 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; int i = 0;
void **si; 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) { for (si = b->sides.begin; si != b->sides.end; ++si) {
side *side = *si; side *side = *si;
if (as==NULL || enemy(side, as)) if (as==NULL || enemy(side, as)) {
{ i += count_side(side, minrow, maxrow);
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;
}
} }
} }
return i; return i;
} }
/* ------------------------------------------------------------- */
troop troop
select_enemy(battle * b, fighter * af, int minrow, int maxrow) 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); minrow = max(minrow, FIGHT_ROW);
enemies = count_enemies(b, as, FS_ENEMY, minrow, maxrow); enemies = count_enemies(b, as, minrow, maxrow);
if (!enemies) if (!enemies)
return dt; /* Niemand ist in der angegebenen Entfernung */ return dt; /* Niemand ist in der angegebenen Entfernung */
@ -2115,7 +2119,7 @@ do_attack(fighter * af)
while (ta.index--) { while (ta.index--) {
/* Wir suchen eine beliebige Feind-Einheit aus. An der können /* Wir suchen eine beliebige Feind-Einheit aus. An der können
* wir feststellen, ob noch jemand da ist. */ * 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; if (!enemies) break;
for (apr=attacks_per_round(ta); apr > 0; apr--) { for (apr=attacks_per_round(ta); apr > 0; apr--) {

View File

@ -1,15 +1,15 @@
/* vi: set ts=2: /* vi: set ts=2:
* *
* Eressea PB(E)M host Copyright (C) 1998-2003 * Eressea PB(E)M host Copyright (C) 1998-2003
* Christian Schlittchen (corwin@amber.kn-bremen.de) * Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de) * Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
* *
* This program may not be used, modified or distributed without * This program may not be used, modified or distributed without
* prior permission by the authors of Eressea. * prior permission by the authors of Eressea.
*/ */
#ifndef H_KRNL_BATTLE #ifndef H_KRNL_BATTLE
#define H_KRNL_BATTLE #define H_KRNL_BATTLE
@ -17,14 +17,14 @@
extern "C" { extern "C" {
#endif #endif
/** new code defines **/ /** new code defines **/
#undef FAST_GETUNITROW #undef FAST_GETUNITROW
/** more defines **/ /** more defines **/
#define FS_ENEMY 1 #define FS_ENEMY 1
#define FS_HELP 2 #define FS_HELP 2
/***** Verteidigungslinien. /***** Verteidigungslinien.
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen * Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen
*/ */
#define NUMROWS 5 #define NUMROWS 5
@ -36,15 +36,15 @@ extern "C" {
#define LAST_ROW (NUMROWS-1) #define LAST_ROW (NUMROWS-1)
#define FIRST_ROW FIGHT_ROW #define FIRST_ROW FIGHT_ROW
typedef struct bfaction { typedef struct bfaction {
struct bfaction * next; struct bfaction * next;
struct side * sides; struct side * sides;
struct faction *faction; struct faction *faction;
int lastturn; /* last time this struct faction was involved in combat */ int lastturn; /* last time this struct faction was involved in combat */
boolean attacker; boolean attacker;
} bfaction; } bfaction;
typedef struct battle { typedef struct battle {
cvector leaders; cvector leaders;
struct region *region; struct region *region;
struct plane *plane; struct plane *plane;
@ -64,14 +64,14 @@ typedef struct battle {
#ifdef FAST_GETUNITROW #ifdef FAST_GETUNITROW
boolean nonblockers; boolean nonblockers;
#endif #endif
} battle; } battle;
typedef struct tactics { typedef struct tactics {
cvector fighters; cvector fighters;
int value; int value;
} tactics; } tactics;
typedef struct side { typedef struct side {
struct tactics leader; /* der beste Taktiker des Heeres */ struct tactics leader; /* der beste Taktiker des Heeres */
struct side * nextF; /* nächstes Heer der gleichen Partei */ struct side * nextF; /* nächstes Heer der gleichen Partei */
struct battle * battle; struct battle * battle;
@ -93,16 +93,16 @@ typedef struct side {
boolean dh; boolean dh;
boolean stealth; /* Die Einheiten sind getarnt */ boolean stealth; /* Die Einheiten sind getarnt */
const struct faction *stealthfaction; const struct faction *stealthfaction;
} side; } side;
typedef struct weapon { typedef struct weapon {
int count, used; int count, used;
const struct weapon_type * type; const struct weapon_type * type;
int attackskill : 8; int attackskill : 8;
int defenseskill : 8; int defenseskill : 8;
} weapon; } weapon;
/*** fighter::person::flags ***/ /*** fighter::person::flags ***/
#define FL_TIRED 1 #define FL_TIRED 1
#define FL_DAZZLED 2 /* durch Untote oder Dämonen eingeschüchtert */ #define FL_DAZZLED 2 /* durch Untote oder Dämonen eingeschüchtert */
#define FL_PANICED 4 #define FL_PANICED 4
@ -110,12 +110,12 @@ typedef struct weapon {
#define FL_SLEEPING 16 #define FL_SLEEPING 16
#define FL_STUNNED 32 /* eine Runde keinen Angriff */ #define FL_STUNNED 32 /* eine Runde keinen Angriff */
/*** fighter::flags ***/ /*** fighter::flags ***/
#define FIG_ATTACKED 1 #define FIG_ATTACKED 1
#define FIG_NOLOOT 2 #define FIG_NOLOOT 2
typedef unsigned char armor_t; typedef unsigned char armor_t;
enum { enum {
#ifdef COMPATIBILITY #ifdef COMPATIBILITY
AR_MAGICAL, AR_MAGICAL,
#endif #endif
@ -128,9 +128,9 @@ enum {
AR_EOGCHAIN, AR_EOGCHAIN,
AR_MAX, AR_MAX,
AR_NONE AR_NONE
}; };
typedef struct fighter { typedef struct fighter {
struct side *side; struct side *side;
struct unit *unit; /* Die Einheit, die hier kämpft */ struct unit *unit; /* Die Einheit, die hier kämpft */
struct building *building; /* Gebäude, in dem die Einheit evtl. steht */ struct building *building; /* Gebäude, in dem die Einheit evtl. steht */
@ -182,55 +182,55 @@ typedef struct fighter {
int cached; int cached;
} row; } row;
#endif #endif
} fighter; } fighter;
typedef struct troop { typedef struct troop {
struct fighter *fighter; struct fighter *fighter;
int index; int index;
} troop; } troop;
/* schilde */ /* schilde */
enum { enum {
SHIELD_REDUCE, SHIELD_REDUCE,
SHIELD_ARMOR, SHIELD_ARMOR,
SHIELD_WIND, SHIELD_WIND,
SHIELD_BLOCK, SHIELD_BLOCK,
SHIELD_MAX SHIELD_MAX
}; };
typedef struct meffect { typedef struct meffect {
fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */ fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */
int typ; /* Wirkungsweise des Schilds */ int typ; /* Wirkungsweise des Schilds */
int effect; int effect;
int duration; int duration;
} meffect; } meffect;
extern const troop no_troop; extern const troop no_troop;
extern void do_battle(void); extern void do_battle(void);
/* for combar spells and special attacks */ /* for combar spells and special attacks */
extern int damage_unit(struct unit *u, const char *dam, boolean armor, boolean magic); 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 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 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 battlemsg(battle * b, struct unit * u, const char * s);
extern void battlerecord(battle * b, const char *s); extern void battlerecord(battle * b, const char *s);
extern int hits(troop at, troop dt, weapon * awp); extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg, int damage_abs); 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 struct cvector * fighters(struct battle *b, struct fighter *af, int minrow, int maxrow, int mask);
extern int countallies(struct side * as); 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 boolean helping(struct side * as, struct side * ds);
extern void rmfighter(fighter *df, int i); extern void rmfighter(fighter *df, int i);
extern struct region * fleeregion(const struct unit * u); extern struct region * fleeregion(const struct unit * u);
extern struct troop select_corpse(struct battle * b, struct fighter * af); extern struct troop select_corpse(struct battle * b, struct fighter * af);
extern fighter * make_fighter(struct battle * b, struct unit * u, side * s, boolean attack); extern fighter * make_fighter(struct battle * b, struct unit * u, side * s, boolean attack);
extern int statusrow(int status); extern int statusrow(int status);
extern void drain_exp(struct unit *u, int d); extern void drain_exp(struct unit *u, int d);
extern void rmtroop(troop dt); extern void rmtroop(troop dt);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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