Move sacrifice special cases into data
authorNicholas Feinberg <pleasingfung@gmail.com>
Sun, 30 Nov 2014 04:29:21 +0000 (20:29 -0800)
committerNicholas Feinberg <pleasingfung@gmail.com>
Sun, 30 Nov 2014 04:29:21 +0000 (20:29 -0800)
crawl-ref/source/godabil.cc
crawl-ref/source/sacrifice-data.h

index 0a2f7dd..5274f6b 100644 (file)
@@ -80,6 +80,8 @@
 #include "viewchar.h"
 #include "view.h"
 
+static bool _player_sacrificed_arcana();
+
 // Load the sacrifice_def definition and the sac_data array.
 #include "sacrifice-data.h"
 
@@ -5210,7 +5212,7 @@ static void _choose_arcana_mutations()
 /**
  * Has the player sacrificed any arcana?
  */
-bool _player_sacrificed_arcana()
+static bool _player_sacrificed_arcana()
 {
     for (const vector<mutation_type> arcane_sacrifice_list :
                                     _arcane_sacrifice_lists)
@@ -5251,18 +5253,10 @@ static bool _sacrifice_is_possible(sacrifice_def &sacrifice)
             return false;
     }
 
-    // XXX: move this into sacrifice-data.h itself
-    switch (sacrifice.sacrifice)
-    {
-        case ABIL_RU_SACRIFICE_DRINK:
-            return you.species != SP_MUMMY;
-        case ABIL_RU_SACRIFICE_DURABILITY:
-            return you_can_wear(EQ_BODY_ARMOUR);
-        case ABIL_RU_SACRIFICE_ARCANA:
-            return !_player_sacrificed_arcana();
-        default:
-            return true;
-    }
+    if (sacrifice.valid != nullptr && !sacrifice.valid())
+        return false;
+
+    return true;
 }
 
 /**
index 774276f..b4a3117 100644 (file)
@@ -15,6 +15,10 @@ struct sacrifice_def
                                     // multiple mutations. It is a key into
                                     // you.props, yielding a list of mutations
                                     // granted by the sacrifice.
+    bool (*valid)();                // Whether the sacrifice is currently an
+                                    // valid choice for Ru to offer. Only
+                                    // checks factors specific to this
+                                    // sacrifice, not general checks.
 };
 
 static const sacrifice_def sac_data[] =
@@ -27,6 +31,7 @@ static const sacrifice_def sac_data[] =
   0,
   SK_NONE,
   PURITY_SAC_KEY,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_WORDS, MUT_NO_READ,
@@ -36,6 +41,7 @@ static const sacrifice_def sac_data[] =
   28,
   SK_NONE,
   nullptr,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_DRINK, MUT_NO_DRINK,
@@ -45,6 +51,7 @@ static const sacrifice_def sac_data[] =
   28,
   SK_NONE,
   nullptr,
+  []() { return you.species != SP_MUMMY; },
 },
 
 { ABIL_RU_SACRIFICE_ESSENCE, MUT_NON_MUTATION,
@@ -54,6 +61,7 @@ static const sacrifice_def sac_data[] =
   0,
   SK_NONE,
   ESSENCE_SAC_KEY,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_HEALTH, MUT_NON_MUTATION,
@@ -63,6 +71,7 @@ static const sacrifice_def sac_data[] =
   20,
   SK_NONE,
   HEALTH_SAC_KEY,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_STEALTH, MUT_NO_STEALTH,
@@ -72,6 +81,7 @@ static const sacrifice_def sac_data[] =
   15,
   SK_STEALTH,
   nullptr,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_ARTIFICE, MUT_NO_ARTIFICE,
@@ -81,6 +91,7 @@ static const sacrifice_def sac_data[] =
   70,
   SK_EVOCATIONS,
   nullptr,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_LOVE, MUT_NO_LOVE,
@@ -90,6 +101,7 @@ static const sacrifice_def sac_data[] =
   22,
   SK_NONE,
   nullptr,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_COURAGE, MUT_COWARDICE,
@@ -99,6 +111,7 @@ static const sacrifice_def sac_data[] =
   25,
   SK_NONE,
   nullptr,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_ARCANA, MUT_NON_MUTATION,
@@ -108,6 +121,7 @@ static const sacrifice_def sac_data[] =
   25,
   SK_NONE,
   ARCANA_SAC_KEY,
+  []() { return !_player_sacrificed_arcana(); },
 },
 
 { ABIL_RU_SACRIFICE_NIMBLENESS, MUT_NO_DODGING,
@@ -117,6 +131,7 @@ static const sacrifice_def sac_data[] =
   28,
   SK_DODGING,
   nullptr,
+  nullptr,
 },
 
 { ABIL_RU_SACRIFICE_DURABILITY, MUT_NO_ARMOUR,
@@ -126,6 +141,7 @@ static const sacrifice_def sac_data[] =
   28,
   SK_ARMOUR,
   nullptr,
+  []() { return you_can_wear(EQ_BODY_ARMOUR); },
 },
 
 { ABIL_RU_SACRIFICE_HAND, MUT_MISSING_HAND,
@@ -135,5 +151,6 @@ static const sacrifice_def sac_data[] =
   70,
   SK_SHIELDS,
   nullptr,
+  nullptr,
 },
 };