diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 13fe2d2b0..be0b553cc 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1509,46 +1509,46 @@ get_allocator(const struct resource_type * rtype) return NULL; } -static void +void split_allocations(region * r) { - allocation_list ** p_alist=&allocations; - freset(r, RF_DH); - while (*p_alist) { - allocation_list * alist = *p_alist; - const resource_type * rtype = alist->type; - allocate_function alloc = get_allocator(rtype); - const item_type * itype = resource2item(rtype); - allocation ** p_al = &alist->data; + allocation_list ** p_alist=&allocations; + freset(r, RF_DH); + while (*p_alist) { + allocation_list * alist = *p_alist; + const resource_type * rtype = alist->type; + allocate_function alloc = get_allocator(rtype); + const item_type * itype = resource2item(rtype); + allocation ** p_al = &alist->data; - freset(r, RF_DH); - alloc(rtype, r, alist->data); + freset(r, RF_DH); + alloc(rtype, r, alist->data); - while (*p_al) { - allocation * al = *p_al; - if (al->get) { - assert(itype || !"not implemented for non-items"); - i_change(&al->unit->items, itype, al->get); - produceexp(al->unit, itype->construction->skill, al->unit->number); - fset(r, RF_DH); - } - if (al->want==INT_MAX) al->want = al->get; - if (fval(al, AFL_LOWSKILL)) { - ADDMSG(&al->unit->faction->msgs, - msg_message("produce_lowskill", "unit region resource", - al->unit, al->unit->region, rtype)); - } else { - ADDMSG(&al->unit->faction->msgs, msg_message("produce", + while (*p_al) { + allocation * al = *p_al; + if (al->get) { + assert(itype || !"not implemented for non-items"); + i_change(&al->unit->items, itype, al->get); + produceexp(al->unit, itype->construction->skill, al->unit->number); + fset(r, RF_DH); + } + if (al->want==INT_MAX) al->want = al->get; + if (fval(al, AFL_LOWSKILL)) { + ADDMSG(&al->unit->faction->msgs, + msg_message("produce_lowskill", "unit region resource", + al->unit, al->unit->region, rtype)); + } else { + ADDMSG(&al->unit->faction->msgs, msg_message("produce", "unit region amount wanted resource", - al->unit, al->unit->region, al->get, al->want, rtype)); - } - *p_al=al->next; - free_allocation(al); - } - *p_alist=alist->next; - free(alist); - } - allocations = NULL; + al->unit, al->unit->region, al->get, al->want, rtype)); + } + *p_al=al->next; + free_allocation(al); + } + *p_alist=alist->next; + free(alist); + } + allocations = NULL; } static void @@ -3171,7 +3171,6 @@ produce(void) } } - split_allocations(r); /* Entertainment (expandentertainment) und Besteuerung (expandtax) vor den * Befehlen, die den Bauern mehr Geld geben, damit man aus den Zahlen der * letzten Runde berechnen kann, wieviel die Bauern für Unterhaltung diff --git a/src/common/gamecode/economy.h b/src/common/gamecode/economy.h index 7dbe2fabc..4262a47a8 100644 --- a/src/common/gamecode/economy.h +++ b/src/common/gamecode/economy.h @@ -54,6 +54,7 @@ enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC void maintain_buildings(struct region * r, boolean crash); extern void add_spende(struct faction * f1, struct faction * f2, int betrag, struct region * r); extern int make_cmd(struct unit * u, struct order * ord); +extern void split_allocations(struct region * r); #ifdef __cplusplus } diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 42d2444a3..a82b4b53d 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3690,7 +3690,7 @@ claim_cmd(unit * u, struct order * ord) typedef struct processor { struct processor * next; int priority; - enum { PR_GLOBAL, PR_REGION, PR_UNIT, PR_ORDER } type; + enum { PR_GLOBAL, PR_REGION_PRE, PR_UNIT, PR_ORDER, PR_REGION_POST } type; union { struct { keyword_t kword; @@ -3712,8 +3712,8 @@ typedef struct 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 * +add_proc(int priority, const char * name, int type) { processor **pproc = &processors; processor *proc; @@ -3721,87 +3721,67 @@ add_proc_order(int priority, keyword_t kword, int (*parser)(struct unit *, struc while (*pproc) { proc = *pproc; if (proc->priority>priority) break; - else if (proc->priority==priority && proc->type>=PR_ORDER) break; + else if (proc->priority==priority && proc->type>=type) 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->type = type; proc->name = name; proc->next = *pproc; *pproc = proc; + return proc; +} + +void +add_proc_order(int priority, keyword_t kword, int (*parser)(struct unit *, struct order *), boolean thisorder, const char * name) +{ + processor * proc = add_proc(priority, name, PR_ORDER); + if (proc) { + proc->data.per_order.process = parser; + proc->data.per_order.kword = kword; + proc->data.per_order.thisorder = thisorder; + } } 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; + processor * proc = add_proc(priority, name, PR_GLOBAL); + if (proc) { + proc->data.global.process = process; } - - 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; + processor * proc = add_proc(priority, name, PR_REGION_PRE); + if (proc) { + proc->data.per_region.process = process; } +} - 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_postregion(int priority, void (*process)(region *), const char * name) +{ + processor * proc = add_proc(priority, name, PR_REGION_POST); + if (proc) { + proc->data.per_region.process = process; + } } 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; + processor * proc = add_proc(priority, name, PR_UNIT); + if (proc) { + proc->data.per_unit.process = process; } - - 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; } +/* per priority, execute processors in order from PR_GLOBAL down to PR_ORDER */ void process(void) { @@ -3827,7 +3807,7 @@ process(void) unit *u; processor *pregion = pglobal; - while (pregion && pregion->priority==prio && pregion->type==PR_REGION) { + while (pregion && pregion->priority==prio && pregion->type==PR_REGION_PRE) { pregion->data.per_region.process(r); pregion = pregion->next; } @@ -3856,6 +3836,12 @@ process(void) porder = porder->next; } } + while (pregion && pregion->priority==prio && pregion->type==PR_REGION_POST) { + pregion->data.per_region.process(r); + pregion = pregion->next; + } + if (pregion==NULL || pregion->priority!=prio) continue; + } } } @@ -3971,8 +3957,9 @@ processorders (void) add_proc_order(p, K_STUDY, &learn_cmd, true, "Lernen"); p+=10; - add_proc_order(p, K_MAKE, &make_cmd, true, "Produktion"); add_proc_global(p, &produce, "Arbeiten, Handel, Rekruten"); + add_proc_order(p, K_MAKE, &make_cmd, true, "Produktion"); + add_proc_postregion(p, &split_allocations, "Produktion II"); p+=10; add_proc_region(p, &enter_2, "Kontaktieren & Betreten (3. Versuch)");