From 7cb18e90ea6c0b488c2afbebe1474d6e94ff1e21 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 May 2008 22:03:57 +0000 Subject: [PATCH] http://eressea.upb.de/mantis/view.php?id=1408 "Zauberpatzer - Effektmeldung" - fixed positive message should be negative - fixed ct_find - fixed a few places not checking u->number or u->region - speeding up pool when units have no items. --- src/common/gamecode/spy.c | 60 ++++++++++++++++++++--------------- src/common/kernel/curse.c | 10 ++++-- src/common/kernel/eressea.c | 24 +++++++------- src/common/kernel/magic.c | 2 +- src/common/kernel/pool.c | 3 +- src/common/kernel/unit.c | 2 +- src/common/spells/unitcurse.c | 10 ++++-- src/common/util/xml.c | 2 +- src/eressea/lua/test.cpp | 4 ++- src/res/messages.xml | 9 ++++++ src/res/resources.xml | 4 +-- 11 files changed, 81 insertions(+), 49 deletions(-) diff --git a/src/common/gamecode/spy.c b/src/common/gamecode/spy.c index 44b9372be..e7d920ac3 100644 --- a/src/common/gamecode/spy.c +++ b/src/common/gamecode/spy.c @@ -208,6 +208,38 @@ setwere_cmd(unit *u, struct order * ord) return 0; } +void +set_factionstealth(unit * u, faction * f) +{ + region * lastr = NULL; + /* for all units mu of our faction, check all the units in the region + * they are in, if their visible faction is f, it's ok. use lastr to + * avoid testing the same region twice in a row. */ + unit * mu = u->faction->units; + while (mu!=NULL) { + if (mu->number && mu->region!=lastr) { + unit * ru = mu->region->units; + lastr = mu->region; + while (ru!=NULL) { + if (ru->number) { + faction * fv = visible_faction(f, ru); + if (fv==f) { + if (cansee(f, lastr, ru, 0)) break; + } + } + ru = ru->next; + } + if (ru!=NULL) break; + } + mu = mu->nextF; + } + if (mu!=NULL) { + attrib * a = a_find(u->attribs, &at_otherfaction); + if (!a) a = a_add(&u->attribs, make_otherfaction(f)); + else a->data.v = f; + } +} + int setstealth_cmd(unit * u, struct order * ord) { @@ -281,34 +313,10 @@ setstealth_cmd(unit * u, struct order * ord) a_removeall(&u->attribs, &at_otherfaction); } else { struct faction * f = findfaction(nr); - if(f==NULL) { + if (f==NULL) { cmistake(u, ord, 66, MSG_EVENT); } else { - region * lastr = NULL; - /* for all units mu of our faction, check all the units in the region - * they are in, if their visible faction is f, it's ok. use lastr to - * avoid testing the same region twice in a row. */ - unit * mu = u->faction->units; - while (mu!=NULL) { - unit * ru = mu->region->units; - if (mu->region!=lastr) { - lastr = mu->region; - while (ru!=NULL) { - faction * fv = visible_faction(f, ru); - if (fv==f) { - if (cansee(f, lastr, ru, 0)) break; - } - ru = ru->next; - } - if (ru!=NULL) break; - } - mu = mu->nextF; - } - if (mu!=NULL) { - attrib * a = a_find(u->attribs, &at_otherfaction); - if (!a) a = a_add(&u->attribs, make_otherfaction(f)); - else a->data.v = f; - } + set_factionstealth(u, f); } } } else { diff --git a/src/common/kernel/curse.c b/src/common/kernel/curse.c index b1a6bb580..1b0183541 100644 --- a/src/common/kernel/curse.c +++ b/src/common/kernel/curse.c @@ -311,8 +311,14 @@ ct_find(const char *c) unsigned int hash = tolower(c[0]); cursetype_list * ctl = cursetypes[hash]; while (ctl) { - size_t k = min(strlen(c), strlen(ctl->type->cname)); - if (!strncasecmp(c, ctl->type->cname, k)) return ctl->type; + if (strcmp(c, ctl->type->cname)==0) { + return ctl->type; + } else { + size_t k = min(strlen(c), strlen(ctl->type->cname)); + if (!strncasecmp(c, ctl->type->cname, k)) { + return ctl->type; + } + } ctl = ctl->next; } return NULL; diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index caf99227f..678c0b88d 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -974,23 +974,25 @@ int alliedunit(const unit * u, const faction * f2, int mode) { ally * sf; - const plane * pl = u->region->planep; int automode; + assert(u->region); /* the unit should be in a region, but it's possible that u->number==0 (TEMP units) */ if (u->faction == f2) return mode; - if (u->faction == NULL || f2==NULL) return 0; + if (u->faction != NULL && f2!=NULL) { + plane * pl = u->region->planep; + automode = mode & autoalliance(pl, u->faction, f2); - automode = mode & autoalliance(pl, u->faction, f2); + if (pl!=NULL && (pl->flags & PFL_NOALLIANCES)) + mode = (mode & automode) | (mode & HELP_GIVE); - if (pl!=NULL && (pl->flags & PFL_NOALLIANCES)) - mode = (mode & automode) | (mode & HELP_GIVE); - - sf = u->faction->allies; - if (fval(u, UFL_GROUP)) { - const attrib * a = a_findc(u->attribs, &at_group); - if (a!=NULL) sf = ((group*)a->data.v)->allies; + sf = u->faction->allies; + if (fval(u, UFL_GROUP)) { + const attrib * a = a_findc(u->attribs, &at_group); + if (a!=NULL) sf = ((group*)a->data.v)->allies; + } + return alliedgroup(pl, u->faction, f2, sf, mode); } - return alliedgroup(pl, u->faction, f2, sf, mode); + return 0; } boolean diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index 31d17a6e5..c540e3510 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -1357,7 +1357,7 @@ do_fumble(castorder *co) /* temporärer Stufenverlust */ duration = max(rng_int()%level/2, 2); effect.i = -(level/2); - c = create_curse(u, &u->attribs, ct_find("skill"), (float)level, duration, + c = create_curse(u, &u->attribs, ct_find("skillmod"), (float)level, duration, effect, 1); c->data.i = SK_MAGIC; ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); diff --git a/src/common/kernel/pool.c b/src/common/kernel/pool.c index 753c18318..4fe2a92cc 100644 --- a/src/common/kernel/pool.c +++ b/src/common/kernel/pool.c @@ -188,7 +188,7 @@ get_pooled(const unit * u, const resource_type * rtype, unsigned int mode, int c for (v = r->units; v && usenext) if (u!=v) { int mask; - if (u==v) continue; + if (v->items==NULL && rtype->uget==NULL) continue; if ((urace(v)->ec_flags & GIVEITEM) == 0) continue; if (v->faction == f) { @@ -238,6 +238,7 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) for (v = r->units; use>0 && v!=NULL; v = v->next) if (u!=v) { int mask; if ((urace(v)->ec_flags & GIVEITEM) == 0) continue; + if (v->items==NULL && rtype->uget==NULL) continue; if (v->faction == f) { mask = (mode >> 3) & (GET_SLACK|GET_RESERVE); diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 5b96829b2..b2bda127d 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1211,7 +1211,7 @@ att_modification(const unit *u, skill_t sk) unit * mage = c->magician; /* wir suchen jeweils den größten Bonus und den größten Malus */ if (mod>bonus) { - if (mage==NULL || alliedunit(mage, u->faction, HELP_GUARD)) { + if (mage==NULL || mage->number==0 || alliedunit(mage, u->faction, HELP_GUARD)) { bonus = mod; } } else if (mod < malus) { diff --git a/src/common/spells/unitcurse.c b/src/common/spells/unitcurse.c index 5c544d46b..799d37bad 100644 --- a/src/common/spells/unitcurse.c +++ b/src/common/spells/unitcurse.c @@ -320,20 +320,24 @@ write_skill(struct storage * store, const curse * c) } static message * -cinfo_skill(const void * obj, typ_t typ, const curse *c, int self) +cinfo_skillmod(const void * obj, typ_t typ, const curse *c, int self) { unused(typ); if (self != 0) { unit *u = (unit *)obj; int sk = c->data.i; - return msg_message("curseinfo::skill_1", "unit skill id", u, sk, c->no); + if (c->effect.i>0) { + return msg_message("curseinfo::skill_1", "unit skill id", u, sk, c->no); + } else if (c->effect.i<0) { + return msg_message("curseinfo::skill_2", "unit skill id", u, sk, c->no); + } } return NULL; } static struct curse_type ct_skillmod = { - "skillmod", CURSETYP_NORM, CURSE_SPREADMODULO, M_MEN, cinfo_skill, + "skillmod", CURSETYP_NORM, CURSE_SPREADMODULO, M_MEN, cinfo_skillmod, NULL, read_skill, write_skill }; diff --git a/src/common/util/xml.c b/src/common/util/xml.c index 13c8568f2..930277b55 100644 --- a/src/common/util/xml.c +++ b/src/common/util/xml.c @@ -42,7 +42,7 @@ xml_bvalue(xmlNodePtr node, const char * name, boolean dflt) if (propValue!=NULL) { if (strcmp((const char*)propValue, "no")==0) result = false; else if (strcmp((const char*)propValue, "yes")==0) result = true; - else if (strcmp((const char*)propValue, "false")==0) result = true; + else if (strcmp((const char*)propValue, "false")==0) result = false; else if (strcmp((const char*)propValue, "true")==0) result = true; else if (strcmp((const char*)propValue, "1")==0) { log_warning(("boolean value is '1': %s::%s\n", node->name, name)); diff --git a/src/eressea/lua/test.cpp b/src/eressea/lua/test.cpp index cd4af295b..08c25a4a2 100644 --- a/src/eressea/lua/test.cpp +++ b/src/eressea/lua/test.cpp @@ -19,6 +19,7 @@ using namespace luabind; #include +#include #include static const char * @@ -44,6 +45,7 @@ bind_test(lua_State * L) { module(L, "test")[ def("loc_skill", &loc_getskill), - def("loc_keyword", &loc_getkeyword) + def("loc_keyword", &loc_getkeyword), + def("rng_int", &rng_int) ]; } diff --git a/src/res/messages.xml b/src/res/messages.xml index dd973100d..48c11a878 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -235,6 +235,15 @@ "$unit($unit) scheint $race($race, 0) zu mögen. ($int36($id))" "$unit($unit) seems to like $race($race, 0). ($int36($id))" + + + + + + + "$unit($unit) ist ungewöhnlich ungeschickt in $skill($skill). ($int36($id))" + "$unit($unit) has some troubles with $skill($skill). ($int36($id))" + diff --git a/src/res/resources.xml b/src/res/resources.xml index f40e458a4..45ccd3e07 100644 --- a/src/res/resources.xml +++ b/src/res/resources.xml @@ -329,12 +329,12 @@ - + - +