forked from github/server
properly create missing monster faction when spawning dragons.
remove cached monster faction (static). Conflicts: src/kernel/faction.c
This commit is contained in:
parent
206e0a2fc5
commit
138a4c10a0
|
@ -105,32 +105,37 @@ 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)
|
faction *get_monsters(void) {
|
||||||
{
|
|
||||||
static faction *monsters;
|
|
||||||
static int gamecookie = -1;
|
|
||||||
|
|
||||||
if (gamecookie != global.cookie) {
|
|
||||||
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 f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!monsters) {
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
faction *get_or_create_monsters(void)
|
||||||
|
{
|
||||||
|
faction *f = get_monsters();
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
/* shit! */
|
/* shit! */
|
||||||
monsters = findfaction(666);
|
f = findfaction(666);
|
||||||
}
|
}
|
||||||
if (monsters) {
|
if (!f) {
|
||||||
fset(monsters, FFL_NPC | FFL_NOIDLEOUT);
|
const race *rc = rc_find("dragon");
|
||||||
|
|
||||||
|
f = addfaction("noreply@eressea.de", NULL, rc, NULL, 0);
|
||||||
|
renumber_faction(f, 666);
|
||||||
|
faction_setname(f, "Monster");
|
||||||
|
f->options = 0;
|
||||||
}
|
}
|
||||||
|
if (f) {
|
||||||
|
fset(f, FFL_NPC | FFL_NOIDLEOUT);
|
||||||
}
|
}
|
||||||
return monsters;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unit *random_unit_in_faction(const faction * f)
|
const unit *random_unit_in_faction(const faction * f)
|
||||||
|
@ -162,7 +167,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;
|
||||||
|
@ -235,6 +241,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +325,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))) {
|
||||||
|
@ -331,7 +342,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) {
|
||||||
|
@ -584,7 +596,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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue