Total ohne Not mal wieder eine grosse Umstellung gemacht: Diesmal am Parser.

Okay, natuerlich habe ich damit was im Sinne: Das ist eine Vorbereitung auf voll geskriptete, neu zugefuegte Befehle und anderes Processing (aus Skripten). Fuer ein neues Spiel.

Hoffen wir, dass nicht zuviel kaputtgeht :-)
This commit is contained in:
Enno Rehling 2006-08-12 19:15:16 +00:00
parent 150a1e38b0
commit ed70863843
30 changed files with 1176 additions and 1175 deletions

View File

@ -995,10 +995,8 @@ gebaeude_stuerzt_ein(region * r, building * b)
}
void
maintain_buildings(boolean crash)
maintain_buildings(region * r, boolean crash)
{
region * r;
for (r = regions; r; r = r->next) {
building **bp = &r->buildings;
while (*bp) {
building * b = *bp;
@ -1026,22 +1024,18 @@ maintain_buildings(boolean crash)
bp=&b->next;
}
}
}
void
economics(void)
economics(region *r)
{
region *r;
unit *u;
request *recruitorders = NULL;
/* Geben vor Selbstmord (doquit)! Hier alle unmittelbaren Befehle.
* Rekrutieren vor allen Einnahmequellen. Bewachen JA vor Steuern
* eintreiben. */
for (r = regions; r; r = r->next) if (r->units) {
request *recruitorders = NULL;
for (u = r->units; u; u = u->next) {
order * ord;
boolean destroyed = false;
@ -1080,8 +1074,7 @@ economics(void)
}
if (recruitorders) expandrecruit(r, recruitorders);
}
remove_empty_units_in_region(r);
}
/* ------------------------------------------------------------- */

View File

@ -47,11 +47,11 @@ extern int income(const struct unit * u);
/* Wieviel Fremde eine Partei pro Woche aufnehmen kann */
#define MAXNEWBIES 5
void economics(void);
void economics(struct region *r);
void produce(void);
enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC };
void maintain_buildings(boolean crash);
void maintain_buildings(struct region * r, boolean crash);
extern void add_spende(struct faction * f1, struct faction * f2, int betrag, struct region * r);
#ifdef __cplusplus

View File

