clean up some dealings with monsters and NPCs

This commit is contained in:
Enno Rehling 2014-11-07 21:15:46 +01:00
parent 49493fa630
commit c8f2f33eab
2 changed files with 8 additions and 27 deletions

View File

@ -139,43 +139,24 @@ 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 *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 *get_or_create_monsters(void)
{ {
faction *f = get_monsters(); faction *f = findfaction(666);
if (!f) { if (!f) {
/* shit! */ const race *rc = rc_get_or_create("dragon");
f = findfaction(666);
}
if (!f) {
const race *rc = rc_find("dragon");
const char *email = get_param(global.parameters, "monster.email"); const char *email = get_param(global.parameters, "monster.email");
if (email) { f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, NULL, 0);
f = addfaction(email, NULL, rc, NULL, 0);
}
else {
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");
}
if (f) {
fset(f, FFL_NPC | FFL_NOIDLEOUT); fset(f, FFL_NPC | FFL_NOIDLEOUT);
} }
return f; return f;
} }
faction *get_monsters(void) {
return get_or_create_monsters();
}
const unit *random_unit_in_faction(const faction * f) const unit *random_unit_in_faction(const faction * f)
{ {
unit *u; unit *u;

View File

@ -54,7 +54,7 @@ extern "C" {
#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT) #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 { typedef struct faction {
struct faction *next; struct faction *next;