1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
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 | physics_queue::~physics_queue () |
|
|
106 | { |
|
|
107 | while (object *ob = pop ()) |
|
|
108 | ob->refcnt_dec (); |
|
|
109 | } |
|
|
110 | |
|
|
111 | object * |
|
|
112 | physics_queue::pop () |
|
|
113 | { |
|
|
114 | if (expect_true (i < size ())) |
|
|
115 | return (*this)[i++]; |
|
|
116 | |
|
|
117 | i = 0; |
|
|
118 | clear (); //TODO: this frees, but we do not want to free, unless really a lot of objects were queued |
|
|
119 | return 0; |
|
|
120 | } |
|
|
121 | |
|
|
122 | inline unsigned int |
|
|
123 | queue_of (tick_t tick) |
|
|
124 | { |
|
|
125 | return tick & (PHYSICS_QUEUES - 1); |
|
|
126 | } |
|
|
127 | |
|
|
128 | void update_physics (maptile *m, int x, int y) |
|
|
129 | { |
|
|
130 | } |
|
|
131 | |
|
|
132 | // handle physics updates |
|
|
133 | void move_physics (object *ob) |
|
|
134 | { |
|
|
135 | } |
|
|
136 | |
|
|
137 | // preliminary slots docs |
|
|
138 | // level - water level 1..7 |
|
|
139 | // value - pressure |
|
|
140 | // |
|
|
141 | |
|
|
142 | static object * |
|
|
143 | flow_to (maptile *m, sint16 x, sint16 y) |
|
|
144 | { |
|
|
145 | if (!xy_normalise (m, x, y)) |
|
|
146 | return 0; |
|
|
147 | |
|
|
148 | mapspace &ms = m->at (x, y); |
|
|
149 | |
|
|
150 | ms.update (); |
|
|
151 | if (ms.move_block & MOVE_WALK) |
|
|
152 | return 0; |
|
|
153 | |
|
|
154 | for (object *w = ms.top; w; w = w->below) |
|
|
155 | if (w->type == PHYSICS) |
|
|
156 | if (w->subtype == ST_WATER_SOURCE) |
|
|
157 | return 0; |
|
|
158 | else if (w->subtype == ST_WATER_FLOW) |
|
|
159 | return w; |
|
|
160 | |
|
|
161 | printf ("creating flow at %d,%d\n", x, y);//D |
|
|
162 | object *w = archetype::get (shstr_quad_water_flow); |
|
|
163 | w->level = 0; |
|
|
164 | w->value = 0; |
|
|
165 | |
|
|
166 | m->insert (w, x, y); |
|
|
167 | m->queue_physics (w, 1); |
|
|
168 | |
|
|
169 | return w; |
|
|
170 | } |
|
|
171 | |
|
|
172 | static int |
|
|
173 | find_ortho_flow (object *src, object **result) |
|
|
174 | { |
|
|
175 | object **res = result; |
|
|
176 | |
|
|
177 | for (int dir = 1; dir < 8; dir += 2) |
|
|
178 | { |
|
|
179 | mapxy pos (src->map, src->x, src->y); |
|
|
180 | pos.move (dir); |
|
|
181 | if (pos.normalise ()) |
|
|
182 | if (object *w = flow_to (pos.m, pos.x, pos.y)) |
|
|
183 | *res++ = w; |
|
|
184 | } |
|
|
185 | |
|
|
186 | return res - result; |
|
|
187 | } |
|
|
188 | |
|
|
189 | static bool |
|
|
190 | water_set (object *w, int level, int pressure = -1) |
|
|
191 | { |
|
|
192 | if (!level) |
|
|
193 | { |
|
|
194 | w->destroy (); |
|
|
195 | return true; |
|
|
196 | } |
|
|
197 | |
|
|
198 | bool activity = false; |
|
|
199 | |
|
|
200 | min_it (level, 7); |
|
|
201 | |
|
|
202 | if (level != w->level) |
|
|
203 | { |
|
|
204 | w->level = level; |
|
|
205 | // update face |
|
|
206 | activity = true; |
|
|
207 | } |
|
|
208 | |
|
|
209 | if (pressure != w->value && pressure >= 0) |
|
|
210 | { |
|
|
211 | w->value = pressure; |
|
|
212 | activity = true; |
|
|
213 | } |
|
|
214 | |
|
|
215 | if (activity) // this is overkill, but... |
|
|
216 | w->map->queue_physics_at (w->x, w->y); |
|
|
217 | |
|
|
218 | return activity; |
|
|
219 | } |
|
|
220 | |
|
|
221 | static void |
|
|
222 | run_physics (object *ob) |
|
|
223 | { |
|
|
224 | //TODO: behaviour objects with virtual methods? |
|
|
225 | switch (ob->subtype) |
|
|
226 | { |
|
|
227 | case ST_WATER_SOURCE: |
|
|
228 | { |
|
|
229 | bool activity = false; |
|
|
230 | |
|
|
231 | // water sources generate flowing water "everywhere", but are currently |
|
|
232 | // very simple otherwise. |
|
|
233 | if (!has_floor (ob->map, ob->x, ob->y) && ob->map->tile_path [TILE_DOWN]) |
|
|
234 | if (maptile *m = ob->map->tile_available (TILE_DOWN)) |
|
|
235 | { |
|
|
236 | if (object *w = flow_to (m, ob->x, ob->y)) |
|
|
237 | activity = activity || water_set (w, 7); |
|
|
238 | } |
|
|
239 | else |
|
|
240 | activity = true; |
|
|
241 | |
|
|
242 | #if 0 |
|
|
243 | object *w [4]; |
|
|
244 | int w_cnt = find_ortho_flow (ob, w); |
|
|
245 | |
|
|
246 | while (w_cnt--) |
|
|
247 | activity = activity || water_set (w [w_cnt], 7); |
|
|
248 | |
|
|
249 | if (activity) |
|
|
250 | ob->map->queue_physics (ob, 1); |
|
|
251 | #endif |
|
|
252 | } |
|
|
253 | break; |
|
|
254 | |
|
|
255 | case ST_WATER_FLOW: |
|
|
256 | #if 0 |
|
|
257 | // flow down as much as possible |
|
|
258 | if (!has_floor (ob->map, ob->x, ob->y) && ob->map->tile_path [TILE_DOWN]) |
|
|
259 | if (maptile *m = ob->map->tile_available (TILE_DOWN)) |
|
|
260 | { |
|
|
261 | if (object *w = flow_to (m, ob->x, ob->y)) |
|
|
262 | { |
|
|
263 | if (int flow = min (ob->level, 7 - w->level)) |
|
|
264 | { |
|
|
265 | water_set (w, w->level + flow); |
|
|
266 | water_set (ob, w->level - flow); |
|
|
267 | if (!ob->level) |
|
|
268 | return; // we escaped downwards |
|
|
269 | } |
|
|
270 | else if (ob->level >= 5) // exert pressure -> does not count as activity |
|
|
271 | water_set (w, w->level, ob->value - 1); |
|
|
272 | } |
|
|
273 | } |
|
|
274 | |
|
|
275 | if (ob->level >= 2) |
|
|
276 | { |
|
|
277 | object *ws [4]; |
|
|
278 | int w_cnt = find_ortho_flow (ob, ws); |
|
|
279 | |
|
|
280 | bool activity = false; |
|
|
281 | |
|
|
282 | // distribute 1 to every neighbour that has less - should use some random ordering of course |
|
|
283 | |
|
|
284 | while (w_cnt--) |
|
|
285 | { |
|
|
286 | object *w = ws [w_cnt]; |
|
|
287 | |
|
|
288 | if (w->level < ob->level - 1) |
|
|
289 | { |
|
|
290 | water_set (w, w->level + 1); |
|
|
291 | --ob->level; |
|
|
292 | activity = true; |
|
|
293 | } |
|
|
294 | } |
|
|
295 | |
|
|
296 | if (activity) |
|
|
297 | ob->map->queue_physics (ob, 1); |
|
|
298 | } |
|
|
299 | else if (ob->level) |
|
|
300 | ; |
|
|
301 | else |
|
|
302 | ob->destroy (); |
|
|
303 | #endif |
|
|
304 | |
|
|
305 | // TODO: flow up with pressure |
|
|
306 | break; |
|
|
307 | |
|
|
308 | default: |
|
|
309 | LOG (llevError, "object with unsupported physics subtype %d: %s\n", ob->subtype, ob->debug_desc ()); |
|
|
310 | break; |
|
|
311 | } |
|
|
312 | } |
|
|
313 | |
|
|
314 | int |
|
|
315 | maptile::run_physics (tick_t tick, int max_objects) |
|
|
316 | { |
|
|
317 | if (state != MAP_ACTIVE) |
|
|
318 | return 0; |
|
|
319 | |
|
|
320 | int orig_max_object = max_objects; |
|
|
321 | physics_queue &q = pq [queue_of (server_tick)]; |
|
|
322 | |
|
|
323 | //if (q.size()) printf ("q %d < %d\n", q.i, (int)q.size());//D |
|
|
324 | |
|
|
325 | while (object *ob = q.pop ()) |
|
|
326 | { |
|
|
327 | ob->flag [FLAG_PHYSICS_QUEUE] = false; |
|
|
328 | ob->refcnt_dec (); |
|
|
329 | |
|
|
330 | if (ob->map != this) |
|
|
331 | { |
|
|
332 | if (!ob->flag [FLAG_FREED]) |
|
|
333 | { |
|
|
334 | LOG (llevError, "%s: physical object on wrong map\n", ob->debug_desc ()); |
|
|
335 | //ob->map->queue_physics (ob); |
|
|
336 | } |
|
|
337 | } |
|
|
338 | else |
|
|
339 | { |
|
|
340 | //printf ("handling ob %s\n", ob->debug_desc());//D |
|
|
341 | ::run_physics (ob); |
|
|
342 | } |
|
|
343 | |
|
|
344 | if (--max_objects <= 0) |
|
|
345 | break; |
|
|
346 | } |
|
|
347 | |
|
|
348 | return orig_max_object - max_objects; |
|
|
349 | } |
|
|
350 | |
|
|
351 | void |
|
|
352 | maptile::queue_physics (object *ob, int after) |
|
|
353 | { |
|
|
354 | if (!after) after = 14; //D |
|
|
355 | if (!ob->flag [FLAG_PHYSICS_QUEUE]) |
|
|
356 | { |
|
|
357 | ob->flag [FLAG_PHYSICS_QUEUE] = true; |
|
|
358 | ob->refcnt_inc (); |
|
|
359 | |
|
|
360 | pq [queue_of (server_tick + min (PHYSICS_QUEUES - 2, after))].push_back (ob); |
|
|
361 | } |
|
|
362 | } |
|
|
363 | |
|
|
364 | static void |
|
|
365 | queue_physics_at (maptile *m, int x, int y) |
|
|
366 | { |
|
|
367 | mapspace &ms = m->at (x, y); |
|
|
368 | |
|
|
369 | for (object *ob = ms.bot; ob; ob = ob->above) |
|
|
370 | if (ob->type == PHYSICS) |
|
|
371 | m->queue_physics (ob, 1); |
|
|
372 | } |
|
|
373 | |
|
|
374 | // this mapspace has changed - potentially activate dormant physics objects |
|
|
375 | // in the vicinity. vicinity is the 4 spaces around in the same z layer, and above and below. |
|
|
376 | // TODO: maybe include diagonals in the same z-layer? |
|
|
377 | // TODO: do not go through floors? |
|
|
378 | void |
|
|
379 | maptile::queue_physics_at (int x, int y) |
|
|
380 | { |
|
|
381 | if (maptile *m = tile_available (TILE_DOWN)) |
|
|
382 | ::queue_physics_at (m, x, y); |
|
|
383 | |
|
|
384 | if (maptile *m = tile_available (TILE_UP)) |
|
|
385 | ::queue_physics_at (m, x, y); |
|
|
386 | |
|
|
387 | ::queue_physics_at (this, x, y); |
|
|
388 | |
|
|
389 | for (int dir = 1; dir < 8; dir += 2) |
|
|
390 | { |
|
|
391 | mapxy pos (this, x, y); |
|
|
392 | pos.move (dir); |
|
|
393 | if (pos.normalise ()) |
|
|
394 | ::queue_physics_at (pos.m, pos.x, pos.y); |
|
|
395 | } |
|
|
396 | } |
|
|
397 | |
|
|
398 | void |
|
|
399 | maptile::activate_physics () |
|
|
400 | { |
|
|
401 | // most of this is total overkill, but better be safe than sorry, eh? |
|
|
402 | |
|
|
403 | coroapi::cede_to_tick (); |
|
|
404 | |
|
|
405 | if (maptile *m = tile_map [TILE_UP]) |
|
|
406 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
|
|
407 | ms->invalidate (); // invalidate faces, in case... |
|
|
408 | |
|
|
409 | coroapi::cede_to_tick (); |
|
|
410 | |
|
|
411 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
|
|
412 | for (object *op = ms->bot; op; op = op->above) |
|
|
413 | if (op->type == PHYSICS) |
|
|
414 | queue_physics (op, 0); |
|
|
415 | } |
|
|
416 | |
|
|
417 | ///////////////////////////////////////////////////////////////////////////// |
|
|
418 | |
27 | #define FANCY_GRAPHICS 0 |
419 | #define FANCY_GRAPHICS 0 |
28 | |
420 | |
29 | static void |
421 | static void |
30 | gen_quadspace (maptile *m, int mx, int my, int x, int y, int z) |
422 | gen_quadspace (maptile *m, int mx, int my, int x, int y, int z) |
31 | { |
423 | { |
… | |
… | |
38 | static frac2d vec_gen1 (6, 2, 0.5, 1); |
430 | static frac2d vec_gen1 (6, 2, 0.5, 1); |
39 | static frac2d vec_gen2 (6, 2, 0.5, 2); |
431 | static frac2d vec_gen2 (6, 2, 0.5, 2); |
40 | |
432 | |
41 | const float continent_scale = 0.00008; |
433 | const float continent_scale = 0.00008; |
42 | |
434 | |
43 | vec2d perturb_pos = pow (P, 1.4) * 1e-5; |
435 | vec2d perturb_pos = pow (P, vec2d (1.4)) * 1e-5; |
44 | |
436 | |
45 | vec2d perturb ( |
437 | vec2d perturb ( |
46 | vec_gen1.fBm (perturb_pos), |
438 | vec_gen1.fBm (perturb_pos), |
47 | vec_gen2.fBm (perturb_pos) |
439 | vec_gen2.fBm (perturb_pos) |
48 | ); |
440 | ); |
… | |
… | |
62 | |
454 | |
63 | const float N = (25000 - 1) * continent_scale; |
455 | const float N = (25000 - 1) * continent_scale; |
64 | |
456 | |
65 | // we clip a large border on the perturbed shape, to get irregular coastline |
457 | // we clip a large border on the perturbed shape, to get irregular coastline |
66 | // and then clip a smaller border around the real shape |
458 | // and then clip a smaller border around the real shape |
67 | continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale); |
459 | //continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale); |
68 | continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale); |
460 | continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale); |
69 | |
461 | |
70 | enum { |
462 | enum { |
71 | T_NONE, |
463 | T_NONE, |
72 | T_OCEAN, |
464 | T_OCEAN, |
73 | T_RIVER, |
465 | T_RIVER, |
74 | T_VALLEY, |
466 | T_VALLEY, |
75 | T_MOUNTAIN, |
467 | T_MOUNTAIN, |
76 | T_UNDERGROUND, |
468 | T_UNDERGROUND, |
|
|
469 | T_AIR, // unused |
77 | T_ACQUIFER, |
470 | T_ACQUIFER, |
78 | } t = T_NONE; |
471 | } t = T_NONE; |
79 | |
472 | |
80 | vec3d c; |
473 | vec3d c; |
81 | int h0 = 0; // "water level" |
474 | int h0 = 0; // "water level" |
82 | int h = 1000000; // height form heightmap |
475 | int h = 1000000; // height form heightmap |
83 | |
476 | |
84 | // the continent increases in height from 0 to ~700 levels in the absence of anything else |
477 | // the continent increases in height from 0 to ~700 levels in the absence of anything else |
85 | // thats about one step every 7 maps. |
478 | // thats about one step every 7 maps. |
86 | int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); |
479 | int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); |
87 | int river_height = base_height * 9 / 10; |
480 | int river_height = base_height; // * 9 / 10; |
88 | |
481 | |
89 | // add this to rivers to "dry them out" |
482 | // 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)); |
483 | float dry_out = max (0.f, lerp (xy_gradient, 0.7f, 1.f, 0.f, 0.3f)); |
91 | |
484 | |
92 | static frac2d river_gen (2); |
485 | static frac2d river_gen (2); |
93 | float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)) + dry_out; |
486 | 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; |
487 | float river2 = river_gen.ridgedmultifractal (P * 0.04, 0.8, 10) - y_gradient * 0.2 - 0.16 - dry_out; |
95 | |
488 | |
96 | float valley = river1 - 0.2f; |
489 | float valley = river1 - 0.2f; |
97 | |
490 | |
98 | static frac2d mountain_gen (8, 2.14, 0.5); |
491 | static frac2d mountain_gen (6, 2.14, 0.5); |
99 | float mountain = mountain_gen.ridgedmultifractal (P * 0.004); |
492 | float mountain = mountain_gen.ridgedmultifractal (P * 0.004); |
100 | |
493 | |
101 | //TODO: mountains should not lower the height, should they? |
494 | //TODO: mountains should not lower the height, should they? |
102 | t = valley < 0 ? T_VALLEY : T_MOUNTAIN; |
495 | t = valley < 0 ? T_VALLEY : T_MOUNTAIN; |
103 | c = blend0 (vec3d (0, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f); |
496 | 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); |
497 | h = blend0 (base_height + continent * 0, base_height + mountain * xy_gradient * 100, valley, 0.1f); |
105 | |
498 | |
106 | if (river1 < 0.01f) |
499 | if (river1 < 0.01f) |
107 | { |
500 | { |
108 | // main rivers - they cut deeply into the mountains (base_height * 0.9f) |
501 | // main rivers - they cut deeply into the mountains (base_height * 0.9f) |
|
|
502 | // well, silly, they don't |
109 | t = T_RIVER; |
503 | t = T_RIVER; |
110 | c = vec3d (0.2, 0.2, 1); |
504 | c = vec3d (0.2, 0.2, 1); |
111 | h0 = river_height; |
505 | h0 = river_height; |
112 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1)); |
506 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -10, -1)); |
113 | } |
507 | } |
114 | |
508 | |
115 | if (river2 > 0) |
509 | if (river2 > 0) |
116 | { |
510 | { |
117 | t = T_RIVER; |
511 | t = T_RIVER; |
118 | c = vec3d (0.2, 0.2, 1); |
512 | c = vec3d (0.2, 0.2, 1); |
119 | h0 = river_height; |
513 | h0 = river_height; |
120 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1)); |
514 | min_it (h, river_height + max (-5, lerp<float> (river2, 0.01f, 0, -4, -1))); |
121 | } |
515 | } |
122 | |
516 | |
123 | if (continent < 0) |
517 | if (continent < 0) |
124 | { |
518 | { |
125 | t = T_OCEAN; |
519 | t = T_OCEAN; |
|
|
520 | h0 = 0; |
126 | min_it (h, min (continent * 200, -1)); |
521 | min_it (h, min (continent * 200, -1)); |
127 | c = vec3d (0, 0, 1); |
522 | c = vec3d (0, 0, 1); |
128 | } |
523 | } |
129 | |
524 | |
130 | // now we have the base height, and base terrain |
525 | // now we have the base height, and base terrain |
… | |
… | |
135 | |
530 | |
136 | max_it (h0, h); |
531 | max_it (h0, h); |
137 | |
532 | |
138 | // everything below the surface is underground, or a variant |
533 | // everything below the surface is underground, or a variant |
139 | if (z < h) |
534 | if (z < h) |
140 | { |
|
|
141 | t = T_UNDERGROUND; |
535 | t = T_UNDERGROUND; |
142 | } |
|
|
143 | |
536 | |
144 | // put acquifers a bit below the surface, to reduce them leaking out (will still happen) |
537 | // put acquifers a bit below the surface, to reduce them leaking out (will still happen) |
145 | if (z < h - 3) |
538 | if (z < h - 3) |
146 | { |
539 | { |
147 | static frac3d acquifer_gen (4); |
540 | static frac3d acquifer_gen (4); |
… | |
… | |
151 | { |
544 | { |
152 | t = T_ACQUIFER; |
545 | t = T_ACQUIFER; |
153 | c = vec3d (1,1,1); |
546 | c = vec3d (1,1,1); |
154 | } |
547 | } |
155 | } |
548 | } |
|
|
549 | |
|
|
550 | //printf ("+%d+%d %d z %d h %d,%d P%g,%g\n", mx, my, t, z, h,h0, P[0],P[1]);//D |
156 | |
551 | |
157 | // TODO: caves |
552 | // TODO: caves |
158 | // TODO: chees areas |
553 | // TODO: chees areas |
159 | // TODO: minerals |
554 | // TODO: minerals |
160 | // TODO: monsters |
555 | // TODO: monsters |
… | |
… | |
168 | putc (clamp<int> (255 * c[2], 0, 255), stdout); |
563 | putc (clamp<int> (255 * c[2], 0, 255), stdout); |
169 | #else |
564 | #else |
170 | shstr arch_floor = shstr ("quad_open_space"); |
565 | shstr arch_floor = shstr ("quad_open_space"); |
171 | shstr arch_wall; |
566 | shstr arch_wall; |
172 | |
567 | |
|
|
568 | // TODO: this is shit - we should never generatea water surface, but only |
|
|
569 | // water above the surface |
173 | switch (t) |
570 | switch (t) |
174 | { |
571 | { |
175 | case T_OCEAN: |
572 | case T_OCEAN: |
|
|
573 | if (z < h0) |
|
|
574 | arch_wall = shstr_quad_water_source; |
|
|
575 | else if (z == h0) |
|
|
576 | arch_floor = shstr ("quad_ocean_floor"); |
|
|
577 | break; |
|
|
578 | |
176 | case T_RIVER: |
579 | case T_RIVER: |
177 | if (z < h0) |
580 | if (z < h0) |
|
|
581 | arch_wall = shstr_quad_water_source; |
|
|
582 | else if (z == h0) |
178 | arch_wall = shstr ("quad_water_wall"); |
583 | arch_floor = shstr ("quad_water_floor"); |
179 | break; |
584 | break; |
180 | |
585 | |
181 | case T_VALLEY: |
586 | case T_VALLEY: |
182 | if (z == h) |
587 | if (z == h) |
183 | arch_floor = shstr ("quad_dirt_floor"); |
588 | arch_floor = shstr ("quad_dirt_floor"); |
… | |
… | |
190 | |
595 | |
191 | case T_UNDERGROUND: |
596 | case T_UNDERGROUND: |
192 | // todo, use a fractal |
597 | // todo, use a fractal |
193 | if (z < h - 10) |
598 | if (z < h - 10) |
194 | { |
599 | { |
|
|
600 | arch_floor = shstr ("quad_stone_floor"); |
|
|
601 | arch_wall = shstr ("quad_stone_wall"); |
|
|
602 | } |
|
|
603 | else |
|
|
604 | { |
195 | arch_floor = shstr ("quad_dirt_floor"); |
605 | arch_floor = shstr ("quad_dirt_floor"); |
196 | arch_wall = shstr ("quad_dirt_wall"); |
606 | arch_wall = shstr ("quad_dirt_wall"); |
197 | } |
607 | } |
198 | else |
|
|
199 | { |
|
|
200 | arch_floor = shstr ("quad_stone_floor"); |
|
|
201 | arch_wall = shstr ("quad_stone_wall"); |
|
|
202 | } |
|
|
203 | break; |
608 | break; |
204 | |
609 | |
205 | case T_ACQUIFER: |
610 | case T_ACQUIFER: |
206 | arch_wall = shstr ("quad_water_wall"); |
611 | arch_wall = shstr_quad_water_source; |
207 | break; |
612 | break; |
208 | |
613 | |
209 | default: |
614 | default: |
210 | abort (); |
615 | abort (); |
211 | } |
616 | } |
… | |
… | |
227 | for (int mx = 0; mx < 50; ++mx) |
632 | for (int mx = 0; mx < 50; ++mx) |
228 | for (int my = 0; my < 50; ++my) |
633 | for (int my = 0; my < 50; ++my) |
229 | gen_quadspace (m, mx, my, x + mx, y + my, z); |
634 | gen_quadspace (m, mx, my, x + mx, y + my, z); |
230 | } |
635 | } |
231 | |
636 | |
|
|
637 | ///////////////////////////////////////////////////////////////////////////// |
|
|
638 | |
232 | void noise_test (); |
639 | void noise_test (); |
233 | void noise_test () |
640 | void noise_test () |
234 | { |
641 | { |
235 | #if 1 |
642 | #if 1 |
236 | int Nw = 700; |
643 | int Nw = 700; |
… | |
… | |
250 | { |
657 | { |
251 | if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D |
658 | if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D |
252 | |
659 | |
253 | for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 1000, y + 22000, 0); |
660 | for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 1000, y + 22000, 0); |
254 | for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 12500, y + 12500, 0); |
661 | for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 12500, y + 12500, 0); |
255 | for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 22000, y + 22500, 0); |
662 | for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 22000, y + 22000, 0); |
256 | } |
663 | } |
257 | |
664 | |
258 | //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout); |
665 | //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout); |
259 | //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); |
666 | //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); |
260 | //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout); |
667 | //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout); |
… | |
… | |
319 | } |
726 | } |
320 | #endif |
727 | #endif |
321 | |
728 | |
322 | exit (0); |
729 | exit (0); |
323 | } |
730 | } |
|
|
731 | |