move game_board to its own file, update project files
This commit is contained in:
parent
471e7ab865
commit
2afe4f4f5a
10 changed files with 132 additions and 71 deletions
|
@ -285,6 +285,7 @@
|
|||
<Unit filename="../../src/formula_tokenizer.cpp" />
|
||||
<Unit filename="../../src/formula_tokenizer.hpp" />
|
||||
<Unit filename="../../src/game.cpp" />
|
||||
<Unit filename="../../src/game_board.cpp" />
|
||||
<Unit filename="../../src/game_config.cpp" />
|
||||
<Unit filename="../../src/game_config.hpp" />
|
||||
<Unit filename="../../src/game_config_manager.cpp" />
|
||||
|
|
|
@ -322,6 +322,7 @@
|
|||
<Unit filename="..\..\src\formula_tokenizer.cpp" />
|
||||
<Unit filename="..\..\src\formula_tokenizer.hpp" />
|
||||
<Unit filename="..\..\src\game.cpp" />
|
||||
<Unit filename="..\..\src\game_board.cpp" />
|
||||
<Unit filename="..\..\src\game_config.cpp" />
|
||||
<Unit filename="..\..\src\game_config.hpp" />
|
||||
<Unit filename="..\..\src\game_config_manager.cpp" />
|
||||
|
|
|
@ -4285,6 +4285,8 @@
|
|||
<File Name="../../src/tooltips.cpp"/>
|
||||
<File Name="../../src/race.hpp"/>
|
||||
<File Name="../../src/halo.cpp"/>
|
||||
<File Name="../../src/game_board.cpp"/>
|
||||
<File Name="../../src/game_board.hpp"/>
|
||||
<File Name="../../src/play_controller.cpp"/>
|
||||
<File Name="../../src/multiplayer_connect.cpp"/>
|
||||
<File Name="../../src/game_preferences_display.cpp"/>
|
||||
|
|
|
@ -20060,6 +20060,14 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game_board.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game_board.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game_config.hpp"
|
||||
>
|
||||
|
|
|
@ -736,6 +736,7 @@ set(wesnoth-main_SRC
|
|||
formula_function.cpp
|
||||
formula_string_utils.cpp
|
||||
formula_tokenizer.cpp
|
||||
game_board.cpp
|
||||
game_config_manager.cpp
|
||||
game_controller.cpp
|
||||
game_display.cpp
|
||||
|
|
|
@ -268,6 +268,7 @@ wesnoth_sources = Split("""
|
|||
formula_function.cpp
|
||||
formula_string_utils.cpp
|
||||
formula_tokenizer.cpp
|
||||
game_board.cpp
|
||||
game_config_manager.cpp
|
||||
game_controller.cpp
|
||||
game_display.cpp
|
||||
|
|
74
src/game_board.cpp
Normal file
74
src/game_board.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "config.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "unit.hpp"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
|
||||
void game_board::new_turn(int player_num) {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
if (i.side() == player_num) {
|
||||
i.new_turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::end_turn(int player_num) {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
if (i.side() == player_num) {
|
||||
i.end_turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::set_all_units_user_end_turn() {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
i.set_user_end_turn(true);
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::write_config(config & cfg) const {
|
||||
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
int side_num = t - teams_.begin() + 1;
|
||||
|
||||
config& side = cfg.add_child("side");
|
||||
t->write(side);
|
||||
side["no_leader"] = true;
|
||||
side["side"] = str_cast(side_num);
|
||||
|
||||
//current units
|
||||
{
|
||||
BOOST_FOREACH(const unit & i, units_) {
|
||||
if (i.side() == side_num) {
|
||||
config& u = side.add_child("unit");
|
||||
i.get_location().write(u);
|
||||
i.write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
//recall list
|
||||
{
|
||||
BOOST_FOREACH(const unit & j, t->recall_list()) {
|
||||
config& u = side.add_child("unit");
|
||||
j.write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//write the map
|
||||
cfg["map_data"] = map_.write();
|
||||
}
|
43
src/game_board.hpp
Normal file
43
src/game_board.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef GAME_BOARD_HPP_INCLUDED
|
||||
#define GAME_BOARD_HPP_INCLUDED
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "map.hpp"
|
||||
#include "team.hpp"
|
||||
#include "unit_map.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class config;
|
||||
|
||||
struct game_board {
|
||||
game_board(const config & game_config, const config & level) : teams_(), map_(game_config, level), units_() {}
|
||||
|
||||
std::vector<team> teams_;
|
||||
|
||||
gamemap map_;
|
||||
unit_map units_;
|
||||
|
||||
void new_turn(int pnum);
|
||||
void end_turn(int pnum);
|
||||
void set_all_units_user_end_turn();
|
||||
|
||||
void write_config(config & cfg) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1495,57 +1495,3 @@ void play_controller::toggle_accelerated_speed()
|
|||
gui_->announce(_("Accelerated speed disabled!"), font::NORMAL_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::new_turn(int player_num) {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
if (i.side() == player_num) {
|
||||
i.new_turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::end_turn(int player_num) {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
if (i.side() == player_num) {
|
||||
i.end_turn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::set_all_units_user_end_turn() {
|
||||
BOOST_FOREACH (unit & i, units_) {
|
||||
i.set_user_end_turn(true);
|
||||
}
|
||||
}
|
||||
|
||||
void game_board::write_config(config & cfg) const {
|
||||
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
int side_num = t - teams_.begin() + 1;
|
||||
|
||||
config& side = cfg.add_child("side");
|
||||
t->write(side);
|
||||
side["no_leader"] = true;
|
||||
side["side"] = str_cast(side_num);
|
||||
|
||||
//current units
|
||||
{
|
||||
BOOST_FOREACH(const unit & i, units_) {
|
||||
if (i.side() == side_num) {
|
||||
config& u = side.add_child("unit");
|
||||
i.get_location().write(u);
|
||||
i.write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
//recall list
|
||||
{
|
||||
BOOST_FOREACH(const unit & j, t->recall_list()) {
|
||||
config& u = side.add_child("unit");
|
||||
j.write(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//write the map
|
||||
cfg["map_data"] = map_.write();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "controller_base.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
#include "game_board.hpp"
|
||||
#include "help.hpp"
|
||||
#include "menu_events.hpp"
|
||||
#include "mouse_events.hpp"
|
||||
|
@ -68,23 +69,6 @@ namespace wb {
|
|||
} // namespace wb
|
||||
|
||||
|
||||
// This should eventually be moved to it's own header but the simplest way to begin refactor is right here
|
||||
struct game_board {
|
||||
game_board(const config & game_config, const config & level) : teams_(), map_(game_config, level), units_() {}
|
||||
|
||||
std::vector<team> teams_;
|
||||
|
||||
gamemap map_;
|
||||
unit_map units_;
|
||||
|
||||
void new_turn(int pnum);
|
||||
void end_turn(int pnum);
|
||||
void set_all_units_user_end_turn();
|
||||
|
||||
void write_config(config & cfg) const;
|
||||
};
|
||||
|
||||
|
||||
class play_controller : public controller_base, public events::observer, public savegame::savegame_config
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue