1 #pragma once
2 
3 #include <vector>
4 
5 #include "env.h"
6 #include "fixedarray.h"
7 
8 // Sets height to the given height, iff the env.heightmap is already initialized
9 void dgn_height_set_at(const coord_def &c, int height = 0);
10 
11 // The caller is responsible for ensuring that env.heightmap is set.
dgn_height_at(const coord_def & c)12 static inline short &dgn_height_at(const coord_def &c)
13 {
14     return (*env.heightmap)(c);
15 }
16 
17 typedef FixedArray<bool, GXM, GYM> grid_bool;
18 typedef FixedArray<short, GXM, GYM> grid_short;
19 typedef pair<int, int> int_range;
20 
21 const int DGN_UNDEFINED_HEIGHT = -10000;
22 
23 int resolve_range(int_range range, int nrolls = 1);
24 
25 void dgn_initialise_heightmap(int initial_height = 0);
26 void dgn_smooth_height_at(coord_def c, int radius = 1,
27                           int max_height = DGN_UNDEFINED_HEIGHT);
28 void dgn_smooth_heights(int radius = 1, int npasses = 1);
29 
30 void dgn_island_centred_at(const coord_def &c,
31                            // Number of times to raise heights of
32                            // points near c.
33                            int n_points,
34 
35                            // Radius within which all height
36                            // increments are applied.
37                            int radius,
38 
39                            // Lower and upper limits to the height
40                            // delta per perturbation.
41                            int_range height_delta_range,
42 
43                            int border_margin = 6,
44 
45                            // If make_atoll is set, all points chosen for
46                            // height increment will be close to the specified
47                            // radius from c, thus producing a ragged ring.
48                            bool make_atoll = false);
49 
50 struct dgn_island_plan
51 {
52 public:
53     // Number of squares of border to leave around the level.
54     int level_border_depth;
55 
56     // Number of auxiliary high points for each island.
57     int_range n_aux_centres;
58 
59     // Distance from the island centre where the aux high points are placed.
60     int_range aux_centre_offset_range;
61 
62     // Percentage of island (aux) centres that are built as atolls.
63     int atoll_roll;
64 
65     // The positions of the primary centre of each island.
66     vector<coord_def> islands;
67 
68     // The square of the minimum distance that must separate any two
69     // island centres. This is not intended to prevent island overlap, only
70     // to prevent too much clumping of islands.
71     int island_separation_dist2;
72 
73     // Number of points near each island centre that will be raised by
74     // the island builder.
75     int_range n_island_centre_delta_points;
76 
77     // Range of radii for island primary centres.
78     int_range island_centre_radius_range;
79 
80     int_range island_centre_point_height_increment;
81 
82     // Number of points near secondary island centres that will be
83     // raised by the island builder.
84     int_range n_island_aux_delta_points;
85 
86     // Range of radii for island aux centres.
87     int_range island_aux_radius_range;
88 
89     int_range island_aux_point_height_increment;
90 
91 public:
92     void build(int nislands);
93     coord_def pick_and_remove_random_island();
94 
95 private:
96     coord_def pick_island_spot();
97     void build_island();
98 };
99