@ -1196,12 +1196,7 @@ parse_restart(void)
/* Clear away debris of destroyed factions */
puts(" - beseitige leere Einheiten und leere Parteien...");
remove_empty_units();
/* Auskommentiert: Wenn factions gelöscht werden, zeigen
* Spendenpointer ins Leere. */
/* remove_empty_factions(); */
}
/* ------------------------------------------------------------- */
@ -1798,71 +1793,6 @@ deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver)
}
}
static int
prepare_mail_cmd(unit * u, struct order * ord)
{
const char *s;
int n;
init_tokens(ord);
skip_token(); /* skip the keyword */
s = getstrtoken();
/* Falls kein Parameter, ist das eine Einheitsnummer;
* das Füllwort "AN" muß wegfallen, da gültige Nummer! */
if (strcasecmp(s, "to") == 0) s = getstrtoken();
else if (strcasecmp(s, "an") == 0) s = getstrtoken();
switch (findparam(s, u->faction->locale)) {
case P_REGION:
break;
case P_FACTION:
break;
case P_UNIT:
{
region *r = u->region;
unit *u2;
boolean see = false;
n = getid();
for (u2=r->units; u2; u2=u2->next) {
if (u2->no == n && cansee(u->faction, r, u2, 0)) {
see = true;
break;
}
}
if (see == false) {
break;
}
s = getstrtoken();
if (!s[0]) {
break;
}
u2 = findunitr(r,n);
if(u2 && cansee(u->faction, r, u2, 0)) {
event_arg args[3];
args[0].data.v = (void*)s;
args[0].type = "string";
args[1].data.v = (void*)u;
args[1].type = "unit";
args[2].type = NULL;
handle_event(&u2->attribs, "message", args);
}
}
break;
case P_BUILDING:
case P_GEBAEUDE:
break;
case P_SHIP:
break;
}
return 0;
}
static void
mailunit(region * r, unit * u, int n, struct order * ord, const char * s)
{
@ -1971,9 +1901,21 @@ mail_cmd(unit * u, struct order * ord)
if (!s[0]) {
cmistake(u, ord, 30, MSG_MESSAGE);
break;
} else {
attrib * a = a_find(u2->attribs, &at_eventhandler);
if (a!=NULL) {
event_arg args[3];
args[0].data.v = (void*)s;
args[0].type = "string";
args[1].data.v = (void*)u;
args[1].type = "unit";
args[2].type = NULL;
handle_event(a, "message", args);
}
mailunit(r, u, n, ord, s);
}
}
break;
case P_BUILDING:
@ -2167,43 +2109,6 @@ send_cmd(unit * u, struct order * ord)
return 0;
}
static void
set_passw(void)
{
region *r;
puts(" - setze Passwörter, Adressen und Format, Abstimmungen");
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
struct order * ord;
for (ord = u->orders; ord; ord = ord->next) {
switch (get_keyword(ord)) {
case NOKEYWORD:
cmistake(u, ord, 22, MSG_EVENT);
break;
case K_BANNER:
if (banner_cmd(u, ord)!=0) ord = NULL;
break;
case K_EMAIL:
if (email_cmd(u, ord)!=0) ord = NULL;
break;
case K_PASSWORD:
if (password_cmd(u, ord)!=0) ord = NULL;
break;
case K_SEND:
if (send_cmd(u, ord)!=0) ord = NULL;
break;
}
}
}
}
}
static boolean
display_item(faction *f, unit *u, const item_type * itype)
{
@ -2667,7 +2572,6 @@ instant_orders(void)
}
}
parse(K_GROUP, group_cmd, false);
for (r = regions; r; r = r->next) {
unit * u;
for (u = r->units; u; u = u->next) {
@ -2774,12 +2678,8 @@ guard_on_cmd(unit * u, struct order * ord)
}
static void
sinkships(void)
sinkships(region * r)
{
region *r;
/* Unbemannte Schiffe können sinken */
for (r = regions; r; r = r->next) {
ship *sh;
list_foreach(ship, r->ships, sh) {
@ -2795,7 +2695,6 @@ sinkships(void)
}
list_next(sh);
}
}
/* The following functions do not really belong here: */
#include "eressea.h"
@ -3064,19 +2963,13 @@ declare_war(void)
}
#endif
static void
renumber(void)
static int
renumber_cmd(unit * u, order * ord)
{
region *r;
const char * s;
unit * u;
int i;
for (r=regions;r;r=r->next) {
for (u=r->units;u;u=u->next) {
faction * f = u->faction;
struct order * ord;
for (ord = u->orders; ord; ord = ord->next) if (get_keyword(ord)==K_NUMBER) {
init_tokens(ord);
skip_token();
s = getstrtoken();
@ -3100,17 +2993,17 @@ renumber(void)
i = atoi36(s);
if (i<=0 || i>MAX_UNIT_NR) {
cmistake(u, ord, 114, MSG_EVENT);
continue;
break;
}
if (forbiddenid(i)) {
cmistake(u, ord, 116, MSG_EVENT);
continue;
break;
}
if(findunitg(i, r)) {
if (findunitg(i, u->region)) {
cmistake(u, ord, 115, MSG_EVENT);
continue;
break;
}
}
uunhash(u);
@ -3125,11 +3018,11 @@ renumber(void)
case P_SHIP:
if (!u->ship) {
cmistake(u,ord,144,MSG_EVENT);
continue;
break;
}
if (!fval(u, UFL_OWNER)) {
cmistake(u,ord,146,MSG_EVENT);
continue;
break;
}
s = getstrtoken();
if(s == NULL || *s == 0) {
@ -3138,11 +3031,11 @@ renumber(void)
i = atoi36(s);
if (i<=0 || i>MAX_CONTAINER_NR) {
cmistake(u,ord,114,MSG_EVENT);
continue;
break;
}
if (findship(i) || findbuilding(i)) {
cmistake(u,ord,115,MSG_EVENT);
continue;
break;
}
}
sunhash(u->ship);
@ -3154,11 +3047,11 @@ renumber(void)
case P_GEBAEUDE:
if (!u->building) {
cmistake(u,ord,145,MSG_EVENT);
continue;
break;
}
if(!fval(u, UFL_OWNER)) {
cmistake(u,ord,148,MSG_EVENT);
continue;
break;
}
s = getstrtoken();
if(*s == 0) {
@ -3167,11 +3060,11 @@ renumber(void)
i = atoi36(s);
if (i<=0 || i>MAX_CONTAINER_NR) {
cmistake(u,ord,114,MSG_EVENT);
continue;
break;
}
if(findship(i) || findbuilding(i)) {
cmistake(u,ord,115,MSG_EVENT);
continue;
break;
}
}
bunhash(u->building);
@ -3182,10 +3075,7 @@ renumber(void)
default:
cmistake(u, ord, 239, MSG_EVENT);
}
}
}
}
renumber_factions();
return 0;
}
static building *
@ -3260,7 +3150,7 @@ age_building(building * b)
}
a_age(&b->attribs);
handle_event(&b->attribs, "timer", b);
handle_event(b->attribs, "timer", b);
return b;
}
@ -3302,7 +3192,7 @@ ageing(void)
/* Factions */
for (f=factions;f;f=f->next) {
a_age(&f->attribs);
handle_event(&f->attribs, "timer", f);
handle_event(f->attribs, "timer", f);
}
/* Regionen */
@ -3312,13 +3202,13 @@ ageing(void)
ship ** sp;
a_age(&r->attribs);
handle_event(&r->attribs, "timer", r);
handle_event(r->attribs, "timer", r);
/* Einheiten */
for (up=&r->units;*up;) {
unit * u = *up;
a_age(&u->attribs);
if (u==*up) handle_event(&u->attribs, "timer", u);
if (u==*up) handle_event(u->attribs, "timer", u);
if (u==*up) up = &(*up)->next;
}
@ -3326,7 +3216,7 @@ ageing(void)
for (sp=&r->ships;*sp;) {
ship * s = *sp;
a_age(&s->attribs);
if (s==*sp) handle_event(&s->attribs, "timer", s);
if (s==*sp) handle_event(s->attribs, "timer", s);
if (s==*sp) sp = &(*sp)->next;
}
@ -3467,14 +3357,8 @@ new_units (void)
}
static void
setdefaults (void)
setdefaults(unit *u)
{
region *r;
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
order *ord;
boolean trade = false;
boolean hunger = LongHunger(u);
@ -3540,7 +3424,7 @@ setdefaults (void)
}
}
if (hunger) continue;
if (hunger) return;
/* Wenn die Einheit handelt, muß der Default-Befehl gelöscht
* werden. */
@ -3572,8 +3456,6 @@ setdefaults (void)
}
#endif
}
}
}
static int
use_item(unit * u, const item_type * itype, int amount, struct order * ord)
@ -3861,166 +3743,354 @@ claim_cmd(unit * u, struct order * ord)
return 0;
}
typedef struct processor {
struct processor * next;
int priority;
enum { PR_GLOBAL, PR_REGION, PR_UNIT, PR_ORDER } type;
union {
struct {
keyword_t kword;
boolean thisorder;
int (*process)(struct unit *, struct order *);
} per_order;
struct {
void (*process)(struct unit *);
} per_unit;
struct {
void (*process)(struct region *);
} per_region;
struct {
void (*process)(void);
} global;
} data;
const char * name;
} processor;
static processor * processors;
void
add_proc_order(int priority, keyword_t kword, int (*parser)(struct unit *, struct order *), boolean thisorder, const char * name)
{
processor **pproc = &processors;
processor *proc;
while (*pproc) {
proc = *pproc;
if (proc->priority>priority) break;
else if (proc->priority==priority && proc->type>=PR_ORDER) break;
pproc = &proc->next;
}
proc = malloc(sizeof(processor));
proc->priority = priority;
proc->type = PR_ORDER;
proc->data.per_order.process = parser;
proc->data.per_order.kword = kword;
proc->data.per_order.thisorder = thisorder;
proc->name = name;
proc->next = *pproc;
*pproc = proc;
}
void
add_proc_global(int priority, void (*process)(void), const char * name)
{
processor **pproc = &processors;
processor *proc;
while (*pproc) {
proc = *pproc;
if (proc->priority>priority) break;
else if (proc->priority==priority && proc->type>=PR_GLOBAL) break;
pproc = &proc->next;
}
proc = malloc(sizeof(processor));
proc->priority = priority;
proc->type = PR_GLOBAL;
proc->data.global.process = process;
proc->name = name;
proc->next = *pproc;
*pproc = proc;
}
void
add_proc_region(int priority, void (*process)(region *), const char * name)
{
processor **pproc = &processors;
processor *proc;
while (*pproc) {
proc = *pproc;
if (proc->priority>priority) break;
else if (proc->priority==priority && proc->type>=PR_REGION) break;
pproc = &proc->next;
}
proc = malloc(sizeof(processor));
proc->priority = priority;
proc->type = PR_REGION;
proc->data.per_region.process = process;
proc->name = name;
proc->next = *pproc;
*pproc = proc;
}
void
add_proc_unit(int priority, void (*process)(unit *), const char * name)
{
processor **pproc = &processors;
processor *proc;
while (*pproc) {
proc = *pproc;
if (proc->priority>priority) break;
else if (proc->priority==priority && proc->type>=PR_UNIT) break;
pproc = &proc->next;
}
proc = malloc(sizeof(processor));
proc->priority = priority;
proc->type = PR_UNIT;
proc->data.per_unit.process = process;
proc->name = name;
proc->next = *pproc;
*pproc = proc;
}
void
process(void)
{
processor *proc = processors;
while (proc) {
int prio = proc->priority;
region *r;
processor *pglobal = proc;
printf("- Step %u\n", prio);
while (proc && proc->priority==prio) {
if (proc->name) printf(" - %s\n", proc->name);
proc = proc->next;
}
while (pglobal && pglobal->priority==prio && pglobal->type==PR_GLOBAL) {
pglobal->data.global.process();
pglobal = pglobal->next;
}
if (pglobal==NULL || pglobal->priority!=prio) continue;
for (r = regions; r; r = r->next) {
unit **up;
processor *pregion = pglobal;
while (pregion && pregion->priority==prio && pregion->type==PR_REGION) {
pregion->data.per_region.process(r);
pregion = pregion->next;
}
if (pregion==NULL || pregion->priority!=prio) continue;
for (up=&r->units;*up;) {
unit * u = *up;
processor *porder, *punit = pregion;
while (punit && punit->priority==prio && punit->type==PR_UNIT) {
punit->data.per_unit.process(u);
punit = punit->next;
}
if (punit==NULL || punit->priority!=prio) continue;
porder = punit;
while (porder && porder->priority==prio && porder->type==PR_ORDER) {
order ** ordp = &u->orders;
if (porder->data.per_order.thisorder) ordp = &u->thisorder;
while (*ordp) {
order * ord = *ordp;
if (get_keyword(ord) == porder->data.per_order.kword) {
porder->data.per_order.process(u, ord);
}
if (*ordp==ord) ordp=&ord->next;
}
porder = porder->next;
}
assert(*up==u);
up=&u->next;
}
}
}
}
static void enter_1(region * r) { do_misc(r, false); }
static void enter_2(region * r) { do_misc(r, true); }
static void maintain_buildings_1(region * r) { maintain_buildings(r, false); }
static void maintain_buildings_2(region * r) { maintain_buildings(r,true); }
static void reset_moved(unit * u) { freset(u, UFL_MOVED); }
static void reset_rng(void) {
if (turn == 0) rng_init((int)time(0));
else rng_init(turn);
}
void
processorders (void)
{
region *r;
int p;
set_passw(); /* und pruefe auf illegale Befehle */
p = 10;
add_proc_global(p, &new_units, "Neue Einheiten erschaffen");
puts(" - neue Einheiten erschaffen...");
new_units();
p+=10;
add_proc_unit(p, &setdefaults, "Default-Befehle");
add_proc_order(p, K_BANNER, &banner_cmd, false, NULL);
add_proc_order(p, K_EMAIL, &email_cmd, false, NULL);
add_proc_order(p, K_PASSWORD, &password_cmd, false, NULL);
add_proc_order(p, K_SEND, &send_cmd, false, NULL);
add_proc_order(p, K_GROUP, &group_cmd, false, NULL);
puts(" - Defaults und Instant-Befehle...");
setdefaults();
instant_orders();
if (alliances!=NULL) alliancekick();
parse(K_MAIL, prepare_mail_cmd, false);
parse(K_MAIL, mail_cmd, false);
puts(" - Parteien altern");
age_factions();
puts(" - Benutzen");
parse(K_CLAIM, claim_cmd, false);
parse(K_USE, use_cmd, false);
puts(" - Kontaktieren, Betreten von Schiffen und Gebäuden (1.Versuch)");
do_misc(false);
p+=10;
add_proc_unit(p, &reset_moved, "Instant-Befehle");
add_proc_order(p, K_QUIT, &quit_cmd, false, NULL);
add_proc_order(p, K_URSPRUNG, &origin_cmd, false, NULL);
add_proc_order(p, K_ALLY, &ally_cmd, false, NULL);
add_proc_order(p, K_PREFIX, &prefix_cmd, false, NULL);
add_proc_order(p, K_SYNONYM, &synonym_cmd, false, NULL);
add_proc_order(p, K_SETSTEALTH, &setstealth_cmd, false, NULL);
add_proc_order(p, K_STATUS, &status_cmd, false, NULL);
add_proc_order(p, K_COMBAT, &combatspell_cmd, false, NULL);
add_proc_order(p, K_DISPLAY, &display_cmd, false, NULL);
add_proc_order(p, K_NAME, &name_cmd, false, NULL);
add_proc_order(p, K_GUARD, &guard_off_cmd, false, NULL);
add_proc_order(p, K_RESHOW, &reshow_cmd, false, NULL);
#ifdef KARMA_MODULE
add_proc_order(p, K_WEREWOLF, &setwere_cmd, false, NULL);
#endif /* KARMA_MODULE */
if (alliances!=NULL) {
puts(" - Testen der Allianzbedingungen");
alliancevictory();
p+=10;
add_proc_global(p, &alliancekick, NULL);
}
p+=10;
add_proc_global(p, &age_factions, "Parteienalter++");
add_proc_order(p, K_MAIL, &mail_cmd, false, "Botschaften");
add_proc_order(p, K_CLAIM, &claim_cmd, false, NULL);
p+=10; /* all claims must be done before we can USE */
add_proc_region(p, &enter_1, "Kontaktieren & Betreten (1. Versuch)");
add_proc_order(p, K_USE, &use_cmd, false, "Benutzen");
if (alliances!=NULL) {
p+=10; /* in case USE changes it */
add_proc_global(p, &alliancevictory, "Testen der Allianzbedingungen");
}
puts(" - GM Kommandos");
#ifdef INFOCMD_MODULE
infocommands();
add_proc_global(p, &infocommands, NULL);
#endif
gmcommands();
add_proc_global(p, &gmcommands, "GM Kommandos");
puts(" - Verlassen");
parse(K_LEAVE, leave_cmd, false);
puts(" - Kontakte löschen");
remove_contacts();
p += 10; /* in case it has any effects on allincevictories */
add_proc_order(p, K_LEAVE, &leave_cmd, false, "Verlassen");
if (!nobattle) {
#ifdef KARMA_MODULE
puts(" - Jihad-Angriffe");
jihad_attacks();
p+=10;
add_proc_global(p, &jihad_attacks, "Jihad-Angriffe");
#endif
puts(" - Attackieren");
if (nobattle == false) do_battle();
if (turn == 0) rng_init((int)time(0));
else rng_init(turn);
puts(" - Belagern");
do_siege();
puts(" - Initialisieren des Pools, Reservieren");
init_pool();
puts(" - Kontaktieren, Betreten von Schiffen und Gebäuden (2.Versuch)");
do_misc(false);
puts(" - Folge auf Einheiten ersetzen");
follow_unit();
if (turn == 0) rng_init((int)time(0));
else rng_init(turn);
puts(" - Zerstören, Geben, Rekrutieren, Vergessen");
economics();
remove_empty_units();
puts(" - Gebäudeunterhalt (1. Versuch)");
maintain_buildings(false);
puts(" - Sterben, Neustart");
quit();
parse_restart();
puts(" - Zaubern");
magic();
remove_empty_units();
if (!global.disabled[K_TEACH]) {
puts(" - Lehren");
teaching();
add_proc_region(p, &do_battle, "Attackieren");
}
puts(" - Lernen");
learn();
p+=10; /* after combat, reset rng */
add_proc_global(p, &reset_rng, NULL);
add_proc_region(p, &do_siege, "Belagern");
puts(" - Produzieren, Geldverdienen, Handeln, Anwerben");
produce();
p+=10; /* can't allow reserve before siege (weapons) */
add_proc_region(p, &enter_2, "Kontaktieren & Betreten (2. Versuch)");
add_proc_order(p, K_RESERVE, &reserve_cmd, false, "Reservieren");
add_proc_unit(p, &follow_unit, "Folge auf Einheiten setzen");
puts(" - Kontaktieren, Betreten von Schiffen und Gebäuden (3.Versuch)");
do_misc(true);
p+=10; /* rest rng again before economics */
add_proc_global(p, &reset_rng, NULL);
add_proc_region(p, &economics, "Zerstören, Geben, Rekrutieren, Vergessen");
puts(" - Schiffe sinken");
sinkships();
p+=10;
add_proc_region(p, &maintain_buildings_1, "Gebäudeunterhalt (1. Versuch)");
puts(" - Bewegungen");
movement();
p+=10; /* QUIT fuer sich alleine */
add_proc_global(p, &quit, "Sterben");
add_proc_global(p, &parse_restart, "Neustart");
puts(" - Bewache (an)");
parse(K_GUARD, guard_on_cmd, false);
p+=10;
add_proc_global(p, &magic, "Zaubern");
puts(" - Zufallsbegegnungen");
encounters();
p+=10;
if (!global.disabled[K_TEACH]) {
add_proc_region(p, &teaching, "Lehren");
}
add_proc_order(p, K_STUDY, &learn_cmd, true, "Lernen");
if (turn == 0) rng_init((int)time(0));
else rng_init(turn);
p+=10;
add_proc_global(p, &produce, "Produktion, Handel, Rekruten");
puts(" - Monster fressen und vertreiben Bauern");
monsters_kill_peasants();
p+=10;
add_proc_region(p, &enter_2, "Kontaktieren & Betreten (3. Versuch)");
puts(" - random events");
randomevents();
p+=10;
add_proc_region(p, &sinkships, "Schiffe sinken");
puts(" - newspaper commands");
p+=10;
add_proc_global(p, &movement, "Bewegungen");
p+=10;
add_proc_order(p, K_GUARD, &guard_on_cmd, false, "Bewache (an)");
#ifdef XECMD_MODULE
xecmd();
/* can do together with guard */
add_proc_order(p, K_LEAVE, &xecmd, false, "Zeitung");
#endif
puts(" - regeneration (healing & aura)");
monthly_healing();
regeneration_magiepunkte();
p+=10;
add_proc_global(p, &encounters, "Zufallsbegegnungen");
p+=10;
add_proc_global(p, &reset_rng, NULL);
add_proc_unit(p, &monsters_kill_peasants, "Monster fressen und vertreiben Bauern");
puts(" - Defaults setzen");
defaultorders();
p+=10;
add_proc_global(p, &randomevents, "Zufallsereignisse");
puts(" - Unterhaltskosten, Nachfrage, Seuchen, Wachstum, Auswanderung");
demographics();
p+=10;
add_proc_global(p, &monthly_healing, "Regeneration (HP)");
add_proc_global(p, &regeneration_magiepunkte, "Regeneration (Aura)");
add_proc_global(p, &defaultorders, "Defaults setzen");
add_proc_global(p, &demographics, "Nahrung, Seuchen, Wachstum, Wanderung");
puts(" - Gebäudeunterhalt (2. Versuch)");
maintain_buildings(true);
p+=10;
add_proc_region(p, &maintain_buildings_2, "Gebäudeunterhalt (2. Versuch)");
p+=10;
add_proc_global(p, &reorder, "Einheiten sortieren");
#ifdef KARMA_MODULE
puts(" - Jihads setzen");
karma();
p+=10;
add_proc_global(p, &karma, "Jihads setzen");
#endif
puts(" - Einheiten Sortieren");
reorder();
#ifdef ALLIANCEJOIN
alliancejoin();
p+=10;
add_proc_global(p, &alliancejoin, "Allianzen");
#endif
#ifdef ENEMIES
puts(" - Krieg & Frieden");
declare_war();
p+=10;
add_proc_global(p, &declare_war, "Krieg & Frieden");
#endif
#ifdef HEROES
puts(" - Heldenbeförderung");
parse(K_PROMOTION, promotion_cmd, false);
add_proc_order(p, K_PROMOTION, &promotion_cmd, false, "Heldenbeförderung");
#endif
puts(" - Neue Nummern");
renumber();
p+=10;
add_proc_global(p, &renumber_factions, "Neue Nummern");
add_proc_order(p, K_NUMBER, &renumber_cmd, false, "Neue Nummern (Einheiten)");
process();
/*************************************************/
for (r = regions;r;r=r->next) reorder_owners(r);
puts(" - Attribute altern");

View File

@ -761,13 +761,8 @@ monster_learn(unit *u)
}
void
monsters_kill_peasants(void)
monsters_kill_peasants(unit * u)
{
region *r;
unit *u;
for (r = regions; r; r = r->next) {
for (u = r->units; u; u = u->next) if(!fval(u, UFL_MOVED)) {
if (u->race->flags & RCF_SCAREPEASANTS) {
scared_by_monster(u);
}
@ -778,8 +773,6 @@ monsters_kill_peasants(void)
absorbed_by_monster(u);
}
}
}
}
static boolean
check_overpopulated(unit *u)

