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