aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/TerrainType.hpp
blob: 1a5b09c9371eadabd8ecbc30e06f23a301c3f0aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include "openvic-simulation/misc/Modifier.hpp"

namespace OpenVic {
   struct TerrainTypeManager;

   struct TerrainType : HasIdentifierAndColour, ModifierValue {
      friend struct TerrainTypeManager;

   private:
      const ModifierValue PROPERTY(modifier);
      const bool PROPERTY(is_water);

      TerrainType(std::string_view new_identifier, colour_t new_colour, ModifierValue&& new_modifier, bool new_is_water);

   public:
      TerrainType(TerrainType&&) = default;
   };

   struct TerrainTypeMapping : HasIdentifier {
      friend struct TerrainTypeManager;

      using index_t = uint8_t;

   private:
      TerrainType const& PROPERTY(type);
      const std::vector<index_t> PROPERTY(terrain_indices);
      const index_t PROPERTY(priority);
      const bool PROPERTY(has_texture);

      TerrainTypeMapping(
         std::string_view new_identifier, TerrainType const& new_type, std::vector<index_t>&& new_terrain_indicies,
         index_t new_priority, bool new_has_texture
      );

   public:
      TerrainTypeMapping(TerrainTypeMapping&&) = default;
   };

   struct TerrainTypeManager {
   private:
      using terrain_type_mappings_map_t = std::map<TerrainTypeMapping::index_t, size_t>;
      IdentifierRegistry<TerrainType> IDENTIFIER_REGISTRY(terrain_type);
      IdentifierRegistry<TerrainTypeMapping> IDENTIFIER_REGISTRY(terrain_type_mapping);
      terrain_type_mappings_map_t terrain_type_mappings_map;

      TerrainTypeMapping::index_t terrain_texture_limit = 0, terrain_texture_count = 0;

      NodeTools::node_callback_t _load_terrain_type_categories(ModifierManager const& modifier_manager);
      bool _load_terrain_type_mapping(std::string_view key, ast::NodeCPtr value);

   public:
      bool add_terrain_type(std::string_view identifier, colour_t colour, ModifierValue&& values, bool is_water);

      bool add_terrain_type_mapping(
         std::string_view identifier, TerrainType const* type, std::vector<TerrainTypeMapping::index_t>&& terrain_indicies,
         TerrainTypeMapping::index_t priority, bool has_texture
      );

      TerrainTypeMapping const* get_terrain_type_mapping_for(TerrainTypeMapping::index_t idx) const;

      TerrainTypeMapping::index_t get_terrain_texture_limit() const;

      bool load_terrain_types(ModifierManager const& modifier_manager, ast::NodeCPtr root);
   };
}