fix compilation (what was I thinking?), remove uses of f.alive where they should not be needed.

This commit is contained in:
Enno Rehling 2016-01-11 11:54:45 +01:00
parent de512be1ba
commit b4389c91fe
7 changed files with 22 additions and 24 deletions

View file

@ -333,6 +333,7 @@ void destroyfaction(faction ** fp)
*fp = f->next; *fp = f->next;
fset(f, FFL_QUIT); fset(f, FFL_QUIT);
f->_alive = false;
if (f->spellbook) { if (f->spellbook) {
spellbook_clear(f->spellbook); spellbook_clear(f->spellbook);
@ -388,7 +389,6 @@ void destroyfaction(faction ** fp)
u = u->nextF; u = u->nextF;
} }
} }
f->alive = false;
/* no way! f->units = NULL; */ /* no way! f->units = NULL; */
handle_event(f->attribs, "destroy", f); handle_event(f->attribs, "destroy", f);
for (ff = factions; ff; ff = ff->next) { for (ff = factions; ff; ff = ff->next) {
@ -648,7 +648,7 @@ void remove_empty_factions(void)
for (fp = &factions; *fp;) { for (fp = &factions; *fp;) {
faction *f = *fp; faction *f = *fp;
if ((!f->alive || !f->units) && !fval(f, FFL_NOIDLEOUT)) { if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
log_debug("dead: %s", factionname(f)); log_debug("dead: %s", factionname(f));
destroyfaction(fp); destroyfaction(fp);
} }

View file

@ -76,7 +76,7 @@ static void test_remove_dead_factions(CuTest *tc) {
CuAssertPtrEquals(tc, f, findfaction(f->no)); CuAssertPtrEquals(tc, f, findfaction(f->no));
CuAssertPtrNotNull(tc, get_monsters()); CuAssertPtrNotNull(tc, get_monsters());
fm->units = 0; fm->units = 0;
f->alive = 0; f->_alive = false;
fno = f->no; fno = f->no;
remove_empty_factions(); remove_empty_factions();
CuAssertPtrEquals(tc, 0, findfaction(fno)); CuAssertPtrEquals(tc, 0, findfaction(fno));
@ -107,7 +107,7 @@ static void test_addfaction(CuTest *tc) {
CuAssertIntEquals(tc, 1234, f->subscription); CuAssertIntEquals(tc, 1234, f->subscription);
CuAssertIntEquals(tc, 0, f->flags); CuAssertIntEquals(tc, 0, f->flags);
CuAssertIntEquals(tc, 0, f->age); CuAssertIntEquals(tc, 0, f->age);
CuAssertIntEquals(tc, 1, f->alive); CuAssertIntEquals(tc, true, f->_alive);
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
CuAssertIntEquals(tc, turn, f->lastorders); CuAssertIntEquals(tc, turn, f->lastorders);
CuAssertPtrEquals(tc, f, findfaction(f->no)); CuAssertPtrEquals(tc, f, findfaction(f->no));

View file

@ -1668,7 +1668,7 @@ int readgame(const char *filename, bool backup)
log_debug("marking factions as alive.\n"); log_debug("marking factions as alive.\n");
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if (f->flags & FFL_NPC) { if (f->flags & FFL_NPC) {
f->alive = 1; f->_alive = true;
f->magiegebiet = M_GRAY; f->magiegebiet = M_GRAY;
if (f->no == 0) { if (f->no == 0) {
int no = 666; int no = 666;
@ -1698,7 +1698,7 @@ int readgame(const char *filename, bool backup)
} }
} }
if (u->number > 0) { if (u->number > 0) {
f->alive = true; f->_alive = true;
if (global.data_version >= SPELL_LEVEL_VERSION) { if (global.data_version >= SPELL_LEVEL_VERSION) {
break; break;
} }

View file

@ -1463,7 +1463,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
assert(urace); assert(urace);
if (f) { if (f) {
assert(f->alive); assert(f->_alive);
u_setfaction(u, f); u_setfaction(u, f);
if (f->locale) { if (f->locale) {
@ -1828,7 +1828,7 @@ void remove_empty_units_in_region(region * r)
if (u->number) { if (u->number) {
faction *f = u->faction; faction *f = u->faction;
if (f == NULL || !f->alive) { if (f == NULL || !f->_alive) {
set_number(u, 0); set_number(u, 0);
} }
} }

View file

@ -86,7 +86,7 @@ static void test_remove_units_with_dead_faction(CuTest *tc) {
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
uid = u->no; uid = u->no;
u->faction->alive = false; u->faction->_alive = false;
remove_empty_units_in_region(u->region); remove_empty_units_in_region(u->region);
CuAssertPtrEquals(tc, 0, findunit(uid)); CuAssertPtrEquals(tc, 0, findunit(uid));
CuAssertIntEquals(tc, 0, u->number); CuAssertIntEquals(tc, 0, u->number);

View file

@ -1244,7 +1244,7 @@ static void remove_idle_players(void)
age = calloc(_max(4, turn + 1), sizeof(int)); age = calloc(_max(4, turn + 1), sizeof(int));
for (fp = &factions; *fp;) { for (fp = &factions; *fp;) {
faction *f = *fp; faction *f = *fp;
if (f->alive && !is_monsters(f)) { if (!is_monsters(f)) {
if (RemoveNMRNewbie() && !fval(f, FFL_NOIDLEOUT)) { if (RemoveNMRNewbie() && !fval(f, FFL_NOIDLEOUT)) {
if (f->age >= 0 && f->age <= turn) if (f->age >= 0 && f->age <= turn)
++age[f->age]; ++age[f->age];
@ -4267,18 +4267,16 @@ static int warn_password(void)
faction *f; faction *f;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
bool pwok = true; bool pwok = true;
if (f->alive) { const char *c = f->passw;
const char *c = f->passw; while (*c && pwok) {
while (*c && pwok) { if (!isalnum((unsigned char)*c))
if (!isalnum((unsigned char)*c)) pwok = false;
pwok = false; c++;
c++; }
} if (!pwok) {
if (!pwok) { free(f->passw);
free(f->passw); f->passw = _strdup(itoa36(rng_int()));
f->passw = _strdup(itoa36(rng_int())); ADDMSG(&f->msgs, msg_message("illegal_password", "newpass", f->passw));
ADDMSG(&f->msgs, msg_message("illegal_password", "newpass", f->passw));
}
} }
} }
return 0; return 0;

View file

@ -89,7 +89,7 @@ int update_nmrs(void)
if (fval(f, FFL_ISNEW)) { if (fval(f, FFL_ISNEW)) {
++newplayers; ++newplayers;
} }
else if (!fval(f, FFL_NOIDLEOUT) && f->alive) { else if (!fval(f, FFL_NOIDLEOUT)) {
int nmr = turn - f->lastorders + 1; int nmr = turn - f->lastorders + 1;
if (nmr < 0 || nmr > NMRTimeout()) { if (nmr < 0 || nmr > NMRTimeout()) {
log_error("faction %s has %d NMRS\n", factionid(f), nmr); log_error("faction %s has %d NMRS\n", factionid(f), nmr);
@ -370,7 +370,7 @@ summary *make_summary(void)
f->nregions = 0; f->nregions = 0;
f->num_total = 0; f->num_total = 0;
f->money = 0; f->money = 0;
if (f->alive && f->units) { if (f->units) {
s->factions++; s->factions++;
/* Problem mit Monsterpartei ... */ /* Problem mit Monsterpartei ... */
if (!is_monsters(f)) { if (!is_monsters(f)) {