Merge pull request #216 from badgerman/feature/issue-198

issue #198: gmtool makes invalid demand
This commit is contained in:
Enno Rehling 2015-06-01 23:39:41 +02:00
commit 70967fc041
4 changed files with 26 additions and 27 deletions

View File

@ -431,7 +431,7 @@ static int get_row(const side * s, int row, const side * vs)
return result; return result;
} }
int get_unitrow(const fighter * af, const side * vs) static int get_unitrow(const fighter * af, const side * vs)
{ {
int row = statusrow(af->status); int row = statusrow(af->status);
if (vs == NULL) { if (vs == NULL) {
@ -3661,6 +3661,24 @@ static void free_fighter(fighter * fig)
} }
static void battle_free(battle * b) {
side *s;
assert(b);
for (s = b->sides; s != b->sides + b->nsides; ++s) {
fighter *fnext = s->fighters;
while (fnext) {
fighter *fig = fnext;
fnext = fig->next;
free_fighter(fig);
free(fig);
}
free_side(s);
}
free(b);
}
void free_battle(battle * b) void free_battle(battle * b)
{ {
int max_fac_no = 0; int max_fac_no = 0;
@ -3740,7 +3758,7 @@ static int battle_report(battle * b)
char buffer[32]; char buffer[32];
if (komma) { if (komma) {
bytes = strlcpy(bufp, ", ", size); strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -4295,21 +4313,3 @@ void do_battle(region * r)
} }
} }
void battle_free(battle * b) {
side *s;
assert(b);
for (s = b->sides; s != b->sides + b->nsides; ++s) {
fighter *fnext = s->fighters;
while (fnext) {
fighter *fig = fnext;
fnext = fig->next;
free_fighter(fig);
free(fig);
}
free_side(s);
}
free(b);
}

View File

@ -225,8 +225,6 @@ extern "C" {
extern const troop no_troop; extern const troop no_troop;
/* BEGIN battle interface */ /* BEGIN battle interface */
void battle_init(battle * b);
void battle_free(battle * b);
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
side * get_side(battle * b, const struct unit * u); side * get_side(battle * b, const struct unit * u);
fighter * get_fighter(battle * b, const struct unit * u); fighter * get_fighter(battle * b, const struct unit * u);
@ -251,11 +249,10 @@ extern "C" {
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, extern void damage_building(struct battle *b, struct building *bldg,
int damage_abs); int damage_abs);
extern struct quicklist *fighters(struct battle *b, const struct side *vs, struct quicklist *fighters(struct battle *b, const struct side *vs,
int minrow, int maxrow, int mask); int minrow, int maxrow, int mask);
extern int count_allies(const struct side *as, int minrow, int maxrow, int count_allies(const struct side *as, int minrow, int maxrow,
int select, int allytype); int select, int allytype);
extern int get_unitrow(const struct fighter *af, const struct side *vs);
extern bool helping(const struct side *as, const struct side *ds); extern bool helping(const struct side *as, const struct side *ds);
extern void rmfighter(fighter * df, int i); extern void rmfighter(fighter * df, int i);
extern struct fighter *select_corpse(struct battle *b, struct fighter *af); extern struct fighter *select_corpse(struct battle *b, struct fighter *af);

View File

@ -956,8 +956,10 @@ void setluxuries(region * r, const luxury_type * sale)
assert(r->land); assert(r->land);
if (r->land->demands) if (r->land->demands) {
freelist(r->land->demands); freelist(r->land->demands);
r->land->demands = 0;
}
for (ltype = luxurytypes; ltype; ltype = ltype->next) { for (ltype = luxurytypes; ltype; ltype = ltype->next) {
struct demand *dmd = malloc(sizeof(struct demand)); struct demand *dmd = malloc(sizeof(struct demand));

View File

@ -20,7 +20,7 @@ int wrptr(char **ptr, size_t * size, size_t bytes)
*ptr += *size; *ptr += *size;
*size = 0; *size = 0;
return ENAMETOOLONG; return ERANGE;
} }
#ifndef HAVE_STRLCPY #ifndef HAVE_STRLCPY