diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml
index 015bc0498..620a05cb3 100644
--- a/data/Memory-ng.xml
+++ b/data/Memory-ng.xml
@@ -1596,9 +1596,9 @@
-
-
-
+
+
+
diff --git a/library/include/dfhack/DFError.h b/library/include/dfhack/DFError.h
index e4def9883..fcb80f724 100644
--- a/library/include/dfhack/DFError.h
+++ b/library/include/dfhack/DFError.h
@@ -34,7 +34,12 @@ namespace DFHack
{
namespace Error
{
- class DFHACK_EXPORT NoProcess : public std::exception
+ /*
+ * our wrapper for the C++ exception. used to differentiate
+ * the whole array of DFHack exceptions from the rest
+ */
+ class DFHACK_EXPORT All : public std::exception{};
+ class DFHACK_EXPORT NoProcess : public All
{
public:
virtual const char* what() const throw()
@@ -43,7 +48,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT CantAttach : public std::exception
+ class DFHACK_EXPORT CantAttach : public All
{
public:
virtual const char* what() const throw()
@@ -52,7 +57,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT NoMapLoaded : public std::exception
+ class DFHACK_EXPORT NoMapLoaded : public All
{
public:
virtual const char* what() const throw()
@@ -61,7 +66,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT BadMapDimensions : public std::exception
+ class DFHACK_EXPORT BadMapDimensions : public All
{
public:
BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {}
@@ -75,7 +80,7 @@ namespace DFHack
};
// a call to DFHack::mem_info::get* failed
- class DFHACK_EXPORT MissingMemoryDefinition : public std::exception
+ class DFHACK_EXPORT MissingMemoryDefinition : public All
{
public:
MissingMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key)
@@ -108,7 +113,7 @@ namespace DFHack
};
// a call to DFHack::mem_info::get* failed
- class DFHACK_EXPORT UnsetMemoryDefinition : public std::exception
+ class DFHACK_EXPORT UnsetMemoryDefinition : public All
{
public:
UnsetMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key)
@@ -141,7 +146,7 @@ namespace DFHack
};
// Syntax errors and whatnot, the xml cant be read
- class DFHACK_EXPORT MemoryXmlParse : public std::exception
+ class DFHACK_EXPORT MemoryXmlParse : public All
{
public:
MemoryXmlParse(const char* _desc, int _id, int _row, int _col)
@@ -167,7 +172,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT MemoryXmlBadAttribute : public std::exception
+ class DFHACK_EXPORT MemoryXmlBadAttribute : public All
{
public:
MemoryXmlBadAttribute(const char* _attr) : attr(_attr)
@@ -187,7 +192,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT MemoryXmlNoRoot : public std::exception
+ class DFHACK_EXPORT MemoryXmlNoRoot : public All
{
public:
MemoryXmlNoRoot() {}
@@ -200,7 +205,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT MemoryXmlNoDFExtractor : public std::exception
+ class DFHACK_EXPORT MemoryXmlNoDFExtractor : public All
{
public:
MemoryXmlNoDFExtractor(const char* _name) : name(_name)
@@ -220,7 +225,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT MemoryXmlUnderspecifiedEntry : public std::exception
+ class DFHACK_EXPORT MemoryXmlUnderspecifiedEntry : public All
{
public:
MemoryXmlUnderspecifiedEntry(const char * _where) : where(_where)
@@ -238,7 +243,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT MemoryXmlUnknownType : public std::exception
+ class DFHACK_EXPORT MemoryXmlUnknownType : public All
{
public:
MemoryXmlUnknownType(const char* _type) : type(_type)
@@ -258,7 +263,7 @@ namespace DFHack
}
};
- class DFHACK_EXPORT SHMServerDisappeared : public std::exception
+ class DFHACK_EXPORT SHMServerDisappeared : public All
{
public:
SHMServerDisappeared(){}
@@ -268,7 +273,7 @@ namespace DFHack
return "The server process has disappeared";
}
};
- class DFHACK_EXPORT SHMLockingError : public std::exception
+ class DFHACK_EXPORT SHMLockingError : public All
{
public:
SHMLockingError(const char* _type) : type(_type)
@@ -287,7 +292,7 @@ namespace DFHack
return full.c_str();
}
};
- class DFHACK_EXPORT MemoryAccessDenied : public std::exception
+ class DFHACK_EXPORT MemoryAccessDenied : public All
{
public:
MemoryAccessDenied() {}
@@ -297,7 +302,7 @@ namespace DFHack
return "SHM ACCESS DENIED";
}
};
- class DFHACK_EXPORT SHMVersionMismatch : public std::exception
+ class DFHACK_EXPORT SHMVersionMismatch : public All
{
public:
SHMVersionMismatch() {}
@@ -307,7 +312,7 @@ namespace DFHack
return "SHM VERSION MISMATCH";
}
};
- class DFHACK_EXPORT SHMAttachFailure : public std::exception
+ class DFHACK_EXPORT SHMAttachFailure : public All
{
public:
SHMAttachFailure() {}
@@ -317,7 +322,7 @@ namespace DFHack
return "SHM ATTACH FAILURE";
}
};
- class DFHACK_EXPORT ModuleNotInitialized : public std::exception
+ class DFHACK_EXPORT ModuleNotInitialized : public All
{
public:
ModuleNotInitialized() {}
diff --git a/library/modules/Position.cpp b/library/modules/Position.cpp
index 920660321..7442d9ddb 100644
--- a/library/modules/Position.cpp
+++ b/library/modules/Position.cpp
@@ -27,6 +27,7 @@ distribution.
#include "dfhack/modules/Position.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
+#include "dfhack/DFError.h"
using namespace DFHack;
struct Position::Private
@@ -72,7 +73,7 @@ Position::Position(DFContextShared * d_)
d->window_dims_offset = OG_Position->getAddress ("window_dims");
d->Started = true;
}
- catch(exception &){};
+ catch(Error::All &){};
try
{
OffsetGroup * OG_Hotkeys = mem->getGroup("Hotkeys");
@@ -82,13 +83,13 @@ Position::Position(DFContextShared * d_)
d->hotkey_size = OG_Hotkeys->getHexValue("size");
d->StartedHotkeys = true;
}
- catch(exception &){};
+ catch(Error::All &){};
try
{
d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer");
d->StartedScreen = true;
}
- catch(exception &){};
+ catch(Error::All &){};
}
Position::~Position()
diff --git a/library/modules/World.cpp b/library/modules/World.cpp
index a24dbf2a6..009b696ac 100644
--- a/library/modules/World.cpp
+++ b/library/modules/World.cpp
@@ -40,13 +40,15 @@ FIXME: Japa said that he had to do this with the time stuff he got from here
#include "dfhack/DFProcess.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h"
+#include "dfhack/DFError.h"
using namespace DFHack;
struct World::Private
{
bool Inited;
- bool Started;
+ bool StartedTime;
+ bool StartedWeather;
uint32_t year_offset;
uint32_t tick_offset;
uint32_t weather_offset;
@@ -60,12 +62,23 @@ World::World(DFContextShared * _d)
d = new Private;
d->d = _d;
d->owner = _d->p;
+ d->Inited = d->StartedTime = d->StartedWeather = false;
OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World");
- d->year_offset = OG_World->getAddress( "current_year" );
- d->tick_offset = OG_World->getAddress( "current_tick" );
- d->weather_offset = OG_World->getAddress( "current_weather" );
- d->Inited = d->Started = true;
+ try
+ {
+ d->year_offset = OG_World->getAddress( "current_year" );
+ d->tick_offset = OG_World->getAddress( "current_tick" );
+ d->StartedTime = true;
+ }
+ catch(Error::All &){};
+ try
+ {
+ d->weather_offset = OG_World->getAddress( "current_weather" );
+ d->StartedWeather = true;
+ }
+ catch(Error::All &){};
+ d->Inited = true;
}
World::~World()
@@ -85,14 +98,14 @@ bool World::Finish()
uint32_t World::ReadCurrentYear()
{
- if(d->Inited)
+ if(d->Inited && d->StartedTime)
return(d->owner->readDWord(d->year_offset));
return 0;
}
uint32_t World::ReadCurrentTick()
{
- if(d->Inited)
+ if(d->Inited && d->StartedTime)
return(d->owner->readDWord(d->tick_offset));
return 0;
}
@@ -119,13 +132,13 @@ uint32_t World::ReadCurrentDay()
uint8_t World::ReadCurrentWeather()
{
- if (d->Inited)
+ if (d->Inited && d->StartedWeather)
return(d->owner->readByte(d->weather_offset));
return 0;
}
void World::SetCurrentWeather(uint8_t weather)
{
- if (d->Inited)
+ if (d->Inited && d->StartedWeather)
d->owner->writeByte(d->weather_offset,weather);
}