Replay fixes,

...cleaned up config.cpp/config.hpp to make other applications compile again
This commit is contained in:
Jörg Hinrichs 2005-11-09 19:21:36 +00:00
parent 49a92e11be
commit 1f4a865e62
8 changed files with 26 additions and 179 deletions

View file

@ -10,6 +10,7 @@ SVN trunk:
* cleaned up prestart events to stop units hopping around at map setup
* user_interface
* added advancement and AMLA indicator icons, tooltips to dfool theme
* new replay functionality
* graphics
* new title screen and logo
* changed the storm trident attack icon from fireball to lightingbolt

View file

@ -41,6 +41,7 @@ wesnoth_SOURCES = \
checksum.cpp \
clipboard.cpp \
config.cpp \
config_adapter.cpp \
cursor.cpp \
dialogs.cpp \
display.cpp \
@ -143,6 +144,7 @@ wesnoth_SOURCES = \
clipboard.hpp \
cursor.hpp \
config.hpp \
config_adapter.hpp \
dialogs.hpp \
display.hpp \
events.hpp \

View file

@ -17,19 +17,14 @@
#include <algorithm>
#include <sstream>
#include "config.hpp"
#include "game_errors.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "preferences.hpp"
#include "unit.hpp"
#include "util.hpp"
#include "wassert.hpp"
#include <iostream>
#define ERR_CF LOG_STREAM(err, config)
#define LOG_NG LOG_STREAM(info, engine)
config::config(const config& cfg)
{
@ -572,166 +567,6 @@ bool operator!=(const config& a, const config& b)
return !operator==(a,b);
}
std::string get_unique_saveid(const config& cfg, std::set<std::string>& seen_save_ids){
std::string save_id = cfg["save_id"];
if(save_id.empty()) {
save_id=cfg["description"];
}
//make sure the 'save_id' is unique
while(seen_save_ids.count(save_id)) {
save_id += "_";
}
return save_id;
}
void get_player_info(const config& cfg, game_state& gamestate, std::string save_id, std::vector<team>& teams, const config& level, const game_data& gameinfo, gamemap& map, unit_map& units){
player_info *player = NULL;
if(cfg["controller"] == "human" ||
cfg["controller"] == "network" ||
cfg["persistent"] == "1") {
player = gamestate.get_player(save_id);
if(player == NULL && !save_id.empty()) {
player = &gamestate.players[save_id];
}
}
LOG_NG << "initializing team...\n";
std::string gold = cfg["gold"];
if(gold.empty())
gold = "100";
LOG_NG << "found gold: '" << gold << "'\n";
int ngold = lexical_cast_default<int>(gold);
if(player != NULL && player->gold >= ngold) {
ngold = player->gold;
}
LOG_NG << "set gold to '" << ngold << "'\n";
teams.push_back(team(cfg,ngold));
//update/fix the recall list for this side, by setting the
//"side" of each unit in it to be the "side" of the player.
int side = lexical_cast_default<int>(cfg["side"], 1);
if(player != NULL) {
for(std::vector<unit>::iterator it = player->available_units.begin(); it != player->available_units.end(); ++it) {
it->set_side(side);
}
}
//if this team has no objectives, set its objectives to the
//level-global "objectives"
if(teams.back().objectives().empty())
teams.back().set_objectives(level["objectives"]);
//if this side tag describes the leader of the side
if(cfg["no_leader"] != "yes" && cfg["controller"] != "null") {
unit new_unit(gameinfo, cfg);
//search the recall list for leader units, and if there is
//one, use it in place of the config-described unit
if(player != NULL) {
for(std::vector<unit>::iterator it = player->available_units.begin(); it != player->available_units.end(); ++it) {
if(it->can_recruit()) {
new_unit = *it;
player->available_units.erase(it);
break;
}
}
}
//see if the side specifies its location. Otherwise start it at the map-given
//starting position
const std::string& has_loc = cfg["x"];
gamemap::location start_pos(cfg);
if(has_loc.empty()) {
start_pos = map.starting_position(side);
LOG_NG << "initializing side '" << cfg["side"] << "' at "
<< start_pos << '\n';
}
if(map.empty()) {
throw game::load_game_failed("Map not found");
}
if(!start_pos.valid() && new_unit.side() == 1) {
throw game::load_game_failed("No starting position for side 1");
}
if(start_pos.valid()) {
new_unit.new_turn();
units.insert(std::pair<gamemap::location,unit>(
map.starting_position(new_unit.side()), new_unit));
}
}
//if the game state specifies units that can be recruited for the player
//then add them
if(player != NULL && player->can_recruit.empty() == false) {
std::copy(player->can_recruit.begin(),player->can_recruit.end(),
std::inserter(teams.back().recruits(),teams.back().recruits().end()));
}
if(player != NULL) {
player->can_recruit = teams.back().recruits();
}
//if there are additional starting units on this side
const config::child_list& starting_units = cfg.get_children("unit");
for(config::child_list::const_iterator su = starting_units.begin(); su != starting_units.end(); ++su) {
unit new_unit(gameinfo,**su);
new_unit.set_side(side);
const std::string& x = (**su)["x"];
const std::string& y = (**su)["y"];
const gamemap::location loc(**su);
if(x.empty() || y.empty() || !map.on_board(loc)) {
if(player) {
player->available_units.push_back(new_unit);
}
} else {
units.insert(std::pair<gamemap::location,unit>(loc,new_unit));
LOG_NG << "inserting unit for side " << new_unit.side() << "\n";
}
}
}
int get_first_human_team(const config::child_list::const_iterator& cfg, const config::child_list& unit_cfg){
int result = -1;
const std::string& controller = (**cfg)["controller"];
if (controller == preferences::client_type() && (**cfg)["description"] == preferences::login()) {
result = cfg - unit_cfg.begin();
} else if(result == -1 && ((**cfg)["controller"] == "human" || (**cfg)["persistent"] == "1")) {
result = cfg - unit_cfg.begin();
}
return result;
}
const config* get_theme(const config& game_config, std::string theme_name){
const config* theme_cfg = NULL;
if(theme_name != "") {
theme_cfg = game_config.find_child("theme","name",theme_name);
}
if(theme_cfg == NULL) {
theme_cfg = game_config.find_child("theme","name",preferences::theme());
}
if (theme_cfg == NULL){
theme_cfg = new config();
}
return theme_cfg;
}
//#define TEST_CONFIG
#ifdef TEST_CONFIG

