diff --git a/session_data.cpp b/session_data.cpp index 8679f2a..48e5468 100644 --- a/session_data.cpp +++ b/session_data.cpp @@ -1,8 +1,76 @@ #include "session_data.h" +// #include "event_factory.h" +#include "mapscanner.h" + #include using std::vector; +//--------------------------------------------------------- +//---------------- SurfaceData ---------------------------- +//--------------------------------------------------------- + +bool SurfaceData::Init() { + // open map, read it + // asign map pointers + // init factories + str locationName = SessionData::gameData.locationID; + MapScanner scanner; + MapData data = scanner.getMap(locationName); + surfaceMatrix = data.surfaceMatrix; + mapHeight = data.mapHeight; + mapWidth = data.mapWidth; + SessionData::gameData.mapHeight = mapHeight; + SessionData::gameData.mapWidth = mapWidth; + return true; +} + +int SurfaceData::getWidth() { + return mapWidth; +} + +int SurfaceData::getHeight() { + return mapHeight; +} + +short SurfaceData::getSurface(coord& point) { + if ((point.x <= 0 || point.x >= mapWidth) || (point.y <= 0 || point.y >= mapHeight)) + return -1; + return surfaceMatrix[point.x][point.y]; +} + +bool SurfaceData::IsValidCoord(coord& point) { + if ((point.x < 0 || point.x > mapWidth) || (point.y < 0 || point.y > mapHeight)) + return false; + return true; +} + +bool SurfaceData::IsValidRadius(coord& point, short radius) { + if ( + (point.x - radius <= 0) || + (point.x + radius >= mapWidth) || + (point.y + radius >= mapHeight) || + (point.y - radius <= 0) || + (!IsValidCoord(point)) + ) return false; + + bool flag = false; + coord temp; + for (int i = point.x - radius; i < point.x + radius; i++) { + for (int j = point.y - radius; j < point.y + radius; j++) { + temp.x = i; temp.y = j; + if (getSurface(temp)) flag = true; + } + } + + return flag; +} + +bool SurfaceData::IsWalkable(coord& point) { + if (getSurface(point)) return true; + return false; +} + //--------------------------------------------------------- //----------------- EventsData ---------------------------- //--------------------------------------------------------- @@ -34,8 +102,8 @@ add event to map for (auto i : list) { Event event = i.second; - int width = GameData::mapWidth; - int height = GameData::mapHeight; + int width = SessionData::gameData.mapWidth; + int height = SessionData::gameData.mapHeight; coord eventCenter = event.GetCoord(); if (eventCenter.x > width || eventCenter.y > height) throw "coordinates are out of range"; @@ -87,3 +155,12 @@ bool ArtifactsData::Init() { Artifact& ArtifactsData::getArtifact(const str key) { return currentArtifactsList.at(key); } + +//--------------------------------------------------------- +//--------------------- GameData -------------------------- +//--------------------------------------------------------- + +bool GameData::Init() { + using namespace SessionData; + return eventsData.Init() && surfaceData.Init() && artifactsData.Init(); +} \ No newline at end of file diff --git a/session_data.h b/session_data.h index 7290d13..ac7e951 100644 --- a/session_data.h +++ b/session_data.h @@ -9,10 +9,7 @@ #include "event_factory.h" #include "artifact.h" // #include "artifact_factory.h" -#include "mapdata.h" -#include "mapscanner.h" -#include "surface.h" - +#include "surface.h" //here is SurfaceData, temporary solution. class SystemData { // coming soon @@ -21,14 +18,26 @@ class SystemData { class GameData { // stores finished events and other stuff public: -// bool Init(); - static short getHeight(); - static short getWidth(); - static void setHeight(short); - static void setWidth(short); + bool Init(); + int mapHeight; + int mapWidth; + str locationID; // ID of a map going to be loaded +}; + +class SurfaceData { +public: + bool Init(); + int getWidth(); + int getHeight(); + bool IsValidRadius(coord&, short); + bool IsValidCoord(coord&); + bool IsWalkable(coord&); + short getSurface(coord&); + Surface& getSurface(str); private: - static short mapHeight; - static short mapWidth; + int mapWidth, mapHeight; + short** surfaceMatrix; // std::unordered_map currentSurfaceList; // currently useless + // std::unordered_map globalSurfaceList; //will be added in future }; class EventsData { @@ -36,6 +45,7 @@ class EventsData { bool Init(); Event& getEvent(const str); Event& getEvent(coord); + void removeFrontEvent(coord); // no realization yet // more methods coming in future private: void SortEventVector(std::vector*); @@ -53,8 +63,21 @@ class ArtifactsData { Artifact& getArtifact(const str); private: std::unordered_map currentArtifactsList; - std::unordered_map globalArtifactsList; - + // std::unordered_map globalArtifactsList; }; +namespace SessionData { + SystemData systemData; + GameData gameData; + SurfaceData surfaceData; + EventsData eventsData; + ArtifactsData artifactsData; + + // hero initialization + str name = "Hero"; + str id = "super_hero"; + coord start; + Hero hero(name, id, 1, 10, start, nullptr); +} + #endif //SESSION \ No newline at end of file