simplify game_state construction
instead of calling constructor and init you now only have to call the constructor. In order to make this work this commit removes the uses of resources::gameboard/units during team construction. while doing that i moved the unit_creator class to a new file. This commit also removes the ticks parameter from game_startes constructor and replaces it with a ticks() function in play_controller, other classes were also changed to use the play_controller::ticks() function.
This commit is contained in:
parent
99c75bf9ae
commit
20fafdee28
19 changed files with 381 additions and 272 deletions
|
@ -739,6 +739,7 @@ set(wesnoth-main_SRC
|
|||
actions/undo_recall_action.cpp
|
||||
actions/undo_recruit_action.cpp
|
||||
actions/undo_update_shroud_action.cpp
|
||||
actions/unit_creator.cpp
|
||||
actions/vision.cpp
|
||||
addon/client.cpp
|
||||
addon/info.cpp
|
||||
|
|
|
@ -198,6 +198,7 @@ wesnoth_sources = Split("""
|
|||
actions/undo_recall_action.cpp
|
||||
actions/undo_recruit_action.cpp
|
||||
actions/undo_update_shroud_action.cpp
|
||||
actions/unit_creator.cpp
|
||||
actions/vision.cpp
|
||||
addon/client.cpp
|
||||
addon/info.cpp
|
||||
|
|
|
@ -59,183 +59,8 @@ static lg::log_domain log_engine("engine");
|
|||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
unit_creator::unit_creator(team &tm, const map_location &start_pos)
|
||||
: add_to_recall_(false),discover_(false),get_village_(false),invalidate_(false), rename_side_(false), show_(false), start_pos_(start_pos), team_(tm)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_show(bool b)
|
||||
{
|
||||
show_=b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_get_village(bool b)
|
||||
{
|
||||
get_village_=b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_rename_side(bool b)
|
||||
{
|
||||
rename_side_=b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
unit_creator& unit_creator::allow_invalidate(bool b)
|
||||
{
|
||||
invalidate_=b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_discover(bool b)
|
||||
{
|
||||
discover_=b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_add_to_recall(bool b)
|
||||
{
|
||||
add_to_recall_=b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
map_location unit_creator::find_location(const config &cfg, const unit* pass_check)
|
||||
{
|
||||
|
||||
DBG_NG << "finding location for unit with id=["<<cfg["id"]<<"] placement=["<<cfg["placement"]<<"] x=["<<cfg["x"]<<"] y=["<<cfg["y"]<<"] for side " << team_.side() << "\n";
|
||||
|
||||
std::vector< std::string > placements = utils::split(cfg["placement"]);
|
||||
|
||||
placements.push_back("map");
|
||||
placements.push_back("recall");
|
||||
|
||||
BOOST_FOREACH(const std::string& place, placements) {
|
||||
map_location loc;
|
||||
|
||||
if ( place == "recall" ) {
|
||||
return map_location::null_location();
|
||||
}
|
||||
|
||||
else if ( place == "leader" || place == "leader_passable" ) {
|
||||
unit_map::const_iterator leader = resources::units->find_leader(team_.side());
|
||||
//todo: take 'leader in recall list' possibility into account
|
||||
if (leader.valid()) {
|
||||
loc = leader->get_location();
|
||||
} else {
|
||||
loc = start_pos_;
|
||||
}
|
||||
}
|
||||
|
||||
// "map", "map_passable", and "map_overwrite".
|
||||
else if ( place == "map" || place.compare(0, 4, "map_") == 0 ) {
|
||||
loc = map_location(cfg,resources::gamedata);
|
||||
}
|
||||
|
||||
if(loc.valid() && resources::gameboard->map().on_board(loc)) {
|
||||
const bool pass((place == "leader_passable") || (place == "map_passable"));
|
||||
if ( place != "map_overwrite" ) {
|
||||
loc = find_vacant_tile(loc, pathfind::VACANT_ANY,
|
||||
pass ? pass_check : NULL);
|
||||
}
|
||||
if(loc.valid() && resources::gameboard->map().on_board(loc)) {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map_location::null_location();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void unit_creator::add_unit(const config &cfg, const vconfig* vcfg)
|
||||
{
|
||||
config temp_cfg(cfg);
|
||||
temp_cfg["side"] = team_.side();
|
||||
temp_cfg.remove_attribute("player_id");
|
||||
temp_cfg.remove_attribute("faction_from_recruit");
|
||||
|
||||
const std::string& id =(cfg)["id"];
|
||||
bool animate = temp_cfg["animate"].to_bool();
|
||||
temp_cfg.remove_attribute("animate");
|
||||
|
||||
unit_ptr recall_list_element = team_.recall_list().find_if_matches_id(id);
|
||||
|
||||
if ( !recall_list_element ) {
|
||||
//make the new unit
|
||||
unit_ptr new_unit(new unit(temp_cfg, true, vcfg));
|
||||
map_location loc = find_location(temp_cfg, new_unit.get());
|
||||
if ( loc.valid() ) {
|
||||
//add the new unit to map
|
||||
resources::units->replace(loc, *new_unit);
|
||||
LOG_NG << "inserting unit for side " << new_unit->side() << "\n";
|
||||
post_create(loc,*(resources::units->find(loc)),animate);
|
||||
}
|
||||
else if ( add_to_recall_ ) {
|
||||
//add to recall list
|
||||
team_.recall_list().add(new_unit);
|
||||
DBG_NG << "inserting unit with id=["<<id<<"] on recall list for side " << new_unit->side() << "\n";
|
||||
preferences::encountered_units().insert(new_unit->type_id());
|
||||
}
|
||||
} else {
|
||||
//get unit from recall list
|
||||
map_location loc = find_location(temp_cfg, recall_list_element.get());
|
||||
if ( loc.valid() ) {
|
||||
resources::units->replace(loc, *recall_list_element);
|
||||
LOG_NG << "inserting unit from recall list for side " << recall_list_element->side()<< " with id="<< id << "\n";
|
||||
post_create(loc,*(resources::units->find(loc)),animate);
|
||||
//if id is not empty, delete units with this ID from recall list
|
||||
team_.recall_list().erase_if_matches_id( id);
|
||||
}
|
||||
else if ( add_to_recall_ ) {
|
||||
LOG_NG << "wanted to insert unit on recall list, but recall list for side " << (cfg)["side"] << "already contains id=" <<id<<"\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void unit_creator::post_create(const map_location &loc, const unit &new_unit, bool anim)
|
||||
{
|
||||
|
||||
if (discover_) {
|
||||
preferences::encountered_units().insert(new_unit.type_id());
|
||||
}
|
||||
|
||||
bool show = show_ && (resources::screen !=NULL) && !resources::screen->fogged(loc);
|
||||
bool animate = show && anim;
|
||||
|
||||
if (get_village_) {
|
||||
if (resources::gameboard->map().is_village(loc)) {
|
||||
actions::get_village(loc, new_unit.side());
|
||||
}
|
||||
}
|
||||
|
||||
if (resources::screen!=NULL) {
|
||||
|
||||
if (invalidate_ ) {
|
||||
resources::screen->invalidate(loc);
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
unit_display::unit_recruited(loc);
|
||||
} else if (show) {
|
||||
resources::screen->draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace actions {
|
||||
|
||||
|
||||
const std::set<std::string> get_recruits(int side, const map_location &recruit_loc)
|
||||
{
|
||||
const team & current_team = (*resources::teams)[side -1];
|
||||
|
|
|
@ -26,47 +26,11 @@ class team;
|
|||
class unit_type;
|
||||
class vconfig;
|
||||
|
||||
#include "unit_creator.hpp"
|
||||
|
||||
#include "../map_location.hpp"
|
||||
#include "../unit_ptr.hpp"
|
||||
|
||||
|
||||
class unit_creator {
|
||||
public:
|
||||
unit_creator(team &tm, const map_location &start_pos);
|
||||
unit_creator& allow_show(bool b);
|
||||
unit_creator& allow_get_village(bool b);
|
||||
unit_creator& allow_rename_side(bool b);
|
||||
unit_creator& allow_invalidate(bool b);
|
||||
unit_creator& allow_discover(bool b);
|
||||
unit_creator& allow_add_to_recall(bool b);
|
||||
|
||||
/**
|
||||
* finds a suitable location for unit
|
||||
* @retval map_location::null_location() if unit is to be put into recall list
|
||||
* @retval valid on-board map location otherwise
|
||||
*/
|
||||
map_location find_location(const config &cfg, const unit* pass_check=NULL);
|
||||
|
||||
|
||||
/**
|
||||
* adds a unit on map without firing any events (so, usable during team construction in gamestatus)
|
||||
*/
|
||||
void add_unit(const config &cfg, const vconfig* vcfg = NULL);
|
||||
|
||||
private:
|
||||
void post_create(const map_location &loc, const unit &new_unit, bool anim);
|
||||
|
||||
bool add_to_recall_;
|
||||
bool discover_;
|
||||
bool get_village_;
|
||||
bool invalidate_;
|
||||
bool rename_side_;
|
||||
bool show_;
|
||||
const map_location start_pos_;
|
||||
team &team_;
|
||||
|
||||
};
|
||||
|
||||
namespace actions {
|
||||
|
||||
/// The possible results of finding a location for recruiting (or recalling).
|
||||
|
|
230
src/actions/unit_creator.cpp
Normal file
230
src/actions/unit_creator.cpp
Normal file
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2015 by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Recruiting, recalling.
|
||||
*/
|
||||
|
||||
#include "unit_creator.hpp"
|
||||
|
||||
#include "move.hpp" //for actions::get_village
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../filter_context.hpp"
|
||||
#include "../game_board.hpp"
|
||||
#include "../game_preferences.hpp"
|
||||
#include "../game_data.hpp" // for resources::gamedata conversion variable_set
|
||||
#include "../gettext.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../map.hpp"
|
||||
#include "../pathfind/pathfind.hpp"
|
||||
#include "../resources.hpp" // for resources::screen, resources::gamedata
|
||||
#include "../team.hpp" //for team
|
||||
#include "../unit.hpp" // for unit
|
||||
#include "../unit_display.hpp" // for unit_display
|
||||
#include "../variable.hpp" // for vconfig
|
||||
|
||||
#include "../game_display.hpp" // for resources::screen
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
unit_creator::unit_creator(team &tm, const map_location &start_pos, game_board* board)
|
||||
: add_to_recall_(false)
|
||||
, discover_(false)
|
||||
, get_village_(false)
|
||||
, invalidate_(false)
|
||||
, rename_side_(false)
|
||||
, show_(false)
|
||||
, start_pos_(start_pos)
|
||||
, team_(tm)
|
||||
, board_(board ? board : resources::gameboard)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_show(bool b)
|
||||
{
|
||||
show_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_get_village(bool b)
|
||||
{
|
||||
get_village_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_rename_side(bool b)
|
||||
{
|
||||
rename_side_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
unit_creator& unit_creator::allow_invalidate(bool b)
|
||||
{
|
||||
invalidate_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_discover(bool b)
|
||||
{
|
||||
discover_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
unit_creator& unit_creator::allow_add_to_recall(bool b)
|
||||
{
|
||||
add_to_recall_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
map_location unit_creator::find_location(const config &cfg, const unit* pass_check)
|
||||
{
|
||||
|
||||
DBG_NG << "finding location for unit with id=["<<cfg["id"]<<"] placement=["<<cfg["placement"]<<"] x=["<<cfg["x"]<<"] y=["<<cfg["y"]<<"] for side " << team_.side() << "\n";
|
||||
|
||||
std::vector<std::string> placements = utils::split(cfg["placement"]);
|
||||
|
||||
placements.push_back("map");
|
||||
placements.push_back("recall");
|
||||
|
||||
BOOST_FOREACH(const std::string& place, placements)
|
||||
{
|
||||
map_location loc;
|
||||
|
||||
if ( place == "recall" ) {
|
||||
return map_location::null_location();
|
||||
}
|
||||
|
||||
else if ( place == "leader" || place == "leader_passable" ) {
|
||||
unit_map::const_iterator leader = board_->units().find_leader(team_.side());
|
||||
//todo: take 'leader in recall list' possibility into account
|
||||
if (leader.valid()) {
|
||||
loc = leader->get_location();
|
||||
} else {
|
||||
loc = start_pos_;
|
||||
}
|
||||
}
|
||||
|
||||
// "map", "map_passable", and "map_overwrite".
|
||||
else if ( place == "map" || place.compare(0, 4, "map_") == 0 ) {
|
||||
loc = map_location(cfg, resources::gamedata);
|
||||
}
|
||||
|
||||
if(loc.valid() && board_->map().on_board(loc)) {
|
||||
const bool pass((place == "leader_passable") || (place == "map_passable"));
|
||||
if ( place != "map_overwrite" ) {
|
||||
loc = find_vacant_tile(loc, pathfind::VACANT_ANY,
|
||||
pass ? pass_check : NULL, NULL, board_);
|
||||
}
|
||||
if(loc.valid() && board_->map().on_board(loc)) {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map_location::null_location();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void unit_creator::add_unit(const config &cfg, const vconfig* vcfg)
|
||||
{
|
||||
config temp_cfg(cfg);
|
||||
temp_cfg["side"] = team_.side();
|
||||
temp_cfg.remove_attribute("player_id");
|
||||
temp_cfg.remove_attribute("faction_from_recruit");
|
||||
|
||||
const std::string& id =(cfg)["id"];
|
||||
bool animate = temp_cfg["animate"].to_bool();
|
||||
temp_cfg.remove_attribute("animate");
|
||||
|
||||
unit_ptr recall_list_element = team_.recall_list().find_if_matches_id(id);
|
||||
|
||||
if ( !recall_list_element ) {
|
||||
//make the new unit
|
||||
unit_ptr new_unit(new unit(temp_cfg, true, vcfg, &board_->unit_id_manager()));
|
||||
map_location loc = find_location(temp_cfg, new_unit.get());
|
||||
if ( loc.valid() ) {
|
||||
//add the new unit to map
|
||||
board_->units().replace(loc, *new_unit);
|
||||
LOG_NG << "inserting unit for side " << new_unit->side() << "\n";
|
||||
post_create(loc,*(board_->units().find(loc)),animate);
|
||||
}
|
||||
else if ( add_to_recall_ ) {
|
||||
//add to recall list
|
||||
team_.recall_list().add(new_unit);
|
||||
DBG_NG << "inserting unit with id=["<<id<<"] on recall list for side " << new_unit->side() << "\n";
|
||||
preferences::encountered_units().insert(new_unit->type_id());
|
||||
}
|
||||
} else {
|
||||
//get unit from recall list
|
||||
map_location loc = find_location(temp_cfg, recall_list_element.get());
|
||||
if ( loc.valid() ) {
|
||||
board_->units().replace(loc, *recall_list_element);
|
||||
LOG_NG << "inserting unit from recall list for side " << recall_list_element->side()<< " with id="<< id << "\n";
|
||||
post_create(loc,*(board_->units().find(loc)),animate);
|
||||
//if id is not empty, delete units with this ID from recall list
|
||||
team_.recall_list().erase_if_matches_id( id);
|
||||
}
|
||||
else if ( add_to_recall_ ) {
|
||||
LOG_NG << "wanted to insert unit on recall list, but recall list for side " << (cfg)["side"] << "already contains id=" <<id<<"\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void unit_creator::post_create(const map_location &loc, const unit &new_unit, bool anim)
|
||||
{
|
||||
|
||||
if (discover_) {
|
||||
preferences::encountered_units().insert(new_unit.type_id());
|
||||
}
|
||||
|
||||
bool show = show_ && (resources::screen !=NULL) && !resources::screen->fogged(loc);
|
||||
bool animate = show && anim;
|
||||
|
||||
if (get_village_) {
|
||||
assert(resources::gameboard);
|
||||
if (board_->map().is_village(loc)) {
|
||||
actions::get_village(loc, new_unit.side());
|
||||
}
|
||||
}
|
||||
|
||||
if (resources::screen!=NULL) {
|
||||
|
||||
if (invalidate_ ) {
|
||||
resources::screen->invalidate(loc);
|
||||
}
|
||||
|
||||
if (animate) {
|
||||
unit_display::unit_recruited(loc);
|
||||
} else if (show) {
|
||||
resources::screen->draw();
|
||||
}
|
||||
}
|
||||
}
|
68
src/actions/unit_creator.hpp
Normal file
68
src/actions/unit_creator.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2015 by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Various functions related to the creation of units (recruits, recalls,
|
||||
* and placed units).
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class config;
|
||||
class team;
|
||||
class vconfig;
|
||||
class game_board;
|
||||
class unit;
|
||||
|
||||
#include "../map_location.hpp"
|
||||
|
||||
class unit_creator
|
||||
{
|
||||
public:
|
||||
unit_creator(team &tm, const map_location &start_pos, game_board* board = NULL);
|
||||
unit_creator& allow_show(bool b);
|
||||
unit_creator& allow_get_village(bool b);
|
||||
unit_creator& allow_rename_side(bool b);
|
||||
unit_creator& allow_invalidate(bool b);
|
||||
unit_creator& allow_discover(bool b);
|
||||
unit_creator& allow_add_to_recall(bool b);
|
||||
|
||||
/**
|
||||
* finds a suitable location for unit
|
||||
* @retval map_location::null_location() if unit is to be put into recall list
|
||||
* @retval valid on-board map location otherwise
|
||||
*/
|
||||
map_location find_location(const config &cfg, const unit* pass_check=NULL);
|
||||
|
||||
|
||||
/**
|
||||
* adds a unit on map without firing any events (so, usable during team construction in gamestatus)
|
||||
*/
|
||||
void add_unit(const config &cfg, const vconfig* vcfg = NULL);
|
||||
|
||||
private:
|
||||
void post_create(const map_location &loc, const unit &new_unit, bool anim);
|
||||
|
||||
bool add_to_recall_;
|
||||
bool discover_;
|
||||
bool get_village_;
|
||||
bool invalidate_;
|
||||
bool rename_side_;
|
||||
bool show_;
|
||||
const map_location start_pos_;
|
||||
team &team_;
|
||||
game_board* board_;
|
||||
|
||||
};
|
|
@ -97,6 +97,7 @@ public:
|
|||
virtual const std::vector<team> & teams() const { return teams_; }
|
||||
virtual const gamemap & map() const { return *map_; }
|
||||
virtual const unit_map & units() const { return units_; }
|
||||
unit_map & units() { return units_; }
|
||||
virtual const std::vector<std::string> & hidden_label_categories() const { return labels_; }
|
||||
|
||||
// Copy and swap idiom, because we have a scoped pointer.
|
||||
|
|
|
@ -44,7 +44,7 @@ static lg::log_domain log_engine("engine");
|
|||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||
|
||||
game_state::game_state(const config & level, const tdata_cache & tdata) :
|
||||
game_state::game_state(const config & level, play_controller & pc, const tdata_cache & tdata) :
|
||||
gamedata_(level),
|
||||
board_(tdata, level),
|
||||
tod_manager_(level),
|
||||
|
@ -53,7 +53,9 @@ game_state::game_state(const config & level, const tdata_cache & tdata) :
|
|||
lua_kernel_(),
|
||||
events_manager_(),
|
||||
first_human_team_(-1)
|
||||
{}
|
||||
{
|
||||
init(pc.ticks(), pc, level);
|
||||
}
|
||||
|
||||
game_state::~game_state() {}
|
||||
|
||||
|
@ -160,7 +162,7 @@ void game_state::init(const int ticks, play_controller & pc, const config& level
|
|||
}
|
||||
}
|
||||
team_builder_ptr tb_ptr = create_team_builder(side,
|
||||
board_.teams_, level, *board_.map_);
|
||||
board_.teams_, level, board_);
|
||||
++team_num;
|
||||
build_team_stage_one(tb_ptr);
|
||||
team_builders.push_back(tb_ptr);
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
const game_events::wmi_container& get_wml_menu_items() const;
|
||||
int first_human_team_; //needed to initialize the viewpoint during setup
|
||||
|
||||
game_state(const config & level, const tdata_cache & tdata);
|
||||
game_state(const config & level, play_controller &, const tdata_cache & tdata);
|
||||
|
||||
~game_state();
|
||||
|
||||
|
|
|
@ -56,10 +56,14 @@ namespace pathfind {
|
|||
* team's shroud will be considered.
|
||||
*/
|
||||
map_location find_vacant_tile(const map_location& loc, VACANT_TILE_TYPE vacancy,
|
||||
const unit* pass_check, const team* shroud_check)
|
||||
const unit* pass_check, const team* shroud_check, const game_board* board)
|
||||
{
|
||||
const gamemap & map = resources::gameboard->map();
|
||||
const unit_map & units = *resources::units;
|
||||
if (!board) {
|
||||
board = resources::gameboard;
|
||||
assert(board);
|
||||
}
|
||||
const gamemap & map = board->map();
|
||||
const unit_map & units = board->units();
|
||||
|
||||
if (!map.on_board(loc)) return map_location();
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class gamemap;
|
|||
class team;
|
||||
class unit;
|
||||
class unit_type;
|
||||
|
||||
class game_board;
|
||||
#include "map_location.hpp"
|
||||
#include "movetype.hpp"
|
||||
|
||||
|
@ -43,7 +43,8 @@ enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
|
|||
map_location find_vacant_tile(const map_location& loc,
|
||||
VACANT_TILE_TYPE vacancy=VACANT_ANY,
|
||||
const unit* pass_check=NULL,
|
||||
const team* shroud_check=NULL);
|
||||
const team* shroud_check=NULL,
|
||||
const game_board* board=NULL);
|
||||
/// Wrapper for find_vacant_tile() when looking for a vacant castle tile
|
||||
/// near a leader.
|
||||
map_location find_vacant_castle(const unit & leader);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "game_events/menu_item.hpp"
|
||||
#include "game_events/pump.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "game_state.hpp"
|
||||
#include "hotkey/hotkey_item.hpp"
|
||||
#include "hotkey_handler.hpp"
|
||||
#include "map_label.hpp"
|
||||
|
@ -137,7 +138,8 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
|
|||
: controller_base(game_config, video)
|
||||
, observer()
|
||||
, savegame_config()
|
||||
, gamestate_(new game_state(level, tdata))
|
||||
, tdata_(tdata)
|
||||
, gamestate_()
|
||||
, level_()
|
||||
, saved_game_(state_of_game)
|
||||
, prefs_disp_manager_()
|
||||
|
@ -173,16 +175,11 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
|
|||
, player_type_changed_(false)
|
||||
{
|
||||
copy_persistent(level, level_);
|
||||
|
||||
resources::controller = this;
|
||||
resources::gameboard = &gamestate().board_;
|
||||
resources::gamedata = &gamestate().gamedata_;
|
||||
resources::persist = &persist_;
|
||||
resources::teams = &gamestate().board_.teams_;
|
||||
resources::tod_manager = &gamestate().tod_manager_;
|
||||
resources::undo_stack = undo_stack_.get();
|
||||
resources::recorder = replay_.get();
|
||||
resources::units = &gamestate().board_.units_;
|
||||
resources::filter_con = &gamestate();
|
||||
|
||||
resources::classification = &saved_game_.classification();
|
||||
resources::mp_settings = &saved_game_.mp_settings();
|
||||
|
@ -204,7 +201,7 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
|
|||
hotkey::deactivate_all_scopes();
|
||||
hotkey::set_scope_active(hotkey::SCOPE_GAME);
|
||||
try {
|
||||
init(video, level_);
|
||||
init(video, level);
|
||||
} catch (...) {
|
||||
clear_resources();
|
||||
throw;
|
||||
|
@ -229,23 +226,31 @@ void play_controller::init(CVideo& video, const config& level)
|
|||
|
||||
loadscreen::start_stage("load level");
|
||||
|
||||
LOG_NG << "initializing game_state..." << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
gamestate().init(ticks_, *this, level);
|
||||
LOG_NG << "initializing game_state..." << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
gamestate_.reset(new game_state(level, *this, tdata_));
|
||||
|
||||
resources::gameboard = &gamestate().board_;
|
||||
resources::gamedata = &gamestate().gamedata_;
|
||||
resources::teams = &gamestate().board_.teams_;
|
||||
resources::tod_manager = &gamestate().tod_manager_;
|
||||
resources::units = &gamestate().board_.units_;
|
||||
resources::filter_con = &gamestate();
|
||||
|
||||
resources::tunnels = gamestate().pathfind_manager_.get();
|
||||
|
||||
LOG_NG << "initializing whiteboard..." << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "initializing whiteboard..." << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
whiteboard_manager_.reset(new wb::manager());
|
||||
resources::whiteboard = whiteboard_manager_;
|
||||
|
||||
LOG_NG << "loading units..." << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "loading units..." << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
loadscreen::start_stage("load units");
|
||||
preferences::encounter_all_content(gamestate().board_);
|
||||
|
||||
LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
loadscreen::start_stage("init theme");
|
||||
const config &theme_cfg = controller_base::get_theme(game_config_, level["theme"]);
|
||||
|
||||
LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
loadscreen::start_stage("build terrain");
|
||||
gui_.reset(new game_display(gamestate().board_, video, whiteboard_manager_, *gamestate().reports_, gamestate().tod_manager_, theme_cfg, level));
|
||||
if (!gui_->video().faked()) {
|
||||
|
@ -260,9 +265,9 @@ void play_controller::init(CVideo& video, const config& level)
|
|||
menu_handler_.set_gui(gui_.get());
|
||||
resources::screen = gui_.get();
|
||||
|
||||
LOG_NG << "done initializing display... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "done initializing display... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
|
||||
LOG_NG << "building gamestate to gui and whiteboard... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "building gamestate to gui and whiteboard... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
//loadscreen::start_stage("build events manager & lua");
|
||||
// This *needs* to be created before the show_intro and show_map_scene
|
||||
// as that functions use the manager state_of_game
|
||||
|
@ -301,13 +306,13 @@ void play_controller::init(CVideo& video, const config& level)
|
|||
|
||||
void play_controller::init_managers()
|
||||
{
|
||||
LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
prefs_disp_manager_.reset(new preferences::display_manager(gui_.get()));
|
||||
tooltips_manager_.reset(new tooltips::manager(gui_->video()));
|
||||
soundsources_manager_.reset(new soundsource::manager(*gui_));
|
||||
|
||||
resources::soundsources = soundsources_manager_.get();
|
||||
LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks_) << std::endl;
|
||||
LOG_NG << "done initializing managers... " << (SDL_GetTicks() - ticks()) << std::endl;
|
||||
}
|
||||
|
||||
void play_controller::fire_preload(const config& level)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "controller_base.hpp"
|
||||
#include "floating_label.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_state.hpp"
|
||||
#include "help/help.hpp"
|
||||
#include "hotkey/command_executor.hpp"
|
||||
#include "menu_events.hpp"
|
||||
|
@ -27,6 +26,7 @@
|
|||
#include "persist_manager.hpp"
|
||||
#include "terrain_type_data.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "game_state.hpp"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
@ -219,6 +219,7 @@ public:
|
|||
|
||||
bool can_use_synced_wml_menu() const;
|
||||
std::set<std::string> all_players() const;
|
||||
int ticks() const { return ticks_; }
|
||||
protected:
|
||||
struct scoped_savegame_snapshot
|
||||
{
|
||||
|
@ -252,8 +253,11 @@ protected:
|
|||
bool is_team_visible(int team_num, bool observer) const;
|
||||
/// returns 0 if no such team was found.
|
||||
int find_last_visible_team() const;
|
||||
|
||||
private:
|
||||
const int ticks_;
|
||||
protected:
|
||||
//gamestate
|
||||
const tdata_cache & tdata_;
|
||||
boost::scoped_ptr<game_state> gamestate_;
|
||||
saved_game & saved_game_;
|
||||
|
||||
|
@ -295,7 +299,6 @@ protected:
|
|||
bool init_side_done_;
|
||||
/// whether we did init side in this session ( false = we did init side before we reloaded the game).
|
||||
bool init_side_done_now_;
|
||||
const int ticks_;
|
||||
const std::string& select_victory_music() const;
|
||||
const std::string& select_defeat_music() const;
|
||||
void set_victory_music_list(const std::string& list);
|
||||
|
|
|
@ -117,7 +117,7 @@ playsingle_controller::~playsingle_controller()
|
|||
}
|
||||
|
||||
void playsingle_controller::init_gui(){
|
||||
LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks_) << "\n";
|
||||
LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()) << "\n";
|
||||
play_controller::init_gui();
|
||||
|
||||
if(gamestate().first_human_team_ != -1) {
|
||||
|
@ -211,8 +211,9 @@ void playsingle_controller::play_scenario_init(const config& level) {
|
|||
return;
|
||||
}
|
||||
|
||||
void playsingle_controller::play_scenario_main_loop() {
|
||||
LOG_NG << "starting main loop\n" << (SDL_GetTicks() - ticks_) << "\n";
|
||||
void playsingle_controller::play_scenario_main_loop()
|
||||
{
|
||||
LOG_NG << "starting main loop\n" << (SDL_GetTicks() - ticks()) << "\n";
|
||||
|
||||
|
||||
// Avoid autosaving after loading, but still
|
||||
|
@ -259,7 +260,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
|
|||
ERR_NG << "Skipping this sound source..." << std::endl;
|
||||
}
|
||||
}
|
||||
LOG_NG << "entering try... " << (SDL_GetTicks() - ticks_) << "\n";
|
||||
LOG_NG << "entering try... " << (SDL_GetTicks() - ticks()) << "\n";
|
||||
try {
|
||||
play_scenario_init(level);
|
||||
// clears level config;
|
||||
|
|
|
@ -197,7 +197,7 @@ void replay_controller::init()
|
|||
|
||||
void replay_controller::init_gui()
|
||||
{
|
||||
DBG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks_) << "\n";
|
||||
DBG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()) << "\n";
|
||||
play_controller::init_gui();
|
||||
|
||||
gui_->set_team(vision_ == HUMAN_TEAM ? gamestate().first_human_team_ : 0, vision_ == SHOW_ALL);
|
||||
|
@ -211,12 +211,12 @@ void replay_controller::init_gui()
|
|||
}
|
||||
|
||||
void replay_controller::init_replay_display(){
|
||||
DBG_REPLAY << "initializing replay-display... " << (SDL_GetTicks() - ticks_) << "\n";
|
||||
DBG_REPLAY << "initializing replay-display... " << (SDL_GetTicks() - ticks()) << "\n";
|
||||
|
||||
rebuild_replay_theme();
|
||||
gui_->get_theme().theme_reset_event().attach_handler(this);
|
||||
gui_->complete_redraw_event().attach_handler(this);
|
||||
DBG_REPLAY << "done initializing replay-display... " << (SDL_GetTicks() - ticks_) << "\n";
|
||||
DBG_REPLAY << "done initializing replay-display... " << (SDL_GetTicks() - ticks()) << "\n";
|
||||
}
|
||||
|
||||
void replay_controller::rebuild_replay_theme()
|
||||
|
|
|
@ -39,11 +39,11 @@ static lg::log_domain log_engine_tc("engine/team_construction");
|
|||
class team_builder {
|
||||
public:
|
||||
team_builder(const config& side_cfg, std::vector<team>& teams,
|
||||
const config& level, gamemap& map)
|
||||
const config& level, game_board& board)
|
||||
: gold_info_ngold_(0)
|
||||
, leader_configs_()
|
||||
, level_(level)
|
||||
, map_(map)
|
||||
, board_(board)
|
||||
, player_exists_(false)
|
||||
, seen_ids_()
|
||||
, side_(0)
|
||||
|
@ -96,7 +96,7 @@ protected:
|
|||
std::deque<config> leader_configs_;
|
||||
//only used for objectives
|
||||
const config &level_;
|
||||
gamemap &map_;
|
||||
game_board &board_;
|
||||
//only used for debug message
|
||||
bool player_exists_;
|
||||
std::set<std::string> seen_ids_;
|
||||
|
@ -134,7 +134,7 @@ protected:
|
|||
//track whether a [player] tag with persistence information exists (in addition to the [side] tag)
|
||||
player_exists_ = false;
|
||||
|
||||
if(map_.empty()) {
|
||||
if(board_.map().empty()) {
|
||||
throw game::load_game_failed("Map not found");
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ protected:
|
|||
void new_team()
|
||||
{
|
||||
log_step("new team");
|
||||
t_->build(side_cfg_, map_, gold_info_ngold_);
|
||||
t_->build(side_cfg_, board_.map(), gold_info_ngold_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -304,11 +304,11 @@ protected:
|
|||
void place_units()
|
||||
{
|
||||
log_step("place units");
|
||||
unit_creator uc(*t_,map_.starting_position(side_));
|
||||
unit_creator uc(*t_, board_.map().starting_position(side_), &board_);
|
||||
uc
|
||||
.allow_add_to_recall(true)
|
||||
.allow_discover(true)
|
||||
.allow_get_village(true)
|
||||
.allow_get_village(false)
|
||||
.allow_invalidate(false)
|
||||
.allow_rename_side(true)
|
||||
.allow_show(false);
|
||||
|
@ -318,8 +318,8 @@ protected:
|
|||
}
|
||||
|
||||
// Find the first leader and use its name as the player name.
|
||||
unit_map::iterator u = resources::units->find_first_leader(t_->side());
|
||||
if ((u != resources::units->end()) && t_->current_player().empty())
|
||||
unit_map::iterator u = board_.units().find_first_leader(t_->side());
|
||||
if ((u != board_.units().end()) && t_->current_player().empty())
|
||||
t_->set_current_player(u->name());
|
||||
|
||||
}
|
||||
|
@ -328,9 +328,9 @@ protected:
|
|||
|
||||
team_builder_ptr create_team_builder(const config& side_cfg,
|
||||
std::vector<team>& teams,
|
||||
const config& level, gamemap& map)
|
||||
const config& level, game_board& board)
|
||||
{
|
||||
return team_builder_ptr(new team_builder(side_cfg, teams, level, map));
|
||||
return team_builder_ptr(new team_builder(side_cfg, teams, level, board));
|
||||
}
|
||||
|
||||
void build_team_stage_one(team_builder_ptr tb_ptr)
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
class config;
|
||||
class gamemap;
|
||||
class team_builder;
|
||||
|
||||
class game_board;
|
||||
typedef boost::shared_ptr<team_builder> team_builder_ptr;
|
||||
|
||||
//create an object responsible for creating and populating a team from a config
|
||||
team_builder_ptr create_team_builder(const config& side_cfg,
|
||||
std::vector<team>& teams,
|
||||
const config& level, gamemap& map);
|
||||
const config& level, game_board& board);
|
||||
|
||||
//do first stage of team initialization (everything except unit placement)
|
||||
void build_team_stage_one(team_builder_ptr tb_ptr);
|
||||
|
|
16
src/unit.cpp
16
src/unit.cpp
|
@ -249,7 +249,7 @@ unit::unit(const unit& o)
|
|||
{
|
||||
}
|
||||
|
||||
unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg)
|
||||
unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg, n_unit::id_manager* id_manager)
|
||||
: ref_count_(0)
|
||||
, cfg_()
|
||||
, loc_(cfg["x"] - 1, cfg["y"] - 1)
|
||||
|
@ -321,7 +321,7 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg)
|
|||
|
||||
validate_side(side_);
|
||||
underlying_id_ = n_unit::unit_id::create_real(cfg["underlying_id"].to_int());
|
||||
set_underlying_id();
|
||||
set_underlying_id(id_manager ? *id_manager : resources::gameboard->unit_id_manager());
|
||||
|
||||
overlays_ = utils::parenthetical_split(cfg["overlays"], ',');
|
||||
if(overlays_.size() == 1 && overlays_.front() == "") {
|
||||
|
@ -639,7 +639,7 @@ unit::unit(const unit_type &u_type, int side, bool real_unit,
|
|||
if(real_unit) {
|
||||
generate_name();
|
||||
}
|
||||
set_underlying_id();
|
||||
set_underlying_id(resources::gameboard->unit_id_manager());
|
||||
|
||||
// Set these after traits and modifications have set the maximums.
|
||||
movement_ = max_movement_;
|
||||
|
@ -2269,13 +2269,15 @@ bool unit::is_visible_to_team(team const& team, gamemap const& map, bool const s
|
|||
return true;
|
||||
}
|
||||
|
||||
void unit::set_underlying_id() {
|
||||
void unit::set_underlying_id(n_unit::id_manager& id_manager)
|
||||
{
|
||||
if(underlying_id_.value == 0) {
|
||||
|
||||
if(synced_context::is_synced() || !resources::gamedata || resources::gamedata->phase() == game_data::INITIAL) {
|
||||
underlying_id_ = resources::gameboard->unit_id_manager().next_id();
|
||||
underlying_id_ = id_manager.next_id();
|
||||
}
|
||||
else {
|
||||
underlying_id_ = resources::gameboard->unit_id_manager().next_fake_id();
|
||||
underlying_id_ = id_manager.next_fake_id();
|
||||
}
|
||||
}
|
||||
if (id_.empty() /*&& !underlying_id_.is_fake()*/) {
|
||||
|
@ -2302,7 +2304,7 @@ unit& unit::clone(bool is_temporary)
|
|||
// this appears to be a duplicate of a generic unit, so give it a new id
|
||||
WRN_UT << "assigning new id to clone of generic unit " << id_ << std::endl;
|
||||
id_.clear();
|
||||
set_underlying_id();
|
||||
set_underlying_id(resources::gameboard->unit_id_manager());
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
|
|
|
@ -98,7 +98,8 @@ public:
|
|||
explicit unit(
|
||||
const config& cfg
|
||||
, bool use_traits = false
|
||||
, const vconfig* vcfg = NULL);
|
||||
, const vconfig* vcfg = NULL
|
||||
, n_unit::id_manager* id_manager = NULL);
|
||||
|
||||
/**
|
||||
* Initializes a unit from a unit type
|
||||
|
@ -406,7 +407,7 @@ private:
|
|||
/** register a trait's name and its description for UI's use*/
|
||||
void add_trait_description(const config& trait, const t_string& description);
|
||||
|
||||
void set_underlying_id();
|
||||
void set_underlying_id(n_unit::id_manager& id_manager);
|
||||
|
||||
config cfg_;
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue