/* vi: set ts=2: * * * Eressea PB(E)M host Copyright (C) 1998-2003 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de) * Enno Rehling (enno@eressea-pbem.de) * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) * * based on: * * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace * Atlantis v1.7 Copyright 1996 by Alex Schröder * * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. * This program may not be sold or used commercially without prior written * permission from the authors. */ #include #include "eressea.h" #include "luck.h" /* attributes includes */ #include #include #include "economy.h" #include "randenc.h" /* kernel include */ #include #include #include #include #include #include #include #include #include /* util includes */ #include #include /* libc includes */ #include #include #include #include #include #define STANDARD_LUCK 0 extern struct item_type *i_silver; static void lucky_silver(const unit *u) { int i = 0, r, max = 0; int luck = fspecial(u->faction, FS_LUCKY); do { r = 1 + rand()%(10000*(luck+STANDARD_LUCK)); if(r > max) max = r; i++; } while(i <= luck); i_change(&((unit *)u)->items, i_silver, max); add_message(&u->faction->msgs, new_message(u->faction, "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) { int i = 0, r, max = 0; item_type *itype; int amount; int luck = fspecial(u->faction, FS_LUCKY); /* 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; do { r = rand()%nitems; if(r > max) max = r; i++; } while(i <= luck); itype = it_find(it_list[r].name); if(luck) amount = 10 + rand()%(luck*40) + rand()%(luck*40); else amount = 5 + rand()%10 +rand()%10; i_change(&((unit *)u)->items, itype, amount); add_message(&u->faction->msgs, new_message(u->faction, "lucky_item%u:unit%X:item%d:amount", u, itype->rtype, amount)); } 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); const int n_items = 13; item_type *it_list[] = { olditemtype[I_AMULET_OF_HEALING], olditemtype[I_AMULET_OF_TRUE_SEEING], olditemtype[I_RING_OF_INVISIBILITY], olditemtype[I_RING_OF_POWER], olditemtype[I_FIRESWORD], olditemtype[I_CHASTITY_BELT], olditemtype[I_FEENSTIEFEL], olditemtype[I_ANTIMAGICCRYSTAL], olditemtype[I_RING_OF_NIMBLEFINGER], olditemtype[I_TROLLBELT], olditemtype[I_TACTICCRYSTAL], olditemtype[I_RING_OF_REGENERATION], olditemtype[I_SACK_OF_CONSERVATION], }; itype = it_list[rand()%n_items]; amount = 1 + rand()%luck; i_change(&((unit *)u)->items, itype, amount); 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) { const unit *u = random_unit_in_faction(f); if(!u) return; switch(rand()%3) { case 0: lucky_silver(u); break; case 1: lucky_item(u); break; case 2: lucky_magic_item(u); break; } } void check_luck(void) { faction *f; for(f=factions; f; f=f->next) { if(rand()%100 < STANDARD_LUCK+fspecial(f, FS_LUCKY)*8) lucky_event(f); } }