1 #pragma once
2 
3 #include "cost_info.h"
4 #include "util.h"
5 #include "unique_entity.h"
6 #include "position.h"
7 #include "furniture_type.h"
8 #include "furniture_layer.h"
9 #include "resource_id.h"
10 #include "position_map.h"
11 
12 class ConstructionMap {
13   public:
14 
15   class FurnitureInfo {
16     public:
17     FurnitureInfo(FurnitureType, CostInfo);
18     static FurnitureInfo getBuilt(FurnitureType);
19     void setBuilt();
20     void reset();
21     void setTask(UniqueEntity<Task>::Id);
22     CostInfo getCost() const;
23     bool isBuilt() const;
24     UniqueEntity<Task>::Id getTask() const;
25     bool hasTask() const;
26     FurnitureType getFurnitureType() const;
27     FurnitureLayer getLayer() const;
28 
29     SERIALIZATION_DECL(FurnitureInfo);
30 
31     private:
32     CostInfo SERIAL(cost);
33     bool SERIAL(built) = false;
34     FurnitureType SERIAL(type);
35     optional<UniqueEntity<Task>::Id> SERIAL(task);
36   };
37 
38   class TrapInfo {
39     public:
40     TrapInfo(TrapType);
41     bool isMarked() const;
42     bool isArmed() const;
43     TrapType getType() const;
44     void setArmed();
45     void setMarked();
46     void reset();
47 
48     SERIALIZATION_DECL(TrapInfo);
49 
50     private:
51     TrapType SERIAL(type);
52     bool SERIAL(armed) = false;
53     bool SERIAL(marked) = false;
54   };
55 
56   const optional<FurnitureInfo>& getFurniture(Position, FurnitureLayer) const;
57   void setTask(Position, FurnitureLayer, UniqueEntity<Task>::Id);
58   void removeFurniture(Position, FurnitureLayer);
59   void onFurnitureDestroyed(Position, FurnitureLayer);
60   void addFurniture(Position, const FurnitureInfo&);
61   bool containsFurniture(Position, FurnitureLayer) const;
62   int getBuiltCount(FurnitureType) const;
63   int getTotalCount(FurnitureType) const;
64   const set<Position>& getBuiltPositions(FurnitureType) const;
65   void onConstructed(Position, FurnitureType);
66 
67   const optional<TrapInfo>& getTrap(Position) const;
68   optional<TrapInfo>& getTrap(Position);
69   void removeTrap(Position);
70   void addTrap(Position, const TrapInfo&);
71 
72   const vector<Position>& getSquares() const;
73   const vector<pair<Position, FurnitureLayer>>& getAllFurniture() const;
74   const vector<Position>& getAllTraps() const;
75   int getDebt(CollectiveResourceId) const;
76 
77   template <class Archive>
78   void serialize(Archive& ar, const unsigned int version);
79 
80   private:
81   EnumMap<FurnitureLayer, PositionMap<optional<FurnitureInfo>>> SERIAL(furniture);
82   EnumMap<FurnitureType, set<Position>> SERIAL(furniturePositions);
83   EnumMap<FurnitureType, int> SERIAL(unbuiltCounts);
84   vector<pair<Position, FurnitureLayer>> SERIAL(allFurniture);
85   PositionMap<optional<TrapInfo>> SERIAL(traps);
86   vector<Position> SERIAL(allTraps);
87   EnumMap<CollectiveResourceId, int> SERIAL(debt);
88   void addDebt(const CostInfo&);
89 };
90