From c722a382a244f1ff43fa0fe6d238ff7613680282 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 25 Mar 2007 00:04:40 +0000 Subject: [PATCH] Generalisierung der Tests fuer lange Befehle, (Insekten, Meermenschen auf See usw.) damit ich die nicht ueberall vergesse. --- src/common/gamecode/economy.c | 31 +++++------- src/common/gamecode/laws.c | 95 ++++++++++++++++++++++------------- src/common/gamecode/study.c | 87 +++++++------------------------- src/common/gamecode/study.h | 2 +- src/common/kernel/alchemy.c | 54 ++++++++++---------- src/common/kernel/race.c | 2 +- 6 files changed, 117 insertions(+), 154 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 6e9258945..8a9dc9104 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1604,20 +1604,20 @@ create_potion(unit * u, const potion_type * ptype, int want) static void create_item(unit * u, const item_type * itype, int want) { - if (fval(itype->rtype, RTF_LIMITED)) { + if (fval(itype->rtype, RTF_LIMITED)) { #if GUARD_DISABLES_PRODUCTION == 1 - if(is_guarded(u->region, u, GUARD_PRODUCE)) { - cmistake(u, u->thisorder, 70, MSG_EVENT); - return; - } + if(is_guarded(u->region, u, GUARD_PRODUCE)) { + cmistake(u, u->thisorder, 70, MSG_EVENT); + return; + } #endif - allocate_resource(u, itype->rtype, want); - } else { - const potion_type * ptype = resource2potion(itype->rtype); - if (ptype!=NULL) create_potion(u, ptype, want); - else if (itype->construction && itype->construction->materials) manufacture(u, itype, want); - else cmistake(u, u->thisorder, 125, MSG_PRODUCE); - } + allocate_resource(u, itype->rtype, want); + } else { + const potion_type * ptype = resource2potion(itype->rtype); + if (ptype!=NULL) create_potion(u, ptype, want); + else if (itype->construction && itype->construction->materials) manufacture(u, itype, want); + else cmistake(u, u->thisorder, 125, MSG_PRODUCE); + } } int @@ -1632,13 +1632,6 @@ make_cmd(unit * u, struct order * ord) const char *s; const struct locale * lang = u->faction->locale; - if (u->number==0) return 0; - - if (fval(r->terrain, SEA_REGION) && u->race != new_race[RC_AQUARIAN]) { - cmistake(u, ord, 242, MSG_INCOME); - return; - } - init_tokens(ord); skip_token(); s = getstrtoken(); diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 6505f5316..3fd3ce0b0 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3688,14 +3688,18 @@ claim_cmd(unit * u, struct order * ord) return 0; } +enum { + PROC_THISORDER = 1<<0, + PROC_LONGORDER = 1<<1 +}; typedef struct processor { struct processor * next; int priority; enum { PR_GLOBAL, PR_REGION_PRE, PR_UNIT, PR_ORDER, PR_REGION_POST } type; + unsigned int flags; union { struct { keyword_t kword; - boolean thisorder; int (*process)(struct unit *, struct order *); } per_order; struct { @@ -3736,13 +3740,13 @@ add_proc(int priority, const char * name, int type) } void -add_proc_order(int priority, keyword_t kword, int (*parser)(struct unit *, struct order *), boolean thisorder, const char * name) +add_proc_order(int priority, keyword_t kword, int (*parser)(struct unit *, struct order *), unsigned int flags, 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; + proc->flags = flags; } } @@ -3827,13 +3831,31 @@ process(void) porder = punit; while (porder && porder->priority==prio && porder->type==PR_ORDER) { order ** ordp = &u->orders; - if (porder->data.per_order.thisorder) ordp = &u->thisorder; + if (porder->flags & PROC_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 (u->number==0) { + ord = NULL; + } else if (porder->flags & PROC_LONGORDER) { + if (u->race == new_race[RC_INSECT] && r_insectstalled(r) && !is_cursed(u->attribs, C_KAELTESCHUTZ,0)) { + ord = NULL; + } else if (LongHunger(u)) { + cmistake(u, ord, 224, MSG_MAGIC); + ord = NULL; + } else if (fval(u, UFL_LONGACTION)) { + cmistake(u, ord, 52, MSG_PRODUCE); + ord = NULL; + } else if (fval(r->terrain, SEA_REGION) && u->race != new_race[RC_AQUARIAN] && !(u->race->flags & RCF_SWIM)) { + cmistake(u, ord, 242, MSG_INCOME); + ord = NULL; + } + } + if (ord) { + porder->data.per_order.process(u, ord); + } } - if (*ordp==ord) ordp=&ord->next; + if (!ord || *ordp==ord) ordp=&(*ordp)->next; } porder = porder->next; } @@ -3876,28 +3898,28 @@ processorders (void) 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); + add_proc_order(p, K_BANNER, &banner_cmd, 0, NULL); + add_proc_order(p, K_EMAIL, &email_cmd, 0, NULL); + add_proc_order(p, K_PASSWORD, &password_cmd, 0, NULL); + add_proc_order(p, K_SEND, &send_cmd, 0, NULL); + add_proc_order(p, K_GROUP, &group_cmd, 0, NULL); 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); + add_proc_order(p, K_QUIT, &quit_cmd, 0, NULL); + add_proc_order(p, K_URSPRUNG, &origin_cmd, 0, NULL); + add_proc_order(p, K_ALLY, &ally_cmd, 0, NULL); + add_proc_order(p, K_PREFIX, &prefix_cmd, 0, NULL); + add_proc_order(p, K_SYNONYM, &synonym_cmd, 0, NULL); + add_proc_order(p, K_SETSTEALTH, &setstealth_cmd, 0, NULL); + add_proc_order(p, K_STATUS, &status_cmd, 0, NULL); + add_proc_order(p, K_COMBAT, &combatspell_cmd, 0, NULL); + add_proc_order(p, K_DISPLAY, &display_cmd, 0, NULL); + add_proc_order(p, K_NAME, &name_cmd, 0, NULL); + add_proc_order(p, K_GUARD, &guard_off_cmd, 0, NULL); + add_proc_order(p, K_RESHOW, &reshow_cmd, 0, NULL); #ifdef KARMA_MODULE - add_proc_order(p, K_WEREWOLF, &setwere_cmd, false, NULL); + add_proc_order(p, K_WEREWOLF, &setwere_cmd, 0, NULL); #endif /* KARMA_MODULE */ if (alliances!=NULL) { @@ -3907,12 +3929,12 @@ processorders (void) 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); + add_proc_order(p, K_MAIL, &mail_cmd, 0, "Botschaften"); + add_proc_order(p, K_CLAIM, &claim_cmd, 0, 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"); + add_proc_order(p, K_USE, &use_cmd, 0, "Benutzen"); if (alliances!=NULL) { p+=10; /* in case USE changes it */ @@ -3925,7 +3947,7 @@ processorders (void) add_proc_global(p, &gmcommands, "GM Kommandos"); p += 10; /* in case it has any effects on allincevictories */ - add_proc_order(p, K_LEAVE, &leave_cmd, false, "Verlassen"); + add_proc_order(p, K_LEAVE, &leave_cmd, 0, "Verlassen"); if (!nobattle) { #ifdef KARMA_MODULE @@ -3941,7 +3963,7 @@ processorders (void) p+=10; /* can't allow reserve before siege (weapons) */ add_proc_region(p, &enter_1, "Kontaktieren & Betreten (2. Versuch)"); - add_proc_order(p, K_RESERVE, &reserve_cmd, false, "Reservieren"); + add_proc_order(p, K_RESERVE, &reserve_cmd, 0, "Reservieren"); add_proc_unit(p, &follow_unit, "Folge auf Einheiten setzen"); p+=10; /* rest rng again before economics */ @@ -3960,13 +3982,14 @@ processorders (void) p+=10; if (!global.disabled[K_TEACH]) { - add_proc_region(p, &teaching, "Lehren"); + add_proc_order(p, K_TEACH, &teach_cmd, PROC_THISORDER|PROC_LONGORDER, "Lehren"); } - add_proc_order(p, K_STUDY, &learn_cmd, true, "Lernen"); + p+=10; + add_proc_order(p, K_STUDY, &learn_cmd, PROC_THISORDER|PROC_LONGORDER, "Lernen"); p+=10; add_proc_global(p, &produce, "Arbeiten, Handel, Rekruten"); - add_proc_order(p, K_MAKE, &make_cmd, true, "Produktion"); + add_proc_order(p, K_MAKE, &make_cmd, PROC_THISORDER|PROC_LONGORDER, "Produktion"); add_proc_postregion(p, &split_allocations, "Produktion II"); p+=10; @@ -3979,10 +4002,10 @@ processorders (void) add_proc_global(p, &movement, "Bewegungen"); p+=10; - add_proc_order(p, K_GUARD, &guard_on_cmd, false, "Bewache (an)"); + add_proc_order(p, K_GUARD, &guard_on_cmd, 0, "Bewache (an)"); #ifdef XECMD_MODULE /* can do together with guard */ - add_proc_order(p, K_LEAVE, &xecmd, false, "Zeitung"); + add_proc_order(p, K_LEAVE, &xecmd, 0, "Zeitung"); #endif p+=10; @@ -4018,9 +4041,9 @@ processorders (void) add_proc_global(p, &declare_war, "Krieg & Frieden"); #endif #ifdef HEROES - add_proc_order(p, K_PROMOTION, &promotion_cmd, false, "Heldenbeförderung"); + add_proc_order(p, K_PROMOTION, &promotion_cmd, 0, "Heldenbeförderung"); #endif - add_proc_order(p, K_NUMBER, &renumber_cmd, false, "Neue Nummern (Einheiten)"); + add_proc_order(p, K_NUMBER, &renumber_cmd, 0, "Neue Nummern (Einheiten)"); p+=10; add_proc_global(p, &renumber_factions, "Neue Nummern"); diff --git a/src/common/gamecode/study.c b/src/common/gamecode/study.c index 1b43b064b..ae3d18fbe 100644 --- a/src/common/gamecode/study.c +++ b/src/common/gamecode/study.c @@ -238,22 +238,33 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, return n; } -static void -teach(unit * u, struct order * ord) +int +teach_cmd(unit * u, struct order * ord) { + static const curse_type * gbdream_ct = NULL; + region * r = u->region; int teaching, i, j, count, academy=0; unit *u2; skill_t sk = NOSKILL; + if (gbdream_ct==0) gbdream_ct = ct_find("gbdream"); + if (gbdream_ct) { + if (get_curse(u->region->attribs, gbdream_ct)) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "gbdream_noteach", "")); + return 0; + } + } + if ((u->race->flags & RCF_NOTEACH) || fval(u, UFL_WERE)) { cmistake(u, ord, 274, MSG_EVENT); - return; + return 0; } if (r->planep && fval(r->planep, PFL_NOTEACH)) { cmistake(u, ord, 273, MSG_EVENT); - return; + return 0; } teaching = u->number * 30 * TEACHNUMBER; @@ -267,7 +278,7 @@ teach(unit * u, struct order * ord) ADDMSG(&u->faction->msgs, msg_message("teachdumb", "teacher amount", u, j)); } - if (teaching == 0) return; + if (teaching == 0) return 0; u2 = 0; @@ -436,6 +447,7 @@ teach(unit * u, struct order * ord) academy = academy/30; /* anzahl gelehrter wochen, max. 10 */ learn_skill(u, sk, academy/30.0/TEACHNUMBER); } + return 0; } /* ------------------------------------------------------------- */ @@ -460,23 +472,6 @@ learn_cmd(unit * u, order * ord) else learn_newskills = 1; } - if (u->number==0) return 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)) { - return 0; - } - if (fval(u, UFL_LONGACTION)) { - 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, ord, buf, MSG_EVENT); @@ -744,51 +739,3 @@ learn_cmd(unit * u, order * ord) } return 0; } - -void -teaching(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. */ - - unit *u; - - for (u = r->units; u; u = u->next) { - - if (u->race == new_race[RC_SPELL] || fval(u, UFL_LONGACTION)) - continue; - - if (fval(r->terrain, SEA_REGION) - && u->race != new_race[RC_AQUARIAN] - && !(u->race->flags & RCF_SWIM)) - continue; - - if (u->race == new_race[RC_INSECT] && r_insectstalled(r) - && !is_cursed(u->attribs, C_KAELTESCHUTZ,0)) { - continue; - } - - switch (get_keyword(u->thisorder)) { - case K_TEACH: - if (fval(u, UFL_LONGACTION)) { - cmistake(u, u->thisorder, 52, MSG_PRODUCE); - continue; - } else { - static const curse_type * gbdream_ct = NULL; - if (gbdream_ct==0) gbdream_ct = ct_find("gbdream"); - if (gbdream_ct) { - if (get_curse(u->region->attribs, gbdream_ct)) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, u->thisorder, "gbdream_noteach", "")); - continue; - } - } - } - teach(u, u->thisorder); - break; - } - } -} diff --git a/src/common/gamecode/study.h b/src/common/gamecode/study.h index 177976d49..0397f1a7a 100644 --- a/src/common/gamecode/study.h +++ b/src/common/gamecode/study.h @@ -19,7 +19,7 @@ extern "C" { #endif -extern void teaching(struct region * r); +extern int teach_cmd(struct unit * u, struct order * ord); extern int learn_cmd(struct unit * u, struct order * ord); extern magic_t getmagicskill(void); diff --git a/src/common/kernel/alchemy.c b/src/common/kernel/alchemy.c index 789eb9b74..3f5f351c7 100644 --- a/src/common/kernel/alchemy.c +++ b/src/common/kernel/alchemy.c @@ -49,41 +49,41 @@ void herbsearch(region * r, unit * u, int max) { - int herbsfound; - const item_type * whichherb; + int herbsfound; + const item_type * whichherb; - if (eff_skill(u, SK_HERBALISM, r) == 0) { - cmistake(u, u->thisorder, 59, MSG_PRODUCE); - return; - } + if (eff_skill(u, SK_HERBALISM, r) == 0) { + cmistake(u, u->thisorder, 59, MSG_PRODUCE); + return; + } - if(is_guarded(r, u, GUARD_PRODUCE)) { - cmistake(u, u->thisorder, 70, MSG_EVENT); - return; - } + if(is_guarded(r, u, GUARD_PRODUCE)) { + cmistake(u, u->thisorder, 70, MSG_EVENT); + return; + } - whichherb = rherbtype(r); - if (whichherb == NULL) { - cmistake(u, u->thisorder, 108, MSG_PRODUCE); - return; - } + whichherb = rherbtype(r); + if (whichherb == NULL) { + cmistake(u, u->thisorder, 108, MSG_PRODUCE); + return; + } - if (max) max = min(max, rherbs(r)); - else max = rherbs(r); - herbsfound = ntimespprob(eff_skill(u, SK_HERBALISM, r) * u->number, - (double)rherbs(r)/100.0L, -0.01L); - herbsfound = min(herbsfound, max); - rsetherbs(r, rherbs(r)-herbsfound); + if (max) max = min(max, rherbs(r)); + else max = rherbs(r); + herbsfound = ntimespprob(eff_skill(u, SK_HERBALISM, r) * u->number, + (double)rherbs(r)/100.0L, -0.01L); + herbsfound = min(herbsfound, max); + rsetherbs(r, rherbs(r)-herbsfound); - if (herbsfound) { - produceexp(u, SK_HERBALISM, u->number); - i_change(&u->items, whichherb, herbsfound); - ADDMSG(&u->faction->msgs, msg_message("herbfound", + if (herbsfound) { + produceexp(u, SK_HERBALISM, u->number); + i_change(&u->items, whichherb, herbsfound); + ADDMSG(&u->faction->msgs, msg_message("herbfound", "unit region amount herb", u, r, herbsfound, whichherb->rtype)); - } else { + } else { ADDMSG(&u->faction->msgs, msg_message("researchherb_none", "unit region", u, u->region)); - } + } } int diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index 2dd284b55..653defc76 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -270,7 +270,7 @@ give_starting_equipment(struct unit *u) boolean r_insectstalled(const region * r) { - return fval(r->terrain, ARCTIC_REGION); + return fval(r->terrain, ARCTIC_REGION); } const char *