ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/quadland.C
(Generate patch)

Comparing deliantra/server/server/quadland.C (file contents):
Revision 1.8 by root, Tue May 3 17:12:15 2011 UTC vs.
Revision 1.24 by root, Wed Dec 5 19:03:27 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines