mp_game_settings.cpp

Go to the documentation of this file.
00001 /* $Id: mp_game_settings.cpp 54051 2012-04-30 21:52:38Z brilliand $ */
00002 /*
00003    Copyright (C) 2006 - 2012 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
00004    wesnoth playlevel Copyright (C) 2003 by David White <dave@whitevine.net>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 /**
00018  *  @file
00019  *  Container for multiplayer game-creation parameters.
00020  */
00021 
00022 #include "mp_game_settings.hpp"
00023 
00024 mp_game_settings::mp_game_settings() :
00025     savegame_config(),
00026     name(),
00027     password(),
00028     hash(),
00029     mp_era(),
00030     mp_scenario(),
00031     village_gold(0),
00032     village_support(1),
00033     xp_modifier(0),
00034     mp_countdown_init_time(0),
00035     mp_countdown_reservoir_time(0),
00036     mp_countdown_turn_bonus(0),
00037     mp_countdown_action_bonus(0),
00038     mp_countdown(false),
00039     use_map_settings(false),
00040     random_start_time(false),
00041     fog_game(false),
00042     shroud_game(false),
00043     allow_observers(false),
00044     shuffle_sides(false),
00045     share_view(false),
00046     share_maps(false),
00047     saved_game(false),
00048     scenario_data()
00049 
00050 { reset(); }
00051 
00052 mp_game_settings::mp_game_settings(const config& cfg) :
00053     savegame_config(),
00054     name(),
00055     password(),
00056     hash(),
00057     mp_era(),
00058     mp_scenario(),
00059     village_gold(0),
00060     village_support(1),
00061     xp_modifier(0),
00062     mp_countdown_init_time(0),
00063     mp_countdown_reservoir_time(0),
00064     mp_countdown_turn_bonus(0),
00065     mp_countdown_action_bonus(0),
00066     mp_countdown(false),
00067     use_map_settings(false),
00068     random_start_time(false),
00069     fog_game(false),
00070     shroud_game(false),
00071     allow_observers(false),
00072     shuffle_sides(false),
00073     share_view(false),
00074     share_maps(false),
00075     saved_game(false),
00076     scenario_data()
00077 {
00078     set_from_config(cfg);
00079 }
00080 
00081 mp_game_settings::mp_game_settings(const mp_game_settings& settings)
00082     : savegame_config()
00083     , name(settings.name)
00084     , password(settings.password)
00085     , hash(settings.hash)
00086     , mp_era(settings.mp_era)
00087     , mp_scenario(settings.mp_scenario)
00088     , village_gold(settings.village_gold)
00089     , village_support(settings.village_support)
00090     , xp_modifier(settings.xp_modifier)
00091     , mp_countdown_init_time(settings.mp_countdown_init_time)
00092     , mp_countdown_reservoir_time(settings.mp_countdown_reservoir_time)
00093     , mp_countdown_turn_bonus(settings.mp_countdown_turn_bonus)
00094     , mp_countdown_action_bonus(settings.mp_countdown_action_bonus)
00095     , mp_countdown(settings.mp_countdown)
00096     , use_map_settings(settings.use_map_settings)
00097     , random_start_time(settings.random_start_time)
00098     , fog_game(settings.fog_game)
00099     , shroud_game(settings.shroud_game)
00100     , allow_observers(settings.allow_observers)
00101     , shuffle_sides(settings.shuffle_sides)
00102     , share_view(settings.share_view)
00103     , share_maps(settings.share_maps)
00104     , saved_game(settings.saved_game)
00105     , scenario_data(settings.scenario_data)
00106 {
00107 }
00108 
00109 void mp_game_settings::set_from_config(const config& game_cfg)
00110 {
00111     const config& mp = game_cfg.child("multiplayer");
00112     const config& rs = game_cfg.child("replay_start");
00113     // if it's a replay the multiplayer section can be in the replay_start tag else fallback to top level
00114     const config& cfg = mp ? mp : rs ? (rs.child("multiplayer") ? rs.child("multiplayer") : game_cfg) : game_cfg;
00115     name = cfg["scenario"].str();
00116     hash = cfg["hash"].str();
00117     mp_era = cfg["mp_era"].str();
00118     mp_scenario = cfg["mp_scenario"].str();
00119     xp_modifier = cfg["experience_modifier"];
00120     use_map_settings = cfg["mp_use_map_settings"].to_bool();
00121     fog_game = cfg["mp_fog"].to_bool();
00122     shroud_game = cfg["mp_shroud"].to_bool();
00123     mp_countdown = cfg["mp_countdown"].to_bool();
00124     mp_countdown_init_time = cfg["mp_countdown_init_time"];
00125     mp_countdown_turn_bonus = cfg["mp_countdown_turn_bonus"];
00126     mp_countdown_reservoir_time = cfg["mp_countdown_reservoir_time"];
00127     mp_countdown_action_bonus = cfg["mp_countdown_action_bonus"];
00128     village_gold = cfg["mp_village_gold"];
00129     village_support = cfg["mp_village_support"];
00130     allow_observers = cfg["observer"].to_bool();
00131     shuffle_sides = cfg["shuffle_sides"].to_bool();
00132     saved_game = cfg["savegame"].to_bool();
00133 }
00134 
00135 void mp_game_settings::reset()
00136 {
00137     name = "";
00138     password = "";
00139     hash = "";
00140     mp_era = "";
00141     mp_scenario = "";
00142     village_gold = 0;
00143     village_support = 1;
00144     xp_modifier = 0;
00145     mp_countdown_init_time=0;
00146     mp_countdown_reservoir_time=0;
00147     mp_countdown_turn_bonus=0;
00148     mp_countdown_action_bonus=0;
00149     mp_countdown=false;
00150     use_map_settings = random_start_time = fog_game = shroud_game = allow_observers = shuffle_sides = share_view = share_maps = false;
00151 
00152     scenario_data.clear();
00153 }
00154 
00155 config mp_game_settings::to_config() const
00156 {
00157     config cfg;
00158 
00159     cfg["scenario"] = name;
00160     cfg["hash"] = hash;
00161     cfg["mp_era"] = mp_era;
00162     cfg["mp_scenario"] = mp_scenario;
00163     cfg["experience_modifier"] = xp_modifier;
00164     cfg["mp_countdown"] = mp_countdown;
00165     cfg["mp_countdown_init_time"] = mp_countdown_init_time;
00166     cfg["mp_countdown_turn_bonus"] = mp_countdown_turn_bonus;
00167     cfg["mp_countdown_reservoir_time"] = mp_countdown_reservoir_time;
00168     cfg["mp_countdown_action_bonus"] = mp_countdown_action_bonus;
00169     cfg["mp_village_gold"] = village_gold;
00170     cfg["mp_village_support"] = village_support;
00171     cfg["mp_fog"] = fog_game;
00172     cfg["mp_shroud"] = shroud_game;
00173     cfg["mp_use_map_settings"] = use_map_settings;
00174     cfg["observer"] = allow_observers;
00175     cfg["shuffle_sides"] = shuffle_sides;
00176     cfg["savegame"] = saved_game;
00177 
00178     return cfg;
00179 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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