The Battle for Wesnoth  1.15.12+dev
teambuilder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "config.hpp"
18 
19 #include <deque>
20 #include <memory>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
25 class team;
26 class game_board;
27 
29 {
30 public:
31  team_builder(const config& side_cfg, team& to_build, const config& level, game_board& board, int num);
32 
33  /**
34  * Very important! Delete copy constructor and declare a move constructor.
35  *
36  * @c `unit_configs_` may hold a pointer to a config object stored in @c `leader_configs_`.
37  * In that case, if a copy happens (such as when doing in-place construction that requires
38  * the vector be resized), these pointers will become invalid and lead to a crash.
39  */
40  team_builder(const team_builder&) = delete;
41  team_builder(team_builder&&) = default;
42 
43  /** Handles the first stage of team initialization (everything except unit placement). */
44  void build_team_stage_one();
45 
46  /** Handles the second stage of team initialization (unit placement). */
47  void build_team_stage_two();
48 
49 private:
51  std::deque<config> leader_configs_;
52  // only used for objectives
53  const config& level_;
55  // only used for debug message
57  std::set<std::string> seen_ids_;
58  int side_;
59  const config& side_cfg_;
61  std::vector<const config*> unit_configs_;
62 
63  void log_step(const char* s) const;
64  void init();
65  void gold();
66  void new_team();
67  void objectives();
68  void previous_recruits();
69  void handle_unit(const config& u, const char* origin);
70  void handle_leader(const config& leader);
71  void leader();
72  void prepare_units();
73  void place_units();
74 };
Game board class.
Definition: game_board.hpp:50
std::deque< config > leader_configs_
Definition: teambuilder.hpp:51
void place_units()
team_builder(const config &side_cfg, team &to_build, const config &level, game_board &board, int num)
Definition: teambuilder.cpp:37
void build_team_stage_two()
Handles the second stage of team initialization (unit placement).
Definition: teambuilder.cpp:75
std::vector< const config * > unit_configs_
Definition: teambuilder.hpp:61
Definitions for the interface to Wesnoth Markup Language (WML).
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
bool player_exists_
Definition: teambuilder.hpp:56
void objectives()
void previous_recruits()
void handle_leader(const config &leader)
int gold_info_ngold_
Definition: teambuilder.hpp:50
void log_step(const char *s) const
Definition: teambuilder.cpp:82
void build_team_stage_one()
Handles the first stage of team initialization (everything except unit placement).
Definition: teambuilder.cpp:51
const config & level_
Definition: teambuilder.hpp:53
void prepare_units()
static map_location::DIRECTION s
void handle_unit(const config &u, const char *origin)
game_board & board_
Definition: teambuilder.hpp:54
std::set< std::string > seen_ids_
Definition: teambuilder.hpp:57
const config & side_cfg_
Definition: teambuilder.hpp:59
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59