From 81909732f69d66ccd53c0701bbb7c6507ecec5b1 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Thu, 12 Nov 2009 20:15:12 -0800 Subject: store: can now handle monsters and Lua chunks CrawlHashTables and CrawlVectors can now contain monsters and Lua chunks. --- crawl-ref/source/store.cc | 137 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 125 insertions(+), 12 deletions(-) (limited to 'crawl-ref/source/store.cc') 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(other.val.ptr)); + val.ptr = static_cast(mon); + break; + } + + case SV_LUA: + { + dlua_chunk* chunk; + chunk = new dlua_chunk(*static_cast(other.val.ptr)); + val.ptr = static_cast(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(val.ptr); + delete mon; + val.ptr = NULL; + break; + } + + case SV_LUA: + { + dlua_chunk* chunk = static_cast(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(val.ptr); + marshallMonster(th, *mon); + break; + } + + case SV_LUA: + { + dlua_chunk* chunk = static_cast(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) \ -- cgit v1.2.3-54-g00ecf