properly create missing monster faction when spawning dragons.

This commit is contained in:
Enno Rehling 2014-08-16 13:46:34 +02:00
parent 90ec28fed3
commit 8803a9e9a8
3 changed files with 363 additions and 351 deletions

View File

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -105,40 +105,44 @@ void set_show_item(faction * f, const struct item_type *itype)
a->data.v = (void *)itype; a->data.v = (void *)itype;
} }
faction *get_monsters(void) static faction *monsters;
{
static faction *monsters;
static int gamecookie = -1;
if (gamecookie != global.cookie) { faction *get_monsters(void) {
monsters = NULL;
gamecookie = global.cookie;
}
if (!monsters) {
faction *f; faction *f;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if ((f->flags & FFL_NPC) && !(f->flags & FFL_DEFENDER)) { if ((f->flags & FFL_NPC) && !(f->flags & FFL_DEFENDER)) {
return monsters = f; return monsters = f;
} }
} }
if (!monsters) { return 0;
/* shit! */ }
monsters = findfaction(666);
faction *get_or_create_monsters(void)
{
faction *f = get_monsters();
static int gamecookie = -1;
if (gamecookie != global.cookie) {
monsters = NULL;
gamecookie = global.cookie;
} }
if (!monsters) {
if (!f) {
/* shit! */
f = findfaction(666);
}
if (!f) {
const race *rc = rc_find("dragon"); const race *rc = rc_find("dragon");
faction *f = addfaction("noreply@eressea.de", NULL, rc, NULL, 0);
f = addfaction("noreply@eressea.de", NULL, rc, NULL, 0);
renumber_faction(f, 666); renumber_faction(f, 666);
faction_setname(f, "Monster"); faction_setname(f, "Monster");
f->options = 0; f->options = 0;
monsters = f;
} }
if (monsters) { if (f) {
fset(monsters, FFL_NPC | FFL_NOIDLEOUT); fset(f, FFL_NPC | FFL_NOIDLEOUT);
} }
} return monsters = f;
return monsters;
} }
const unit *random_unit_in_faction(const faction * f) const unit *random_unit_in_faction(const faction * f)
@ -170,7 +174,8 @@ const char *factionname(const faction * f)
if (f && f->name) { if (f && f->name) {
slprintf(ibuf, sizeof(name), "%s (%s)", f->name, itoa36(f->no)); slprintf(ibuf, sizeof(name), "%s (%s)", f->name, itoa36(f->no));
} else { }
else {
strcpy(ibuf, "Unbekannte Partei (?)"); strcpy(ibuf, "Unbekannte Partei (?)");
} }
return ibuf; return ibuf;
@ -186,7 +191,7 @@ int resolve_faction(variant id, void *address)
result = -1; result = -1;
} }
} }
*(faction **) address = f; *(faction **)address = f;
return result; return result;
} }
@ -211,7 +216,6 @@ faction *addfaction(const char *email, const char *password,
faction *f = calloc(sizeof(faction), 1); faction *f = calloc(sizeof(faction), 1);
char buf[128]; char buf[128];
assert(frace || !"cannot create a faction that has no race");
if (set_email(&f->email, email) != 0) { if (set_email(&f->email, email) != 0) {
log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), email); log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
} }
@ -242,6 +246,10 @@ faction *addfaction(const char *email, const char *password,
slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), factionid(f)); slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), factionid(f));
f->name = _strdup(buf); f->name = _strdup(buf);
if (!f->race) {
log_warning("creating a faction that has no race", factionid(f));
}
return f; return f;
} }
@ -263,7 +271,7 @@ unit *addplayer(region * r, faction * f)
race_t urc; race_t urc;
race *rc; race *rc;
do { do {
urc = (race_t) (rng_int() % MAXRACES); urc = (race_t)(rng_int() % MAXRACES);
rc = get_race(urc); rc = get_race(urc);
} while (rc == NULL || urc == RC_DAEMON || !playerrace(rc)); } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc));
u->irace = rc; u->irace = rc;
@ -322,7 +330,8 @@ void destroyfaction(faction * f)
unit *zombie = u; unit *zombie = u;
u = u->nextF; u = u->nextF;
make_zombie(zombie); make_zombie(zombie);
} else { }
else {
region *r = u->region; region *r = u->region;
if (!fval(r->terrain, SEA_REGION) && !!playerrace(u_race(u))) { if (!fval(r->terrain, SEA_REGION) && !!playerrace(u_race(u))) {
@ -338,7 +347,8 @@ void destroyfaction(faction * f)
* stammen */ * stammen */
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */ if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
h += u->number; h += u->number;
} else { /* Orks zählen nur zur Hälfte */ }
else { /* Orks zählen nur zur Hälfte */
p += (int)(u->number * rc->recruit_multi); p += (int)(u->number * rc->recruit_multi);
} }
for (itm = u->items; itm; itm = itm->next) { for (itm = u->items; itm; itm = itm->next) {
@ -357,7 +367,7 @@ void destroyfaction(faction * f)
} }
} }
f->alive = 0; f->alive = 0;
/* 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) {
group *g; group *g;
@ -505,7 +515,7 @@ bool valid_race(const struct faction *f, const struct race *rc)
else { else {
const char *str = get_param(f->race->parameters, "other_race"); const char *str = get_param(f->race->parameters, "other_race");
if (str) if (str)
return (bool) (rc_find(str) == rc); return (bool)(rc_find(str) == rc);
return false; return false;
} }
} }
@ -528,7 +538,7 @@ struct spellbook * faction_get_spellbook(struct faction *f)
if (f->spellbook) { if (f->spellbook) {
return f->spellbook; return f->spellbook;
} }
if (f->magiegebiet!=M_GRAY) { if (f->magiegebiet != M_GRAY) {
return get_spellbook(magic_school[f->magiegebiet]); return get_spellbook(magic_school[f->magiegebiet]);
} }
return 0; return 0;
@ -542,7 +552,7 @@ static int allied_skillcount(const faction * f, skill_t sk)
int qi; int qi;
for (qi = 0; members; ql_advance(&members, &qi, 1)) { for (qi = 0; members; ql_advance(&members, &qi, 1)) {
faction *m = (faction *) ql_get(members, qi); faction *m = (faction *)ql_get(members, qi);
num += count_skill(m, sk); num += count_skill(m, sk);
} }
return num; return num;
@ -591,7 +601,8 @@ int skill_limit(faction * f, skill_t sk)
} }
if (sk == SK_MAGIC) { if (sk == SK_MAGIC) {
m = max_magicians(f); m = max_magicians(f);
} else if (sk == SK_ALCHEMY) { }
else if (sk == SK_ALCHEMY) {
m = get_param_int(global.parameters, "rules.maxskills.alchemy", m = get_param_int(global.parameters, "rules.maxskills.alchemy",
MAXALCHEMISTS); MAXALCHEMISTS);
} }

View File

@ -114,6 +114,7 @@ typedef struct faction {
extern struct faction *factions; extern struct faction *factions;
struct faction *get_monsters(void); struct faction *get_monsters(void);
struct faction *get_or_create_monsters(void);
int max_magicians(const faction * f); int max_magicians(const faction * f);
void set_show_item(faction * f, const struct item_type *itype); void set_show_item(faction * f, const struct item_type *itype);

View File

@ -889,7 +889,7 @@ static int nrand(int start, int sub)
void spawn_dragons(void) void spawn_dragons(void)
{ {
region *r; region *r;
faction *monsters = get_monsters(); faction *monsters = get_or_create_monsters();
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit *u; unit *u;