The Battle for Wesnoth  1.19.0-dev
teambuilder.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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 <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 construction). */
44  void build_team_stage_one();
45 
46  /** Handles the second stage of team initialization ((some) unit construction). */
47  void build_team_stage_two();
48  /** Handles the third stage of team initialization (unit placement). */
50 
51 private:
53  std::deque<config> leader_configs_;
54  // only used for objectives
55  const config& level_;
57  // only used for debug message
59  std::set<std::string> seen_ids_;
60  int side_;
61  const config& side_cfg_;
63  std::vector<const config*> unit_configs_;
64 
65  void log_step(const char* s) const;
66  void init();
67  void gold();
68  void new_team();
69  void objectives();
70  void previous_recruits();
71  void handle_unit(const config& u, const char* origin);
72  void handle_leader(const config& leader);
73  void leader();
74  void prepare_units();
75  void place_units();
76 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Game board class.
Definition: game_board.hpp:46
int gold_info_ngold_
Definition: teambuilder.hpp:52
std::deque< config > leader_configs_
Definition: teambuilder.hpp:53
team_builder(const config &side_cfg, team &to_build, const config &level, game_board &board, int num)
Definition: teambuilder.cpp:36
bool player_exists_
Definition: teambuilder.hpp:58
void build_team_stage_three()
Handles the third stage of team initialization (unit placement).
Definition: teambuilder.cpp:78
void handle_leader(const config &leader)
const config & side_cfg_
Definition: teambuilder.hpp:61
void objectives()
void build_team_stage_two()
Handles the second stage of team initialization ((some) unit construction).
Definition: teambuilder.cpp:69
team_builder(team_builder &&)=default
void prepare_units()
std::set< std::string > seen_ids_
Definition: teambuilder.hpp:59
team_builder(const team_builder &)=delete
Very important! Delete copy constructor and declare a move constructor.
std::vector< const config * > unit_configs_
Definition: teambuilder.hpp:63
void previous_recruits()
void build_team_stage_one()
Handles the first stage of team initialization (everything except unit construction).
Definition: teambuilder.cpp:50
void handle_unit(const config &u, const char *origin)
const config & level_
Definition: teambuilder.hpp:55
void place_units()
void log_step(const char *s) const
Definition: teambuilder.cpp:85
game_board & board_
Definition: teambuilder.hpp:56
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
static map_location::DIRECTION s