Skip to content

Commit

Permalink
move game_board to its own file, update project files
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 1, 2014
1 parent 471e7ab commit 2afe4f4
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 71 deletions.
1 change: 1 addition & 0 deletions projectfiles/CodeBlocks-SCons/wesnoth.cbp
Expand Up @@ -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" />
Expand Down
1 change: 1 addition & 0 deletions projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -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" />
Expand Down
2 changes: 2 additions & 0 deletions projectfiles/CodeLite/wesnoth.project
Expand Up @@ -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"/>
Expand Down
8 changes: 8 additions & 0 deletions projectfiles/VC9/wesnoth.vcproj
Expand Up @@ -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"
>
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions src/game_board.cpp
@@ -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 changes: 43 additions & 0 deletions src/game_board.hpp
@@ -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
54 changes: 0 additions & 54 deletions src/play_controller.cpp
Expand Up @@ -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 changes: 1 addition & 17 deletions src/play_controller.hpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2afe4f4

Please sign in to comment.