1 #pragma once
2 
3 #include "util.h"
4 #include "level.h"
5 #include "square_array.h"
6 #include "furniture_array.h"
7 #include "view_object.h"
8 
9 class ProgressMeter;
10 class Model;
11 class LevelMaker;
12 class Square;
13 class FurnitureFactory;
14 class CollectiveBuilder;
15 
16 RICH_ENUM(SquareAttrib,
17   NO_DIG,
18   MOUNTAIN,
19   HILL,
20   LOWLAND,
21   CONNECT_ROAD,
22   CONNECT_CORRIDOR,
23   CONNECTOR,
24   LAKE,
25   RIVER,
26   ROAD_CUT_THRU,
27   NO_ROAD,
28   ROOM,
29   ROOM_WALL,
30   COLLECTIVE_START,
31   COLLECTIVE_STAIRS,
32   EMPTY_ROOM,
33   BUILDINGS_CENTER,
34   CASTLE_CORNER,
35   FOG,
36   FORREST,
37   SOKOBAN_ENTRY,
38   SOKOBAN_PRIZE
39 );
40 
41 class LevelBuilder {
42   public:
43   /** Constructs a builder with given size and name. */
44   LevelBuilder(ProgressMeter*, RandomGen&, int width, int height, const string& name, bool covered = true,
45       optional<double> defaultLight = none);
46   LevelBuilder(RandomGen&, int width, int height, const string& name, bool covered = true);
47 
48   LevelBuilder(LevelBuilder&&);
49   ~LevelBuilder();
50 
51   /** Returns a given square.*/
52   WSquare modSquare(Vec2);
53 
54   /** Checks if it's possible to put a creature on given square.*/
55   bool canPutCreature(Vec2, WCreature);
56 
57   /** Puts a creatue on a given square. If the square is later changed to something else, the creature remains.*/
58   void putCreature(Vec2, PCreature);
59 
60   /** Puts items on a given square. If the square is later changed to something else, the items remain.*/
61   void putItems(Vec2, vector<PItem> items);
62 
63   /** Sets the message displayed when the player first enters the level.*/
64   void setMessage(const string& message);
65 
66   /** Builds the level. The level will keep reference to the model.
67       \paramname{surface} tells if this level is on the Earth surface.*/
68   PLevel build(WModel, LevelMaker*, LevelId);
69 
70   /** Checks if the given square has an attribute.*/
71   bool hasAttrib(Vec2 pos, SquareAttrib attr);
72 
73   /** Adds attribute to given square. The attribute will remain if the square is changed.*/
74   void addAttrib(Vec2 pos, SquareAttrib attr);
75 
76   void putFurniture(Vec2 pos, FurnitureFactory&, optional<SquareAttrib> = none);
77   void putFurniture(Vec2 pos, FurnitureParams, optional<SquareAttrib> = none);
78   void putFurniture(Vec2 pos, FurnitureType, optional<SquareAttrib> = none);
79   void resetFurniture(Vec2 pos, FurnitureType, optional<SquareAttrib> = none);
80   bool canPutFurniture(Vec2 pos, FurnitureLayer);
81   void removeFurniture(Vec2 pos, FurnitureLayer);
82   void removeAllFurniture(Vec2 pos);
83   optional<FurnitureType> getFurnitureType(Vec2 pos, FurnitureLayer);
84   bool isFurnitureType(Vec2 pos, FurnitureType);
85   WConstFurniture getFurniture(Vec2 pos, FurnitureLayer);
86 
87   void setLandingLink(Vec2 pos, StairKey);
88 
89   /** Removes attribute from given square.*/
90   void removeAttrib(Vec2 pos, SquareAttrib attr);
91 
92   bool canNavigate(Vec2 pos, const MovementType&);
93 
94   /** Sets the height of the given square.*/
95   void setHeightMap(Vec2 pos, double h);
96 
97   /** Returns the height of the given square.*/
98   double getHeightMap(Vec2 pos);
99 
100   Rectangle toGlobalCoordinates(Rectangle);
101   vector<Vec2> toGlobalCoordinates(vector<Vec2>);
102 
103   /** Adds a collective to the level and initializes it.*/
104   void addCollective(CollectiveBuilder*);
105 
106   /** Sets the cover of the square. The value will remain if square is changed.*/
107   void setCovered(Vec2, bool covered);
108   void setSunlight(Vec2, double);
109 
110   void setNoDiagonalPassing();
111 
112   void setUnavailable(Vec2);
113 
114   enum Rot { CW0, CW1, CW2, CW3};
115 
116   void pushMap(Rectangle bounds, Rot);
117   void popMap();
118 
119   RandomGen& getRandom();
120 
121   private:
122   Vec2 transform(Vec2);
123   SquareArray squares;
124   Table<bool> unavailable;
125   Table<double> heightMap;
126   Table<double> dark;
127   vector<CollectiveBuilder*> collectives;
128   Table<bool> covered;
129   Table<double> sunlight;
130   Table<EnumSet<SquareAttrib>> attrib;
131   vector<pair<PCreature, Vec2>> creatures;
132   Table<vector<PItem>> items;
133   FurnitureArray furniture;
134   string name;
135   vector<Vec2::LinearMap> mapStack;
136   ProgressMeter* progressMeter = nullptr;
137   RandomGen& random;
138   bool noDiagonalPassing = false;
139 };
140