From 166b347aebd40cd0914aa07e5e1ba058ee116b21 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Apr 2002 07:57:26 +0000 Subject: [PATCH] =?UTF-8?q?lucky=5Fitem=20l=C3=A4uft=20nur=20auf=20GCC,=20?= =?UTF-8?q?wieder=20geklammert,=20und=20ne=20alternativimplementation=20an?= =?UTF-8?q?geangen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/luck.c | 37 ++++++++++++++++++++++++++++++++---- src/common/gamecode/report.c | 28 +++++++++------------------ 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/common/gamecode/luck.c b/src/common/gamecode/luck.c index 7861c17cf..5bc2b2fd2 100644 --- a/src/common/gamecode/luck.c +++ b/src/common/gamecode/luck.c @@ -75,6 +75,11 @@ lucky_silver(const unit *u) "lucky_item%u:unit%X:item%d:amount", u, i_silver->rtype, max)); } +typedef struct luckyitem { + const char * name; + int weight; /* weighting the item */ +} luckyitem; + static void lucky_item(const unit *u) { @@ -82,9 +87,10 @@ lucky_item(const unit *u) item_type *itype; int amount; int luck = fspecial(u->faction, FS_LUCKY); - const int n_items = 35; +#if defined(__GNUC__) && !defined(__STDC__) + const int nitems = 35; /* ordered rougly by value */ - item_type *it_list[] = { + item_type *it_list[nitems] = { olditemtype[I_RUSTY_SWORD], olditemtype[I_RUSTY_SHIELD], olditemtype[I_RUSTY_CHAIN_MAIL], @@ -122,14 +128,34 @@ lucky_item(const unit *u) olditemtype[I_LAENSHIELD], olditemtype[I_LAENCHAIN], }; - +#else + /* Das ist schöner so, denke ich... */ + static int nitems = 0; + static int maxweight = 0; + struct luckyitem it_list[] = { + { "mallorn", 1 }, + { NULL, 0 } + }; + if (nitems==0) { + while (it_list[nitems].name) { + maxweight +=it_list[nitems].weight; + ++nitems; + } + } + /* weight is unused */ + r = rand()%nitems; +#endif do { - r = rand()%n_items; + r = rand()%nitems; if(r > max) max = r; i++; } while(i <= luck); +#if defined(__GNUC__) && !defined(__STDC__) itype = it_list[r]; +#else + itype = it_find(it_list[r].name); +#endif if(luck) amount = 10 + rand()%(luck*40) + rand()%(luck*40); @@ -145,6 +171,7 @@ lucky_item(const unit *u) static void lucky_magic_item(const unit *u) { +#if defined(__GNUC__) && !defined(__STDC__) item_type *itype; int amount; int luck = fspecial(u->faction, FS_LUCKY); @@ -172,8 +199,10 @@ lucky_magic_item(const unit *u) add_message(&u->faction->msgs, new_message(u->faction, "lucky_item%u:unit%X:item%d:amount", u, itype->rtype, amount)); +#endif } + static void lucky_event(const faction *f) { diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index e711db3be..b7eaba386 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -2552,32 +2552,22 @@ static boolean add_seen(const struct region * r, unsigned char mode, boolean dis) { seen_region * find = find_seen(r); - if (find) { - if (find->mode >= mode) return false; - if (find->mode>see_neighbour || find->next==NULL) { - find->mode = mode; - find->disbelieves |= dis; - return true; - } - /* take it out the list, so it can get processed again */ - find->next->prev = find->prev; - if (find->prev) find->prev->next = find->next; - else seen = find->next; - } else { + if (find==NULL) { int index = abs((r->x & 0xffff) + ((r->y) << 16)) % MAXSEEHASH; - if (!reuse) reuse = (seen_region*)calloc(1, sizeof(seen_region)); + if (!reuse) reuse = (seen_region*)calloc(1, sizeof(struct seen_region)); *append = find = reuse; reuse = reuse->next; find->nextHash = seehash[index]; seehash[index] = find; find->r = r; + if (last) last->next = find; + find->next = NULL; + find->prev = last; + last = find; + append = &last->next; + } else if (find->mode >= mode) { + return false; } - /* put it at the end of the list, where the unprocessed nodes are */ - if (last) last->next = find; - find->next = NULL; - find->prev = last; - last = find; - append = &last->next; find->mode = mode; find->disbelieves |= dis; return true;