Commits

Anonymous committed f7b810f

Added lakes and deserts. Fixed SERIOUS bug in glTypes.h
(Multiplying a GLcoord would perform a SUBTRACT! Copy & paste
code is bad, Shamus!)

Comments (0)

Files changed (11)

Terrain/CGrass.cpp

 /*-----------------------------------------------------------------------------
 
 -----------------------------------------------------------------------------*/
- /*(
-static GLvector random_normal ()
-{
-
-  GLvector  normal;
-
-  normal = glVector (RandomFloat () - 0.5f, RandomFloat () - 0.5f, 0.5f); 
-  return glVectorNormalize (normal);
-
-}*/
-
-/*-----------------------------------------------------------------------------
-
------------------------------------------------------------------------------*/
 
 CGrass::CGrass () 
 {
   do_grass = CacheSurface (world_x, world_y) == SURFACE_GRASS;
   if (_walk.x % _current_distance || _walk.y  % _current_distance)
     do_grass = false;
-  //if ((_walk.x + _walk.y) % 2)
-    //do_grass = false;
   if (do_grass) {
     GLvector    vb0, vb1, vb2, vb3;
     GLvector    vt0, vt1, vt2, vt3;
     root.x = (float)world_x + (WorldNoisef (world_x + world_y * GRASS_SIZE) -0.5f) * 2.0f;
     root.y = (float)world_y + (WorldNoisef (world_x + world_y * GRASS_SIZE) -0.5f) * 2.0f;
     root.z = CacheElevation (root.x, root.y);
-    height = 0.1f + r.moisture * r.temperature;
+    height = 0.05f + r.moisture * r.temperature;
     size.x = 0.2f + WorldNoisef (world_x - world_y * GRASS_SIZE) * 0.5f;
     size.y = WorldNoisef (world_x + world_y * GRASS_SIZE) * height + height;
     do_flower = r.has_flowers;

Terrain/CPage.cpp

       c->surface = SURFACE_GRASS;
     else //Too cold or dry
       c->surface = SURFACE_ROCK;
-
-
+    if (region.climate == CLIMATE_DESERT)
+      c->surface = SURFACE_SAND;
     //Sand is only for coastal regions
     if (low <= region.beach_threshold && (region.climate == CLIMATE_COAST))
       c->surface = SURFACE_SAND;

Terrain/CTree.cpp

     m->PushVertex (glVector (fsize,  0.0f, level2), UP, glVector ( 1.0f, 0.0f));//6
     m->PushVertex (glVector (0.0f,  fsize, level2), UP, glVector ( 1.0f, 1.0f));//7
     m->PushVertex (glVector (-fsize, 0.0f, level2), UP, glVector ( 0.5f, 1.0f));//8
+    //Center, but lower
+    m->PushVertex (glVector ( 0.0f, 0.0f, level1 / 8), UP, glVector ( 0.75f, 0.5f));
+    
+    //Cap
+    m->PushTriangle (base_index, base_index + 2, base_index + 1);
+    m->PushTriangle (base_index, base_index + 3, base_index + 2);
+    m->PushTriangle (base_index, base_index + 4, base_index + 3);
+    m->PushTriangle (base_index, base_index + 1, base_index + 4);
+    //Outer triangles
+    m->PushTriangle (base_index + 5, base_index + 1, base_index + 2);
+    m->PushTriangle (base_index + 6, base_index + 2, base_index + 3);
+    m->PushTriangle (base_index + 7, base_index + 3, base_index + 4);
+    m->PushTriangle (base_index + 8, base_index + 4, base_index + 1);
+    
+    //Inside of the code, to make it 2-sided
+    m->PushTriangle (base_index + 9, base_index + 5, base_index + 6);
+    m->PushTriangle (base_index + 9, base_index + 6, base_index + 7);
+    m->PushTriangle (base_index + 9, base_index + 7, base_index + 8);
+    m->PushTriangle (base_index + 9, base_index + 8, base_index + 5);
 
-    //Cap
-    m->PushTriangle (base_index, base_index + 1, base_index + 2);
-    m->PushTriangle (base_index, base_index + 2, base_index + 3);
-    m->PushTriangle (base_index, base_index + 3, base_index + 4);
-    m->PushTriangle (base_index, base_index + 4, base_index + 1);
-    //Outer triangles
-    m->PushTriangle (base_index + 5, base_index + 2, base_index + 1);
-    m->PushTriangle (base_index + 6, base_index + 3, base_index + 2);
-    m->PushTriangle (base_index + 7, base_index + 4, base_index + 3);
-    m->PushTriangle (base_index + 8, base_index + 1, base_index + 4);
+
 
   } else if (_foliage_style == TREE_FOLIAGE_BOWL) {
     float  tip_height;
     desired.fog_min = 1;
     desired.fog_max = NIGHT_FOG;
     desired.star_fade = 1.0f;
-    desired.color[ENV_COLOR_LIGHT] = glRgba (0.5f, 0.7f, 1.0f);
+    desired.color[ENV_COLOR_LIGHT] = glRgba (0.1f, 0.5f, 1.0f);
     desired.light = VECTOR_NIGHT;
     desired.sun_angle = -90.0f;
     desired.draw_sun = false;
 TODO:
 
 * Small trees up, big trees down
+http://opengameart.org/content/very-low-poly-human
 
 -----------------------------------------------------------------------------*/
 

Terrain/Terraform.cpp

 
   for (xx = -radius; xx <= radius; xx++) {
     for (yy = -radius; yy <= radius; yy++) {
+      if (x + xx < 0 || x + xx >= WORLD_GRID)
+        return false;
+      if (y + yy < 0 || y + yy >= WORLD_GRID)
+        return false;
       r = WorldRegionGet (x + xx, y + yy);
       if (r.climate != CLIMATE_INVALID)
         return false;
 }
 
 
+//Place a desert
+static void do_desert (int x, int y, int size)
+{
+
+  Region    r;
+  int       xx, yy;
+
+  for (xx = -size; xx <= size; xx++) {
+    for (yy = -size; yy <= size; yy++) {
+      r = WorldRegionGet (xx + x, yy + y);
+      sprintf (r.title, "Desert");
+      r.climate = CLIMATE_DESERT;
+      r.color_atmosphere = glRgba (0.6f, 0.3f, 0.1f);
+      r.geo_detail = 8.0f;
+      r.geo_bias = 4.0f;
+      r.tree_threshold = 0.0f;
+      WorldRegionSet (x + xx, y + yy, r);
+    }
+  }
+
+}
+
+
 
 static void do_canyon (int x, int y, int radius)
 {
 
 }
 
+static bool try_lake (int try_x, int try_y, int id)
+{
 
+  Region    r;
+  int       xx, yy;
+  int       size;
+  float     depth;
+  float     water_level;
+  GLvector2 to_center;
+
+  size = 4;
+  //if (!is_free (try_x, try_y, size)) 
+    //return false;
+  //Find the lowest water level in our lake
+  water_level = 9999.9f;
+  for (xx = -size; xx <= size; xx++) {
+    for (yy = -size; yy <= size; yy++) {
+      r = WorldRegionGet (xx + try_x, yy + try_y);
+      if (r.climate != CLIMATE_INVALID && r.climate != CLIMATE_RIVER && r.climate != CLIMATE_RIVER_BANK)
+        return false;
+      if (r.moisture < 0.5f)
+        return false;
+      water_level = min (water_level, r.geo_water);
+    }
+  }
+  for (xx = -size; xx <= size; xx++) {
+    for (yy = -size; yy <= size; yy++) {
+      to_center = glVector ((float)xx, (float)yy);
+      depth = to_center.Length ();
+      if (depth > (float)size)
+        continue;
+      depth = (float)size - depth;
+      r = WorldRegionGet (xx + try_x, yy + try_y);
+      sprintf (r.title, "Lake%d", id);
+      r.geo_water = water_level;
+      r.geo_detail = 2.0f;
+      r.geo_bias = -4.0f * depth;
+      r.climate = CLIMATE_LAKE;
+      r.flags_shape |= REGION_FLAG_NOBLEND;
+      WorldRegionSet (xx + try_x, yy + try_y, r);
+    }
+  }
+  return true;
+
+}
 
 static bool try_river (int start_x, int start_y, int id)
 {
     if (r.climate == CLIMATE_OCEAN)
       rainfall = 1.0f;
     //We lose rainfall as we move inland.
-    rain_loss = 1.0f / WORLD_GRID_CENTER;
+    rain_loss = 1.5f / WORLD_GRID_CENTER;
     //We lose rainfall more slowly as it gets colder.
     if (temp < 0.5f)
       rain_loss *= temp * 2.0f;
         r.color_map = glRgba (0.2f + (float)r.mountain_height / 4.0f);
         r.color_map.Normalize ();
         break;
+      case CLIMATE_DESERT:
       case CLIMATE_COAST:
         r.color_map = glRgba (0.9f, 0.7f, 0.4f);
         break;
         r.color_map.Clamp ();
         break;
       case CLIMATE_RIVER:
+      case CLIMATE_LAKE:
         r.color_map = glRgba (0.0f, 0.0f, 0.6f);
         break;
       case CLIMATE_RIVER_BANK:
 
 }
 
+//Search around for places to put lakes
+void TerraformLakes (int count)
+{
+
+  int         lakes;
+  int         cycles;
+  int         x, y;
+  int         range;
+  GLcoord     shove;
+
+  lakes = 0;
+  cycles = 0;
+  range = WORLD_GRID_CENTER / 4;
+  while (lakes < count && cycles < 100) {
+    //Pick a random spot in the middle of the map
+    x = WORLD_GRID_CENTER + (WorldNoisei (cycles) % range) - range / 2;
+    y = WORLD_GRID_CENTER + (WorldNoisei (cycles * 2) % range) - range / 2;
+    //Now push that point away from the middle
+    shove = get_map_side (x, y);
+    shove *= range;
+    if (try_lake (x + shove.x, y + shove.y, lakes)) 
+      lakes++;
+    cycles++;
+  }
+
+}
+
 //Create zones of different climates.
 void TerraformZones ()
 {
   walk.Clear ();
   do {
     x = walk.x;
-    y = walk.y + WorldNoisei (walk.x + walk.y * WORLD_GRID) % 4;
-    radius = 1 + WorldNoisei (10 + walk.x + walk.y * WORLD_GRID) % 4;
+    y = walk.y;// + WorldNoisei (walk.x + walk.y * WORLD_GRID) % 4;
+    radius = 2 + WorldNoisei (10 + walk.x + walk.y * WORLD_GRID) % 9;
     if (is_free (x, y, radius)) {
       r = WorldRegionGet (x, y);
       climates.clear ();
       //mountains only appear in the middle
       if (abs (x - WORLD_GRID_CENTER) < 10 && radius > 1)
         climates.push_back (CLIMATE_MOUNTAIN);
+      //Deserts are HOT and DRY. Duh.
+      if (r.temperature > TEMP_HOT && r.moisture < 0.05f && radius > 1)
+        climates.push_back (CLIMATE_DESERT);
       //fields should be not too hot or cold.
       if (r.temperature > TEMP_TEMPERATE && r.temperature < TEMP_HOT && r.moisture > 0.5f && radius == 1)
         climates.push_back (CLIMATE_FIELD);
         climates.push_back (CLIMATE_CANYON);
       if (r.temperature > TEMP_TEMPERATE && r.temperature < TEMP_HOT && r.moisture > 0.5f)
         climates.push_back (CLIMATE_FOREST);
-      if (climates.empty ())
+      if (climates.empty ()) {
+        walk.Walk (WORLD_GRID);
         continue;
+      }              
       c = climates[RandomVal () % climates.size ()];
       switch (c) {
       case CLIMATE_ROCKY:
       case CLIMATE_FIELD:
         do_field (x, y, radius);
         break;
+      case CLIMATE_DESERT:
+        do_desert (x, y, radius);
+        break;
       case CLIMATE_PLAINS:
         do_plains (x, y, radius);
         break;
         do_forest (x, y, radius);
         break;
       }
-      //leave a bit of a gap before the next one
-      walk.x += radius * 3;
     }
   } while (!walk.Walk (WORLD_GRID));
 

Terrain/Terraform.h

 void    TerraformClimate ();
 void    TerraformFill ();
 void    TerraformFlora ();
+void    TerraformLakes (int count);
 void    TerraformOceans ();
 void    TerraformPrepare ();
 void    TerraformRivers (int count);

Terrain/Water.cpp

   glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	
   water.Render ();  
   glDepthMask (true);
+  return;
   glBindTexture (GL_TEXTURE_2D, WorldMap ());
   //glDisable (GL_FOG);
 

Terrain/World.cpp

   planet.wind_from_west = (RandomVal () % 2) ? true : false;
   planet.northern_hemisphere = (RandomVal () % 2) ? true : false;
   planet.river_count = 5 + RandomVal () % 4;
+  planet.lake_count = 5 + RandomVal () % 4;
   TerraformPrepare ();
   TerraformOceans ();
   TerraformCoast ();
   TerraformClimate ();
   TerraformRivers (planet.river_count);
+  TerraformLakes (planet.lake_count);
   TerraformClimate ();//Do climate a second time now that rivers are in
   TerraformZones ();
   TerraformClimate ();//Now again, since we have added climate-modifying features (Mountains, etc.)
   CLIMATE_RIVER_BANK,
   CLIMATE_SWAMP,
   CLIMATE_ROCKY,
+  CLIMATE_LAKE,
+  CLIMATE_DESERT,
   CLIMATE_FIELD,
   CLIMATE_PLAINS,
   CLIMATE_CANYON,
   bool         wind_from_west;
   bool         northern_hemisphere;
   unsigned     river_count;
+  unsigned     lake_count;
   float        noisef[NOISE_BUFFER];
   unsigned     noisei[NOISE_BUFFER];
   Region       map[WORLD_GRID][WORLD_GRID];

Terrain/glTypes.h

 
   GLcoord     operator*  (const int& c);
   GLcoord     operator*  (const GLcoord& c);
-  void        operator*= (const int& c) { x -= c; y -= c; };
-  void        operator*= (const GLcoord& c) { x -= c.x; y -= c.y; };
+  void        operator*= (const int& c) { x *= c; y *= c; };
+  void        operator*= (const GLcoord& c) { x *= c.x; y *= c.y; };
 
 };