diff --git a/CGame_Init.cpp b/CGame_Init.cpp index cedc812..353b97b 100644 --- a/CGame_Init.cpp +++ b/CGame_Init.cpp @@ -3,6 +3,7 @@ #include "CSurface.h" #include "callbacks.h" #include "globals.h" +#include "lua/GameDataLoader.h" #include #include #include @@ -81,6 +82,13 @@ bool CGame::Init() surfSplash, 0, 0, surfSplash->w - 1, 0, 0, surfSplash->h - 1, surfSplash->w - 1, surfSplash->h - 1); SDL_Flip(Surf_Display); + GameDataLoader gdLoader(global::worldDesc); + if(!gdLoader.Load()) + { + std::cerr << "Failed to load game data!" << std::endl; + return false; + } + // continue loading pictures using namespace boost::assign; std::vector paths; diff --git a/CIO/CFile.cpp b/CIO/CFile.cpp index 1ad5a5f..5dc4d59 100644 --- a/CIO/CFile.cpp +++ b/CIO/CFile.cpp @@ -534,7 +534,7 @@ bool CFile::open_gou() bobMAP* CFile::open_wld() { - bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP)); + bobMAP* myMap = new bobMAP(); if(myMap == NULL) return myMap; @@ -573,11 +573,7 @@ bobMAP* CFile::open_wld() CHECK_READ(libendian::le_read_us(&myMap->width, fp)); CHECK_READ(libendian::le_read_us(&myMap->height, fp)); - if((myMap->vertex = (MapNode*)malloc(sizeof(MapNode) * myMap->width * myMap->height)) == NULL) - { - free(myMap); - return NULL; - } + myMap->vertex.resize(myMap->width * myMap->height); // go to altitude information (we skip the 16 bytes long map data header that each block has) fseek(fp, 16, SEEK_CUR); @@ -1045,8 +1041,7 @@ bool CFile::read_bob02() } // array for start adresses of picture lines - if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL) - return false; + starts = new Uint16[bmpArray->h]; // read start adresses for(int y = 0; y < bmpArray->h; y++) @@ -1114,7 +1109,7 @@ bool CFile::read_bob02() // increment bmpArray for the next picture bmpArray++; - free(starts); + delete[] starts; return true; } @@ -1216,8 +1211,7 @@ bool CFile::read_bob04(int player_color) } // array for start adresses of picture lines - if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL) - return false; + starts = new Uint16[bmpArray->h]; // read start adresses for(int y = 0; y < bmpArray->h; y++) @@ -1289,7 +1283,7 @@ bool CFile::read_bob04(int player_color) // increment bmpArray for the next picture bmpArray++; - free(starts); + delete[] starts; return true; } @@ -1356,8 +1350,7 @@ bool CFile::read_bob07() } // array for start adresses of picture lines - if((starts = (Uint16*)malloc(shadowArray->h * sizeof(Uint16))) == NULL) - return false; + starts = new Uint16[shadowArray->h]; // read start adresses for(int y = 0; y < shadowArray->h; y++) @@ -1428,7 +1421,7 @@ bool CFile::read_bob07() // increment shadowArray shadowArray++; - free(starts); + delete[] starts; return true; } diff --git a/CMakeLists.txt b/CMakeLists.txt index d2926d6..12fe7c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,7 @@ ENDIF() add_executable(s25edit ${MAIN_SOURCES} ${CIO_SOURCES} ${icon_RC}) -target_link_libraries(s25edit SGE rttrConfig s25Common endian nowide-static ${SDL_LIBRARY}) +target_link_libraries(s25edit SGE rttrConfig s25Common gamedata endian nowide-static ${SDL_LIBRARY}) if(MINGW) target_link_libraries(s25edit -mconsole) diff --git a/CMap.cpp b/CMap.cpp index 3496c1f..0330b2e 100644 --- a/CMap.cpp +++ b/CMap.cpp @@ -118,7 +118,7 @@ void CMap::constructMap(const std::string& filename, int width, int height, int for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++) VertexCounter++; } - Vertices = (struct cursorPoint*)malloc(VertexCounter * sizeof(struct cursorPoint)); + Vertices.resize(VertexCounter); calculateVertices(); setupVerticesActivity(); mode = EDITOR_MODE_HEIGHT_RAISE; @@ -129,12 +129,10 @@ void CMap::constructMap(const std::string& filename, int width, int height, int MaxRaiseHeight = 0x3C; MinReduceHeight = 0x00; saveCurrentVertices = false; - if((CurrPtr_savedVertices = (struct savedVertices*)malloc(sizeof(struct savedVertices))) != NULL) - { - CurrPtr_savedVertices->empty = true; - CurrPtr_savedVertices->prev = NULL; - CurrPtr_savedVertices->next = NULL; - } + CurrPtr_savedVertices = new SavedVertices; + CurrPtr_savedVertices->empty = true; + CurrPtr_savedVertices->prev = NULL; + CurrPtr_savedVertices->next = NULL; // we count the players, cause the original editor writes number of players to header no matter if they are set or not int CountPlayers = 0; @@ -175,6 +173,26 @@ void CMap::constructMap(const std::string& filename, int width, int height, int HorizontalMovementLocked = false; VerticalMovementLocked = false; + + DescIdx lt(0); + for(DescIdx i(0); i.value < global::worldDesc.landscapes.size(); i.value++) + { + if(global::worldDesc.get(i).s2Id == map->type) + { + lt = i; + break; + } + } + for(DescIdx i(0); i.value < global::worldDesc.terrain.size(); i.value++) + { + const TerrainDesc& t = global::worldDesc.get(i); + if(t.landscape == lt) + { + if(map->s2IdToTerrain.size() <= t.s2Id) + map->s2IdToTerrain.resize(t.s2Id + 1); + map->s2IdToTerrain[t.s2Id] = i; + } + } } void CMap::destructMap() { @@ -192,9 +210,9 @@ void CMap::destructMap() while(CurrPtr_savedVertices->prev != NULL) { CurrPtr_savedVertices = CurrPtr_savedVertices->prev; - free(CurrPtr_savedVertices->next); + delete CurrPtr_savedVertices->next; } - free(CurrPtr_savedVertices); + delete CurrPtr_savedVertices; } // free the map surface SDL_FreeSurface(Surf_Map); @@ -203,16 +221,14 @@ void CMap::destructMap() SDL_FreeSurface(Surf_RightMenubar); Surf_RightMenubar = NULL; // free vertex array - free(Vertices); - // free vertex memory - free(map->vertex); + Vertices.clear(); // free map structure memory - free(map); + delete map; } bobMAP* CMap::generateMap(int width, int height, int type, int texture, int border, int border_texture) { - bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP)); + bobMAP* myMap = new bobMAP(); if(!myMap) return NULL; @@ -230,11 +246,7 @@ bobMAP* CMap::generateMap(int width, int height, int type, int texture, int bord myMap->HQy[i] = 0xFFFF; } - if((myMap->vertex = (MapNode*)malloc(sizeof(MapNode) * myMap->width * myMap->height)) == NULL) - { - free(myMap); - return NULL; - } + myMap->vertex.resize(myMap->width * myMap->height); for(int j = 0; j < myMap->height; j++) { @@ -275,9 +287,7 @@ bobMAP* CMap::generateMap(int width, int height, int type, int texture, int bord void CMap::rotateMap() { // we allocate memory for the new triangle field but with x equals the height and y equals the width - MapNode* new_vertex = NULL; - if((new_vertex = (MapNode*)malloc(map->height * map->width * sizeof(MapNode))) == NULL) - return; + std::vector new_vertex(map->vertex.size()); // free concatenated list for "undo" and "do" if(CurrPtr_savedVertices != NULL) @@ -291,7 +301,7 @@ void CMap::rotateMap() while(CurrPtr_savedVertices->prev != NULL) { CurrPtr_savedVertices = CurrPtr_savedVertices->prev; - free(CurrPtr_savedVertices->next); + delete CurrPtr_savedVertices->next; } CurrPtr_savedVertices->next = NULL; } @@ -306,8 +316,7 @@ void CMap::rotateMap() } // release old map and point to new - free(map->vertex); - map->vertex = new_vertex; + std::swap(map->vertex, new_vertex); // permute width and height Uint16 tmp_height = map->height; @@ -1151,7 +1160,7 @@ void CMap::render() if(modify) modifyVertex(); - if(map->vertex != NULL) + if(!map->vertex.empty()) CSurface::DrawTriangleField(Surf_Map, displayRect, map); // draw pictures to cursor position @@ -1538,13 +1547,11 @@ void CMap::modifyVertex() } if(CurrPtr_savedVertices->next == NULL) { - if((CurrPtr_savedVertices->next = (struct savedVertices*)malloc(sizeof(struct savedVertices))) != NULL) - { - CurrPtr_savedVertices->next->empty = true; - CurrPtr_savedVertices->next->prev = CurrPtr_savedVertices; - CurrPtr_savedVertices->next->next = NULL; - CurrPtr_savedVertices = CurrPtr_savedVertices->next; - } + CurrPtr_savedVertices->next = new SavedVertices; + CurrPtr_savedVertices->next->empty = true; + CurrPtr_savedVertices->next->prev = CurrPtr_savedVertices; + CurrPtr_savedVertices->next->next = NULL; + CurrPtr_savedVertices = CurrPtr_savedVertices->next; } else CurrPtr_savedVertices = CurrPtr_savedVertices->next; } diff --git a/CMap.h b/CMap.h index b3b8003..352f65d 100644 --- a/CMap.h +++ b/CMap.h @@ -32,7 +32,7 @@ class CMap bool modify; // necessary for "undo"- and "do"-function bool saveCurrentVertices; - struct savedVertices + struct SavedVertices { bool empty; int VertexX, VertexY; @@ -41,8 +41,8 @@ class CMap // this ranges up to 10 vertices //+ 2 because modifications on a vertex will touch building and shading around MapNode PointsArroundVertex[((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1)]; - struct savedVertices* prev; - struct savedVertices* next; + struct SavedVertices* prev; + struct SavedVertices* next; } * CurrPtr_savedVertices; // get the number of the triangle nearest to cursor and save it to VertexX and VertexY void saveVertex(Uint16 MouseX, Uint16 MouseY, Uint8 MouseState); @@ -67,7 +67,7 @@ class CMap // counts how many vertices we have around the cursor (and including the cursor) int VertexCounter; // array to store all vertices (editor mode) --> after constructing class CMap this will have 'VertexCounter' elements - struct cursorPoint* Vertices; + std::vector Vertices; // these are the new (internal) values for player positions (otherwise we had to walk through the objectXXXX-Blocks step by step) Uint16 PlayerHQx[MAXPLAYERS]; Uint16 PlayerHQy[MAXPLAYERS]; diff --git a/CSurface.cpp b/CSurface.cpp index e5fd696..b092a9e 100644 --- a/CSurface.cpp +++ b/CSurface.cpp @@ -5,6 +5,34 @@ #include #include +SDL_Rect rect2SDL_Rect(const Rect& rect) +{ + Point origin(rect.getOrigin()); + Point size(rect.getSize()); + SDL_Rect result{origin.x, origin.y, size.x, size.y}; + return result; +} + +void DrawPreCalcFadedTexturedTrigon(SDL_Surface* dest, Point16 p1, Point16 p2, Point16 p3, SDL_Surface* source, const SDL_Rect& rect, + Uint16 I1, Uint16 I2, Uint8 PreCalcPalettes[][256]) +{ + Sint16 right = rect.x + rect.w - 1; + Sint16 middle = rect.x + rect.w / Sint16(2); + Sint16 bottom = rect.y + rect.h - 1; + sge_PreCalcFadedTexturedTrigonColorKeys(dest, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, source, rect.x, rect.y, right, rect.y, middle, bottom, + I1, I2, I2, PreCalcPalettes, &source->format->colorkey, 1); +} + +void DrawFadedTexturedTrigon(SDL_Surface* dest, Point16 p1, Point16 p2, Point16 p3, SDL_Surface* source, const SDL_Rect& rect, Sint32 I1, + Sint32 I2) +{ + Sint16 right = rect.x + rect.w - 1; + Sint16 middle = rect.x + rect.w / Sint16(2); + Sint16 bottom = rect.y + rect.h - 1; + sge_FadedTexturedTrigonColorKeys(dest, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, source, rect.x, rect.y, right, rect.y, middle, bottom, I1, + I2, I2, &source->format->colorkey, 1); +} + bool CSurface::drawTextures = false; bool CSurface::useOpenGL = false; @@ -464,6 +492,30 @@ void CSurface::DrawTriangleField(SDL_Surface* display, const DisplayRectangle& d } } +int CalcBorders(const bobMAP& map, Uint8 s2Id1, Uint8 s2Id2, SDL_Rect& borderRect) +{ + DescIdx idxTop = map.s2IdToTerrain[s2Id1]; + DescIdx idxBottom = map.s2IdToTerrain[s2Id2]; + if(idxTop == idxBottom) + return 0; + const TerrainDesc& t1 = global::worldDesc.get(idxTop); + const TerrainDesc& t2 = global::worldDesc.get(idxBottom); + if(t1.edgePriority > t2.edgePriority) + { + if(!t1.edgeType) + return 0; + borderRect = rect2SDL_Rect(global::worldDesc.get(t1.edgeType).posInTexture); + return 1; + } else if(t1.edgePriority < t2.edgePriority) + { + if(!t2.edgeType) + return 0; + borderRect = rect2SDL_Rect(global::worldDesc.get(t2.edgeType).posInTexture); + return -1; + } + return 0; +} + void CSurface::DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap, Uint8 type, MapNode P1, MapNode P2, MapNode P3) { @@ -579,9 +631,6 @@ void CSurface::DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, // find out the texture for the triangle // upperX2, ..... are for special use in winterland. unsigned char upperX, upperY, leftX, leftY, rightX, rightY, upperX2 = 0, upperY2 = 0, leftX2 = 0, leftY2 = 0, rightX2 = 0, rightY2 = 0; - static SDL_Rect BorderRect, BorderRectSnow = {210, 176, 31, 9}, BorderRectMining = {210, 192, 31, 9}, - BorderRectSteppe = {210, 208, 31, 9}, BorderRectMeadow = {210, 224, 31, 9}, - BorderRectWater = {210, 240, 31, 9}; Uint8 texture, texture_raw; SDL_Surface* Surf_Tileset; @@ -967,293 +1016,54 @@ void CSurface::DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, /// PRIORITY FROM HIGH TO LOW: SNOW, MINING_MEADOW, STEPPE, STEPPE_MEADOW2, MINING, MEADOW, FLOWER, STEPPE_MEADOW1, SWAMP, WATER, LAVA if(global::s2->getMapObj()->getRenderBorders()) { - // we have to decide which border to blit, "left or right" or "top or bottom", therefore we are using two bool variables, the first - // is left/top, the second is right/bottom - bool Border1, Border2; + // we have to decide which border to blit, "left or right" or "top or bottom", therefore we are using an int: 0 = nothing, + // 1=left/top, -1=right/bottom + int borderSide; + SDL_Rect BorderRect; MapNode tempP; // RSU-Triangle if(P1.y < P2.y) { - // decide which border to blit (top/bottom) - therefore get the rsu-texture one line above to compare + // decide which border to blit (top/bottom) - therefore get the usd-texture from left to compare Uint16 col = (P1.VertexX - 1 < 0 ? myMap->width - 1 : P1.VertexX - 1); tempP = myMap->getVertex(col, P1.VertexY); - // only if textures are not the same or textures are both mining or meadow - if(!((tempP.usdTexture == P1.rsuTexture) - || ((tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW1 || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW3 || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - && (P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW1 || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW3 || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR)) - || ((tempP.usdTexture == TRIANGLE_TEXTURE_MINING1 || tempP.usdTexture == TRIANGLE_TEXTURE_MINING2 - || tempP.usdTexture == TRIANGLE_TEXTURE_MINING3 || tempP.usdTexture == TRIANGLE_TEXTURE_MINING4) - && (P1.rsuTexture == TRIANGLE_TEXTURE_MINING1 || P1.rsuTexture == TRIANGLE_TEXTURE_MINING2 - || P1.rsuTexture == TRIANGLE_TEXTURE_MINING3 || P1.rsuTexture == TRIANGLE_TEXTURE_MINING4)))) + borderSide = CalcBorders(*myMap, tempP.usdTexture, P1.rsuTexture, BorderRect); + if(borderSide != 0) { - Border1 = false; - Border2 = false; + Point16 thirdPt = (borderSide > 0) ? shiftedP3 : Point16(tempP.x - displayRect.x, tempP.y - displayRect.y); + Point16 tipPt = (shiftedP1 + shiftedP2 + thirdPt) / Sint16(3); + Point16 tmpP1 = (borderSide > 0) ? shiftedP1 : shiftedP1 + Point16(1, 0); + Point16 tmpP2 = (borderSide > 0) ? shiftedP2 : shiftedP2 + Point16(1, 0); - if(tempP.usdTexture == TRIANGLE_TEXTURE_WATER) - { - BorderRect = BorderRectWater; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_WATER) - { - BorderRect = BorderRectWater; - Border1 = false; - Border2 = true; - } - if(tempP.usdTexture == TRIANGLE_TEXTURE_SWAMP || tempP.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || tempP.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || tempP.usdTexture == TRIANGLE_TEXTURE_FLOWER - || tempP.usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW1 - || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW3 - || tempP.usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - { - BorderRect = BorderRectMeadow; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_SWAMP || P1.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || P1.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || P1.rsuTexture == TRIANGLE_TEXTURE_FLOWER - || P1.rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || P1.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - { - BorderRect = BorderRectMeadow; - Border1 = false; - Border2 = true; - } - if(tempP.usdTexture == TRIANGLE_TEXTURE_MINING1 || tempP.usdTexture == TRIANGLE_TEXTURE_MINING2 - || tempP.usdTexture == TRIANGLE_TEXTURE_MINING3 || tempP.usdTexture == TRIANGLE_TEXTURE_MINING4) - { - BorderRect = BorderRectMining; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_MINING1 || P1.rsuTexture == TRIANGLE_TEXTURE_MINING2 - || P1.rsuTexture == TRIANGLE_TEXTURE_MINING3 || P1.rsuTexture == TRIANGLE_TEXTURE_MINING4) - { - BorderRect = BorderRectMining; - Border1 = false; - Border2 = true; - } - if(tempP.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || tempP.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR) - { - BorderRect = BorderRectSteppe; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || P1.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR) - { - BorderRect = BorderRectSteppe; - Border1 = false; - Border2 = true; - } - if(tempP.usdTexture == TRIANGLE_TEXTURE_STEPPE) - { - BorderRect = BorderRectSteppe; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_STEPPE) - { - BorderRect = BorderRectSteppe; - Border1 = false; - Border2 = true; - } - if(tempP.usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW || tempP.usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - BorderRect = BorderRectMining; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW || P1.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - BorderRect = BorderRectMining; - Border1 = false; - Border2 = true; - } - if(tempP.usdTexture == TRIANGLE_TEXTURE_SNOW) - { - BorderRect = BorderRectSnow; - Border1 = true; - Border2 = false; - } else if(P1.rsuTexture == TRIANGLE_TEXTURE_SNOW) - { - BorderRect = BorderRectSnow; - Border1 = false; - Border2 = true; - } - - if(Border1) - { - // usd-right - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedRect(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y - 2, shiftedP1.x + 5, - shiftedP1.y + 3, shiftedP2.x + 5, shiftedP2.y + 1, Surf_Tileset, BorderRect.x, - BorderRect.y, BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, - BorderRect.y + BorderRect.h, BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, - P1.shading << 8, P2.shading << 8, gouData[type]); - else - sge_FadedTexturedRect(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y - 2, shiftedP1.x + 5, - shiftedP1.y + 3, shiftedP2.x + 5, shiftedP2.y + 1, Surf_Tileset, BorderRect.x, BorderRect.y, - BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y + BorderRect.h, - BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, P1.i, P2.i); - } else if(Border2) - { - // rsu-left - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedRect(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y + 2, shiftedP1.x - 5, - shiftedP1.y - 3, shiftedP2.x - 5, shiftedP2.y - 1, Surf_Tileset, BorderRect.x, - BorderRect.y, BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, - BorderRect.y + BorderRect.h, BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, - P1.shading << 8, P2.shading << 8, gouData[type]); - else - sge_FadedTexturedRect(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y + 2, shiftedP1.x - 5, - shiftedP1.y - 3, shiftedP2.x - 5, shiftedP2.y - 1, Surf_Tileset, BorderRect.x, BorderRect.y, - BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y + BorderRect.h, - BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, P1.i, P2.i); - } + if(global::s2->getMapObj()->getBitsPerPixel() == 8) + DrawPreCalcFadedTexturedTrigon(display, tmpP1, tmpP2, tipPt, Surf_Tileset, BorderRect, P1.shading << 8, P2.shading << 8, + gouData[type]); + else + DrawFadedTexturedTrigon(display, tmpP1, tmpP2, tipPt, Surf_Tileset, BorderRect, P1.i, P2.i); } } // USD-Triangle else { - // only if textures are not the same or textures are both mining or meadow - if(!((P2.rsuTexture == P2.usdTexture) - || ((P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1 || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW3 || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - && (P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1 || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3 || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR)) - || ((P2.rsuTexture == TRIANGLE_TEXTURE_MINING1 || P2.rsuTexture == TRIANGLE_TEXTURE_MINING2 - || P2.rsuTexture == TRIANGLE_TEXTURE_MINING3 || P2.rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (P2.usdTexture == TRIANGLE_TEXTURE_MINING1 || P2.usdTexture == TRIANGLE_TEXTURE_MINING2 - || P2.usdTexture == TRIANGLE_TEXTURE_MINING3 || P2.usdTexture == TRIANGLE_TEXTURE_MINING4)))) + borderSide = CalcBorders(*myMap, P2.rsuTexture, P2.usdTexture, BorderRect); + + if(borderSide != 0) { - Border1 = false; - Border2 = false; + Uint16 col = (P1.VertexX - 1 < 0 ? myMap->width - 1 : P1.VertexX - 1); + tempP = myMap->getVertex(col, P1.VertexY); - // decide which border to blit (left/right) - if(P2.rsuTexture == TRIANGLE_TEXTURE_WATER) - { - BorderRect = BorderRectWater; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_WATER) - { - BorderRect = BorderRectWater; - Border1 = false; - Border2 = true; - } - if(P2.rsuTexture == TRIANGLE_TEXTURE_SWAMP || P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_FLOWER - || P2.rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - { - BorderRect = BorderRectMeadow; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_SWAMP || P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_FLOWER - || P2.usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - { - BorderRect = BorderRectMeadow; - Border1 = false; - Border2 = true; - } - if(P2.rsuTexture == TRIANGLE_TEXTURE_MINING1 || P2.rsuTexture == TRIANGLE_TEXTURE_MINING2 - || P2.rsuTexture == TRIANGLE_TEXTURE_MINING3 || P2.rsuTexture == TRIANGLE_TEXTURE_MINING4) - { - BorderRect = BorderRectMining; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_MINING1 || P2.usdTexture == TRIANGLE_TEXTURE_MINING2 - || P2.usdTexture == TRIANGLE_TEXTURE_MINING3 || P2.usdTexture == TRIANGLE_TEXTURE_MINING4) - { - BorderRect = BorderRectMining; - Border1 = false; - Border2 = true; - } - if(P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR) - { - BorderRect = BorderRectSteppe; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR) - { - BorderRect = BorderRectSteppe; - Border1 = false; - Border2 = true; - } - if(P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE) - { - BorderRect = BorderRectSteppe; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_STEPPE) - { - BorderRect = BorderRectSteppe; - Border1 = false; - Border2 = true; - } - if(P2.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW || P2.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - BorderRect = BorderRectMining; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW || P2.usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - BorderRect = BorderRectMining; - Border1 = false; - Border2 = true; - } - if(P2.rsuTexture == TRIANGLE_TEXTURE_SNOW) - { - BorderRect = BorderRectSnow; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_SNOW) - { - BorderRect = BorderRectSnow; - Border1 = false; - Border2 = true; - } + Point16 thirdPt = (borderSide > 0) ? shiftedP3 : Point16(tempP.x - displayRect.x, tempP.y - displayRect.y); + Point16 tipPt = (shiftedP1 + shiftedP2 + thirdPt) / Sint16(3); - if(Border1) - { - // rsu-right - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedRect(display, shiftedP1.x, shiftedP1.y + 2, shiftedP2.x, shiftedP2.y, shiftedP1.x + 5, - shiftedP1.y - 1, shiftedP2.x + 5, shiftedP2.y - 3, Surf_Tileset, BorderRect.x, - BorderRect.y, BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, - BorderRect.y + BorderRect.h, BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, - P1.shading << 8, P2.shading << 8, gouData[type]); - else - sge_FadedTexturedRect(display, shiftedP1.x, shiftedP1.y + 2, shiftedP2.x, shiftedP2.y, shiftedP1.x + 5, - shiftedP1.y - 1, shiftedP2.x + 5, shiftedP2.y - 3, Surf_Tileset, BorderRect.x, BorderRect.y, - BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y + BorderRect.h, - BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, P1.i, P2.i); - } else if(Border2) - { - // usd-left - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedRect(display, shiftedP2.x, shiftedP2.y - 2, shiftedP1.x, shiftedP1.y, shiftedP2.x - 5, - shiftedP2.y + 1, shiftedP1.x - 5, shiftedP1.y + 3, Surf_Tileset, BorderRect.x, - BorderRect.y, BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, - BorderRect.y + BorderRect.h, BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, - P2.shading << 8, P1.shading << 8, gouData[type]); - else - sge_FadedTexturedRect(display, shiftedP2.x, shiftedP2.y - 2, shiftedP1.x, shiftedP1.y, shiftedP2.x - 5, - shiftedP2.y + 1, shiftedP1.x - 5, shiftedP1.y + 3, Surf_Tileset, BorderRect.x, BorderRect.y, - BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y + BorderRect.h, - BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, P2.i, P1.i); - } + Point16 tmpP1 = (borderSide < 0) ? shiftedP1 : shiftedP1 - Point16(1, 0); + Point16 tmpP2 = (borderSide < 0) ? shiftedP2 : shiftedP2 - Point16(1, 0); + + if(global::s2->getMapObj()->getBitsPerPixel() == 8) + DrawPreCalcFadedTexturedTrigon(display, tmpP1, tmpP2, tipPt, Surf_Tileset, BorderRect, P1.shading << 8, P2.shading << 8, + gouData[type]); + else + DrawFadedTexturedTrigon(display, tmpP1, tmpP2, tipPt, Surf_Tileset, BorderRect, P1.i, P2.i); } // decide which border to blit (top/bottom) - therefore get the rsu-texture one line above to compare @@ -1261,165 +1071,16 @@ void CSurface::DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, Uint16 col = (P2.VertexY % 2 == 0 ? P2.VertexX : (P2.VertexX + 1 > myMap->width - 1 ? 0 : P2.VertexX + 1)); tempP = myMap->getVertex(col, row); - // only if textures are not the same or textures are both mining or meadow - if(!((tempP.rsuTexture == P2.usdTexture) - || ((tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW1 || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW3 || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - && (P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1 || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3 || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR)) - || ((tempP.rsuTexture == TRIANGLE_TEXTURE_MINING1 || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING2 - || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING3 || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (P2.usdTexture == TRIANGLE_TEXTURE_MINING1 || P2.usdTexture == TRIANGLE_TEXTURE_MINING2 - || P2.usdTexture == TRIANGLE_TEXTURE_MINING3 || P2.usdTexture == TRIANGLE_TEXTURE_MINING4)))) + borderSide = CalcBorders(*myMap, tempP.rsuTexture, P2.usdTexture, BorderRect); + if(borderSide != 0) { - Border1 = false; - Border2 = false; - - if(tempP.rsuTexture == TRIANGLE_TEXTURE_WATER) - { - BorderRect = BorderRectWater; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_WATER) - { - BorderRect = BorderRectWater; - Border1 = false; - Border2 = true; - } - if(tempP.rsuTexture == TRIANGLE_TEXTURE_SWAMP || tempP.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || tempP.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || tempP.rsuTexture == TRIANGLE_TEXTURE_FLOWER - || tempP.rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || tempP.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - { - BorderRect = BorderRectMeadow; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_SWAMP || P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_FLOWER - || P2.usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3 - || P2.usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR) - { - BorderRect = BorderRectMeadow; - Border1 = false; - Border2 = true; - } - if(tempP.rsuTexture == TRIANGLE_TEXTURE_MINING1 || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING2 - || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING3 || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING4) - { - BorderRect = BorderRectMining; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_MINING1 || P2.usdTexture == TRIANGLE_TEXTURE_MINING2 - || P2.usdTexture == TRIANGLE_TEXTURE_MINING3 || P2.usdTexture == TRIANGLE_TEXTURE_MINING4) - { - BorderRect = BorderRectMining; - Border1 = false; - Border2 = true; - } - if(tempP.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || tempP.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR) - { - BorderRect = BorderRectSteppe; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || P2.usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR) - { - BorderRect = BorderRectSteppe; - Border1 = false; - Border2 = true; - } - if(tempP.rsuTexture == TRIANGLE_TEXTURE_STEPPE) - { - BorderRect = BorderRectSteppe; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_STEPPE) - { - BorderRect = BorderRectSteppe; - Border1 = false; - Border2 = true; - } - if(tempP.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW || tempP.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - BorderRect = BorderRectMining; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW || P2.usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - BorderRect = BorderRectMining; - Border1 = false; - Border2 = true; - } - if(tempP.rsuTexture == TRIANGLE_TEXTURE_SNOW) - { - BorderRect = BorderRectSnow; - Border1 = true; - Border2 = false; - } else if(P2.usdTexture == TRIANGLE_TEXTURE_SNOW) - { - BorderRect = BorderRectSnow; - Border1 = false; - Border2 = true; - } - - if(Border1) - { - // rsu-down - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedRect(display, shiftedP2.x - 2, shiftedP2.y, shiftedP3.x + 2, shiftedP3.y, shiftedP2.x - 2, - shiftedP2.y + 5, shiftedP3.x + 2, shiftedP3.y + 5, Surf_Tileset, BorderRect.x, - BorderRect.y, BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, - BorderRect.y + BorderRect.h, BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, - P2.shading << 8, P3.shading << 8, gouData[type]); - else - sge_FadedTexturedRect(display, shiftedP2.x - 2, shiftedP2.y, shiftedP3.x + 2, shiftedP3.y, shiftedP2.x - 2, - shiftedP2.y + 5, shiftedP3.x + 2, shiftedP3.y + 5, Surf_Tileset, BorderRect.x, BorderRect.y, - BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y + BorderRect.h, - BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, P2.i, P3.i); - } else if(Border2) - { - // usd-top - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedRect(display, shiftedP2.x - 2, shiftedP2.y, shiftedP3.x + 2, shiftedP3.y, shiftedP2.x - 2, - shiftedP2.y - 5, shiftedP3.x + 2, shiftedP3.y - 5, Surf_Tileset, BorderRect.x, - BorderRect.y, BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, - BorderRect.y + BorderRect.h, BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, - P2.shading << 8, P3.shading << 8, gouData[type]); - else - sge_FadedTexturedRect(display, shiftedP2.x - 2, shiftedP2.y, shiftedP3.x + 2, shiftedP3.y, shiftedP2.x - 2, - shiftedP2.y - 5, shiftedP3.x + 2, shiftedP3.y - 5, Surf_Tileset, BorderRect.x, BorderRect.y, - BorderRect.x + BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y + BorderRect.h, - BorderRect.x + BorderRect.w, BorderRect.y + BorderRect.h, P2.i, P3.i); - } - - /// all border-blit functions for copy&paste - // rsu-down - // sge_TexturedRect(display, P2.x-displayRect.x-2, P2.y-displayRect.y, P3.x-displayRect.x+2, P3.y-displayRect.y, - // P2.x-displayRect.x-2, P2.y-displayRect.y+5, P3.x-displayRect.x+2, P3.y-displayRect.y+5, Surf_Tileset, BorderRect.x, - // BorderRect.y, BorderRect.x+BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y+BorderRect.h, - // BorderRect.x+BorderRect.w, BorderRect.y+BorderRect.h); rsu-left sge_TexturedRect(display, P1.x-displayRect.x, - // P1.y-displayRect.y, P2.x-displayRect.x, P2.y-displayRect.y+2, P1.x-displayRect.x-5, P1.y-displayRect.y-3, - // P2.x-displayRect.x-5, P2.y-displayRect.y-1, Surf_Tileset, BorderRect.x, BorderRect.y, BorderRect.x+BorderRect.w, - // BorderRect.y, BorderRect.x, BorderRect.y+BorderRect.h, BorderRect.x+BorderRect.w, BorderRect.y+BorderRect.h); rsu-right - // sge_TexturedRect(display, P3.x-displayRect.x, P3.y-displayRect.y+2, P1.x-displayRect.x, P1.y-displayRect.y, - // P3.x-displayRect.x+5, P3.y-displayRect.y-1, P1.x-displayRect.x+5, P1.y-displayRect.y-3, Surf_Tileset, BorderRect.x, - // BorderRect.y, BorderRect.x+BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y+BorderRect.h, - // BorderRect.x+BorderRect.w, BorderRect.y+BorderRect.h); usd-top sge_TexturedRect(display, P2.x-displayRect.x-2, - // P2.y-displayRect.y, P3.x-displayRect.x+2, P3.y-displayRect.y, P2.x-displayRect.x-2, P2.y-displayRect.y-5, - // P3.x-displayRect.x+2, P3.y-displayRect.y-5, Surf_Tileset, BorderRect.x, BorderRect.y, BorderRect.x+BorderRect.w, - // BorderRect.y, BorderRect.x, BorderRect.y+BorderRect.h, BorderRect.x+BorderRect.w, BorderRect.y+BorderRect.h); usd-left - // sge_TexturedRect(display, P1.x-displayRect.x, P1.y-displayRect.y-2, P2.x-displayRect.x, P2.y-displayRect.y, - // P1.x-displayRect.x-5, P1.y-displayRect.y+1, P2.x-displayRect.x-5, P2.y-displayRect.y+3, Surf_Tileset, BorderRect.x, - // BorderRect.y, BorderRect.x+BorderRect.w, BorderRect.y, BorderRect.x, BorderRect.y+BorderRect.h, - // BorderRect.x+BorderRect.w, BorderRect.y+BorderRect.h); usd-right sge_TexturedRect(display, P3.x-displayRect.x, - // P3.y-displayRect.y, P1.x-displayRect.x, P1.y-displayRect.y-2, P3.x-displayRect.x+5, P3.y-displayRect.y+3, - // P1.x-displayRect.x+5, P1.y-displayRect.y+1, Surf_Tileset, BorderRect.x, BorderRect.y, BorderRect.x+BorderRect.w, - // BorderRect.y, BorderRect.x, BorderRect.y+BorderRect.h, BorderRect.x+BorderRect.w, BorderRect.y+BorderRect.h); + Point16 thirdPt = (borderSide > 0) ? shiftedP1 : Point16(tempP.x - displayRect.x, tempP.y - displayRect.y); + Point16 tipPt = (shiftedP2 + shiftedP3 + thirdPt) / Sint16(3); + if(global::s2->getMapObj()->getBitsPerPixel() == 8) + DrawPreCalcFadedTexturedTrigon(display, shiftedP2, shiftedP3, tipPt, Surf_Tileset, BorderRect, P2.shading << 8, + P3.shading << 8, gouData[type]); + else + DrawFadedTexturedTrigon(display, shiftedP2, shiftedP3, tipPt, Surf_Tileset, BorderRect, P2.i, P3.i); } } } diff --git a/defines.h b/defines.h index f6a1719..0d446fc 100644 --- a/defines.h +++ b/defines.h @@ -2,6 +2,11 @@ #define _DEFINES_H #include "commonDefines.h" +#include "Point.h" +#include "gameData/DescIdx.h" +#include + +struct TerrainDesc; // define the mode to compile (if all is uncommented, the game will compile in normal mode // in admin mode, there are some key combos to open debugger, resource viewer and so on @@ -139,11 +144,6 @@ struct DisplayRectangle Sint32 x, y; Sint32 w, h; }; -template -struct Point -{ - T x, y; -}; typedef Point Point16; typedef Point Point32; // map strutcture @@ -164,8 +164,9 @@ struct bobMAP char author[20]; // 250 items from the big map header MapHeaderItem header[250]; - MapNode* vertex; + std::vector vertex; MapNode& getVertex(unsigned x, unsigned y) { return vertex[y * width + x]; } + std::vector > s2IdToTerrain; // Initializes or updates the vertex indices and coordinates void initVertexCoords(); /// Updates x,y,z positions (e.g. after height change) diff --git a/globals.cpp b/globals.cpp index 7a89bac..32ef7fb 100644 --- a/globals.cpp +++ b/globals.cpp @@ -11,6 +11,7 @@ CGame* global::s2; std::string global::gameDataFilePath("."); std::string global::userMapsPath("./WORLDS"); +WorldDescription global::worldDesc; unsigned char TRIANGLE_HEIGHT = 28; unsigned char TRIANGLE_WIDTH = 56; diff --git a/globals.h b/globals.h index 90b9a13..272ce30 100644 --- a/globals.h +++ b/globals.h @@ -2,6 +2,7 @@ #define _GLOBALS_H #include "includes.h" +#include "gameData/WorldDescription.h" #include class CGame; @@ -19,6 +20,7 @@ extern CGame* s2; extern std::string gameDataFilePath; // Path where maps will be stored (must not be empty!) extern std::string userMapsPath; +extern WorldDescription worldDesc; } // namespace global extern unsigned char TRIANGLE_HEIGHT;