gamestatus.hpp

Go to the documentation of this file.
00001 /* $Id: gamestatus.hpp 53318 2012-02-29 08:08:39Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file */
00017 
00018 #ifndef GAME_STATUS_HPP_INCLUDED
00019 #define GAME_STATUS_HPP_INCLUDED
00020 
00021 #include "mp_game_settings.hpp"
00022 #include "random.hpp"
00023 #include "simple_rng.hpp"
00024 #include "map_location.hpp"
00025 #include "variable.hpp"
00026 #include "serialization/binary_or_text.hpp"
00027 #include "boost/shared_ptr.hpp"
00028 
00029 class scoped_wml_variable;
00030 class team;
00031 class gamemap;
00032 namespace t_translation {
00033     struct t_match;
00034 }
00035 
00036 class team_builder;
00037 typedef boost::shared_ptr<team_builder> team_builder_ptr;
00038 
00039 //meta information of the game
00040 class game_classification : public savegame::savegame_config
00041 {
00042 public:
00043     game_classification();
00044     game_classification(const config& cfg);
00045     game_classification(const game_classification& gc);
00046 
00047     config to_config() const;
00048 
00049     std::string label;                               /**< Name of the game (e.g. name of save file). */
00050     std::string parent;                              /**< Parent of the game (for save-threading purposes). */
00051     std::string version;                             /**< Version game was created with. */
00052     std::string campaign_type;                       /**< Type of the game - campaign, multiplayer etc. */
00053     std::string campaign_define;                     /**< If there is a define the campaign uses to customize data */
00054     std::vector<std::string> campaign_xtra_defines;  /**< more customization of data */
00055 
00056     std::string campaign;                            /**< the campaign being played */
00057     std::string history;                             /**< ancestral IDs */
00058     std::string abbrev;                              /**< the campaign abbreviation */
00059     std::string scenario;                            /**< the scenario being played */
00060     std::string next_scenario;                       /**< the scenario coming next (for campaigns) */
00061     std::string completion;                          /**< running. victory, or defeat */
00062     bool end_credits;                                /**< whether to show the standard credits at the end */
00063     std::string end_text;                            /**< end-of-campaign text */
00064     unsigned int end_text_duration;                  /**< for how long the end-of-campaign text is shown */
00065     std::string difficulty; /**< The difficulty level the game is being played on. */
00066 };
00067 
00068 struct wml_menu_item
00069 {
00070     wml_menu_item(const std::string& id, const config* cfg=NULL);
00071     std::string name;
00072     const std::string event_id;
00073     std::string image;
00074     t_string description;
00075     bool needs_select;
00076     config show_if;
00077     config filter_location;
00078     config command;
00079 };
00080 
00081 class game_state : public variable_set
00082 {
00083 public:
00084     game_state();
00085     game_state(const game_state& state);
00086     game_state(const config& cfg, bool show_replay = false);
00087 
00088     ~game_state();
00089     game_state& operator=(const game_state& state);
00090 
00091     std::vector<scoped_wml_variable*> scoped_variables;
00092     std::map<std::string, wml_menu_item*> wml_menu_items;
00093 
00094     const config& get_variables() const { return variables_; }
00095     void set_variables(const config& vars);
00096 
00097     void set_menu_items(const config::const_child_itors &menu_items);
00098 
00099     //write the gamestate into a config object
00100     void write_snapshot(config& cfg) const;
00101     //write the config information into a stream (file)
00102     void write_config(config_writer& out, bool write_variables=true) const;
00103 
00104     // Variable access
00105 
00106     config::attribute_value &get_variable(const std::string &varname);
00107     virtual config::attribute_value get_variable_const(const std::string& varname) const;
00108     config& get_variable_cfg(const std::string& varname);
00109 
00110     void set_variable(const std::string& varname, const t_string& value);
00111     config& add_variable_cfg(const std::string& varname, const config& value=config());
00112 
00113     void clear_variable(const std::string& varname);
00114     void clear_variable_cfg(const std::string& varname); // Clears only the config children
00115 
00116     const rand_rng::simple_rng& rng() const { return rng_; }
00117     rand_rng::simple_rng& rng() { return rng_; }
00118 
00119     enum PHASE {
00120         INITIAL,
00121         PRELOAD,
00122         PRESTART,
00123         START,
00124         PLAY
00125     };
00126     PHASE phase() const { return phase_; }
00127     void set_phase(PHASE phase) { phase_ = phase; }
00128 
00129     //create an object responsible for creating and populating a team from a config
00130     team_builder_ptr create_team_builder(const config& side_cfg, std::string save_id
00131             , std::vector<team>& teams, const config& level, gamemap& map
00132             , unit_map& units, bool snapshot);
00133 
00134     //do first stage of team initialization (everything except unit placement)
00135     void build_team_stage_one(team_builder_ptr tb_ptr);
00136 
00137     //do second stage of team initialization (unit placement)
00138     void build_team_stage_two(team_builder_ptr tb_ptr);
00139 
00140     game_classification& classification() { return classification_; }
00141     const game_classification& classification() const { return classification_; } //FIXME: const getter to allow use from const gamestatus::sog() (see ai.cpp:344) - remove after merge?
00142 
00143     /** Multiplayer parameters for this game */
00144     mp_game_settings& mp_settings() { return mp_settings_; }
00145     const mp_game_settings& mp_settings() const { return mp_settings_; }
00146 
00147     bool allow_end_turn() const { return can_end_turn_; }
00148     void set_allow_end_turn(bool value) { can_end_turn_ = value; }
00149 
00150     /**
00151      * If the game is saved mid-level, we have a series of replay steps
00152      * to take the game up to the position it was saved at.
00153      */
00154     config replay_data;
00155 
00156     /**
00157      * Saved starting state of the game.
00158      *
00159      * For multiplayer games, the position the game started in may be different
00160      * to the scenario.
00161      */
00162     config starting_pos;
00163 
00164     /**
00165      * Snapshot of the game's current contents.
00166      *
00167      * i.e. unless the player selects to view a replay, the game's settings are
00168      * read in from this object.
00169      */
00170     config snapshot;
00171 
00172     /** the last location where a select event fired. */
00173     map_location last_selected;
00174 
00175 private:
00176     rand_rng::simple_rng rng_;
00177     config variables_;
00178     mutable config temporaries_; // lengths of arrays, etc.
00179     const rand_rng::set_random_generator generator_setter_; /**< Make sure that rng is initialized first */
00180     friend struct variable_info;
00181     game_classification classification_;
00182     mp_game_settings mp_settings_;
00183     PHASE phase_;
00184     bool can_end_turn_;
00185 };
00186 
00187 
00188 void write_players(game_state& gamestate, config& cfg, const bool use_snapshot=true, const bool merge_side = false);
00189 
00190 void extract_summary_from_config(config& cfg_save, config& cfg_summary);
00191 
00192 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:53 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs