From 8276a63c1e1995706747903fb29b88c374812263 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 8 Sep 2005 19:03:42 +0000 Subject: [PATCH] =?UTF-8?q?http://eressea.upb.de/mantis/view.php=3Fid=3D68?= =?UTF-8?q?0=20Einheit=20verhungert=20und=20Gegenst=C3=A4nde=20gehen=20ver?= =?UTF-8?q?loren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aauflösen von Einheiten vereinheitlicht, und einige alte #defines mitsamt Code entfernt. --- src/common/gamecode/laws.c | 27 --------------- src/common/gamecode/report.c | 7 ---- src/common/kernel/eressea.h | 4 --- src/common/kernel/faction.c | 61 +-------------------------------- src/common/kernel/unit.c | 66 ++++++++++++++++++++++++++++++++++-- src/common/kernel/unit.h | 3 +- src/common/modules/arena.c | 8 ++--- src/mapper/map_modify.c | 22 +----------- src/mapper/map_units.c | 4 --- src/res/en/strings.xml | 2 +- 10 files changed, 72 insertions(+), 132 deletions(-) diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 3a4e4f6c5..baf618f4a 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -896,7 +896,6 @@ demographics(void) if (rterrain(r) != T_OCEAN) { /* die Nachfrage nach Produkten steigt. */ -#ifdef NEW_ITEMS struct demand * dmd; if (r->land) for (dmd=r->land->demands;dmd;dmd=dmd->next) { if (dmd->value>0 && dmd->value < MAXDEMAND) { @@ -905,24 +904,6 @@ demographics(void) if (rand() % 100 < rise) dmd->value++; } } -#else - item_t n; - for (n = 0; n != MAXLUXURIES; n++) { - int d = rdemand(r, n); - if (d > 0 && d < MAXDEMAND) { - if (buildingtype_exists(r, &bt_harbour)) { - if (rand() % 100 < DMRISEHAFEN) { - d++; - } - } else { - if (rand() % 100 < DMRISE) { - d++; - } - } - } - rsetdemand(r, n, (char)d); - } -#endif /* Seuchen erst nachdem die Bauern sich vermehrt haben * und gewandert sind */ @@ -2737,7 +2718,6 @@ instant_orders(void) for (f = factions; f; f = f->next) { attrib *a; -#ifdef NEW_ITEMS a = a_find(f->attribs, &at_showitem); while(a!=NULL) { const item_type * itype = (const item_type *)a->data.v; @@ -2750,13 +2730,6 @@ instant_orders(void) a = n; } else a = a->nexttype; } -#else - a = a_find(f->attribs, &at_show_item_description); - while (a!=NULL) { - display_item(f, NULL, (item_t)(a->data.i)); - a_remove(&f->attribs, a); - } -#endif } parse(K_GROUP, group_cmd, false); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 85fbae3c3..793d41058 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1178,11 +1178,7 @@ describe(FILE * F, const region * r, int partial, faction * f) if (rhorses(r)) { bufp += sprintf(bufp, ", %d ", rhorses(r)); -#ifdef NEW_ITEMS bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_HORSE], (rhorses(r)>1)?GR_PLURAL:0))); -#else - bufp += strxcpy(bufp, itemdata[I_HORSE].name[rhorses(r) > 1]); -#endif } strcpy(bufp++, "."); @@ -1916,9 +1912,6 @@ static int report(FILE *F, faction * f, struct seen_region ** seen, const faction_list * addresses, const char * pzTime) { -#ifndef NEW_ITEMS - potion_t potion; -#endif int flag = 0; char ch; int dh; diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index fa7a2454f..028180c60 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -205,10 +205,6 @@ extern void read_laen(struct region * r, int laen); #define MAXPEASANTS_PER_AREA 10 -#if !defined(NEW_ITEMS) -# define NEW_ITEMS -#endif - /* So lange kann die Partei nicht angegriffen werden */ #undef STUDY_IF_NOT_WORKING diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index 849e706ce..335fe3e46 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -191,66 +191,7 @@ destroyfaction(faction * f) for (u=f->units;u;u=u->nextF) { region * r = u->region; - unit * au; - int number = 0; - struct friend { - struct friend * next; - int number; - faction * faction; - unit * unit; - } * friends = NULL; - for (au=r->units;au;au=au->next) if (au->faction!=f) { - if (alliedunit(u, au->faction, HELP_ALL)) { - struct friend * nf, ** fr = &friends; - - while (*fr && (*fr)->faction->nofaction->no) fr = &(*fr)->next; - nf = *fr; - if (nf==NULL || nf->faction!=au->faction) { - nf = calloc(sizeof(struct friend), 1); - nf->next = *fr; - nf->faction = au->faction; - nf->unit = au; - *fr = nf; - } - nf->number += au->number; - number += au->number; - } - } - if (friends && number) { - struct friend * nf = friends; - while (nf) { - unit * u2 = nf->unit; -#ifdef NEW_ITEMS - item * itm = u->items; - while(itm){ - const item_type * itype = itm->type; - item * itn = itm->next; - int n = itm->number; - n = n * nf->number / number; - if (n>0) { - i_change(&u->items, itype, -n); - i_change(&u2->items, itype, n); - } - itm = itn; - } -#else - resource_t res; - for (res = 0; res <= R_SILVER; ++res) { - int n = get_resource(u, res); - if (n<=0) continue; - n = n * nf->number / number; - if (n<=0) continue; - change_resource(u, res, -n); - change_resource(u2, res, n); - } -#endif - number -= nf->number; - nf = nf->next; - free(friends); - friends = nf; - } - friends = NULL; - } + distribute_items(u); if (rterrain(r) != T_OCEAN && !!playerrace(u->race)) { const race * rc = u->race; int p = rpeasants(u->region); diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 541b7242f..189b12807 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -114,8 +114,69 @@ dfindhash(int no) unit * udestroy = NULL; -#undef DESTROY -/* Einheiten werden nicht wirklich zerstört. */ +/** distributes a unit's posessions to friendly units +* this happens when units die and no own units are in the region +*/ +void +distribute_items(unit * u) +{ + faction * f = u->faction; + region * r = u->region; + unit * au; + int number = 0; + struct friend { + struct friend * next; + int number; + faction * faction; + unit * unit; + } * friends = NULL; + + if (u->items==NULL) return; + + for (au=r->units;au;au=au->next) if (au->faction!=f) { + if (alliedunit(u, au->faction, HELP_ALL)) { + struct friend * nf, ** fr = &friends; + + while (*fr && (*fr)->faction->nofaction->no) fr = &(*fr)->next; + nf = *fr; + if (nf==NULL || nf->faction!=au->faction) { + nf = malloc(sizeof(struct friend)); + nf->next = *fr; + nf->faction = au->faction; + nf->unit = au; + nf->number = 0; + *fr = nf; + } + nf->number += au->number; + number += au->number; + } + } + + if (friends && number) { + struct friend * nf = friends; + while (nf) { + unit * u2 = nf->unit; + item * itm = u->items; + while (itm!=NULL) { + const item_type * itype = itm->type; + item * itn = itm->next; + int n = itm->number; + n = n * nf->number / number; + if (n>0) { + i_change(&u->items, itype, -n); + i_change(&u2->items, itype, n); + } + itm = itn; + } + number -= nf->number; + nf = nf->next; + free(friends); + friends = nf; + } + friends = NULL; + } +} + void destroy_unit(unit * u) { @@ -156,6 +217,7 @@ destroy_unit(unit * u) } if (*p_item == item) p_item=&item->next; } + if (u->items) distribute_items(u); } /* Wir machen das erst nach dem Löschen der Items. Der Klon darf keine diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index 04661fa61..adb3f0391 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -186,10 +186,9 @@ extern int eff_skill_study(const struct unit * u, skill_t sk, const struct regio extern int get_modifier(const struct unit * u, skill_t sk, int lvl, const struct region * r, boolean noitem); -#undef DESTROY - /* Einheiten werden nicht wirklich zerstört. */ extern void destroy_unit(struct unit * u); +extern void distribute_items(struct unit * u); /* see resolve.h */ extern void * resolve_unit(variant data); diff --git a/src/common/modules/arena.c b/src/common/modules/arena.c index fc55c4c40..8f2c4518f 100644 --- a/src/common/modules/arena.c +++ b/src/common/modules/arena.c @@ -139,9 +139,9 @@ enter_arena(unit * u, const item_type * itype, int amount, order * ord) if (get_level(u, sk)>1 && enter_fail(u)) return -1; } for (u2=r->units;u2;u2=u2->next) if (u2->faction==u->faction) break; -#ifdef NEW_ITEMS - assert(!"not implemented"); -#else + + assert(!"not implemented"); +/* for (res=0;res!=MAXRESOURCES;++res) if (res!=R_SILVER && res!=R_ARENA_GATE && (is_item(res) || is_herb(res) || is_potion(res))) { int x = get_resource(u, res); if (x) { @@ -152,7 +152,7 @@ enter_arena(unit * u, const item_type * itype, int amount, order * ord) else if (enter_fail(u)) return -1; } } -#endif +*/ if (get_money(u) > fee) { if (u2) change_money(u2, get_money(u) - fee); else if (enter_fail(u)) return -1; diff --git a/src/mapper/map_modify.c b/src/mapper/map_modify.c index de8afcaa1..ec1c49f6c 100644 --- a/src/mapper/map_modify.c +++ b/src/mapper/map_modify.c @@ -1236,7 +1236,7 @@ shift(void) t_queue_len--; return r; } -#ifdef NEW_ITEMS + static const luxury_type * tradegood = NULL; void @@ -1260,22 +1260,6 @@ settg(region *r) } } -#else -int tradegood; - -void -settg(region *r) -{ - int i; - - for(i=0; i <= MAXLUXURIES; i++) { - rsetdemand(r, i, 1+rand()%5); - } - rsetdemand(r, tradegood, 0); - if(rand()%100 < 20) tradegood = rand()%7; -} -#endif - boolean Create_Island(region *r, int * n, terrain_t t, int x, int y) { if (!r) return false; @@ -1303,11 +1287,7 @@ create_island(region *r, int n, terrain_t t) for(r2=regions; r2; r2=r2->next) { r2->msgs = (void *)0; } -#ifdef NEW_ITEMS tradegood = NULL; -#else - tradegood = rand()%7; -#endif terraform(r,t); if(r->land) settg(r); r->msgs = (void *)(rand()%6); diff --git a/src/mapper/map_units.c b/src/mapper/map_units.c index bd568e489..8c1c3569e 100644 --- a/src/mapper/map_units.c +++ b/src/mapper/map_units.c @@ -179,7 +179,6 @@ input_string(const char * text, char * result, size_t len) { return res; } -#ifdef NEW_ITEMS static boolean i_modif = false; static void @@ -200,7 +199,6 @@ chg_item(selection * s, void * data) { s->str = strdup(buf); } } -#endif boolean modify_items(unit * u) @@ -456,9 +454,7 @@ modify_unit(region * r, unit * modunit) int q, a, x, y, zt, zg; char modif = 0; int at; -#ifdef NEW_ITEMS const item * itm; -#endif wclear(mywin); sprintf(buf, "< Einheit modifizieren: %s,%s >", diff --git a/src/res/en/strings.xml b/src/res/en/strings.xml index fef88b9b7..048119287 100644 --- a/src/res/en/strings.xml +++ b/src/res/en/strings.xml @@ -1608,7 +1608,7 @@ damage - Your faction has been eliminated. We hope you had a good time anyways, and encourage you to sign up you for another game. + Your faction has been eliminated. We hope that you had a good time, and if you liked the game, you should sign up and play again.