summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/store.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-12 20:15:12 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-12 20:16:21 -0800
commit81909732f69d66ccd53c0701bbb7c6507ecec5b1 (patch)
tree9aec6574a716fa9b22ca8cb0e950f9738575ecda /crawl-ref/source/store.cc
parenteb59a79d8f2e4957fc45a4550b5ab9245150c14c (diff)
downloadcrawl-ref-81909732f69d66ccd53c0701bbb7c6507ecec5b1.tar.gz
crawl-ref-81909732f69d66ccd53c0701bbb7c6507ecec5b1.zip
store: can now handle monsters and Lua chunks
CrawlHashTables and CrawlVectors can now contain monsters and Lua chunks.
Diffstat (limited to 'crawl-ref/source/store.cc')
-rw-r--r--crawl-ref/source/store.cc137
1 files changed, 125 insertions, 12 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) \