View File

@ -29,7 +29,7 @@ extern "C" {
void age_illusion(struct unit *u);
void monsters_kill_peasants(void);
void monsters_kill_peasants(struct unit * u);
void plan_monsters(void);
struct unit *random_unit(const struct region * r);

View File

@ -459,9 +459,8 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
sprintf(buf, (dead == 1) ? person_lost_msg : persons_lost_msg,
dead, unitname(u), unit_dies_msg);
}
if (dead == u->number)
if (dead == u->number) {
/* the poor creature, she dies */
{
*ui = u->next;
destroy_unit(u);
}

View File

@ -439,11 +439,10 @@ teach(unit * u, struct order * ord)
}
/* ------------------------------------------------------------- */
void
learn(void)
int
learn_cmd(unit * u, order * ord)
{
region *r;
unit *u;
region *r = u->region;
int p;
magic_t mtyp;
int l;
@ -451,17 +450,7 @@ learn(void)
/* lernen nach lehren */
for (r = regions; r; r = r->next) {
for (u = r->units; u; u = u->next) {
int days;
if (fval(r->terrain, SEA_REGION)) {
/* sonderbehandlung aller die auf Ozeanen lernen können */
if (u->race!=new_race[RC_AQUARIAN] && !(u->race->flags & RCF_SWIM)) {
continue;
}
}
if (fval(u, UFL_LONGACTION)) continue;
if (get_keyword(u->thisorder) == K_STUDY) {
double multi = 1.0;
attrib * a = NULL;
teaching_info * teach = NULL;
@ -469,42 +458,50 @@ learn(void)
skill_t sk;
int maxalchemy = 0;
if (fval(r->terrain, SEA_REGION)) {
/* sonderbehandlung aller die auf Ozeanen lernen können */
if (u->race!=new_race[RC_AQUARIAN] && !(u->race->flags & RCF_SWIM)) {
return 0;
}
}
if (fval(u, UFL_LONGACTION)) return 0;
if (u->race == new_race[RC_INSECT] && r_insectstalled(r)
&& !is_cursed(u->attribs, C_KAELTESCHUTZ,0)) {
continue;
return 0;
}
if (fval(u, UFL_LONGACTION)) {
cmistake(u, u->thisorder, 52, MSG_PRODUCE);
continue;
cmistake(u, ord, 52, MSG_PRODUCE);
return 0;
}
if ((u->race->flags & RCF_NOLEARN) || fval(u, UFL_WERE)) {
sprintf(buf, "%s können nichts lernen", LOC(default_locale, rc_name(u->race, 1)));
mistake(u, u->thisorder, buf, MSG_EVENT);
continue;
mistake(u, ord, buf, MSG_EVENT);
return 0;
}
init_tokens(u->thisorder);
init_tokens(ord);
skip_token();
sk = getskill(u->faction->locale);
if (sk < 0) {
cmistake(u, u->thisorder, 77, MSG_EVENT);
continue;
cmistake(u, ord, 77, MSG_EVENT);
return 0;
}
if (SkillCap(sk) && SkillCap(sk) <= effskill(u, sk)) {
cmistake(u, u->thisorder, 77, MSG_EVENT);
continue;
cmistake(u, ord, 77, MSG_EVENT);
return 0;
}
/* Hack: Talente mit Malus -99 können nicht gelernt werden */
if (u->race->bonus[sk] == -99) {
cmistake(u, u->thisorder, 77, MSG_EVENT);
continue;
cmistake(u, ord, 77, MSG_EVENT);
return 0;
}
/* snotlings können Talente nur bis T8 lernen */
if (u->race == new_race[RC_SNOTLING]){
if (get_level(u, sk) >= 8){
cmistake(u, u->thisorder, 308, MSG_EVENT);
continue;
cmistake(u, ord, 308, MSG_EVENT);
return 0;
}
}
@ -519,8 +516,8 @@ learn(void)
* studycost darf hier noch nicht durch Akademie erhöht sein */
if (studycost > 0 && !ExpensiveMigrants() && is_migrant(u)) {
sprintf(buf, "Migranten können keine kostenpflichtigen Talente lernen");
mistake(u, u->thisorder, buf, MSG_EVENT);
continue;
mistake(u, ord, buf, MSG_EVENT);
return 0;
}
/* Akademie: */
{
@ -534,8 +531,8 @@ learn(void)
if (sk == SK_MAGIC) {
if (u->number > 1){
cmistake(u, u->thisorder, 106, MSG_MAGIC);
continue;
cmistake(u, ord, 106, MSG_MAGIC);
return 0;
}
if (is_familiar(u)){
/* Vertraute zählen nicht zu den Magiern einer Partei,
@ -549,8 +546,8 @@ learn(void)
{
sprintf(buf, "Es kann maximal %d Magier pro Partei geben",
max_skill(u->faction, SK_MAGIC));
mistake(u, u->thisorder, buf, MSG_EVENT);
continue;
mistake(u, ord, buf, MSG_EVENT);
return 0;
}
mtyp = getmagicskill();
if (mtyp == M_NONE || mtyp == M_GRAU) {
@ -561,16 +558,16 @@ learn(void)
} else {
/* Es wurde kein Magiegebiet angegeben und die Partei
* hat noch keins gewählt. */
cmistake(u, u->thisorder, 178, MSG_MAGIC);
continue;
cmistake(u, ord, 178, MSG_MAGIC);
return 0;
}
}
if (mtyp != u->faction->magiegebiet){
/* Es wurde versucht, ein anderes Magiegebiet zu lernen
* als das der Partei */
if (u->faction->magiegebiet != 0){
cmistake(u, u->thisorder, 179, MSG_MAGIC);
continue;
cmistake(u, ord, 179, MSG_MAGIC);
return 0;
} else {
/* Lernt zum ersten mal Magie und legt damit das
* Magiegebiet der Partei fest */
@ -584,8 +581,8 @@ learn(void)
/* die Partei hat noch kein Magiegebiet gewählt. */
mtyp = getmagicskill();
if (mtyp == M_NONE){
cmistake(u, u->thisorder, 178, MSG_MAGIC);
continue;
cmistake(u, ord, 178, MSG_MAGIC);
return 0;
} else {
/* Legt damit das Magiegebiet der Partei fest */
u->faction->magiegebiet = mtyp;
@ -600,8 +597,8 @@ learn(void)
max_skill(u->faction, SK_ALCHEMY)) {
sprintf(buf, "Es kann maximal %d Alchemisten pro Partei geben",
max_skill(u->faction, SK_ALCHEMY));
mistake(u, u->thisorder, buf, MSG_EVENT);
continue;
mistake(u, ord, buf, MSG_EVENT);
return 0;
}
}
if (studycost) {
@ -614,11 +611,11 @@ learn(void)
money = min(money, studycost);
if (p>0 && money < studycost * u->number) {
#ifdef PARTIAL_STUDY
cmistake(u, u->thisorder, 65, MSG_EVENT);
cmistake(u, ord, 65, MSG_EVENT);
multi = money / (double)(studycost * u->number);
#else
cmistake(u, u->thisorder, 65, MSG_EVENT);
continue; /* nein, Silber reicht auch so nicht */
cmistake(u, ord, 65, MSG_EVENT);
return 0; /* nein, Silber reicht auch so nicht */
#endif
}
}
@ -734,22 +731,16 @@ learn(void)
}
}
}
}
}
}
void
teaching(void)
teaching(region *r)
{
region *r;
/* das sind alles befehle, die 30 tage brauchen, und die in thisorder
* stehen! von allen 30-tage befehlen wird einfach der letzte verwendet
* (dosetdefaults).
*
* lehren vor lernen. */
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
@ -788,4 +779,3 @@ teaching(void)
}
}
}
}