View file

@ -13,11 +13,9 @@
#ifndef CONFIG_HPP_INCLUDED
#define CONFIG_HPP_INCLUDED
#include <set>
#include <map>
#include <string>
#include <vector>
#include "map.hpp"
#include "tstring.hpp"
//This module defines the interface to Wesnoth Markup Language (WML).
@ -28,12 +26,6 @@
//sent across the network in this format. It is thus used extensively
//throughout the game.
class t_string;
class unit;
struct game_data;
struct game_state;
class team;
typedef std::map<std::string,t_string> string_map;
//a config object defines a single node in a WML file, with access to
@ -150,9 +142,4 @@ private:
bool operator==(const config& a, const config& b);
bool operator!=(const config& a, const config& b);
std::string get_unique_saveid(const config& cfg, std::set<std::string>& seen_save_ids);
int get_first_human_team(const config::child_list::const_iterator& cfg, const config::child_list& unit_cfg);
void get_player_info(const config& cfg, game_state& gamestate, std::string save_id, std::vector<team>& teams, const config& level, const game_data& gameinfo, gamemap& map, std::map<gamemap::location,unit>& units);
const config* get_theme(const config& game_config, std::string theme_name);
#endif

View file

@ -14,6 +14,7 @@
#include "global.hpp"
#include "ai_interface.hpp"
#include "config_adapter.hpp"
#include "cursor.hpp"
#include "dialogs.hpp"
#include "events.hpp"

View file

@ -1,6 +1,7 @@
#include "global.hpp"
#include "ai_interface.hpp"
#include "config_adapter.hpp"
#include "cursor.hpp"
#include "dialogs.hpp"
#include "events.hpp"

View file

@ -161,6 +161,10 @@ SOURCE=.\src\config.cpp
# End Source File
# Begin Source File
SOURCE=.\src\config_adapter.cpp
# End Source File
# Begin Source File
SOURCE=.\src\cursor.cpp
# End Source File
# Begin Source File
@ -581,6 +585,10 @@ SOURCE=.\src\config.hpp
# End Source File
# Begin Source File
SOURCE=.\src\config_adapter.hpp
# End Source File
# Begin Source File
SOURCE=.\src\cursor.hpp
# End Source File
# Begin Source File

View file

@ -1,5 +1,5 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
###############################################################################
@ -15,6 +15,18 @@ Package=<4>
###############################################################################
Project: "wesnothd"=.\wesnothd\wesnothd.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>