]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Terrain.cpp
Fixed a bug loading all persons with the same ID. I hope it will fix weapon problems
[lugaru.git] / Source / Terrain.cpp
index b0aff61581df56406c7c174de27d4fa09bf620cb..34da00ea94b2fd1d3071e1f755dee31de2fc2b3c 100644 (file)
@@ -1,5 +1,6 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
@@ -20,6 +21,8 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Game.h"
 #include "Terrain.h"
 #include "Objects.h"
+#include "Utils/Folders.h"
+
 extern XYZ viewer;
 extern float viewdistance;
 extern float fadestart;
@@ -34,7 +37,6 @@ extern bool decals;
 extern float blurness;
 extern float targetblurness;
 extern Objects objects;
-extern TGAImageRec texture;
 extern bool visibleloading;
 extern bool skyboxtexture;
 extern int tutoriallevel;
@@ -197,7 +199,6 @@ void Terrain::UpdateTransparency(int whichx, int whichy)
 
 void Terrain::UpdateTransparencyother(int whichx, int whichy)
 {
-    static XYZ vertex;
     static int i, j, a, b, c, d, patch_size, stepsize;
 
     patch_size = size / subdivision;
@@ -397,22 +398,20 @@ void Terrain::UpdateVertexArray(int whichx, int whichy)
 }
 
 
-bool Terrain::load(const char *fileName)
+bool Terrain::load(const std::string& fileName)
 {
     static long i, j;
     static long x, y;
     static float patch_size;
 
     float temptexdetail = texdetail;
-    //LoadTGA( fileName );
 
-    // Fixing filename so that it works with its own os
-    char * FixedFN = ConvertFileName(fileName);
+    ImageRec texture;
 
-    unsigned char fileNamep[256];
-    CopyCStringToPascal(FixedFN, fileNamep);
     //Load Image
-    upload_image( fileNamep , 0);
+    if (!load_image(Folders::getResourcePath(fileName).c_str(), texture)) {
+        return false;
+    }
 
     //Is it valid?
     if (texture.bpp > 24) {
@@ -516,28 +515,6 @@ bool Terrain::load(const char *fileName)
     if (visibleloading)
         Game::LoadingScreen();
 
-    /*float total;
-    int todivide;
-    //Smooth opacityother
-    for(i=0;i<size;i++){
-    for(j=0;j<size;j++){
-    total=0;
-    todivide=0;
-    if(i!=0){total+=opacityother[j][i-1]; todivide++;}
-    if(i!=size-1){total+=opacityother[j][i+1]; todivide++;}
-    if(j!=0){total+=opacityother[j-1][i]; todivide++;}
-    if(j!=size-1){total+=opacityother[j+1][i]; todivide++;}
-    if(i!=0&&j!=0){total+=opacityother[j-1][i-1]; todivide++;}
-    if(i!=size-1&&j!=0){total+=opacityother[j-1][i+1]; todivide++;}
-    if(j!=size-1&&i!=size-1){total+=opacityother[j+1][i+1]; todivide++;}
-    if(j!=size-1&&i!=0){total+=opacityother[j+1][i-1]; todivide++;}
-    total+=opacityother[j][i]; todivide++;
-
-    opacityother[j][i]=total/(float)todivide;
-    }
-    }*/
-
-
     for (i = 0; i < size; i++) {
         for (j = 0; j < size; j++) {
             if (opacityother[i][j] < .1)
@@ -667,15 +644,8 @@ bool Terrain::load(const char *fileName)
     patch_size = size / subdivision;
     patch_elements = (patch_size) * (patch_size) * 54;
     CalculateNormals();
-    /*DoShadows();
-
-    for(i=0;i<subdivision;i++){
-    for(j=0;j<subdivision;j++){
-    UpdateVertexArray(i,j);
-    }
-    }*/
 
-    return 1;
+    return true;
 }
 
 void Terrain::CalculateNormals()
@@ -837,7 +807,7 @@ void Terrain::drawpatchotherother(int whichx, int whichy, float opacity)
 float Terrain::getHeight(float pointx, float pointz)
 {
     static int tilex, tiley;
-    static XYZ startpoint, endpoint, intersect, triangle[3], average;
+    static XYZ startpoint, endpoint, intersect, triangle[3];
 
     pointx /= scale;
     pointz /= scale;
@@ -882,11 +852,6 @@ float Terrain::getHeight(float pointx, float pointz)
         LineFacetd(&startpoint, &endpoint, &triangle[0], &triangle[1], &triangle[2], &intersect);
     }
     return intersect.y * scale + getOpacity(pointx * scale, pointz * scale) / 8;
-
-    //height1=heightmap[tilex][tiley]*(1-(pointx-tilex))+heightmap[tilex+1][tiley]*(pointx-tilex);
-    //height2=heightmap[tilex][tiley+1]*(1-(pointx-tilex))+heightmap[tilex+1][tiley+1]*(pointx-tilex);
-
-    //return height1*(1-(pointz-tiley))*scale+height2*(pointz-tiley)*scale;
 }
 
 float Terrain::getOpacity(float pointx, float pointz)
@@ -1237,11 +1202,6 @@ void Terrain::MakeDecal(int type, XYZ where, float size, float opacity, float ro
             patchy[2] = (where.z + size) / scale;
             patchy[3] = (where.z + size) / scale;
 
-            /*if(patchx[1]<subdivision-1&&patchy[1]<subdivision-1&&patchx[1]>0&&patchy[1]>0)
-            if(patchx[2]<subdivision-1&&patchy[2]<subdivision-1&&patchx[2]>0&&patchy[2]>0)
-            if(patchx[3]<subdivision-1&&patchy[3]<subdivision-1&&patchx[3]>0&&patchy[3]>0)
-            if(patchx[0]<subdivision-1&&patchy[0]<subdivision-1&&patchx[0]>0&&patchy[0]>0){
-            */
             if ((patchx[0] != patchx[1] || patchy[0] != patchy[1]) && (patchx[0] != patchx[2] || patchy[0] != patchy[2]) && (patchx[0] != patchx[3] || patchy[0] != patchy[3])) {
                 MakeDecalLock(type, where, patchx[0], patchy[0], size, opacity, rotation);
             }