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 <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 construction). */
45  void build_team_stage_one();
46 
47  /** Handles the second stage of team initialization ((some) unit construction). */
48  void build_team_stage_two();
49  /** Handles the third stage of team initialization (unit placement). */
51 
52 private:
54  std::deque<config> leader_configs_;
55  // only used for objectives
56  const config& level_;
58  // only used for debug message
60  std::set<std::string> seen_ids_;
61  int side_;
62  const config& side_cfg_;
64  std::vector<const config*> unit_configs_;
65 
66  void log_step(const char* s) const;
67  void init();
68  void gold();
69  void new_team();
70  void objectives();
71  void previous_recruits();
72  void handle_unit(const config& u, const char* origin);
73  void handle_leader(const config& leader);
74  void leader();
75  void prepare_units();
76  void place_units();
77 };
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:53
int gold_info_ngold_
Definition: teambuilder.hpp:53
std::deque< config > leader_configs_
Definition: teambuilder.hpp:54
team_builder(const config &side_cfg, team &to_build, const config &level, game_board &board, int num)
Definition: teambuilder.cpp:38
bool player_exists_
Definition: teambuilder.hpp:59
void build_team_stage_three()
Handles the third stage of team initialization (unit placement).
Definition: teambuilder.cpp:80
void handle_leader(const config &leader)
const config & side_cfg_
Definition: teambuilder.hpp:62
void objectives()
void build_team_stage_two()
Handles the second stage of team initialization ((some) unit construction).
Definition: teambuilder.cpp:71
team_builder(team_builder &&)=default
void prepare_units()
std::set< std::string > seen_ids_
Definition: teambuilder.hpp:60
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:64
void previous_recruits()
void build_team_stage_one()
Handles the first stage of team initialization (everything except unit construction).
Definition: teambuilder.cpp:52
void handle_unit(const config &u, const char *origin)
const config & level_
Definition: teambuilder.hpp:56
void place_units()
void log_step(const char *s) const
Definition: teambuilder.cpp:87
game_board & board_
Definition: teambuilder.hpp:57
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:76
static map_location::DIRECTION s