lucky_item läuft nur auf GCC, wieder geklammert, und ne alternativimplementation angeangen.

This commit is contained in:
Enno Rehling 2002-04-14 07:57:26 +00:00
parent 09c503ba69
commit 166b347aeb
2 changed files with 42 additions and 23 deletions

View File

@ -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)
{

View File

@ -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;
}
/* 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;
} else if (find->mode >= mode) {
return false;
}
find->mode = mode;
find->disbelieves |= dis;
return true;