diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 2707bc7eb..4ba41dbde 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: economy.c,v 1.4 2001/02/10 10:40:10 enno Exp $ + * $Id: economy.c,v 1.5 2001/02/10 14:17:59 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -711,7 +711,7 @@ giveunit(region * r, unit * u, unit * u2, strlist * S) new_message(u2->faction, "give%u:unit%u:target%r:region%X:resource%i:amount", u?&u_peasants:(cansee(u2->faction, u->region, u, 0)?u:NULL), u2, u->region, r_unit, 1)); - set_faction(u, u2->faction); + u_setfaction(u, u2->faction); u2->faction->newbies += n; /* "Ich gebe einer Partei eine Einheit, die den Befehl hat, effektiv diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 17e0c785b..05a9dc7ba 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: laws.c,v 1.9 2001/02/10 10:40:10 enno Exp $ + * $Id: laws.c,v 1.10 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -2527,7 +2527,7 @@ new_units (void) u2 = createunitid(r, u->faction, 0, u->faction->race, alias, name); a_add(&u2->attribs, a_new(&at_alias))->data.i = alias; - set_faction(u2, u->faction); + u_setfaction(u2, u->faction); u2->building = u->building; u2->ship = u->ship; diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index 2156ca850..05f615b5a 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: randenc.c,v 1.8 2001/02/10 14:07:29 corwin Exp $ + * $Id: randenc.c,v 1.9 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -519,7 +519,7 @@ chaos(region * r) sprintf(buf, "%s scheint von einer seltsamen Krankheit befallen.", unitname(u)); addmessage(0, u->faction, buf, MSG_EVENT, ML_IMPORTANT); - set_faction(u, findfaction(MONSTER_FACTION)); + u_setfaction(u, findfaction(MONSTER_FACTION)); u->race = RC_GHOUL; } } diff --git a/src/common/kernel/combatspells.c b/src/common/kernel/combatspells.c index 08b2bbf91..4ead8a3bb 100644 --- a/src/common/kernel/combatspells.c +++ b/src/common/kernel/combatspells.c @@ -1542,7 +1542,7 @@ sp_undeadhero(fighter * fi, int level, int force, spell * sp) du->race = RC_UNDEAD; setguard(du, GUARD_NONE); - set_faction(du,mage->faction); + u_setfaction(du,mage->faction); if (fval(mage, FL_PARTEITARNUNG)) fset(du, FL_PARTEITARNUNG); df->alive = du->number; diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index a7061b7cb..22a830443 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: eressea.c,v 1.11 2001/02/10 10:40:11 enno Exp $ + * $Id: eressea.c,v 1.12 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -629,59 +629,6 @@ eff_stealth (const unit * u, const region * r) return e; } -void -set_faction (unit * u, faction * f) -{ - int cnt = u->number; - if (u->faction==f) return; -#ifndef NDEBUG - assert(u->debug_number == u->number); -#endif - if (u->faction) { - set_number(u, 0); - join_group(u, NULL); - } - if (u->prevF) u->prevF->nextF = u->nextF; - else if (u->faction) { - assert(u->faction->units==u); - u->faction->units = u->nextF; - } - if (u->nextF) u->nextF->prevF = u->prevF; - - if (f!=NULL) { - u->nextF = f->units; - f->units = u; - } - else u->nextF = NULL; - if (u->nextF) u->nextF->prevF = u; - u->prevF = NULL; - - u->faction = f; - if (cnt && f) set_number(u, cnt); -} - -/* vorsicht Sprüche können u->number == 0 (RS_FARVISION) haben! */ -void -set_number (unit * u, int count) -{ - assert (count >= 0); -#ifndef NDEBUG - assert (u->debug_number == u->number); - assert (u->faction != 0 || u->number > 0); -#endif - if (u->faction && u->race != u->faction->race && !nonplayer(u) - && u->race != RC_SPELL && u->race != RC_SPECIAL - && !(is_cursed(u->attribs, C_SLAVE, 0))){ - u->faction->num_migrants += count - u->number; - } - - u->faction->num_people += count - u->number; - u->number = count; -#ifndef NDEBUG - u->debug_number = count; -#endif -} - void scale_number (unit * u, int n) { @@ -1577,7 +1524,7 @@ createunitid(region * r1, faction * f, int number, race_t race, int id, const ch unit * u = calloc(1, sizeof(unit)); assert(f->alive); - set_faction(u, f); + u_setfaction(u, f); set_string(&u->thisorder, ""); set_string(&u->lastorder, keywords[K_WORK]); u_seteffstealth(u, -1); diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index d2bc14e00..b5616365e 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: eressea.h,v 1.14 2001/02/10 13:20:09 enno Exp $ + * $Id: eressea.h,v 1.15 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1015,11 +1015,8 @@ char * set_string(char **s, const char *neu); int check_option(struct faction * f, int option); -void set_number(struct unit * u, int number); - /* Anzahl Personen in einer Einheit festlegen. NUR (!) mit dieser Routine, * sonst großes Unglück. Durch asserts an ein paar Stellen abgesichert. */ -void set_faction(struct unit * u, struct faction * f); void verify_data(void); void stripfaction(struct faction * f); @@ -1039,7 +1036,6 @@ struct region *lastregion(struct faction * f); #define f_koor_x(x) x-f->ursprung[0] #define f_koor_y(y) y-f->ursprung[1] -void set_faction(struct unit * u, struct faction * f); void inituhash(void); void uhash(struct unit * u); void uunhash(struct unit * u); diff --git a/src/common/kernel/item.c b/src/common/kernel/item.c index 3f9ddb6df..0dec1ec9d 100644 --- a/src/common/kernel/item.c +++ b/src/common/kernel/item.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: item.c,v 1.7 2001/02/10 13:20:09 enno Exp $ + * $Id: item.c,v 1.8 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1772,7 +1772,7 @@ use_bloodpotion(struct unit *u, const struct potion_type *ptype, const char *cmd /* bekommt nicht: */ cmistake(u, cmd, 165, MSG_EVENT); u->race = RC_GHOUL; - set_faction(u, findfaction(MONSTER_FACTION)); + u_setfaction(u, findfaction(MONSTER_FACTION)); } return 0; } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index af16f1bba..f4b045f56 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: save.c,v 1.12 2001/02/10 12:50:29 corwin Exp $ + * $Id: save.c,v 1.13 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1202,7 +1202,7 @@ readgame(boolean backup) } else { n = ri(F); } - set_faction(u, findfaction(n)); + u_setfaction(u, findfaction(n)); } uhash(u); rds(F, &u->name); @@ -1227,7 +1227,7 @@ readgame(boolean backup) } else { n = ri(F); } - set_faction(u, findfaction(n)); + u_setfaction(u, findfaction(n)); u->race = typus2race(oldtypus); u->irace = typus2race(olditypus); @@ -1273,7 +1273,7 @@ readgame(boolean backup) u->race = (race_t) ri(F); u->irace = (race_t) ri(F); if (global.data_versionfaction == NULL) fprintf(stderr,"\nEinheit %s hat faction==NULL\n",unitname(u)); diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index d160a4784..0f6dd06d4 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: spell.c,v 1.8 2001/02/04 09:46:47 corwin Exp $ + * $Id: spell.c,v 1.9 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -3827,7 +3827,7 @@ sp_charmingsong(castorder *co) create_curse(mage, &target->attribs, C_SLAVE, 0, force, duration, 0, 0); /* setze Partei um und lösche langen Befehl aus Sicherheitsgründen */ - set_faction(target,mage->faction); + u_setfaction(target,mage->faction); set_string(&target->thisorder, ""); /* setze Parteitarnung, damit nicht sofort klar ist, wer dahinter @@ -4138,7 +4138,7 @@ sp_migranten(castorder *co) addmessage(0, mage->faction, buf, MSG_MAGIC, ML_MISTAKE); return 0; } - set_faction(target,mage->faction); + u_setfaction(target,mage->faction); set_string(&target->thisorder, ""); /* Erfolg melden */ diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 66be961aa..acaa02bc9 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: unit.c,v 1.4 2001/02/03 13:45:32 enno Exp $ + * $Id: unit.c,v 1.5 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -127,14 +127,14 @@ destroy_unit(unit * u) } } if (zombie) { - set_faction(u, findfaction(MONSTER_FACTION)); + u_setfaction(u, findfaction(MONSTER_FACTION)); scale_number(u, 1); u->race = u->irace = RC_ZOMBIE; } else { if (r && rterrain(r) != T_OCEAN) rsetmoney(r, rmoney(r) + get_money(u)); dhash(u->no, u->faction); - set_faction(u, NULL); + u_setfaction(u, NULL); if (r) leave(r, u); uunhash(u); if (r) choplist(&r->units, u); @@ -749,3 +749,56 @@ struct building * inside_building(const struct unit * u) } return NULL; } + +void +u_setfaction(unit * u, faction * f) +{ + int cnt = u->number; + if (u->faction==f) return; +#ifndef NDEBUG + assert(u->debug_number == u->number); +#endif + if (u->faction) { + set_number(u, 0); + join_group(u, NULL); + } + if (u->prevF) u->prevF->nextF = u->nextF; + else if (u->faction) { + assert(u->faction->units==u); + u->faction->units = u->nextF; + } + if (u->nextF) u->nextF->prevF = u->prevF; + + if (f!=NULL) { + u->nextF = f->units; + f->units = u; + } + else u->nextF = NULL; + if (u->nextF) u->nextF->prevF = u; + u->prevF = NULL; + + u->faction = f; + if (cnt && f) set_number(u, cnt); +} + +/* vorsicht Sprüche können u->number == 0 (RS_FARVISION) haben! */ +void +set_number (unit * u, int count) +{ + assert (count >= 0); +#ifndef NDEBUG + assert (u->debug_number == u->number); + assert (u->faction != 0 || u->number > 0); +#endif + if (u->faction && u->race != u->faction->race && !nonplayer(u) + && u->race != RC_SPELL && u->race != RC_SPECIAL + && !(is_cursed(u->attribs, C_SLAVE, 0))){ + u->faction->num_migrants += count - u->number; + } + + u->faction->num_people += count - u->number; + u->number = count; +#ifndef NDEBUG + u->debug_number = count; +#endif +} diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index 305754507..052e1ef67 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: unit.h,v 1.3 2001/02/03 13:45:33 enno Exp $ + * $Id: unit.h,v 1.4 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -183,4 +183,7 @@ extern struct building * inside_building(const struct unit * u); /* cleanup code for this module */ extern void free_units(void); extern struct faction * dfindhash(int i); +extern void u_setfaction(struct unit * u, struct faction * f); +/* vorsicht Sprüche können u->number == 0 (RS_FARVISION) haben! */ +extern void set_number(struct unit * u, int count); #endif diff --git a/src/eressea-6.opt b/src/eressea-6.opt index 9fdc89f32..c066ec286 100644 Binary files a/src/eressea-6.opt and b/src/eressea-6.opt differ diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index eba056054..5c29caf88 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: korrektur.c,v 1.18 2001/02/10 13:20:09 enno Exp $ + * $Id: korrektur.c,v 1.19 2001/02/10 14:18:00 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -237,7 +237,7 @@ static void add_magrathea(void) { unit * tans = ufindhash(atoi36("tans")); - if (tans) set_faction(tans, findfaction(999)); + if (tans) u_setfaction(tans, findfaction(999)); } #endif @@ -880,7 +880,7 @@ give_questling(void) add_message(&u1->faction->msgs, new_message(u1->faction, "give%u:unit%u:target%r:region%X:resource%i:amount", u1, u2, u1->region, r_unit, 1)); - set_faction(u1, u2->faction); + u_setfaction(u1, u2->faction); add_message(&u2->faction->msgs, new_message(u1->faction, "give%u:unit%u:target%r:region%X:resource%i:amount", u1, u2, u1->region, r_unit, 1)); diff --git a/src/eressea/old/trigger.c b/src/eressea/old/trigger.c index deb4f9b1d..32c55ea45 100644 --- a/src/eressea/old/trigger.c +++ b/src/eressea/old/trigger.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: trigger.c,v 1.2 2001/02/03 13:45:34 enno Exp $ + * $Id: trigger.c,v 1.3 2001/02/10 14:18:01 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -523,7 +523,7 @@ do_actions(void) faction *f; assert(act->typ == TYP_UNIT); f = findfaction_unique_id(act->i[0]); - set_faction((unit*)act->obj, f); + u_setfaction((unit*)act->obj, f); break; } case AC_CREATEUNIT:{