summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/store.cc137
-rw-r--r--crawl-ref/source/store.h19
-rw-r--r--crawl-ref/source/tags.cc15
-rw-r--r--crawl-ref/source/tags.h2
4 files changed, 150 insertions, 23 deletions
diff --git a/crawl-ref/source/store.cc b/crawl-ref/source/store.cc
index ad302640e6..f52a97d510 100644
--- a/crawl-ref/source/store.cc
+++ b/crawl-ref/source/store.cc
@@ -9,7 +9,9 @@
#include "store.h"
+#include "dlua.h"
#include "externs.h"
+#include "monster.h"
#include "tags.h"
#include "travel.h"
@@ -105,6 +107,22 @@ CrawlStoreValue::CrawlStoreValue(const CrawlStoreValue &other)
break;
}
+ case SV_MONST:
+ {
+ monsters* mon;
+ mon = new monsters(*static_cast<monsters*>(other.val.ptr));
+ val.ptr = static_cast<void*>(mon);
+ break;
+ }
+
+ case SV_LUA:
+ {
+ dlua_chunk* chunk;
+ chunk = new dlua_chunk(*static_cast<dlua_chunk*>(other.val.ptr));
+ val.ptr = static_cast<void*>(chunk);
+ break;
+ }
+
case NUM_STORE_VAL_TYPES:
ASSERT(false);
}
@@ -208,6 +226,20 @@ CrawlStoreValue::CrawlStoreValue(const level_pos &_val)
get_level_pos() = _val;
}
+CrawlStoreValue::CrawlStoreValue(const monsters &_val)
+ : type(SV_MONST), flags(SFLAG_UNSET)
+{
+ val.ptr = NULL;
+ get_monster() = _val;
+}
+
+CrawlStoreValue::CrawlStoreValue(const dlua_chunk &_val)
+ : type(SV_LUA), flags(SFLAG_UNSET)
+{
+ val.ptr = NULL;
+ get_lua() = _val;
+}
+
CrawlStoreValue::~CrawlStoreValue()
{
unset(true);
@@ -301,6 +333,22 @@ void CrawlStoreValue::unset(bool force)
break;
}
+ case SV_MONST:
+ {
+ monsters* mon = static_cast<monsters*>(val.ptr);
+ delete mon;
+ val.ptr = NULL;
+ break;
+ }
+
+ case SV_LUA:
+ {
+ dlua_chunk* chunk = static_cast<dlua_chunk*>(val.ptr);
+ delete chunk;
+ val.ptr = NULL;
+ break;
+ }
+
case SV_NONE:
DEBUGSTR("CrawlStoreValue::unset: unsetting nothing");
break;
@@ -490,6 +538,20 @@ void CrawlStoreValue::write(writer &th) const
break;
}
+ case SV_MONST:
+ {
+ monsters* mon = static_cast<monsters*>(val.ptr);
+ marshallMonster(th, *mon);
+ break;
+ }
+
+ case SV_LUA:
+ {
+ dlua_chunk* chunk = static_cast<dlua_chunk*>(val.ptr);
+ chunk->write(th);
+ break;
+ }
+
case SV_NONE:
break;
@@ -589,6 +651,24 @@ void CrawlStoreValue::read(reader &th)
break;
}
+ case SV_MONST:
+ {
+ monsters mon;
+ unmarshallMonster(th, mon);
+ val.ptr = (void*) new monsters(mon);
+
+ break;
+ }
+
+ case SV_LUA:
+ {
+ dlua_chunk chunk;
+ chunk.read(th);
+ val.ptr = (void*) new dlua_chunk(chunk);
+
+ break;
+ }
+
case SV_NONE:
break;
@@ -759,6 +839,15 @@ level_pos &CrawlStoreValue::get_level_pos()
GET_VAL_PTR(SV_LEV_POS, level_pos*, new level_pos());
}
+monsters &CrawlStoreValue::get_monster()
+{
+ GET_VAL_PTR(SV_MONST, monsters*, new monsters());
+}
+
+dlua_chunk &CrawlStoreValue::get_lua()
+{
+ GET_VAL_PTR(SV_LUA, dlua_chunk*, new dlua_chunk());
+}
CrawlStoreValue &CrawlStoreValue::operator [] (const std::string &key)
{
@@ -863,18 +952,20 @@ const CrawlStoreValue &CrawlStoreValue::operator
/////////////////////
// Typecast operators
#ifdef TARGET_COMPILER_VC
-CrawlStoreValue::operator bool&() { return get_bool(); }
-CrawlStoreValue::operator char&() { return get_byte(); }
-CrawlStoreValue::operator short&() { return get_short(); }
-CrawlStoreValue::operator float&() { return get_float(); }
-CrawlStoreValue::operator long&() { return get_long(); }
-CrawlStoreValue::operator std::string&() { return get_string(); }
-CrawlStoreValue::operator coord_def&() { return get_coord(); }
-CrawlStoreValue::operator CrawlHashTable&() { return get_table(); }
-CrawlStoreValue::operator CrawlVector&() { return get_vector(); }
-CrawlStoreValue::operator item_def&() { return get_item(); }
-CrawlStoreValue::operator level_id&() { return get_level_id(); }
-CrawlStoreValue::operator level_pos&() { return get_level_pos(); }
+CrawlStoreValue::operator bool&() { return get_bool(); }
+CrawlStoreValue::operator char&() { return get_byte(); }
+CrawlStoreValue::operator short&() { return get_short(); }
+CrawlStoreValue::operator float&() { return get_float(); }
+CrawlStoreValue::operator long&() { return get_long(); }
+CrawlStoreValue::operator std::string&() { return get_string(); }
+CrawlStoreValue::operator coord_def&() { return get_coord(); }
+CrawlStoreValue::operator CrawlHashTable&() { return get_table(); }
+CrawlStoreValue::operator CrawlVector&() { return get_vector(); }
+CrawlStoreValue::operator item_def&() { return get_item(); }
+CrawlStoreValue::operator level_id&() { return get_level_id(); }
+CrawlStoreValue::operator level_pos&() { return get_level_pos(); }
+CrawlStoreValue::operator monster&() { return get_monster(); }
+CrawlStoreValue::operator dlua_chunk&() { return get_dlua_chunk(); }
#else
&CrawlStoreValue::operator bool()
{
@@ -935,6 +1026,16 @@ CrawlStoreValue::operator level_pos&() { return get_level_pos(); }
{
return get_level_pos();
}
+
+&CrawlStoreValue::operator monsters()
+{
+ return get_monster();
+}
+
+&CrawlStoreValue::operator dlua_chunk()
+{
+ return get_lua();
+}
#endif
///////////////////////////
@@ -1078,6 +1179,18 @@ CrawlStoreValue &CrawlStoreValue::operator = (const level_pos &_val)
return (*this);
}
+CrawlStoreValue &CrawlStoreValue::operator = (const monsters &_val)
+{
+ get_monster() = _val;
+ return (*this);
+}
+
+CrawlStoreValue &CrawlStoreValue::operator = (const dlua_chunk &_val)
+{
+ get_lua() = _val;
+ return (*this);
+}
+
///////////////////////////////////////////////////
// Non-assignment operators which affect the lvalue
#define INT_OPERATOR_UNARY(op) \
diff --git a/crawl-ref/source/store.h b/crawl-ref/source/store.h
index e23e6056be..79b9454c97 100644
--- a/crawl-ref/source/store.h
+++ b/crawl-ref/source/store.h
@@ -20,7 +20,9 @@ class CrawlVector;
struct item_def;
struct coord_def;
struct level_pos;
-class level_id;
+class level_id;
+class dlua_chunk;
+class monsters;
typedef unsigned char hash_size;
typedef unsigned char vec_size;
@@ -46,6 +48,8 @@ enum store_val_type
SV_VEC,
SV_LEV_ID,
SV_LEV_POS,
+ SV_MONST,
+ SV_LUA,
NUM_STORE_VAL_TYPES
};
@@ -94,8 +98,9 @@ public:
CrawlStoreValue(const CrawlVector &val);
CrawlStoreValue(const level_id &val);
CrawlStoreValue(const level_pos &val);
+ CrawlStoreValue(const monsters &val);
+ CrawlStoreValue(const dlua_chunk &val);
- // Only needed for doing some assertion checking.
CrawlStoreValue &operator = (const CrawlStoreValue &other);
protected:
@@ -128,6 +133,8 @@ public:
item_def &get_item();
level_id &get_level_id();
level_pos &get_level_pos();
+ monsters &get_monster();
+ dlua_chunk &get_lua();
bool get_bool() const;
char get_byte() const;
@@ -142,6 +149,8 @@ public:
const CrawlHashTable& get_table() const;
const CrawlVector& get_vector() const;
const item_def& get_item() const;
+ const monsters& get_monster() const;
+ const dlua_chunk& get_lua() const;
#if 0
// These don't actually exist
@@ -188,6 +197,8 @@ public:
operator item_def&();
operator level_id&();
operator level_pos&();
+ operator monsters&();
+ operator dlua_chunk&();
#else
&operator bool();
&operator char();
@@ -201,6 +212,8 @@ public:
&operator item_def();
&operator level_id();
&operator level_pos();
+ &operator monsters();
+ &operator dlua_chunk();
#endif
operator bool() const;
@@ -227,6 +240,8 @@ public:
CrawlStoreValue &operator = (const item_def &val);
CrawlStoreValue &operator = (const level_id &val);
CrawlStoreValue &operator = (const level_pos &val);
+ CrawlStoreValue &operator = (const monsters &val);
+ CrawlStoreValue &operator = (const dlua_chunk &val);
// Misc operators
std::string &operator += (const std::string &val);
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 0b99e3e2ff..fabf242086 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -202,9 +202,6 @@ static void unmarshallResists(reader &th, mon_resist_def &res,
static void marshallSpells(writer &, const monster_spells &);
static void unmarshallSpells(reader &, monster_spells &);
-static void marshall_monster(writer &th, const monsters &m);
-static void unmarshall_monster(reader &th, monsters &m);
-
template<typename T, typename T_iter, typename T_marshal>
static void marshall_iterator(writer &th, T_iter beg, T_iter end,
T_marshal marshal);
@@ -1161,14 +1158,14 @@ static void tag_construct_you_dungeon(writer &th)
static void marshall_follower(writer &th, const follower &f)
{
- marshall_monster(th, f.mons);
+ marshallMonster(th, f.mons);
for (int i = 0; i < NUM_MONSTER_SLOTS; ++i)
marshallItem(th, f.items[i]);
}
static void unmarshall_follower(reader &th, follower &f)
{
- unmarshall_monster(th, f.mons);
+ unmarshallMonster(th, f.mons);
for (int i = 0; i < NUM_MONSTER_SLOTS; ++i)
unmarshallItem(th, f.items[i]);
}
@@ -1876,7 +1873,7 @@ static mon_enchant unmarshall_mon_enchant(reader &th)
return (me);
}
-static void marshall_monster(writer &th, const monsters &m)
+void marshallMonster(writer &th, const monsters &m)
{
marshallString(th, m.mname);
marshallByte(th, m.ac);
@@ -1965,7 +1962,7 @@ static void tag_construct_level_monsters(writer &th)
}
}
#endif
- marshall_monster(th, m);
+ marshallMonster(th, m);
}
}
@@ -2188,7 +2185,7 @@ static void tag_read_level_items(reader &th, char minorVersion)
#endif
}
-static void unmarshall_monster(reader &th, monsters &m)
+void unmarshallMonster(reader &th, monsters &m)
{
m.reset();
@@ -2278,7 +2275,7 @@ static void tag_read_level_monsters(reader &th, char minorVersion)
for (i = 0; i < count; i++)
{
monsters &m = menv[i];
- unmarshall_monster(th, m);
+ unmarshallMonster(th, m);
// place monster
if (m.type != MONS_NO_MONSTER)
diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h
index da4e1211aa..773c686b49 100644
--- a/crawl-ref/source/tags.h
+++ b/crawl-ref/source/tags.h
@@ -96,6 +96,7 @@ void marshallString (writer &, const std::string &, int maxSize = 0);
void marshallString4 (writer &, const std::string &);
void marshallCoord (writer &, const coord_def &);
void marshallItem (writer &, const item_def &);
+void marshallMonster (writer &, const monsters &);
void marshallShowtype (writer &, const show_type &);
/* ***********************************************************************
@@ -134,6 +135,7 @@ std::string unmarshallString (reader &, int maxSize = 1000);
void unmarshallString4 (reader &, std::string&);
void unmarshallCoord (reader &, coord_def &c);
void unmarshallItem (reader &, item_def &item);
+void unmarshallMonster (reader &, monsters &item);
show_type unmarshallShowtype (reader &);
/* ***********************************************************************