1 /*
2  *  Copyright (C) 2000-2013  The Exult Team
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef GAME_H
20 #define GAME_H
21 
22 #include <string>
23 #include <vector>
24 
25 #include "hash_utils.h"
26 #include "exult_constants.h"
27 #include "palette.h"
28 #include "vgafile.h"
29 #include "singles.h"
30 
31 class Game_window;
32 class Image_window8;
33 class Image_buffer8;
34 class Mouse;
35 class Configuration;
36 class BaseGameInfo;
37 class Shape_frame;
38 
39 struct str_int_pair {
40 	const char *str;
41 	int  num;
42 };
43 
44 #define GAME_BG (Game::get_game_type() == BLACK_GATE)
45 #define GAME_SI (Game::get_game_type() == SERPENT_ISLE)
46 #define GAME_FOV (Game::get_game_type()==BLACK_GATE && Game::has_expansion())
47 #define GAME_SS (Game::get_game_type()==SERPENT_ISLE && Game::has_expansion())
48 #define GAME_SIB (Game::get_game_type()==SERPENT_ISLE && Game::is_si_beta())
49 
50 class Game : public Game_singletons {
51 private:
52 	static bool new_game_flag;
53 	static Exult_Game game_type;
54 	static Game_Language language;
55 	static bool expansion, sibeta;
56 	using shapes_map = std::unordered_map<const char *, int, hashstr, eqstr>;
57 	using rsc_map = std::unordered_map<const char *, str_int_pair, hashstr, eqstr>;
58 	shapes_map shapes;
59 	rsc_map resources;
60 	Configuration *xml = nullptr;     /* Shapes/resources from XML file. */
61 	std::vector<char *> xmlstrings;
62 	Mouse *menu_mouse;
63 	static std::string gametitle;
64 	static std::string modtitle;
65 	static unsigned int ticks;
66 
67 protected:
68 	static bool editing_flag;
69 	int topx, topy, centerx, centery;
70 	Vga_file menushapes;
71 	bool    jive;
72 
73 public:
74 	Game_window *gwin;
75 	Image_window8 *win;
76 	Image_buffer8 *ibuf;
77 	//  Palette pal;
78 
79 	Game();
80 	virtual ~Game();
81 
set_new_game()82 	static void set_new_game() {
83 		new_game_flag = true;
84 	}
is_new_game()85 	static bool is_new_game() {
86 		return new_game_flag;
87 	}
is_editing()88 	static bool is_editing() {
89 		return editing_flag;
90 	}
91 	static Game *create_game(BaseGameInfo *mygame);
get_game_type()92 	static Exult_Game get_game_type() {
93 		return game_type;
94 	}
get_game_language()95 	static Game_Language get_game_language() {
96 		return language;
97 	}
has_expansion()98 	static bool has_expansion() {
99 		return expansion;
100 	}
is_si_beta()101 	static bool is_si_beta() {
102 		return sibeta;
103 	}
104 
105 	static const char *get_avname();
106 	static int get_avsex();
107 	static int get_avskin();
108 	static void set_avname(const char *name);
109 	static void set_avsex(int sex);
110 	static void set_avskin(int skin);
111 	static void clear_avname();
112 	static void clear_avsex();
113 	static void clear_avskin();
114 
get_gametitle()115 	static std::string get_gametitle() {
116 		return gametitle;
117 	}
get_modtitle()118 	static std::string get_modtitle() {
119 		return modtitle;
120 	}
121 
122 	virtual void play_intro() = 0;
123 	virtual void end_game(bool success) = 0;
124 	virtual void top_menu() = 0;
125 	virtual void show_quotes() = 0;
126 	virtual void show_credits() = 0;
127 	virtual bool new_game(Vga_file &shapes) = 0;
128 	virtual int  get_start_tile_x() = 0;
129 	virtual int  get_start_tile_y() = 0;
130 	virtual void show_journey_failed() = 0;
131 	virtual Shape_frame *get_menu_shape() = 0;
132 
133 	void add_shape(const char *name, int shapenum);
134 	int get_shape(const char *name);
135 	void add_resource(const char *name, const char *str, int num);
136 	const str_int_pair &get_resource(const char *name);
137 	void write_game_xml();
138 	bool read_game_xml(const char *name1 = nullptr);
139 
140 	bool show_menu(bool skip = false);
141 	void journey_failed_text();
set_jive()142 	void set_jive() {
143 		jive = true;
144 	}
clear_jive()145 	void clear_jive() {
146 		jive = false;
147 	}
148 
get_ticks()149 	inline static unsigned int get_ticks() {
150 		return ticks;
151 	}
set_ticks(unsigned int t)152 	inline static void set_ticks(unsigned int t) {
153 		ticks = t;
154 	}
155 };
156 
157 extern Game *game;
158 extern int wait_delay(int ms, int startcol = 0, int ncol = 0, int rotspd = 100);
159 extern Exult_Game exult_menu(Game_window *gwin);
160 
161 #endif
162