From 3fcc28592001fa644a08d88517d15380de417107 Mon Sep 17 00:00:00 2001 From: haranp Date: Mon, 9 Jul 2007 15:38:21 +0000 Subject: Nemelex now remembers what you've sacrificed and gifts decks accordingly. High-value sacrifices can reduce the gift countdown. Nemelex is easier to please. Breaks savefiles. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1821 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/externs.h | 1 + crawl-ref/source/player.cc | 1 + crawl-ref/source/religion.cc | 45 +++++++++++++++++++++++++++++++++++++------- crawl-ref/source/stuff.h | 17 ++++++++++++++++- crawl-ref/source/tags.cc | 9 +++++++++ 5 files changed, 65 insertions(+), 8 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 8477dfad3a..14828a0dd8 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -714,6 +714,7 @@ public: int berserk_penalty; // penalty for moving while berserk FixedVector attribute; + FixedVector sacrifice_value; undead_state_type is_undead; diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 2e678eea91..72fc64978b 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -4596,6 +4596,7 @@ void player::init() total_skill_points = 0; attribute.init(0); + sacrifice_value.init(0); for (int i = 0; i < ENDOFPACK; i++) { diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index cfd0bfd0e1..2de5c3d88a 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -476,7 +476,17 @@ static void do_god_gift() MISC_DECK_OF_SUMMONING, MISC_DECK_OF_WONDERS }; - gift_type = RANDOM_ELEMENT(pure_decks); + int weights[5]; + weights[0] = you.sacrifice_value[OBJ_SCROLLS] + + you.sacrifice_value[OBJ_ARMOUR] + 1; + weights[1] = you.sacrifice_value[OBJ_WEAPONS] + + you.sacrifice_value[OBJ_STAVES] + + you.sacrifice_value[OBJ_MISSILES] + 1; + weights[2] = you.sacrifice_value[OBJ_MISCELLANY]; + weights[3] = you.sacrifice_value[OBJ_CORPSES] * 100; + weights[4] = you.sacrifice_value[OBJ_POTIONS]; + gift_type = pure_decks[choose_random_weighted(weights, + weights+5)]; } else { @@ -2445,21 +2455,42 @@ void offer_items() const int value = item_value( mitm[i], true ); +#ifdef DEBUG_DIAGNOSTICS + mprf(MSGCH_DIAGNOSTICS, "Sacrifice item value: %d", value); +#endif + switch (you.religion) { + case GOD_NEMELEX_XOBEH: + you.sacrifice_value[mitm[i].base_type] += value; + if ( you.attribute[ATTR_CARD_COUNTDOWN] && + random2(800) < value ) + { + you.attribute[ATTR_CARD_COUNTDOWN]--; +#ifdef DEBUG_DIAGNOSTICS + mprf(MSGCH_DIAGNOSTICS, "Countdown down to %d", + you.attribute[ATTR_CARD_COUNTDOWN]); +#endif + } + + mprf(MSGCH_GOD, "%s%s", mitm[i].name(DESC_CAP_THE).c_str(), + sacrifice_message(you.religion, mitm[i]).c_str()); + if ((mitm[i].base_type == OBJ_CORPSES && coinflip()) + // Nemelex piety gain is fairly fast. + || random2(value) >= random2(60)) + { + gain_piety(1); + } + destroy_item(i); + break; + case GOD_ZIN: case GOD_OKAWARU: case GOD_MAKHLEB: - case GOD_NEMELEX_XOBEH: mprf(MSGCH_GOD, "%s%s", mitm[i].name(DESC_CAP_THE).c_str(), sacrifice_message(you.religion, mitm[i]).c_str()); - -#ifdef DEBUG_DIAGNOSTICS - mprf(MSGCH_DIAGNOSTICS, "Sacrifice item value: %d", value); -#endif if (mitm[i].base_type == OBJ_CORPSES || random2(value) >= 50 - || (you.religion == GOD_NEMELEX_XOBEH && one_chance_in(50)) || player_under_penance()) { gain_piety(1); diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h index 27c8ec519e..f936151b24 100644 --- a/crawl-ref/source/stuff.h +++ b/crawl-ref/source/stuff.h @@ -128,5 +128,20 @@ public: ~rng_save_excursion() { pop_rng_state(); } }; -#endif +template +int choose_random_weighted(Iterator beg, const Iterator end) +{ + int totalweight = 0; + int count = 0, result = 0; + while ( beg != end ) + { + totalweight += *beg; + if ( random2(totalweight) < *beg ) + result = count; + ++count; + ++beg; + } + return result; +} +#endif diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 41de4143fc..8b779c0995 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -793,6 +793,11 @@ static void tag_construct_you(struct tagHeader &th) for (j = 0; j < NUM_ATTRIBUTES; ++j) marshallByte(th,you.attribute[j]); + // sacrifice values + marshallByte(th, NUM_OBJECT_CLASSES); + for (j = 0; j < NUM_OBJECT_CLASSES; ++j) + marshallLong(th, you.sacrifice_value[j]); + // how many mutations/demon powers? marshallShort(th, NUM_MUTATIONS); for (j = 0; j < NUM_MUTATIONS; ++j) @@ -1096,6 +1101,10 @@ static void tag_read_you(struct tagHeader &th, char minorVersion) for (j = 0; j < count_c; ++j) you.attribute[j] = unmarshallByte(th); + count_c = unmarshallByte(th); + for (j = 0; j < count_c; ++j) + you.sacrifice_value[j] = unmarshallLong(th); + // how many mutations/demon powers? count_s = unmarshallShort(th); for (j = 0; j < count_s; ++j) -- cgit v1.2.3-54-g00ecf