forked from github/server
defining NPC-factions with a flag instead of MONSTER_FACTION.
This commit is contained in:
parent
478ee8d153
commit
dcf3292467
|
@ -54,24 +54,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
createmonsters(void)
|
||||
faction *
|
||||
createmonsters(int no)
|
||||
{
|
||||
faction *f;
|
||||
faction *f = findfaction(no);
|
||||
|
||||
if (findfaction(MONSTER_FACTION)) {
|
||||
puts("* Fehler! Die Monster Partei gibt es schon.");
|
||||
return;
|
||||
}
|
||||
f = (faction *) calloc(1, sizeof(faction));
|
||||
f->no = MONSTER_FACTION;
|
||||
/* alles ist auf null gesetzt, ausser dem folgenden. achtung - partei
|
||||
* no 0 muss keine orders einreichen! */
|
||||
if (f) {
|
||||
puts("* Fehler! Die Monster Partei gibt es schon.");
|
||||
return f;
|
||||
}
|
||||
f = (faction *) calloc(1, sizeof(faction));
|
||||
f->no = no;
|
||||
/* alles ist auf null gesetzt, ausser dem folgenden. achtung - partei
|
||||
* no 0 muss keine orders einreichen! */
|
||||
|
||||
f->email = strdup("monsters@eressea.de");
|
||||
f->name = strdup("Monster");
|
||||
f->alive = 1;
|
||||
f->options = (char)(1<<O_REPORT);
|
||||
addlist(&factions, f);
|
||||
f->email = strdup("monsters@eressea.de");
|
||||
f->name = strdup("Monster");
|
||||
f->alive = 1;
|
||||
f->options = (char)(1<<O_REPORT);
|
||||
addlist(&factions, f);
|
||||
fhash(f);
|
||||
return f;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void createmonsters(void);
|
||||
struct faction * createmonsters(int no);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -919,7 +919,7 @@ void
|
|||
plan_monsters(void)
|
||||
{
|
||||
region *r;
|
||||
faction *f = findfaction(MONSTER_FACTION);
|
||||
faction *f = get_monsters();
|
||||
|
||||
if (!f) return;
|
||||
f->lastorders = turn;
|
||||
|
@ -1060,13 +1060,14 @@ void
|
|||
spawn_dragons(void)
|
||||
{
|
||||
region * r;
|
||||
faction * monsters = get_monsters();
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
message * msg;
|
||||
|
||||
if (fval(r->terrain, SEA_REGION) && rng_int()%10000 < 1) {
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), 1, new_race[RC_SEASERPENT]);
|
||||
u = createunit(r, monsters, 1, new_race[RC_SEASERPENT]);
|
||||
fset(u, UFL_ISNEW|UFL_MOVED);
|
||||
set_level(u, SK_MAGIC, 4);
|
||||
set_level(u, SK_OBSERVATION, 3);
|
||||
|
@ -1077,9 +1078,9 @@ spawn_dragons(void)
|
|||
if ((rterrain(r) == T_GLACIER || r->terrain == newterrain(T_SWAMP) || rterrain(r) == T_DESERT) && rng_int() % 10000 < (5 + 100 * chaosfactor(r)))
|
||||
{
|
||||
if (chance(0.80)) {
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), nrand(60, 20) + 1, new_race[RC_FIREDRAGON]);
|
||||
u = createunit(r, monsters, nrand(60, 20) + 1, new_race[RC_FIREDRAGON]);
|
||||
} else {
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), nrand(30, 20) + 1, new_race[RC_DRAGON]);
|
||||
u = createunit(r, monsters, nrand(30, 20) + 1, new_race[RC_DRAGON]);
|
||||
}
|
||||
fset(u, UFL_ISNEW|UFL_MOVED);
|
||||
|
||||
|
@ -1120,6 +1121,7 @@ void
|
|||
spawn_undead(void)
|
||||
{
|
||||
region * r;
|
||||
faction * monsters = get_monsters();
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
int unburied = deathcount(r);
|
||||
|
@ -1150,7 +1152,7 @@ spawn_undead(void)
|
|||
rc = new_race[RC_GHOUL]; break;
|
||||
}
|
||||
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), undead, rc);
|
||||
u = createunit(r, monsters, undead, rc);
|
||||
fset(u, UFL_ISNEW|UFL_MOVED);
|
||||
if ((rc == new_race[RC_SKELETON] || rc == new_race[RC_ZOMBIE]) && rng_int()%10 < 4) {
|
||||
equip_unit(u, get_equipment("rising_undead"));
|
||||
|
|
|
@ -426,87 +426,87 @@ chaosterrain(void)
|
|||
void
|
||||
chaos(region * r)
|
||||
{
|
||||
unit *u = NULL, *u2;
|
||||
building *b, *b2;
|
||||
unit *u = NULL, *u2;
|
||||
building *b, *b2;
|
||||
|
||||
if (rng_int() % 100 < 8) {
|
||||
switch (rng_int() % 3) {
|
||||
case 0: /* Untote */
|
||||
if (!fval(r->terrain, SEA_REGION)) {
|
||||
u = random_unit(r);
|
||||
if (u && playerrace(u->race)) {
|
||||
if (rng_int() % 100 < 8) {
|
||||
switch (rng_int() % 3) {
|
||||
case 0: /* Untote */
|
||||
if (!fval(r->terrain, SEA_REGION)) {
|
||||
u = random_unit(r);
|
||||
if (u && playerrace(u->race)) {
|
||||
ADDMSG(&u->faction->msgs, msg_message("chaos_disease", "unit", u));
|
||||
u_setfaction(u, findfaction(MONSTER_FACTION));
|
||||
u->race = new_race[RC_GHOUL];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1: /* Drachen */
|
||||
if (random_unit(r)) {
|
||||
int mfac = 0;
|
||||
switch (rng_int() % 3) {
|
||||
case 0:
|
||||
mfac = 100;
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), rng_int() % 8 + 1, new_race[RC_FIREDRAGON]);
|
||||
break;
|
||||
case 1:
|
||||
mfac = 500;
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), rng_int() % 4 + 1, new_race[RC_DRAGON]);
|
||||
break;
|
||||
case 2:
|
||||
mfac = 1000;
|
||||
u = createunit(r, findfaction(MONSTER_FACTION), rng_int() % 2 + 1, new_race[RC_WYRM]);
|
||||
break;
|
||||
}
|
||||
if (mfac) set_money(u, u->number * (rng_int() % mfac));
|
||||
u_setfaction(u, get_monsters());
|
||||
u->race = new_race[RC_GHOUL];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1: /* Drachen */
|
||||
if (random_unit(r)) {
|
||||
int mfac = 0;
|
||||
switch (rng_int() % 3) {
|
||||
case 0:
|
||||
mfac = 100;
|
||||
u = createunit(r, get_monsters(), rng_int() % 8 + 1, new_race[RC_FIREDRAGON]);
|
||||
break;
|
||||
case 1:
|
||||
mfac = 500;
|
||||
u = createunit(r, get_monsters(), rng_int() % 4 + 1, new_race[RC_DRAGON]);
|
||||
break;
|
||||
case 2:
|
||||
mfac = 1000;
|
||||
u = createunit(r, get_monsters(), rng_int() % 2 + 1, new_race[RC_WYRM]);
|
||||
break;
|
||||
}
|
||||
if (mfac) set_money(u, u->number * (rng_int() % mfac));
|
||||
fset(u, UFL_ISNEW|UFL_MOVED);
|
||||
}
|
||||
case 2: /* Terrainveränderung */
|
||||
if (!fval(r->terrain, FORBIDDEN_REGION)) {
|
||||
if (!fval(r->terrain, SEA_REGION)) {
|
||||
direction_t dir;
|
||||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * rn = rconnect(r, dir);
|
||||
if (rn && fval(rn->terrain, SEA_REGION)) break;
|
||||
}
|
||||
if (dir!=MAXDIRECTIONS) {
|
||||
ship * sh = r->ships;
|
||||
while (sh) {
|
||||
ship * nsh = sh->next;
|
||||
damage_ship(sh, 0.50);
|
||||
if (sh->damage >= sh->size * DAMAGE_SCALE) destroy_ship(sh);
|
||||
sh = nsh;
|
||||
}
|
||||
|
||||
for (u = r->units; u;) {
|
||||
u2 = u->next;
|
||||
if (u->race != new_race[RC_SPELL] && u->ship == 0) {
|
||||
set_number(u, 0);
|
||||
}
|
||||
u = u2;
|
||||
}
|
||||
ADDMSG(&r->msgs, msg_message("tidalwave", "region", r));
|
||||
|
||||
for (b = rbuildings(r); b;) {
|
||||
b2 = b->next;
|
||||
destroy_building(b);
|
||||
b = b2;
|
||||
}
|
||||
terraform(r, T_OCEAN);
|
||||
}
|
||||
} else {
|
||||
direction_t dir;
|
||||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
}
|
||||
case 2: /* Terrainveränderung */
|
||||
if (!fval(r->terrain, FORBIDDEN_REGION)) {
|
||||
if (!fval(r->terrain, SEA_REGION)) {
|
||||
direction_t dir;
|
||||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * rn = rconnect(r, dir);
|
||||
if (rn && fval(rn->terrain, SEA_REGION)) break;
|
||||
}
|
||||
if (dir!=MAXDIRECTIONS) {
|
||||
terraform_region(r, chaosterrain());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dir!=MAXDIRECTIONS) {
|
||||
ship * sh = r->ships;
|
||||
while (sh) {
|
||||
ship * nsh = sh->next;
|
||||
damage_ship(sh, 0.50);
|
||||
if (sh->damage >= sh->size * DAMAGE_SCALE) destroy_ship(sh);
|
||||
sh = nsh;
|
||||
}
|
||||
|
||||
for (u = r->units; u;) {
|
||||
u2 = u->next;
|
||||
if (u->race != new_race[RC_SPELL] && u->ship == 0) {
|
||||
set_number(u, 0);
|
||||
}
|
||||
u = u2;
|
||||
}
|
||||
ADDMSG(&r->msgs, msg_message("tidalwave", "region", r));
|
||||
|
||||
for (b = rbuildings(r); b;) {
|
||||
b2 = b->next;
|
||||
destroy_building(b);
|
||||
b = b2;
|
||||
}
|
||||
terraform(r, T_OCEAN);
|
||||
}
|
||||
} else {
|
||||
direction_t dir;
|
||||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * rn = rconnect(r, dir);
|
||||
if (rn && fval(rn->terrain, SEA_REGION)) break;
|
||||
}
|
||||
if (dir!=MAXDIRECTIONS) {
|
||||
terraform_region(r, chaosterrain());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1211,7 +1211,7 @@ randomevents(void)
|
|||
if (rng_int()%100 < 5) {
|
||||
ADDMSG(&u->faction->msgs, msg_message("desertion",
|
||||
"unit region", u, r));
|
||||
u_setfaction(u, findfaction(MONSTER_FACTION));
|
||||
u_setfaction(u, get_monsters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2412,7 +2412,7 @@ remove_empty_units(void)
|
|||
boolean
|
||||
faction_id_is_unused(int id)
|
||||
{
|
||||
return findfaction(id)==NULL && id!=MONSTER_FACTION;
|
||||
return findfaction(id)==NULL;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -47,8 +47,6 @@ extern "C" {
|
|||
# define MAXUNITS 1048573 /* must be prime for hashing. 524287 was >90% full */
|
||||
#endif
|
||||
|
||||
#define MONSTER_FACTION 0 /* Die Partei, in der die Monster sind. */
|
||||
#define is_monsters(f) ((f)->no==MONSTER_FACTION)
|
||||
#define MAXPEASANTS_PER_AREA 10 /* number of peasants per region-size */
|
||||
#define TREESIZE (MAXPEASANTS_PER_AREA-2) /* space used by trees (in #peasants) */
|
||||
|
||||
|
|
|
@ -47,6 +47,22 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
faction *
|
||||
get_monsters(void)
|
||||
{
|
||||
static faction * monsters = NULL;
|
||||
|
||||
if (!monsters) {
|
||||
faction * f;
|
||||
for (f=factions;f;f=f->next) {
|
||||
if (f->flags&FFL_NPC) {
|
||||
return monsters=f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return monsters;
|
||||
}
|
||||
|
||||
const unit *
|
||||
random_unit_in_faction(const faction *f)
|
||||
{
|
||||
|
|
|
@ -50,8 +50,12 @@ typedef struct shortpwd {
|
|||
#define FFL_DBENTRY (1<<28) /* Partei ist in Datenbank eingetragen */
|
||||
#define FFL_NOTIMEOUT (1<<29) /* ignore MaxAge() */
|
||||
#define FFL_GM (1<<30) /* eine Partei mit Sonderrechten */
|
||||
#define FFL_NPC (1<<31) /* eine Partei mit Monstern */
|
||||
|
||||
#define FFL_SAVEMASK (FFL_NEWID|FFL_GM|FFL_NOTIMEOUT|FFL_DBENTRY|FFL_NOTIMEOUT)
|
||||
#define FFL_SAVEMASK (FFL_NEWID|FFL_GM|FFL_NPC|FFL_NOTIMEOUT|FFL_DBENTRY|FFL_NOTIMEOUT)
|
||||
|
||||
struct faction * get_monsters(void);
|
||||
#define is_monsters(f) ((f)->flags&FFL_NPC)
|
||||
|
||||
typedef struct faction {
|
||||
struct faction *next;
|
||||
|
|
|
@ -925,7 +925,7 @@ readunit(struct storage * store)
|
|||
}
|
||||
if (u->faction == NULL) {
|
||||
log_error(("unit %s has faction == NULL\n", unitname(u)));
|
||||
u_setfaction(u, findfaction(MONSTER_FACTION));
|
||||
u_setfaction(u, get_monsters());
|
||||
set_number(u, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ void
|
|||
spawn_braineaters(float chance)
|
||||
{
|
||||
region *r;
|
||||
faction *f0 = findfaction(MONSTER_FACTION);
|
||||
faction *f0 = get_monsters();
|
||||
int next = rng_int() % (int)(chance*100);
|
||||
|
||||
if (f0==NULL) return;
|
||||
|
|
|
@ -312,7 +312,7 @@ destroy_unit(unit * u)
|
|||
} else
|
||||
#endif
|
||||
if (zombie) {
|
||||
u_setfaction(u, findfaction(MONSTER_FACTION));
|
||||
u_setfaction(u, get_monsters());
|
||||
scale_number(u, 1);
|
||||
u->race = u->irace = new_race[RC_ZOMBIE];
|
||||
} else {
|
||||
|
|
|
@ -89,7 +89,7 @@ make_dungeon(const dungeon * data)
|
|||
int iterations = size * size;
|
||||
unsigned int flags = PFL_NORECRUITS;
|
||||
int n = 0;
|
||||
struct faction * fmonsters = findfaction(MONSTER_FACTION);
|
||||
struct faction * fmonsters = get_monsters();
|
||||
plane * p;
|
||||
region *r, *center;
|
||||
region * rnext;
|
||||
|
|
|
@ -156,7 +156,7 @@ score(void)
|
|||
|
||||
for (fc = factions; fc; fc = fc->next) {
|
||||
fc->score = fc->score / 5;
|
||||
if (fc->no != MONSTER_FACTION && fc->race != new_race[RC_TEMPLATE]) {
|
||||
if (!is_monsters(fc) && fc->race != new_race[RC_TEMPLATE]) {
|
||||
allscores += fc->score;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,25 +36,25 @@
|
|||
void
|
||||
age_undead(unit *u)
|
||||
{
|
||||
region *r = u->region;
|
||||
int n = 0;
|
||||
region *r = u->region;
|
||||
int n = 0;
|
||||
|
||||
/* untote, die einer partei angehoeren, koennen sich
|
||||
* absplitten, anstatt sich zu vermehren. monster
|
||||
* untote vermehren sich nur noch */
|
||||
/* untote, die einer partei angehoeren, koennen sich
|
||||
* absplitten, anstatt sich zu vermehren. monster
|
||||
* untote vermehren sich nur noch */
|
||||
|
||||
if (u->number > UNDEAD_MIN && !is_monsters(u->faction) && rng_int() % 100 < UNDEAD_BREAKUP) {
|
||||
int m;
|
||||
unit *u2;
|
||||
if (u->number > UNDEAD_MIN && !is_monsters(u->faction) && rng_int() % 100 < UNDEAD_BREAKUP) {
|
||||
int m;
|
||||
unit *u2;
|
||||
|
||||
n = 0;
|
||||
for (m = u->number; m; m--)
|
||||
if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION)
|
||||
n++;
|
||||
u2 = create_unit(r, findfaction(MONSTER_FACTION), 0, new_race[RC_UNDEAD], 0, NULL, u);
|
||||
n = 0;
|
||||
for (m = u->number; m; m--) {
|
||||
if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION) ++n;
|
||||
}
|
||||
u2 = create_unit(r, get_monsters(), 0, new_race[RC_UNDEAD], 0, NULL, u);
|
||||
make_undead_unit(u2);
|
||||
transfermen(u, u2, u->number - n);
|
||||
}
|
||||
transfermen(u, u2, u->number - n);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -103,7 +103,7 @@ sp_summon_alp(struct castorder *co)
|
|||
int cast_level = co->level;
|
||||
spellparameter *pa = co->par;
|
||||
const struct race * rc = new_race[RC_ALP];
|
||||
struct faction * f = findfaction(MONSTER_FACTION);
|
||||
struct faction * f = get_monsters();
|
||||
struct message * msg;
|
||||
|
||||
opfer = pa->param[0]->data.u;
|
||||
|
|
|
@ -1212,7 +1212,7 @@ patzer_ents(castorder *co)
|
|||
}
|
||||
|
||||
ents = (int)(force*10);
|
||||
u = create_unit(r, findfaction(MONSTER_FACTION), ents, new_race[RC_TREEMAN], 0, NULL, NULL);
|
||||
u = create_unit(r, get_monsters(), ents, new_race[RC_TREEMAN], 0, NULL, NULL);
|
||||
|
||||
/* 'Erfolg' melden */
|
||||
ADDMSG(&mage->faction->msgs, msg_message(
|
||||
|
@ -2395,7 +2395,7 @@ patzer_peasantmob(castorder *co)
|
|||
}
|
||||
|
||||
if (r->land) {
|
||||
faction * f = findfaction(MONSTER_FACTION);
|
||||
faction * f = get_monsters();
|
||||
const struct locale * lang = f->locale;
|
||||
message * msg;
|
||||
|
||||
|
@ -2621,7 +2621,7 @@ sp_summondragon(castorder *co)
|
|||
int number;
|
||||
const race * race;
|
||||
|
||||
f = findfaction(MONSTER_FACTION);
|
||||
f = get_monsters();
|
||||
|
||||
if (r->terrain != newterrain(T_SWAMP) && rterrain(r) != T_DESERT
|
||||
&& rterrain(r) != T_GLACIER) {
|
||||
|
@ -4035,7 +4035,7 @@ sp_raisepeasantmob(castorder *co)
|
|||
int cast_level = co->level;
|
||||
double force = co->force;
|
||||
int duration = (int)force+1;
|
||||
faction * monsters = findfaction(MONSTER_FACTION);
|
||||
faction * monsters = get_monsters();
|
||||
message * msg;
|
||||
|
||||
anteil.i = 6 + (rng_int()%4);
|
||||
|
@ -4365,7 +4365,7 @@ sp_pump(castorder *co)
|
|||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error_not_on_undead", ""));
|
||||
return 0;
|
||||
}
|
||||
if (is_magic_resistant(mage, target, 0) || target->faction->no == MONSTER_FACTION) {
|
||||
if (is_magic_resistant(mage, target, 0) || is_monsters(target->faction)) {
|
||||
report_failure(mage, co->order);
|
||||
return 0;
|
||||
}
|
||||
|
@ -4684,7 +4684,7 @@ sp_dragonsong(castorder *co)
|
|||
|
||||
/* TODO HP-Effekt */
|
||||
|
||||
f = findfaction(MONSTER_FACTION);
|
||||
f = get_monsters();
|
||||
|
||||
rl = all_in_range(r, (int)power);
|
||||
|
||||
|
|
|
@ -655,7 +655,7 @@ fix_astralplane(void)
|
|||
plane * astralplane = get_astralplane();
|
||||
region * rs;
|
||||
region_list * rlist = NULL;
|
||||
faction * monsters = findfaction(MONSTER_FACTION);
|
||||
faction * monsters = get_monsters();
|
||||
|
||||
if (astralplane==NULL || monsters==NULL) return 0;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ static void
|
|||
lua_planmonsters(void)
|
||||
{
|
||||
unit * u;
|
||||
faction * f = findfaction(MONSTER_FACTION);
|
||||
faction * f = get_monsters();
|
||||
|
||||
if (f==NULL) return;
|
||||
rng_init(turn?turn:(int)time(0));
|
||||
|
|
Loading…
Reference in New Issue