View File

@ -19,8 +19,8 @@
extern "C" {
#endif
extern void teaching(void);
extern void learn(void);
extern void teaching(struct region * r);
extern int learn_cmd(struct unit * u, struct order * ord);
extern magic_t getmagicskill(void);
extern boolean is_migrant(struct unit *u);

View File

@ -3988,23 +3988,19 @@ battle_flee(battle * b)
}
void
do_battle(void)
do_battle(region * r)
{
region *r;
#ifdef SMALL_BATTLE_MESSAGES
char smallbuf[512];
#endif
for (r=regions;r!=NULL;r=r->next) {
battle *b = NULL;
boolean fighting = false;
ship * sh;
building *bu;
/* int *rows; */
fighting = init_battle(r, &b);
if (b==NULL) continue;
if (b==NULL) return;
/* Bevor wir die alliierten hineinziehen, sollten wir schauen, *
* Ob jemand fliehen kann. Dann erübrigt sich das ganze ja
@ -4017,7 +4013,7 @@ do_battle(void)
msg_release(m);
free_battle(b);
free(b);
continue;
return;
}
join_allies(b);
#ifdef HEROES
@ -4090,4 +4086,3 @@ do_battle(void)
free(b);
}
}
}

View File

@ -206,7 +206,7 @@ extern "C" {
extern const troop no_troop;
extern void do_battle(void);
extern void do_battle(struct region * r);
/* for combar spells and special attacks */
enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 };

View File

@ -281,11 +281,8 @@ siege_cmd(unit * u, order * ord)
}
void
do_siege(void)
do_siege(region *r)
{
region *r;
for (r = regions; r; r = r->next) {
if (fval(r->terrain, LAND_REGION)) {
unit *u;
@ -296,7 +293,6 @@ do_siege(void)
}
}
}
}
/* ------------------------------------------------------------- */
static void
@ -1106,26 +1102,6 @@ mayboard(const unit * u, const ship * sh)
}
void
remove_contacts(void)
{
region *r;
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
attrib * a = (attrib *)a_find(u->attribs, &at_contact);
while (a!=NULL &&a->type==&at_contact) {
attrib * ar = a;
a = a->next;
a_remove(&u->attribs, ar);
}
}
}
}
int
leave_cmd(unit * u, struct order * ord)
{
@ -1255,13 +1231,8 @@ enter_building(unit * u, order * ord, int id, boolean report)
}
void
do_misc(boolean lasttry)
do_misc(region * r, boolean lasttry)
{
region *r;
/* lasttry: Fehler nur im zweiten Versuch melden. Sonst konfus. */
for (r = regions; r; r = r->next) {
unit **uptr, *uc;
for (uc = r->units; uc; uc = uc->next) {
@ -1344,4 +1315,3 @@ do_misc(boolean lasttry)
if (*uptr==u) uptr = &u->next;
}
}
}

