From 19cd686ac4de180ecd38ac4516016f5553693475 Mon Sep 17 00:00:00 2001 From: mizipzor Date: Sun, 28 Feb 2010 02:37:05 +0100 Subject: [PATCH] added exceptions to API::InitMap --- library/DFError.h | 22 ++++++++++++++++++++++ library/DFHackAPI.cpp | 8 +++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/library/DFError.h b/library/DFError.h index c6255aa04..5a44df27c 100644 --- a/library/DFError.h +++ b/library/DFError.h @@ -49,6 +49,28 @@ namespace DFHack return "couldn't attach to process"; } }; + + class NoMapLoaded : public exception + { + public: + virtual const char* what() const throw() + { + return "no map has been loaded in the dwarf fortress process"; + } + }; + + class BadMapDimensions : public exception + { + public: + BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {} + const uint32_t x; + const uint32_t y; + + virtual const char* what() const throw() + { + return "both x and y needs to be between 0 and 48"; + } + }; } } diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index ff602d0d8..cfa761378 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -184,12 +184,13 @@ bool API::InitMap() d->offset_descriptor->resolveClassnameToVPtr("block_square_event_mineral",d->vein_mineral_vptr); // get the map pointer - uint32_t x_array_loc = g_pProcess->readDWord (map_offset); + uint32_t x_array_loc = g_pProcess->readDWord (map_offset); //FIXME: very inadequate if (!x_array_loc) { + throw Error::NoMapLoaded(); // bad stuffz happend - return false; + //return false; } uint32_t mx, my, mz; @@ -201,7 +202,8 @@ bool API::InitMap() // test for wrong map dimensions if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0) { - return false; + throw Error::BadMapDimensions(mx, my); + //return false; } // alloc array for pointers to all blocks