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.1 by root, Sun May 1 13:18:24 2011 UTC vs.
Revision 1.2 by root, Sun May 1 16:58:17 2011 UTC

22 22
23#include <global.h> 23#include <global.h>
24 24
25#include "noise.h" 25#include "noise.h"
26 26
27#define FANCY_GRAPHICS 1 27#define FANCY_GRAPHICS 0
28 28
29static void 29static void
30gen_quadspace (int x, int y, int z) 30gen_quadspace (maptile *m, int mx, int my, int x, int y, int z)
31{ 31{
32 vec2d P = vec2d (x, y); 32 vec2d P = vec2d (x, y);
33 33
34 const int deep_sea_z = -200; 34 const int deep_sea_z = -200;
35 35
76 T_UNDERGROUND, 76 T_UNDERGROUND,
77 T_ACQUIFER, 77 T_ACQUIFER,
78 } t = T_NONE; 78 } t = T_NONE;
79 79
80 vec3d c; 80 vec3d c;
81 int h0 = 0; // "water level"
81 int h = 1000000; // height form heightmap 82 int h = 1000000; // height form heightmap
82 83
83 // the continent increases in height from 0 to ~700 levels in the absence of anything else 84 // the continent increases in height from 0 to ~700 levels in the absence of anything else
84 // thats about one step every 7 maps. 85 // thats about one step every 7 maps.
85 int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); 86 int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f);
105 if (river1 < 0.01f) 106 if (river1 < 0.01f)
106 { 107 {
107 // main rivers - they cut deeply into the mountains (base_height * 0.9f) 108 // main rivers - they cut deeply into the mountains (base_height * 0.9f)
108 t = T_RIVER; 109 t = T_RIVER;
109 c = vec3d (0.2, 0.2, 1); 110 c = vec3d (0.2, 0.2, 1);
111 h0 = river_height;
110 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1)); 112 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1));
111 } 113 }
112 114
113 if (river2 > 0) 115 if (river2 > 0)
114 { 116 {
115 t = T_RIVER; 117 t = T_RIVER;
116 c = vec3d (0.2, 0.2, 1); 118 c = vec3d (0.2, 0.2, 1);
119 h0 = river_height;
117 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1)); 120 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1));
118 } 121 }
119 122
120 if (continent < 0) 123 if (continent < 0)
121 { 124 {
127 // now we have the base height, and base terrain 130 // now we have the base height, and base terrain
128 131
129#if FANCY_GRAPHICS 132#if FANCY_GRAPHICS
130 z = h; // show the surface, not the given z layer 133 z = h; // show the surface, not the given z layer
131#endif 134#endif
135
136 max_it (h0, h);
132 137
133 // everything below the surface is underground, or a variant 138 // everything below the surface is underground, or a variant
134 if (z < h) 139 if (z < h)
135 { 140 {
136 t = T_UNDERGROUND; 141 t = T_UNDERGROUND;
159 c *= v; 164 c *= v;
160 165
161 putc (clamp<int> (255 * c[0], 0, 255), stdout); 166 putc (clamp<int> (255 * c[0], 0, 255), stdout);
162 putc (clamp<int> (255 * c[1], 0, 255), stdout); 167 putc (clamp<int> (255 * c[1], 0, 255), stdout);
163 putc (clamp<int> (255 * c[2], 0, 255), stdout); 168 putc (clamp<int> (255 * c[2], 0, 255), stdout);
169#else
170 shstr arch_floor = shstr ("quad_open_space");
171 shstr arch_wall;
172
173 switch (t)
174 {
175 case T_OCEAN:
176 case T_RIVER:
177 if (z <= h0)
178 arch_wall = shstr ("quad_water_wall");
179 break;
180
181 case T_VALLEY:
182 if (z == h)
183 {
184 arch_floor = shstr ("quad_dirt_floor");
185 arch_wall = shstr ("quad_dirt_wall");
186 }
187 break;
188
189 case T_MOUNTAIN:
190 if (z == h)
191 {
192 arch_floor = shstr ("quad_stone_floor");
193 arch_wall = shstr ("quad_stone_wall");
194 }
195 break;
196
197 case T_UNDERGROUND:
198 // todo, use a fractal
199 if (z < h - 10)
200 {
201 arch_floor = shstr ("quad_dirt_floor");
202 arch_wall = shstr ("quad_dirt_wall");
203 }
204 else
205 {
206 arch_floor = shstr ("quad_stone_floor");
207 arch_wall = shstr ("quad_stone_wall");
208 }
209 break;
210
211 case T_ACQUIFER:
212 arch_wall = shstr ("quad_water_wall");
213 break;
214
215 default:
216 abort ();
217 }
218
219 if (arch_floor)
220 m->insert (archetype::get (arch_floor), mx, my);
221
222 if (arch_wall)
223 m->insert (archetype::get (arch_wall ), mx, my);
164#endif 224#endif
225}
226
227void
228gen_quadmap (maptile *m, int x, int y, int z)
229{
230 assert (m->width == 50);
231 assert (m->height == 50);
232
233 for (int mx = 0; mx < 50; ++mx)
234 for (int my = 0; my < 50; ++my)
235 gen_quadspace (m, mx, my, x + mx, y + my, z);
165} 236}
166 237
167void noise_test (); 238void noise_test ();
168void noise_test () 239void noise_test ()
169{ 240{
170#if 0 241#if 1
171 int Nw = 700; 242 int Nw = 700;
172 243
173 printf ("P6 %d %d 255\n", Nw * 3, Nw * 2); 244 printf ("P6 %d %d 255\n", Nw * 3, Nw * 2);
174 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm 245 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
175 for (int y = 0; y < Nw; ++y) 246 for (int y = 0; y < Nw; ++y)
176 { 247 {
177 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D 248 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D
178 249
179 for (int x = 0; x < Nw; ++x) gen_quadspace (x * 25000 / Nw, y * 25000 / Nw, 0); 250 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x * 25000 / Nw, y * 25000 / Nw, 0);
180 251
181 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 400, y, 0); 252 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 400, y, 0);
182 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 22000, y + 2000, 0); 253 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 22000, y + 2000, 0);
183 } 254 }
184 for (int y = 0; y < Nw; ++y) 255 for (int y = 0; y < Nw; ++y)
185 { 256 {
186 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D 257 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D
187 258
188 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 1000, y + 22000, 0); 259 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 1000, y + 22000, 0);
189 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 12500, y + 12500, 0); 260 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 12500, y + 12500, 0);
190 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 22000, y + 22500, 0); 261 for (int x = 0; x < Nw; ++x) gen_quadspace (0, 0, 0, x + 22000, y + 22500, 0);
191 } 262 }
192 263
193 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout); 264 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout);
194 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); 265 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
195 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout); 266 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout);
204 printf ("P6 %d %d 255\n", N, N); 275 printf ("P6 %d %d 255\n", N, N);
205 for (int y = 0; y < N; ++y) 276 for (int y = 0; y < N; ++y)
206 { 277 {
207 if (!(y&63))fprintf (stderr, "y %d\n", y);//D 278 if (!(y&63))fprintf (stderr, "y %d\n", y);//D
208 279
209 for (int x = 0; x < N; ++x) gen_quadspace (x, y, 0); 280 for (int x = 0; x < N; ++x) gen_quadspace (0, 0, 0, x, y, 0);
210 } 281 }
211#else 282#else
212 int N = 200; 283 int N = 200;
213 284
214 //printf ("P6 %d %d 255\n", N, N); 285 //printf ("P6 %d %d 255\n", N, N);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines