This repository has been archived by the owner on Jul 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
game.hpp
239 lines (194 loc) · 7.11 KB
/
game.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* Copyright (c) 2013, Abdullah A. Hassan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GAME_HPP
#define GAME_HPP
#include <string>
#include <vector>
#include <map>
#include <cstdint>
#include <memory>
#include <fstream>
//#include <v8.h>
#include <json/json.h>
#include <unordered_map>
#include "animation.hpp"
#include "map.hpp"
#include "engine.hpp"
namespace ADWIF
{
class Game;
class MapGenerator;
class Skill;
class Profession;
class Faction;
class Race;
class Foliage;
class Skill
{
public:
std::string name, desc, dispName, title;
bool activeSkill;
std::vector<std::string> dependencies;
Json::Value jsonValue;
static Skill * parse(const Json::Value & value);
};
class Profession
{
public:
enum NameKind
{
SingularMale,
SingularFemale,
Plural,
NameKindMax
};
std::string name, desc;
std::string dispName[3];
std::vector<std::string> skills;
bool maleOnly, femaleOnly;
Json::Value jsonValue;
static Profession * parse(const Json::Value & value);
};
class Faction
{
public:
std::string name, dispName, surname, desc, home;
bool joinable;
Json::Value jsonValue;
static Faction * parse(const Json::Value & value);
};
class Race
{
public:
std::string name, desc;
std::vector<std::string> allowedProfessions;
std::vector<std::string> factions;
Json::Value jsonValue;
static Race * parse(const Json::Value & value);
};
class Element
{
public:
std::string name;
std::string dispName;
std::string desc;
std::unordered_map<TerrainType, std::vector<dispEntry>, std::hash<int> > disp;
MaterialState state;
palEntry style;
Json::Value jsonValue;
static Element * parse(const Json::Value & value);
};
class Material
{
public:
std::string name;
std::string dispName;
std::string desc;
std::unordered_map<MaterialState, std::unordered_set<std::string>, std::hash<int> > states;
Json::Value jsonValue;
static Material * parse(const Json::Value & value);
};
class Biome
{
public:
std::string name, desc;
dispEntry disp;
std::vector<std::string> materials;
std::vector<std::string> liquids;
int layerStart, layerEnd;
uint32_t mapColour;
bool background;
bool aquatic;
Json::Value jsonValue;
static Biome * parse(const Json::Value & value);
};
class Foliage
{
public:
std::string name, desc;
dispEntry disp;
bool grow;
std::vector<std::string> soil;
std::vector<std::string> needs;
};
class Game: public std::enable_shared_from_this<Game>
{
public:
Game(const std::shared_ptr<class Engine> & engine);
~Game() ;
void init();
void shutdown(bool graceful = true);
void reloadData();
void clearData();
void createNew(std::shared_ptr<class Player> & player) { this->player(player); }
void load(const std::string & fileName);
void save(const std::string & fileName);
void createMap();
void loadMap();
void saveMap();
std::shared_ptr<class Engine> engine() { return myEngine.lock(); }
const std::shared_ptr<class Engine> engine() const { return myEngine.lock(); }
std::shared_ptr<class Player> & player() { return myPlayer; }
const std::shared_ptr<class Player> & player() const { return myPlayer; }
void player(const std::shared_ptr<class Player> & player);
std::shared_ptr<class Map> & map() { return myMap; }
const std::shared_ptr<class Map> & map() const { return myMap; }
void map(const std::shared_ptr<class Map> & map) { myMap = map; }
std::shared_ptr<MapGenerator> & generator() { return myGenerator; }
const std::shared_ptr<MapGenerator> & generator() const { return myGenerator; }
void generator(const std::shared_ptr<class MapGenerator> & generator) { myGenerator = generator; }
std::map<std::string, Race *> & races() { return myRaces; }
std::map<std::string, Profession *> & professions() { return myProfessions; }
std::map<std::string, Skill *> & skills() { return mySkills; }
std::map<std::string, Faction *> & factions() { return myFactions; }
std::map<std::string, Element *> & elements() { return myElements; }
std::map<std::string, Material *> & materials() { return myMaterials; }
std::map<std::string, Biome *> & biomes() { return myBiomes; }
const std::map<std::string, Race *> & races() const { return myRaces; }
const std::map<std::string, Profession *> & professions() const { return myProfessions; }
const std::map<std::string, Skill *> & skills() const { return mySkills; }
const std::map<std::string, Faction *> & factions() const { return myFactions; }
const std::map<std::string, Element *> & elements() const { return myElements; }
const std::map<std::string, Material *> & materials() const { return myMaterials; }
const std::map<std::string, Biome *> & biomes() const { return myBiomes; }
private:
void loadSkills(const Json::Value & skills);
void loadProfessions(const Json::Value & professions);
void loadFactions(const Json::Value & factions);
void loadRaces(const Json::Value & races);
void loadElements(const Json::Value & elements);
void loadMaterials(const Json::Value & materials);
void loadBiomes(const Json::Value biomes);
void sanityCheck();
private:
std::weak_ptr<class Engine> myEngine;
std::shared_ptr<class Player> myPlayer;
std::shared_ptr<class Map> myMap;
std::map<std::string, Race *> myRaces;
std::map<std::string, Profession *> myProfessions;
std::map<std::string, Skill *> mySkills;
std::map<std::string, Faction *> myFactions;
std::map<std::string, Element *> myElements;
std::map<std::string, Material *> myMaterials;
std::map<std::string, Biome *> myBiomes;
std::shared_ptr<class MapGenerator> myGenerator;
};
}
#endif // GAME_HPP
struct stat;