1 #ifndef __BT_GAME_H__ 2 #define __BT_GAME_H__ 3 4 /* Battle Tanks Game 5 * Copyright (C) 2006-2009 Battle Tanks team 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 /* 23 * Additional rights can be granted beyond the GNU General Public License 24 * on the terms provided in the Exception. If you modify this file, 25 * you may extend this exception to your version of the file, 26 * but you are not obligated to do so. If you do not wish to provide this 27 * exception without modification, you must delete this exception statement 28 * from your version and license this file solely under the GPL without exception. 29 */ 30 31 #include "mrt/singleton.h" 32 #include <string> 33 #include <map> 34 #include <vector> 35 #include <set> 36 #include <list> 37 38 #include "math/v2.h" 39 #include "player_state.h" 40 #include "alarm.h" 41 42 #include "export_btanks.h" 43 #include "sdlx/sdlx.h" 44 #include "sl08/sl08.h" 45 46 #include "random_pool.h" 47 48 class BaseObject; 49 class Object; 50 class Message; 51 class Server; 52 class Client; 53 class Connection; 54 class ControlMethod; 55 class PlayerSlot; 56 class Hud; 57 class Cheater; 58 class MainMenu; 59 class Tooltip; 60 class Chat; 61 class Logo; 62 63 namespace sdlx { 64 class Surface; 65 class Rect; 66 class Font; 67 } 68 69 struct Cutscene { 70 virtual void render(const float dt, sdlx::Surface &surface) = 0; 71 virtual bool finished() const = 0; ~CutsceneCutscene72 virtual ~Cutscene() {} 73 }; 74 75 class BTANKSAPI IGame { 76 77 public: 78 DECLARE_SINGLETON(IGame); 79 80 void init(const int argc, char *argv[]); 81 void resource_init(); 82 void run(); 83 void deinit(); 84 85 void clear(); 86 void pause(); 87 88 IGame(); 89 ~IGame(); 90 91 //stupid visual effect 92 void shake(const float duration, const int intensity); 93 94 static void loadPlugins(); 95 getChat()96 Chat *getChat() { return _net_talk; } 97 98 void stop(); 99 100 void add_logo(sdlx::Surface * surface, float duration, Uint32 color, bool fade = true); 101 102 private: 103 sl08::slot1<void, const int, IGame> reset_slot; 104 void resetLoadingBar(const int total); 105 106 sl08::slot2<void, const int, const char *, IGame> notify_slot; 107 void notifyLoadingBar(const int progress, const char *what); 108 109 sl08::slot1<bool, float, IGame> on_tick_slot; 110 bool onTick(float dt); 111 sl08::slot1<bool, float, IGame> on_logo_tick_slot; 112 bool logo_tick(float dt); 113 bool tick(float dt); 114 115 sl08::slot2<bool, const SDL_keysym, const bool, IGame> on_key_slot; 116 bool onKey(const SDL_keysym sym, const bool pressed); 117 118 sl08::slot3<void, const int, const int, const bool, IGame> on_joy_slot; 119 void onJoyButton(const int, const int, const bool); 120 121 sl08::slot4<bool, const int, const bool, const int, const int, IGame> on_mouse_slot; 122 bool onMouse(const int button, const bool pressed, const int x, const int y); 123 124 sl08::slot5<bool, const int, const int, const int, const int, const int, IGame> on_mouse_motion_slot; 125 bool onMouseMotion(const int state, const int x, const int y, const int xrel, const int yrel); 126 127 sl08::slot1<void, const std::string &, IGame> on_menu_slot; 128 void onMenu(const std::string &name); 129 130 sl08::slot0<void, IGame> on_map_slot; 131 void onMap(); 132 133 sl08::slot2<const std::string, const std::string &, const std::string &, IGame> on_console_slot; 134 const std::string onConsole(const std::string &cmd, const std::string ¶m); 135 136 sl08::slot1<void, const SDL_Event &, IGame> on_event_slot; 137 void onEvent(const SDL_Event &event); 138 139 void quit(); 140 141 void stop_cutscene(); 142 void parse_logos(); 143 144 bool _paused; 145 146 MainMenu *_main_menu; 147 148 bool _show_fps; 149 const sdlx::Font * small_font; 150 151 bool _autojoin; 152 std::string _address; 153 154 float _shake, _shake_max; 155 int _shake_int; 156 157 Hud *_hud; 158 bool _show_stats; 159 int _loading_bar_total, _loading_bar_now; 160 161 Cutscene *_cutscene; 162 Cheater *_cheater; 163 164 Tooltip *_tip; 165 Chat *_net_talk; 166 bool server_running; 167 int spawn_ai; 168 169 std::vector<std::string> preload_map; 170 RandomPool<size_t> preload_map_pool; 171 void start_random_map(); 172 173 IGame(const IGame &); 174 const IGame& operator=(const IGame &); 175 176 std::list<Logo *> _logos; 177 bool _need_postinit, _quit; 178 }; 179 180 PUBLIC_SINGLETON(BTANKSAPI, Game, IGame); 181 182 #endif 183 184