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