The Battle for Wesnoth  1.15.1+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <>
3  Part of the Battle for Wesnoth Project
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,
12  See the COPYING file for more details.
13 */
15 #pragma once
17 #include "terrain/terrain.hpp"
19 #include <map>
22 private:
24  using tcodeToTerrain_t = std::map<t_translation::terrain_code, terrain_type>;
27  mutable bool initialized_;
30 public:
33  const t_translation::ter_list & list() const;
34  const std::map<t_translation::terrain_code, terrain_type> & map() const;
36  /**
37  * Get the corresponding terrain_type information object
38  * for a given type of terrain.
39  */
42  // The name of the terrain is the terrain itself,
43  // The underlying terrain is the name of the terrain for game-logic purposes.
44  // I.e. if the terrain is simply an alias, the underlying terrain name
45  // is the name of the terrain that it's aliased to.
49  /**
50  * Get a formatted terrain name -- terrain (underlying, terrains)
51  */
52  std::string get_terrain_string(const t_translation::terrain_code& terrain) const;
57  { return get_terrain_info(terrain).is_village(); }
59  { return get_terrain_info(terrain).gives_healing(); }
61  { return get_terrain_info(terrain).is_castle(); }
63  { return get_terrain_info(terrain).is_keep(); }
65  enum merge_mode {
69  };
71  /**
72  * Tries to merge old and new terrain using the merge_settings config
73  * Relevant parameters are "layer" and "replace_conflicting"
74  * "layer" specifies the layer that should be replaced (base or overlay, default is both).
75  * If "replace_conflicting" is true the new terrain will replace the old one if merging failed
76  * (using the default base if new terrain is an overlay terrain)
77  * Will return the resulting terrain or NONE_TERRAIN if merging failed
78  */
79  t_translation::terrain_code merge_terrains(const t_translation::terrain_code & old_t, const t_translation::terrain_code & new_t, const merge_mode mode, bool replace_if_failed = false);
81  /**
82  * Tries to find out if "terrain" can be created by combining two existing
83  * terrains Will add the resulting terrain to the terrain list if
84  * successful
85  */
88 private:
89  tcodeToTerrain_t::const_iterator find_or_merge(t_translation::terrain_code) const;
90 };
92 typedef std::shared_ptr<terrain_type_data> ter_data_cache;
bool is_castle() const
Definition: terrain.hpp:66
tcodeToTerrain_t::const_iterator find_or_merge(t_translation::terrain_code) const
Definition: type_data.cpp:155
bool is_keep(const t_translation::terrain_code &terrain) const
Definition: type_data.hpp:62
t_translation::ter_list terrainList_
Definition: type_data.hpp:23
std::shared_ptr< terrain_type_data > ter_data_cache
Definition: type_data.hpp:92
std::string get_terrain_editor_string(const t_translation::terrain_code &terrain) const
Definition: type_data.cpp:118
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
Get the corresponding terrain_type information object for a given type of terrain.
Definition: type_data.cpp:51
t_translation::terrain_code merge_terrains(const t_translation::terrain_code &old_t, const t_translation::terrain_code &new_t, const merge_mode mode, bool replace_if_failed=false)
Tries to merge old and new terrain using the merge_settings config Relevant parameters are "layer" an...
Definition: type_data.cpp:180
bool is_village() const
Definition: terrain.hpp:65
const std::map< t_translation::terrain_code, terrain_type > & map() const
Definition: type_data.cpp:40
const t_translation::ter_list & underlying_mvt_terrain(const t_translation::terrain_code &terrain) const
Definition: type_data.cpp:63
const t_translation::ter_list & list() const
Definition: type_data.cpp:29
const t_translation::ter_list & underlying_def_terrain(const t_translation::terrain_code &terrain) const
Definition: type_data.cpp:79
std::string get_underlying_terrain_string(const t_translation::terrain_code &terrain) const
Definition: type_data.cpp:135
std::map< t_translation::terrain_code, terrain_type > tcodeToTerrain_t
Definition: type_data.hpp:24
std::string get_terrain_string(const t_translation::terrain_code &terrain) const
Get a formatted terrain name – terrain (underlying, terrains)
Definition: type_data.cpp:108
int gives_healing() const
Definition: terrain.hpp:64
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:130
bool is_castle(const t_translation::terrain_code &terrain) const
Definition: type_data.hpp:60
bool is_keep() const
Definition: terrain.hpp:67
bool is_village(const t_translation::terrain_code &terrain) const
Definition: type_data.hpp:56
Game configuration data as global variables.
Definition: build_info.cpp:49
const t_translation::ter_list & underlying_union_terrain(const t_translation::terrain_code &terrain) const
Definition: type_data.cpp:92
std::vector< terrain_code > ter_list
Definition: translation.hpp:78
terrain_type_data(const config &game_config)
Definition: type_data.cpp:21
int gives_healing(const t_translation::terrain_code &terrain) const
Definition: type_data.hpp:58
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
tcodeToTerrain_t tcodeToTerrain_
Definition: type_data.hpp:25
const config & game_config_
Definition: type_data.hpp:28
bool try_merge_terrains(const t_translation::terrain_code &terrain)
Tries to find out if "terrain" can be created by combining two existing terrains Will add the resulti...
Definition: type_data.cpp:175