Attached Files |
8515-0001-Expose-bitset-s-count-function-through-FixedBitVecto.patch [^] (2,142 bytes) 2014-05-08 08:09 [Show Content] [Hide Content]From cf9aa48a0ec0aa2860796f73dafaa65ebcd1ef8f Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez <ed.gonzalez3@gmail.com>
Date: Wed, 7 May 2014 01:14:01 -0700
Subject: [PATCH 1/3] Expose bitset's count function through FixedBitVector...
and use it to speed up counting runes in a few places.
Vaults and Zot entrances report activated runes by name, so weren't updated.
---
crawl-ref/source/bitary.h | 5 +++++
crawl-ref/source/items.cc | 8 +-------
crawl-ref/source/stairs.cc | 6 +-----
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/crawl-ref/source/bitary.h b/crawl-ref/source/bitary.h
index 4fd7e2f..8cadb3c 100644
--- a/crawl-ref/source/bitary.h
+++ b/crawl-ref/source/bitary.h
@@ -78,6 +78,11 @@ public:
data[i] = value;
}
+ inline unsigned int count() const
+ {
+ return data.count();
+ }
+
inline FixedBitVector<SIZE>& operator|=(const FixedBitVector<SIZE>&x)
{
data |= x.data;
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 9ad9967..d746890 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -4129,13 +4129,7 @@ item_info get_item_info(const item_def& item)
int runes_in_pack()
{
- int num_runes = 0;
-
- for (int i = 0; i < NUM_RUNE_TYPES; i++)
- if (you.runes[i])
- num_runes++;
-
- return num_runes;
+ return static_cast<int>(you.runes.count());
}
static const object_class_type _mimic_item_classes[] =
diff --git a/crawl-ref/source/stairs.cc b/crawl-ref/source/stairs.cc
index a5dc223..f34968d 100644
--- a/crawl-ref/source/stairs.cc
+++ b/crawl-ref/source/stairs.cc
@@ -806,11 +806,7 @@ void down_stairs(dungeon_feature_type force_stair, bool force_known_shaft)
if (stair_find == DNGN_ENTER_ZIGGURAT)
{
#define ZIG_RUNES 3
- int nrune = 0;
- for (int i = 0; i < NUM_RUNE_TYPES; i++)
- if (you.runes[i])
- nrune++;
- if (nrune < ZIG_RUNES)
+ if (runes_in_pack() < ZIG_RUNES)
{
mprf("You need at least %d runes to enter this place.", ZIG_RUNES);
return;
--
1.9.1
8515-0002-Recalculate-cache-of-equipped-unrands-with-world_rea.patch [^] (6,277 bytes) 2014-05-08 08:09 [Show Content] [Hide Content]From 7053bb10bf5fdd53809b136fa5f48e5449414441 Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez <ed.gonzalez3@gmail.com>
Date: Wed, 7 May 2014 02:59:10 -0700
Subject: [PATCH 2/3] Recalculate cache of equipped unrands with world_reacts
on save load
This allows us to more easily add or remove those hooks on existing unrands.
The data type has also been changed to FixedBitVector from unsigned short,
allowing the expanded ring slots to be referenced.
---
crawl-ref/source/artefact.cc | 2 +-
crawl-ref/source/bitary.h | 5 +++++
crawl-ref/source/player-equip.cc | 8 ++++----
crawl-ref/source/player-reacts.cc | 2 +-
crawl-ref/source/player.cc | 2 +-
crawl-ref/source/player.h | 2 +-
crawl-ref/source/tag-version.h | 1 +
crawl-ref/source/tags.cc | 20 ++++++++++++++++++--
8 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/crawl-ref/source/artefact.cc b/crawl-ref/source/artefact.cc
index 56b03d1..574ccf5 100644
--- a/crawl-ref/source/artefact.cc
+++ b/crawl-ref/source/artefact.cc
@@ -2071,7 +2071,7 @@ void unrand_reacts()
for (int i = 0; i < NUM_EQUIP; i++)
{
- if (you.unrand_reacts & (1 << i))
+ if (you.unrand_reacts[i])
{
item_def& item = you.inv[you.equip[i]];
const unrandart_entry* entry = get_unrand_entry(item.special);
diff --git a/crawl-ref/source/bitary.h b/crawl-ref/source/bitary.h
index 8cadb3c..139950b 100644
--- a/crawl-ref/source/bitary.h
+++ b/crawl-ref/source/bitary.h
@@ -83,6 +83,11 @@ public:
return data.count();
}
+ inline bool any() const
+ {
+ return data.any();
+ }
+
inline FixedBitVector<SIZE>& operator|=(const FixedBitVector<SIZE>&x)
{
data |= x.data;
diff --git a/crawl-ref/source/player-equip.cc b/crawl-ref/source/player-equip.cc
index ac505c2..7977041 100644
--- a/crawl-ref/source/player-equip.cc
+++ b/crawl-ref/source/player-equip.cc
@@ -215,8 +215,8 @@ static void _equip_artefact_effect(item_def &item, bool *show_msgs, bool unmeld)
if (entry->world_reacts_func)
{
- equipment_type eq = get_item_slot(item.base_type, item.sub_type);
- you.unrand_reacts |= (1 << eq);
+ equipment_type slot = get_item_slot(item.base_type, item.sub_type);
+ you.unrand_reacts.set(slot);
}
}
@@ -348,8 +348,8 @@ static void _unequip_artefact_effect(item_def &item,
if (entry->world_reacts_func)
{
- equipment_type eq = get_item_slot(item.base_type, item.sub_type);
- you.unrand_reacts &= ~(1 << eq);
+ equipment_type slot = get_item_slot(item.base_type, item.sub_type);
+ you.unrand_reacts.set(slot, false);
}
}
}
diff --git a/crawl-ref/source/player-reacts.cc b/crawl-ref/source/player-reacts.cc
index a1fa4d9..6ce8925 100644
--- a/crawl-ref/source/player-reacts.cc
+++ b/crawl-ref/source/player-reacts.cc
@@ -1253,7 +1253,7 @@ void player_reacts()
_check_equipment_conducts();
- if (you.unrand_reacts != 0)
+ if (you.unrand_reacts.any())
unrand_reacts();
// Handle sound-dependent effects that are silenced
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 8ecd791..6edbdac 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -5874,7 +5874,7 @@ void player::init()
equip.init(-1);
melded.reset();
- unrand_reacts = 0;
+ unrand_reacts.reset();
symbol = MONS_PLAYER;
form = TRAN_NONE;
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index fb81221..35fc6ad 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -79,7 +79,7 @@ public:
FixedVector<int8_t, NUM_EQUIP> equip;
FixedBitVector<NUM_EQUIP> melded;
- unsigned short unrand_reacts;
+ FixedBitVector<NUM_EQUIP> unrand_reacts;
FixedArray<int, NUM_OBJECT_CLASSES, MAX_SUBTYPES> force_autopickup;
diff --git a/crawl-ref/source/tag-version.h b/crawl-ref/source/tag-version.h
index d4be991..7b72129 100644
--- a/crawl-ref/source/tag-version.h
+++ b/crawl-ref/source/tag-version.h
@@ -94,6 +94,7 @@ enum tag_minor_version
TAG_MINOR_BRIBE_BRANCH, // Bribe branch tracking
TAG_MINOR_CLOUD_OWNER, // Track owners of clouds in map knowledge
TAG_MINOR_NO_DEVICE_HEAL, // Made MUT_NO_DEVICE_HEAL a normal bad mutation.
+ TAG_MINOR_CALC_UNRAND_REACTS, // Compute you.unrand_reacts on load
#endif
NUM_TAG_MINORS,
TAG_MINOR_VERSION = NUM_TAG_MINORS - 1
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 4d7be78..30df2d1 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -1291,7 +1291,6 @@ static void tag_construct_you(writer &th)
marshallByte(th, you.royal_jelly_dead);
marshallByte(th, you.transform_uncancellable);
marshallByte(th, you.is_undead);
- marshallShort(th, you.unrand_reacts);
marshallByte(th, you.berserk_penalty);
marshallInt(th, you.abyss_speed);
@@ -2120,7 +2119,10 @@ static void tag_read_you(reader &th)
you.is_undead = static_cast<undead_state_type>(unmarshallUByte(th));
ASSERT(you.is_undead <= US_SEMI_UNDEAD);
- you.unrand_reacts = unmarshallShort(th);
+#if TAG_MAJOR_VERSION == 34
+ if (th.getMinorVersion() < TAG_MINOR_CALC_UNRAND_REACTS)
+ unmarshallShort(th);
+#endif
you.berserk_penalty = unmarshallByte(th);
#if TAG_MAJOR_VERSION == 34
if (th.getMinorVersion() >= TAG_MINOR_GARGOYLE_DR
@@ -2952,6 +2954,20 @@ static void tag_read_you_items(reader &th)
for (i = 0; i < count; ++i)
unmarshallItem(th, you.inv[i]);
+ // Initialize cache of equipped unrand functions
+ for (i = 0; i < NUM_EQUIP; ++i)
+ {
+ const item_def *item = you.slot_item(static_cast<equipment_type>(i));
+
+ if (item && is_unrandom_artefact(*item))
+ {
+ const unrandart_entry *entry = get_unrand_entry(item->special);
+
+ if (entry->world_reacts_func)
+ you.unrand_reacts.set(i);
+ }
+ }
+
unmarshallFixedBitVector<NUM_RUNE_TYPES>(th, you.runes);
you.obtainable_runes = unmarshallByte(th);
--
1.9.1
8515-0003-Pass-equipment-slot-to-artefact-equip-unequip-effect.patch [^] (8,022 bytes) 2014-05-08 08:09 [Show Content] [Hide Content]From 43023c208d92976422d9bf4e1083881fe14b8229 Mon Sep 17 00:00:00 2001
From: Eduardo Gonzalez <ed.gonzalez3@gmail.com>
Date: Wed, 7 May 2014 03:41:50 -0700
Subject: [PATCH 3/3] Pass equipment slot to artefact equip/unequip effects
This allows the correct ring slot to be registered for art-func hooks
if we choose to make any such unrands.
---
crawl-ref/source/player-equip.cc | 52 +++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 22 deletions(-)
diff --git a/crawl-ref/source/player-equip.cc b/crawl-ref/source/player-equip.cc
index 7977041..b7875e1 100644
--- a/crawl-ref/source/player-equip.cc
+++ b/crawl-ref/source/player-equip.cc
@@ -129,10 +129,14 @@ bool unmeld_slot(equipment_type slot, bool msg)
static void _equip_weapon_effect(item_def& item, bool showMsgs, bool unmeld);
static void _unequip_weapon_effect(item_def& item, bool showMsgs, bool meld);
-static void _equip_armour_effect(item_def& arm, bool unmeld);
-static void _unequip_armour_effect(item_def& item, bool meld);
-static void _equip_jewellery_effect(item_def &item, bool unmeld);
-static void _unequip_jewellery_effect(item_def &item, bool mesg, bool meld);
+static void _equip_armour_effect(item_def& arm, bool unmeld,
+ equipment_type slot);
+static void _unequip_armour_effect(item_def& item, bool meld,
+ equipment_type slot);
+static void _equip_jewellery_effect(item_def &item, bool unmeld,
+ equipment_type slot);
+static void _unequip_jewellery_effect(item_def &item, bool mesg, bool meld,
+ equipment_type slot);
static void _equip_use_warning(const item_def& item);
static void _assert_valid_slot(equipment_type eq, equipment_type slot)
@@ -170,9 +174,9 @@ static void _equip_effect(equipment_type slot, int item_slot, bool unmeld,
if (slot == EQ_WEAPON)
_equip_weapon_effect(item, msg, unmeld);
else if (slot >= EQ_CLOAK && slot <= EQ_BODY_ARMOUR)
- _equip_armour_effect(item, unmeld);
+ _equip_armour_effect(item, unmeld, slot);
else if (slot >= EQ_LEFT_RING && slot < NUM_EQUIP)
- _equip_jewellery_effect(item, unmeld);
+ _equip_jewellery_effect(item, unmeld, slot);
}
static void _unequip_effect(equipment_type slot, int item_slot, bool meld,
@@ -189,16 +193,17 @@ static void _unequip_effect(equipment_type slot, int item_slot, bool meld,
if (slot == EQ_WEAPON)
_unequip_weapon_effect(item, msg, meld);
else if (slot >= EQ_CLOAK && slot <= EQ_BODY_ARMOUR)
- _unequip_armour_effect(item, meld);
+ _unequip_armour_effect(item, meld, slot);
else if (slot >= EQ_LEFT_RING && slot < NUM_EQUIP)
- _unequip_jewellery_effect(item, msg, meld);
+ _unequip_jewellery_effect(item, msg, meld, slot);
}
///////////////////////////////////////////////////////////
// Actual equip and unequip effect implementation below
//
-static void _equip_artefact_effect(item_def &item, bool *show_msgs, bool unmeld)
+static void _equip_artefact_effect(item_def &item, bool *show_msgs, bool unmeld,
+ equipment_type slot)
{
#define unknown_proprt(prop) (proprt[(prop)] && !known[(prop)])
@@ -215,7 +220,6 @@ static void _equip_artefact_effect(item_def &item, bool *show_msgs, bool unmeld)
if (entry->world_reacts_func)
{
- equipment_type slot = get_item_slot(item.base_type, item.sub_type);
you.unrand_reacts.set(slot);
}
}
@@ -281,7 +285,8 @@ static void _equip_artefact_effect(item_def &item, bool *show_msgs, bool unmeld)
}
static void _unequip_artefact_effect(item_def &item,
- bool *show_msgs, bool meld)
+ bool *show_msgs, bool meld,
+ equipment_type slot)
{
ASSERT(is_artefact(item));
@@ -348,7 +353,6 @@ static void _unequip_artefact_effect(item_def &item,
if (entry->world_reacts_func)
{
- equipment_type slot = get_item_slot(item.base_type, item.sub_type);
you.unrand_reacts.set(slot, false);
}
}
@@ -464,7 +468,7 @@ static void _equip_weapon_effect(item_def& item, bool showMsgs, bool unmeld)
{
// Call unrandart equip func before item is identified.
if (artefact)
- _equip_artefact_effect(item, &showMsgs, unmeld);
+ _equip_artefact_effect(item, &showMsgs, unmeld, EQ_WEAPON);
const bool was_known = item_type_known(item);
bool known_recurser = false;
@@ -660,7 +664,7 @@ static void _unequip_weapon_effect(item_def& item, bool showMsgs, bool meld)
// Call this first, so that the unrandart func can set showMsgs to
// false if it does its own message handling.
if (is_artefact(item))
- _unequip_artefact_effect(item, &showMsgs, meld);
+ _unequip_artefact_effect(item, &showMsgs, meld, EQ_WEAPON);
if (item.base_type == OBJ_MISCELLANY
&& item.sub_type == MISC_LANTERN_OF_SHADOWS)
@@ -821,7 +825,8 @@ static void _spirit_shield_message(bool unmeld)
mpr("You feel spirits watching over you.");
}
-static void _equip_armour_effect(item_def& arm, bool unmeld)
+static void _equip_armour_effect(item_def& arm, bool unmeld,
+ equipment_type slot)
{
const bool known_cursed = item_known_cursed(arm);
int ego = get_armour_ego_type(arm);
@@ -929,7 +934,7 @@ static void _equip_armour_effect(item_def& arm, bool unmeld)
if (is_artefact(arm))
{
bool show_msgs = true;
- _equip_artefact_effect(arm, &show_msgs, unmeld);
+ _equip_artefact_effect(arm, &show_msgs, unmeld, slot);
}
if (arm.cursed() && !unmeld)
@@ -961,7 +966,8 @@ static void _equip_armour_effect(item_def& arm, bool unmeld)
you.redraw_evasion = true;
}
-static void _unequip_armour_effect(item_def& item, bool meld)
+static void _unequip_armour_effect(item_def& item, bool meld,
+ equipment_type slot)
{
you.redraw_armour_class = true;
you.redraw_evasion = true;
@@ -1090,7 +1096,7 @@ static void _unequip_armour_effect(item_def& item, bool meld)
}
if (is_artefact(item))
- _unequip_artefact_effect(item, NULL, meld);
+ _unequip_artefact_effect(item, NULL, meld, slot);
}
static void _remove_amulet_of_faith(item_def &item)
@@ -1164,7 +1170,8 @@ static void _remove_amulet_of_faith(item_def &item)
}
}
-static void _equip_jewellery_effect(item_def &item, bool unmeld)
+static void _equip_jewellery_effect(item_def &item, bool unmeld,
+ equipment_type slot)
{
const bool artefact = is_artefact(item);
const bool known_cursed = item_known_cursed(item);
@@ -1290,7 +1297,7 @@ static void _equip_jewellery_effect(item_def &item, bool unmeld)
if (artefact)
{
bool show_msgs = true;
- _equip_artefact_effect(item, &show_msgs, unmeld);
+ _equip_artefact_effect(item, &show_msgs, unmeld, slot);
set_ident_flags(item, ISFLAG_KNOW_PROPERTIES);
}
@@ -1324,7 +1331,8 @@ static void _equip_jewellery_effect(item_def &item, bool unmeld)
mprf_nocap("%s", item.name(DESC_INVENTORY_EQUIP).c_str());
}
-static void _unequip_jewellery_effect(item_def &item, bool mesg, bool meld)
+static void _unequip_jewellery_effect(item_def &item, bool mesg, bool meld,
+ equipment_type slot)
{
// The ring/amulet must already be removed from you.equip at this point.
@@ -1415,7 +1423,7 @@ static void _unequip_jewellery_effect(item_def &item, bool mesg, bool meld)
}
if (is_artefact(item))
- _unequip_artefact_effect(item, &mesg, meld);
+ _unequip_artefact_effect(item, &mesg, meld, slot);
// Must occur after ring is removed. -- bwr
calc_mp();
--
1.9.1
|