View File

@ -62,7 +62,7 @@ extern int leave_cmd(struct unit * u, struct order * ord);
extern boolean can_contact(const struct region *r, const struct unit *u, const struct unit *u2);
void do_siege(void);
void do_siege(struct region *r);
void build_road(struct region * r, struct unit * u, int size, direction_t d);
void create_ship(struct region * r, struct unit * u, const struct ship_type * newtype, int size, struct order * ord);
void continue_ship(struct region * r, struct unit * u, int size);
@ -70,8 +70,7 @@ void continue_ship(struct region * r, struct unit * u, int size);
struct building * getbuilding(const struct region * r);
struct ship *getship(const struct region * r);
void remove_contacts(void);
void do_misc(boolean tries);
void do_misc(struct region *r, boolean tries);
void reportevent(struct region * r, char *s);

View File

@ -496,7 +496,7 @@ destroy_building(building * b)
/* Stattdessen nur aus Liste entfernen, aber im Speicher halten. */
choplist(&b->region->buildings, b);
handle_event(&b->attribs, "destroy", b);
handle_event(b->attribs, "destroy", b);
}
extern attrib_type at_icastle;

View File

@ -2539,9 +2539,9 @@ remove_empty_units_in_region(region *r)
faction * f = u->faction;
if (!fval(f, FFL_NOTIMEOUT) && f->age > MaxAge()) set_number(u, 0);
}
if ((u->number == 0 && u->race != new_race[RC_SPELL])
|| (u->age <= 0 && u->race == new_race[RC_SPELL])) {
if ((u->number == 0 && u->race != new_race[RC_SPELL]) || (u->age <= 0 && u->race == new_race[RC_SPELL])) {
destroy_unit(u);
if (u->number==0) remove_unit(u);
}
if (*up==u) up=&u->next;
}

