1 /* 2 * modmgr.h - Mod manager for Exult. 3 * 4 * Copyright (C) 2006 The Exult Team 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 21 #ifndef MODMGR_H 22 #define MODMGR_H 23 24 #include "Configuration.h" 25 #include "exceptions.h" 26 #include "exult_constants.h" 27 28 #include <string> 29 #include <utility> 30 #include <vector> 31 32 extern Configuration *config; 33 34 class BaseGameInfo { 35 protected: 36 Exult_Game type = NONE; // Game type 37 Game_Language language = ENGLISH; // Official translation language 38 std::string cfgname; // What the game is called in Exult.cfg 39 std::string path_prefix; // System path prefix for the game/mod. 40 std::string mod_title; // Internal mod name, the mod's title 41 std::string menustring; // Text displayed in mods menu 42 bool expansion = false; // For FoV/SS ONLY. 43 bool sibeta = false; // For beta version of SI. 44 bool found = false; // If the game/mod is found. 45 bool editing = false; // Game is being edited and may have missing files. 46 std::string codepage = "CP437"; // Game/mod codepage (mainly for ES). 47 public: 48 BaseGameInfo() = default; BaseGameInfo(const Exult_Game ty,const Game_Language lang,std::string cf,std::string mt,std::string pt,std::string ms,bool exp,bool sib,bool f,bool ed,std::string cp)49 BaseGameInfo( 50 const Exult_Game ty, const Game_Language lang, std::string cf, 51 std::string mt, std::string pt, std::string ms, bool exp, bool sib, 52 bool f, bool ed, std::string cp) 53 : type(ty), language(lang), cfgname(std::move(cf)), 54 path_prefix(std::move(pt)), mod_title(std::move(mt)), 55 menustring(std::move(ms)), expansion(exp), sibeta(sib), found(f), 56 editing(ed), codepage(std::move(cp)) 57 { } 58 BaseGameInfo(const BaseGameInfo &) = default; 59 virtual ~BaseGameInfo() = default; 60 get_cfgname()61 std::string get_cfgname() const { 62 return cfgname; 63 } get_path_prefix()64 std::string get_path_prefix() const { 65 return path_prefix; 66 } get_mod_title()67 std::string get_mod_title() const { 68 return mod_title; 69 } get_menu_string()70 std::string get_menu_string() const { 71 return menustring; 72 } get_game_type()73 Exult_Game get_game_type() const { 74 return type; 75 } get_game_language()76 Game_Language get_game_language() const { 77 return language; 78 } get_codepage()79 std::string get_codepage() const { 80 return codepage; 81 } 82 // For FoV/SS ONLY. have_expansion()83 bool have_expansion() const { 84 return expansion; 85 } is_si_beta()86 bool is_si_beta() const { 87 return sibeta; 88 } is_there()89 bool is_there() const { 90 return found; 91 } being_edited()92 bool being_edited() const { 93 return editing; 94 } set_cfgname(const std::string & name)95 void set_cfgname(const std::string &name) { 96 cfgname = name; 97 } set_path_prefix(const std::string & pt)98 void set_path_prefix(const std::string &pt) { 99 path_prefix = pt; 100 } set_mod_title(const std::string & mod)101 void set_mod_title(const std::string &mod) { 102 mod_title = mod; 103 } set_menu_string(const std::string & menu)104 void set_menu_string(const std::string &menu) { 105 menustring = menu; 106 } set_game_type(Exult_Game game)107 void set_game_type(Exult_Game game) { 108 type = game; 109 } set_game_language(Game_Language lang)110 void set_game_language(Game_Language lang) { 111 language = lang; 112 } 113 // For FoV/SS ONLY. set_expansion(bool tf)114 void set_expansion(bool tf) { 115 expansion = tf; 116 } set_si_beta(bool tf)117 void set_si_beta(bool tf) { 118 sibeta = tf; 119 } set_found(bool tf)120 void set_found(bool tf) { 121 found = tf; 122 } set_editing(bool tf)123 void set_editing(bool tf) { 124 editing = tf; 125 } set_codepage(const std::string & cp)126 void set_codepage(const std::string &cp) { 127 codepage = cp; 128 } 129 130 void setup_game_paths(); 131 132 virtual bool get_config_file(Configuration *&cfg, std::string &root) = 0; 133 }; 134 135 class ModInfo : public BaseGameInfo { 136 protected: 137 std::string configfile; 138 bool compatible; 139 public: 140 ModInfo(Exult_Game game, Game_Language lang, const std::string &name, const std::string &mod, 141 const std::string &path, bool exp, bool sib, bool ed, const std::string &cfg); 142 is_mod_compatible()143 bool is_mod_compatible() const { 144 return compatible; 145 } 146 get_config_file(Configuration * & cfg,std::string & root)147 bool get_config_file(Configuration *&cfg, std::string &root) override { 148 cfg = new Configuration(configfile, "modinfo"); 149 root = "mod_info/"; 150 return true; 151 } 152 }; 153 154 class ModManager : public BaseGameInfo { 155 protected: 156 std::vector<ModInfo> modlist; 157 public: 158 ModManager(const std::string &name, const std::string &menu, bool needtitle, 159 bool silent = false); 160 ModManager() = default; 161 get_mod_list()162 std::vector<ModInfo> &get_mod_list() { 163 return modlist; 164 } 165 ModInfo *find_mod(const std::string &name); 166 int find_mod_index(const std::string &name); 167 has_mods()168 bool has_mods() const { 169 return !modlist.empty(); 170 } get_mod(int i)171 ModInfo *get_mod(int i) { 172 return &(modlist.at(i)); 173 } 174 BaseGameInfo *get_mod(const std::string &name, bool checkversion = true); begin()175 auto begin() { 176 return modlist.begin(); 177 } begin()178 auto begin() const { 179 return modlist.begin(); 180 } cbegin()181 auto cbegin() const { 182 return modlist.cbegin(); 183 } end()184 auto end() { 185 return modlist.end(); 186 } end()187 auto end() const { 188 return modlist.end(); 189 } cend()190 auto cend() const { 191 return modlist.cend(); 192 } 193 void add_mod(const std::string &mod, const std::string &modconfig); 194 195 void get_game_paths(const std::string &game_path); 196 void gather_mods(); 197 get_config_file(Configuration * & cfg,std::string & root)198 bool get_config_file(Configuration *&cfg, std::string &root) override { 199 cfg = config; 200 root = "config/disk/game/" + cfgname + "/"; 201 return false; 202 } 203 }; 204 205 class GameManager : nonreplicatable { 206 protected: 207 // -> to original games. 208 ModManager *bg; 209 ModManager *fov; 210 ModManager *si; 211 ModManager *ss; 212 ModManager *sib; 213 std::vector<ModManager> games; 214 void print_found(ModManager *game, const char *flex, 215 const char *title, const char *cfgname, const char *basepath, 216 bool silent); 217 public: 218 GameManager(bool silent = false); 219 get_game_list()220 std::vector<ModManager> &get_game_list() { 221 return games; 222 } get_game_count()223 int get_game_count() const { 224 return games.size(); 225 } get_game(int i)226 ModManager *get_game(int i) { 227 return &(games.at(i)); 228 } is_bg_installed()229 bool is_bg_installed() const { 230 return bg != nullptr; 231 } is_fov_installed()232 bool is_fov_installed() const { 233 return fov != nullptr; 234 } is_si_installed()235 bool is_si_installed() const { 236 return si != nullptr; 237 } is_ss_installed()238 bool is_ss_installed() const { 239 return ss != nullptr; 240 } is_sib_installed()241 bool is_sib_installed() const { 242 return sib != nullptr; 243 } 244 ModManager *find_game(const std::string &name); get_bg()245 ModManager *get_bg() { 246 return bg ? bg : fov; 247 } get_fov()248 ModManager *get_fov() { 249 return fov; 250 } get_si()251 ModManager *get_si() { 252 return si ? si : ss; 253 } get_ss()254 ModManager *get_ss() { 255 return ss; 256 } get_sib()257 ModManager *get_sib() { 258 return sib; 259 } 260 int find_game_index(const std::string &name); 261 void add_game(const std::string &name, const std::string &menu); 262 }; 263 264 #endif 265