… | |
… | |
22 | |
22 | |
23 | #include <global.h> |
23 | #include <global.h> |
24 | |
24 | |
25 | #include "noise.h" |
25 | #include "noise.h" |
26 | |
26 | |
|
|
27 | ///////////////////////////////////////////////////////////////////////////// |
|
|
28 | |
|
|
29 | static bool |
|
|
30 | has_floor (maptile *m, sint16 x, sint16 y) |
|
|
31 | { |
|
|
32 | mapxy pos (m, x, y); |
|
|
33 | |
|
|
34 | if (!pos.normalise ()) |
|
|
35 | return true; |
|
|
36 | |
|
|
37 | mapspace &ms = pos.ms (); |
|
|
38 | |
|
|
39 | for (object *ob = ms.bot; ob; ob = ob->above) |
|
|
40 | if (ob->arch->archname == shstr_quad_open_space) |
|
|
41 | return false; |
|
|
42 | else if (ob->flag [FLAG_IS_FLOOR]) |
|
|
43 | return true; |
|
|
44 | |
|
|
45 | return false; |
|
|
46 | } |
|
|
47 | |
|
|
48 | void |
|
|
49 | move_into_wall (object *ob, object *wall) |
|
|
50 | { |
|
|
51 | bool visible = !wall->invisible && !ob->flag [FLAG_BLIND]; |
|
|
52 | |
|
|
53 | if (wall->flag [FLAG_IS_QUAD] && visible) |
|
|
54 | { |
|
|
55 | maptile *m = wall->map; |
|
|
56 | |
|
|
57 | if (ob->map->tile_path [TILE_UP] && wall->map->tile_path [TILE_UP]) |
|
|
58 | { |
|
|
59 | maptile *wall_up = wall->map->tile_available (TILE_UP); |
|
|
60 | maptile *ob_up = ob ->map->tile_available (TILE_UP); |
|
|
61 | |
|
|
62 | if (wall_up && ob_up) |
|
|
63 | { |
|
|
64 | if (ob->blocked (ob_up, ob->x, ob->y) || has_floor (ob_up, ob->x, ob->y)) |
|
|
65 | ob->failmsg (format ("Ouch, you hit your head while climbing the %s! H<Didn't you see the ceiling? :)>", query_name (wall))); |
|
|
66 | //TODO: reduce health |
|
|
67 | else if (ob->blocked (wall_up, wall->x, wall->y)) |
|
|
68 | ob->failmsg (format ("You try to climb up, but the %s is too high for you! H<No free space on top of this block.>", query_name (wall))); |
|
|
69 | //TODO: reduce health |
|
|
70 | else |
|
|
71 | { |
|
|
72 | ob->statusmsg (format ("You successfully climb up the %s.", query_name (wall))); |
|
|
73 | // here we assume that ob is a player... |
|
|
74 | ob->enter_map (wall_up, wall->x, wall->y); |
|
|
75 | } |
|
|
76 | } |
|
|
77 | else |
|
|
78 | ob->failmsg (format ("You try to climb the %s, but you fall down! H<Try again.>", query_name (wall))); |
|
|
79 | } |
|
|
80 | else |
|
|
81 | ob->failmsg (format ("You fail to climb up the %s! H<You cannot climb up here.>", query_name (wall))); |
|
|
82 | |
|
|
83 | |
|
|
84 | return; |
|
|
85 | } |
|
|
86 | |
|
|
87 | if (ob->contr->ns->bumpmsg) |
|
|
88 | { |
|
|
89 | ob->play_sound (sound_find ("bump_wall")); |
|
|
90 | |
|
|
91 | ob->statusmsg (visible |
|
|
92 | ? format ("You bump into the %s.", query_name (wall)) |
|
|
93 | : "You bump into something." |
|
|
94 | ); |
|
|
95 | } |
|
|
96 | } |
|
|
97 | |
|
|
98 | ///////////////////////////////////////////////////////////////////////////// |
|
|
99 | |
|
|
100 | physics_queue::physics_queue () |
|
|
101 | { |
|
|
102 | i = 0; |
|
|
103 | } |
|
|
104 | |
|
|
105 | object * |
|
|
106 | physics_queue::pop () |
|
|
107 | { |
|
|
108 | if (expect_true (i < size ())) |
|
|
109 | return (*this)[i++]; |
|
|
110 | |
|
|
111 | i = 0; |
|
|
112 | clear (); |
|
|
113 | return 0; |
|
|
114 | } |
|
|
115 | |
|
|
116 | inline unsigned int |
|
|
117 | queue_of (tick_t tick) |
|
|
118 | { |
|
|
119 | return tick & (PHYSICS_QUEUES - 1); |
|
|
120 | } |
|
|
121 | |
|
|
122 | void update_physics (maptile *m, int x, int y) |
|
|
123 | { |
|
|
124 | } |
|
|
125 | |
|
|
126 | // handle physics updates |
|
|
127 | void move_physics (object *ob) |
|
|
128 | { |
|
|
129 | } |
|
|
130 | |
|
|
131 | int |
|
|
132 | maptile::run_physics (tick_t tick, int max_objects) |
|
|
133 | { |
|
|
134 | int orig_max_object = max_objects; |
|
|
135 | physics_queue &q = pq [queue_of (server_tick)]; |
|
|
136 | |
|
|
137 | while (object *ob = q.pop ()) |
|
|
138 | { |
|
|
139 | --max_objects; |
|
|
140 | |
|
|
141 | //printf ("handling ob %s\n", ob->debug_desc());//D |
|
|
142 | |
|
|
143 | if (max_objects <= 0) |
|
|
144 | break; |
|
|
145 | } |
|
|
146 | |
|
|
147 | return orig_max_object - max_objects; |
|
|
148 | } |
|
|
149 | |
|
|
150 | void |
|
|
151 | maptile::queue_physics (object *ob) |
|
|
152 | { |
|
|
153 | if (!ob->flag [FLAG_PHYSICS_QUEUE]) |
|
|
154 | pq [queue_of (server_tick)].push_back (ob); |
|
|
155 | } |
|
|
156 | |
|
|
157 | // this mapspace has changed - potentialyl activate dormant physics objects |
|
|
158 | // in the vicinity |
|
|
159 | void |
|
|
160 | maptile::queue_physics_at (int x, int y) |
|
|
161 | { |
|
|
162 | } |
|
|
163 | |
|
|
164 | void |
|
|
165 | maptile::post_load_physics () |
|
|
166 | { |
|
|
167 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
|
|
168 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
|
|
169 | if (tmp->type == PHYSICS) |
|
|
170 | queue_physics (tmp); |
|
|
171 | } |
|
|
172 | |
|
|
173 | ///////////////////////////////////////////////////////////////////////////// |
|
|
174 | |
27 | #define FANCY_GRAPHICS 0 |
175 | #define FANCY_GRAPHICS 0 |
28 | |
176 | |
29 | static void |
177 | static void |
30 | gen_quadspace (maptile *m, int mx, int my, int x, int y, int z) |
178 | gen_quadspace (maptile *m, int mx, int my, int x, int y, int z) |
31 | { |
179 | { |
… | |
… | |
72 | T_OCEAN, |
220 | T_OCEAN, |
73 | T_RIVER, |
221 | T_RIVER, |
74 | T_VALLEY, |
222 | T_VALLEY, |
75 | T_MOUNTAIN, |
223 | T_MOUNTAIN, |
76 | T_UNDERGROUND, |
224 | T_UNDERGROUND, |
|
|
225 | T_AIR, // unused |
77 | T_ACQUIFER, |
226 | T_ACQUIFER, |
78 | } t = T_NONE; |
227 | } t = T_NONE; |
79 | |
228 | |
80 | vec3d c; |
229 | vec3d c; |
81 | int h0 = 0; // "water level" |
230 | int h0 = 0; // "water level" |
82 | int h = 1000000; // height form heightmap |
231 | int h = 1000000; // height form heightmap |
83 | |
232 | |
84 | // the continent increases in height from 0 to ~700 levels in the absence of anything else |
233 | // the continent increases in height from 0 to ~700 levels in the absence of anything else |
85 | // thats about one step every 7 maps. |
234 | // thats about one step every 7 maps. |
86 | int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); |
235 | int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); |
87 | int river_height = base_height * 9 / 10; |
236 | int river_height = base_height; // * 9 / 10; |
88 | |
237 | |
89 | // add this to rivers to "dry them out" |
238 | // add this to rivers to "dry them out" |
90 | float dry_out = max (0.f, lerp (xy_gradient, 0.7f, 1.f, 0.f, 0.3f)); |
239 | float dry_out = max (0.f, lerp (xy_gradient, 0.7f, 1.f, 0.f, 0.3f)); |
91 | |
240 | |
92 | static frac2d river_gen (2); |
241 | static frac2d river_gen (2); |
93 | float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)) + dry_out; |
242 | float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)) + dry_out; |
94 | float river2 = river_gen.ridgedmultifractal (P * 0.04, 0.8, 10) - y_gradient * 0.2 - 0.16 - dry_out; |
243 | float river2 = river_gen.ridgedmultifractal (P * 0.04, 0.8, 10) - y_gradient * 0.2 - 0.16 - dry_out; |
95 | |
244 | |
96 | float valley = river1 - 0.2f; |
245 | float valley = river1 - 0.2f; |
97 | |
246 | |
98 | static frac2d mountain_gen (8, 2.14, 0.5); |
247 | static frac2d mountain_gen (6, 2.14, 0.5); |
99 | float mountain = mountain_gen.ridgedmultifractal (P * 0.004); |
248 | float mountain = mountain_gen.ridgedmultifractal (P * 0.004); |
100 | |
249 | |
101 | //TODO: mountains should not lower the height, should they? |
250 | //TODO: mountains should not lower the height, should they? |
102 | t = valley < 0 ? T_VALLEY : T_MOUNTAIN; |
251 | t = valley < 0 ? T_VALLEY : T_MOUNTAIN; |
103 | c = blend0 (vec3d (0, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f); |
252 | c = blend0 (vec3d (0, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f); |
104 | h = blend0 (base_height + continent * 300, base_height + mountain * xy_gradient * 400, valley, 0.1f); |
253 | h = blend0 (base_height + continent * 3, base_height + mountain * xy_gradient * 100, valley, 0.1f); |
105 | |
254 | |
106 | if (river1 < 0.01f) |
255 | if (river1 < 0.01f) |
107 | { |
256 | { |
108 | // main rivers - they cut deeply into the mountains (base_height * 0.9f) |
257 | // main rivers - they cut deeply into the mountains (base_height * 0.9f) |
109 | t = T_RIVER; |
258 | t = T_RIVER; |
110 | c = vec3d (0.2, 0.2, 1); |
259 | c = vec3d (0.2, 0.2, 1); |
111 | h0 = river_height; |
260 | h0 = river_height; |
112 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1)); |
261 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -10, -1)); |
113 | } |
262 | } |
114 | |
263 | |
115 | if (river2 > 0) |
264 | if (river2 > 0) |
116 | { |
265 | { |
117 | t = T_RIVER; |
266 | t = T_RIVER; |
118 | c = vec3d (0.2, 0.2, 1); |
267 | c = vec3d (0.2, 0.2, 1); |
119 | h0 = river_height; |
268 | h0 = river_height; |
120 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1)); |
269 | min_it (h, river_height + max (-5, lerp<float> (river2, 0.01f, 0, -4, -1))); |
121 | } |
270 | } |
122 | |
271 | |
123 | if (continent < 0) |
272 | if (continent < 0) |
124 | { |
273 | { |
125 | t = T_OCEAN; |
274 | t = T_OCEAN; |
|
|
275 | h0 = 0; |
126 | min_it (h, min (continent * 200, -1)); |
276 | min_it (h, min (continent * 200, -1)); |
127 | c = vec3d (0, 0, 1); |
277 | c = vec3d (0, 0, 1); |
128 | } |
278 | } |
129 | |
279 | |
130 | // now we have the base height, and base terrain |
280 | // now we have the base height, and base terrain |
… | |
… | |
135 | |
285 | |
136 | max_it (h0, h); |
286 | max_it (h0, h); |
137 | |
287 | |
138 | // everything below the surface is underground, or a variant |
288 | // everything below the surface is underground, or a variant |
139 | if (z < h) |
289 | if (z < h) |
140 | { |
|
|
141 | t = T_UNDERGROUND; |
290 | t = T_UNDERGROUND; |
142 | } |
|
|
143 | |
291 | |
144 | // put acquifers a bit below the surface, to reduce them leaking out (will still happen) |
292 | // put acquifers a bit below the surface, to reduce them leaking out (will still happen) |
145 | if (z < h - 3) |
293 | if (z < h - 3) |
146 | { |
294 | { |
147 | static frac3d acquifer_gen (4); |
295 | static frac3d acquifer_gen (4); |
… | |
… | |
151 | { |
299 | { |
152 | t = T_ACQUIFER; |
300 | t = T_ACQUIFER; |
153 | c = vec3d (1,1,1); |
301 | c = vec3d (1,1,1); |
154 | } |
302 | } |
155 | } |
303 | } |
|
|
304 | |
|
|
305 | //printf ("+%d+%d %d z %d h %d,%d\n", mx, my, t, z, h,h0);//D |
156 | |
306 | |
157 | // TODO: caves |
307 | // TODO: caves |
158 | // TODO: chees areas |
308 | // TODO: chees areas |
159 | // TODO: minerals |
309 | // TODO: minerals |
160 | // TODO: monsters |
310 | // TODO: monsters |
… | |
… | |
168 | putc (clamp<int> (255 * c[2], 0, 255), stdout); |
318 | putc (clamp<int> (255 * c[2], 0, 255), stdout); |
169 | #else |
319 | #else |
170 | shstr arch_floor = shstr ("quad_open_space"); |
320 | shstr arch_floor = shstr ("quad_open_space"); |
171 | shstr arch_wall; |
321 | shstr arch_wall; |
172 | |
322 | |
|
|
323 | // TODO: this is shit - we should never generatea water surface, but only |
|
|
324 | // water above the surface |
173 | switch (t) |
325 | switch (t) |
174 | { |
326 | { |
175 | case T_OCEAN: |
327 | case T_OCEAN: |
|
|
328 | if (z < h0) |
|
|
329 | arch_wall = shstr ("quad_water_wall"); |
|
|
330 | else if (z == h0) |
|
|
331 | arch_floor = shstr ("quad_ocean_floor"); |
|
|
332 | break; |
|
|
333 | |
176 | case T_RIVER: |
334 | case T_RIVER: |
177 | if (z < h0) |
335 | if (z < h0) |
178 | arch_wall = shstr ("quad_water_wall"); |
336 | arch_wall = shstr ("quad_water_wall"); |
|
|
337 | else if (z == h0) |
|
|
338 | arch_floor = shstr ("quad_water_floor"); |
179 | break; |
339 | break; |
180 | |
340 | |
181 | case T_VALLEY: |
341 | case T_VALLEY: |
182 | if (z == h) |
342 | if (z == h) |
183 | arch_floor = shstr ("quad_dirt_floor"); |
343 | arch_floor = shstr ("quad_dirt_floor"); |
… | |
… | |
190 | |
350 | |
191 | case T_UNDERGROUND: |
351 | case T_UNDERGROUND: |
192 | // todo, use a fractal |
352 | // todo, use a fractal |
193 | if (z < h - 10) |
353 | if (z < h - 10) |
194 | { |
354 | { |
|
|
355 | arch_floor = shstr ("quad_stone_floor"); |
|
|
356 | arch_wall = shstr ("quad_stone_wall"); |
|
|
357 | } |
|
|
358 | else |
|
|
359 | { |
195 | arch_floor = shstr ("quad_dirt_floor"); |
360 | arch_floor = shstr ("quad_dirt_floor"); |
196 | arch_wall = shstr ("quad_dirt_wall"); |
361 | arch_wall = shstr ("quad_dirt_wall"); |
197 | } |
362 | } |
198 | else |
|
|
199 | { |
|
|
200 | arch_floor = shstr ("quad_stone_floor"); |
|
|
201 | arch_wall = shstr ("quad_stone_wall"); |
|
|
202 | } |
|
|
203 | break; |
363 | break; |
204 | |
364 | |
205 | case T_ACQUIFER: |
365 | case T_ACQUIFER: |
206 | arch_wall = shstr ("quad_water_wall"); |
366 | arch_wall = shstr ("quad_water_wall"); |
207 | break; |
367 | break; |
… | |
… | |
226 | |
386 | |
227 | for (int mx = 0; mx < 50; ++mx) |
387 | for (int mx = 0; mx < 50; ++mx) |
228 | for (int my = 0; my < 50; ++my) |
388 | for (int my = 0; my < 50; ++my) |
229 | gen_quadspace (m, mx, my, x + mx, y + my, z); |
389 | gen_quadspace (m, mx, my, x + mx, y + my, z); |
230 | } |
390 | } |
|
|
391 | |
|
|
392 | ///////////////////////////////////////////////////////////////////////////// |
231 | |
393 | |
232 | void noise_test (); |
394 | void noise_test (); |
233 | void noise_test () |
395 | void noise_test () |
234 | { |
396 | { |
235 | #if 1 |
397 | #if 1 |
… | |
… | |
319 | } |
481 | } |
320 | #endif |
482 | #endif |
321 | |
483 | |
322 | exit (0); |
484 | exit (0); |
323 | } |
485 | } |
|
|
486 | |