View File

@ -253,7 +253,7 @@ destroyfaction(faction * f)
}
f->alive = 0;
/* no way! f->units = NULL; */
handle_event(&f->attribs, "destroy", f);
handle_event(f->attribs, "destroy", f);
for (ff = factions; ff; ff = ff->next) {
group *g;
ally *sf, *sfn;

View File

@ -124,8 +124,8 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, struct ord
}
#endif
#endif
handle_event(&src->attribs, "give", dest);
handle_event(&dest->attribs, "receive", src);
handle_event(src->attribs, "give", dest);
handle_event(dest->attribs, "receive", src);
#if defined(MUSEUM_MODULE) && defined(TODO)
/* TODO: Einen Trigger für den museums-warden benutzen! */
if (a_find(dest->attribs, &at_warden)) {

View File

@ -2807,6 +2807,7 @@ magic(void)
for (spellrank = 0; spellrank < MAX_SPELLRANK; spellrank++) {
free_castorders(cll[spellrank]);
}
remove_empty_units();
}
const char *

View File

@ -2524,19 +2524,14 @@ movement(void)
* FOLLOW SHIP is a long order, and doesn't need to be treated in here.
*/
void
follow_unit(void)
follow_unit(unit * u)
{
region * r;
for (r=regions;r;r=r->next) {
unit * u;
for (u=r->units;u;u=u->next) {
attrib * a;
region * r = u->region;
attrib * a = NULL;
order * ord;
if (fval(u, UFL_LONGACTION) || LongHunger(u)) continue;
a = a_find(u->attribs, &at_follow);
if (fval(u, UFL_LONGACTION) || LongHunger(u)) return;
for (ord=u->orders;ord;ord=ord->next) {
const struct locale * lang = u->faction->locale;
@ -2546,6 +2541,10 @@ follow_unit(void)
if (getparam(lang) == P_UNIT) {
int id = read_unitid(u->faction, r);
if (a!=NULL) {
a = a_find(u->attribs, &at_follow);
}
if (id>0) {
unit * uf = findunit(id);
if (!a) {
@ -2565,8 +2564,9 @@ follow_unit(void)
unit * u2 = a->data.v;
boolean follow = false;
if (!u2 || u2->region!=r || !cansee(u->faction, r, u2, 0))
continue;
if (!u2 || u2->region!=r || !cansee(u->faction, r, u2, 0)) {
return;
}
switch (get_keyword(u2->thisorder)) {
case K_MOVE:
@ -2602,5 +2602,3 @@ follow_unit(void)
}
}
}
}
}

View File

@ -61,7 +61,7 @@ extern void travelthru(const struct unit * u, struct region * r);
extern struct ship * move_ship(struct ship * sh, struct region * from, struct region * to, struct region_list * route);
extern int walkingcapacity(const struct unit * u);
extern void follow_unit(void);
extern void follow_unit(struct unit * u);
struct building_type;
boolean buildingtype_exists(const struct region * r, const struct building_type * bt);

View File

@ -260,19 +260,10 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
}
void
init_pool(void)
int
reserve_cmd(unit * u, struct order *ord)
{
unit *u;
region *r;
/* Falls jemand diese Listen erweitert hat, muß er auch den R_* enum
* erweitert haben. */
for (r = regions; r; r = r->next) {
for (u = r->units; u; u = u->next) {
order * ord;
for (ord=u->orders; ord; ord=ord->next) {
if (u->number > 0 && (urace(u)->ec_flags & GETITEM) && get_keyword(ord) == K_RESERVE) {
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
int use, count = geti();
const resource_type * rtype;
@ -281,7 +272,7 @@ init_pool(void)
count = geti();
rtype = findresourcetype(getstrtoken(), u->faction->locale);
if (rtype == NULL) continue;
if (rtype == NULL) return 0;
new_set_resvalue(u, rtype, 0); /* make sure the pool is empty */
use = use_pooled(u, rtype, GET_DEFAULT, count);
@ -290,8 +281,6 @@ init_pool(void)
change_resource(u, rtype, use);
}
}
}
}
}
return 0;
}

View File

@ -46,7 +46,7 @@ int change_resource(struct unit * u, const struct resource_type * res, int chang
int get_reservation(const struct unit * u, const struct resource_type * res);
int change_reservation(struct unit * u, const struct resource_type * res, int value);
void init_pool(void);
int reserve_cmd(struct unit *u, struct order *ord);
/** init_pool
* initialisiert den regionalen Pool.

View File

@ -199,7 +199,7 @@ destroy_ship(ship * sh)
}
sunhash(sh);
choplist(&r->ships, sh);
handle_event(&sh->attribs, "destroy", sh);
handle_event(sh->attribs, "destroy", sh);
}
const char *

View File

@ -178,6 +178,17 @@ distribute_items(unit * u)
}
}
void
remove_unit(unit * u)
{
region * r = u->region;
assert(u->number==0);
uunhash(u);
if (r) choplist(&r->units, u);
u->next = udestroy;
udestroy = u;
}
void
destroy_unit(unit * u)
{
@ -261,17 +272,13 @@ destroy_unit(unit * u)
u->race = u->irace = new_race[RC_ZOMBIE];
} else {
if (u->number) set_number(u, 0);
handle_event(&u->attribs, "destroy", u);
handle_event(u->attribs, "destroy", u);
if (r && !fval(r->terrain, SEA_REGION)) {
rsetmoney(r, rmoney(r) + get_money(u));
}
dhash(u->no, u->faction);
u_setfaction(u, NULL);
if (r) leave(r, u);
uunhash(u);
if (r) choplist(&r->units, u);
u->next = udestroy;
udestroy = u;
}
}

View File

@ -189,6 +189,7 @@ extern int get_modifier(const struct unit * u, skill_t sk, int lvl, const struct
/* Einheiten werden nicht wirklich zerstört. */
extern void destroy_unit(struct unit * u);
extern void remove_unit(struct unit * u);
extern void distribute_items(struct unit * u);
/* see resolve.h */

View File

@ -88,17 +88,12 @@ xe_giveballon(unit *u, struct order *ord)
fset(u2, UFL_OWNER);
}
void
xecmd(void)
int
xecmd(unit * u, order * ord)
{
faction *f;
faction *f = u->faction;
for(f=factions; f; f=f->next) {
if (a_find(f->attribs, &at_xontormiaexpress)) {
unit *u;
for(u=f->units; u; u=u->nextF) {
order * ord;
for (ord=u->orders; ord; ord=ord->next) {
if (get_keyword(ord) == K_XE) {
init_tokens(ord);
skip_token();
@ -115,9 +110,7 @@ xecmd(void)
}
}
}
}
}
}
return 0;
}
#endif

