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