forked from github/server
- removing cruft
- fixing print_fighters() since list is not ordered by status anymore
This commit is contained in:
parent
573d283e92
commit
34fce9b8a7
|
@ -404,15 +404,14 @@ hpflee(int status)
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
int
|
||||
get_unitrow(const fighter * af)
|
||||
static int
|
||||
get_row(const side * s, int row)
|
||||
{
|
||||
boolean counted[MAXSIDES];
|
||||
int enemyfront = 0;
|
||||
int line, result;
|
||||
int retreat = 0;
|
||||
int size[NUMROWS];
|
||||
int row = statusrow(af->status);
|
||||
int front = 0;
|
||||
|
||||
memset(counted, 0, sizeof(counted));
|
||||
|
@ -420,17 +419,19 @@ get_unitrow(const fighter * af)
|
|||
for (line=FIRST_ROW;line!=NUMROWS;++line) {
|
||||
int si;
|
||||
/* how many enemies are there in the first row? */
|
||||
for (si=0;af->side->enemies[si];++si) {
|
||||
side *s = af->side->enemies[si];
|
||||
if (s->size[line]>0) {
|
||||
for (si=0;s->enemies[si];++si) {
|
||||
side *se = s->enemies[si];
|
||||
if (se->size[line]>0) {
|
||||
int ai;
|
||||
enemyfront += s->size[line]; /* - s->nonblockers[line] (nicht, weil angreifer) */
|
||||
for (ai=0;s->enemies[ai];++ai) {
|
||||
side * ally = s->enemies[ai];
|
||||
if (!counted[ally->index] && !enemy(ally, af->side)) {
|
||||
enemyfront += se->size[line]; /* - s->nonblockers[line] (nicht, weil angreifer) */
|
||||
for (ai=0;se->enemies[ai];++ai) {
|
||||
side * ally = se->enemies[ai];
|
||||
if (!counted[ally->index] && !enemy(ally, s)) {
|
||||
int i;
|
||||
counted[ally->index] = true;
|
||||
for (i=0;i!=NUMROWS;++i) size[i] += ally->size[i] - ally->nonblockers[i];
|
||||
for (i=0;i!=NUMROWS;++i) {
|
||||
size[i] += ally->size[i] - ally->nonblockers[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -453,17 +454,11 @@ get_unitrow(const fighter * af)
|
|||
return result;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int
|
||||
sort_fighterrow(fighter ** elem1, fighter ** elem2)
|
||||
int
|
||||
get_unitrow(const fighter * af)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
a = get_unitrow(*elem1);
|
||||
b = get_unitrow(*elem2);
|
||||
return (a < b) ? -1 : ((a == b) ? 0 : 1);
|
||||
return get_row(af->side, statusrow(af->status));
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
reportcasualties(battle * b, fighter * fig, int dead)
|
||||
|
@ -1320,7 +1315,7 @@ select_opponent(battle * b, troop at, int minrow, int maxrow)
|
|||
* cvector *fgs=fighters(b,af,FIGHT_ROW,BEHIND_ROW, FS_HELP|FS_ENEMY);
|
||||
* fighter *fig;
|
||||
*
|
||||
* Optional: Verwirbeln. Vorsicht: Aufwendig!
|
||||
* Optional: Verwirbeln. Vorsicht: Aufwändig!
|
||||
* v_scramble(fgs->begin, fgs->end);
|
||||
*
|
||||
* for (fig = fgs->begin; fig != fgs->end; ++fig) {
|
||||
|
@ -2654,23 +2649,25 @@ battle_punit(unit * u, battle * b)
|
|||
}
|
||||
|
||||
static void
|
||||
print_fighters(battle * b, fighter * fighters)
|
||||
print_fighters(battle * b, const side * s)
|
||||
{
|
||||
fighter *df;
|
||||
int lastrow = -1;
|
||||
int row;
|
||||
|
||||
for (df=fighters; df; df=df->next) {
|
||||
unit *du = df->unit;
|
||||
for (row=1;row!=NUMROWS;++row) {
|
||||
int unitrow = get_row(s, row);
|
||||
|
||||
int row = get_unitrow(df);
|
||||
for (df=s->fighters; df; df=df->next) {
|
||||
unit *du = df->unit;
|
||||
int thisrow = statusrow(df->unit->status);
|
||||
|
||||
if (row != lastrow) {
|
||||
message * m = msg_message("battle::row_header", "row", row);
|
||||
message_all(b, m);
|
||||
msg_release(m);
|
||||
lastrow = row;
|
||||
if (row == thisrow) {
|
||||
message * m = msg_message("battle::row_header", "row", unitrow);
|
||||
message_all(b, m);
|
||||
msg_release(m);
|
||||
}
|
||||
battle_punit(du, b);
|
||||
}
|
||||
battle_punit(du, b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2794,7 +2791,7 @@ print_stats(battle * b)
|
|||
}
|
||||
battledebug(buf);
|
||||
}
|
||||
print_fighters(b, s->fighters);
|
||||
print_fighters(b, s);
|
||||
}
|
||||
|
||||
battlerecord(b, " ");
|
||||
|
@ -3787,65 +3784,6 @@ battle_stats(FILE * F, battle * b)
|
|||
}
|
||||
}
|
||||
|
||||
/** randomly shuffle an array of fighters.
|
||||
* for correctness, see Donald E. Knuth, The Art of Computer Programming
|
||||
*/
|
||||
#if 0
|
||||
static void
|
||||
shuffle_fighters(fighter ** fighters, int n)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i!=n;++i) {
|
||||
int j = i + (rng_int() % (n-i));
|
||||
fighter * fig = fighters[i];
|
||||
fighters[i] = fighters[j];
|
||||
fighters[j] = fig;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sort_fighters(fighter ** fighters, int * rows, int N)
|
||||
{
|
||||
unsigned int n = N, i = n/2, parent, child;
|
||||
int tr;
|
||||
fighter * tf;
|
||||
|
||||
for (;;) {
|
||||
if (i > 0) {
|
||||
i--;
|
||||
tr = rows[i];
|
||||
tf = fighters[i];
|
||||
} else {
|
||||
n--;
|
||||
if (n == 0) return;
|
||||
tr = rows[n];
|
||||
tf = fighters[n];
|
||||
rows[n] = rows[0];
|
||||
fighters[n] = fighters[0];
|
||||
}
|
||||
|
||||
parent = i;
|
||||
child = i*2 + 1;
|
||||
|
||||
while (child < n) {
|
||||
if (child + 1 < n && rows[child + 1] > rows[child]) {
|
||||
child++;
|
||||
}
|
||||
if (rows[child] > tr) {
|
||||
rows[parent] = rows[child];
|
||||
fighters[parent] = fighters[child];
|
||||
parent = child;
|
||||
child = parent*2 + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
rows[parent] = tr;
|
||||
fighters[parent] = tf;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/** execute one round of attacks
|
||||
* fig->fighting is used to determine who attacks, not fig->alive, since
|
||||
* the latter may be influenced by attacks that already took place.
|
||||
|
@ -4033,35 +3971,6 @@ do_battle(void)
|
|||
/* PRECOMBATSPELLS */
|
||||
do_combatmagic(b, DO_PRECOMBATSPELL);
|
||||
|
||||
/* Nun erstellen wir eine Liste von allen Kämpfern, die wir
|
||||
* dann scramblen. Zuerst werden sie wild gemischt, und dann wird (stabil)
|
||||
* nach der Kampfreihe sortiert */
|
||||
|
||||
/* das ist wahrscheinlich alles nicht wichtig, sondern uralt */
|
||||
#if 0
|
||||
b->fighters = malloc(sizeof(fighter*)*b->nfighters);
|
||||
for (i=0, s=b->sides; s; s=s->next) {
|
||||
fighter * fig;
|
||||
for (fig=s->fighters; fig; fig=fig->next) {
|
||||
b->fighters[i++] = fig;
|
||||
}
|
||||
}
|
||||
assert(i<=b->nfighters);
|
||||
shuffle_fighters(b->fighters, b->nfighters);
|
||||
#endif
|
||||
/*
|
||||
rows = malloc(sizeof(int)*b->nfighters);
|
||||
for (i=0;i!=b->nfighters;++i) {
|
||||
rows[i] = get_unitrow(b->fighters[i]);
|
||||
}
|
||||
sort_fighters(b->fighters, rows, b->nfighters);
|
||||
free(rows);
|
||||
|
||||
for (s = b->sides; s; s = s->next) {
|
||||
v_sort(s->fighters.begin, s->fighters.end, (v_sort_fun) sort_fighterrow);
|
||||
}
|
||||
*/
|
||||
|
||||
print_stats(b); /* gibt die Kampfaufstellung aus */
|
||||
printf("%s (%d, %d) : ", rname(r, NULL), r->x, r->y);
|
||||
|
||||
|
|
|
@ -58,9 +58,6 @@ extern "C" {
|
|||
bfaction * factions;
|
||||
int nfactions;
|
||||
int nfighters;
|
||||
#if 0
|
||||
struct fighter ** fighters;
|
||||
#endif
|
||||
struct side * sides;
|
||||
int nsides;
|
||||
cvector meffects;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* 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)
|
||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||
* Henning Peters (faroul@beyond.kn-bremen.de)
|
||||
|
@ -31,124 +31,70 @@
|
|||
void
|
||||
cv_init(cvector * cv)
|
||||
{
|
||||
cv->begin = 0;
|
||||
cv->end = 0;
|
||||
cv->space = 0;
|
||||
cv->begin = 0;
|
||||
cv->end = 0;
|
||||
cv->space = 0;
|
||||
}
|
||||
|
||||
cvector *
|
||||
cv_kill(cvector * cv)
|
||||
{
|
||||
if (cv->begin) free(cv->begin);
|
||||
cv_init(cv);
|
||||
return cv;
|
||||
if (cv->begin) free(cv->begin);
|
||||
cv_init(cv);
|
||||
return cv;
|
||||
}
|
||||
|
||||
size_t
|
||||
cv_size(cvector * cv)
|
||||
{
|
||||
return cv->end - cv->begin;
|
||||
return cv->end - cv->begin;
|
||||
}
|
||||
|
||||
void
|
||||
cv_reserve(cvector * cv, size_t size)
|
||||
{
|
||||
size_t count = cv->end - cv->begin;
|
||||
cv->begin = realloc(cv->begin, size * sizeof(void *));
|
||||
size_t count = cv->end - cv->begin;
|
||||
cv->begin = realloc(cv->begin, size * sizeof(void *));
|
||||
|
||||
cv->space = size;
|
||||
cv->end = cv->begin + count;
|
||||
cv->space = size;
|
||||
cv->end = cv->begin + count;
|
||||
}
|
||||
|
||||
void
|
||||
cv_pushback(cvector * cv, void *u)
|
||||
{
|
||||
if (cv->space == cv_size(cv))
|
||||
cv_reserve(cv, cv->space ? cv->space * 2 : 2);
|
||||
*(cv->end++) = u;
|
||||
}
|
||||
|
||||
void
|
||||
v_sort(void **begin, void **end, int (__cdecl * compare) (const void *, const void *))
|
||||
{
|
||||
qsort(begin, end - begin, sizeof(void *), compare);
|
||||
}
|
||||
|
||||
void **
|
||||
v_find(void **begin, void **end, void *item)
|
||||
{
|
||||
void **it;
|
||||
|
||||
for (it = begin; it != end; ++it)
|
||||
if (*it == item)
|
||||
return it;
|
||||
return it;
|
||||
}
|
||||
|
||||
void **
|
||||
v_findx(void **begin, void **end, void *item, int (__cdecl * cmp) (void *, void *))
|
||||
{
|
||||
void **it;
|
||||
|
||||
for (it = begin; it != end; ++it)
|
||||
if (cmp(*it, item))
|
||||
return it;
|
||||
return it;
|
||||
if (cv->space == cv_size(cv))
|
||||
cv_reserve(cv, cv->space ? cv->space * 2 : 2);
|
||||
*(cv->end++) = u;
|
||||
}
|
||||
|
||||
int
|
||||
__cv_scramblecmp(const void *p1, const void *p2)
|
||||
{
|
||||
return *((long *) p1) - *((long *) p2);
|
||||
return *((long *) p1) - *((long *) p2);
|
||||
}
|
||||
|
||||
#define addptr(p,i) ((void *)(((char *)p) + i))
|
||||
|
||||
void
|
||||
/** randomly shuffle an array
|
||||
* for correctness, see Donald E. Knuth, The Art of Computer Programming
|
||||
*/
|
||||
static void
|
||||
__cv_scramble(void *v1, size_t n, size_t width)
|
||||
{
|
||||
size_t i;
|
||||
static size_t s = 0;
|
||||
static void *v = 0;
|
||||
|
||||
if (n * (width + 4) > s) {
|
||||
s = n * (width + 4);
|
||||
v = (void *) realloc(v, s);
|
||||
}
|
||||
for (i = 0; i != n; i++) {
|
||||
*(long *) addptr(v, i * (width + 4)) = rng_int();
|
||||
memcpy(addptr(v, i * (width + 4) + 4), addptr(v1, i * width), width);
|
||||
}
|
||||
|
||||
qsort(v, n, width + 4, __cv_scramblecmp);
|
||||
|
||||
for (i = 0; i != n; i++)
|
||||
memcpy(addptr(v1, i * width), addptr(v, i * (width + 4) + 4), width);
|
||||
|
||||
size_t i;
|
||||
void * temp = malloc(width);
|
||||
for (i=0;i!=n;++i) {
|
||||
size_t j = i + (rng_int() % (n-i));
|
||||
memcpy(temp, addptr(v1, i*width), width);
|
||||
memcpy(addptr(v1, i*width), addptr(v1, j*width), width);
|
||||
memcpy(addptr(v1, j*width), temp, width);
|
||||
}
|
||||
free(temp);
|
||||
}
|
||||
|
||||
void
|
||||
v_scramble(void **begin, void **end)
|
||||
{
|
||||
__cv_scramble(begin, end - begin, sizeof(void *));
|
||||
}
|
||||
|
||||
void
|
||||
cv_mergeunique(cvector * c, const cvector * a, const cvector * b, int (__cdecl * keyfun) (const void *))
|
||||
{
|
||||
void **ai, **bi;
|
||||
|
||||
assert(cv_size(c) == 0);
|
||||
|
||||
for (ai = a->begin, bi = b->begin; ai != a->end || bi != b->end;) {
|
||||
int ak = (ai == a->end) ? INT_MAX : keyfun(*ai);
|
||||
int bk = (bi == b->end) ? INT_MAX : keyfun(*bi);
|
||||
int nk = (ak < bk) ? ak : bk;
|
||||
|
||||
cv_pushback(c, (ak == nk) ? (*ai) : (*bi));
|
||||
while (ai != a->end && keyfun(*ai) == nk)
|
||||
++ai;
|
||||
while (bi != b->end && keyfun(*bi) == nk)
|
||||
++bi;
|
||||
}
|
||||
__cv_scramble(begin, end - begin, sizeof(void *));
|
||||
}
|
||||
|
|
|
@ -40,11 +40,7 @@ cvector *cv_kill(cvector * cv);
|
|||
size_t cv_size(cvector * cv);
|
||||
void cv_reserve(cvector * cv, size_t size);
|
||||
void cv_pushback(cvector * cv, void *u);
|
||||
void v_sort(void **begin, void **end, int (__cdecl * compare) (const void *, const void *));
|
||||
extern void **v_find(void **begin, void **end, void *);
|
||||
extern void **v_findx(void **begin, void **end, void *, int (__cdecl * cmp) (void *, void *));
|
||||
void v_scramble(void **begin, void **end);
|
||||
void cv_mergeunique(cvector * c, const cvector * a, const cvector * b, int (__cdecl * keyfun) (const void *));
|
||||
|
||||
#define cv_remove(c, i) { void** x = v_find((c)->begin, (c)->end, (i)); if (x) { *x = *(c)->end; (c)->end--; } }
|
||||
#define cv_foreach(item, vector) \
|
||||
|
|
Loading…
Reference in New Issue