From c8f2f33eab70f6863dc530901631175181bc87e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 7 Nov 2014 21:15:46 +0100 Subject: [PATCH] clean up some dealings with monsters and NPCs --- src/kernel/faction.c | 33 +++++++-------------------------- src/kernel/faction.h | 2 +- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 1515e9c65..b61db7297 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -139,43 +139,24 @@ void set_show_item(faction * f, const struct item_type *itype) a->data.v = (void *)itype; } -faction *get_monsters(void) { - faction *f; - - for (f = factions; f; f = f->next) { - if ((f->flags & FFL_NPC) && !(f->flags & FFL_DEFENDER)) { - return f; - } - } - return 0; -} - faction *get_or_create_monsters(void) { - faction *f = get_monsters(); + faction *f = findfaction(666); if (!f) { - /* shit! */ - f = findfaction(666); - } - if (!f) { - const race *rc = rc_find("dragon"); - + const race *rc = rc_get_or_create("dragon"); const char *email = get_param(global.parameters, "monster.email"); - if (email) { - f = addfaction(email, NULL, rc, NULL, 0); - } - else { - f = addfaction("noreply@eressea.de", NULL, rc, NULL, 0); - } + f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, NULL, 0); renumber_faction(f, 666); faction_setname(f, "Monster"); - } - if (f) { fset(f, FFL_NPC | FFL_NOIDLEOUT); } return f; } +faction *get_monsters(void) { + return get_or_create_monsters(); +} + const unit *random_unit_in_faction(const faction * f) { unit *u; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 25d8f20b5..91c98546a 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -54,7 +54,7 @@ extern "C" { #define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT) -#define is_monsters(f) ((f)->flags&FFL_NPC) +#define is_monsters(f) (f && f==get_monsters()) typedef struct faction { struct faction *next;