View File

@ -18,7 +18,7 @@ extern "C" {
#ifdef XECMD_MODULE
extern attrib_type at_xontormiaexpress;
void xecmd(void);
int xecmd(struct unit * u, struct order * ord);
#endif
#ifdef __cplusplus

View File

@ -200,20 +200,20 @@ add_trigger(struct attrib ** ap, const char * eventname, struct trigger * t)
}
void
handle_event(attrib ** attribs, const char * eventname, void * data)
handle_event(attrib * attribs, const char * eventname, void * data)
{
while (*attribs) {
if ((*attribs)->type==&at_eventhandler) break;
attribs = &(*attribs)->next;
while (attribs) {
if (attribs->type==&at_eventhandler) break;
attribs = attribs->nexttype;
}
while (*attribs && (*attribs)->type==&at_eventhandler) {
handler_info * tl = (handler_info*)(*attribs)->data.v;
while (attribs && attribs->type==&at_eventhandler) {
handler_info * tl = (handler_info*)attribs->data.v;
if (!strcmp(tl->event, eventname)) {
handler_info * tl = (handler_info*)(*attribs)->data.v;
handler_info * tl = (handler_info*)attribs->data.v;
handle_triggers(&tl->triggers, data);
break;
}
attribs = &(*attribs)->next;
attribs = attribs->next;
}
}

View File

@ -58,7 +58,7 @@ extern void add_trigger(struct attrib ** ap, const char * eventname, struct trig
extern void remove_triggers(struct attrib ** ap, const char * eventname, const trigger_type * tt);
extern struct trigger ** get_triggers(struct attrib * ap, const char * eventname);
/* calls handle() for each of these. e.g. used in timeout */
extern void handle_event(struct attrib ** attribs, const char * eventname, void * data);
extern void handle_event(struct attrib * attribs, const char * eventname, void * data);
/* functions for making complex triggers: */
extern void free_triggers(trigger * triggers); /* release all these triggers */

View File

@ -232,7 +232,9 @@ region_remove(region& r)
while (*rp) {
if (*rp==&r) {
while (r.units) {
destroy_unit(r.units);
unit * u = r.units;
destroy_unit(u);
remove_unit(u);
}
*rp = r.next;
#ifdef FAST_CONNECT

View File

@ -1465,6 +1465,7 @@ showunits(region * r)
if (yes_no(0, lbuf, 'n')) {
modified = 1;
destroy_unit(clipunit);
if (clipunit->number==0) remove_unit(clipunit);
clipunit = 0;
clipregion = 0;
for (pline = 0, tmp = eh; tmp != pointer; tmp = tmp->next)