ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/quadland.C
Revision: 1.6
Committed: Mon May 2 16:57:28 2011 UTC (13 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.5: +0 -1 lines
Log Message:
do not pull an elmex

File Contents

# User Rev Content
1 root 1.1 /*
2     * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3     *
4     * Copyright (©) 2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5     *
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
8     * Free Software Foundation, either version 3 of the License, or (at your
9     * option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
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
18     * <http://www.gnu.org/licenses/>.
19     *
20     * The authors can be reached via e-mail to <support@deliantra.net>
21     */
22    
23     #include <global.h>
24    
25     #include "noise.h"
26    
27 root 1.5 /////////////////////////////////////////////////////////////////////////////
28    
29     void
30     move_into_wall (object *ob, object *wall)
31     {
32     bool visible = !wall->invisible && !ob->flag [FLAG_BLIND];
33    
34     if (wall->flag [FLAG_IS_QUAD] && visible)
35     {
36     maptile *m = wall->map;
37    
38     if (m->tile_path [TILE_UP])
39     if (maptile *up = m->tile_available (TILE_UP))
40     {
41     if (ob->blocked (up, ob->x, ob->y))
42     ob->failmsg (format ("Ouch, you hit your head while climbing the %s! H<Didn't you see the ceiling?>", query_name (wall)));
43     //TODO: reduce health
44     else if (ob->blocked (up, wall->x, wall->y))
45     ob->failmsg (format ("You try to climb up, but the %s is too high for you!", query_name (wall)));
46     //TODO: reduce health
47     else
48     {
49     ob->statusmsg (format ("You successfully climb up the %s.", query_name (wall)));
50     // here we assume that ob is a player...
51     ob->enter_map (up, wall->x, wall->y);
52     }
53     }
54     else
55     ob->failmsg (format ("You try to climb the %s, but you fall down! H<Try again.>", query_name (wall)));
56     else
57     ob->failmsg (format ("You fail to climb up the %s! H<You cannot climb up here.>", query_name (wall)));
58    
59    
60     return;
61     }
62    
63     if (ob->contr->ns->bumpmsg)
64     {
65     ob->play_sound (sound_find ("bump_wall"));
66    
67     ob->statusmsg (visible
68     ? format ("You bump into the %s.", query_name (wall))
69     : "You bump into something."
70     );
71     }
72     }
73    
74     /////////////////////////////////////////////////////////////////////////////
75    
76 root 1.2 #define FANCY_GRAPHICS 0
77 root 1.1
78     static void
79 root 1.2 gen_quadspace (maptile *m, int mx, int my, int x, int y, int z)
80 root 1.1 {
81     vec2d P = vec2d (x, y);
82    
83     const int deep_sea_z = -200;
84    
85     static frac2d gen(13);
86    
87     static frac2d vec_gen1 (6, 2, 0.5, 1);
88     static frac2d vec_gen2 (6, 2, 0.5, 2);
89    
90     const float continent_scale = 0.00008;
91    
92     vec2d perturb_pos = pow (P, 1.4) * 1e-5;
93    
94     vec2d perturb (
95     vec_gen1.fBm (perturb_pos),
96     vec_gen2.fBm (perturb_pos)
97     );
98    
99     float perturb_perturb = 1 - (P[1] - P[0]) * (1. / 25000 / 2);
100     perturb_perturb = perturb_perturb * perturb_perturb * 0.4;
101     perturb *= perturb_perturb;
102    
103     vec2d P_continent = P * continent_scale + perturb;
104    
105     static frac2d continent_gen (13, 2.13, 0.5);
106     float continent = continent_gen.fBm (P_continent) + 0.05f;
107    
108     float x_gradient = P[0] * (1. / 25000);
109     float y_gradient = P[1] * (1. / 25000);
110     float xy_gradient = (P[0] + P[1]) * (0.5 / 25000);
111    
112     const float N = (25000 - 1) * continent_scale;
113    
114     // we clip a large border on the perturbed shape, to get irregular coastline
115     // and then clip a smaller border around the real shape
116     continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale);
117     continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale);
118    
119     enum {
120     T_NONE,
121     T_OCEAN,
122     T_RIVER,
123     T_VALLEY,
124     T_MOUNTAIN,
125     T_UNDERGROUND,
126     T_ACQUIFER,
127     } t = T_NONE;
128    
129     vec3d c;
130 root 1.2 int h0 = 0; // "water level"
131 root 1.1 int h = 1000000; // height form heightmap
132    
133     // the continent increases in height from 0 to ~700 levels in the absence of anything else
134     // thats about one step every 7 maps.
135     int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f);
136     int river_height = base_height * 9 / 10;
137    
138     // add this to rivers to "dry them out"
139     float dry_out = max (0.f, lerp (xy_gradient, 0.7f, 1.f, 0.f, 0.3f));
140    
141     static frac2d river_gen (2);
142     float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)) + dry_out;
143     float river2 = river_gen.ridgedmultifractal (P * 0.04, 0.8, 10) - y_gradient * 0.2 - 0.16 - dry_out;
144    
145     float valley = river1 - 0.2f;
146    
147     static frac2d mountain_gen (8, 2.14, 0.5);
148     float mountain = mountain_gen.ridgedmultifractal (P * 0.004);
149    
150     //TODO: mountains should not lower the height, should they?
151     t = valley < 0 ? T_VALLEY : T_MOUNTAIN;
152     c = blend0 (vec3d (0, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f);
153     h = blend0 (base_height + continent * 300, base_height + mountain * xy_gradient * 400, valley, 0.1f);
154    
155     if (river1 < 0.01f)
156     {
157     // main rivers - they cut deeply into the mountains (base_height * 0.9f)
158     t = T_RIVER;
159     c = vec3d (0.2, 0.2, 1);
160 root 1.2 h0 = river_height;
161 root 1.1 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1));
162     }
163    
164     if (river2 > 0)
165     {
166     t = T_RIVER;
167     c = vec3d (0.2, 0.2, 1);
168 root 1.2 h0 = river_height;
169 root 1.1 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1));
170     }
171    
172     if (continent < 0)
173     {
174     t = T_OCEAN;
175     min_it (h, min (continent * 200, -1));
176     c = vec3d (0, 0, 1);
177     }
178    
179     // now we have the base height, and base terrain
180    
181     #if FANCY_GRAPHICS
182     z = h; // show the surface, not the given z layer
183     #endif
184    
185 root 1.2 max_it (h0, h);
186    
187 root 1.1 // everything below the surface is underground, or a variant
188     if (z < h)
189     {
190     t = T_UNDERGROUND;
191     }
192    
193     // put acquifers a bit below the surface, to reduce them leaking out (will still happen)
194     if (z < h - 3)
195     {
196     static frac3d acquifer_gen (4);
197     float acquifer = acquifer_gen.ridgedmultifractal (vec3d (x * 0.001, y * 0.001, z * 0.01), 1.003, 2);
198    
199     if (acquifer > 0.48)
200     {
201     t = T_ACQUIFER;
202     c = vec3d (1,1,1);
203     }
204     }
205    
206     // TODO: caves
207     // TODO: chees areas
208     // TODO: minerals
209     // TODO: monsters
210    
211     #if FANCY_GRAPHICS
212     float v = clamp (lerp<float> (h, deep_sea_z, 800, 0.f, 1.f), 0.f, 1.f);
213     c *= v;
214    
215     putc (clamp<int> (255 * c[0], 0, 255), stdout);
216     putc (clamp<int> (255 * c[1], 0, 255), stdout);
217     putc (clamp<int> (255 * c[2], 0, 255), stdout);
218 root 1.2 #else
219     shstr arch_floor = shstr ("quad_open_space");
220     shstr arch_wall;
221    
222     switch (t)
223     {
224     case T_OCEAN:
225 root 1.4 if (z < h0)
226     arch_wall = shstr ("quad_water_wall");
227     else
228     arch_floor = shstr ("quad_ocean_floor");
229     break;
230    
231 root 1.2 case T_RIVER:
232 root 1.3 if (z < h0)
233 root 1.2 arch_wall = shstr ("quad_water_wall");
234 root 1.4 else
235     arch_floor = shstr ("quad_water_floor");
236 root 1.2 break;
237    
238     case T_VALLEY:
239     if (z == h)
240 root 1.3 arch_floor = shstr ("quad_dirt_floor");
241 root 1.2 break;
242    
243     case T_MOUNTAIN:
244     if (z == h)
245 root 1.3 arch_floor = shstr ("quad_stone_floor");
246 root 1.2 break;
247    
248     case T_UNDERGROUND:
249     // todo, use a fractal
250     if (z < h - 10)
251     {
252     arch_floor = shstr ("quad_dirt_floor");
253     arch_wall = shstr ("quad_dirt_wall");
254     }
255     else
256     {
257     arch_floor = shstr ("quad_stone_floor");
258     arch_wall = shstr ("quad_stone_wall");
259     }
260     break;
261    
262     case T_ACQUIFER:
263     arch_wall = shstr ("quad_water_wall");
264     break;
265    
266     default:
267     abort ();
268     }
269    
270     if (arch_floor)
271     m->insert (archetype::get (arch_floor), mx, my);
272    
273     if (arch_wall)
274     m->insert (archetype::get (arch_wall ), mx, my);
275 root 1.1 #endif
276     }
277    
278 root 1.2 void
279     gen_quadmap (maptile *m, int x, int y, int z)
280     {
281     assert (m->width == 50);
282     assert (m->height == 50);
283    
284     for (int mx = 0; mx < 50; ++mx)
285     for (int my = 0; my < 50; ++my)
286     gen_quadspace (m, mx, my, x + mx, y + my, z);
287     }
288    
289 root 1.5 /////////////////////////////////////////////////////////////////////////////
290    
291 root 1.1 void noise_test ();
292     void noise_test ()
293     {
294 root 1.2 #if 1
295 root 1.1 int Nw = 700;
296    
297     printf ("P6 %d %d 255\n", Nw * 3, Nw * 2);
298     // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
299     for (int y = 0; y < Nw; ++y)
300     {
301     if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D
302    
303 root 1.2 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x * 25000 / Nw, y * 25000 / Nw, 0);
304 root 1.1
305 root 1.2 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 400, y, 0);
306     for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 22000, y + 2000, 0);
307 root 1.1 }
308     for (int y = 0; y < Nw; ++y)
309     {
310     if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D
311    
312 root 1.2 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 1000, y + 22000, 0);
313     for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 12500, y + 12500, 0);
314     for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 22000, y + 22500, 0);
315 root 1.1 }
316    
317     //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout);
318     //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
319     //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout);
320     //putc (256 * gen.turbulence (vec2d (x * 0.004 - 1, y * 0.004 - 1), 10), stdout);
321     //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout);
322     //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout);
323     //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout);
324     //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout);
325     #elif 1
326     int N = 25000;
327    
328     printf ("P6 %d %d 255\n", N, N);
329     for (int y = 0; y < N; ++y)
330     {
331     if (!(y&63))fprintf (stderr, "y %d\n", y);//D
332    
333 root 1.2 for (int x = 0; x < N; ++x) gen_quadspace (0, 0, 0, x, y, 0);
334 root 1.1 }
335     #else
336     int N = 200;
337    
338     //printf ("P6 %d %d 255\n", N, N);
339     // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
340     for (int z = 0; z < N; ++z)
341     {
342     if (!(z&7))fprintf (stderr, "z %d\n", z);//D
343     for (int y = 0; y < N; ++y)
344     for (int x = 0; x < N; ++x)
345     {
346     #if 0
347     float v = gen3.ridgedmultifractal (vec3d (x * 0.001 + 0.2, y * 0.001 + 0.2, z * 0.01 + 0.2), 1.03, 2) * 2;
348    
349     if (z < 64)
350     v = v * (z * z) / (64 * 64);
351    
352     if (v <= 0.9)
353     continue;
354     #endif
355     static frac3d gen3 (10);
356     //float v = gen3.turbulence (vec3d (x * 0.01, y * 0.01, z * 0.01));
357     float v = gen3.ridgedmultifractal (vec3d (x * 0.001, y * 0.001, z * 0.001), 1.003, 2);
358    
359     if (v <= 0.48) continue;
360    
361     float r[4];
362     int i[4];
363    
364     r[0] = x;
365     r[1] = y;
366     r[2] = z;
367     r[3] = v;
368    
369     memcpy (i, r, 16);
370    
371     i[0] = htonl (i[0]);
372     i[1] = htonl (i[1]);
373     i[2] = htonl (i[2]);
374     i[3] = htonl (i[3]);
375    
376     fwrite (i, 4*4, 1, stdout);
377     }
378     }
379     #endif
380    
381     exit (0);
382     }