diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..53e83a7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,39 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +#sources +*.c text +*.cc text +*.cxx text +*.cpp text +*.c++ text +*.hpp text +*.h text +*.h++ text +*.hh text + +# Compiled Object files +*.slo binary +*.lo binary +*.o binary +*.obj binary + +# Precompiled Headers +*.gch binary +*.pch binary + +# Compiled Dynamic libraries +*.so binary +*.dylib binary +*.dll binary + +# Compiled Static libraries +*.lai binary +*.la binary +*.a binary +*.lib binary + +# Executables +*.exe binary +*.out binary +*.app binary diff --git a/CDebug.cpp b/CDebug.cpp index 3a6be97..0731a57 100644 --- a/CDebug.cpp +++ b/CDebug.cpp @@ -1,543 +1,543 @@ -#include "CDebug.h" -#include "CGame.h" -#include "CIO/CWindow.h" -#include "CMap.h" -#include "globals.h" - -#ifdef _ADMINMODE - -CDebug::CDebug(void dbgCallback(int), int quitParam) -{ - dbgWnd = new CWindow(dbgCallback, quitParam, 0, 0, 540, 130, "Debugger", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); - global::s2->RegisterWindow(dbgWnd); - dbgWnd->addText("Debugger started", 0, 0, fontsize); - this->dbgCallback = dbgCallback; - FrameCounterText = NULL; - FramesPerSecText = NULL; - msWaitText = NULL; - RegisteredMenusText = NULL; - RegisteredWindowsText = NULL; - RegisteredCallbacksText = NULL; - MouseText = NULL; - MapNameText = NULL; - MapSizeText = NULL; - MapAuthorText = NULL; - MapTypeText = NULL; - MapPlayerText = NULL; - VertexText = NULL; - VertexDataText = NULL; - VertexVectorText = NULL; - FlatVectorText = NULL; - rsuTextureText = NULL; - usdTextureText = NULL; - roadText = NULL; - objectTypeText = NULL; - objectInfoText = NULL; - animalText = NULL; - unknown1Text = NULL; - buildText = NULL; - unknown2Text = NULL; - unknown3Text = NULL; - resourceText = NULL; - shadingText = NULL; - unknown5Text = NULL; - editorModeText = NULL; - fontsize = 9; - MapObj = global::s2->MapObj; - map = NULL; - global::s2->RegisterCallback(dbgCallback); - - // add buttons for in-/decrementing msWait - dbgWnd->addButton(dbgCallback, DECREMENT_MSWAIT, 75, 30, 15, 15, BUTTON_GREY, "-"); - dbgWnd->addButton(dbgCallback, SETZERO_MSWAIT, 90, 30, 15, 15, BUTTON_GREY, "0"); - dbgWnd->addButton(dbgCallback, INCREMENT_MSWAIT, 105, 30, 15, 15, BUTTON_GREY, "+"); - - // we draw a vertical line to separate map data on the right side from things on the left side - dbgWnd->addText("#", 240, 10, fontsize); - dbgWnd->addText("#", 240, 20, fontsize); - dbgWnd->addText("#", 240, 30, fontsize); - dbgWnd->addText("#", 240, 40, fontsize); - dbgWnd->addText("#", 240, 50, fontsize); - dbgWnd->addText("#", 240, 60, fontsize); - dbgWnd->addText("#", 240, 70, fontsize); - dbgWnd->addText("#", 240, 80, fontsize); - dbgWnd->addText("#", 240, 90, fontsize); - dbgWnd->addText("#", 240, 100, fontsize); - dbgWnd->addText("#", 240, 110, fontsize); - dbgWnd->addText("#", 240, 120, fontsize); - dbgWnd->addText("#", 240, 130, fontsize); - dbgWnd->addText("#", 240, 140, fontsize); - dbgWnd->addText("#", 240, 150, fontsize); - dbgWnd->addText("#", 240, 160, fontsize); - dbgWnd->addText("#", 240, 170, fontsize); - dbgWnd->addText("#", 240, 180, fontsize); - dbgWnd->addText("#", 240, 190, fontsize); - dbgWnd->addText("#", 240, 200, fontsize); - dbgWnd->addText("#", 240, 210, fontsize); - dbgWnd->addText("#", 240, 220, fontsize); -} - -CDebug::~CDebug() -{ - global::s2->UnregisterCallback(dbgCallback); - dbgWnd->setWaste(); -} - -void CDebug::sendParam(int Param) -{ - switch(Param) - { - case CALL_FROM_GAMELOOP: actualizeData(); break; - - case INCREMENT_MSWAIT: global::s2->msWait++; break; - - case DECREMENT_MSWAIT: - if(global::s2->msWait > 0) - global::s2->msWait--; - break; - - case SETZERO_MSWAIT: global::s2->msWait = 0; break; - - default: break; - } -} - -void CDebug::actualizeData() -{ - // del FrameCounterText before drawing new - if(FrameCounterText != NULL) - dbgWnd->delText(FrameCounterText); - // write new FrameCounterText and draw it - sprintf(puffer1, "Actual Frame: %ld", global::s2->FrameCounter); - FrameCounterText = dbgWnd->addText(puffer1, 0, 10, fontsize); - - // Frames per Second - static float tmpFrameCtr = 0, tmpTickCtr = (float)SDL_GetTicks(); - if(tmpFrameCtr == 10) - { - // del FramesPerSecText before drawing new - if(FramesPerSecText != NULL) - dbgWnd->delText(FramesPerSecText); - // write new FramesPerSecText and draw it - sprintf(puffer1, "Frames per Sec: %.2f", tmpFrameCtr / (((float)SDL_GetTicks() - tmpTickCtr) / 1000)); - FramesPerSecText = dbgWnd->addText(puffer1, 0, 20, fontsize); - // set new values - tmpFrameCtr = 0; - tmpTickCtr = (float)SDL_GetTicks(); - } else - tmpFrameCtr++; - - // del msWaitText before drawing new - if(msWaitText != NULL) - dbgWnd->delText(msWaitText); - // write new msWaitText and draw it - sprintf(puffer1, "Wait: %dms", global::s2->msWait); - msWaitText = dbgWnd->addText(puffer1, 0, 35, fontsize); - - // del MouseText before drawing new - if(MouseText != NULL) - dbgWnd->delText(MouseText); - // write new MouseText and draw it - sprintf(puffer1, "Mouse: x=%d y=%d %s", global::s2->Cursor.x, global::s2->Cursor.y, - (global::s2->Cursor.clicked ? - (global::s2->Cursor.button.left ? "LMB clicked" : (global::s2->Cursor.button.right ? "RMB clicked" : "clicked")) : - "unclicked")); - MouseText = dbgWnd->addText(puffer1, 0, 50, fontsize); - - // del RegisteredMenusText before drawing new - if(RegisteredMenusText != NULL) - dbgWnd->delText(RegisteredMenusText); - // write new RegisteredMenusText and draw it - sprintf(puffer1, "Registered Menus: %d (max. %d)", global::s2->RegisteredMenus, MAXMENUS); - RegisteredMenusText = dbgWnd->addText(puffer1, 0, 60, fontsize); - - // del RegisteredWindowsText before drawing new - if(RegisteredWindowsText != NULL) - dbgWnd->delText(RegisteredWindowsText); - // write new RegisteredWindowsText and draw it - sprintf(puffer1, "Registered Windows: %d (max. %d)", global::s2->RegisteredWindows, MAXWINDOWS); - RegisteredWindowsText = dbgWnd->addText(puffer1, 0, 70, fontsize); - - // del RegisteredCallbacksText before drawing new - if(RegisteredCallbacksText != NULL) - dbgWnd->delText(RegisteredCallbacksText); - // write new RegisteredCallbacksText and draw it - sprintf(puffer1, "Registered Callbacks: %d (max. %d)", global::s2->RegisteredCallbacks, MAXCALLBACKS); - RegisteredCallbacksText = dbgWnd->addText(puffer1, 0, 80, fontsize); - - // we will now write the map data if a map is active - MapObj = global::s2->MapObj; - if(MapObj != NULL) - { - map = MapObj->map; - - if(MapNameText != NULL) - { - if(dbgWnd->delText(MapNameText)) - MapNameText = NULL; - } - if(MapNameText == NULL) - { - sprintf(puffer1, "Map Name: %s", map->name); - MapNameText = dbgWnd->addText(puffer1, 260, 10, fontsize); - } - if(MapSizeText != NULL) - { - if(dbgWnd->delText(MapSizeText)) - MapSizeText = NULL; - } - if(MapSizeText == NULL) - { - sprintf(puffer1, "Width: %d Height: %d", map->width, map->height); - MapSizeText = dbgWnd->addText(puffer1, 260, 20, fontsize); - } - if(MapAuthorText != NULL) - { - if(dbgWnd->delText(MapAuthorText)) - MapAuthorText = NULL; - } - if(MapAuthorText == NULL) - { - sprintf(puffer1, "Author: %s", map->author); - MapAuthorText = dbgWnd->addText(puffer1, 260, 30, fontsize); - } - if(MapTypeText != NULL) - { - if(dbgWnd->delText(MapTypeText)) - MapTypeText = NULL; - } - if(MapTypeText == NULL) - { - sprintf(puffer1, "Type: %d (%s)", map->type, - (map->type == MAP_GREENLAND ? - "Greenland" : - (map->type == MAP_WASTELAND ? "Wasteland" : (map->type == MAP_WINTERLAND ? "Winterland" : "Unknown")))); - MapTypeText = dbgWnd->addText(puffer1, 260, 40, fontsize); - } - if(MapPlayerText != NULL) - { - if(dbgWnd->delText(MapPlayerText)) - MapPlayerText = NULL; - } - if(MapPlayerText == NULL) - { - sprintf(puffer1, "Player: %d", map->player); - MapPlayerText = dbgWnd->addText(puffer1, 260, 50, fontsize); - } - if(VertexText != NULL) - { - if(dbgWnd->delText(VertexText)) - VertexText = NULL; - } - if(VertexText == NULL) - { - sprintf(puffer1, "Vertex: %d, %d", MapObj->VertexX, MapObj->VertexY); - VertexText = dbgWnd->addText(puffer1, 260, 60, fontsize); - } - if(VertexDataText != NULL) - { - if(dbgWnd->delText(VertexDataText)) - VertexDataText = NULL; - } - if(VertexDataText == NULL) - { - sprintf(puffer1, "Vertex Data: x=%d, y=%d, z=%d i=%.2f h=%#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].x, - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].y, - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].z, - ((float)map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].i) / pow(2, 16), - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].h); - VertexDataText = dbgWnd->addText(puffer1, 260, 70, fontsize); - } - if(VertexVectorText != NULL) - { - if(dbgWnd->delText(VertexVectorText)) - VertexVectorText = NULL; - } - if(VertexVectorText == NULL) - { - sprintf(puffer1, "Vertex Vector: (%.2f, %.2f, %.2f)", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].normVector.x, - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].normVector.y, - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].normVector.z); - VertexVectorText = dbgWnd->addText(puffer1, 260, 80, fontsize); - } - if(FlatVectorText != NULL) - { - if(dbgWnd->delText(FlatVectorText)) - FlatVectorText = NULL; - } - if(FlatVectorText == NULL) - { - sprintf(puffer1, "Flat Vector: (%.2f, %.2f, %.2f)", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].flatVector.x, - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].flatVector.y, - map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].flatVector.z); - FlatVectorText = dbgWnd->addText(puffer1, 260, 90, fontsize); - } - if(rsuTextureText != NULL) - { - dbgWnd->delText(rsuTextureText); - rsuTextureText = NULL; - } - if(rsuTextureText == NULL) - { - sprintf(puffer1, "RSU-Texture: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].rsuTexture); - rsuTextureText = dbgWnd->addText(puffer1, 260, 100, fontsize); - } - if(usdTextureText != NULL) - { - if(dbgWnd->delText(usdTextureText)) - usdTextureText = NULL; - } - if(usdTextureText == NULL) - { - sprintf(puffer1, "USD-Texture: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].usdTexture); - usdTextureText = dbgWnd->addText(puffer1, 260, 110, fontsize); - } - if(roadText != NULL) - { - if(dbgWnd->delText(roadText)) - roadText = NULL; - } - if(roadText == NULL) - { - sprintf(puffer1, "road: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].road); - roadText = dbgWnd->addText(puffer1, 260, 120, fontsize); - } - if(objectTypeText != NULL) - { - if(dbgWnd->delText(objectTypeText)) - objectTypeText = NULL; - } - if(objectTypeText == NULL) - { - sprintf(puffer1, "objectType: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].objectType); - objectTypeText = dbgWnd->addText(puffer1, 260, 130, fontsize); - } - if(objectInfoText != NULL) - { - if(dbgWnd->delText(objectInfoText)) - objectInfoText = NULL; - } - if(objectInfoText == NULL) - { - sprintf(puffer1, "objectInfo: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].objectInfo); - objectInfoText = dbgWnd->addText(puffer1, 260, 140, fontsize); - } - if(animalText != NULL) - { - if(dbgWnd->delText(animalText)) - animalText = NULL; - } - if(animalText == NULL) - { - sprintf(puffer1, "animal: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].animal); - animalText = dbgWnd->addText(puffer1, 260, 150, fontsize); - } - if(unknown1Text != NULL) - { - if(dbgWnd->delText(unknown1Text)) - unknown1Text = NULL; - } - if(unknown1Text == NULL) - { - sprintf(puffer1, "unknown1: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown1); - unknown1Text = dbgWnd->addText(puffer1, 260, 160, fontsize); - } - if(buildText != NULL) - { - if(dbgWnd->delText(buildText)) - buildText = NULL; - } - if(buildText == NULL) - { - sprintf(puffer1, "build: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].build); - buildText = dbgWnd->addText(puffer1, 260, 170, fontsize); - } - if(unknown2Text != NULL) - { - if(dbgWnd->delText(unknown2Text)) - unknown2Text = NULL; - } - if(unknown2Text == NULL) - { - sprintf(puffer1, "unknown2: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown2); - unknown2Text = dbgWnd->addText(puffer1, 260, 180, fontsize); - } - if(unknown3Text != NULL) - { - if(dbgWnd->delText(unknown3Text)) - unknown3Text = NULL; - } - if(unknown3Text == NULL) - { - sprintf(puffer1, "unknown3: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown3); - unknown3Text = dbgWnd->addText(puffer1, 260, 190, fontsize); - } - if(resourceText != NULL) - { - if(dbgWnd->delText(resourceText)) - resourceText = NULL; - } - if(resourceText == NULL) - { - sprintf(puffer1, "resource: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].resource); - resourceText = dbgWnd->addText(puffer1, 260, 200, fontsize); - } - if(shadingText != NULL) - { - if(dbgWnd->delText(shadingText)) - shadingText = NULL; - } - if(shadingText == NULL) - { - sprintf(puffer1, "shading: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].shading); - shadingText = dbgWnd->addText(puffer1, 260, 210, fontsize); - } - if(unknown5Text != NULL) - { - if(dbgWnd->delText(unknown5Text)) - unknown5Text = NULL; - } - if(unknown5Text == NULL) - { - sprintf(puffer1, "unknown5: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown5); - unknown5Text = dbgWnd->addText(puffer1, 260, 220, fontsize); - } - if(editorModeText != NULL) - { - if(dbgWnd->delText(editorModeText)) - editorModeText = NULL; - } - if(editorModeText == NULL) - { - sprintf(puffer1, "Editor --> Mode: %d Content: %#04x Content2: %#04x", MapObj->mode, MapObj->modeContent, MapObj->modeContent2); - editorModeText = dbgWnd->addText(puffer1, 260, 230, fontsize); - } - } else - { - // del MapNameText before drawing new - if(MapNameText != NULL) - { - if(dbgWnd->delText(MapNameText)) - MapNameText = NULL; - } - if(MapNameText == NULL) - { - // write new MapNameText and draw it - sprintf(puffer1, "No Map loaded!"); - MapNameText = dbgWnd->addText(puffer1, 260, 10, fontsize); - } - if(MapSizeText != NULL) - { - if(dbgWnd->delText(MapSizeText)) - MapSizeText = NULL; - } - if(MapAuthorText != NULL) - { - if(dbgWnd->delText(MapAuthorText)) - MapAuthorText = NULL; - } - if(MapTypeText != NULL) - { - if(dbgWnd->delText(MapTypeText)) - MapTypeText = NULL; - } - if(MapPlayerText != NULL) - { - if(dbgWnd->delText(MapPlayerText)) - MapPlayerText = NULL; - } - if(VertexText != NULL) - { - if(dbgWnd->delText(VertexText)) - VertexText = NULL; - } - if(VertexDataText != NULL) - { - if(dbgWnd->delText(VertexDataText)) - VertexDataText = NULL; - } - if(VertexVectorText != NULL) - { - if(dbgWnd->delText(VertexVectorText)) - VertexVectorText = NULL; - } - if(FlatVectorText != NULL) - { - if(dbgWnd->delText(FlatVectorText)) - FlatVectorText = NULL; - } - if(rsuTextureText != NULL) - { - if(dbgWnd->delText(rsuTextureText)) - rsuTextureText = NULL; - } - if(usdTextureText != NULL) - { - if(dbgWnd->delText(usdTextureText)) - usdTextureText = NULL; - } - if(roadText != NULL) - { - if(dbgWnd->delText(roadText)) - roadText = NULL; - } - if(objectTypeText != NULL) - { - if(dbgWnd->delText(objectTypeText)) - objectTypeText = NULL; - } - if(objectInfoText != NULL) - { - if(dbgWnd->delText(objectInfoText)) - objectInfoText = NULL; - } - if(animalText != NULL) - { - if(dbgWnd->delText(animalText)) - animalText = NULL; - } - if(unknown1Text != NULL) - { - if(dbgWnd->delText(unknown1Text)) - unknown1Text = NULL; - } - if(buildText != NULL) - { - if(dbgWnd->delText(buildText)) - buildText = NULL; - } - if(unknown2Text != NULL) - { - if(dbgWnd->delText(unknown2Text)) - unknown2Text = NULL; - } - if(unknown3Text != NULL) - { - if(dbgWnd->delText(unknown3Text)) - unknown3Text = NULL; - } - if(resourceText != NULL) - { - if(dbgWnd->delText(resourceText)) - resourceText = NULL; - } - if(shadingText != NULL) - { - if(dbgWnd->delText(shadingText)) - shadingText = NULL; - } - if(unknown5Text != NULL) - { - if(dbgWnd->delText(unknown5Text)) - unknown5Text = NULL; - } - if(editorModeText != NULL) - { - if(dbgWnd->delText(editorModeText)) - editorModeText = NULL; - } - } -} - -#endif +#include "CDebug.h" +#include "CGame.h" +#include "CIO/CWindow.h" +#include "CMap.h" +#include "globals.h" + +#ifdef _ADMINMODE + +CDebug::CDebug(void dbgCallback(int), int quitParam) +{ + dbgWnd = new CWindow(dbgCallback, quitParam, 0, 0, 540, 130, "Debugger", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); + global::s2->RegisterWindow(dbgWnd); + dbgWnd->addText("Debugger started", 0, 0, fontsize); + this->dbgCallback = dbgCallback; + FrameCounterText = NULL; + FramesPerSecText = NULL; + msWaitText = NULL; + RegisteredMenusText = NULL; + RegisteredWindowsText = NULL; + RegisteredCallbacksText = NULL; + MouseText = NULL; + MapNameText = NULL; + MapSizeText = NULL; + MapAuthorText = NULL; + MapTypeText = NULL; + MapPlayerText = NULL; + VertexText = NULL; + VertexDataText = NULL; + VertexVectorText = NULL; + FlatVectorText = NULL; + rsuTextureText = NULL; + usdTextureText = NULL; + roadText = NULL; + objectTypeText = NULL; + objectInfoText = NULL; + animalText = NULL; + unknown1Text = NULL; + buildText = NULL; + unknown2Text = NULL; + unknown3Text = NULL; + resourceText = NULL; + shadingText = NULL; + unknown5Text = NULL; + editorModeText = NULL; + fontsize = 9; + MapObj = global::s2->MapObj; + map = NULL; + global::s2->RegisterCallback(dbgCallback); + + // add buttons for in-/decrementing msWait + dbgWnd->addButton(dbgCallback, DECREMENT_MSWAIT, 75, 30, 15, 15, BUTTON_GREY, "-"); + dbgWnd->addButton(dbgCallback, SETZERO_MSWAIT, 90, 30, 15, 15, BUTTON_GREY, "0"); + dbgWnd->addButton(dbgCallback, INCREMENT_MSWAIT, 105, 30, 15, 15, BUTTON_GREY, "+"); + + // we draw a vertical line to separate map data on the right side from things on the left side + dbgWnd->addText("#", 240, 10, fontsize); + dbgWnd->addText("#", 240, 20, fontsize); + dbgWnd->addText("#", 240, 30, fontsize); + dbgWnd->addText("#", 240, 40, fontsize); + dbgWnd->addText("#", 240, 50, fontsize); + dbgWnd->addText("#", 240, 60, fontsize); + dbgWnd->addText("#", 240, 70, fontsize); + dbgWnd->addText("#", 240, 80, fontsize); + dbgWnd->addText("#", 240, 90, fontsize); + dbgWnd->addText("#", 240, 100, fontsize); + dbgWnd->addText("#", 240, 110, fontsize); + dbgWnd->addText("#", 240, 120, fontsize); + dbgWnd->addText("#", 240, 130, fontsize); + dbgWnd->addText("#", 240, 140, fontsize); + dbgWnd->addText("#", 240, 150, fontsize); + dbgWnd->addText("#", 240, 160, fontsize); + dbgWnd->addText("#", 240, 170, fontsize); + dbgWnd->addText("#", 240, 180, fontsize); + dbgWnd->addText("#", 240, 190, fontsize); + dbgWnd->addText("#", 240, 200, fontsize); + dbgWnd->addText("#", 240, 210, fontsize); + dbgWnd->addText("#", 240, 220, fontsize); +} + +CDebug::~CDebug() +{ + global::s2->UnregisterCallback(dbgCallback); + dbgWnd->setWaste(); +} + +void CDebug::sendParam(int Param) +{ + switch(Param) + { + case CALL_FROM_GAMELOOP: actualizeData(); break; + + case INCREMENT_MSWAIT: global::s2->msWait++; break; + + case DECREMENT_MSWAIT: + if(global::s2->msWait > 0) + global::s2->msWait--; + break; + + case SETZERO_MSWAIT: global::s2->msWait = 0; break; + + default: break; + } +} + +void CDebug::actualizeData() +{ + // del FrameCounterText before drawing new + if(FrameCounterText != NULL) + dbgWnd->delText(FrameCounterText); + // write new FrameCounterText and draw it + sprintf(puffer1, "Actual Frame: %ld", global::s2->FrameCounter); + FrameCounterText = dbgWnd->addText(puffer1, 0, 10, fontsize); + + // Frames per Second + static float tmpFrameCtr = 0, tmpTickCtr = (float)SDL_GetTicks(); + if(tmpFrameCtr == 10) + { + // del FramesPerSecText before drawing new + if(FramesPerSecText != NULL) + dbgWnd->delText(FramesPerSecText); + // write new FramesPerSecText and draw it + sprintf(puffer1, "Frames per Sec: %.2f", tmpFrameCtr / (((float)SDL_GetTicks() - tmpTickCtr) / 1000)); + FramesPerSecText = dbgWnd->addText(puffer1, 0, 20, fontsize); + // set new values + tmpFrameCtr = 0; + tmpTickCtr = (float)SDL_GetTicks(); + } else + tmpFrameCtr++; + + // del msWaitText before drawing new + if(msWaitText != NULL) + dbgWnd->delText(msWaitText); + // write new msWaitText and draw it + sprintf(puffer1, "Wait: %dms", global::s2->msWait); + msWaitText = dbgWnd->addText(puffer1, 0, 35, fontsize); + + // del MouseText before drawing new + if(MouseText != NULL) + dbgWnd->delText(MouseText); + // write new MouseText and draw it + sprintf(puffer1, "Mouse: x=%d y=%d %s", global::s2->Cursor.x, global::s2->Cursor.y, + (global::s2->Cursor.clicked ? + (global::s2->Cursor.button.left ? "LMB clicked" : (global::s2->Cursor.button.right ? "RMB clicked" : "clicked")) : + "unclicked")); + MouseText = dbgWnd->addText(puffer1, 0, 50, fontsize); + + // del RegisteredMenusText before drawing new + if(RegisteredMenusText != NULL) + dbgWnd->delText(RegisteredMenusText); + // write new RegisteredMenusText and draw it + sprintf(puffer1, "Registered Menus: %d (max. %d)", global::s2->RegisteredMenus, MAXMENUS); + RegisteredMenusText = dbgWnd->addText(puffer1, 0, 60, fontsize); + + // del RegisteredWindowsText before drawing new + if(RegisteredWindowsText != NULL) + dbgWnd->delText(RegisteredWindowsText); + // write new RegisteredWindowsText and draw it + sprintf(puffer1, "Registered Windows: %d (max. %d)", global::s2->RegisteredWindows, MAXWINDOWS); + RegisteredWindowsText = dbgWnd->addText(puffer1, 0, 70, fontsize); + + // del RegisteredCallbacksText before drawing new + if(RegisteredCallbacksText != NULL) + dbgWnd->delText(RegisteredCallbacksText); + // write new RegisteredCallbacksText and draw it + sprintf(puffer1, "Registered Callbacks: %d (max. %d)", global::s2->RegisteredCallbacks, MAXCALLBACKS); + RegisteredCallbacksText = dbgWnd->addText(puffer1, 0, 80, fontsize); + + // we will now write the map data if a map is active + MapObj = global::s2->MapObj; + if(MapObj != NULL) + { + map = MapObj->map; + + if(MapNameText != NULL) + { + if(dbgWnd->delText(MapNameText)) + MapNameText = NULL; + } + if(MapNameText == NULL) + { + sprintf(puffer1, "Map Name: %s", map->name); + MapNameText = dbgWnd->addText(puffer1, 260, 10, fontsize); + } + if(MapSizeText != NULL) + { + if(dbgWnd->delText(MapSizeText)) + MapSizeText = NULL; + } + if(MapSizeText == NULL) + { + sprintf(puffer1, "Width: %d Height: %d", map->width, map->height); + MapSizeText = dbgWnd->addText(puffer1, 260, 20, fontsize); + } + if(MapAuthorText != NULL) + { + if(dbgWnd->delText(MapAuthorText)) + MapAuthorText = NULL; + } + if(MapAuthorText == NULL) + { + sprintf(puffer1, "Author: %s", map->author); + MapAuthorText = dbgWnd->addText(puffer1, 260, 30, fontsize); + } + if(MapTypeText != NULL) + { + if(dbgWnd->delText(MapTypeText)) + MapTypeText = NULL; + } + if(MapTypeText == NULL) + { + sprintf(puffer1, "Type: %d (%s)", map->type, + (map->type == MAP_GREENLAND ? + "Greenland" : + (map->type == MAP_WASTELAND ? "Wasteland" : (map->type == MAP_WINTERLAND ? "Winterland" : "Unknown")))); + MapTypeText = dbgWnd->addText(puffer1, 260, 40, fontsize); + } + if(MapPlayerText != NULL) + { + if(dbgWnd->delText(MapPlayerText)) + MapPlayerText = NULL; + } + if(MapPlayerText == NULL) + { + sprintf(puffer1, "Player: %d", map->player); + MapPlayerText = dbgWnd->addText(puffer1, 260, 50, fontsize); + } + if(VertexText != NULL) + { + if(dbgWnd->delText(VertexText)) + VertexText = NULL; + } + if(VertexText == NULL) + { + sprintf(puffer1, "Vertex: %d, %d", MapObj->VertexX, MapObj->VertexY); + VertexText = dbgWnd->addText(puffer1, 260, 60, fontsize); + } + if(VertexDataText != NULL) + { + if(dbgWnd->delText(VertexDataText)) + VertexDataText = NULL; + } + if(VertexDataText == NULL) + { + sprintf(puffer1, "Vertex Data: x=%d, y=%d, z=%d i=%.2f h=%#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].x, + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].y, + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].z, + ((float)map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].i) / pow(2, 16), + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].h); + VertexDataText = dbgWnd->addText(puffer1, 260, 70, fontsize); + } + if(VertexVectorText != NULL) + { + if(dbgWnd->delText(VertexVectorText)) + VertexVectorText = NULL; + } + if(VertexVectorText == NULL) + { + sprintf(puffer1, "Vertex Vector: (%.2f, %.2f, %.2f)", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].normVector.x, + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].normVector.y, + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].normVector.z); + VertexVectorText = dbgWnd->addText(puffer1, 260, 80, fontsize); + } + if(FlatVectorText != NULL) + { + if(dbgWnd->delText(FlatVectorText)) + FlatVectorText = NULL; + } + if(FlatVectorText == NULL) + { + sprintf(puffer1, "Flat Vector: (%.2f, %.2f, %.2f)", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].flatVector.x, + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].flatVector.y, + map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].flatVector.z); + FlatVectorText = dbgWnd->addText(puffer1, 260, 90, fontsize); + } + if(rsuTextureText != NULL) + { + dbgWnd->delText(rsuTextureText); + rsuTextureText = NULL; + } + if(rsuTextureText == NULL) + { + sprintf(puffer1, "RSU-Texture: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].rsuTexture); + rsuTextureText = dbgWnd->addText(puffer1, 260, 100, fontsize); + } + if(usdTextureText != NULL) + { + if(dbgWnd->delText(usdTextureText)) + usdTextureText = NULL; + } + if(usdTextureText == NULL) + { + sprintf(puffer1, "USD-Texture: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].usdTexture); + usdTextureText = dbgWnd->addText(puffer1, 260, 110, fontsize); + } + if(roadText != NULL) + { + if(dbgWnd->delText(roadText)) + roadText = NULL; + } + if(roadText == NULL) + { + sprintf(puffer1, "road: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].road); + roadText = dbgWnd->addText(puffer1, 260, 120, fontsize); + } + if(objectTypeText != NULL) + { + if(dbgWnd->delText(objectTypeText)) + objectTypeText = NULL; + } + if(objectTypeText == NULL) + { + sprintf(puffer1, "objectType: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].objectType); + objectTypeText = dbgWnd->addText(puffer1, 260, 130, fontsize); + } + if(objectInfoText != NULL) + { + if(dbgWnd->delText(objectInfoText)) + objectInfoText = NULL; + } + if(objectInfoText == NULL) + { + sprintf(puffer1, "objectInfo: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].objectInfo); + objectInfoText = dbgWnd->addText(puffer1, 260, 140, fontsize); + } + if(animalText != NULL) + { + if(dbgWnd->delText(animalText)) + animalText = NULL; + } + if(animalText == NULL) + { + sprintf(puffer1, "animal: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].animal); + animalText = dbgWnd->addText(puffer1, 260, 150, fontsize); + } + if(unknown1Text != NULL) + { + if(dbgWnd->delText(unknown1Text)) + unknown1Text = NULL; + } + if(unknown1Text == NULL) + { + sprintf(puffer1, "unknown1: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown1); + unknown1Text = dbgWnd->addText(puffer1, 260, 160, fontsize); + } + if(buildText != NULL) + { + if(dbgWnd->delText(buildText)) + buildText = NULL; + } + if(buildText == NULL) + { + sprintf(puffer1, "build: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].build); + buildText = dbgWnd->addText(puffer1, 260, 170, fontsize); + } + if(unknown2Text != NULL) + { + if(dbgWnd->delText(unknown2Text)) + unknown2Text = NULL; + } + if(unknown2Text == NULL) + { + sprintf(puffer1, "unknown2: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown2); + unknown2Text = dbgWnd->addText(puffer1, 260, 180, fontsize); + } + if(unknown3Text != NULL) + { + if(dbgWnd->delText(unknown3Text)) + unknown3Text = NULL; + } + if(unknown3Text == NULL) + { + sprintf(puffer1, "unknown3: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown3); + unknown3Text = dbgWnd->addText(puffer1, 260, 190, fontsize); + } + if(resourceText != NULL) + { + if(dbgWnd->delText(resourceText)) + resourceText = NULL; + } + if(resourceText == NULL) + { + sprintf(puffer1, "resource: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].resource); + resourceText = dbgWnd->addText(puffer1, 260, 200, fontsize); + } + if(shadingText != NULL) + { + if(dbgWnd->delText(shadingText)) + shadingText = NULL; + } + if(shadingText == NULL) + { + sprintf(puffer1, "shading: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].shading); + shadingText = dbgWnd->addText(puffer1, 260, 210, fontsize); + } + if(unknown5Text != NULL) + { + if(dbgWnd->delText(unknown5Text)) + unknown5Text = NULL; + } + if(unknown5Text == NULL) + { + sprintf(puffer1, "unknown5: %#04x", map->vertex[MapObj->VertexY * map->width + MapObj->VertexX].unknown5); + unknown5Text = dbgWnd->addText(puffer1, 260, 220, fontsize); + } + if(editorModeText != NULL) + { + if(dbgWnd->delText(editorModeText)) + editorModeText = NULL; + } + if(editorModeText == NULL) + { + sprintf(puffer1, "Editor --> Mode: %d Content: %#04x Content2: %#04x", MapObj->mode, MapObj->modeContent, MapObj->modeContent2); + editorModeText = dbgWnd->addText(puffer1, 260, 230, fontsize); + } + } else + { + // del MapNameText before drawing new + if(MapNameText != NULL) + { + if(dbgWnd->delText(MapNameText)) + MapNameText = NULL; + } + if(MapNameText == NULL) + { + // write new MapNameText and draw it + sprintf(puffer1, "No Map loaded!"); + MapNameText = dbgWnd->addText(puffer1, 260, 10, fontsize); + } + if(MapSizeText != NULL) + { + if(dbgWnd->delText(MapSizeText)) + MapSizeText = NULL; + } + if(MapAuthorText != NULL) + { + if(dbgWnd->delText(MapAuthorText)) + MapAuthorText = NULL; + } + if(MapTypeText != NULL) + { + if(dbgWnd->delText(MapTypeText)) + MapTypeText = NULL; + } + if(MapPlayerText != NULL) + { + if(dbgWnd->delText(MapPlayerText)) + MapPlayerText = NULL; + } + if(VertexText != NULL) + { + if(dbgWnd->delText(VertexText)) + VertexText = NULL; + } + if(VertexDataText != NULL) + { + if(dbgWnd->delText(VertexDataText)) + VertexDataText = NULL; + } + if(VertexVectorText != NULL) + { + if(dbgWnd->delText(VertexVectorText)) + VertexVectorText = NULL; + } + if(FlatVectorText != NULL) + { + if(dbgWnd->delText(FlatVectorText)) + FlatVectorText = NULL; + } + if(rsuTextureText != NULL) + { + if(dbgWnd->delText(rsuTextureText)) + rsuTextureText = NULL; + } + if(usdTextureText != NULL) + { + if(dbgWnd->delText(usdTextureText)) + usdTextureText = NULL; + } + if(roadText != NULL) + { + if(dbgWnd->delText(roadText)) + roadText = NULL; + } + if(objectTypeText != NULL) + { + if(dbgWnd->delText(objectTypeText)) + objectTypeText = NULL; + } + if(objectInfoText != NULL) + { + if(dbgWnd->delText(objectInfoText)) + objectInfoText = NULL; + } + if(animalText != NULL) + { + if(dbgWnd->delText(animalText)) + animalText = NULL; + } + if(unknown1Text != NULL) + { + if(dbgWnd->delText(unknown1Text)) + unknown1Text = NULL; + } + if(buildText != NULL) + { + if(dbgWnd->delText(buildText)) + buildText = NULL; + } + if(unknown2Text != NULL) + { + if(dbgWnd->delText(unknown2Text)) + unknown2Text = NULL; + } + if(unknown3Text != NULL) + { + if(dbgWnd->delText(unknown3Text)) + unknown3Text = NULL; + } + if(resourceText != NULL) + { + if(dbgWnd->delText(resourceText)) + resourceText = NULL; + } + if(shadingText != NULL) + { + if(dbgWnd->delText(shadingText)) + shadingText = NULL; + } + if(unknown5Text != NULL) + { + if(dbgWnd->delText(unknown5Text)) + unknown5Text = NULL; + } + if(editorModeText != NULL) + { + if(dbgWnd->delText(editorModeText)) + editorModeText = NULL; + } + } +} + +#endif diff --git a/CDebug.h b/CDebug.h index 2f3f165..3c81089 100644 --- a/CDebug.h +++ b/CDebug.h @@ -1,93 +1,93 @@ -#ifndef _CDEBUG_H -#define _CDEBUG_H - -#include "includes.h" - -class CFont; -class CWindow; -class CMap; - -class CDebug -{ -private: - // callback fuction that is constructing the Debugger-Object - void (*dbgCallback)(int); - // debugger window - CWindow* dbgWnd; - // text for FrameCounter - CFont* FrameCounterText; - // text for Frames per Second - CFont* FramesPerSecText; - // text for msWait (milliseconds to wait --> SDL_Delay()) - CFont* msWaitText; - // text for Registered Menus - CFont* RegisteredMenusText; - // text for Registered Windows - CFont* RegisteredWindowsText; - // text for Registered Callbacks - CFont* RegisteredCallbacksText; - // text for mouse cursor data - CFont* MouseText; - // text for map name - CFont* MapNameText; - // text for map width and height - CFont* MapSizeText; - // text for map author - CFont* MapAuthorText; - // text for map type - CFont* MapTypeText; - // text for map players - CFont* MapPlayerText; - // text for position of cursor (position means the number of the triangle/vertex) - CFont* VertexText; - // text for data at the vertex the cursor is on - CFont* VertexDataText; - // text for vector at the vertex the cursor is on - CFont* VertexVectorText; - // text for vector at the triangle below the vertex the cursor is on - CFont* FlatVectorText; - // texts for map data at the vertex the cursor is on - CFont* rsuTextureText; - CFont* usdTextureText; - CFont* roadText; - CFont* objectTypeText; - CFont* objectInfoText; - CFont* animalText; - CFont* unknown1Text; - CFont* buildText; - CFont* unknown2Text; - CFont* unknown3Text; - CFont* resourceText; - CFont* shadingText; - CFont* unknown5Text; - CFont* editorModeText; - // some puffers to write texts with sprintf() - char puffer1[100]; - // char puffer2[100]; - // char puffer3[100]; - // fontsize for debugging window (remember: only 9, 11 or 14) - int fontsize; - // temporary pointer to Map-Object - CMap* MapObj; - // temporary pointer to map - bobMAP* map; - - // enumeration for messages sent to the debugger - enum - { - WNDQUIT = 1, // debugger window closed - INCREMENT_MSWAIT, - DECREMENT_MSWAIT, - SETZERO_MSWAIT - }; - -public: - // Constructor, Destructor - CDebug(void dbgCallback(int), int quitParam); - ~CDebug(); - // Methods - void sendParam(int Param); - void actualizeData(); -}; - -#endif +#ifndef _CDEBUG_H +#define _CDEBUG_H + +#include "includes.h" + +class CFont; +class CWindow; +class CMap; + +class CDebug +{ +private: + // callback fuction that is constructing the Debugger-Object + void (*dbgCallback)(int); + // debugger window + CWindow* dbgWnd; + // text for FrameCounter + CFont* FrameCounterText; + // text for Frames per Second + CFont* FramesPerSecText; + // text for msWait (milliseconds to wait --> SDL_Delay()) + CFont* msWaitText; + // text for Registered Menus + CFont* RegisteredMenusText; + // text for Registered Windows + CFont* RegisteredWindowsText; + // text for Registered Callbacks + CFont* RegisteredCallbacksText; + // text for mouse cursor data + CFont* MouseText; + // text for map name + CFont* MapNameText; + // text for map width and height + CFont* MapSizeText; + // text for map author + CFont* MapAuthorText; + // text for map type + CFont* MapTypeText; + // text for map players + CFont* MapPlayerText; + // text for position of cursor (position means the number of the triangle/vertex) + CFont* VertexText; + // text for data at the vertex the cursor is on + CFont* VertexDataText; + // text for vector at the vertex the cursor is on + CFont* VertexVectorText; + // text for vector at the triangle below the vertex the cursor is on + CFont* FlatVectorText; + // texts for map data at the vertex the cursor is on + CFont* rsuTextureText; + CFont* usdTextureText; + CFont* roadText; + CFont* objectTypeText; + CFont* objectInfoText; + CFont* animalText; + CFont* unknown1Text; + CFont* buildText; + CFont* unknown2Text; + CFont* unknown3Text; + CFont* resourceText; + CFont* shadingText; + CFont* unknown5Text; + CFont* editorModeText; + // some puffers to write texts with sprintf() + char puffer1[100]; + // char puffer2[100]; + // char puffer3[100]; + // fontsize for debugging window (remember: only 9, 11 or 14) + int fontsize; + // temporary pointer to Map-Object + CMap* MapObj; + // temporary pointer to map + bobMAP* map; + + // enumeration for messages sent to the debugger + enum + { + WNDQUIT = 1, // debugger window closed + INCREMENT_MSWAIT, + DECREMENT_MSWAIT, + SETZERO_MSWAIT + }; + +public: + // Constructor, Destructor + CDebug(void dbgCallback(int), int quitParam); + ~CDebug(); + // Methods + void sendParam(int Param); + void actualizeData(); +}; + +#endif diff --git a/CGame.cpp b/CGame.cpp index 1d1dad2..ee7a594 100644 --- a/CGame.cpp +++ b/CGame.cpp @@ -1,254 +1,254 @@ -#include "CGame.h" -#include "CIO/CMenu.h" -#include "CIO/CWindow.h" -#include "CMap.h" -#include "RttrConfig.h" -#include "files.h" -#include "globals.h" -#include -#include - -//#include - -CGame::CGame() -{ - GameResolutionX = 1024; - GameResolutionY = 768; - MenuResolutionX = 640; - MenuResolutionY = 480; - fullscreen = false; - -#ifdef _ADMINMODE - FrameCounter = 0; - RegisteredCallbacks = 0; - RegisteredWindows = 0; - RegisteredMenus = 0; -#endif - - msWait = 0; - - Surf_Display = NULL; - Surf_DisplayGL = NULL; - Running = true; - // mouse cursor data - Cursor.x = 0; - Cursor.y = 0; - Cursor.clicked = false; - Cursor.button.left = false; - Cursor.button.right = false; - - for(int i = 0; i < MAXMENUS; i++) - Menus[i] = NULL; - for(int i = 0; i < MAXWINDOWS; i++) - Windows[i] = NULL; - for(int i = 0; i < MAXCALLBACKS; i++) - Callbacks[i] = NULL; - MapObj = NULL; -} - -CGame::~CGame() {} - -int CGame::Execute() -{ - if(Init() == false) - return -1; - - SDL_Event Event; - - while(Running) - { - while(SDL_PollEvent(&Event)) - EventHandling(&Event); - - GameLoop(); - Render(); - } - - Cleanup(); - - return 0; -} - -bool CGame::RegisterMenu(CMenu* Menu) -{ - bool success = false; - - if(Menu == NULL) - return success; - for(int i = 0; i < MAXMENUS; i++) - { - if(!success && Menus[i] == NULL) - { - Menus[i] = Menu; - Menus[i]->setActive(); - success = true; -#ifdef _ADMINMODE - RegisteredMenus++; -#endif - } else if(Menus[i] != NULL) - Menus[i]->setInactive(); - } - return success; -} - -bool CGame::UnregisterMenu(CMenu* Menu) -{ - if(Menu == NULL) - return false; - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] == Menu) - { - for(int j = i - 1; j >= 0; j--) - { - if(Menus[j] != NULL) - { - Menus[i - 1]->setActive(); - break; - } - } - delete Menus[i]; - Menus[i] = NULL; -#ifdef _ADMINMODE - RegisteredMenus--; -#endif - return true; - } - } - return false; -} - -bool CGame::RegisterWindow(CWindow* Window) -{ - bool success = false; - int highestPriority = 0; - - // first find the highest priority - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && Windows[i]->getPriority() > highestPriority) - highestPriority = Windows[i]->getPriority(); - } - - if(Window == NULL) - return success; - for(int i = 0; i < MAXWINDOWS; i++) - { - if(!success && Windows[i] == NULL) - { - Windows[i] = Window; - Windows[i]->setActive(); - Windows[i]->setPriority(highestPriority + 1); - success = true; -#ifdef _ADMINMODE - RegisteredWindows++; -#endif - } else if(Windows[i] != NULL) - Windows[i]->setInactive(); - } - return success; -} - -bool CGame::UnregisterWindow(CWindow* Window) -{ - if(Window == NULL) - return false; - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] == Window) - { - for(int j = i - 1; j >= 0; j--) - { - if(Windows[j] != NULL) - { - Windows[j]->setActive(); - break; - } - } - delete Windows[i]; - Windows[i] = NULL; -#ifdef _ADMINMODE - RegisteredWindows--; -#endif - return true; - } - } - return false; -} - -bool CGame::RegisterCallback(void (*callback)(int)) -{ - if(callback == NULL) - return false; - for(int i = 0; i < MAXCALLBACKS; i++) - { - if(Callbacks[i] == NULL) - { - Callbacks[i] = callback; -#ifdef _ADMINMODE - RegisteredCallbacks++; -#endif - return true; - } - } - return false; -} - -bool CGame::UnregisterCallback(void (*callback)(int)) -{ - if(callback == NULL) - return false; - for(int i = 0; i < MAXCALLBACKS; i++) - { - if(Callbacks[i] == callback) - { - Callbacks[i] = NULL; -#ifdef _ADMINMODE - RegisteredCallbacks--; -#endif - return true; - } - } - return false; -} - -void CGame::delMapObj() -{ - delete MapObj; - MapObj = NULL; -} - -#undef main -int main(int argc, char* argv[]) -{ - if(!RTTRCONFIG.Init()) - { - std::cerr << "Failed to init program!" << std::endl; - return 1; - } - - global::gameDataFilePath = RTTRCONFIG.ExpandPath(""); - global::userMapsPath = RTTRCONFIG.ExpandPath(FILE_PATHS[41]); - boost::system::error_code ec; - boost::filesystem::create_directories(global::userMapsPath, ec); - if(ec) - { - std::cerr << "Could not create " << global::userMapsPath << ": " << ec << std::endl; - return 1; - } - - try - { - global::s2 = new CGame; - - global::s2->Execute(); - } catch(...) - { - std::cerr << "Unhandled Exception" << std::endl; - delete global::s2; - return 1; - } - delete global::s2; - - return 0; -} +#include "CGame.h" +#include "CIO/CMenu.h" +#include "CIO/CWindow.h" +#include "CMap.h" +#include "RttrConfig.h" +#include "files.h" +#include "globals.h" +#include +#include + +//#include + +CGame::CGame() +{ + GameResolutionX = 1024; + GameResolutionY = 768; + MenuResolutionX = 640; + MenuResolutionY = 480; + fullscreen = false; + +#ifdef _ADMINMODE + FrameCounter = 0; + RegisteredCallbacks = 0; + RegisteredWindows = 0; + RegisteredMenus = 0; +#endif + + msWait = 0; + + Surf_Display = NULL; + Surf_DisplayGL = NULL; + Running = true; + // mouse cursor data + Cursor.x = 0; + Cursor.y = 0; + Cursor.clicked = false; + Cursor.button.left = false; + Cursor.button.right = false; + + for(int i = 0; i < MAXMENUS; i++) + Menus[i] = NULL; + for(int i = 0; i < MAXWINDOWS; i++) + Windows[i] = NULL; + for(int i = 0; i < MAXCALLBACKS; i++) + Callbacks[i] = NULL; + MapObj = NULL; +} + +CGame::~CGame() {} + +int CGame::Execute() +{ + if(Init() == false) + return -1; + + SDL_Event Event; + + while(Running) + { + while(SDL_PollEvent(&Event)) + EventHandling(&Event); + + GameLoop(); + Render(); + } + + Cleanup(); + + return 0; +} + +bool CGame::RegisterMenu(CMenu* Menu) +{ + bool success = false; + + if(Menu == NULL) + return success; + for(int i = 0; i < MAXMENUS; i++) + { + if(!success && Menus[i] == NULL) + { + Menus[i] = Menu; + Menus[i]->setActive(); + success = true; +#ifdef _ADMINMODE + RegisteredMenus++; +#endif + } else if(Menus[i] != NULL) + Menus[i]->setInactive(); + } + return success; +} + +bool CGame::UnregisterMenu(CMenu* Menu) +{ + if(Menu == NULL) + return false; + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] == Menu) + { + for(int j = i - 1; j >= 0; j--) + { + if(Menus[j] != NULL) + { + Menus[i - 1]->setActive(); + break; + } + } + delete Menus[i]; + Menus[i] = NULL; +#ifdef _ADMINMODE + RegisteredMenus--; +#endif + return true; + } + } + return false; +} + +bool CGame::RegisterWindow(CWindow* Window) +{ + bool success = false; + int highestPriority = 0; + + // first find the highest priority + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && Windows[i]->getPriority() > highestPriority) + highestPriority = Windows[i]->getPriority(); + } + + if(Window == NULL) + return success; + for(int i = 0; i < MAXWINDOWS; i++) + { + if(!success && Windows[i] == NULL) + { + Windows[i] = Window; + Windows[i]->setActive(); + Windows[i]->setPriority(highestPriority + 1); + success = true; +#ifdef _ADMINMODE + RegisteredWindows++; +#endif + } else if(Windows[i] != NULL) + Windows[i]->setInactive(); + } + return success; +} + +bool CGame::UnregisterWindow(CWindow* Window) +{ + if(Window == NULL) + return false; + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] == Window) + { + for(int j = i - 1; j >= 0; j--) + { + if(Windows[j] != NULL) + { + Windows[j]->setActive(); + break; + } + } + delete Windows[i]; + Windows[i] = NULL; +#ifdef _ADMINMODE + RegisteredWindows--; +#endif + return true; + } + } + return false; +} + +bool CGame::RegisterCallback(void (*callback)(int)) +{ + if(callback == NULL) + return false; + for(int i = 0; i < MAXCALLBACKS; i++) + { + if(Callbacks[i] == NULL) + { + Callbacks[i] = callback; +#ifdef _ADMINMODE + RegisteredCallbacks++; +#endif + return true; + } + } + return false; +} + +bool CGame::UnregisterCallback(void (*callback)(int)) +{ + if(callback == NULL) + return false; + for(int i = 0; i < MAXCALLBACKS; i++) + { + if(Callbacks[i] == callback) + { + Callbacks[i] = NULL; +#ifdef _ADMINMODE + RegisteredCallbacks--; +#endif + return true; + } + } + return false; +} + +void CGame::delMapObj() +{ + delete MapObj; + MapObj = NULL; +} + +#undef main +int main(int argc, char* argv[]) +{ + if(!RTTRCONFIG.Init()) + { + std::cerr << "Failed to init program!" << std::endl; + return 1; + } + + global::gameDataFilePath = RTTRCONFIG.ExpandPath(""); + global::userMapsPath = RTTRCONFIG.ExpandPath(FILE_PATHS[41]); + boost::system::error_code ec; + boost::filesystem::create_directories(global::userMapsPath, ec); + if(ec) + { + std::cerr << "Could not create " << global::userMapsPath << ": " << ec << std::endl; + return 1; + } + + try + { + global::s2 = new CGame; + + global::s2->Execute(); + } catch(...) + { + std::cerr << "Unhandled Exception" << std::endl; + delete global::s2; + return 1; + } + delete global::s2; + + return 0; +} diff --git a/CGame.h b/CGame.h index a1e56eb..5d4e85a 100644 --- a/CGame.h +++ b/CGame.h @@ -1,90 +1,90 @@ -#ifndef _CGAME_H -#define _CGAME_H - -#include "includes.h" - -class CWindow; -class CMap; -class CMenu; - -class CGame -{ - friend class CDebug; - -public: - int GameResolutionX; - int GameResolutionY; - // MenuResolution is old and not used anymore - int MenuResolutionX; - int MenuResolutionY; - bool fullscreen; - - bool Running; - bool showLoadScreen; - SDL_Surface *Surf_Display, *Surf_DisplayGL; - -private: -#ifdef _ADMINMODE - // some debugging variables - unsigned long int FrameCounter; - int RegisteredCallbacks; - int RegisteredWindows; - int RegisteredMenus; -#endif - // milliseconds for SDL_Delay() - Uint32 msWait; - // structure for mouse cursor - struct - { - Uint16 x, y; - bool clicked; - struct - { - bool left; - bool right; - } button; - } Cursor; - - // Object for Menu Screens - CMenu* Menus[MAXMENUS]; - // Object for Windows - CWindow* Windows[MAXWINDOWS]; - // Object for Callbacks - void (*Callbacks[MAXCALLBACKS])(int); - // Object for the Map - CMap* MapObj; - - void SetAppIcon(); - -public: - CGame(); - ~CGame(); - - int Execute(); - - bool Init(); - - void EventHandling(SDL_Event* Event); - - void GameLoop(); - - void Render(); - - void Cleanup(); - - bool RegisterMenu(CMenu* Menu); - bool UnregisterMenu(CMenu* Menu); - bool RegisterWindow(CWindow* Window); - bool UnregisterWindow(CWindow* Window); - bool RegisterCallback(void (*callback)(int)); - bool UnregisterCallback(void (*callback)(int)); - void setMapObj(CMap* MapObj) { this->MapObj = MapObj; }; - CMap* getMapObj() { return MapObj; }; - void delMapObj(); - SDL_Surface* getDisplaySurface() { return Surf_Display; }; - SDL_Surface* getDisplayGLSurface() { return Surf_DisplayGL; }; - int getResX() { return GameResolutionX; } - int getResY() { return GameResolutionY; } -}; - -#endif +#ifndef _CGAME_H +#define _CGAME_H + +#include "includes.h" + +class CWindow; +class CMap; +class CMenu; + +class CGame +{ + friend class CDebug; + +public: + int GameResolutionX; + int GameResolutionY; + // MenuResolution is old and not used anymore + int MenuResolutionX; + int MenuResolutionY; + bool fullscreen; + + bool Running; + bool showLoadScreen; + SDL_Surface *Surf_Display, *Surf_DisplayGL; + +private: +#ifdef _ADMINMODE + // some debugging variables + unsigned long int FrameCounter; + int RegisteredCallbacks; + int RegisteredWindows; + int RegisteredMenus; +#endif + // milliseconds for SDL_Delay() + Uint32 msWait; + // structure for mouse cursor + struct + { + Uint16 x, y; + bool clicked; + struct + { + bool left; + bool right; + } button; + } Cursor; + + // Object for Menu Screens + CMenu* Menus[MAXMENUS]; + // Object for Windows + CWindow* Windows[MAXWINDOWS]; + // Object for Callbacks + void (*Callbacks[MAXCALLBACKS])(int); + // Object for the Map + CMap* MapObj; + + void SetAppIcon(); + +public: + CGame(); + ~CGame(); + + int Execute(); + + bool Init(); + + void EventHandling(SDL_Event* Event); + + void GameLoop(); + + void Render(); + + void Cleanup(); + + bool RegisterMenu(CMenu* Menu); + bool UnregisterMenu(CMenu* Menu); + bool RegisterWindow(CWindow* Window); + bool UnregisterWindow(CWindow* Window); + bool RegisterCallback(void (*callback)(int)); + bool UnregisterCallback(void (*callback)(int)); + void setMapObj(CMap* MapObj) { this->MapObj = MapObj; }; + CMap* getMapObj() { return MapObj; }; + void delMapObj(); + SDL_Surface* getDisplaySurface() { return Surf_Display; }; + SDL_Surface* getDisplayGLSurface() { return Surf_DisplayGL; }; + int getResX() { return GameResolutionX; } + int getResY() { return GameResolutionY; } +}; + +#endif diff --git a/CGame_Cleanup.cpp b/CGame_Cleanup.cpp index 47c3fde..cd9f788 100644 --- a/CGame_Cleanup.cpp +++ b/CGame_Cleanup.cpp @@ -1,40 +1,40 @@ -#include "CGame.h" -#include "CIO/CMenu.h" -#include "CIO/CWindow.h" -#include "CSurface.h" -#include "globals.h" - -void CGame::Cleanup() -{ - // unregister menus - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL) - CSurface::Draw(Surf_Display, Menus[i]->getSurface(), 0, 0); - } - // unregister windows - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL) - CSurface::Draw(Surf_Display, Windows[i]->getSurface(), 0, 0); - } - - // free all picture surfaces - for(int i = 0; i < MAXBOBBMP; i++) - { - if(global::bmpArray[i].surface != NULL) - SDL_FreeSurface(global::bmpArray[i].surface); - } - // free all shadow surfaces - for(int i = 0; i < MAXBOBSHADOW; i++) - { - if(global::shadowArray[i].surface != NULL) - SDL_FreeSurface(global::shadowArray[i].surface); - } - - SDL_FreeSurface(Surf_Display); - if(Surf_DisplayGL != NULL) - SDL_FreeSurface(Surf_DisplayGL); - - SDL_Quit(); -} +#include "CGame.h" +#include "CIO/CMenu.h" +#include "CIO/CWindow.h" +#include "CSurface.h" +#include "globals.h" + +void CGame::Cleanup() +{ + // unregister menus + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL) + CSurface::Draw(Surf_Display, Menus[i]->getSurface(), 0, 0); + } + // unregister windows + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL) + CSurface::Draw(Surf_Display, Windows[i]->getSurface(), 0, 0); + } + + // free all picture surfaces + for(int i = 0; i < MAXBOBBMP; i++) + { + if(global::bmpArray[i].surface != NULL) + SDL_FreeSurface(global::bmpArray[i].surface); + } + // free all shadow surfaces + for(int i = 0; i < MAXBOBSHADOW; i++) + { + if(global::shadowArray[i].surface != NULL) + SDL_FreeSurface(global::shadowArray[i].surface); + } + + SDL_FreeSurface(Surf_Display); + if(Surf_DisplayGL != NULL) + SDL_FreeSurface(Surf_DisplayGL); + + SDL_Quit(); +} diff --git a/CGame_Event.cpp b/CGame_Event.cpp index b13cf65..f2617d6 100644 --- a/CGame_Event.cpp +++ b/CGame_Event.cpp @@ -1,483 +1,483 @@ -#include "CGame.h" -#include "CIO/CMenu.h" -#include "CIO/CWindow.h" -#include "CMap.h" -#include "CSurface.h" -#include "callbacks.h" -#include "globals.h" - -void CGame::EventHandling(SDL_Event* Event) -{ - switch(Event->type) - { - case SDL_ACTIVEEVENT: - { - switch(Event->active.state) - { - case SDL_APPMOUSEFOCUS: { break; - } - case SDL_APPINPUTFOCUS: { break; - } - case SDL_APPACTIVE: { break; - } - } - break; - } - - case SDL_KEYDOWN: - { - // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop - // delivering earlier, for doing this we make use of a variable showing us the deliver status - bool delivered = false; - // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) - // we have to change the prioritys of the windows (for rendering), so find the highest one - int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) - { - if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); - } - - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->isMarked() && Windows[i]->getPriority() == highestPriority - && Windows[i]->hasActiveInputElement()) - { - Windows[i]->setKeyboardData(Event->key); - delivered = true; - break; - } - } - // if (delivered) - // break; - - // deliver keyboard data to map if active - if(!delivered) - { - if(MapObj != NULL && MapObj->isActive()) - { - MapObj->setKeyboardData(Event->key); - // data has been delivered to map, so no menu is in the foreground --> stop delivering - // break; - } - } - - // deliver keyboard data to active menus - if(!delivered) - { - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) - Menus[i]->setKeyboardData(Event->key); - } - } - - switch(Event->key.keysym.sym) - { - case SDLK_F2: - if(fullscreen) - fullscreen = false; - else - fullscreen = true; - break; - -#ifdef _ADMINMODE - case SDLK_F3: // if CTRL and ALT are pressed - // if (SDL_GetModState() == (KMOD_LCTRL | KMOD_LALT)) - callback::debugger(INITIALIZING_CALL); - break; - case SDLK_F4: // if CTRL and ALT are pressed - // if (SDL_GetModState() == (KMOD_LCTRL | KMOD_LALT)) - callback::viewer(INITIALIZING_CALL); - break; -#endif - // F5 - F7 is ZOOM, F5 = zoom in, F6 = normal view, F7 = zoom out - case SDLK_F5: - if(TRIANGLE_INCREASE < 10) - { - callback::PleaseWait(INITIALIZING_CALL); - TRIANGLE_HEIGHT += 5; - TRIANGLE_WIDTH += 11; - TRIANGLE_INCREASE += 1; - bobMAP* myMap = MapObj->getMap(); - int a; - int b = 0; - int heightFactor; - for(int j = 0; j < myMap->height; j++) - { - if(j % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int i = 0; i < myMap->width; i++) - { - heightFactor = myMap->vertex[j * myMap->width + i].h; - myMap->vertex[j * myMap->width + i].x = a; - myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); - myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } - CSurface::get_nodeVectors(myMap); - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } - break; - case SDLK_F6: - { - callback::PleaseWait(INITIALIZING_CALL); - TRIANGLE_HEIGHT = 28; - TRIANGLE_WIDTH = 56; - TRIANGLE_INCREASE = 5; - bobMAP* myMap = MapObj->getMap(); - int a; - int b = 0; - int heightFactor; - for(int j = 0; j < myMap->height; j++) - { - if(j % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int i = 0; i < myMap->width; i++) - { - heightFactor = myMap->vertex[j * myMap->width + i].h; - myMap->vertex[j * myMap->width + i].x = a; - myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); - myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } - CSurface::get_nodeVectors(myMap); - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } - break; - case SDLK_F7: - if(TRIANGLE_INCREASE > 1) - { - callback::PleaseWait(INITIALIZING_CALL); - TRIANGLE_HEIGHT -= 5; - TRIANGLE_WIDTH -= 11; - TRIANGLE_INCREASE -= 1; - bobMAP* myMap = MapObj->getMap(); - int a; - int b = 0; - int heightFactor; - for(int j = 0; j < myMap->height; j++) - { - if(j % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int i = 0; i < myMap->width; i++) - { - heightFactor = myMap->vertex[j * myMap->width + i].h; - myMap->vertex[j * myMap->width + i].x = a; - myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); - myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } - CSurface::get_nodeVectors(myMap); - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } - break; - - default: break; - } - - break; - } - - case SDL_KEYUP: - { - // deliver keyboard data to map - if(MapObj != NULL) - MapObj->setKeyboardData(Event->key); - - break; - } - - case SDL_MOUSEMOTION: - { - // setup mouse cursor data - if(MapObj != NULL && MapObj->isActive()) - { - if((Event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) == 0) - { - Cursor.x = Event->motion.x; - Cursor.y = Event->motion.y; - } - } else - { - Cursor.x = Event->motion.x; - Cursor.y = Event->motion.y; - } - /* - //NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop - // delivering earlier, for doing this we make use of a variable showing us the deliver status - int delivered = false; - //deliver mouse motion data to the active window - for (int i = 0; i < MAXWINDOWS; i++) - { - if (Windows[i] != NULL && Windows[i]->isActive() && !Windows[i]->isWaste()) - { - Windows[i]->setMouseData(Event->motion); - if ( (Event->motion.x >= Windows[i]->getX()) && (Event->motion.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->motion.y >= Windows[i]->getY()) && (Event->motion.y < Windows[i]->getY() + Windows[i]->getH()) ) delivered = true; - } - } - if (delivered) - break; - */ - - // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop - // delivering earlier, for doing this we make use of a variable showing us the deliver status - bool delivered = false; - // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) - // we have to change the prioritys of the windows (for rendering), so find the highest one - int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) - { - if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); - } - - for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) - { - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) - { - // is the cursor INSIDE the window or does the user move or resize the window? - if(((Event->motion.x >= Windows[i]->getX()) && (Event->motion.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->motion.y >= Windows[i]->getY()) && (Event->motion.y < Windows[i]->getY() + Windows[i]->getH())) - || Windows[i]->isMoving() || Windows[i]->isResizing()) - { - // Windows[i]->setActive(); - // Windows[i]->setPriority(highestPriority+1); - Windows[i]->setMouseData(Event->motion); - delivered = true; - break; - } - } - } - if(delivered) - break; - } - // if mouse data has been delivered, stop delivering anymore - if(delivered) - break; - - // deliver mouse motion data to map if active - if(MapObj != NULL && MapObj->isActive()) - { - MapObj->setMouseData(Event->motion); - // data has been delivered to map, so no menu is in the foreground --> stop delivering - break; - } - - // deliver mouse motion data to active menus - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) - { - Menus[i]->setMouseData(Event->motion); - break; - } - } - - break; - } - - case SDL_MOUSEBUTTONDOWN: - { - // setup mouse cursor data - Cursor.clicked = true; - Cursor.button.left = false; - Cursor.button.right = false; - if(Event->button.button == SDL_BUTTON_LEFT) - Cursor.button.left = true; - else if(Event->button.button == SDL_BUTTON_RIGHT) - Cursor.button.right = true; - - // clicking a mouse button will close the S2 loading screen if it is shown - if(showLoadScreen) - { - showLoadScreen = false; - // prevent pressing another object "behind" the loading screen - break; - } - - // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop - // delivering earlier, for doing this we make use of a variable showing us the deliver status - bool delivered = false; - // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) - // we have to change the prioritys of the windows (for rendering), so find the highest one - int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) - { - if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); - } - - for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) - { - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) - { - // is the cursor INSIDE the window? - if((Event->button.x >= Windows[i]->getX()) && (Event->button.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->button.y >= Windows[i]->getY()) && (Event->button.y < Windows[i]->getY() + Windows[i]->getH())) - { - Windows[i]->setActive(); - Windows[i]->setPriority(highestPriority + 1); - Windows[i]->setMouseData(Event->button); - delivered = true; - break; - } else if(Windows[i]->isActive()) - Windows[i]->setInactive(); - } - } - if(delivered) - break; - } - // if mouse data has been deliverd, stop delivering anymore - if(delivered) - break; - - // deliver mouse button data to map if active - if(MapObj != NULL && MapObj->isActive()) - { - MapObj->setMouseData(Event->button); - // data has been delivered to map, so no menu is in the foreground --> stop delivering - break; - } - - // deliver mouse button data to active menus - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) - Menus[i]->setMouseData(Event->button); - } - - switch(Event->button.button) - { - case SDL_BUTTON_LEFT: { break; - } - case SDL_BUTTON_RIGHT: { break; - } - case SDL_BUTTON_MIDDLE: { break; - } - } - break; - } - - case SDL_MOUSEBUTTONUP: - { - // setup mouse cursor data - Cursor.clicked = false; - - // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop - // delivering earlier, for doing this we make use of a variable showing us the deliver status - bool delivered = false; - // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) - // we have to change the prioritys of the windows (for rendering), so find the highest one - int highestPriority = 0; - for(int j = 0; j < MAXWINDOWS; j++) - { - if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) - highestPriority = Windows[j]->getPriority(); - } - - for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) - { - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) - { - // is the cursor INSIDE the window? - if((Event->button.x >= Windows[i]->getX()) && (Event->button.x < Windows[i]->getX() + Windows[i]->getW()) - && (Event->button.y >= Windows[i]->getY()) && (Event->button.y < Windows[i]->getY() + Windows[i]->getH())) - { - // Windows[i]->setActive(); - // Windows[i]->setPriority(highestPriority+1); - Windows[i]->setMouseData(Event->button); - delivered = true; - break; - } - // else if (Windows[i]->isActive()) - // Windows[i]->setInactive(); - } - } - if(delivered) - break; - } - // if mouse data has been deliverd, stop delivering anymore - /// We can't stop here cause of problems with the map. If user has the left mouse button pressed and modifies the vertices, - /// it will cause a problem if he walks over a window with pressed mouse button and releases it in the window. - /// So the MapObj needs the "release-event" of the mouse button. - // if (delivered) - // break; - - // if still not delivered, keep delivering to secondary elements like menu or map - - // deliver mouse button data to map if active - if(MapObj != NULL && MapObj->isActive()) - { - MapObj->setMouseData(Event->button); - // data has been delivered to map, so no menu is in the foreground --> stop delivering - break; - } - - /// now we do what we commented out a few lines before - if(delivered) - break; - - // deliver mouse button data to active menus - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) - Menus[i]->setMouseData(Event->button); - } - - switch(Event->button.button) - { - case SDL_BUTTON_LEFT: { break; - } - case SDL_BUTTON_RIGHT: { break; - } - case SDL_BUTTON_MIDDLE: { break; - } - } - break; - } - - case SDL_QUIT: - { - Running = false; - break; - } - - case SDL_SYSWMEVENT: - { - // Ignore - break; - } - - case SDL_VIDEORESIZE: { break; - } - - case SDL_VIDEOEXPOSE: { break; - } - - default: { break; - } - } -} +#include "CGame.h" +#include "CIO/CMenu.h" +#include "CIO/CWindow.h" +#include "CMap.h" +#include "CSurface.h" +#include "callbacks.h" +#include "globals.h" + +void CGame::EventHandling(SDL_Event* Event) +{ + switch(Event->type) + { + case SDL_ACTIVEEVENT: + { + switch(Event->active.state) + { + case SDL_APPMOUSEFOCUS: { break; + } + case SDL_APPINPUTFOCUS: { break; + } + case SDL_APPACTIVE: { break; + } + } + break; + } + + case SDL_KEYDOWN: + { + // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop + // delivering earlier, for doing this we make use of a variable showing us the deliver status + bool delivered = false; + // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) + // we have to change the prioritys of the windows (for rendering), so find the highest one + int highestPriority = 0; + for(int j = 0; j < MAXWINDOWS; j++) + { + if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) + highestPriority = Windows[j]->getPriority(); + } + + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->isMarked() && Windows[i]->getPriority() == highestPriority + && Windows[i]->hasActiveInputElement()) + { + Windows[i]->setKeyboardData(Event->key); + delivered = true; + break; + } + } + // if (delivered) + // break; + + // deliver keyboard data to map if active + if(!delivered) + { + if(MapObj != NULL && MapObj->isActive()) + { + MapObj->setKeyboardData(Event->key); + // data has been delivered to map, so no menu is in the foreground --> stop delivering + // break; + } + } + + // deliver keyboard data to active menus + if(!delivered) + { + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) + Menus[i]->setKeyboardData(Event->key); + } + } + + switch(Event->key.keysym.sym) + { + case SDLK_F2: + if(fullscreen) + fullscreen = false; + else + fullscreen = true; + break; + +#ifdef _ADMINMODE + case SDLK_F3: // if CTRL and ALT are pressed + // if (SDL_GetModState() == (KMOD_LCTRL | KMOD_LALT)) + callback::debugger(INITIALIZING_CALL); + break; + case SDLK_F4: // if CTRL and ALT are pressed + // if (SDL_GetModState() == (KMOD_LCTRL | KMOD_LALT)) + callback::viewer(INITIALIZING_CALL); + break; +#endif + // F5 - F7 is ZOOM, F5 = zoom in, F6 = normal view, F7 = zoom out + case SDLK_F5: + if(TRIANGLE_INCREASE < 10) + { + callback::PleaseWait(INITIALIZING_CALL); + TRIANGLE_HEIGHT += 5; + TRIANGLE_WIDTH += 11; + TRIANGLE_INCREASE += 1; + bobMAP* myMap = MapObj->getMap(); + int a; + int b = 0; + int heightFactor; + for(int j = 0; j < myMap->height; j++) + { + if(j % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int i = 0; i < myMap->width; i++) + { + heightFactor = myMap->vertex[j * myMap->width + i].h; + myMap->vertex[j * myMap->width + i].x = a; + myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); + myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } + CSurface::get_nodeVectors(myMap); + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } + break; + case SDLK_F6: + { + callback::PleaseWait(INITIALIZING_CALL); + TRIANGLE_HEIGHT = 28; + TRIANGLE_WIDTH = 56; + TRIANGLE_INCREASE = 5; + bobMAP* myMap = MapObj->getMap(); + int a; + int b = 0; + int heightFactor; + for(int j = 0; j < myMap->height; j++) + { + if(j % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int i = 0; i < myMap->width; i++) + { + heightFactor = myMap->vertex[j * myMap->width + i].h; + myMap->vertex[j * myMap->width + i].x = a; + myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); + myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } + CSurface::get_nodeVectors(myMap); + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } + break; + case SDLK_F7: + if(TRIANGLE_INCREASE > 1) + { + callback::PleaseWait(INITIALIZING_CALL); + TRIANGLE_HEIGHT -= 5; + TRIANGLE_WIDTH -= 11; + TRIANGLE_INCREASE -= 1; + bobMAP* myMap = MapObj->getMap(); + int a; + int b = 0; + int heightFactor; + for(int j = 0; j < myMap->height; j++) + { + if(j % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int i = 0; i < myMap->width; i++) + { + heightFactor = myMap->vertex[j * myMap->width + i].h; + myMap->vertex[j * myMap->width + i].x = a; + myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); + myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } + CSurface::get_nodeVectors(myMap); + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } + break; + + default: break; + } + + break; + } + + case SDL_KEYUP: + { + // deliver keyboard data to map + if(MapObj != NULL) + MapObj->setKeyboardData(Event->key); + + break; + } + + case SDL_MOUSEMOTION: + { + // setup mouse cursor data + if(MapObj != NULL && MapObj->isActive()) + { + if((Event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) == 0) + { + Cursor.x = Event->motion.x; + Cursor.y = Event->motion.y; + } + } else + { + Cursor.x = Event->motion.x; + Cursor.y = Event->motion.y; + } + /* + //NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop + // delivering earlier, for doing this we make use of a variable showing us the deliver status + int delivered = false; + //deliver mouse motion data to the active window + for (int i = 0; i < MAXWINDOWS; i++) + { + if (Windows[i] != NULL && Windows[i]->isActive() && !Windows[i]->isWaste()) + { + Windows[i]->setMouseData(Event->motion); + if ( (Event->motion.x >= Windows[i]->getX()) && (Event->motion.x < Windows[i]->getX() + Windows[i]->getW()) + && (Event->motion.y >= Windows[i]->getY()) && (Event->motion.y < Windows[i]->getY() + Windows[i]->getH()) ) delivered = true; + } + } + if (delivered) + break; + */ + + // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop + // delivering earlier, for doing this we make use of a variable showing us the deliver status + bool delivered = false; + // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) + // we have to change the prioritys of the windows (for rendering), so find the highest one + int highestPriority = 0; + for(int j = 0; j < MAXWINDOWS; j++) + { + if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) + highestPriority = Windows[j]->getPriority(); + } + + for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) + { + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) + { + // is the cursor INSIDE the window or does the user move or resize the window? + if(((Event->motion.x >= Windows[i]->getX()) && (Event->motion.x < Windows[i]->getX() + Windows[i]->getW()) + && (Event->motion.y >= Windows[i]->getY()) && (Event->motion.y < Windows[i]->getY() + Windows[i]->getH())) + || Windows[i]->isMoving() || Windows[i]->isResizing()) + { + // Windows[i]->setActive(); + // Windows[i]->setPriority(highestPriority+1); + Windows[i]->setMouseData(Event->motion); + delivered = true; + break; + } + } + } + if(delivered) + break; + } + // if mouse data has been delivered, stop delivering anymore + if(delivered) + break; + + // deliver mouse motion data to map if active + if(MapObj != NULL && MapObj->isActive()) + { + MapObj->setMouseData(Event->motion); + // data has been delivered to map, so no menu is in the foreground --> stop delivering + break; + } + + // deliver mouse motion data to active menus + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) + { + Menus[i]->setMouseData(Event->motion); + break; + } + } + + break; + } + + case SDL_MOUSEBUTTONDOWN: + { + // setup mouse cursor data + Cursor.clicked = true; + Cursor.button.left = false; + Cursor.button.right = false; + if(Event->button.button == SDL_BUTTON_LEFT) + Cursor.button.left = true; + else if(Event->button.button == SDL_BUTTON_RIGHT) + Cursor.button.right = true; + + // clicking a mouse button will close the S2 loading screen if it is shown + if(showLoadScreen) + { + showLoadScreen = false; + // prevent pressing another object "behind" the loading screen + break; + } + + // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop + // delivering earlier, for doing this we make use of a variable showing us the deliver status + bool delivered = false; + // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) + // we have to change the prioritys of the windows (for rendering), so find the highest one + int highestPriority = 0; + for(int j = 0; j < MAXWINDOWS; j++) + { + if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) + highestPriority = Windows[j]->getPriority(); + } + + for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) + { + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) + { + // is the cursor INSIDE the window? + if((Event->button.x >= Windows[i]->getX()) && (Event->button.x < Windows[i]->getX() + Windows[i]->getW()) + && (Event->button.y >= Windows[i]->getY()) && (Event->button.y < Windows[i]->getY() + Windows[i]->getH())) + { + Windows[i]->setActive(); + Windows[i]->setPriority(highestPriority + 1); + Windows[i]->setMouseData(Event->button); + delivered = true; + break; + } else if(Windows[i]->isActive()) + Windows[i]->setInactive(); + } + } + if(delivered) + break; + } + // if mouse data has been deliverd, stop delivering anymore + if(delivered) + break; + + // deliver mouse button data to map if active + if(MapObj != NULL && MapObj->isActive()) + { + MapObj->setMouseData(Event->button); + // data has been delivered to map, so no menu is in the foreground --> stop delivering + break; + } + + // deliver mouse button data to active menus + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) + Menus[i]->setMouseData(Event->button); + } + + switch(Event->button.button) + { + case SDL_BUTTON_LEFT: { break; + } + case SDL_BUTTON_RIGHT: { break; + } + case SDL_BUTTON_MIDDLE: { break; + } + } + break; + } + + case SDL_MOUSEBUTTONUP: + { + // setup mouse cursor data + Cursor.clicked = false; + + // NOTE: we will now deliver the data to menus, windows, map etc., sometimes we have to break the switch and stop + // delivering earlier, for doing this we make use of a variable showing us the deliver status + bool delivered = false; + // now we walk through the windows and find out, if cursor is on one of these (ordered by priority) + // we have to change the prioritys of the windows (for rendering), so find the highest one + int highestPriority = 0; + for(int j = 0; j < MAXWINDOWS; j++) + { + if(Windows[j] != NULL && Windows[j]->getPriority() > highestPriority) + highestPriority = Windows[j]->getPriority(); + } + + for(int actualPriority = highestPriority; actualPriority >= 0; actualPriority--) + { + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && !Windows[i]->isWaste() && Windows[i]->getPriority() == actualPriority) + { + // is the cursor INSIDE the window? + if((Event->button.x >= Windows[i]->getX()) && (Event->button.x < Windows[i]->getX() + Windows[i]->getW()) + && (Event->button.y >= Windows[i]->getY()) && (Event->button.y < Windows[i]->getY() + Windows[i]->getH())) + { + // Windows[i]->setActive(); + // Windows[i]->setPriority(highestPriority+1); + Windows[i]->setMouseData(Event->button); + delivered = true; + break; + } + // else if (Windows[i]->isActive()) + // Windows[i]->setInactive(); + } + } + if(delivered) + break; + } + // if mouse data has been deliverd, stop delivering anymore + /// We can't stop here cause of problems with the map. If user has the left mouse button pressed and modifies the vertices, + /// it will cause a problem if he walks over a window with pressed mouse button and releases it in the window. + /// So the MapObj needs the "release-event" of the mouse button. + // if (delivered) + // break; + + // if still not delivered, keep delivering to secondary elements like menu or map + + // deliver mouse button data to map if active + if(MapObj != NULL && MapObj->isActive()) + { + MapObj->setMouseData(Event->button); + // data has been delivered to map, so no menu is in the foreground --> stop delivering + break; + } + + /// now we do what we commented out a few lines before + if(delivered) + break; + + // deliver mouse button data to active menus + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL && Menus[i]->isActive() && !Menus[i]->isWaste()) + Menus[i]->setMouseData(Event->button); + } + + switch(Event->button.button) + { + case SDL_BUTTON_LEFT: { break; + } + case SDL_BUTTON_RIGHT: { break; + } + case SDL_BUTTON_MIDDLE: { break; + } + } + break; + } + + case SDL_QUIT: + { + Running = false; + break; + } + + case SDL_SYSWMEVENT: + { + // Ignore + break; + } + + case SDL_VIDEORESIZE: { break; + } + + case SDL_VIDEOEXPOSE: { break; + } + + default: { break; + } + } +} diff --git a/CGame_GameLoop.cpp b/CGame_GameLoop.cpp index 8cfdecb..7d854bd 100644 --- a/CGame_GameLoop.cpp +++ b/CGame_GameLoop.cpp @@ -1,22 +1,22 @@ -#include "CGame.h" -#include "CIO/CMenu.h" -#include "CIO/CWindow.h" - -void CGame::GameLoop() -{ - for(int i = 0; i < MAXCALLBACKS; i++) - { - if(Callbacks[i] != NULL) - Callbacks[i](CALL_FROM_GAMELOOP); - } - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL && Menus[i]->isWaste()) - UnregisterMenu(Menus[i]); - } - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && Windows[i]->isWaste()) - UnregisterWindow(Windows[i]); - } -} +#include "CGame.h" +#include "CIO/CMenu.h" +#include "CIO/CWindow.h" + +void CGame::GameLoop() +{ + for(int i = 0; i < MAXCALLBACKS; i++) + { + if(Callbacks[i] != NULL) + Callbacks[i](CALL_FROM_GAMELOOP); + } + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL && Menus[i]->isWaste()) + UnregisterMenu(Menus[i]); + } + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && Windows[i]->isWaste()) + UnregisterWindow(Windows[i]); + } +} diff --git a/CGame_Init.cpp b/CGame_Init.cpp index 641c08b..33b81cb 100644 --- a/CGame_Init.cpp +++ b/CGame_Init.cpp @@ -1,282 +1,282 @@ -#include "CGame.h" -#include "CIO/CFile.h" -#include "CSurface.h" -#include "callbacks.h" -#include "globals.h" -#include -#include -#include -#include - -bool CGame::Init() -{ - std::cout << "Return to the Roots Mapeditor\n"; - - std::cout << "\nInitializing SDL..."; - if(SDL_Init(SDL_INIT_EVERYTHING) < 0) - { - std::cout << "failure"; - return false; - } - - SDL_EnableKeyRepeat(100, 100); - SDL_ShowCursor(SDL_DISABLE); - - std::cout << "\nCreate Window..."; - if(CSurface::useOpenGL) - { - Surf_DisplayGL = SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); - Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolutionX, GameResolutionY, 32, 0, 0, 0, 0); - if(Surf_Display == NULL || Surf_DisplayGL == NULL) - { - std::cout << "failure"; - return false; - } - } else - { - Surf_Display = - SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); - if(Surf_Display == NULL) - { - std::cout << "failure"; - return false; - } - } - - SDL_WM_SetCaption("Return to the Roots Mapeditor [BETA]", 0); - SetAppIcon(); - - /*NOTE: its important to load a palette at first, - * otherwise all images will be black (in exception of the LBM-Files, they have their own palette). - * if its necessary to load pictures from a - * specified file with a special palette, so - * load this palette from a file and set - * CFile::palActual = CFile::palArray - 1 (--> last loaden palette) - * and after loading the images set - * CFile::palActual = CFile::palArray (--> first palette) - */ - - // load some pictures (after all the splash-screens) - // at first /GFX/PICS/SETUP997.LBM, cause this is the S2-loading picture - std::cout << "\nLoading file: /GFX/PICS/SETUP997.LBM..."; - if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP997.LBM", LBM)) - { - std::cout << "failure"; - // if SETUP997.LBM doesn't exist, it's probably settlers2+missioncd and there we have SETUP998.LBM instead - std::cout << "\nTry to load file: /GFX/PICS/SETUP998.LBM instead..."; - if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP998.LBM", LBM)) - { - std::cout << "failure"; - return false; - } - } - - // std::cout << "\nShow loading screen..."; - showLoadScreen = true; - // CSurface::Draw(Surf_Display, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0); - sge_TexturedRect( - Surf_Display, 0, 0, Surf_Display->w - 1, 0, 0, Surf_Display->h - 1, Surf_Display->w - 1, Surf_Display->h - 1, - global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, 0, 0, - global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, - global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1); - SDL_Flip(Surf_Display); - - // continue loading pictures - using namespace boost::assign; - std::vector paths; - paths += "/GFX/PICS/SETUP000.LBM", "/GFX/PICS/SETUP010.LBM", "/GFX/PICS/SETUP011.LBM", "/GFX/PICS/SETUP012.LBM", - "/GFX/PICS/SETUP013.LBM", "/GFX/PICS/SETUP014.LBM", "/GFX/PICS/SETUP015.LBM"; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, LBM)) - { - std::cout << "failure"; - // if it doesn't exist, it's probably settlers2+missioncd and we simply load SETUP010.LBM instead - std::cout << "\nLoading file: /GFX/PICS/SETUP010.LBM instead..."; - if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP010.LBM", LBM)) - { - std::cout << "failure"; - return false; - } - } - } - - paths.clear(); - paths += "/GFX/PICS/SETUP666.LBM", "/GFX/PICS/SETUP667.LBM", "/GFX/PICS/SETUP801.LBM", "/GFX/PICS/SETUP802.LBM", - "/GFX/PICS/SETUP803.LBM", "/GFX/PICS/SETUP804.LBM", "/GFX/PICS/SETUP805.LBM", "/GFX/PICS/SETUP806.LBM", "/GFX/PICS/SETUP810.LBM", - "/GFX/PICS/SETUP811.LBM", "/GFX/PICS/SETUP895.LBM", "/GFX/PICS/SETUP896.LBM"; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, LBM)) - { - std::cout << "failure"; - return false; - } - } - - paths.clear(); - paths += "/GFX/PICS/SETUP897.LBM", "/GFX/PICS/SETUP898.LBM"; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, LBM)) - { - std::cout << "failure"; - // if it doesn't exist, it's probably settlers2+missioncd and we simply load SETUP896.LBM instead - std::cout << "\nLoading file: /GFX/PICS/SETUP896.LBM instead..."; - if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP896.LBM", LBM)) - { - std::cout << "failure"; - return false; - } - } - } - - paths.clear(); - paths += "/GFX/PICS/SETUP899.LBM", "/GFX/PICS/SETUP990.LBM", "/GFX/PICS/WORLD.LBM", "/GFX/PICS/WORLDMSK.LBM"; - std::cout << "\nLoading file: /GFX/PICS/SETUP899.LBM..."; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, LBM)) - { - std::cout << "failure"; - return false; - } - } - - // load gouraud data - paths.clear(); - paths += "/DATA/TEXTURES/GOU5.DAT", "/DATA/TEXTURES/GOU6.DAT", "/DATA/TEXTURES/GOU7.DAT"; - std::cout << "\nLoading file: /DATA/TEXTURES/GOU5.DAT..."; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, GOU)) - { - std::cout << "failure"; - return false; - } - } - -#ifdef _EDITORMODE - // load only the palette at this time from editres.idx - std::cout << "\nLoading palette from file: /DATA/EDITRES.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/EDITRES.IDX", IDX, true)) - { - std::cout << "failure"; - return false; - } - // set the right palette - CFile::set_palActual(CFile::get_palArray() - 1); - std::cout << "\nLoading file: /DATA/EDITRES.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/EDITRES.IDX", IDX)) - { - std::cout << "failure"; - return false; - } - // set back palette - CFile::set_palActual(CFile::get_palArray()); - // load only the palette at this time from editio.idx - std::cout << "\nLoading palette from file: /DATA/IO/EDITIO.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/EDITIO.IDX", IDX, true)) - { - std::cout << "failure"; - return false; - } - // set the right palette - CFile::set_palActual(CFile::get_palArray() - 1); - std::cout << "\nLoading file: /DATA/IO/EDITIO.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/EDITIO.IDX", IDX)) - { - std::cout << "failure"; - return false; - } - // set back palette - CFile::set_palActual(CFile::get_palArray()); - std::cout << "\nLoading file: /DATA/EDITBOB.LST..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/EDITBOB.LST", LST)) - { - std::cout << "failure"; - return false; - } -#else - // load only the palette at this time from resource.idx - std::cout << "\nLoading palette from file: /DATA/RESOURCE.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/RESOURCE.IDX", IDX, true)) - { - std::cout << "failure"; - return false; - } - // set the right palette - CFile::set_palActual(CFile::get_palArray() - 1); - std::cout << "\nLoading file: /DATA/RESOURCE.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/RESOURCE.IDX", IDX)) - { - std::cout << "failure"; - return false; - } - // set back palette - CFile::set_palActual(CFile::get_palArray()); - // load only the palette at this time from io.idx - std::cout << "\nLoading palette from file: /DATA/IO/IO.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/IO.IDX", IDX, true)) - { - std::cout << "failure"; - return false; - } - // set the right palette - CFile::set_palActual(CFile::get_palArray() - 1); - std::cout << "\nLoading file: /DATA/IO/IO.IDX..."; - if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/IO.IDX", IDX)) - { - std::cout << "failure"; - return false; - } - // set back palette - CFile::set_palActual(CFile::get_palArray()); -#endif - - // texture tilesets - paths.clear(); - paths += "/GFX/TEXTURES/TEX5.LBM", "/GFX/TEXTURES/TEX6.LBM", "/GFX/TEXTURES/TEX7.LBM"; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, LBM)) - { - std::cout << "failure"; - return false; - } - } - - /* - std::cout << "\nLoading palette from file: /GFX/PALETTE/PAL5.BBM..."; - if ( !CFile::open_file(global::gameDataFilePath + "/GFX/PALETTE/PAL5.BBM", BBM, true) ) - { - std::cout << "failure"; - return false; - } - */ - - // EVERY MISSION-FILE SHOULD BE LOADED SEPARATLY IF THE SPECIFIED MISSION GOES ON -- SO THIS IS TEMPORARY - paths.clear(); - paths += "/DATA/MIS0BOBS.LST", "/DATA/MIS1BOBS.LST", "/DATA/MIS2BOBS.LST", "/DATA/MIS3BOBS.LST", "/DATA/MIS4BOBS.LST", - "/DATA/MIS5BOBS.LST"; - BOOST_FOREACH(const std::string& file, paths) - { - std::cout << "\nLoading file: " << file << "..."; - if(!CFile::open_file(global::gameDataFilePath + file, LST)) - { - std::cout << "failure"; - return false; - } - } - - // create the mainmenu - callback::mainmenu(INITIALIZING_CALL); - - return true; -} +#include "CGame.h" +#include "CIO/CFile.h" +#include "CSurface.h" +#include "callbacks.h" +#include "globals.h" +#include +#include +#include +#include + +bool CGame::Init() +{ + std::cout << "Return to the Roots Mapeditor\n"; + + std::cout << "\nInitializing SDL..."; + if(SDL_Init(SDL_INIT_EVERYTHING) < 0) + { + std::cout << "failure"; + return false; + } + + SDL_EnableKeyRepeat(100, 100); + SDL_ShowCursor(SDL_DISABLE); + + std::cout << "\nCreate Window..."; + if(CSurface::useOpenGL) + { + Surf_DisplayGL = SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); + Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolutionX, GameResolutionY, 32, 0, 0, 0, 0); + if(Surf_Display == NULL || Surf_DisplayGL == NULL) + { + std::cout << "failure"; + return false; + } + } else + { + Surf_Display = + SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); + if(Surf_Display == NULL) + { + std::cout << "failure"; + return false; + } + } + + SDL_WM_SetCaption("Return to the Roots Mapeditor [BETA]", 0); + SetAppIcon(); + + /*NOTE: its important to load a palette at first, + * otherwise all images will be black (in exception of the LBM-Files, they have their own palette). + * if its necessary to load pictures from a + * specified file with a special palette, so + * load this palette from a file and set + * CFile::palActual = CFile::palArray - 1 (--> last loaden palette) + * and after loading the images set + * CFile::palActual = CFile::palArray (--> first palette) + */ + + // load some pictures (after all the splash-screens) + // at first /GFX/PICS/SETUP997.LBM, cause this is the S2-loading picture + std::cout << "\nLoading file: /GFX/PICS/SETUP997.LBM..."; + if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP997.LBM", LBM)) + { + std::cout << "failure"; + // if SETUP997.LBM doesn't exist, it's probably settlers2+missioncd and there we have SETUP998.LBM instead + std::cout << "\nTry to load file: /GFX/PICS/SETUP998.LBM instead..."; + if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP998.LBM", LBM)) + { + std::cout << "failure"; + return false; + } + } + + // std::cout << "\nShow loading screen..."; + showLoadScreen = true; + // CSurface::Draw(Surf_Display, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0); + sge_TexturedRect( + Surf_Display, 0, 0, Surf_Display->w - 1, 0, 0, Surf_Display->h - 1, Surf_Display->w - 1, Surf_Display->h - 1, + global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, 0, 0, + global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, + global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1); + SDL_Flip(Surf_Display); + + // continue loading pictures + using namespace boost::assign; + std::vector paths; + paths += "/GFX/PICS/SETUP000.LBM", "/GFX/PICS/SETUP010.LBM", "/GFX/PICS/SETUP011.LBM", "/GFX/PICS/SETUP012.LBM", + "/GFX/PICS/SETUP013.LBM", "/GFX/PICS/SETUP014.LBM", "/GFX/PICS/SETUP015.LBM"; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, LBM)) + { + std::cout << "failure"; + // if it doesn't exist, it's probably settlers2+missioncd and we simply load SETUP010.LBM instead + std::cout << "\nLoading file: /GFX/PICS/SETUP010.LBM instead..."; + if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP010.LBM", LBM)) + { + std::cout << "failure"; + return false; + } + } + } + + paths.clear(); + paths += "/GFX/PICS/SETUP666.LBM", "/GFX/PICS/SETUP667.LBM", "/GFX/PICS/SETUP801.LBM", "/GFX/PICS/SETUP802.LBM", + "/GFX/PICS/SETUP803.LBM", "/GFX/PICS/SETUP804.LBM", "/GFX/PICS/SETUP805.LBM", "/GFX/PICS/SETUP806.LBM", "/GFX/PICS/SETUP810.LBM", + "/GFX/PICS/SETUP811.LBM", "/GFX/PICS/SETUP895.LBM", "/GFX/PICS/SETUP896.LBM"; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, LBM)) + { + std::cout << "failure"; + return false; + } + } + + paths.clear(); + paths += "/GFX/PICS/SETUP897.LBM", "/GFX/PICS/SETUP898.LBM"; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, LBM)) + { + std::cout << "failure"; + // if it doesn't exist, it's probably settlers2+missioncd and we simply load SETUP896.LBM instead + std::cout << "\nLoading file: /GFX/PICS/SETUP896.LBM instead..."; + if(!CFile::open_file(global::gameDataFilePath + "/GFX/PICS/SETUP896.LBM", LBM)) + { + std::cout << "failure"; + return false; + } + } + } + + paths.clear(); + paths += "/GFX/PICS/SETUP899.LBM", "/GFX/PICS/SETUP990.LBM", "/GFX/PICS/WORLD.LBM", "/GFX/PICS/WORLDMSK.LBM"; + std::cout << "\nLoading file: /GFX/PICS/SETUP899.LBM..."; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, LBM)) + { + std::cout << "failure"; + return false; + } + } + + // load gouraud data + paths.clear(); + paths += "/DATA/TEXTURES/GOU5.DAT", "/DATA/TEXTURES/GOU6.DAT", "/DATA/TEXTURES/GOU7.DAT"; + std::cout << "\nLoading file: /DATA/TEXTURES/GOU5.DAT..."; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, GOU)) + { + std::cout << "failure"; + return false; + } + } + +#ifdef _EDITORMODE + // load only the palette at this time from editres.idx + std::cout << "\nLoading palette from file: /DATA/EDITRES.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/EDITRES.IDX", IDX, true)) + { + std::cout << "failure"; + return false; + } + // set the right palette + CFile::set_palActual(CFile::get_palArray() - 1); + std::cout << "\nLoading file: /DATA/EDITRES.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/EDITRES.IDX", IDX)) + { + std::cout << "failure"; + return false; + } + // set back palette + CFile::set_palActual(CFile::get_palArray()); + // load only the palette at this time from editio.idx + std::cout << "\nLoading palette from file: /DATA/IO/EDITIO.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/EDITIO.IDX", IDX, true)) + { + std::cout << "failure"; + return false; + } + // set the right palette + CFile::set_palActual(CFile::get_palArray() - 1); + std::cout << "\nLoading file: /DATA/IO/EDITIO.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/EDITIO.IDX", IDX)) + { + std::cout << "failure"; + return false; + } + // set back palette + CFile::set_palActual(CFile::get_palArray()); + std::cout << "\nLoading file: /DATA/EDITBOB.LST..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/EDITBOB.LST", LST)) + { + std::cout << "failure"; + return false; + } +#else + // load only the palette at this time from resource.idx + std::cout << "\nLoading palette from file: /DATA/RESOURCE.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/RESOURCE.IDX", IDX, true)) + { + std::cout << "failure"; + return false; + } + // set the right palette + CFile::set_palActual(CFile::get_palArray() - 1); + std::cout << "\nLoading file: /DATA/RESOURCE.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/RESOURCE.IDX", IDX)) + { + std::cout << "failure"; + return false; + } + // set back palette + CFile::set_palActual(CFile::get_palArray()); + // load only the palette at this time from io.idx + std::cout << "\nLoading palette from file: /DATA/IO/IO.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/IO.IDX", IDX, true)) + { + std::cout << "failure"; + return false; + } + // set the right palette + CFile::set_palActual(CFile::get_palArray() - 1); + std::cout << "\nLoading file: /DATA/IO/IO.IDX..."; + if(!CFile::open_file(global::gameDataFilePath + "/DATA/IO/IO.IDX", IDX)) + { + std::cout << "failure"; + return false; + } + // set back palette + CFile::set_palActual(CFile::get_palArray()); +#endif + + // texture tilesets + paths.clear(); + paths += "/GFX/TEXTURES/TEX5.LBM", "/GFX/TEXTURES/TEX6.LBM", "/GFX/TEXTURES/TEX7.LBM"; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, LBM)) + { + std::cout << "failure"; + return false; + } + } + + /* + std::cout << "\nLoading palette from file: /GFX/PALETTE/PAL5.BBM..."; + if ( !CFile::open_file(global::gameDataFilePath + "/GFX/PALETTE/PAL5.BBM", BBM, true) ) + { + std::cout << "failure"; + return false; + } + */ + + // EVERY MISSION-FILE SHOULD BE LOADED SEPARATLY IF THE SPECIFIED MISSION GOES ON -- SO THIS IS TEMPORARY + paths.clear(); + paths += "/DATA/MIS0BOBS.LST", "/DATA/MIS1BOBS.LST", "/DATA/MIS2BOBS.LST", "/DATA/MIS3BOBS.LST", "/DATA/MIS4BOBS.LST", + "/DATA/MIS5BOBS.LST"; + BOOST_FOREACH(const std::string& file, paths) + { + std::cout << "\nLoading file: " << file << "..."; + if(!CFile::open_file(global::gameDataFilePath + file, LST)) + { + std::cout << "failure"; + return false; + } + } + + // create the mainmenu + callback::mainmenu(INITIALIZING_CALL); + + return true; +} diff --git a/CGame_Render.cpp b/CGame_Render.cpp index 11fde70..92fc299 100644 --- a/CGame_Render.cpp +++ b/CGame_Render.cpp @@ -1,148 +1,148 @@ -#include "CGame.h" -#include "CIO/CMenu.h" -#include "CIO/CWindow.h" -#include "CMap.h" -#include "CSurface.h" -#include "globals.h" -#include -#ifdef _WIN32 -#include "s25editResource.h" -#include -#define WIN32_LEAN_AND_MEAN -#include -#endif - -void CGame::SetAppIcon() -{ -#ifdef _WIN32 - LPARAM icon = (LPARAM)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SYMBOL)); - SendMessage(GetConsoleWindow(), WM_SETICON, ICON_BIG, icon); - SendMessage(GetConsoleWindow(), WM_SETICON, ICON_SMALL, icon); - - SDL_SysWMinfo info; - // get window handle from SDL - SDL_VERSION(&info.version); - if(SDL_GetWMInfo(&info) != 1) - return; - SendMessage(info.window, WM_SETICON, ICON_BIG, icon); - SendMessage(info.window, WM_SETICON, ICON_SMALL, icon); -#endif // _WIN32 -} - -void CGame::Render() -{ - // clear the surface before drawing new (in normal case not needed) - // SDL_FillRect( Surf_Display, NULL, SDL_MapRGB(Surf_Display->format,0,0,0) ); - - // check resolution - /* - if (MapObj == NULL || !MapObj->isActive()) - { - //we are in menu - if ( (Surf_Display->w != MenuResolutionX || Surf_Display->h != MenuResolutionY) || - ( (fullscreen && !(Surf_Display->flags&SDL_FULLSCREEN)) || (!fullscreen && (Surf_Display->flags&SDL_FULLSCREEN)) ) - ) - { - SDL_FreeSurface(Surf_Display); - Surf_Display = SDL_SetVideoMode(MenuResolutionX, MenuResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? - SDL_FULLSCREEN : 0)); - } - } - else - { - */ - // we are in game - if((Surf_Display->w != GameResolutionX || Surf_Display->h != GameResolutionY) - || ((fullscreen && !(Surf_Display->flags & SDL_FULLSCREEN)) || (!fullscreen && (Surf_Display->flags & SDL_FULLSCREEN)))) - { - SDL_FreeSurface(Surf_Display); - Surf_Display = NULL; - - if(CSurface::useOpenGL) - { - SDL_FreeSurface(Surf_DisplayGL); - - Surf_DisplayGL = SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); - Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolutionX, GameResolutionY, 32, 0, 0, 0, 0); - } else - { - Surf_Display = - SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); - } - SetAppIcon(); - } - //} - - // if the S2 loading screen is shown, render only this until user clicks a mouse button - if(showLoadScreen) - { - // CSurface::Draw(Surf_Display, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0); - sge_TexturedRect( - Surf_Display, 0, 0, Surf_Display->w - 1, 0, 0, Surf_Display->h - 1, Surf_Display->w - 1, Surf_Display->h - 1, - global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, 0, - 0, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, - global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1); - - if(CSurface::useOpenGL) - { - // SDL_BlitSurface(Surf_Display, NULL, Surf_DisplayGL, NULL); - // SDL_Flip(Surf_DisplayGL); - SDL_GL_SwapBuffers(); - } else - SDL_Flip(Surf_Display); - return; - } - - // render the map if active - if(MapObj != NULL && MapObj->isActive()) - CSurface::Draw(Surf_Display, MapObj->getSurface(), 0, 0); - - // render active menus - for(int i = 0; i < MAXMENUS; i++) - { - if(Menus[i] != NULL && Menus[i]->isActive()) - CSurface::Draw(Surf_Display, Menus[i]->getSurface(), 0, 0); - } - - // render windows ordered by priority - int highestPriority = 0; - // first find the highest priority - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && Windows[i]->getPriority() > highestPriority) - highestPriority = Windows[i]->getPriority(); - } - // render from lowest priority to highest - for(int actualPriority = 0; actualPriority <= highestPriority; actualPriority++) - { - for(int i = 0; i < MAXWINDOWS; i++) - { - if(Windows[i] != NULL && Windows[i]->getPriority() == actualPriority) - CSurface::Draw(Surf_Display, Windows[i]->getSurface(), Windows[i]->getX(), Windows[i]->getY()); - } - } - - // render mouse cursor - if(Cursor.clicked == true) - { - if(Cursor.button.right) - CSurface::Draw(Surf_Display, global::bmpArray[CROSS].surface, Cursor.x, Cursor.y); - else - CSurface::Draw(Surf_Display, global::bmpArray[CURSOR_CLICKED].surface, Cursor.x, Cursor.y); - } else - CSurface::Draw(Surf_Display, global::bmpArray[CURSOR].surface, Cursor.x, Cursor.y); - -#ifdef _ADMINMODE - FrameCounter++; -#endif - - if(CSurface::useOpenGL) - { - SDL_BlitSurface(Surf_Display, NULL, Surf_DisplayGL, NULL); - SDL_Flip(Surf_DisplayGL); - SDL_GL_SwapBuffers(); - } else - SDL_Flip(Surf_Display); - - SDL_Delay(msWait); -} +#include "CGame.h" +#include "CIO/CMenu.h" +#include "CIO/CWindow.h" +#include "CMap.h" +#include "CSurface.h" +#include "globals.h" +#include +#ifdef _WIN32 +#include "s25editResource.h" +#include +#define WIN32_LEAN_AND_MEAN +#include +#endif + +void CGame::SetAppIcon() +{ +#ifdef _WIN32 + LPARAM icon = (LPARAM)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SYMBOL)); + SendMessage(GetConsoleWindow(), WM_SETICON, ICON_BIG, icon); + SendMessage(GetConsoleWindow(), WM_SETICON, ICON_SMALL, icon); + + SDL_SysWMinfo info; + // get window handle from SDL + SDL_VERSION(&info.version); + if(SDL_GetWMInfo(&info) != 1) + return; + SendMessage(info.window, WM_SETICON, ICON_BIG, icon); + SendMessage(info.window, WM_SETICON, ICON_SMALL, icon); +#endif // _WIN32 +} + +void CGame::Render() +{ + // clear the surface before drawing new (in normal case not needed) + // SDL_FillRect( Surf_Display, NULL, SDL_MapRGB(Surf_Display->format,0,0,0) ); + + // check resolution + /* + if (MapObj == NULL || !MapObj->isActive()) + { + //we are in menu + if ( (Surf_Display->w != MenuResolutionX || Surf_Display->h != MenuResolutionY) || + ( (fullscreen && !(Surf_Display->flags&SDL_FULLSCREEN)) || (!fullscreen && (Surf_Display->flags&SDL_FULLSCREEN)) ) + ) + { + SDL_FreeSurface(Surf_Display); + Surf_Display = SDL_SetVideoMode(MenuResolutionX, MenuResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? + SDL_FULLSCREEN : 0)); + } + } + else + { + */ + // we are in game + if((Surf_Display->w != GameResolutionX || Surf_Display->h != GameResolutionY) + || ((fullscreen && !(Surf_Display->flags & SDL_FULLSCREEN)) || (!fullscreen && (Surf_Display->flags & SDL_FULLSCREEN)))) + { + SDL_FreeSurface(Surf_Display); + Surf_Display = NULL; + + if(CSurface::useOpenGL) + { + SDL_FreeSurface(Surf_DisplayGL); + + Surf_DisplayGL = SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)); + Surf_Display = SDL_CreateRGBSurface(SDL_SWSURFACE, GameResolutionX, GameResolutionY, 32, 0, 0, 0, 0); + } else + { + Surf_Display = + SDL_SetVideoMode(GameResolutionX, GameResolutionY, 32, SDL_SWSURFACE | SDL_DOUBLEBUF | (fullscreen ? SDL_FULLSCREEN : 0)); + } + SetAppIcon(); + } + //} + + // if the S2 loading screen is shown, render only this until user clicks a mouse button + if(showLoadScreen) + { + // CSurface::Draw(Surf_Display, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0); + sge_TexturedRect( + Surf_Display, 0, 0, Surf_Display->w - 1, 0, 0, Surf_Display->h - 1, Surf_Display->w - 1, Surf_Display->h - 1, + global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface, 0, 0, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, 0, + 0, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1, global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->w - 1, + global::bmpArray[SPLASHSCREEN_LOADING_S2SCREEN].surface->h - 1); + + if(CSurface::useOpenGL) + { + // SDL_BlitSurface(Surf_Display, NULL, Surf_DisplayGL, NULL); + // SDL_Flip(Surf_DisplayGL); + SDL_GL_SwapBuffers(); + } else + SDL_Flip(Surf_Display); + return; + } + + // render the map if active + if(MapObj != NULL && MapObj->isActive()) + CSurface::Draw(Surf_Display, MapObj->getSurface(), 0, 0); + + // render active menus + for(int i = 0; i < MAXMENUS; i++) + { + if(Menus[i] != NULL && Menus[i]->isActive()) + CSurface::Draw(Surf_Display, Menus[i]->getSurface(), 0, 0); + } + + // render windows ordered by priority + int highestPriority = 0; + // first find the highest priority + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && Windows[i]->getPriority() > highestPriority) + highestPriority = Windows[i]->getPriority(); + } + // render from lowest priority to highest + for(int actualPriority = 0; actualPriority <= highestPriority; actualPriority++) + { + for(int i = 0; i < MAXWINDOWS; i++) + { + if(Windows[i] != NULL && Windows[i]->getPriority() == actualPriority) + CSurface::Draw(Surf_Display, Windows[i]->getSurface(), Windows[i]->getX(), Windows[i]->getY()); + } + } + + // render mouse cursor + if(Cursor.clicked == true) + { + if(Cursor.button.right) + CSurface::Draw(Surf_Display, global::bmpArray[CROSS].surface, Cursor.x, Cursor.y); + else + CSurface::Draw(Surf_Display, global::bmpArray[CURSOR_CLICKED].surface, Cursor.x, Cursor.y); + } else + CSurface::Draw(Surf_Display, global::bmpArray[CURSOR].surface, Cursor.x, Cursor.y); + +#ifdef _ADMINMODE + FrameCounter++; +#endif + + if(CSurface::useOpenGL) + { + SDL_BlitSurface(Surf_Display, NULL, Surf_DisplayGL, NULL); + SDL_Flip(Surf_DisplayGL); + SDL_GL_SwapBuffers(); + } else + SDL_Flip(Surf_Display); + + SDL_Delay(msWait); +} diff --git a/CIO/CButton.cpp b/CIO/CButton.cpp index cb6f4c2..9780fd5 100644 --- a/CIO/CButton.cpp +++ b/CIO/CButton.cpp @@ -1,318 +1,318 @@ -#include "CButton.h" -#include "../CSurface.h" -#include "../globals.h" -#include "CFont.h" - -CButton::CButton(void callback(int), int clickedParam, Uint16 x, Uint16 y, Uint16 w, Uint16 h, int color, const char* text, - int button_picture) -{ - marked = false; - clicked = false; - this->x = x; - this->y = y; - this->w = w; - this->h = h; - setColor(color); - this->button_picture = button_picture; - button_text = text; - button_text_color = FONT_YELLOW; - this->callback = callback; - this->clickedParam = clickedParam; - motionEntryParam = -1; - motionLeaveParam = -1; - Surf_Button = NULL; - needSurface = true; - needRender = true; -} - -CButton::~CButton() -{ - SDL_FreeSurface(Surf_Button); -} - -void CButton::setButtonPicture(int picture) -{ - this->button_picture = picture; - needRender = true; -} - -void CButton::setButtonText(const char* text) -{ - button_text = text; - needRender = true; -} - -void CButton::setColor(int color) -{ - switch(color) - { - case BUTTON_GREY: - pic_normal = BUTTON_GREY_DARK; - pic_marked = BUTTON_GREY_BRIGHT; - pic_background = BUTTON_GREY_BACKGROUND; - break; - - case BUTTON_RED1: - pic_normal = BUTTON_RED1_DARK; - pic_marked = BUTTON_RED1_BRIGHT; - pic_background = BUTTON_RED1_BACKGROUND; - break; - - case BUTTON_GREEN1: - pic_normal = BUTTON_GREEN1_DARK; - pic_marked = BUTTON_GREEN1_BRIGHT; - pic_background = BUTTON_GREEN1_BACKGROUND; - break; - - case BUTTON_GREEN2: - pic_normal = BUTTON_GREEN2_DARK; - pic_marked = BUTTON_GREEN2_BRIGHT; - pic_background = BUTTON_GREEN2_BACKGROUND; - break; - - case BUTTON_RED2: - pic_normal = BUTTON_RED2_DARK; - pic_marked = BUTTON_RED2_BRIGHT; - pic_background = BUTTON_RED2_BACKGROUND; - break; - - case BUTTON_STONE: - pic_normal = BUTTON_STONE_DARK; - pic_marked = BUTTON_STONE_BRIGHT; - pic_background = BUTTON_STONE_BACKGROUND; - break; - - default: - pic_normal = BUTTON_GREY_DARK; - pic_marked = BUTTON_GREY_BRIGHT; - pic_background = BUTTON_GREY_BACKGROUND; - break; - } - - needRender = true; -} - -void CButton::setMouseData(SDL_MouseMotionEvent motion) -{ - // cursor is on the button (and mouse button not pressed while moving on the button) - if((motion.x >= x) && (motion.x < x + w) && (motion.y >= y) && (motion.y < y + h)) - { - if(motion.state != SDL_PRESSED || motion.state == SDL_RELEASED) - { - marked = true; - if(motionEntryParam >= 0 && callback != NULL) - callback(motionEntryParam); - } - } else - { - // button was marked before and mouse cursor is on the button now, so do the callback - if(motionLeaveParam >= 0 && callback != NULL && marked == true) - callback(motionLeaveParam); - marked = false; - } - needRender = true; -} - -void CButton::setMouseData(SDL_MouseButtonEvent button) -{ - // left button is pressed - if(button.button == SDL_BUTTON_LEFT) - { - // if mouse button is pressed ON the button, set marked=true - if((button.state == SDL_PRESSED) && (button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - { - marked = true; - clicked = true; - } else if(button.state == SDL_RELEASED) - { - clicked = false; - // if mouse button is released ON the BUTTON (marked = true), then do the callback - if(marked && callback != NULL) - callback(clickedParam); - } - } - needRender = true; -} - -bool CButton::render() -{ - // position in the Surface 'Surf_Button' - Uint16 pos_x = 0; - Uint16 pos_y = 0; - // width and height of the button color source picture - Uint16 pic_w = 0; - Uint16 pic_h = 0; - // foreground of the button --> marked or unmarked, NOT the picture - int foreground; - - // if we don't need to render, all is up to date, return true - if(!needRender) - return true; - needRender = false; - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_Button); - Surf_Button = NULL; - if((Surf_Button = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) - return false; - needSurface = false; - } - - // at first completly fill the background (not the fastest way, but simplier) - if(w <= global::bmpArray[pic_background].w) - pic_w = w; - else - pic_w = global::bmpArray[pic_background].w; - - if(h <= global::bmpArray[pic_background].h) - pic_h = h; - else - pic_h = global::bmpArray[pic_background].h; - - while(pos_x + pic_w <= Surf_Button->w) - { - while(pos_y + pic_h <= Surf_Button->h) - { - CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); - pos_y += pic_h; - } - - if(Surf_Button->h - pos_y > 0) - CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Button->h - pos_y); - - pos_y = 0; - pos_x += pic_w; - } - - if(Surf_Button->w - pos_x > 0) - { - while(pos_y + pic_h <= Surf_Button->h) - { - CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Button->w - pos_x, pic_h); - pos_y += pic_h; - } - - if(Surf_Button->h - pos_y > 0) - CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Button->w - pos_x, - Surf_Button->h - pos_y); - } - - // draw partial black frame - if(clicked) - { - // black frame is left and up - // draw vertical line - pos_x = 0; - for(int y = 0; y < h; y++) - CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); - - // draw vertical line - pos_x = 1; - for(int y = 0; y < h - 1; y++) - CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); - - // draw horizontal line - pos_y = 0; - for(int x = 0; x < w; x++) - CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); - - // draw horizontal line - pos_y = 1; - for(int x = 0; x < w - 1; x++) - CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); - } else - { - // black frame is right and down - // draw vertical line - pos_x = w - 1; - for(int y = 0; y < h; y++) - CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); - - // draw vertical line - pos_x = w - 2; - for(int y = 1; y < h; y++) - CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); - - // draw horizontal line - pos_y = h - 1; - for(int x = 0; x < w; x++) - CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); - - // draw horizontal line - pos_y = h - 2; - for(int x = 1; x < w; x++) - CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); - } - - // draw the foreground --> at first the color (marked or unmarked) and then the picture or text - if(w <= global::bmpArray[pic_normal].w) - pic_w = w; - else - pic_w = global::bmpArray[pic_normal].w; - - if(h <= global::bmpArray[pic_normal].h) - pic_h = h; - else - pic_h = global::bmpArray[pic_normal].h; - - // beware overdrawing the left and upper frame - pos_x = 2; - pos_y = 2; - - // decide if button lights or not - if(marked && !clicked) - foreground = pic_marked; - else - foreground = pic_normal; - - // '-2' follows a few times, this means: beware overdrawing the right and lower frame - while(pos_x + pic_w <= Surf_Button->w - 2) - { - while(pos_y + pic_h <= Surf_Button->h - 2) - { - CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); - pos_y += pic_h; - } - - if(Surf_Button->h - 2 - pos_y > 0) - CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Button->h - 2 - pos_y); - - pos_y = 2; - pos_x += pic_w; - } - - if(Surf_Button->w - 2 - pos_x > 0) - { - while(pos_y + pic_h <= Surf_Button->h - 2) - { - CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, Surf_Button->w - 2 - pos_x, pic_h); - pos_y += pic_h; - } - - if(Surf_Button->h - 2 - pos_y > 0) - CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, Surf_Button->w - 2 - pos_x, - Surf_Button->h - 2 - pos_y); - } - - // positioning the picture or write text - if(button_picture >= 0) - { - // picture may not be bigger than the button - if(global::bmpArray[button_picture].w <= Surf_Button->w && global::bmpArray[button_picture].h <= Surf_Button->h) - { - // get coordinates of the left upper corner where to positionate the picture - int leftup_x = (int)(Surf_Button->w / 2) - (int)(global::bmpArray[button_picture].w / 2); - int leftup_y = (int)(Surf_Button->h / 2) - (int)(global::bmpArray[button_picture].h / 2); - // blit it - CSurface::Draw(Surf_Button, global::bmpArray[button_picture].surface, leftup_x, leftup_y); - } else - { - button_picture = -1; - button_text = "PIC"; - } - } else if(button_text != NULL) - CFont::writeText(Surf_Button, button_text, (int)w / 2, (int)((h - 11) / 2), 11, button_text_color, ALIGN_MIDDLE); - - return true; -} +#include "CButton.h" +#include "../CSurface.h" +#include "../globals.h" +#include "CFont.h" + +CButton::CButton(void callback(int), int clickedParam, Uint16 x, Uint16 y, Uint16 w, Uint16 h, int color, const char* text, + int button_picture) +{ + marked = false; + clicked = false; + this->x = x; + this->y = y; + this->w = w; + this->h = h; + setColor(color); + this->button_picture = button_picture; + button_text = text; + button_text_color = FONT_YELLOW; + this->callback = callback; + this->clickedParam = clickedParam; + motionEntryParam = -1; + motionLeaveParam = -1; + Surf_Button = NULL; + needSurface = true; + needRender = true; +} + +CButton::~CButton() +{ + SDL_FreeSurface(Surf_Button); +} + +void CButton::setButtonPicture(int picture) +{ + this->button_picture = picture; + needRender = true; +} + +void CButton::setButtonText(const char* text) +{ + button_text = text; + needRender = true; +} + +void CButton::setColor(int color) +{ + switch(color) + { + case BUTTON_GREY: + pic_normal = BUTTON_GREY_DARK; + pic_marked = BUTTON_GREY_BRIGHT; + pic_background = BUTTON_GREY_BACKGROUND; + break; + + case BUTTON_RED1: + pic_normal = BUTTON_RED1_DARK; + pic_marked = BUTTON_RED1_BRIGHT; + pic_background = BUTTON_RED1_BACKGROUND; + break; + + case BUTTON_GREEN1: + pic_normal = BUTTON_GREEN1_DARK; + pic_marked = BUTTON_GREEN1_BRIGHT; + pic_background = BUTTON_GREEN1_BACKGROUND; + break; + + case BUTTON_GREEN2: + pic_normal = BUTTON_GREEN2_DARK; + pic_marked = BUTTON_GREEN2_BRIGHT; + pic_background = BUTTON_GREEN2_BACKGROUND; + break; + + case BUTTON_RED2: + pic_normal = BUTTON_RED2_DARK; + pic_marked = BUTTON_RED2_BRIGHT; + pic_background = BUTTON_RED2_BACKGROUND; + break; + + case BUTTON_STONE: + pic_normal = BUTTON_STONE_DARK; + pic_marked = BUTTON_STONE_BRIGHT; + pic_background = BUTTON_STONE_BACKGROUND; + break; + + default: + pic_normal = BUTTON_GREY_DARK; + pic_marked = BUTTON_GREY_BRIGHT; + pic_background = BUTTON_GREY_BACKGROUND; + break; + } + + needRender = true; +} + +void CButton::setMouseData(SDL_MouseMotionEvent motion) +{ + // cursor is on the button (and mouse button not pressed while moving on the button) + if((motion.x >= x) && (motion.x < x + w) && (motion.y >= y) && (motion.y < y + h)) + { + if(motion.state != SDL_PRESSED || motion.state == SDL_RELEASED) + { + marked = true; + if(motionEntryParam >= 0 && callback != NULL) + callback(motionEntryParam); + } + } else + { + // button was marked before and mouse cursor is on the button now, so do the callback + if(motionLeaveParam >= 0 && callback != NULL && marked == true) + callback(motionLeaveParam); + marked = false; + } + needRender = true; +} + +void CButton::setMouseData(SDL_MouseButtonEvent button) +{ + // left button is pressed + if(button.button == SDL_BUTTON_LEFT) + { + // if mouse button is pressed ON the button, set marked=true + if((button.state == SDL_PRESSED) && (button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + { + marked = true; + clicked = true; + } else if(button.state == SDL_RELEASED) + { + clicked = false; + // if mouse button is released ON the BUTTON (marked = true), then do the callback + if(marked && callback != NULL) + callback(clickedParam); + } + } + needRender = true; +} + +bool CButton::render() +{ + // position in the Surface 'Surf_Button' + Uint16 pos_x = 0; + Uint16 pos_y = 0; + // width and height of the button color source picture + Uint16 pic_w = 0; + Uint16 pic_h = 0; + // foreground of the button --> marked or unmarked, NOT the picture + int foreground; + + // if we don't need to render, all is up to date, return true + if(!needRender) + return true; + needRender = false; + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_Button); + Surf_Button = NULL; + if((Surf_Button = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) + return false; + needSurface = false; + } + + // at first completly fill the background (not the fastest way, but simplier) + if(w <= global::bmpArray[pic_background].w) + pic_w = w; + else + pic_w = global::bmpArray[pic_background].w; + + if(h <= global::bmpArray[pic_background].h) + pic_h = h; + else + pic_h = global::bmpArray[pic_background].h; + + while(pos_x + pic_w <= Surf_Button->w) + { + while(pos_y + pic_h <= Surf_Button->h) + { + CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); + pos_y += pic_h; + } + + if(Surf_Button->h - pos_y > 0) + CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Button->h - pos_y); + + pos_y = 0; + pos_x += pic_w; + } + + if(Surf_Button->w - pos_x > 0) + { + while(pos_y + pic_h <= Surf_Button->h) + { + CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Button->w - pos_x, pic_h); + pos_y += pic_h; + } + + if(Surf_Button->h - pos_y > 0) + CSurface::Draw(Surf_Button, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Button->w - pos_x, + Surf_Button->h - pos_y); + } + + // draw partial black frame + if(clicked) + { + // black frame is left and up + // draw vertical line + pos_x = 0; + for(int y = 0; y < h; y++) + CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); + + // draw vertical line + pos_x = 1; + for(int y = 0; y < h - 1; y++) + CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); + + // draw horizontal line + pos_y = 0; + for(int x = 0; x < w; x++) + CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); + + // draw horizontal line + pos_y = 1; + for(int x = 0; x < w - 1; x++) + CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); + } else + { + // black frame is right and down + // draw vertical line + pos_x = w - 1; + for(int y = 0; y < h; y++) + CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); + + // draw vertical line + pos_x = w - 2; + for(int y = 1; y < h; y++) + CSurface::DrawPixel_RGB(Surf_Button, pos_x, y, 0, 0, 0); + + // draw horizontal line + pos_y = h - 1; + for(int x = 0; x < w; x++) + CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); + + // draw horizontal line + pos_y = h - 2; + for(int x = 1; x < w; x++) + CSurface::DrawPixel_RGB(Surf_Button, x, pos_y, 0, 0, 0); + } + + // draw the foreground --> at first the color (marked or unmarked) and then the picture or text + if(w <= global::bmpArray[pic_normal].w) + pic_w = w; + else + pic_w = global::bmpArray[pic_normal].w; + + if(h <= global::bmpArray[pic_normal].h) + pic_h = h; + else + pic_h = global::bmpArray[pic_normal].h; + + // beware overdrawing the left and upper frame + pos_x = 2; + pos_y = 2; + + // decide if button lights or not + if(marked && !clicked) + foreground = pic_marked; + else + foreground = pic_normal; + + // '-2' follows a few times, this means: beware overdrawing the right and lower frame + while(pos_x + pic_w <= Surf_Button->w - 2) + { + while(pos_y + pic_h <= Surf_Button->h - 2) + { + CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); + pos_y += pic_h; + } + + if(Surf_Button->h - 2 - pos_y > 0) + CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Button->h - 2 - pos_y); + + pos_y = 2; + pos_x += pic_w; + } + + if(Surf_Button->w - 2 - pos_x > 0) + { + while(pos_y + pic_h <= Surf_Button->h - 2) + { + CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, Surf_Button->w - 2 - pos_x, pic_h); + pos_y += pic_h; + } + + if(Surf_Button->h - 2 - pos_y > 0) + CSurface::Draw(Surf_Button, global::bmpArray[foreground].surface, pos_x, pos_y, 0, 0, Surf_Button->w - 2 - pos_x, + Surf_Button->h - 2 - pos_y); + } + + // positioning the picture or write text + if(button_picture >= 0) + { + // picture may not be bigger than the button + if(global::bmpArray[button_picture].w <= Surf_Button->w && global::bmpArray[button_picture].h <= Surf_Button->h) + { + // get coordinates of the left upper corner where to positionate the picture + int leftup_x = (int)(Surf_Button->w / 2) - (int)(global::bmpArray[button_picture].w / 2); + int leftup_y = (int)(Surf_Button->h / 2) - (int)(global::bmpArray[button_picture].h / 2); + // blit it + CSurface::Draw(Surf_Button, global::bmpArray[button_picture].surface, leftup_x, leftup_y); + } else + { + button_picture = -1; + button_text = "PIC"; + } + } else if(button_text != NULL) + CFont::writeText(Surf_Button, button_text, (int)w / 2, (int)((h - 11) / 2), 11, button_text_color, ALIGN_MIDDLE); + + return true; +} diff --git a/CIO/CButton.h b/CIO/CButton.h index 8291b57..d65f0e6 100644 --- a/CIO/CButton.h +++ b/CIO/CButton.h @@ -1,66 +1,66 @@ -#ifndef _CBUTTON_H -#define _CBUTTON_H - -#include "../includes.h" - -class CButton -{ - friend class CDebug; - -private: - SDL_Surface* Surf_Button; - bool needSurface; - bool needRender; - Uint16 x; - Uint16 y; - Uint16 w; - Uint16 h; - int pic_normal; - int pic_marked; - int pic_background; - int button_picture; - const char* button_text; - int button_text_color; - bool marked; - bool clicked; - void (*callback)(int); - int clickedParam; - int motionEntryParam; - int motionLeaveParam; - -public: - // Constructor - Destructor - CButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 w = 20, Uint16 h = 20, int color = BUTTON_GREY, - const char* text = NULL, int picture = -1); - ~CButton(); - // Access - int getX() { return x; }; - int getY() { return y; }; - int getW() { return w; }; - int getH() { return h; }; - void setX(int x) { this->x = x; }; - void setY(int y) { this->y = y; }; - void setButtonPicture(int picture); - void setButtonText(const char* text); - void setMouseData(SDL_MouseMotionEvent motion); - void setMouseData(SDL_MouseButtonEvent button); - bool render(); - SDL_Surface* getSurface() - { - render(); - return Surf_Button; - }; - void setColor(int color); - void setTextColor(int color) - { - button_text_color = color; - needRender = true; - }; - void setMotionParams(int entry, int leave) - { - motionEntryParam = entry; - motionLeaveParam = leave; - }; -}; - -#endif +#ifndef _CBUTTON_H +#define _CBUTTON_H + +#include "../includes.h" + +class CButton +{ + friend class CDebug; + +private: + SDL_Surface* Surf_Button; + bool needSurface; + bool needRender; + Uint16 x; + Uint16 y; + Uint16 w; + Uint16 h; + int pic_normal; + int pic_marked; + int pic_background; + int button_picture; + const char* button_text; + int button_text_color; + bool marked; + bool clicked; + void (*callback)(int); + int clickedParam; + int motionEntryParam; + int motionLeaveParam; + +public: + // Constructor - Destructor + CButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 w = 20, Uint16 h = 20, int color = BUTTON_GREY, + const char* text = NULL, int picture = -1); + ~CButton(); + // Access + int getX() { return x; }; + int getY() { return y; }; + int getW() { return w; }; + int getH() { return h; }; + void setX(int x) { this->x = x; }; + void setY(int y) { this->y = y; }; + void setButtonPicture(int picture); + void setButtonText(const char* text); + void setMouseData(SDL_MouseMotionEvent motion); + void setMouseData(SDL_MouseButtonEvent button); + bool render(); + SDL_Surface* getSurface() + { + render(); + return Surf_Button; + }; + void setColor(int color); + void setTextColor(int color) + { + button_text_color = color; + needRender = true; + }; + void setMotionParams(int entry, int leave) + { + motionEntryParam = entry; + motionLeaveParam = leave; + }; +}; + +#endif diff --git a/CIO/CFile.cpp b/CIO/CFile.cpp index bec985b..9e9acfe 100644 --- a/CIO/CFile.cpp +++ b/CIO/CFile.cpp @@ -1,1502 +1,1502 @@ -#include "CFile.h" -#include "../CSurface.h" -#include "../globals.h" -#include -#include -#include - -// Hard coded file format :( -#if SDL_BYTEORDER != SDL_LIL_ENDIAN -#error "Only little endian systems are supported" -#endif - -FILE* CFile::fp = NULL; -bobBMP* CFile::bmpArray = &global::bmpArray[0]; -bobSHADOW* CFile::shadowArray = &global::shadowArray[0]; -bobPAL* CFile::palArray = &global::palArray[0]; -bobPAL* CFile::palActual = &global::palArray[0]; -bool CFile::loadPAL = false; - -inline void freadChecked(void* buf, size_t elSize, size_t elCt, FILE* file) -{ - if(fread(buf, elSize, elCt, file) != elCt && !feof(file)) - throw std::runtime_error("Read failed"); -} - -CFile::CFile() {} - -CFile::~CFile() {} - -void* CFile::open_file(const std::string& filename, char filetype, bool only_loadPAL) -{ - void* return_value = NULL; - - if(filename.empty() || bmpArray == NULL || shadowArray == NULL || palArray == NULL || palActual == NULL) - return NULL; - - else if((fp = boost::nowide::fopen(filename.c_str(), "rb")) == NULL) - return NULL; - - if(only_loadPAL) - loadPAL = true; - - try - { - switch(filetype) - { - case LST: - if(open_lst()) - return_value = (void*)-1; - - break; - - case BOB: - if(open_bob()) - return_value = (void*)-1; - - break; - - case IDX: - if(open_idx(filename)) - return_value = (void*)-1; - - break; - - case BBM: - if(open_bbm()) - return_value = (void*)-1; - - break; - - case LBM: - if(open_lbm(filename)) - return_value = (void*)-1; - - break; - - case GOU: - if(open_gou()) - return_value = (void*)-1; - - break; - - case WLD: return_value = open_wld(); break; - - case SWD: return_value = open_swd(); break; - - default: // no valid data type - break; - } - } catch(const std::exception& e) - { - std::cerr << "Error while reading " << filename << ": " << e.what() << std::endl; - } - - if(fp != NULL) - { - fclose(fp); - fp = NULL; - } - - loadPAL = false; - - return return_value; -} - -bool CFile::open_lst() -{ - // type of entry (used or unused entry) - Uint16 entrytype; - // bobtype of the entry - Uint16 bobtype; - - // skip: id (2x 1 Bytes) + count (1x 4 Bytes) = 6 Bytes - fseek(fp, 6, SEEK_SET); - - // main loop for reading entrys - while(!feof(fp)) - { - // entry type (2 Bytes) - unused (=0x0000) or used (=0x0001) - - freadChecked(&entrytype, 2, 1, fp); - - // if entry is unused, go back to 'while' --- and by the way: after the last entry there are always zeros in the file, - // so the following case will happen till we have reached the end of the file and the 'while' will break - PERFECT! - if(entrytype == 0x0000) - continue; - - // bobtype (2 Bytes) - freadChecked(&bobtype, 2, 1, fp); - - switch(bobtype) - { - case BOBTYPE01: - if(read_bob01() == false) - return false; - break; - - case BOBTYPE02: - if(read_bob02() == false) - return false; - break; - - case BOBTYPE03: - if(read_bob03() == false) - return false; - break; - - case BOBTYPE04: - if(read_bob04(PLAYER_BLUE) == false) - return false; - break; - - case BOBTYPE05: - if(read_bob05() == false) - return false; - break; - - case BOBTYPE07: - if(read_bob07() == false) - return false; - break; - - case BOBTYPE14: - if(read_bob14() == false) - return false; - break; - - default: // Something is wrong? Maybe the last entry was really the LAST, so we should not return false - break; - } - } - - return true; -} - -bool CFile::open_bob() -{ - return false; -} - -bool CFile::open_idx(const std::string& filename) -{ - // temporary filepointer to save global fp until this function has finished - FILE* fp_tmp; - // pointer to '******.IDX'-File (cause we have to change the global pointer to point to the '.DAT'-File) - FILE* fp_idx; - // pointer to corresponding '******.DAT'-File - FILE* fp_dat; - // array index for the first letter of the file ending ( the 'I' in 'IDX' ) to overwrite IDX with DAT - unsigned fileending; - // starting adress of data in the corresponding '******.DAT'-File - Uint32 offset; - // bobtype of the entry - Uint16 bobtype; - // bobtype is repeated in the corresponging '******.DAT'-File, so we have to check this is correct - Uint16 bobtype_check; - - // save global filepointer - fp_tmp = fp; - // get a new filepointer to the '.IDX'-File - if((fp_idx = boost::nowide::fopen(filename.c_str(), "rb")) == NULL) - return false; - // following code will open the corresponding '******.DAT'-File - // allocate memory for new name - std::string filename_dat = filename; - // if strlen = n, so array walks von 0 to n-1. n-1 is the last letter of the file ending ( the 'X' in 'IDX' ), so we have to walk back - // one time to be at the last letter and then two times to be at the 'I' = walk back 3 times - fileending = static_cast(filename.size() - 3); - // now overwrite 'IDX' with 'DAT' - filename_dat[fileending] = 'D'; - filename_dat[fileending + 1] = 'A'; - filename_dat[fileending + 2] = 'T'; - // get the filepointer of the corresponging '******.DAT'-File - if((fp_dat = boost::nowide::fopen(filename_dat.c_str(), "rb")) == NULL) - return false; - // we are finished opening the 'DAT'-File, now we can handle the content - - // skip: unknown data (1x 4 Bytes) at the beginning of the file - fseek(fp_idx, 4, SEEK_SET); - - // main loop for reading entrys - while(!feof(fp_idx) && !feof(fp_dat)) - { - // skip: name (1x 16 Bytes) - fseek(fp_idx, 16, SEEK_CUR); - // offset (4 Bytes) - freadChecked(&offset, 4, 1, fp_idx); - // skip unknown data (6x 1 Byte) - fseek(fp_idx, 6, SEEK_CUR); - // bobtype (2 Bytes) - freadChecked(&bobtype, 2, 1, fp_idx); - // set fp_dat to the position in 'offset' - fseek(fp_dat, offset, SEEK_SET); - // read bobtype again, now from 'DAT'-File - freadChecked(&bobtype_check, 2, 1, fp_dat); - // check if data in 'DAT'-File is the data that it should be (bobtypes are equal) - if(bobtype != bobtype_check) - return false; - - // set up the global filepointer fp to fp_dat, so the following functions will read from the '.DAT'-File - fp = fp_dat; - - switch(bobtype) - { - case BOBTYPE01: - if(read_bob01() == false) - return false; - break; - - case BOBTYPE02: - if(read_bob02() == false) - return false; - break; - - case BOBTYPE03: - if(read_bob03() == false) - return false; - break; - - case BOBTYPE04: - if(read_bob04() == false) - return false; - break; - - case BOBTYPE05: - if(read_bob05() == false) - return false; - break; - - case BOBTYPE07: - if(read_bob07() == false) - return false; - break; - - case BOBTYPE14: - if(read_bob14() == false) - return false; - break; - - default: // Something is wrong? Maybe the last entry was really the LAST, so we should not return false - break; - } - - // set up the local filepointer fp_dat to fp for the next while loop - fp_dat = fp; - } - - // reset global filepointer to its original value - fp = fp_tmp; - - fclose(fp_idx); - fclose(fp_dat); - - return true; -} - -bool CFile::open_bbm() -{ - // skip header (48 Bytes) - fseek(fp, 48, SEEK_CUR); - - for(int i = 0; i < 256; i++) - { - freadChecked(&((palArray->colors[i]).r), 1, 1, fp); - freadChecked(&((palArray->colors[i]).g), 1, 1, fp); - freadChecked(&((palArray->colors[i]).b), 1, 1, fp); - } - - palArray++; - - return true; -} - -bool CFile::open_lbm(const std::string& filename) -{ - // IMPORTANT NOTE: LBM (also ILBM) is the Interchange File Format (IFF) and the 4-byte-blocks are originally organized as Big Endian, so - // a convertion is needed - - // identifier for the kind of data follows (FORM, BMHD, CMAP, BODY) - char chunk_identifier[5]; - - // length of data block - Uint32 length; - // color depth of the picture - Uint16 color_depth; - // is the picture rle-compressed? - Uint16 compression_flag; - // compression type - Sint8 ctype; - // array for palette colors - SDL_Color colors[256]; - // color value for read pixel - Uint8 color_value; - - // skip File-Identifier "FORM" (1x 4 Bytes) + unknown data (4x 1 Byte) + Header-Identifier "PBM " (1x 4 Bytes) = 12 Bytes - fseek(fp, 12, SEEK_CUR); - - /* READ FIRST CHUNK "BMHD" */ - - // chunk-identifier (4 Bytes) - freadChecked(chunk_identifier, 4, 1, fp); - chunk_identifier[4] = '\0'; - // should be "BMHD" at this time - if(strcmp(chunk_identifier, "BMHD") != 0) - return false; - // length of data block - freadChecked(&length, 4, 1, fp); - endian_swap(length); - // width of picture (2 Bytes) - freadChecked(&(bmpArray->w), 2, 1, fp); - endian_swap(bmpArray->w); - // heigth of picture (2 Bytes) - freadChecked(&(bmpArray->h), 2, 1, fp); - endian_swap(bmpArray->h); - // skip unknown data (4x 1 Bytes) - fseek(fp, 4, SEEK_CUR); - // color depth of the picture (1x 2 Bytes) - freadChecked(&color_depth, 2, 1, fp); - // compression_flag (1x 2 Bytes) - freadChecked(&compression_flag, 2, 1, fp); - // skip unknown data (length - 20 x 1 Byte) - // fseek(fp, length-20, SEEK_CUR); - - /* READ SECOND CHUNK "CMAP" */ - - // chunk-identifier (4 Bytes) - // search for the "CMAP" and skip other chunk-types - while(!feof(fp)) - { - freadChecked(chunk_identifier, 4, 1, fp); - - if(strcmp(chunk_identifier, "CMAP") == 0) - break; - else - fseek(fp, -3, SEEK_CUR); - } - if(feof(fp)) - return false; - // length of data block - freadChecked(&length, 4, 1, fp); - endian_swap(length); - // must be 768 (RGB = 3 Byte x 256 Colors) - if(length != 768) - return false; - // palette - for(int i = 0; i < 256; i++) - { - freadChecked(&colors[i].r, 1, 1, fp); - freadChecked(&colors[i].g, 1, 1, fp); - freadChecked(&colors[i].b, 1, 1, fp); - } - - /* READ THIRD CHUNK "BODY" */ - - // chunk-identifier (4 Bytes) - // search for the "BODY" and skip other chunk-types - while(!feof(fp)) - { - freadChecked(chunk_identifier, 4, 1, fp); - - if(strcmp(chunk_identifier, "BODY") == 0) - break; - else - fseek(fp, -3, SEEK_CUR); - } - if(feof(fp)) - return false; - // length of data block - freadChecked(&length, 4, 1, fp); - endian_swap(length); - - // now we are ready to read the picture lines and fill the surface, so lets create one - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) - return false; - SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, colors, 0, 256); - - if(compression_flag == 0) - { - // picture uncompressed - // main loop for reading picture lines - for(int y = 0; y < bmpArray->h; y++) - { - // loop for reading pixels of the actual picture line - for(int x = 0; x < bmpArray->w; x++) - { - // read color value (1 Byte) - freadChecked(&color_value, 1, 1, fp); - // draw - CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); - } - } - - } else if(compression_flag == 1) - { - // picture compressed - - // main loop for reading picture lines - for(int y = 0; y < bmpArray->h; y++) - { - // loop for reading pixels of the actual picture line - //(cause of a kind of RLE-Compression we cannot read the pixels sequentially) - //'x' will be incremented WITHIN the loop - for(int x = 0; x < bmpArray->w;) - { - // read compression type - freadChecked(&ctype, 1, 1, fp); - - if(ctype >= 0) - { - // following 'ctype + 1' pixels are uncompressed - for(int k = 0; k < ctype + 1; k++, x++) - { - // read color value (1 Byte) - freadChecked(&color_value, 1, 1, fp); - // draw - CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); - } - } else if(ctype < 0 && ctype >= -127) - { - // draw the following byte '-ctype + 1' times to the surface - freadChecked(&color_value, 1, 1, fp); - - for(int k = 0; k < -ctype + 1; k++, x++) - CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); - } else // if (ctype == -128) - { - // ignore - } - } - } - } else - return false; - - // if this is a texture file, we need a secondary 32-bit surface for SGE and we set a color key at both surfaces - if(filename.find("TEX5.LBM") != std::string::npos || filename.find("TEX6.LBM") != std::string::npos - || filename.find("TEX7.LBM") != std::string::npos || filename.find("TEXTUR_0.LBM") != std::string::npos - || filename.find("TEXTUR_3.LBM") != std::string::npos) - { - SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); - - bmpArray++; - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, (bmpArray - 1)->w, (bmpArray - 1)->h, 32, 0, 0, 0, 0)) != NULL) - { - SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); - CSurface::Draw(bmpArray->surface, (bmpArray - 1)->surface, 0, 0); - } else - bmpArray--; - } - - // we are finished, the surface is filled - // increment bmpArray for the next picture - bmpArray++; - - return true; -} - -bool CFile::open_gou() -{ - static int internalArrayCtr = 0; // maximum is two cause there are only 3 GOUx.DAT-Files - - if(internalArrayCtr > 2) - return false; - - freadChecked(gouData[internalArrayCtr], 256, 256, fp); - internalArrayCtr++; - - return true; -} - -bobMAP* CFile::open_wld() -{ - bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP)); - Uint8 heightFactor; - - if(myMap == NULL) - return myMap; - - // initialize myMap->name and myMap->author (both 20 chars) to prevent filling with random memory content - for(int i = 0; i < 20; i++) - { - myMap->name[i] = '\0'; - myMap->author[i] = '\0'; - } - - fseek(fp, 10, SEEK_SET); - freadChecked(myMap->name, 20, 1, fp); - freadChecked(&myMap->width_old, 2, 1, fp); - freadChecked(&myMap->height_old, 2, 1, fp); - freadChecked(&myMap->type, 1, 1, fp); - freadChecked(&myMap->player, 1, 1, fp); - freadChecked(myMap->author, 20, 1, fp); - freadChecked(myMap->HQx, 2, 7, fp); - freadChecked(myMap->HQy, 2, 7, fp); - - // go to big map header and read it - fseek(fp, 92, SEEK_SET); - for(int i = 0; i < 250; i++) - { - freadChecked(&myMap->header[i].type, 1, 1, fp); - freadChecked(&myMap->header[i].x, 1, 2, fp); - freadChecked(&myMap->header[i].y, 1, 2, fp); - freadChecked(&myMap->header[i].area, 1, 4, fp); - } - - // go to real map height and width - fseek(fp, 2348, SEEK_SET); - freadChecked(&myMap->width, 2, 1, fp); - myMap->width_pixel = myMap->width * TRIANGLE_WIDTH; - freadChecked(&myMap->height, 2, 1, fp); - myMap->height_pixel = myMap->height * TRIANGLE_HEIGHT; - - if((myMap->vertex = (struct point*)malloc(sizeof(struct point) * myMap->width * myMap->height)) == NULL) - { - free(myMap); - return NULL; - } - - // go to altitude information (we skip the 16 bytes long map data header that each block has) - fseek(fp, 16, SEEK_CUR); - - long int a; - long int b = 0; - for(int j = 0; j < myMap->height; j++) - { - if(j % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int i = 0; i < myMap->width; i++) - { - myMap->vertex[j * myMap->width + i].VertexX = i; - myMap->vertex[j * myMap->width + i].VertexY = j; - freadChecked(&heightFactor, 1, 1, fp); - myMap->vertex[j * myMap->width + i].h = heightFactor; - myMap->vertex[j * myMap->width + i].x = a; - myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); - myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); - // TEMPORARY: to prevent drawing point outside the surface (negative points) - // if (myMap->vertex[j*myMap->width+i].y < 0) - // myMap->vertex[j*myMap->width+i].y = 0; - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } - - // go to texture information for RightSideUp-Triangles - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].rsuTexture, 1, 1, fp); - } - - // go to texture information for UpSideDown-Triangles - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].usdTexture, 1, 1, fp); - } - - // go to road data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].road, 1, 1, fp); - } - - // go to object type data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].objectType, 1, 1, fp); - } - - // go to object info data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].objectInfo, 1, 1, fp); - } - - // go to animal data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].animal, 1, 1, fp); - } - - // go to unknown1 data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].unknown1, 1, 1, fp); - } - - // go to build data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].build, 1, 1, fp); - } - - // go to unknown2 data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].unknown2, 1, 1, fp); - } - - // go to unknown3 data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].unknown3, 1, 1, fp); - } - - // go to resource data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].resource, 1, 1, fp); - } - - // go to shading data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].shading, 1, 1, fp); - } - - // go to unknown5 data - fseek(fp, 16, SEEK_CUR); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - freadChecked(&myMap->vertex[j * myMap->width + i].unknown5, 1, 1, fp); - } - - return myMap; -} - -bobMAP* CFile::open_swd() -{ - return open_wld(); -} - -bool CFile::save_file(const std::string& filename, char filetype, void* data) -{ - bool return_value = false; - - if(filename.empty() || data == NULL) - return return_value; - - if((fp = boost::nowide::fopen(filename.c_str(), "wb")) == NULL) - return return_value; - - switch(filetype) - { - case LST: return_value = save_lst(data); break; - - case BOB: return_value = save_bob(data); break; - - case IDX: return_value = save_idx(data, filename); break; - - case BBM: return_value = save_bbm(data); break; - - case LBM: return_value = save_lbm(data); break; - - case WLD: return_value = save_wld(data); break; - - case SWD: return_value = save_swd(data); break; - - default: // no valid data type - return_value = false; - break; - } - - if(fp != NULL) - { - fclose(fp); - fp = NULL; - } - - return return_value; -} - -bool CFile::save_lst(void* data) -{ - return false; -} - -bool CFile::save_bob(void* data) -{ - return false; -} - -bool CFile::save_idx(void* data, const std::string& filename) -{ - return false; -} - -bool CFile::save_bbm(void* data) -{ - return false; -} - -bool CFile::save_lbm(void* data) -{ - return false; -} - -bool CFile::save_wld(void* data) -{ - char zero = 0; // to fill bytes - char temp = 0; // to fill bytes - bobMAP* myMap = (bobMAP*)data; - char map_version[11] = "WORLD_V1.0"; - char map_data_header[16]; - - // prepare map data header - map_data_header[0] = 0x10; - map_data_header[1] = 0x27; - map_data_header[2] = 0x00; - map_data_header[3] = 0x00; - map_data_header[4] = 0x00; - map_data_header[5] = 0x00; - *((Uint16*)(map_data_header + 6)) = myMap->width; - *((Uint16*)(map_data_header + 8)) = myMap->height; - map_data_header[10] = 0x01; - map_data_header[11] = 0x00; - *((Uint32*)(map_data_header + 12)) = myMap->width * myMap->height; - - // begin writing data to file - // first of all the map header - // WORLD_V1.0 - fwrite(map_version, 1, 10, fp); - // name - fwrite(myMap->name, 1, 20, fp); - // old width - fwrite(&myMap->width_old, 2, 1, fp); - // old height - fwrite(&myMap->height_old, 2, 1, fp); - // type - fwrite(&myMap->type, 1, 1, fp); - // players - fwrite(&myMap->player, 1, 1, fp); - // author - fwrite(myMap->author, 1, 20, fp); - // headquarters x - fwrite(myMap->HQx, 2, 7, fp); - // headquarters y - fwrite(myMap->HQy, 2, 7, fp); - // unknown data (8 Bytes) - for(int i = 0; i < 8; i++) - fwrite(&zero, 1, 1, fp); - // big map header with area information - for(int i = 0; i < 250; i++) - { - fwrite(&myMap->header[i].type, 1, 1, fp); - fwrite(&myMap->header[i].x, 1, 2, fp); - fwrite(&myMap->header[i].y, 1, 2, fp); - fwrite(&myMap->header[i].area, 1, 4, fp); - } - // 0x11 0x27 - temp = 0x11; - fwrite(&temp, 1, 1, fp); - temp = 0x27; - fwrite(&temp, 1, 1, fp); - // unknown data (always null, 4 Bytes) - for(int i = 0; i < 4; i++) - fwrite(&zero, 1, 1, fp); - // width - fwrite(&myMap->width, 2, 1, fp); - // height - fwrite(&myMap->height, 2, 1, fp); - - // now begin writing the real map data - - // altitude information - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - { - temp = myMap->vertex[j * myMap->width + i].z / 5 + 0x0A; - fwrite(&temp, 1, 1, fp); - } - } - - // texture information for RightSideUp-Triangles - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].rsuTexture, 1, 1, fp); - } - - // go to texture information for UpSideDown-Triangles - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].usdTexture, 1, 1, fp); - } - - // go to road data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].road, 1, 1, fp); - } - - // go to object type data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].objectType, 1, 1, fp); - } - - // go to object info data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].objectInfo, 1, 1, fp); - } - - // go to animal data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].animal, 1, 1, fp); - } - - // go to unknown1 data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].unknown1, 1, 1, fp); - } - - // go to build data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].build, 1, 1, fp); - } - - // go to unknown2 data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].unknown2, 1, 1, fp); - } - - // go to unknown3 data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].unknown3, 1, 1, fp); - } - - // go to resource data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].resource, 1, 1, fp); - } - - // go to shading data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].shading, 1, 1, fp); - } - - // go to unknown5 data - fwrite(&map_data_header, 16, 1, fp); - - for(int j = 0; j < myMap->height; j++) - { - for(int i = 0; i < myMap->width; i++) - fwrite(&myMap->vertex[j * myMap->width + i].unknown5, 1, 1, fp); - } - - // at least write the map footer (ends in 0xFF) - temp = char(0xFF); - fwrite(&temp, 1, 1, fp); - - return true; -} - -bool CFile::save_swd(void* data) -{ - return save_wld(data); -} - -bool CFile::read_bob01() -{ - return false; -} - -bool CFile::read_bob02() -{ - // length of data block - Uint32 length; - // offset of next entry in file - Uint32 next_entry; - // endmark - to test, if a data block has correctly read - Uint8 endmark; - - // Pic-Data - // start adresses of picture lines in the file (offsets) - Uint16* starts; - // starting point for start adresses (starting_point + starts[i] = beginning of i. picture line) - Uint32 starting_point; - // number of following colored pixels in data block - Uint8 count_color; - // number of transparent pixels - Uint8 count_trans; - // color value for read pixel - Uint8 color_value; - - // coordinate for zeropoint x (2 Bytes) - freadChecked(&(bmpArray->nx), 2, 1, fp); - // coordinate for zeropoint y (2 Bytes) - freadChecked(&(bmpArray->ny), 2, 1, fp); - // skip unknown data (4x 1 Byte) - fseek(fp, 4, SEEK_CUR); - // width of picture (2 Bytes) - freadChecked(&(bmpArray->w), 2, 1, fp); - // heigth of picture (2 Bytes) - freadChecked(&(bmpArray->h), 2, 1, fp); - // skip unknown data (1x 2 Bytes) - fseek(fp, 2, SEEK_CUR); - // length of datablock (1x 4 Bytes) - freadChecked(&length, 4, 1, fp); - // fp points now ON the first start adress, so "actual position + length = first offset of next entry in the file" - starting_point = ftell(fp); - next_entry = starting_point + length; - - // if we only want to read a palette at the moment (loadPAL == 1) so skip this and set the filepointer to the next entry - if(loadPAL) - { - fseek(fp, (long int)next_entry, SEEK_SET); - return true; - } - - // array for start adresses of picture lines - if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL) - return false; - - // read start adresses - for(int y = 0; y < bmpArray->h; y++) - freadChecked(&starts[y], 2, 1, fp); - - // now we are ready to read the picture lines and fill the surface, so lets create one - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) - return false; - SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); - SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); - // SDL_SetAlpha(bmpArray->surface, SDL_SRCALPHA, 128); - - // main loop for reading picture lines - for(int y = 0; y < bmpArray->h; y++) - { - // set fp to the needed offset (where the picture line starts) - fseek(fp, starting_point + (Uint32)starts[y], SEEK_SET); - - // loop for reading pixels of the actual picture line - //(cause of a kind of RLE-Compression we cannot read the pixels sequentielly) - //'x' will be incremented WITHIN the loop - for(int x = 0; x < bmpArray->w;) - { - // number of following colored pixels (1 Byte) - freadChecked(&count_color, 1, 1, fp); - - // loop for drawing the colored pixels to the surface - for(int k = 0; k < count_color; k++, x++) - { - // read color value (1 Byte) - freadChecked(&color_value, 1, 1, fp); - // draw - CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); - } - - // number of transparent pixels to draw now (1 Byte) - freadChecked(&count_trans, 1, 1, fp); - - // loop for drawing the transparent pixels to the surface - for(int k = 0; k < count_trans; k++, x++) - { - CSurface::DrawPixel_RGBA(bmpArray->surface, x, y, 0, 0, 0, 0); - } - } - - // the end of line should be 0xFF, otherwise an error has ocurred (1 Byte) - freadChecked(&endmark, 1, 1, fp); - if(endmark != 0xFF) - return false; - } - - // at the end of the block (after the last line) there should be another 0xFF, otherwise an error has ocurred (1 Byte) - freadChecked(&endmark, 1, 1, fp); - if(endmark != 0xFF) - return false; - - // we are finished, the surface is filled - // fp should now point to the first offset of the next entry, this is the last check if this is REALLY the RIGHT position - if(ftell(fp) != (long int)next_entry) - { - fseek(fp, (long int)next_entry, SEEK_SET); - return false; - } - - // increment bmpArray for the next picture - bmpArray++; - - free(starts); - - return true; -} - -bool CFile::read_bob03() -{ - // bobtype of the entry - Uint16 bobtype; - // player color - int player_color; - // save position of the filepointer to read the character again with another color - long int offset; - - // temporary skip x- and y-spacing (2x 1 Byte) --> we will handle this later - fseek(fp, 2, SEEK_CUR); - - // read bobtype04 115 times (for 115 ansi chars) - for(int i = 1; i <= 115; i++) - { - // following data blocks are bobtype04 for some ascii chars, bobtype is repeated at the beginning of each data block - freadChecked(&bobtype, 2, 1, fp); - - // bobtype should be 04. if not, it's possible that there are a lot of zeros till the next block begins - if(bobtype != BOBTYPE04) - { - // read the zeros (2 Bytes for each zero) - while(bobtype == 0) - freadChecked(&bobtype, 2, 1, fp); - - // at the end of all the zeros --> if bobtype is STILL NOT 04, an error has occured - if(bobtype != BOBTYPE04) - return false; - } - - // now read the picture for each player color - offset = ftell(fp); - for(int i = 0; i < 7; i++) - { - switch(i) - { - case 0: player_color = PLAYER_BLUE; break; - case 1: player_color = PLAYER_RED; break; - case 2: player_color = PLAYER_ORANGE; break; - case 3: player_color = PLAYER_GREEN; break; - case 4: player_color = PLAYER_MINTGREEN; break; - case 5: player_color = PLAYER_YELLOW; break; - case 6: player_color = PLAYER_RED_BRIGHT; break; - default: player_color = PLAYER_YELLOW; break; - } - fseek(fp, offset, SEEK_SET); - if(read_bob04(player_color) == false) - return false; - } - } - - return true; -} - -bool CFile::read_bob04(int player_color) -{ - // length of data block - Uint32 length; - // offset of next entry in file - Uint32 next_entry; - - // Pic-Data - //'shift' (1 Byte) --> to decide what pixels and how many we have to draw - Uint8 shift; - // start adresses of picture lines in the file (offsets) - Uint16* starts; - // starting point for start adresses (starting_point + starts[i] = beginning of i. picture line) - Uint32 starting_point; - // color value for read pixel - Uint8 color_value; - - // coordinate for zeropoint x (2 Bytes) - freadChecked(&(bmpArray->nx), 2, 1, fp); - // coordinate for zeropoint y (2 Bytes) - freadChecked(&(bmpArray->ny), 2, 1, fp); - // skip unknown data (4x 1 Byte) - fseek(fp, 4, SEEK_CUR); - // width of picture (2 Bytes) - freadChecked(&(bmpArray->w), 2, 1, fp); - // heigth of picture (2 Bytes) - freadChecked(&(bmpArray->h), 2, 1, fp); - // skip unknown data (1x 2 Bytes) - fseek(fp, 2, SEEK_CUR); - // length of datablock (1x 4 Bytes) - freadChecked(&length, 4, 1, fp); - // fp points now ON the first start adress, so "actual position + length = first offset of next entry in the file" - starting_point = ftell(fp); - next_entry = starting_point + length; - - // if we only want to read a palette at the moment (loadPAL == 1) so skip this and set the filepointer to the next entry - if(loadPAL) - { - fseek(fp, (long int)next_entry, SEEK_SET); - return true; - } - - // array for start adresses of picture lines - if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL) - return false; - - // read start adresses - for(int y = 0; y < bmpArray->h; y++) - freadChecked(&starts[y], 2, 1, fp); - - // now we are ready to read the picture lines and fill the surface, so lets create one - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) - return false; - - SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); - SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); - - // main loop for reading picture lines - for(int y = 0; y < bmpArray->h; y++) - { - // set fp to the needed offset (where the picture line starts) - fseek(fp, starting_point + (Uint32)starts[y], SEEK_SET); - - // loop for reading pixels of the actual picture line - //(cause of a kind of RLE-Compression we cannot read the pixels sequentielly) - //'x' will be incremented WITHIN the loop - for(int x = 0; x < bmpArray->w;) - { - // read our 'shift' (1 Byte) - freadChecked(&shift, 1, 1, fp); - - if(shift < 0x41) - { - for(int i = 1; i <= shift; i++, x++) - { - CSurface::DrawPixel_RGBA(bmpArray->surface, x, y, 0, 0, 0, 0); - } - } else if(shift >= 0x41 && shift < 0x81) - { - freadChecked(&color_value, 1, 1, fp); - - for(int i = 1; i <= shift - 0x40; i++, x++) - { - CSurface::DrawPixel_Color(bmpArray->surface, x, y, /*0x80 - 0x40*/ +(Uint32)color_value); - } - } else if(shift >= 0x81 && shift < 0xC1) - { - freadChecked(&color_value, 1, 1, fp); - - for(int i = 1; i <= shift - 0x80; i++, x++) - { - CSurface::DrawPixel_Color(bmpArray->surface, x, y, player_color + (Uint32)color_value); - } - } else // if (shift > 0xC0) - { - freadChecked(&color_value, 1, 1, fp); - - for(int i = 1; i <= shift - 0xC0; i++, x++) - { - CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); - } - } - } - } - - // we are finished, the surface is filled - // fp should now point to the first offset of the next entry, this is the last check if this is REALLY the RIGHT position - if(ftell(fp) != (long int)next_entry) - { - fseek(fp, (long int)next_entry, SEEK_SET); - // return false; - } - - // increment bmpArray for the next picture - bmpArray++; - - free(starts); - - return true; -} - -bool CFile::read_bob05() -{ - // skip: unknown data (1x 2 Bytes) - fseek(fp, 2, SEEK_CUR); - - for(int i = 0; i < 256; i++) - { - freadChecked(&((palArray->colors[i]).r), 1, 1, fp); - freadChecked(&((palArray->colors[i]).g), 1, 1, fp); - freadChecked(&((palArray->colors[i]).b), 1, 1, fp); - } - - palArray++; - - return true; -} - -bool CFile::read_bob07() -{ - // length of data block - Uint32 length; - // offset of next entry in file - Uint32 next_entry; - // endmark - to test, if a data block has correctly read - Uint8 endmark; - - // Pic-Data - // start adresses of picture lines in the file (offsets) - Uint16* starts; - // starting point for start adresses (starting_point + starts[i] = beginning of i. picture line) - Uint32 starting_point; - // number of half-transparent black pixels in data block - Uint8 count_black; - // number of transparent pixels - Uint8 count_trans; - - // coordinate for zeropoint x (2 Bytes) - freadChecked(&(shadowArray->nx), 2, 1, fp); - // coordinate for zeropoint y (2 Bytes) - freadChecked(&(shadowArray->ny), 2, 1, fp); - // skip unknown data (4x 1 Byte) - fseek(fp, 4, SEEK_CUR); - // width of picture (2 Bytes) - freadChecked(&(shadowArray->w), 2, 1, fp); - // heigth of picture (2 Bytes) - freadChecked(&(shadowArray->h), 2, 1, fp); - // skip unknown data (1x 2 Bytes) - fseek(fp, 2, SEEK_CUR); - // length of datablock (1x 4 Bytes) - freadChecked(&length, 4, 1, fp); - // fp points now ON the first start adress, so "actual position + length = first offset of next entry in the file" - starting_point = ftell(fp); - next_entry = starting_point + length; - - // if we only want to read a palette at the moment (loadPAL == 1) so skip this and set the filepointer to the next entry - if(loadPAL) - { - fseek(fp, (long int)next_entry, SEEK_SET); - return true; - } - - // array for start adresses of picture lines - if((starts = (Uint16*)malloc(shadowArray->h * sizeof(Uint16))) == NULL) - return false; - - // read start adresses - for(int y = 0; y < shadowArray->h; y++) - freadChecked(&starts[y], 2, 1, fp); - - // now we are ready to read the picture lines and fill the surface, so lets create one - if((shadowArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, shadowArray->w, shadowArray->h, 8, 0, 0, 0, 0)) == NULL) - return false; - SDL_SetPalette(shadowArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); - // SDL_SetAlpha(shadowArray->surface, SDL_SRCALPHA, 128); - - // main loop for reading picture lines - for(int y = 0; y < shadowArray->h; y++) - { - // set fp to the needed offset (where the picture line starts) - fseek(fp, starting_point + (Uint32)starts[y], SEEK_SET); - - // loop for reading pixels of the actual picture line - //(cause of a kind of RLE-Compression we cannot read the pixels sequentielly) - //'x' will be incremented WITHIN the loop - for(int x = 0; x < shadowArray->w;) - { - // number of half-transparent black (alpha value = 0x40) pixels (1 Byte) - freadChecked(&count_black, 1, 1, fp); - - // loop for drawing the black pixels to the surface - for(int k = 0; k < count_black; k++, x++) - { - // draw - CSurface::DrawPixel_RGBA(shadowArray->surface, x, y, 0, 0, 0, 0x40); - } - - // number of transparent pixels to draw now (1 Byte) - freadChecked(&count_trans, 1, 1, fp); - - // loop for drawing the transparent pixels to the surface - for(int k = 0; k < count_trans; k++, x++) - { - CSurface::DrawPixel_RGBA(shadowArray->surface, x, y, 0, 0, 0, 0); - } - } - - // the end of line should be 0xFF, otherwise an error has ocurred (1 Byte) - freadChecked(&endmark, 1, 1, fp); - if(endmark != 0xFF) - return false; - } - - // at the end of the block (after the last line) there should be another 0xFF, otherwise an error has ocurred (1 Byte) - freadChecked(&endmark, 1, 1, fp); - if(endmark != 0xFF) - return false; - - // we are finished, the surface is filled - // fp should now point to the first offset of the next entry, this is the last check if this is REALLY the RIGHT position - if(ftell(fp) != (long int)next_entry) - { - fseek(fp, (long int)next_entry, SEEK_SET); - return false; - } - - /**FOLLOWING COMMENTS ARE ABSOLUTLY TEMPORARY, UNTIL I KNOW HOW TO HANDLE SHADOWS WITH ALPHA-BLENDING AND THEN BLITTING - ***---THIS CODE IS NOT USEFUL.**/ - // We have to blit picture and shadow together and because of transparency we need to set the colorkey - // SDL_SetColorKey(shadowArray->surface, SDL_SRCCOLORKEY, SDL_MapRGBA(shadowArray->surface->format, 0, 0, 0, 0)); - // SDL_BlitSurface(shadowArray->surface, NULL, (shadowArray-1)->surface, NULL); - // SDL_FreeSurface(shadowArray->surface); - // increment shadowArray - shadowArray++; - - free(starts); - - return true; -} - -bool CFile::read_bob14() -{ - // length of data block - Uint32 length; - // offset of next entry in file - long int next_entry; - - // Pic-Data - // offset for the first byte of the data block - long int data_start; - // color value for read pixel - Uint8 color_value; - - // skip unknown data (1x 2 Bytes) - fseek(fp, 2, SEEK_CUR); - // length of datablock (1x 4 Bytes) - freadChecked(&length, 4, 1, fp); - // start offset of data block - data_start = ftell(fp); - // jump to first offset after data block - fseek(fp, length, SEEK_CUR); - // coordinate for zeropoint x (2 Bytes) - freadChecked(&(bmpArray->nx), 2, 1, fp); - // coordinate for zeropoint y (2 Bytes) - freadChecked(&(bmpArray->ny), 2, 1, fp); - // width of picture (2 Bytes) - freadChecked(&(bmpArray->w), 2, 1, fp); - // heigth of picture (2 Bytes) - freadChecked(&(bmpArray->h), 2, 1, fp); - // skip unknown data (8x 1 Byte) - fseek(fp, 8, SEEK_CUR); - - // fp points now ON the first adress of the next entry in the file - next_entry = ftell(fp); - - // if we only want to read a palette at the moment (loadPAL == 1) so skip this and let fp on the adress of the next entry - if(loadPAL) - return true; - - // now we are ready to read the picture lines and fill the surface, so lets create one - if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) - return false; - SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); - - // set fp to back to the first offset of data block - fseek(fp, data_start, SEEK_SET); - - // main loop for reading picture lines - for(int y = 0; y < bmpArray->h; y++) - { - // loop for reading pixels of the actual picture line - for(int x = 0; x < bmpArray->w; x++) - { - // read color value (1 Byte) - freadChecked(&color_value, 1, 1, fp); - // draw - CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); - } - } - - // we are finished, the surface is filled - // fp should now point to nx again, so set it to the next entry in the file - fseek(fp, (long int)next_entry, SEEK_SET); - - // increment bmpArray for the next picture - bmpArray++; - - return true; -} - -inline void CFile::endian_swap(Uint16& x) -{ - x = SDL_Swap16(x); -} - -inline void CFile::endian_swap(Uint32& x) -{ - x = SDL_Swap32(x); -} +#include "CFile.h" +#include "../CSurface.h" +#include "../globals.h" +#include +#include +#include + +// Hard coded file format :( +#if SDL_BYTEORDER != SDL_LIL_ENDIAN +#error "Only little endian systems are supported" +#endif + +FILE* CFile::fp = NULL; +bobBMP* CFile::bmpArray = &global::bmpArray[0]; +bobSHADOW* CFile::shadowArray = &global::shadowArray[0]; +bobPAL* CFile::palArray = &global::palArray[0]; +bobPAL* CFile::palActual = &global::palArray[0]; +bool CFile::loadPAL = false; + +inline void freadChecked(void* buf, size_t elSize, size_t elCt, FILE* file) +{ + if(fread(buf, elSize, elCt, file) != elCt && !feof(file)) + throw std::runtime_error("Read failed"); +} + +CFile::CFile() {} + +CFile::~CFile() {} + +void* CFile::open_file(const std::string& filename, char filetype, bool only_loadPAL) +{ + void* return_value = NULL; + + if(filename.empty() || bmpArray == NULL || shadowArray == NULL || palArray == NULL || palActual == NULL) + return NULL; + + else if((fp = boost::nowide::fopen(filename.c_str(), "rb")) == NULL) + return NULL; + + if(only_loadPAL) + loadPAL = true; + + try + { + switch(filetype) + { + case LST: + if(open_lst()) + return_value = (void*)-1; + + break; + + case BOB: + if(open_bob()) + return_value = (void*)-1; + + break; + + case IDX: + if(open_idx(filename)) + return_value = (void*)-1; + + break; + + case BBM: + if(open_bbm()) + return_value = (void*)-1; + + break; + + case LBM: + if(open_lbm(filename)) + return_value = (void*)-1; + + break; + + case GOU: + if(open_gou()) + return_value = (void*)-1; + + break; + + case WLD: return_value = open_wld(); break; + + case SWD: return_value = open_swd(); break; + + default: // no valid data type + break; + } + } catch(const std::exception& e) + { + std::cerr << "Error while reading " << filename << ": " << e.what() << std::endl; + } + + if(fp != NULL) + { + fclose(fp); + fp = NULL; + } + + loadPAL = false; + + return return_value; +} + +bool CFile::open_lst() +{ + // type of entry (used or unused entry) + Uint16 entrytype; + // bobtype of the entry + Uint16 bobtype; + + // skip: id (2x 1 Bytes) + count (1x 4 Bytes) = 6 Bytes + fseek(fp, 6, SEEK_SET); + + // main loop for reading entrys + while(!feof(fp)) + { + // entry type (2 Bytes) - unused (=0x0000) or used (=0x0001) - + freadChecked(&entrytype, 2, 1, fp); + + // if entry is unused, go back to 'while' --- and by the way: after the last entry there are always zeros in the file, + // so the following case will happen till we have reached the end of the file and the 'while' will break - PERFECT! + if(entrytype == 0x0000) + continue; + + // bobtype (2 Bytes) + freadChecked(&bobtype, 2, 1, fp); + + switch(bobtype) + { + case BOBTYPE01: + if(read_bob01() == false) + return false; + break; + + case BOBTYPE02: + if(read_bob02() == false) + return false; + break; + + case BOBTYPE03: + if(read_bob03() == false) + return false; + break; + + case BOBTYPE04: + if(read_bob04(PLAYER_BLUE) == false) + return false; + break; + + case BOBTYPE05: + if(read_bob05() == false) + return false; + break; + + case BOBTYPE07: + if(read_bob07() == false) + return false; + break; + + case BOBTYPE14: + if(read_bob14() == false) + return false; + break; + + default: // Something is wrong? Maybe the last entry was really the LAST, so we should not return false + break; + } + } + + return true; +} + +bool CFile::open_bob() +{ + return false; +} + +bool CFile::open_idx(const std::string& filename) +{ + // temporary filepointer to save global fp until this function has finished + FILE* fp_tmp; + // pointer to '******.IDX'-File (cause we have to change the global pointer to point to the '.DAT'-File) + FILE* fp_idx; + // pointer to corresponding '******.DAT'-File + FILE* fp_dat; + // array index for the first letter of the file ending ( the 'I' in 'IDX' ) to overwrite IDX with DAT + unsigned fileending; + // starting adress of data in the corresponding '******.DAT'-File + Uint32 offset; + // bobtype of the entry + Uint16 bobtype; + // bobtype is repeated in the corresponging '******.DAT'-File, so we have to check this is correct + Uint16 bobtype_check; + + // save global filepointer + fp_tmp = fp; + // get a new filepointer to the '.IDX'-File + if((fp_idx = boost::nowide::fopen(filename.c_str(), "rb")) == NULL) + return false; + // following code will open the corresponding '******.DAT'-File + // allocate memory for new name + std::string filename_dat = filename; + // if strlen = n, so array walks von 0 to n-1. n-1 is the last letter of the file ending ( the 'X' in 'IDX' ), so we have to walk back + // one time to be at the last letter and then two times to be at the 'I' = walk back 3 times + fileending = static_cast(filename.size() - 3); + // now overwrite 'IDX' with 'DAT' + filename_dat[fileending] = 'D'; + filename_dat[fileending + 1] = 'A'; + filename_dat[fileending + 2] = 'T'; + // get the filepointer of the corresponging '******.DAT'-File + if((fp_dat = boost::nowide::fopen(filename_dat.c_str(), "rb")) == NULL) + return false; + // we are finished opening the 'DAT'-File, now we can handle the content + + // skip: unknown data (1x 4 Bytes) at the beginning of the file + fseek(fp_idx, 4, SEEK_SET); + + // main loop for reading entrys + while(!feof(fp_idx) && !feof(fp_dat)) + { + // skip: name (1x 16 Bytes) + fseek(fp_idx, 16, SEEK_CUR); + // offset (4 Bytes) + freadChecked(&offset, 4, 1, fp_idx); + // skip unknown data (6x 1 Byte) + fseek(fp_idx, 6, SEEK_CUR); + // bobtype (2 Bytes) + freadChecked(&bobtype, 2, 1, fp_idx); + // set fp_dat to the position in 'offset' + fseek(fp_dat, offset, SEEK_SET); + // read bobtype again, now from 'DAT'-File + freadChecked(&bobtype_check, 2, 1, fp_dat); + // check if data in 'DAT'-File is the data that it should be (bobtypes are equal) + if(bobtype != bobtype_check) + return false; + + // set up the global filepointer fp to fp_dat, so the following functions will read from the '.DAT'-File + fp = fp_dat; + + switch(bobtype) + { + case BOBTYPE01: + if(read_bob01() == false) + return false; + break; + + case BOBTYPE02: + if(read_bob02() == false) + return false; + break; + + case BOBTYPE03: + if(read_bob03() == false) + return false; + break; + + case BOBTYPE04: + if(read_bob04() == false) + return false; + break; + + case BOBTYPE05: + if(read_bob05() == false) + return false; + break; + + case BOBTYPE07: + if(read_bob07() == false) + return false; + break; + + case BOBTYPE14: + if(read_bob14() == false) + return false; + break; + + default: // Something is wrong? Maybe the last entry was really the LAST, so we should not return false + break; + } + + // set up the local filepointer fp_dat to fp for the next while loop + fp_dat = fp; + } + + // reset global filepointer to its original value + fp = fp_tmp; + + fclose(fp_idx); + fclose(fp_dat); + + return true; +} + +bool CFile::open_bbm() +{ + // skip header (48 Bytes) + fseek(fp, 48, SEEK_CUR); + + for(int i = 0; i < 256; i++) + { + freadChecked(&((palArray->colors[i]).r), 1, 1, fp); + freadChecked(&((palArray->colors[i]).g), 1, 1, fp); + freadChecked(&((palArray->colors[i]).b), 1, 1, fp); + } + + palArray++; + + return true; +} + +bool CFile::open_lbm(const std::string& filename) +{ + // IMPORTANT NOTE: LBM (also ILBM) is the Interchange File Format (IFF) and the 4-byte-blocks are originally organized as Big Endian, so + // a convertion is needed + + // identifier for the kind of data follows (FORM, BMHD, CMAP, BODY) + char chunk_identifier[5]; + + // length of data block + Uint32 length; + // color depth of the picture + Uint16 color_depth; + // is the picture rle-compressed? + Uint16 compression_flag; + // compression type + Sint8 ctype; + // array for palette colors + SDL_Color colors[256]; + // color value for read pixel + Uint8 color_value; + + // skip File-Identifier "FORM" (1x 4 Bytes) + unknown data (4x 1 Byte) + Header-Identifier "PBM " (1x 4 Bytes) = 12 Bytes + fseek(fp, 12, SEEK_CUR); + + /* READ FIRST CHUNK "BMHD" */ + + // chunk-identifier (4 Bytes) + freadChecked(chunk_identifier, 4, 1, fp); + chunk_identifier[4] = '\0'; + // should be "BMHD" at this time + if(strcmp(chunk_identifier, "BMHD") != 0) + return false; + // length of data block + freadChecked(&length, 4, 1, fp); + endian_swap(length); + // width of picture (2 Bytes) + freadChecked(&(bmpArray->w), 2, 1, fp); + endian_swap(bmpArray->w); + // heigth of picture (2 Bytes) + freadChecked(&(bmpArray->h), 2, 1, fp); + endian_swap(bmpArray->h); + // skip unknown data (4x 1 Bytes) + fseek(fp, 4, SEEK_CUR); + // color depth of the picture (1x 2 Bytes) + freadChecked(&color_depth, 2, 1, fp); + // compression_flag (1x 2 Bytes) + freadChecked(&compression_flag, 2, 1, fp); + // skip unknown data (length - 20 x 1 Byte) + // fseek(fp, length-20, SEEK_CUR); + + /* READ SECOND CHUNK "CMAP" */ + + // chunk-identifier (4 Bytes) + // search for the "CMAP" and skip other chunk-types + while(!feof(fp)) + { + freadChecked(chunk_identifier, 4, 1, fp); + + if(strcmp(chunk_identifier, "CMAP") == 0) + break; + else + fseek(fp, -3, SEEK_CUR); + } + if(feof(fp)) + return false; + // length of data block + freadChecked(&length, 4, 1, fp); + endian_swap(length); + // must be 768 (RGB = 3 Byte x 256 Colors) + if(length != 768) + return false; + // palette + for(int i = 0; i < 256; i++) + { + freadChecked(&colors[i].r, 1, 1, fp); + freadChecked(&colors[i].g, 1, 1, fp); + freadChecked(&colors[i].b, 1, 1, fp); + } + + /* READ THIRD CHUNK "BODY" */ + + // chunk-identifier (4 Bytes) + // search for the "BODY" and skip other chunk-types + while(!feof(fp)) + { + freadChecked(chunk_identifier, 4, 1, fp); + + if(strcmp(chunk_identifier, "BODY") == 0) + break; + else + fseek(fp, -3, SEEK_CUR); + } + if(feof(fp)) + return false; + // length of data block + freadChecked(&length, 4, 1, fp); + endian_swap(length); + + // now we are ready to read the picture lines and fill the surface, so lets create one + if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) + return false; + SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, colors, 0, 256); + + if(compression_flag == 0) + { + // picture uncompressed + // main loop for reading picture lines + for(int y = 0; y < bmpArray->h; y++) + { + // loop for reading pixels of the actual picture line + for(int x = 0; x < bmpArray->w; x++) + { + // read color value (1 Byte) + freadChecked(&color_value, 1, 1, fp); + // draw + CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); + } + } + + } else if(compression_flag == 1) + { + // picture compressed + + // main loop for reading picture lines + for(int y = 0; y < bmpArray->h; y++) + { + // loop for reading pixels of the actual picture line + //(cause of a kind of RLE-Compression we cannot read the pixels sequentially) + //'x' will be incremented WITHIN the loop + for(int x = 0; x < bmpArray->w;) + { + // read compression type + freadChecked(&ctype, 1, 1, fp); + + if(ctype >= 0) + { + // following 'ctype + 1' pixels are uncompressed + for(int k = 0; k < ctype + 1; k++, x++) + { + // read color value (1 Byte) + freadChecked(&color_value, 1, 1, fp); + // draw + CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); + } + } else if(ctype < 0 && ctype >= -127) + { + // draw the following byte '-ctype + 1' times to the surface + freadChecked(&color_value, 1, 1, fp); + + for(int k = 0; k < -ctype + 1; k++, x++) + CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); + } else // if (ctype == -128) + { + // ignore + } + } + } + } else + return false; + + // if this is a texture file, we need a secondary 32-bit surface for SGE and we set a color key at both surfaces + if(filename.find("TEX5.LBM") != std::string::npos || filename.find("TEX6.LBM") != std::string::npos + || filename.find("TEX7.LBM") != std::string::npos || filename.find("TEXTUR_0.LBM") != std::string::npos + || filename.find("TEXTUR_3.LBM") != std::string::npos) + { + SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); + + bmpArray++; + if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, (bmpArray - 1)->w, (bmpArray - 1)->h, 32, 0, 0, 0, 0)) != NULL) + { + SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); + CSurface::Draw(bmpArray->surface, (bmpArray - 1)->surface, 0, 0); + } else + bmpArray--; + } + + // we are finished, the surface is filled + // increment bmpArray for the next picture + bmpArray++; + + return true; +} + +bool CFile::open_gou() +{ + static int internalArrayCtr = 0; // maximum is two cause there are only 3 GOUx.DAT-Files + + if(internalArrayCtr > 2) + return false; + + freadChecked(gouData[internalArrayCtr], 256, 256, fp); + internalArrayCtr++; + + return true; +} + +bobMAP* CFile::open_wld() +{ + bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP)); + Uint8 heightFactor; + + if(myMap == NULL) + return myMap; + + // initialize myMap->name and myMap->author (both 20 chars) to prevent filling with random memory content + for(int i = 0; i < 20; i++) + { + myMap->name[i] = '\0'; + myMap->author[i] = '\0'; + } + + fseek(fp, 10, SEEK_SET); + freadChecked(myMap->name, 20, 1, fp); + freadChecked(&myMap->width_old, 2, 1, fp); + freadChecked(&myMap->height_old, 2, 1, fp); + freadChecked(&myMap->type, 1, 1, fp); + freadChecked(&myMap->player, 1, 1, fp); + freadChecked(myMap->author, 20, 1, fp); + freadChecked(myMap->HQx, 2, 7, fp); + freadChecked(myMap->HQy, 2, 7, fp); + + // go to big map header and read it + fseek(fp, 92, SEEK_SET); + for(int i = 0; i < 250; i++) + { + freadChecked(&myMap->header[i].type, 1, 1, fp); + freadChecked(&myMap->header[i].x, 1, 2, fp); + freadChecked(&myMap->header[i].y, 1, 2, fp); + freadChecked(&myMap->header[i].area, 1, 4, fp); + } + + // go to real map height and width + fseek(fp, 2348, SEEK_SET); + freadChecked(&myMap->width, 2, 1, fp); + myMap->width_pixel = myMap->width * TRIANGLE_WIDTH; + freadChecked(&myMap->height, 2, 1, fp); + myMap->height_pixel = myMap->height * TRIANGLE_HEIGHT; + + if((myMap->vertex = (struct point*)malloc(sizeof(struct point) * myMap->width * myMap->height)) == NULL) + { + free(myMap); + return NULL; + } + + // go to altitude information (we skip the 16 bytes long map data header that each block has) + fseek(fp, 16, SEEK_CUR); + + long int a; + long int b = 0; + for(int j = 0; j < myMap->height; j++) + { + if(j % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int i = 0; i < myMap->width; i++) + { + myMap->vertex[j * myMap->width + i].VertexX = i; + myMap->vertex[j * myMap->width + i].VertexY = j; + freadChecked(&heightFactor, 1, 1, fp); + myMap->vertex[j * myMap->width + i].h = heightFactor; + myMap->vertex[j * myMap->width + i].x = a; + myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); + myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); + // TEMPORARY: to prevent drawing point outside the surface (negative points) + // if (myMap->vertex[j*myMap->width+i].y < 0) + // myMap->vertex[j*myMap->width+i].y = 0; + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } + + // go to texture information for RightSideUp-Triangles + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].rsuTexture, 1, 1, fp); + } + + // go to texture information for UpSideDown-Triangles + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].usdTexture, 1, 1, fp); + } + + // go to road data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].road, 1, 1, fp); + } + + // go to object type data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].objectType, 1, 1, fp); + } + + // go to object info data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].objectInfo, 1, 1, fp); + } + + // go to animal data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].animal, 1, 1, fp); + } + + // go to unknown1 data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].unknown1, 1, 1, fp); + } + + // go to build data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].build, 1, 1, fp); + } + + // go to unknown2 data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].unknown2, 1, 1, fp); + } + + // go to unknown3 data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].unknown3, 1, 1, fp); + } + + // go to resource data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].resource, 1, 1, fp); + } + + // go to shading data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].shading, 1, 1, fp); + } + + // go to unknown5 data + fseek(fp, 16, SEEK_CUR); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + freadChecked(&myMap->vertex[j * myMap->width + i].unknown5, 1, 1, fp); + } + + return myMap; +} + +bobMAP* CFile::open_swd() +{ + return open_wld(); +} + +bool CFile::save_file(const std::string& filename, char filetype, void* data) +{ + bool return_value = false; + + if(filename.empty() || data == NULL) + return return_value; + + if((fp = boost::nowide::fopen(filename.c_str(), "wb")) == NULL) + return return_value; + + switch(filetype) + { + case LST: return_value = save_lst(data); break; + + case BOB: return_value = save_bob(data); break; + + case IDX: return_value = save_idx(data, filename); break; + + case BBM: return_value = save_bbm(data); break; + + case LBM: return_value = save_lbm(data); break; + + case WLD: return_value = save_wld(data); break; + + case SWD: return_value = save_swd(data); break; + + default: // no valid data type + return_value = false; + break; + } + + if(fp != NULL) + { + fclose(fp); + fp = NULL; + } + + return return_value; +} + +bool CFile::save_lst(void* data) +{ + return false; +} + +bool CFile::save_bob(void* data) +{ + return false; +} + +bool CFile::save_idx(void* data, const std::string& filename) +{ + return false; +} + +bool CFile::save_bbm(void* data) +{ + return false; +} + +bool CFile::save_lbm(void* data) +{ + return false; +} + +bool CFile::save_wld(void* data) +{ + char zero = 0; // to fill bytes + char temp = 0; // to fill bytes + bobMAP* myMap = (bobMAP*)data; + char map_version[11] = "WORLD_V1.0"; + char map_data_header[16]; + + // prepare map data header + map_data_header[0] = 0x10; + map_data_header[1] = 0x27; + map_data_header[2] = 0x00; + map_data_header[3] = 0x00; + map_data_header[4] = 0x00; + map_data_header[5] = 0x00; + *((Uint16*)(map_data_header + 6)) = myMap->width; + *((Uint16*)(map_data_header + 8)) = myMap->height; + map_data_header[10] = 0x01; + map_data_header[11] = 0x00; + *((Uint32*)(map_data_header + 12)) = myMap->width * myMap->height; + + // begin writing data to file + // first of all the map header + // WORLD_V1.0 + fwrite(map_version, 1, 10, fp); + // name + fwrite(myMap->name, 1, 20, fp); + // old width + fwrite(&myMap->width_old, 2, 1, fp); + // old height + fwrite(&myMap->height_old, 2, 1, fp); + // type + fwrite(&myMap->type, 1, 1, fp); + // players + fwrite(&myMap->player, 1, 1, fp); + // author + fwrite(myMap->author, 1, 20, fp); + // headquarters x + fwrite(myMap->HQx, 2, 7, fp); + // headquarters y + fwrite(myMap->HQy, 2, 7, fp); + // unknown data (8 Bytes) + for(int i = 0; i < 8; i++) + fwrite(&zero, 1, 1, fp); + // big map header with area information + for(int i = 0; i < 250; i++) + { + fwrite(&myMap->header[i].type, 1, 1, fp); + fwrite(&myMap->header[i].x, 1, 2, fp); + fwrite(&myMap->header[i].y, 1, 2, fp); + fwrite(&myMap->header[i].area, 1, 4, fp); + } + // 0x11 0x27 + temp = 0x11; + fwrite(&temp, 1, 1, fp); + temp = 0x27; + fwrite(&temp, 1, 1, fp); + // unknown data (always null, 4 Bytes) + for(int i = 0; i < 4; i++) + fwrite(&zero, 1, 1, fp); + // width + fwrite(&myMap->width, 2, 1, fp); + // height + fwrite(&myMap->height, 2, 1, fp); + + // now begin writing the real map data + + // altitude information + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + { + temp = myMap->vertex[j * myMap->width + i].z / 5 + 0x0A; + fwrite(&temp, 1, 1, fp); + } + } + + // texture information for RightSideUp-Triangles + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].rsuTexture, 1, 1, fp); + } + + // go to texture information for UpSideDown-Triangles + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].usdTexture, 1, 1, fp); + } + + // go to road data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].road, 1, 1, fp); + } + + // go to object type data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].objectType, 1, 1, fp); + } + + // go to object info data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].objectInfo, 1, 1, fp); + } + + // go to animal data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].animal, 1, 1, fp); + } + + // go to unknown1 data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].unknown1, 1, 1, fp); + } + + // go to build data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].build, 1, 1, fp); + } + + // go to unknown2 data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].unknown2, 1, 1, fp); + } + + // go to unknown3 data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].unknown3, 1, 1, fp); + } + + // go to resource data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].resource, 1, 1, fp); + } + + // go to shading data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].shading, 1, 1, fp); + } + + // go to unknown5 data + fwrite(&map_data_header, 16, 1, fp); + + for(int j = 0; j < myMap->height; j++) + { + for(int i = 0; i < myMap->width; i++) + fwrite(&myMap->vertex[j * myMap->width + i].unknown5, 1, 1, fp); + } + + // at least write the map footer (ends in 0xFF) + temp = char(0xFF); + fwrite(&temp, 1, 1, fp); + + return true; +} + +bool CFile::save_swd(void* data) +{ + return save_wld(data); +} + +bool CFile::read_bob01() +{ + return false; +} + +bool CFile::read_bob02() +{ + // length of data block + Uint32 length; + // offset of next entry in file + Uint32 next_entry; + // endmark - to test, if a data block has correctly read + Uint8 endmark; + + // Pic-Data + // start adresses of picture lines in the file (offsets) + Uint16* starts; + // starting point for start adresses (starting_point + starts[i] = beginning of i. picture line) + Uint32 starting_point; + // number of following colored pixels in data block + Uint8 count_color; + // number of transparent pixels + Uint8 count_trans; + // color value for read pixel + Uint8 color_value; + + // coordinate for zeropoint x (2 Bytes) + freadChecked(&(bmpArray->nx), 2, 1, fp); + // coordinate for zeropoint y (2 Bytes) + freadChecked(&(bmpArray->ny), 2, 1, fp); + // skip unknown data (4x 1 Byte) + fseek(fp, 4, SEEK_CUR); + // width of picture (2 Bytes) + freadChecked(&(bmpArray->w), 2, 1, fp); + // heigth of picture (2 Bytes) + freadChecked(&(bmpArray->h), 2, 1, fp); + // skip unknown data (1x 2 Bytes) + fseek(fp, 2, SEEK_CUR); + // length of datablock (1x 4 Bytes) + freadChecked(&length, 4, 1, fp); + // fp points now ON the first start adress, so "actual position + length = first offset of next entry in the file" + starting_point = ftell(fp); + next_entry = starting_point + length; + + // if we only want to read a palette at the moment (loadPAL == 1) so skip this and set the filepointer to the next entry + if(loadPAL) + { + fseek(fp, (long int)next_entry, SEEK_SET); + return true; + } + + // array for start adresses of picture lines + if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL) + return false; + + // read start adresses + for(int y = 0; y < bmpArray->h; y++) + freadChecked(&starts[y], 2, 1, fp); + + // now we are ready to read the picture lines and fill the surface, so lets create one + if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) + return false; + SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); + SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); + // SDL_SetAlpha(bmpArray->surface, SDL_SRCALPHA, 128); + + // main loop for reading picture lines + for(int y = 0; y < bmpArray->h; y++) + { + // set fp to the needed offset (where the picture line starts) + fseek(fp, starting_point + (Uint32)starts[y], SEEK_SET); + + // loop for reading pixels of the actual picture line + //(cause of a kind of RLE-Compression we cannot read the pixels sequentielly) + //'x' will be incremented WITHIN the loop + for(int x = 0; x < bmpArray->w;) + { + // number of following colored pixels (1 Byte) + freadChecked(&count_color, 1, 1, fp); + + // loop for drawing the colored pixels to the surface + for(int k = 0; k < count_color; k++, x++) + { + // read color value (1 Byte) + freadChecked(&color_value, 1, 1, fp); + // draw + CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); + } + + // number of transparent pixels to draw now (1 Byte) + freadChecked(&count_trans, 1, 1, fp); + + // loop for drawing the transparent pixels to the surface + for(int k = 0; k < count_trans; k++, x++) + { + CSurface::DrawPixel_RGBA(bmpArray->surface, x, y, 0, 0, 0, 0); + } + } + + // the end of line should be 0xFF, otherwise an error has ocurred (1 Byte) + freadChecked(&endmark, 1, 1, fp); + if(endmark != 0xFF) + return false; + } + + // at the end of the block (after the last line) there should be another 0xFF, otherwise an error has ocurred (1 Byte) + freadChecked(&endmark, 1, 1, fp); + if(endmark != 0xFF) + return false; + + // we are finished, the surface is filled + // fp should now point to the first offset of the next entry, this is the last check if this is REALLY the RIGHT position + if(ftell(fp) != (long int)next_entry) + { + fseek(fp, (long int)next_entry, SEEK_SET); + return false; + } + + // increment bmpArray for the next picture + bmpArray++; + + free(starts); + + return true; +} + +bool CFile::read_bob03() +{ + // bobtype of the entry + Uint16 bobtype; + // player color + int player_color; + // save position of the filepointer to read the character again with another color + long int offset; + + // temporary skip x- and y-spacing (2x 1 Byte) --> we will handle this later + fseek(fp, 2, SEEK_CUR); + + // read bobtype04 115 times (for 115 ansi chars) + for(int i = 1; i <= 115; i++) + { + // following data blocks are bobtype04 for some ascii chars, bobtype is repeated at the beginning of each data block + freadChecked(&bobtype, 2, 1, fp); + + // bobtype should be 04. if not, it's possible that there are a lot of zeros till the next block begins + if(bobtype != BOBTYPE04) + { + // read the zeros (2 Bytes for each zero) + while(bobtype == 0) + freadChecked(&bobtype, 2, 1, fp); + + // at the end of all the zeros --> if bobtype is STILL NOT 04, an error has occured + if(bobtype != BOBTYPE04) + return false; + } + + // now read the picture for each player color + offset = ftell(fp); + for(int i = 0; i < 7; i++) + { + switch(i) + { + case 0: player_color = PLAYER_BLUE; break; + case 1: player_color = PLAYER_RED; break; + case 2: player_color = PLAYER_ORANGE; break; + case 3: player_color = PLAYER_GREEN; break; + case 4: player_color = PLAYER_MINTGREEN; break; + case 5: player_color = PLAYER_YELLOW; break; + case 6: player_color = PLAYER_RED_BRIGHT; break; + default: player_color = PLAYER_YELLOW; break; + } + fseek(fp, offset, SEEK_SET); + if(read_bob04(player_color) == false) + return false; + } + } + + return true; +} + +bool CFile::read_bob04(int player_color) +{ + // length of data block + Uint32 length; + // offset of next entry in file + Uint32 next_entry; + + // Pic-Data + //'shift' (1 Byte) --> to decide what pixels and how many we have to draw + Uint8 shift; + // start adresses of picture lines in the file (offsets) + Uint16* starts; + // starting point for start adresses (starting_point + starts[i] = beginning of i. picture line) + Uint32 starting_point; + // color value for read pixel + Uint8 color_value; + + // coordinate for zeropoint x (2 Bytes) + freadChecked(&(bmpArray->nx), 2, 1, fp); + // coordinate for zeropoint y (2 Bytes) + freadChecked(&(bmpArray->ny), 2, 1, fp); + // skip unknown data (4x 1 Byte) + fseek(fp, 4, SEEK_CUR); + // width of picture (2 Bytes) + freadChecked(&(bmpArray->w), 2, 1, fp); + // heigth of picture (2 Bytes) + freadChecked(&(bmpArray->h), 2, 1, fp); + // skip unknown data (1x 2 Bytes) + fseek(fp, 2, SEEK_CUR); + // length of datablock (1x 4 Bytes) + freadChecked(&length, 4, 1, fp); + // fp points now ON the first start adress, so "actual position + length = first offset of next entry in the file" + starting_point = ftell(fp); + next_entry = starting_point + length; + + // if we only want to read a palette at the moment (loadPAL == 1) so skip this and set the filepointer to the next entry + if(loadPAL) + { + fseek(fp, (long int)next_entry, SEEK_SET); + return true; + } + + // array for start adresses of picture lines + if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL) + return false; + + // read start adresses + for(int y = 0; y < bmpArray->h; y++) + freadChecked(&starts[y], 2, 1, fp); + + // now we are ready to read the picture lines and fill the surface, so lets create one + if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) + return false; + + SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); + SDL_SetColorKey(bmpArray->surface, SDL_SRCCOLORKEY, SDL_MapRGB(bmpArray->surface->format, 0, 0, 0)); + + // main loop for reading picture lines + for(int y = 0; y < bmpArray->h; y++) + { + // set fp to the needed offset (where the picture line starts) + fseek(fp, starting_point + (Uint32)starts[y], SEEK_SET); + + // loop for reading pixels of the actual picture line + //(cause of a kind of RLE-Compression we cannot read the pixels sequentielly) + //'x' will be incremented WITHIN the loop + for(int x = 0; x < bmpArray->w;) + { + // read our 'shift' (1 Byte) + freadChecked(&shift, 1, 1, fp); + + if(shift < 0x41) + { + for(int i = 1; i <= shift; i++, x++) + { + CSurface::DrawPixel_RGBA(bmpArray->surface, x, y, 0, 0, 0, 0); + } + } else if(shift >= 0x41 && shift < 0x81) + { + freadChecked(&color_value, 1, 1, fp); + + for(int i = 1; i <= shift - 0x40; i++, x++) + { + CSurface::DrawPixel_Color(bmpArray->surface, x, y, /*0x80 - 0x40*/ +(Uint32)color_value); + } + } else if(shift >= 0x81 && shift < 0xC1) + { + freadChecked(&color_value, 1, 1, fp); + + for(int i = 1; i <= shift - 0x80; i++, x++) + { + CSurface::DrawPixel_Color(bmpArray->surface, x, y, player_color + (Uint32)color_value); + } + } else // if (shift > 0xC0) + { + freadChecked(&color_value, 1, 1, fp); + + for(int i = 1; i <= shift - 0xC0; i++, x++) + { + CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); + } + } + } + } + + // we are finished, the surface is filled + // fp should now point to the first offset of the next entry, this is the last check if this is REALLY the RIGHT position + if(ftell(fp) != (long int)next_entry) + { + fseek(fp, (long int)next_entry, SEEK_SET); + // return false; + } + + // increment bmpArray for the next picture + bmpArray++; + + free(starts); + + return true; +} + +bool CFile::read_bob05() +{ + // skip: unknown data (1x 2 Bytes) + fseek(fp, 2, SEEK_CUR); + + for(int i = 0; i < 256; i++) + { + freadChecked(&((palArray->colors[i]).r), 1, 1, fp); + freadChecked(&((palArray->colors[i]).g), 1, 1, fp); + freadChecked(&((palArray->colors[i]).b), 1, 1, fp); + } + + palArray++; + + return true; +} + +bool CFile::read_bob07() +{ + // length of data block + Uint32 length; + // offset of next entry in file + Uint32 next_entry; + // endmark - to test, if a data block has correctly read + Uint8 endmark; + + // Pic-Data + // start adresses of picture lines in the file (offsets) + Uint16* starts; + // starting point for start adresses (starting_point + starts[i] = beginning of i. picture line) + Uint32 starting_point; + // number of half-transparent black pixels in data block + Uint8 count_black; + // number of transparent pixels + Uint8 count_trans; + + // coordinate for zeropoint x (2 Bytes) + freadChecked(&(shadowArray->nx), 2, 1, fp); + // coordinate for zeropoint y (2 Bytes) + freadChecked(&(shadowArray->ny), 2, 1, fp); + // skip unknown data (4x 1 Byte) + fseek(fp, 4, SEEK_CUR); + // width of picture (2 Bytes) + freadChecked(&(shadowArray->w), 2, 1, fp); + // heigth of picture (2 Bytes) + freadChecked(&(shadowArray->h), 2, 1, fp); + // skip unknown data (1x 2 Bytes) + fseek(fp, 2, SEEK_CUR); + // length of datablock (1x 4 Bytes) + freadChecked(&length, 4, 1, fp); + // fp points now ON the first start adress, so "actual position + length = first offset of next entry in the file" + starting_point = ftell(fp); + next_entry = starting_point + length; + + // if we only want to read a palette at the moment (loadPAL == 1) so skip this and set the filepointer to the next entry + if(loadPAL) + { + fseek(fp, (long int)next_entry, SEEK_SET); + return true; + } + + // array for start adresses of picture lines + if((starts = (Uint16*)malloc(shadowArray->h * sizeof(Uint16))) == NULL) + return false; + + // read start adresses + for(int y = 0; y < shadowArray->h; y++) + freadChecked(&starts[y], 2, 1, fp); + + // now we are ready to read the picture lines and fill the surface, so lets create one + if((shadowArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, shadowArray->w, shadowArray->h, 8, 0, 0, 0, 0)) == NULL) + return false; + SDL_SetPalette(shadowArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); + // SDL_SetAlpha(shadowArray->surface, SDL_SRCALPHA, 128); + + // main loop for reading picture lines + for(int y = 0; y < shadowArray->h; y++) + { + // set fp to the needed offset (where the picture line starts) + fseek(fp, starting_point + (Uint32)starts[y], SEEK_SET); + + // loop for reading pixels of the actual picture line + //(cause of a kind of RLE-Compression we cannot read the pixels sequentielly) + //'x' will be incremented WITHIN the loop + for(int x = 0; x < shadowArray->w;) + { + // number of half-transparent black (alpha value = 0x40) pixels (1 Byte) + freadChecked(&count_black, 1, 1, fp); + + // loop for drawing the black pixels to the surface + for(int k = 0; k < count_black; k++, x++) + { + // draw + CSurface::DrawPixel_RGBA(shadowArray->surface, x, y, 0, 0, 0, 0x40); + } + + // number of transparent pixels to draw now (1 Byte) + freadChecked(&count_trans, 1, 1, fp); + + // loop for drawing the transparent pixels to the surface + for(int k = 0; k < count_trans; k++, x++) + { + CSurface::DrawPixel_RGBA(shadowArray->surface, x, y, 0, 0, 0, 0); + } + } + + // the end of line should be 0xFF, otherwise an error has ocurred (1 Byte) + freadChecked(&endmark, 1, 1, fp); + if(endmark != 0xFF) + return false; + } + + // at the end of the block (after the last line) there should be another 0xFF, otherwise an error has ocurred (1 Byte) + freadChecked(&endmark, 1, 1, fp); + if(endmark != 0xFF) + return false; + + // we are finished, the surface is filled + // fp should now point to the first offset of the next entry, this is the last check if this is REALLY the RIGHT position + if(ftell(fp) != (long int)next_entry) + { + fseek(fp, (long int)next_entry, SEEK_SET); + return false; + } + + /**FOLLOWING COMMENTS ARE ABSOLUTLY TEMPORARY, UNTIL I KNOW HOW TO HANDLE SHADOWS WITH ALPHA-BLENDING AND THEN BLITTING + ***---THIS CODE IS NOT USEFUL.**/ + // We have to blit picture and shadow together and because of transparency we need to set the colorkey + // SDL_SetColorKey(shadowArray->surface, SDL_SRCCOLORKEY, SDL_MapRGBA(shadowArray->surface->format, 0, 0, 0, 0)); + // SDL_BlitSurface(shadowArray->surface, NULL, (shadowArray-1)->surface, NULL); + // SDL_FreeSurface(shadowArray->surface); + // increment shadowArray + shadowArray++; + + free(starts); + + return true; +} + +bool CFile::read_bob14() +{ + // length of data block + Uint32 length; + // offset of next entry in file + long int next_entry; + + // Pic-Data + // offset for the first byte of the data block + long int data_start; + // color value for read pixel + Uint8 color_value; + + // skip unknown data (1x 2 Bytes) + fseek(fp, 2, SEEK_CUR); + // length of datablock (1x 4 Bytes) + freadChecked(&length, 4, 1, fp); + // start offset of data block + data_start = ftell(fp); + // jump to first offset after data block + fseek(fp, length, SEEK_CUR); + // coordinate for zeropoint x (2 Bytes) + freadChecked(&(bmpArray->nx), 2, 1, fp); + // coordinate for zeropoint y (2 Bytes) + freadChecked(&(bmpArray->ny), 2, 1, fp); + // width of picture (2 Bytes) + freadChecked(&(bmpArray->w), 2, 1, fp); + // heigth of picture (2 Bytes) + freadChecked(&(bmpArray->h), 2, 1, fp); + // skip unknown data (8x 1 Byte) + fseek(fp, 8, SEEK_CUR); + + // fp points now ON the first adress of the next entry in the file + next_entry = ftell(fp); + + // if we only want to read a palette at the moment (loadPAL == 1) so skip this and let fp on the adress of the next entry + if(loadPAL) + return true; + + // now we are ready to read the picture lines and fill the surface, so lets create one + if((bmpArray->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, bmpArray->w, bmpArray->h, 8, 0, 0, 0, 0)) == NULL) + return false; + SDL_SetPalette(bmpArray->surface, SDL_LOGPAL, palActual->colors, 0, 256); + + // set fp to back to the first offset of data block + fseek(fp, data_start, SEEK_SET); + + // main loop for reading picture lines + for(int y = 0; y < bmpArray->h; y++) + { + // loop for reading pixels of the actual picture line + for(int x = 0; x < bmpArray->w; x++) + { + // read color value (1 Byte) + freadChecked(&color_value, 1, 1, fp); + // draw + CSurface::DrawPixel_Color(bmpArray->surface, x, y, (Uint32)color_value); + } + } + + // we are finished, the surface is filled + // fp should now point to nx again, so set it to the next entry in the file + fseek(fp, (long int)next_entry, SEEK_SET); + + // increment bmpArray for the next picture + bmpArray++; + + return true; +} + +inline void CFile::endian_swap(Uint16& x) +{ + x = SDL_Swap16(x); +} + +inline void CFile::endian_swap(Uint32& x) +{ + x = SDL_Swap32(x); +} diff --git a/CIO/CFile.h b/CIO/CFile.h index d4b4198..5a1e380 100644 --- a/CIO/CFile.h +++ b/CIO/CFile.h @@ -1,60 +1,60 @@ -// handling of the files and data types is mostly based on the file specification from the 'Return to the Roots'-Team - -#ifndef _CFILE_H -#define _CFILE_H - -#include "../includes.h" -#include - -class CFile -{ -private: - static FILE* fp; - static bool loadPAL; - static bobBMP* bmpArray; - static bobSHADOW* shadowArray; - static bobPAL* palArray; - static bobPAL* palActual; // surfaces for new pictures will use this palette -public: - // Access Methods - static void set_palActual(bobPAL* Actual) { palActual = Actual; } - static bobPAL* get_palArray() { return palArray; } - static void set_palArray(bobPAL* Array) { palArray = Array; } - static void set_bmpArray(bobBMP* new_bmpArray) { bmpArray = new_bmpArray; } - -private: - // Methods - static bool open_lst(); - static bool open_bob(); // not implemented yet - static bool open_idx(const std::string& filename); - static bool open_bbm(); - static bool open_lbm(const std::string& filename); - static bool open_gou(); - static bobMAP* open_wld(); - static bobMAP* open_swd(); - static bool save_lst(void* data); // not implemented yet - static bool save_bob(void* data); // not implemented yet - static bool save_idx(void* data, const std::string& filename); // not implemented yet - static bool save_bbm(void* data); // not implemented yet - static bool save_lbm(void* data); // not implemented yet - static bool save_wld(void* data); - static bool save_swd(void* data); - static bool read_bob01(); // not implemented yet - static bool read_bob02(); - static bool read_bob03(); - static bool read_bob04(int player_color = PLAYER_BLUE); - static bool read_bob05(); - static bool read_bob07(); - static bool read_bob14(); - // convert between big- and little-endian - static inline void endian_swap(Uint16& x); - static inline void endian_swap(Uint32& x); - -public: - CFile(); - ~CFile(); - static void* open_file(const std::string& filename, char filetype, bool only_loadPAL = false); - static bool save_file(const std::string& filename, char filetype, void* data); -}; - -#endif +// handling of the files and data types is mostly based on the file specification from the 'Return to the Roots'-Team + +#ifndef _CFILE_H +#define _CFILE_H + +#include "../includes.h" +#include + +class CFile +{ +private: + static FILE* fp; + static bool loadPAL; + static bobBMP* bmpArray; + static bobSHADOW* shadowArray; + static bobPAL* palArray; + static bobPAL* palActual; // surfaces for new pictures will use this palette +public: + // Access Methods + static void set_palActual(bobPAL* Actual) { palActual = Actual; } + static bobPAL* get_palArray() { return palArray; } + static void set_palArray(bobPAL* Array) { palArray = Array; } + static void set_bmpArray(bobBMP* new_bmpArray) { bmpArray = new_bmpArray; } + +private: + // Methods + static bool open_lst(); + static bool open_bob(); // not implemented yet + static bool open_idx(const std::string& filename); + static bool open_bbm(); + static bool open_lbm(const std::string& filename); + static bool open_gou(); + static bobMAP* open_wld(); + static bobMAP* open_swd(); + static bool save_lst(void* data); // not implemented yet + static bool save_bob(void* data); // not implemented yet + static bool save_idx(void* data, const std::string& filename); // not implemented yet + static bool save_bbm(void* data); // not implemented yet + static bool save_lbm(void* data); // not implemented yet + static bool save_wld(void* data); + static bool save_swd(void* data); + static bool read_bob01(); // not implemented yet + static bool read_bob02(); + static bool read_bob03(); + static bool read_bob04(int player_color = PLAYER_BLUE); + static bool read_bob05(); + static bool read_bob07(); + static bool read_bob14(); + // convert between big- and little-endian + static inline void endian_swap(Uint16& x); + static inline void endian_swap(Uint32& x); + +public: + CFile(); + ~CFile(); + static void* open_file(const std::string& filename, char filetype, bool only_loadPAL = false); + static bool save_file(const std::string& filename, char filetype, void* data); +}; + +#endif diff --git a/CIO/CFont.cpp b/CIO/CFont.cpp index 4b576de..ac6a88a 100644 --- a/CIO/CFont.cpp +++ b/CIO/CFont.cpp @@ -1,492 +1,492 @@ -#include "CFont.h" -#include "../CSurface.h" -#include "../globals.h" - -CFont::CFont(const char* string, int x, int y, int fontsize, int color) -{ - this->x = x; - this->y = y; - this->string = string; - // only three sizes are available (in pixels) - if(fontsize != 9 && fontsize != 11 && fontsize != 14) - this->fontsize = 9; - else - this->fontsize = fontsize; - this->color = color; - Surf_Font = NULL; - callback = NULL; - clickedParam = 0; - // create surface and write text to it - writeText(this->string); -} - -CFont::~CFont() -{ - SDL_FreeSurface(Surf_Font); -} - -void CFont::setFontsize(int fontsize) -{ - if(fontsize != 9 && fontsize != 11 && fontsize != 14) - this->fontsize = 9; - else - this->fontsize = fontsize; - writeText(string); -} - -void CFont::setColor(int color) -{ - this->color = color; - writeText(string); -} - -void CFont::setText(const char* string) -{ - SDL_FreeSurface(Surf_Font); - Surf_Font = NULL; - this->string = string; - writeText(this->string); -} - -void CFont::setMouseData(SDL_MouseButtonEvent button) -{ - // left button is pressed - if(button.button == SDL_BUTTON_LEFT) - { - if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - { - // if mouse button is pressed ON the text - if((button.state == SDL_PRESSED) && callback != NULL) - { - setColor(FONT_ORANGE); - } else if(button.state == SDL_RELEASED) - { - if(color == FONT_ORANGE && callback != NULL) - callback(clickedParam); - } - } - } -} - -bool CFont::writeText(const char* string) -{ - // data for counting pixels to create the surface - unsigned int pixel_ctr_w = 0; - unsigned int pixel_ctr_w_tmp = 0; - // ROW_SEPARATOR IS ALSO USED IN CTEXTFIELD-CLASS, SO DO NOT CHANGE!! - int row_separator = (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4)); - unsigned int pixel_ctr_h = fontsize + row_separator; - bool pixel_count_loop = true; - // the index for the chiffre-picture in the global::bmpArray - unsigned int chiffre_index = 0; - // pointer to the chiffres - if(!string) - string = this->string; - const unsigned char* chiffre = reinterpret_cast(string); - // counter for the drawed pixels (cause we dont want to draw outside of the surface) - int pos_x = 0; - int pos_y = 0; - - if(string == NULL && this->string == NULL) - return false; - - // now lets draw the chiffres - while(*chiffre != '\0') - { - // set chiffre_index to the first chiffre (spacebar) depending on the fontsize - switch(fontsize) - { - case 9: chiffre_index = FONT9_SPACE; break; - - case 11: chiffre_index = FONT11_SPACE; break; - - case 14: chiffre_index = FONT14_SPACE; break; - - default: // in fact not necessary, cause this case is handled by the constructor - break; - } - - // subtract 32 shows that we start by spacebar as 'zero-position' - // subtract another value after subtracting 32 means the skipped chiffres in ansi in compare to our enumeration (cause we dont have - // all ansi-values as pictures) - - // between 'spacebar' and the 'Z' - if(*chiffre >= 32 && *chiffre <= 90) - chiffre_index += (*chiffre - 32) * FONT_COLOR_COUNT + color; - /* \ */ - else if(*chiffre == 92) - chiffre_index += 59 * FONT_COLOR_COUNT + color; - // _ - else if(*chiffre == 95) - chiffre_index += 60 * FONT_COLOR_COUNT + color; - // between 'a' and 'z' - else if(*chiffre >= 97 && *chiffre <= 122) - chiffre_index += (*chiffre - 32 - 4) * FONT_COLOR_COUNT + color; - // © - else if(*chiffre == 169) - chiffre_index += 114 * FONT_COLOR_COUNT + color; - // Ä - else if(*chiffre == 196) - chiffre_index += 100 * FONT_COLOR_COUNT + color; - // Ç - else if(*chiffre == 199) - chiffre_index += 87 * FONT_COLOR_COUNT + color; - // Ö - else if(*chiffre == 214) - chiffre_index += 106 * FONT_COLOR_COUNT + color; - // Ü - else if(*chiffre == 220) - chiffre_index += 107 * FONT_COLOR_COUNT + color; - // ß - else if(*chiffre == 223) - chiffre_index += 113 * FONT_COLOR_COUNT + color; - // à - else if(*chiffre == 224) - chiffre_index += 92 * FONT_COLOR_COUNT + color; - // á - else if(*chiffre == 225) - chiffre_index += 108 * FONT_COLOR_COUNT + color; - // â - else if(*chiffre == 226) - chiffre_index += 90 * FONT_COLOR_COUNT + color; - // ä - else if(*chiffre == 228) - chiffre_index += 91 * FONT_COLOR_COUNT + color; - // ç - else if(*chiffre == 231) - chiffre_index += 93 * FONT_COLOR_COUNT + color; - // è - else if(*chiffre == 232) - chiffre_index += 96 * FONT_COLOR_COUNT + color; - // é - else if(*chiffre == 233) - chiffre_index += 89 * FONT_COLOR_COUNT + color; - // ê - else if(*chiffre == 234) - chiffre_index += 94 * FONT_COLOR_COUNT + color; - // ë - else if(*chiffre == 235) - chiffre_index += 95 * FONT_COLOR_COUNT + color; - // ì - else if(*chiffre == 236) - chiffre_index += 99 * FONT_COLOR_COUNT + color; - // í - else if(*chiffre == 237) - chiffre_index += 109 * FONT_COLOR_COUNT + color; - // î - else if(*chiffre == 238) - chiffre_index += 98 * FONT_COLOR_COUNT + color; - // ï - else if(*chiffre == 239) - chiffre_index += 97 * FONT_COLOR_COUNT + color; - // ñ - else if(*chiffre == 241) - chiffre_index += 112 * FONT_COLOR_COUNT + color; - // ò - else if(*chiffre == 242) - chiffre_index += 103 * FONT_COLOR_COUNT + color; - // ó - else if(*chiffre == 243) - chiffre_index += 110 * FONT_COLOR_COUNT + color; - // ô - else if(*chiffre == 244) - chiffre_index += 101 * FONT_COLOR_COUNT + color; - // ö - else if(*chiffre == 246) - chiffre_index += 102 * FONT_COLOR_COUNT + color; - // ù - else if(*chiffre == 249) - chiffre_index += 105 * FONT_COLOR_COUNT + color; - // ú - else if(*chiffre == 250) - chiffre_index += 111 * FONT_COLOR_COUNT + color; - // û - else if(*chiffre == 251) - chiffre_index += 104 * FONT_COLOR_COUNT + color; - // ü - else if(*chiffre == 252) - chiffre_index += 88 * FONT_COLOR_COUNT + color; - // chiffre not available, use '_' instead - else - chiffre_index += 60 * FONT_COLOR_COUNT + color; - - // if we only count pixels in this round - if(pixel_count_loop) - { - if(*chiffre == '\n') - { - pixel_ctr_h += row_separator + fontsize; - if(pixel_ctr_w_tmp > pixel_ctr_w) - pixel_ctr_w = pixel_ctr_w_tmp; - pixel_ctr_w_tmp = 0; - chiffre++; - } else - { - pixel_ctr_w_tmp += global::bmpArray[chiffre_index].w; - chiffre++; - } - - // if this was the last chiffre setup width, create surface and go in normal mode to write text to the surface - if(*chiffre == '\0') - { - if(pixel_ctr_w_tmp > pixel_ctr_w) - pixel_ctr_w = pixel_ctr_w_tmp; - w = pixel_ctr_w; - h = pixel_ctr_h; - if(Surf_Font != NULL) - SDL_FreeSurface(Surf_Font); - if((Surf_Font = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) - return false; - SDL_SetColorKey(Surf_Font, SDL_SRCCOLORKEY, SDL_MapRGB(Surf_Font->format, 0, 0, 0)); - chiffre = reinterpret_cast(string); - pixel_count_loop = false; - continue; - } else - continue; - } - - // now we have our index and can use global::bmpArray[chiffre_index] to get the picture - - // test for new line - if(*chiffre == '\n') - { - pos_y += row_separator + fontsize; - pos_x = 0; - chiffre++; - continue; - } - - // if right end of surface is reached, stop drawing chiffres - if(Surf_Font->w < pos_x + global::bmpArray[chiffre_index].w) - break; - // if lower end of surface is reached, stop drawing chiffres - if(Surf_Font->h < pos_y + row_separator + global::bmpArray[chiffre_index].h) - break; - - // draw the chiffre to the destination - CSurface::Draw(Surf_Font, global::bmpArray[chiffre_index].surface, pos_x, pos_y); - - // set position for next chiffre depending on the width of the actual drawn - // NOTE: there is a bug in the ansi 236 'ì' at fontsize 9, the width is 39, this is not useable, we will use the width of ansi 237 - // 'í' instead - if(fontsize == 9 && *chiffre == 236) - pos_x += global::bmpArray[FONT9_SPACE + 109 * FONT_COLOR_COUNT + color].w; - else - pos_x += global::bmpArray[chiffre_index].w; - - // go to next chiffre - chiffre++; - } - return true; -} - -bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y, int fontsize, int color, int align) -{ - // data for necessary counting pixels depending on alignment - unsigned int pixel_ctr_w = 0; - bool pixel_count_loop; - // the index for the chiffre-picture in the global::bmpArray - unsigned int chiffre_index = 0; - // pointer to the chiffres - unsigned char* chiffre = (unsigned char*)string; - // counter for the drawed pixels (cause we dont want to draw outside of the surface) - int pos_x = x; - int pos_y = y; - - if(Surf_Dest == NULL || string == NULL) - return false; - - // only three sizes are available (in pixels) - if(fontsize != 9 && fontsize != 11 && fontsize != 14) - fontsize = 9; - - // are there enough vertical pixels to draw the chiffres? - if(Surf_Dest->h < y + fontsize) - return false; - - // in case of right or middle alignment we must count the pixels first - switch(align) - { - case ALIGN_LEFT: pixel_count_loop = false; break; - - case ALIGN_MIDDLE: pixel_count_loop = true; break; - - case ALIGN_RIGHT: pixel_count_loop = true; break; - - default: // in default: align = ALIGN_LEFT - pixel_count_loop = false; - break; - } - - // now lets draw the chiffres - while(*chiffre != '\0') - { - // set chiffre_index to the first chiffre (spacebar) depending on the fontsize - switch(fontsize) - { - case 9: chiffre_index = FONT9_SPACE; break; - - case 11: chiffre_index = FONT11_SPACE; break; - - case 14: chiffre_index = FONT14_SPACE; break; - - default: // in fact not necessary, cause this case is handled before - break; - } - - // subtract 32 shows that we start by spacebar as 'zero-position' - // subtract another value after subtracting 32 means the skipped chiffres in ansi in compare to our enumeration (cause we dont have - // all ansi-values as pictures) - - // between 'spacebar' and the 'Z' - if(*chiffre >= 32 && *chiffre <= 90) - chiffre_index += (*chiffre - 32) * FONT_COLOR_COUNT + color; - /* \ */ - else if(*chiffre == 92) - chiffre_index += 59 * FONT_COLOR_COUNT + color; - // _ - else if(*chiffre == 95) - chiffre_index += 60 * FONT_COLOR_COUNT + color; - // between 'a' and 'z' - else if(*chiffre >= 97 && *chiffre <= 122) - chiffre_index += (*chiffre - 32 - 4) * FONT_COLOR_COUNT + color; - // © - else if(*chiffre == 169) - chiffre_index += 114 * FONT_COLOR_COUNT + color; - // Ä - else if(*chiffre == 196) - chiffre_index += 100 * FONT_COLOR_COUNT + color; - // Ç - else if(*chiffre == 199) - chiffre_index += 87 * FONT_COLOR_COUNT + color; - // Ö - else if(*chiffre == 214) - chiffre_index += 106 * FONT_COLOR_COUNT + color; - // Ü - else if(*chiffre == 220) - chiffre_index += 107 * FONT_COLOR_COUNT + color; - // ß - else if(*chiffre == 223) - chiffre_index += 113 * FONT_COLOR_COUNT + color; - // à - else if(*chiffre == 224) - chiffre_index += 92 * FONT_COLOR_COUNT + color; - // á - else if(*chiffre == 225) - chiffre_index += 108 * FONT_COLOR_COUNT + color; - // â - else if(*chiffre == 226) - chiffre_index += 90 * FONT_COLOR_COUNT + color; - // ä - else if(*chiffre == 228) - chiffre_index += 91 * FONT_COLOR_COUNT + color; - // ç - else if(*chiffre == 231) - chiffre_index += 93 * FONT_COLOR_COUNT + color; - // è - else if(*chiffre == 232) - chiffre_index += 96 * FONT_COLOR_COUNT + color; - // é - else if(*chiffre == 233) - chiffre_index += 89 * FONT_COLOR_COUNT + color; - // ê - else if(*chiffre == 234) - chiffre_index += 94 * FONT_COLOR_COUNT + color; - // ë - else if(*chiffre == 235) - chiffre_index += 95 * FONT_COLOR_COUNT + color; - // ì - else if(*chiffre == 236) - chiffre_index += 99 * FONT_COLOR_COUNT + color; - // í - else if(*chiffre == 237) - chiffre_index += 109 * FONT_COLOR_COUNT + color; - // î - else if(*chiffre == 238) - chiffre_index += 98 * FONT_COLOR_COUNT + color; - // ï - else if(*chiffre == 239) - chiffre_index += 97 * FONT_COLOR_COUNT + color; - // ñ - else if(*chiffre == 241) - chiffre_index += 112 * FONT_COLOR_COUNT + color; - // ò - else if(*chiffre == 242) - chiffre_index += 103 * FONT_COLOR_COUNT + color; - // ó - else if(*chiffre == 243) - chiffre_index += 110 * FONT_COLOR_COUNT + color; - // ô - else if(*chiffre == 244) - chiffre_index += 101 * FONT_COLOR_COUNT + color; - // ö - else if(*chiffre == 246) - chiffre_index += 102 * FONT_COLOR_COUNT + color; - // ù - else if(*chiffre == 249) - chiffre_index += 105 * FONT_COLOR_COUNT + color; - // ú - else if(*chiffre == 250) - chiffre_index += 111 * FONT_COLOR_COUNT + color; - // û - else if(*chiffre == 251) - chiffre_index += 104 * FONT_COLOR_COUNT + color; - // ü - else if(*chiffre == 252) - chiffre_index += 88 * FONT_COLOR_COUNT + color; - // chiffre not available, use '_' instead - else - chiffre_index += 60 * FONT_COLOR_COUNT + color; - - // if we only count pixels in this round - if(pixel_count_loop) - { - pixel_ctr_w += global::bmpArray[chiffre_index].w; - - // if text is to long to go further left, stop loop and begin writing at x=0 - if((align == ALIGN_MIDDLE) && (x - (unsigned int)(pixel_ctr_w / 2) <= 0)) - pos_x = 0; - else if((align == ALIGN_RIGHT) && (Surf_Dest->w - 1 - pixel_ctr_w <= 0)) - pos_x = 0; - - chiffre++; - - // if this was the last chiffre go in normal mode and write the text to the specified position - if(*chiffre == '\0') - { - chiffre = (unsigned char*)string; - - if(align == ALIGN_MIDDLE) - pos_x = x - (unsigned int)(pixel_ctr_w / 2); - else if(align == ALIGN_RIGHT) - pos_x = Surf_Dest->w - 1 - pixel_ctr_w; - - pixel_count_loop = false; - continue; - } else - continue; - } - - // now we have our index and can use global::bmpArray[chiffre_index] to get the picture - - // if right end of surface is reached, stop drawing chiffres - if(Surf_Dest->w < pos_x + global::bmpArray[chiffre_index].w) - break; - - // draw the chiffre to the destination - CSurface::Draw(Surf_Dest, global::bmpArray[chiffre_index].surface, pos_x, pos_y); - - // set position for next chiffre depending on the width of the actual drawn - // NOTE: there is a bug in the ansi 236 'ì' at fontsize 9, the width is 39, this is not useable, we will use the width of ansi 237 - // 'í' instead - if(fontsize == 9 && *chiffre == 236) - pos_x += global::bmpArray[FONT9_SPACE + 109 * FONT_COLOR_COUNT + color].w; - else - pos_x += global::bmpArray[chiffre_index].w; - - // go to next chiffre - chiffre++; - } - - return true; -} +#include "CFont.h" +#include "../CSurface.h" +#include "../globals.h" + +CFont::CFont(const char* string, int x, int y, int fontsize, int color) +{ + this->x = x; + this->y = y; + this->string = string; + // only three sizes are available (in pixels) + if(fontsize != 9 && fontsize != 11 && fontsize != 14) + this->fontsize = 9; + else + this->fontsize = fontsize; + this->color = color; + Surf_Font = NULL; + callback = NULL; + clickedParam = 0; + // create surface and write text to it + writeText(this->string); +} + +CFont::~CFont() +{ + SDL_FreeSurface(Surf_Font); +} + +void CFont::setFontsize(int fontsize) +{ + if(fontsize != 9 && fontsize != 11 && fontsize != 14) + this->fontsize = 9; + else + this->fontsize = fontsize; + writeText(string); +} + +void CFont::setColor(int color) +{ + this->color = color; + writeText(string); +} + +void CFont::setText(const char* string) +{ + SDL_FreeSurface(Surf_Font); + Surf_Font = NULL; + this->string = string; + writeText(this->string); +} + +void CFont::setMouseData(SDL_MouseButtonEvent button) +{ + // left button is pressed + if(button.button == SDL_BUTTON_LEFT) + { + if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + { + // if mouse button is pressed ON the text + if((button.state == SDL_PRESSED) && callback != NULL) + { + setColor(FONT_ORANGE); + } else if(button.state == SDL_RELEASED) + { + if(color == FONT_ORANGE && callback != NULL) + callback(clickedParam); + } + } + } +} + +bool CFont::writeText(const char* string) +{ + // data for counting pixels to create the surface + unsigned int pixel_ctr_w = 0; + unsigned int pixel_ctr_w_tmp = 0; + // ROW_SEPARATOR IS ALSO USED IN CTEXTFIELD-CLASS, SO DO NOT CHANGE!! + int row_separator = (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4)); + unsigned int pixel_ctr_h = fontsize + row_separator; + bool pixel_count_loop = true; + // the index for the chiffre-picture in the global::bmpArray + unsigned int chiffre_index = 0; + // pointer to the chiffres + if(!string) + string = this->string; + const unsigned char* chiffre = reinterpret_cast(string); + // counter for the drawed pixels (cause we dont want to draw outside of the surface) + int pos_x = 0; + int pos_y = 0; + + if(string == NULL && this->string == NULL) + return false; + + // now lets draw the chiffres + while(*chiffre != '\0') + { + // set chiffre_index to the first chiffre (spacebar) depending on the fontsize + switch(fontsize) + { + case 9: chiffre_index = FONT9_SPACE; break; + + case 11: chiffre_index = FONT11_SPACE; break; + + case 14: chiffre_index = FONT14_SPACE; break; + + default: // in fact not necessary, cause this case is handled by the constructor + break; + } + + // subtract 32 shows that we start by spacebar as 'zero-position' + // subtract another value after subtracting 32 means the skipped chiffres in ansi in compare to our enumeration (cause we dont have + // all ansi-values as pictures) + + // between 'spacebar' and the 'Z' + if(*chiffre >= 32 && *chiffre <= 90) + chiffre_index += (*chiffre - 32) * FONT_COLOR_COUNT + color; + /* \ */ + else if(*chiffre == 92) + chiffre_index += 59 * FONT_COLOR_COUNT + color; + // _ + else if(*chiffre == 95) + chiffre_index += 60 * FONT_COLOR_COUNT + color; + // between 'a' and 'z' + else if(*chiffre >= 97 && *chiffre <= 122) + chiffre_index += (*chiffre - 32 - 4) * FONT_COLOR_COUNT + color; + // © + else if(*chiffre == 169) + chiffre_index += 114 * FONT_COLOR_COUNT + color; + // Ä + else if(*chiffre == 196) + chiffre_index += 100 * FONT_COLOR_COUNT + color; + // Ç + else if(*chiffre == 199) + chiffre_index += 87 * FONT_COLOR_COUNT + color; + // Ö + else if(*chiffre == 214) + chiffre_index += 106 * FONT_COLOR_COUNT + color; + // Ü + else if(*chiffre == 220) + chiffre_index += 107 * FONT_COLOR_COUNT + color; + // ß + else if(*chiffre == 223) + chiffre_index += 113 * FONT_COLOR_COUNT + color; + // à + else if(*chiffre == 224) + chiffre_index += 92 * FONT_COLOR_COUNT + color; + // á + else if(*chiffre == 225) + chiffre_index += 108 * FONT_COLOR_COUNT + color; + // â + else if(*chiffre == 226) + chiffre_index += 90 * FONT_COLOR_COUNT + color; + // ä + else if(*chiffre == 228) + chiffre_index += 91 * FONT_COLOR_COUNT + color; + // ç + else if(*chiffre == 231) + chiffre_index += 93 * FONT_COLOR_COUNT + color; + // è + else if(*chiffre == 232) + chiffre_index += 96 * FONT_COLOR_COUNT + color; + // é + else if(*chiffre == 233) + chiffre_index += 89 * FONT_COLOR_COUNT + color; + // ê + else if(*chiffre == 234) + chiffre_index += 94 * FONT_COLOR_COUNT + color; + // ë + else if(*chiffre == 235) + chiffre_index += 95 * FONT_COLOR_COUNT + color; + // ì + else if(*chiffre == 236) + chiffre_index += 99 * FONT_COLOR_COUNT + color; + // í + else if(*chiffre == 237) + chiffre_index += 109 * FONT_COLOR_COUNT + color; + // î + else if(*chiffre == 238) + chiffre_index += 98 * FONT_COLOR_COUNT + color; + // ï + else if(*chiffre == 239) + chiffre_index += 97 * FONT_COLOR_COUNT + color; + // ñ + else if(*chiffre == 241) + chiffre_index += 112 * FONT_COLOR_COUNT + color; + // ò + else if(*chiffre == 242) + chiffre_index += 103 * FONT_COLOR_COUNT + color; + // ó + else if(*chiffre == 243) + chiffre_index += 110 * FONT_COLOR_COUNT + color; + // ô + else if(*chiffre == 244) + chiffre_index += 101 * FONT_COLOR_COUNT + color; + // ö + else if(*chiffre == 246) + chiffre_index += 102 * FONT_COLOR_COUNT + color; + // ù + else if(*chiffre == 249) + chiffre_index += 105 * FONT_COLOR_COUNT + color; + // ú + else if(*chiffre == 250) + chiffre_index += 111 * FONT_COLOR_COUNT + color; + // û + else if(*chiffre == 251) + chiffre_index += 104 * FONT_COLOR_COUNT + color; + // ü + else if(*chiffre == 252) + chiffre_index += 88 * FONT_COLOR_COUNT + color; + // chiffre not available, use '_' instead + else + chiffre_index += 60 * FONT_COLOR_COUNT + color; + + // if we only count pixels in this round + if(pixel_count_loop) + { + if(*chiffre == '\n') + { + pixel_ctr_h += row_separator + fontsize; + if(pixel_ctr_w_tmp > pixel_ctr_w) + pixel_ctr_w = pixel_ctr_w_tmp; + pixel_ctr_w_tmp = 0; + chiffre++; + } else + { + pixel_ctr_w_tmp += global::bmpArray[chiffre_index].w; + chiffre++; + } + + // if this was the last chiffre setup width, create surface and go in normal mode to write text to the surface + if(*chiffre == '\0') + { + if(pixel_ctr_w_tmp > pixel_ctr_w) + pixel_ctr_w = pixel_ctr_w_tmp; + w = pixel_ctr_w; + h = pixel_ctr_h; + if(Surf_Font != NULL) + SDL_FreeSurface(Surf_Font); + if((Surf_Font = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) + return false; + SDL_SetColorKey(Surf_Font, SDL_SRCCOLORKEY, SDL_MapRGB(Surf_Font->format, 0, 0, 0)); + chiffre = reinterpret_cast(string); + pixel_count_loop = false; + continue; + } else + continue; + } + + // now we have our index and can use global::bmpArray[chiffre_index] to get the picture + + // test for new line + if(*chiffre == '\n') + { + pos_y += row_separator + fontsize; + pos_x = 0; + chiffre++; + continue; + } + + // if right end of surface is reached, stop drawing chiffres + if(Surf_Font->w < pos_x + global::bmpArray[chiffre_index].w) + break; + // if lower end of surface is reached, stop drawing chiffres + if(Surf_Font->h < pos_y + row_separator + global::bmpArray[chiffre_index].h) + break; + + // draw the chiffre to the destination + CSurface::Draw(Surf_Font, global::bmpArray[chiffre_index].surface, pos_x, pos_y); + + // set position for next chiffre depending on the width of the actual drawn + // NOTE: there is a bug in the ansi 236 'ì' at fontsize 9, the width is 39, this is not useable, we will use the width of ansi 237 + // 'í' instead + if(fontsize == 9 && *chiffre == 236) + pos_x += global::bmpArray[FONT9_SPACE + 109 * FONT_COLOR_COUNT + color].w; + else + pos_x += global::bmpArray[chiffre_index].w; + + // go to next chiffre + chiffre++; + } + return true; +} + +bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y, int fontsize, int color, int align) +{ + // data for necessary counting pixels depending on alignment + unsigned int pixel_ctr_w = 0; + bool pixel_count_loop; + // the index for the chiffre-picture in the global::bmpArray + unsigned int chiffre_index = 0; + // pointer to the chiffres + unsigned char* chiffre = (unsigned char*)string; + // counter for the drawed pixels (cause we dont want to draw outside of the surface) + int pos_x = x; + int pos_y = y; + + if(Surf_Dest == NULL || string == NULL) + return false; + + // only three sizes are available (in pixels) + if(fontsize != 9 && fontsize != 11 && fontsize != 14) + fontsize = 9; + + // are there enough vertical pixels to draw the chiffres? + if(Surf_Dest->h < y + fontsize) + return false; + + // in case of right or middle alignment we must count the pixels first + switch(align) + { + case ALIGN_LEFT: pixel_count_loop = false; break; + + case ALIGN_MIDDLE: pixel_count_loop = true; break; + + case ALIGN_RIGHT: pixel_count_loop = true; break; + + default: // in default: align = ALIGN_LEFT + pixel_count_loop = false; + break; + } + + // now lets draw the chiffres + while(*chiffre != '\0') + { + // set chiffre_index to the first chiffre (spacebar) depending on the fontsize + switch(fontsize) + { + case 9: chiffre_index = FONT9_SPACE; break; + + case 11: chiffre_index = FONT11_SPACE; break; + + case 14: chiffre_index = FONT14_SPACE; break; + + default: // in fact not necessary, cause this case is handled before + break; + } + + // subtract 32 shows that we start by spacebar as 'zero-position' + // subtract another value after subtracting 32 means the skipped chiffres in ansi in compare to our enumeration (cause we dont have + // all ansi-values as pictures) + + // between 'spacebar' and the 'Z' + if(*chiffre >= 32 && *chiffre <= 90) + chiffre_index += (*chiffre - 32) * FONT_COLOR_COUNT + color; + /* \ */ + else if(*chiffre == 92) + chiffre_index += 59 * FONT_COLOR_COUNT + color; + // _ + else if(*chiffre == 95) + chiffre_index += 60 * FONT_COLOR_COUNT + color; + // between 'a' and 'z' + else if(*chiffre >= 97 && *chiffre <= 122) + chiffre_index += (*chiffre - 32 - 4) * FONT_COLOR_COUNT + color; + // © + else if(*chiffre == 169) + chiffre_index += 114 * FONT_COLOR_COUNT + color; + // Ä + else if(*chiffre == 196) + chiffre_index += 100 * FONT_COLOR_COUNT + color; + // Ç + else if(*chiffre == 199) + chiffre_index += 87 * FONT_COLOR_COUNT + color; + // Ö + else if(*chiffre == 214) + chiffre_index += 106 * FONT_COLOR_COUNT + color; + // Ü + else if(*chiffre == 220) + chiffre_index += 107 * FONT_COLOR_COUNT + color; + // ß + else if(*chiffre == 223) + chiffre_index += 113 * FONT_COLOR_COUNT + color; + // à + else if(*chiffre == 224) + chiffre_index += 92 * FONT_COLOR_COUNT + color; + // á + else if(*chiffre == 225) + chiffre_index += 108 * FONT_COLOR_COUNT + color; + // â + else if(*chiffre == 226) + chiffre_index += 90 * FONT_COLOR_COUNT + color; + // ä + else if(*chiffre == 228) + chiffre_index += 91 * FONT_COLOR_COUNT + color; + // ç + else if(*chiffre == 231) + chiffre_index += 93 * FONT_COLOR_COUNT + color; + // è + else if(*chiffre == 232) + chiffre_index += 96 * FONT_COLOR_COUNT + color; + // é + else if(*chiffre == 233) + chiffre_index += 89 * FONT_COLOR_COUNT + color; + // ê + else if(*chiffre == 234) + chiffre_index += 94 * FONT_COLOR_COUNT + color; + // ë + else if(*chiffre == 235) + chiffre_index += 95 * FONT_COLOR_COUNT + color; + // ì + else if(*chiffre == 236) + chiffre_index += 99 * FONT_COLOR_COUNT + color; + // í + else if(*chiffre == 237) + chiffre_index += 109 * FONT_COLOR_COUNT + color; + // î + else if(*chiffre == 238) + chiffre_index += 98 * FONT_COLOR_COUNT + color; + // ï + else if(*chiffre == 239) + chiffre_index += 97 * FONT_COLOR_COUNT + color; + // ñ + else if(*chiffre == 241) + chiffre_index += 112 * FONT_COLOR_COUNT + color; + // ò + else if(*chiffre == 242) + chiffre_index += 103 * FONT_COLOR_COUNT + color; + // ó + else if(*chiffre == 243) + chiffre_index += 110 * FONT_COLOR_COUNT + color; + // ô + else if(*chiffre == 244) + chiffre_index += 101 * FONT_COLOR_COUNT + color; + // ö + else if(*chiffre == 246) + chiffre_index += 102 * FONT_COLOR_COUNT + color; + // ù + else if(*chiffre == 249) + chiffre_index += 105 * FONT_COLOR_COUNT + color; + // ú + else if(*chiffre == 250) + chiffre_index += 111 * FONT_COLOR_COUNT + color; + // û + else if(*chiffre == 251) + chiffre_index += 104 * FONT_COLOR_COUNT + color; + // ü + else if(*chiffre == 252) + chiffre_index += 88 * FONT_COLOR_COUNT + color; + // chiffre not available, use '_' instead + else + chiffre_index += 60 * FONT_COLOR_COUNT + color; + + // if we only count pixels in this round + if(pixel_count_loop) + { + pixel_ctr_w += global::bmpArray[chiffre_index].w; + + // if text is to long to go further left, stop loop and begin writing at x=0 + if((align == ALIGN_MIDDLE) && (x - (unsigned int)(pixel_ctr_w / 2) <= 0)) + pos_x = 0; + else if((align == ALIGN_RIGHT) && (Surf_Dest->w - 1 - pixel_ctr_w <= 0)) + pos_x = 0; + + chiffre++; + + // if this was the last chiffre go in normal mode and write the text to the specified position + if(*chiffre == '\0') + { + chiffre = (unsigned char*)string; + + if(align == ALIGN_MIDDLE) + pos_x = x - (unsigned int)(pixel_ctr_w / 2); + else if(align == ALIGN_RIGHT) + pos_x = Surf_Dest->w - 1 - pixel_ctr_w; + + pixel_count_loop = false; + continue; + } else + continue; + } + + // now we have our index and can use global::bmpArray[chiffre_index] to get the picture + + // if right end of surface is reached, stop drawing chiffres + if(Surf_Dest->w < pos_x + global::bmpArray[chiffre_index].w) + break; + + // draw the chiffre to the destination + CSurface::Draw(Surf_Dest, global::bmpArray[chiffre_index].surface, pos_x, pos_y); + + // set position for next chiffre depending on the width of the actual drawn + // NOTE: there is a bug in the ansi 236 'ì' at fontsize 9, the width is 39, this is not useable, we will use the width of ansi 237 + // 'í' instead + if(fontsize == 9 && *chiffre == 236) + pos_x += global::bmpArray[FONT9_SPACE + 109 * FONT_COLOR_COUNT + color].w; + else + pos_x += global::bmpArray[chiffre_index].w; + + // go to next chiffre + chiffre++; + } + + return true; +} diff --git a/CIO/CFont.h b/CIO/CFont.h index 842745c..53c89cc 100644 --- a/CIO/CFont.h +++ b/CIO/CFont.h @@ -1,57 +1,57 @@ -#ifndef _CFONT_H -#define _CFONT_H - -#include "../includes.h" - -class CFont -{ - friend class CDebug; - -private: - SDL_Surface* Surf_Font; - Uint16 x; - Sint16 y; - Uint16 w; - Uint16 h; - const char* string; - int fontsize; //== Uint16 h; - int color; - void (*callback)(int); - int clickedParam; - -public: - // Constructor - Destructor - CFont(const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW); - ~CFont(); - // Access - int getX() { return x; }; - int getY() { return y; }; - void setX(int x) { this->x = x; }; - void setY(int y) { this->y = y; }; - int getW() { return w; }; - int getH() { return fontsize; }; - void setFontsize(int fontsize); - void setColor(int color); - int getColor() { return color; } - void setText(const char* string); - void setCallback(void (*callback)(int), int param) - { - this->callback = callback; - clickedParam = param; - } - void unsetCallback() - { - callback = NULL; - clickedParam = 0; - } - void setMouseData(SDL_MouseButtonEvent button); - SDL_Surface* getSurface() { return Surf_Font; }; - // Methods - // fontsize can be 9, 11 or 14 (otherwise it will be set to 9) ---- '\n' is possible - bool writeText(const char* string); - // this function can be used as CFont::writeText to write text directly to a surface without creating an object - static bool writeText(SDL_Surface* Surf_Dest, const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW, - int align = ALIGN_LEFT); -}; - -#endif +#ifndef _CFONT_H +#define _CFONT_H + +#include "../includes.h" + +class CFont +{ + friend class CDebug; + +private: + SDL_Surface* Surf_Font; + Uint16 x; + Sint16 y; + Uint16 w; + Uint16 h; + const char* string; + int fontsize; //== Uint16 h; + int color; + void (*callback)(int); + int clickedParam; + +public: + // Constructor - Destructor + CFont(const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW); + ~CFont(); + // Access + int getX() { return x; }; + int getY() { return y; }; + void setX(int x) { this->x = x; }; + void setY(int y) { this->y = y; }; + int getW() { return w; }; + int getH() { return fontsize; }; + void setFontsize(int fontsize); + void setColor(int color); + int getColor() { return color; } + void setText(const char* string); + void setCallback(void (*callback)(int), int param) + { + this->callback = callback; + clickedParam = param; + } + void unsetCallback() + { + callback = NULL; + clickedParam = 0; + } + void setMouseData(SDL_MouseButtonEvent button); + SDL_Surface* getSurface() { return Surf_Font; }; + // Methods + // fontsize can be 9, 11 or 14 (otherwise it will be set to 9) ---- '\n' is possible + bool writeText(const char* string); + // this function can be used as CFont::writeText to write text directly to a surface without creating an object + static bool writeText(SDL_Surface* Surf_Dest, const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW, + int align = ALIGN_LEFT); +}; + +#endif diff --git a/CIO/CMenu.cpp b/CIO/CMenu.cpp index b2f1a31..e83b5e4 100644 --- a/CIO/CMenu.cpp +++ b/CIO/CMenu.cpp @@ -1,397 +1,397 @@ -#include "CMenu.h" -#include "../CGame.h" -#include "../CSurface.h" -#include "../globals.h" -#include "CButton.h" -#include "CFont.h" -#include "CPicture.h" -#include "CSelectBox.h" -#include "CTextfield.h" - -CMenu::CMenu(int pic_background) -{ - this->pic_background = pic_background; - for(int i = 0; i < MAXBUTTONS; i++) - buttons[i] = NULL; - for(int i = 0; i < MAXTEXTS; i++) - texts[i] = NULL; - for(int i = 0; i < MAXPICTURES; i++) - pictures[i] = NULL; - for(int i = 0; i < MAXPICTURES; i++) - { - static_pictures[i].x = 0; - static_pictures[i].y = 0; - static_pictures[i].pic = -1; - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - textfields[i] = NULL; - for(int i = 0; i < MAXSELECTBOXES; i++) - selectboxes[i] = NULL; - - Surf_Menu = NULL; - needSurface = true; - needRender = true; - active = true; - waste = false; - render(); -} - -CMenu::~CMenu() -{ - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - delete buttons[i]; - } - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] != NULL) - delete texts[i]; - } - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - delete pictures[i]; - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - delete textfields[i]; - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - delete selectboxes[i]; - } - SDL_FreeSurface(Surf_Menu); -} - -void CMenu::setBackgroundPicture(int pic_background) -{ - this->pic_background = pic_background; - needRender = true; -} - -void CMenu::setMouseData(SDL_MouseMotionEvent motion) -{ - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - pictures[i]->setMouseData(motion); - } - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - buttons[i]->setMouseData(motion); - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - selectboxes[i]->setMouseData(motion); - } - needRender = true; -} - -void CMenu::setMouseData(SDL_MouseButtonEvent button) -{ - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - pictures[i]->setMouseData(button); - } - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - buttons[i]->setMouseData(button); - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - textfields[i]->setMouseData(button); - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - selectboxes[i]->setMouseData(button); - } - needRender = true; -} - -void CMenu::setKeyboardData(SDL_KeyboardEvent key) -{ - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - textfields[i]->setKeyboardData(key); - } -} - -CButton* CMenu::addButton(void callback(int), int clickedParam, Uint16 x, Uint16 y, Uint16 w, Uint16 h, int color, const char* text, - int picture) -{ - if(x >= Surf_Menu->w || y >= Surf_Menu->h) - return NULL; - - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] == NULL) - { - buttons[i] = new CButton(callback, clickedParam, x, y, w, h, color, text, picture); - needRender = true; - return buttons[i]; - } - } - return NULL; -} - -bool CMenu::delButton(CButton* ButtonToDelete) -{ - if(ButtonToDelete == NULL) - return false; - - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] == ButtonToDelete) - { - delete buttons[i]; - buttons[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -CFont* CMenu::addText(const char* string, int x, int y, int fontsize, int color) -{ - if(x >= Surf_Menu->w || y >= Surf_Menu->h) - return NULL; - - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] == NULL) - { - texts[i] = new CFont(string, x, y, fontsize, color); - needRender = true; - return texts[i]; - } - } - return NULL; -} - -bool CMenu::delText(CFont* TextToDelete) -{ - if(TextToDelete == NULL) - return false; - - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] == TextToDelete) - { - delete texts[i]; - texts[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -CPicture* CMenu::addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) -{ - if(x >= global::s2->MenuResolutionX || y >= global::s2->MenuResolutionY) - return NULL; - - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] == NULL) - { - pictures[i] = new CPicture(callback, clickedParam, x, y, picture); - needRender = true; - return pictures[i]; - } - } - return NULL; -} - -bool CMenu::delPicture(CPicture* PictureToDelete) -{ - if(PictureToDelete == NULL) - return false; - - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] == PictureToDelete) - { - delete pictures[i]; - pictures[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -int CMenu::addStaticPicture(int x, int y, int picture) -{ - if(x >= global::s2->MenuResolutionX || y >= global::s2->MenuResolutionY) - return -1; - - if(picture < 0) - return -1; - - for(int i = 0; i < MAXPICTURES; i++) - { - if(static_pictures[i].pic == -1) - { - static_pictures[i].pic = picture; - static_pictures[i].x = x; - static_pictures[i].y = y; - needRender = true; - return i; - } - } - return -1; -} - -bool CMenu::delStaticPicture(int ArrayIndex) -{ - if(ArrayIndex < 0 || ArrayIndex >= MAXPICTURES) - return false; - - static_pictures[ArrayIndex].pic = -1; - static_pictures[ArrayIndex].x = 0; - static_pictures[ArrayIndex].y = 0; - needRender = true; - - return true; -} - -CTextfield* CMenu::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int fontsize, int text_color, int bg_color, bool button_style) -{ - if(x >= Surf_Menu->w || y >= Surf_Menu->h) - return NULL; - - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] == NULL) - { - textfields[i] = new CTextfield(x, y, cols, rows, fontsize, text_color, bg_color, button_style); - needRender = true; - return textfields[i]; - } - } - return NULL; -} - -bool CMenu::delTextfield(CTextfield* TextfieldToDelete) -{ - if(TextfieldToDelete == NULL) - return false; - - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] == TextfieldToDelete) - { - delete textfields[i]; - textfields[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -CSelectBox* CMenu::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) -{ - if(x >= Surf_Menu->w || y >= Surf_Menu->h) - return NULL; - - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] == NULL) - { - selectboxes[i] = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); - needRender = true; - return selectboxes[i]; - } - } - return NULL; -} - -bool CMenu::delSelectBox(CSelectBox* SelectBoxToDelete) -{ - if(SelectBoxToDelete == NULL) - return false; - - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] == SelectBoxToDelete) - { - delete selectboxes[i]; - selectboxes[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -bool CMenu::render() -{ - if(pic_background < 0) - return false; - - // if we don't need to render, all is up to date, return true - if(!needRender) - return true; - needRender = false; - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_Menu); - Surf_Menu = NULL; - if((Surf_Menu = SDL_CreateRGBSurface(SDL_SWSURFACE, global::s2->getResX(), global::s2->getResY(), 32, 0, 0, 0, 0)) == NULL) - return false; - needSurface = false; - } - - // CSurface::Draw(Surf_Menu, global::bmpArray[pic_background].surface, 0, 0); - sge_TexturedRect(Surf_Menu, 0, 0, Surf_Menu->w - 1, 0, 0, Surf_Menu->h - 1, Surf_Menu->w - 1, Surf_Menu->h - 1, - global::bmpArray[pic_background].surface, 0, 0, global::bmpArray[pic_background].surface->w - 1, 0, 0, - global::bmpArray[pic_background].surface->h - 1, global::bmpArray[pic_background].surface->w - 1, - global::bmpArray[pic_background].surface->h - 1); - - for(int i = 0; i < MAXPICTURES; i++) - { - if(static_pictures[i].pic >= 0) - CSurface::Draw(Surf_Menu, global::bmpArray[static_pictures[i].pic].surface, static_pictures[i].x, static_pictures[i].y); - } - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - CSurface::Draw(Surf_Menu, pictures[i]->getSurface(), pictures[i]->getX(), pictures[i]->getY()); - } - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] != NULL) - CSurface::Draw(Surf_Menu, texts[i]->getSurface(), texts[i]->getX(), texts[i]->getY()); - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - CSurface::Draw(Surf_Menu, textfields[i]->getSurface(), textfields[i]->getX(), textfields[i]->getY()); - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - CSurface::Draw(Surf_Menu, selectboxes[i]->getSurface(), selectboxes[i]->getX(), selectboxes[i]->getY()); - } - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - CSurface::Draw(Surf_Menu, buttons[i]->getSurface(), buttons[i]->getX(), buttons[i]->getY()); - } - - return true; -} +#include "CMenu.h" +#include "../CGame.h" +#include "../CSurface.h" +#include "../globals.h" +#include "CButton.h" +#include "CFont.h" +#include "CPicture.h" +#include "CSelectBox.h" +#include "CTextfield.h" + +CMenu::CMenu(int pic_background) +{ + this->pic_background = pic_background; + for(int i = 0; i < MAXBUTTONS; i++) + buttons[i] = NULL; + for(int i = 0; i < MAXTEXTS; i++) + texts[i] = NULL; + for(int i = 0; i < MAXPICTURES; i++) + pictures[i] = NULL; + for(int i = 0; i < MAXPICTURES; i++) + { + static_pictures[i].x = 0; + static_pictures[i].y = 0; + static_pictures[i].pic = -1; + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + textfields[i] = NULL; + for(int i = 0; i < MAXSELECTBOXES; i++) + selectboxes[i] = NULL; + + Surf_Menu = NULL; + needSurface = true; + needRender = true; + active = true; + waste = false; + render(); +} + +CMenu::~CMenu() +{ + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + delete buttons[i]; + } + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] != NULL) + delete texts[i]; + } + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + delete pictures[i]; + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + delete textfields[i]; + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + delete selectboxes[i]; + } + SDL_FreeSurface(Surf_Menu); +} + +void CMenu::setBackgroundPicture(int pic_background) +{ + this->pic_background = pic_background; + needRender = true; +} + +void CMenu::setMouseData(SDL_MouseMotionEvent motion) +{ + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + pictures[i]->setMouseData(motion); + } + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + buttons[i]->setMouseData(motion); + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + selectboxes[i]->setMouseData(motion); + } + needRender = true; +} + +void CMenu::setMouseData(SDL_MouseButtonEvent button) +{ + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + pictures[i]->setMouseData(button); + } + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + buttons[i]->setMouseData(button); + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + textfields[i]->setMouseData(button); + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + selectboxes[i]->setMouseData(button); + } + needRender = true; +} + +void CMenu::setKeyboardData(SDL_KeyboardEvent key) +{ + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + textfields[i]->setKeyboardData(key); + } +} + +CButton* CMenu::addButton(void callback(int), int clickedParam, Uint16 x, Uint16 y, Uint16 w, Uint16 h, int color, const char* text, + int picture) +{ + if(x >= Surf_Menu->w || y >= Surf_Menu->h) + return NULL; + + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] == NULL) + { + buttons[i] = new CButton(callback, clickedParam, x, y, w, h, color, text, picture); + needRender = true; + return buttons[i]; + } + } + return NULL; +} + +bool CMenu::delButton(CButton* ButtonToDelete) +{ + if(ButtonToDelete == NULL) + return false; + + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] == ButtonToDelete) + { + delete buttons[i]; + buttons[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +CFont* CMenu::addText(const char* string, int x, int y, int fontsize, int color) +{ + if(x >= Surf_Menu->w || y >= Surf_Menu->h) + return NULL; + + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] == NULL) + { + texts[i] = new CFont(string, x, y, fontsize, color); + needRender = true; + return texts[i]; + } + } + return NULL; +} + +bool CMenu::delText(CFont* TextToDelete) +{ + if(TextToDelete == NULL) + return false; + + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] == TextToDelete) + { + delete texts[i]; + texts[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +CPicture* CMenu::addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) +{ + if(x >= global::s2->MenuResolutionX || y >= global::s2->MenuResolutionY) + return NULL; + + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] == NULL) + { + pictures[i] = new CPicture(callback, clickedParam, x, y, picture); + needRender = true; + return pictures[i]; + } + } + return NULL; +} + +bool CMenu::delPicture(CPicture* PictureToDelete) +{ + if(PictureToDelete == NULL) + return false; + + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] == PictureToDelete) + { + delete pictures[i]; + pictures[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +int CMenu::addStaticPicture(int x, int y, int picture) +{ + if(x >= global::s2->MenuResolutionX || y >= global::s2->MenuResolutionY) + return -1; + + if(picture < 0) + return -1; + + for(int i = 0; i < MAXPICTURES; i++) + { + if(static_pictures[i].pic == -1) + { + static_pictures[i].pic = picture; + static_pictures[i].x = x; + static_pictures[i].y = y; + needRender = true; + return i; + } + } + return -1; +} + +bool CMenu::delStaticPicture(int ArrayIndex) +{ + if(ArrayIndex < 0 || ArrayIndex >= MAXPICTURES) + return false; + + static_pictures[ArrayIndex].pic = -1; + static_pictures[ArrayIndex].x = 0; + static_pictures[ArrayIndex].y = 0; + needRender = true; + + return true; +} + +CTextfield* CMenu::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int fontsize, int text_color, int bg_color, bool button_style) +{ + if(x >= Surf_Menu->w || y >= Surf_Menu->h) + return NULL; + + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] == NULL) + { + textfields[i] = new CTextfield(x, y, cols, rows, fontsize, text_color, bg_color, button_style); + needRender = true; + return textfields[i]; + } + } + return NULL; +} + +bool CMenu::delTextfield(CTextfield* TextfieldToDelete) +{ + if(TextfieldToDelete == NULL) + return false; + + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] == TextfieldToDelete) + { + delete textfields[i]; + textfields[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +CSelectBox* CMenu::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) +{ + if(x >= Surf_Menu->w || y >= Surf_Menu->h) + return NULL; + + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] == NULL) + { + selectboxes[i] = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); + needRender = true; + return selectboxes[i]; + } + } + return NULL; +} + +bool CMenu::delSelectBox(CSelectBox* SelectBoxToDelete) +{ + if(SelectBoxToDelete == NULL) + return false; + + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] == SelectBoxToDelete) + { + delete selectboxes[i]; + selectboxes[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +bool CMenu::render() +{ + if(pic_background < 0) + return false; + + // if we don't need to render, all is up to date, return true + if(!needRender) + return true; + needRender = false; + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_Menu); + Surf_Menu = NULL; + if((Surf_Menu = SDL_CreateRGBSurface(SDL_SWSURFACE, global::s2->getResX(), global::s2->getResY(), 32, 0, 0, 0, 0)) == NULL) + return false; + needSurface = false; + } + + // CSurface::Draw(Surf_Menu, global::bmpArray[pic_background].surface, 0, 0); + sge_TexturedRect(Surf_Menu, 0, 0, Surf_Menu->w - 1, 0, 0, Surf_Menu->h - 1, Surf_Menu->w - 1, Surf_Menu->h - 1, + global::bmpArray[pic_background].surface, 0, 0, global::bmpArray[pic_background].surface->w - 1, 0, 0, + global::bmpArray[pic_background].surface->h - 1, global::bmpArray[pic_background].surface->w - 1, + global::bmpArray[pic_background].surface->h - 1); + + for(int i = 0; i < MAXPICTURES; i++) + { + if(static_pictures[i].pic >= 0) + CSurface::Draw(Surf_Menu, global::bmpArray[static_pictures[i].pic].surface, static_pictures[i].x, static_pictures[i].y); + } + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + CSurface::Draw(Surf_Menu, pictures[i]->getSurface(), pictures[i]->getX(), pictures[i]->getY()); + } + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] != NULL) + CSurface::Draw(Surf_Menu, texts[i]->getSurface(), texts[i]->getX(), texts[i]->getY()); + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + CSurface::Draw(Surf_Menu, textfields[i]->getSurface(), textfields[i]->getX(), textfields[i]->getY()); + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + CSurface::Draw(Surf_Menu, selectboxes[i]->getSurface(), selectboxes[i]->getX(), selectboxes[i]->getY()); + } + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + CSurface::Draw(Surf_Menu, buttons[i]->getSurface(), buttons[i]->getX(), buttons[i]->getY()); + } + + return true; +} diff --git a/CIO/CMenu.h b/CIO/CMenu.h index cb3caed..89c0045 100644 --- a/CIO/CMenu.h +++ b/CIO/CMenu.h @@ -1,73 +1,73 @@ -#ifndef _CMENU_H -#define _CMENU_H - -#include "../includes.h" - -class CButton; -class CFont; -class CPicture; -class CTextfield; -class CSelectBox; - -class CMenu -{ - friend class CDebug; - -private: - // if active is false, the menu will not be render within the game loop - bool active; - // if waste is true, the menu will be delete within the game loop - bool waste; - SDL_Surface* Surf_Menu; - bool needSurface; - bool needRender; - int pic_background; - CButton* buttons[MAXBUTTONS]; - CFont* texts[MAXTEXTS]; - CPicture* pictures[MAXPICTURES]; - CTextfield* textfields[MAXTEXTFIELDS]; - CSelectBox* selectboxes[MAXSELECTBOXES]; - struct - { - int x, y, pic; - } static_pictures[MAXPICTURES]; - -public: - // Constructor - Destructor - CMenu(int pic_background); - ~CMenu(); - // Access - void setBackgroundPicture(int pic_background); - void setMouseData(SDL_MouseMotionEvent motion); - void setMouseData(SDL_MouseButtonEvent button); - void setKeyboardData(SDL_KeyboardEvent key); - SDL_Surface* getSurface() - { - render(); - return Surf_Menu; - }; - void setActive() { active = true; }; - void setInactive() { active = false; }; - bool isActive() { return active; }; - void setWaste() { waste = true; }; - bool isWaste() { return waste; }; - // Methods - CButton* addButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 width = 20, Uint16 height = 20, - int color = BUTTON_GREY, const char* text = NULL, int picture = -1); - bool delButton(CButton* ButtonToDelete); - CFont* addText(const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW); - bool delText(CFont* TextToDelete); - CPicture* addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture); - bool delPicture(CPicture* PictureToDelete); - int addStaticPicture(int x, int y, int picture); - bool delStaticPicture(int ArrayIndex); - CTextfield* addTextfield(Uint16 x = 0, Uint16 y = 0, Uint16 cols = 10, Uint16 rows = 1, int fonsize = 14, int text_color = FONT_YELLOW, - int bg_color = -1, bool button_style = false); - bool delTextfield(CTextfield* TextfieldToDelete); - CSelectBox* addSelectBox(Uint16 x = 0, Uint16 y = 0, Uint16 w = 100, Uint16 h = 100, int fonsize = 14, int text_color = FONT_YELLOW, - int bg_color = -1); - bool delSelectBox(CSelectBox* SelectBoxToDelete); - bool render(); -}; - -#endif +#ifndef _CMENU_H +#define _CMENU_H + +#include "../includes.h" + +class CButton; +class CFont; +class CPicture; +class CTextfield; +class CSelectBox; + +class CMenu +{ + friend class CDebug; + +private: + // if active is false, the menu will not be render within the game loop + bool active; + // if waste is true, the menu will be delete within the game loop + bool waste; + SDL_Surface* Surf_Menu; + bool needSurface; + bool needRender; + int pic_background; + CButton* buttons[MAXBUTTONS]; + CFont* texts[MAXTEXTS]; + CPicture* pictures[MAXPICTURES]; + CTextfield* textfields[MAXTEXTFIELDS]; + CSelectBox* selectboxes[MAXSELECTBOXES]; + struct + { + int x, y, pic; + } static_pictures[MAXPICTURES]; + +public: + // Constructor - Destructor + CMenu(int pic_background); + ~CMenu(); + // Access + void setBackgroundPicture(int pic_background); + void setMouseData(SDL_MouseMotionEvent motion); + void setMouseData(SDL_MouseButtonEvent button); + void setKeyboardData(SDL_KeyboardEvent key); + SDL_Surface* getSurface() + { + render(); + return Surf_Menu; + }; + void setActive() { active = true; }; + void setInactive() { active = false; }; + bool isActive() { return active; }; + void setWaste() { waste = true; }; + bool isWaste() { return waste; }; + // Methods + CButton* addButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 width = 20, Uint16 height = 20, + int color = BUTTON_GREY, const char* text = NULL, int picture = -1); + bool delButton(CButton* ButtonToDelete); + CFont* addText(const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW); + bool delText(CFont* TextToDelete); + CPicture* addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture); + bool delPicture(CPicture* PictureToDelete); + int addStaticPicture(int x, int y, int picture); + bool delStaticPicture(int ArrayIndex); + CTextfield* addTextfield(Uint16 x = 0, Uint16 y = 0, Uint16 cols = 10, Uint16 rows = 1, int fonsize = 14, int text_color = FONT_YELLOW, + int bg_color = -1, bool button_style = false); + bool delTextfield(CTextfield* TextfieldToDelete); + CSelectBox* addSelectBox(Uint16 x = 0, Uint16 y = 0, Uint16 w = 100, Uint16 h = 100, int fonsize = 14, int text_color = FONT_YELLOW, + int bg_color = -1); + bool delSelectBox(CSelectBox* SelectBoxToDelete); + bool render(); +}; + +#endif diff --git a/CIO/CPicture.cpp b/CIO/CPicture.cpp index 011a841..6329313 100644 --- a/CIO/CPicture.cpp +++ b/CIO/CPicture.cpp @@ -1,93 +1,93 @@ -#include "CPicture.h" -#include "../CSurface.h" -#include "../globals.h" - -CPicture::CPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) -{ - marked = false; - clicked = false; - this->x = x; - this->y = y; - if(picture >= 0) - this->picture = picture; - else - this->picture = 0; - this->w = global::bmpArray[picture].w; - this->h = global::bmpArray[picture].h; - this->callback = callback; - this->clickedParam = clickedParam; - motionEntryParam = -1; - motionLeaveParam = -1; - Surf_Picture = NULL; - needSurface = true; - needRender = true; -} - -CPicture::~CPicture() -{ - SDL_FreeSurface(Surf_Picture); -} - -void CPicture::setMouseData(SDL_MouseMotionEvent motion) -{ - // cursor is on the picture - if((motion.x >= x) && (motion.x < x + w) && (motion.y >= y) && (motion.y < y + h)) - { - if(motion.state != SDL_PRESSED || motion.state == SDL_RELEASED) - { - marked = true; - if(motionEntryParam >= 0 && callback != NULL) - callback(motionEntryParam); - } - } else - { - // picture was marked before and mouse cursor is on the picture now, so do the callback - if(motionLeaveParam >= 0 && callback != NULL && marked == true) - callback(motionLeaveParam); - marked = false; - } - needRender = true; -} - -void CPicture::setMouseData(SDL_MouseButtonEvent button) -{ - // left button is pressed - if(button.button == SDL_BUTTON_LEFT) - { - // if mouse button is pressed ON the button, set marked=true - if((button.state == SDL_PRESSED) && (button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - { - marked = true; - clicked = true; - } else if(button.state == SDL_RELEASED) - { - clicked = false; - // if mouse button is released ON the PICTURE (marked = true), then do the callback - if(marked && callback != NULL) - callback(clickedParam); - } - } - needRender = true; -} - -bool CPicture::render() -{ - // if we don't need to render, all is up to date, return true - if(!needRender) - return true; - needRender = false; - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_Picture); - Surf_Picture = NULL; - if((Surf_Picture = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) - return false; - SDL_SetColorKey(Surf_Picture, SDL_SRCCOLORKEY, SDL_MapRGB(Surf_Picture->format, 0, 0, 0)); - needSurface = false; - } - - CSurface::Draw(Surf_Picture, global::bmpArray[picture].surface, 0, 0); - - return true; -} +#include "CPicture.h" +#include "../CSurface.h" +#include "../globals.h" + +CPicture::CPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) +{ + marked = false; + clicked = false; + this->x = x; + this->y = y; + if(picture >= 0) + this->picture = picture; + else + this->picture = 0; + this->w = global::bmpArray[picture].w; + this->h = global::bmpArray[picture].h; + this->callback = callback; + this->clickedParam = clickedParam; + motionEntryParam = -1; + motionLeaveParam = -1; + Surf_Picture = NULL; + needSurface = true; + needRender = true; +} + +CPicture::~CPicture() +{ + SDL_FreeSurface(Surf_Picture); +} + +void CPicture::setMouseData(SDL_MouseMotionEvent motion) +{ + // cursor is on the picture + if((motion.x >= x) && (motion.x < x + w) && (motion.y >= y) && (motion.y < y + h)) + { + if(motion.state != SDL_PRESSED || motion.state == SDL_RELEASED) + { + marked = true; + if(motionEntryParam >= 0 && callback != NULL) + callback(motionEntryParam); + } + } else + { + // picture was marked before and mouse cursor is on the picture now, so do the callback + if(motionLeaveParam >= 0 && callback != NULL && marked == true) + callback(motionLeaveParam); + marked = false; + } + needRender = true; +} + +void CPicture::setMouseData(SDL_MouseButtonEvent button) +{ + // left button is pressed + if(button.button == SDL_BUTTON_LEFT) + { + // if mouse button is pressed ON the button, set marked=true + if((button.state == SDL_PRESSED) && (button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + { + marked = true; + clicked = true; + } else if(button.state == SDL_RELEASED) + { + clicked = false; + // if mouse button is released ON the PICTURE (marked = true), then do the callback + if(marked && callback != NULL) + callback(clickedParam); + } + } + needRender = true; +} + +bool CPicture::render() +{ + // if we don't need to render, all is up to date, return true + if(!needRender) + return true; + needRender = false; + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_Picture); + Surf_Picture = NULL; + if((Surf_Picture = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) + return false; + SDL_SetColorKey(Surf_Picture, SDL_SRCCOLORKEY, SDL_MapRGB(Surf_Picture->format, 0, 0, 0)); + needSurface = false; + } + + CSurface::Draw(Surf_Picture, global::bmpArray[picture].surface, 0, 0); + + return true; +} diff --git a/CIO/CPicture.h b/CIO/CPicture.h index b576d9a..f329064 100644 --- a/CIO/CPicture.h +++ b/CIO/CPicture.h @@ -1,52 +1,52 @@ -#ifndef _CPICTURE_H -#define _CPICTURE_H - -#include "../includes.h" - -class CPicture -{ - friend class CDebug; - -private: - SDL_Surface* Surf_Picture; - bool needSurface; - bool needRender; - Uint16 x; - Uint16 y; - Uint16 w; - Uint16 h; - int picture; - bool marked; - bool clicked; - void (*callback)(int); - int clickedParam; - int motionEntryParam; - int motionLeaveParam; - -public: - // Constructor - Destructor - CPicture(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, int picture = -1); - ~CPicture(); - // Access - int getX() { return x; }; - int getY() { return y; }; - int getW() { return w; }; - int getH() { return h; }; - void setX(int x) { this->x = x; }; - void setY(int y) { this->y = y; }; - void setMouseData(SDL_MouseMotionEvent motion); - void setMouseData(SDL_MouseButtonEvent button); - bool render(); - SDL_Surface* getSurface() - { - render(); - return Surf_Picture; - }; - void setMotionParams(int entry, int leave) - { - motionEntryParam = entry; - motionLeaveParam = leave; - }; -}; - -#endif +#ifndef _CPICTURE_H +#define _CPICTURE_H + +#include "../includes.h" + +class CPicture +{ + friend class CDebug; + +private: + SDL_Surface* Surf_Picture; + bool needSurface; + bool needRender; + Uint16 x; + Uint16 y; + Uint16 w; + Uint16 h; + int picture; + bool marked; + bool clicked; + void (*callback)(int); + int clickedParam; + int motionEntryParam; + int motionLeaveParam; + +public: + // Constructor - Destructor + CPicture(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, int picture = -1); + ~CPicture(); + // Access + int getX() { return x; }; + int getY() { return y; }; + int getW() { return w; }; + int getH() { return h; }; + void setX(int x) { this->x = x; }; + void setY(int y) { this->y = y; }; + void setMouseData(SDL_MouseMotionEvent motion); + void setMouseData(SDL_MouseButtonEvent button); + bool render(); + SDL_Surface* getSurface() + { + render(); + return Surf_Picture; + }; + void setMotionParams(int entry, int leave) + { + motionEntryParam = entry; + motionLeaveParam = leave; + }; +}; + +#endif diff --git a/CIO/CSelectBox.cpp b/CIO/CSelectBox.cpp index 860f2f8..6f05fec 100644 --- a/CIO/CSelectBox.cpp +++ b/CIO/CSelectBox.cpp @@ -1,318 +1,318 @@ -#include "CSelectBox.h" -#include "../CSurface.h" -#include "../globals.h" -#include "CButton.h" -#include "CFont.h" - -CSelectBox::CSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) -{ - this->x = x; - this->y = y; - this->w = w; - this->h = h; - last_text_pos_y = 10; - this->fontsize = fontsize; - this->text_color = text_color; - setColor(bg_color); - // initialize CFont array - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - Entries[i] = NULL; - - Surf_SelectBox = NULL; - needSurface = true; - needRender = true; - rendered = false; - // button position is relative to the selectbox - ScrollUpButton = new CButton(NULL, 0, w - 1 - 20, 0, 20, 20, BUTTON_GREY, NULL, PICTURE_SMALL_ARROW_UP); - ScrollDownButton = new CButton(NULL, 0, w - 1 - 20, h - 1 - 20, 20, 20, BUTTON_GREY, NULL, PICTURE_SMALL_ARROW_DOWN); -} - -CSelectBox::~CSelectBox() -{ - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i]) - { - delete Entries[i]; - Entries[i] = NULL; - } - } - delete ScrollUpButton; - delete ScrollDownButton; - SDL_FreeSurface(Surf_SelectBox); -} - -void CSelectBox::setOption(const char* string, void (*callback)(int), int param) -{ - // explanation: row_height = row_separator + fontsize - int row_height = (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4)) + fontsize; - - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i] == NULL) - { - Entries[i] = new CFont(string, 10, last_text_pos_y, fontsize, FONT_YELLOW); - Entries[i]->setCallback(callback, param); - last_text_pos_y += row_height; - break; - } - } -} - -bool CSelectBox::hasRendered() -{ - if(rendered) - { - rendered = false; - return true; - } else - return false; -} - -void CSelectBox::setColor(int color) -{ - switch(color) - { - case BUTTON_GREY: - pic_foreground = BUTTON_GREY_DARK; - pic_background = BUTTON_GREY_BACKGROUND; - break; - - case BUTTON_RED1: - pic_foreground = BUTTON_RED1_DARK; - pic_background = BUTTON_RED1_BACKGROUND; - break; - - case BUTTON_GREEN1: - pic_foreground = BUTTON_GREEN1_DARK; - pic_background = BUTTON_GREEN1_BACKGROUND; - break; - - case BUTTON_GREEN2: - pic_foreground = BUTTON_GREEN2_DARK; - pic_background = BUTTON_GREEN2_BACKGROUND; - break; - - case BUTTON_RED2: - pic_foreground = BUTTON_RED2_DARK; - pic_background = BUTTON_RED2_BACKGROUND; - break; - - case BUTTON_STONE: - pic_foreground = BUTTON_STONE_DARK; - pic_background = BUTTON_STONE_BACKGROUND; - break; - - default: - pic_foreground = -1; - pic_background = -1; - break; - } - - needRender = true; -} - -void CSelectBox::setMouseData(SDL_MouseMotionEvent motion) -{ - // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate - // the motion-structure before give it to the buttons: x_absolute - x_selectbox, y_absolute - y_selectbox - motion.x -= x; - motion.y -= y; - ScrollUpButton->setMouseData(motion); - ScrollDownButton->setMouseData(motion); - needRender = true; -} - -void CSelectBox::setMouseData(SDL_MouseButtonEvent button) -{ - bool manipulated = false; - static bool scroll_up_button_marked = false; - static bool scroll_down_button_marked = false; - - // left button is pressed - if(button.button == SDL_BUTTON_LEFT) - { - // if mouse button is pressed ON the selectbox - if(button.state == SDL_PRESSED) - { - if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - { - // scroll up button - if((button.x > x + w - 20) && (button.y < y + 20)) - { - scroll_up_button_marked = true; - } - // scroll down button - else if((button.x > x + w - 20) && (button.y > y + h - 20)) - { - scroll_down_button_marked = true; - } - - // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate - // the motion-structure before give it to buttons and entries: x_absolute - x_selectbox, y_absolute - y_selectbox - button.x -= x; - button.y -= y; - manipulated = true; - - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i] != NULL) - Entries[i]->setMouseData(button); - } - } - } else if(button.state == SDL_RELEASED) - { - if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - { - // scroll up button - if(scroll_up_button_marked) - { - if((button.x > x + w - 20) && (button.y < y + 20)) - { - // test if first entry is on the most upper position - if(Entries[0] != NULL && Entries[0]->getY() < 10) - { - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i] != NULL) - Entries[i]->setY(Entries[i]->getY() + 10); - } - } - } - } - // scroll down button - else if(scroll_down_button_marked) - { - if((button.x > x + w - 20) && (button.y > y + h - 20)) - { - // test if last entry is on the most lower position - int j; - for(j = 0; j < MAXSELECTBOXENTRIES; j++) - { - if(Entries[j] == NULL) - break; - } - j--; - if(Entries[j] != NULL && Entries[j]->getY() > h - 10) - { - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i] != NULL) - Entries[i]->setY(Entries[i]->getY() - 10); - } - } - } - } - - // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate - // the motion-structure before give it to buttons and entries: x_absolute - x_selectbox, y_absolute - y_selectbox - button.x -= x; - button.y -= y; - manipulated = true; - - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i] != NULL) - Entries[i]->setMouseData(button); - } - } - scroll_up_button_marked = false; - scroll_down_button_marked = false; - } - // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate - // the motion-structure before give it to buttons and entries: x_absolute - x_selectbox, y_absolute - y_selectbox - if(!manipulated) - { - button.x -= x; - button.y -= y; - } - ScrollUpButton->setMouseData(button); - ScrollDownButton->setMouseData(button); - } - - needRender = true; -} - -bool CSelectBox::render() -{ - // position in the Surface 'Surf_Button' - Uint16 pos_x = 0; - Uint16 pos_y = 0; - // width and height of the button color source picture - Uint16 pic_w = 0; - Uint16 pic_h = 0; - - // if we don't need to render, all is up to date, return true - if(!needRender) - return true; - needRender = false; - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_SelectBox); - Surf_SelectBox = NULL; - if((Surf_SelectBox = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) - return false; - needSurface = false; - } - - // draw the pictures for background and foreground or, if not set, fill with black color - if(pic_background >= 0 && pic_foreground >= 0) - { - int pic; - pic = pic_foreground; - - // at first completly fill the background (not the fastest way, but simplier) - if(w <= global::bmpArray[pic].w) - pic_w = w; - else - pic_w = global::bmpArray[pic].w; - - if(h <= global::bmpArray[pic].h) - pic_h = h; - else - pic_h = global::bmpArray[pic].h; - - while(pos_x + pic_w <= Surf_SelectBox->w) - { - while(pos_y + pic_h <= Surf_SelectBox->h) - { - CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); - pos_y += pic_h; - } - - if(Surf_SelectBox->h - pos_y > 0) - CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, Surf_SelectBox->h - pos_y); - - pos_y = 0; - pos_x += pic_w; - } - - if(Surf_SelectBox->w - pos_x > 0) - { - while(pos_y + pic_h <= Surf_SelectBox->h) - { - CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_SelectBox->w - pos_x, pic_h); - pos_y += pic_h; - } - - if(Surf_SelectBox->h - pos_y > 0) - CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_SelectBox->w - pos_x, - Surf_SelectBox->h - pos_y); - } - } else - SDL_FillRect(Surf_SelectBox, NULL, SDL_MapRGB(Surf_SelectBox->format, 0, 0, 0)); - - for(int i = 0; i < MAXSELECTBOXENTRIES; i++) - { - if(Entries[i] != NULL) - CSurface::Draw(Surf_SelectBox, Entries[i]->getSurface(), Entries[i]->getX(), Entries[i]->getY()); - } - - CSurface::Draw(Surf_SelectBox, ScrollUpButton->getSurface(), w - 1 - 20, 0); - CSurface::Draw(Surf_SelectBox, ScrollDownButton->getSurface(), w - 1 - 20, h - 1 - 20); - - rendered = true; - - return true; -} +#include "CSelectBox.h" +#include "../CSurface.h" +#include "../globals.h" +#include "CButton.h" +#include "CFont.h" + +CSelectBox::CSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) +{ + this->x = x; + this->y = y; + this->w = w; + this->h = h; + last_text_pos_y = 10; + this->fontsize = fontsize; + this->text_color = text_color; + setColor(bg_color); + // initialize CFont array + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + Entries[i] = NULL; + + Surf_SelectBox = NULL; + needSurface = true; + needRender = true; + rendered = false; + // button position is relative to the selectbox + ScrollUpButton = new CButton(NULL, 0, w - 1 - 20, 0, 20, 20, BUTTON_GREY, NULL, PICTURE_SMALL_ARROW_UP); + ScrollDownButton = new CButton(NULL, 0, w - 1 - 20, h - 1 - 20, 20, 20, BUTTON_GREY, NULL, PICTURE_SMALL_ARROW_DOWN); +} + +CSelectBox::~CSelectBox() +{ + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i]) + { + delete Entries[i]; + Entries[i] = NULL; + } + } + delete ScrollUpButton; + delete ScrollDownButton; + SDL_FreeSurface(Surf_SelectBox); +} + +void CSelectBox::setOption(const char* string, void (*callback)(int), int param) +{ + // explanation: row_height = row_separator + fontsize + int row_height = (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4)) + fontsize; + + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i] == NULL) + { + Entries[i] = new CFont(string, 10, last_text_pos_y, fontsize, FONT_YELLOW); + Entries[i]->setCallback(callback, param); + last_text_pos_y += row_height; + break; + } + } +} + +bool CSelectBox::hasRendered() +{ + if(rendered) + { + rendered = false; + return true; + } else + return false; +} + +void CSelectBox::setColor(int color) +{ + switch(color) + { + case BUTTON_GREY: + pic_foreground = BUTTON_GREY_DARK; + pic_background = BUTTON_GREY_BACKGROUND; + break; + + case BUTTON_RED1: + pic_foreground = BUTTON_RED1_DARK; + pic_background = BUTTON_RED1_BACKGROUND; + break; + + case BUTTON_GREEN1: + pic_foreground = BUTTON_GREEN1_DARK; + pic_background = BUTTON_GREEN1_BACKGROUND; + break; + + case BUTTON_GREEN2: + pic_foreground = BUTTON_GREEN2_DARK; + pic_background = BUTTON_GREEN2_BACKGROUND; + break; + + case BUTTON_RED2: + pic_foreground = BUTTON_RED2_DARK; + pic_background = BUTTON_RED2_BACKGROUND; + break; + + case BUTTON_STONE: + pic_foreground = BUTTON_STONE_DARK; + pic_background = BUTTON_STONE_BACKGROUND; + break; + + default: + pic_foreground = -1; + pic_background = -1; + break; + } + + needRender = true; +} + +void CSelectBox::setMouseData(SDL_MouseMotionEvent motion) +{ + // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate + // the motion-structure before give it to the buttons: x_absolute - x_selectbox, y_absolute - y_selectbox + motion.x -= x; + motion.y -= y; + ScrollUpButton->setMouseData(motion); + ScrollDownButton->setMouseData(motion); + needRender = true; +} + +void CSelectBox::setMouseData(SDL_MouseButtonEvent button) +{ + bool manipulated = false; + static bool scroll_up_button_marked = false; + static bool scroll_down_button_marked = false; + + // left button is pressed + if(button.button == SDL_BUTTON_LEFT) + { + // if mouse button is pressed ON the selectbox + if(button.state == SDL_PRESSED) + { + if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + { + // scroll up button + if((button.x > x + w - 20) && (button.y < y + 20)) + { + scroll_up_button_marked = true; + } + // scroll down button + else if((button.x > x + w - 20) && (button.y > y + h - 20)) + { + scroll_down_button_marked = true; + } + + // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate + // the motion-structure before give it to buttons and entries: x_absolute - x_selectbox, y_absolute - y_selectbox + button.x -= x; + button.y -= y; + manipulated = true; + + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i] != NULL) + Entries[i]->setMouseData(button); + } + } + } else if(button.state == SDL_RELEASED) + { + if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + { + // scroll up button + if(scroll_up_button_marked) + { + if((button.x > x + w - 20) && (button.y < y + 20)) + { + // test if first entry is on the most upper position + if(Entries[0] != NULL && Entries[0]->getY() < 10) + { + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i] != NULL) + Entries[i]->setY(Entries[i]->getY() + 10); + } + } + } + } + // scroll down button + else if(scroll_down_button_marked) + { + if((button.x > x + w - 20) && (button.y > y + h - 20)) + { + // test if last entry is on the most lower position + int j; + for(j = 0; j < MAXSELECTBOXENTRIES; j++) + { + if(Entries[j] == NULL) + break; + } + j--; + if(Entries[j] != NULL && Entries[j]->getY() > h - 10) + { + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i] != NULL) + Entries[i]->setY(Entries[i]->getY() - 10); + } + } + } + } + + // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate + // the motion-structure before give it to buttons and entries: x_absolute - x_selectbox, y_absolute - y_selectbox + button.x -= x; + button.y -= y; + manipulated = true; + + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i] != NULL) + Entries[i]->setMouseData(button); + } + } + scroll_up_button_marked = false; + scroll_down_button_marked = false; + } + // IMPORTANT: we use the left upper corner of the selectbox as (x,y)=(0,0), so we have to manipulate + // the motion-structure before give it to buttons and entries: x_absolute - x_selectbox, y_absolute - y_selectbox + if(!manipulated) + { + button.x -= x; + button.y -= y; + } + ScrollUpButton->setMouseData(button); + ScrollDownButton->setMouseData(button); + } + + needRender = true; +} + +bool CSelectBox::render() +{ + // position in the Surface 'Surf_Button' + Uint16 pos_x = 0; + Uint16 pos_y = 0; + // width and height of the button color source picture + Uint16 pic_w = 0; + Uint16 pic_h = 0; + + // if we don't need to render, all is up to date, return true + if(!needRender) + return true; + needRender = false; + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_SelectBox); + Surf_SelectBox = NULL; + if((Surf_SelectBox = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) + return false; + needSurface = false; + } + + // draw the pictures for background and foreground or, if not set, fill with black color + if(pic_background >= 0 && pic_foreground >= 0) + { + int pic; + pic = pic_foreground; + + // at first completly fill the background (not the fastest way, but simplier) + if(w <= global::bmpArray[pic].w) + pic_w = w; + else + pic_w = global::bmpArray[pic].w; + + if(h <= global::bmpArray[pic].h) + pic_h = h; + else + pic_h = global::bmpArray[pic].h; + + while(pos_x + pic_w <= Surf_SelectBox->w) + { + while(pos_y + pic_h <= Surf_SelectBox->h) + { + CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); + pos_y += pic_h; + } + + if(Surf_SelectBox->h - pos_y > 0) + CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, Surf_SelectBox->h - pos_y); + + pos_y = 0; + pos_x += pic_w; + } + + if(Surf_SelectBox->w - pos_x > 0) + { + while(pos_y + pic_h <= Surf_SelectBox->h) + { + CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_SelectBox->w - pos_x, pic_h); + pos_y += pic_h; + } + + if(Surf_SelectBox->h - pos_y > 0) + CSurface::Draw(Surf_SelectBox, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_SelectBox->w - pos_x, + Surf_SelectBox->h - pos_y); + } + } else + SDL_FillRect(Surf_SelectBox, NULL, SDL_MapRGB(Surf_SelectBox->format, 0, 0, 0)); + + for(int i = 0; i < MAXSELECTBOXENTRIES; i++) + { + if(Entries[i] != NULL) + CSurface::Draw(Surf_SelectBox, Entries[i]->getSurface(), Entries[i]->getX(), Entries[i]->getY()); + } + + CSurface::Draw(Surf_SelectBox, ScrollUpButton->getSurface(), w - 1 - 20, 0); + CSurface::Draw(Surf_SelectBox, ScrollDownButton->getSurface(), w - 1 - 20, h - 1 - 20); + + rendered = true; + + return true; +} diff --git a/CIO/CSelectBox.h b/CIO/CSelectBox.h index 4a36300..12b1ca2 100644 --- a/CIO/CSelectBox.h +++ b/CIO/CSelectBox.h @@ -1,65 +1,65 @@ -#ifndef _CSELECTBOX_H -#define _CSELECTBOX_H - -#include "../includes.h" - -class CFont; -class CButton; - -// maximum number of entries for a selectbox -#define MAXSELECTBOXENTRIES 20000 - -class CSelectBox -{ - friend class CDebug; - -private: - SDL_Surface* Surf_SelectBox; - CFont* Entries[MAXSELECTBOXENTRIES]; - bool needSurface; - bool needRender; - Uint16 x; - Uint16 y; - Uint16 w; - Uint16 h; - Uint16 last_text_pos_y; - int fontsize; - int pic_background; - int pic_foreground; - int text_color; - // we need this to say the window if it needs to render, otherwise no chiffres are shown - bool rendered; - CButton* ScrollUpButton; - CButton* ScrollDownButton; - -public: - // Constructor - Destructor - CSelectBox(Uint16 x = 0, Uint16 y = 0, Uint16 w = 100, Uint16 h = 100, int fontsize = 14, int text_color = FONT_YELLOW, - int bg_color = -1); - ~CSelectBox(); - // Access; - int getX() { return x; } - int getY() { return y; } - int getW() { return w; } - int getH() { return h; } - void setX(int x) { this->x = x; } - void setY(int y) { this->y = y; } - bool hasRendered(); - void setMouseData(SDL_MouseButtonEvent button); - void setMouseData(SDL_MouseMotionEvent motion); - bool render(); - SDL_Surface* getSurface() - { - render(); - return Surf_SelectBox; - } - void setColor(int color); - void setTextColor(int color) - { - text_color = color; - needRender = true; - } - void setOption(const char* string, void (*callback)(int) = NULL, int param = 0); -}; - -#endif +#ifndef _CSELECTBOX_H +#define _CSELECTBOX_H + +#include "../includes.h" + +class CFont; +class CButton; + +// maximum number of entries for a selectbox +#define MAXSELECTBOXENTRIES 20000 + +class CSelectBox +{ + friend class CDebug; + +private: + SDL_Surface* Surf_SelectBox; + CFont* Entries[MAXSELECTBOXENTRIES]; + bool needSurface; + bool needRender; + Uint16 x; + Uint16 y; + Uint16 w; + Uint16 h; + Uint16 last_text_pos_y; + int fontsize; + int pic_background; + int pic_foreground; + int text_color; + // we need this to say the window if it needs to render, otherwise no chiffres are shown + bool rendered; + CButton* ScrollUpButton; + CButton* ScrollDownButton; + +public: + // Constructor - Destructor + CSelectBox(Uint16 x = 0, Uint16 y = 0, Uint16 w = 100, Uint16 h = 100, int fontsize = 14, int text_color = FONT_YELLOW, + int bg_color = -1); + ~CSelectBox(); + // Access; + int getX() { return x; } + int getY() { return y; } + int getW() { return w; } + int getH() { return h; } + void setX(int x) { this->x = x; } + void setY(int y) { this->y = y; } + bool hasRendered(); + void setMouseData(SDL_MouseButtonEvent button); + void setMouseData(SDL_MouseMotionEvent motion); + bool render(); + SDL_Surface* getSurface() + { + render(); + return Surf_SelectBox; + } + void setColor(int color); + void setTextColor(int color) + { + text_color = color; + needRender = true; + } + void setOption(const char* string, void (*callback)(int) = NULL, int param = 0); +}; + +#endif diff --git a/CIO/CTextfield.cpp b/CIO/CTextfield.cpp index 219e3e0..4a93bb5 100644 --- a/CIO/CTextfield.cpp +++ b/CIO/CTextfield.cpp @@ -1,454 +1,454 @@ -#include "CTextfield.h" -#include "../CSurface.h" -#include "../globals.h" -#include "CFont.h" - -CTextfield::CTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int fontsize, int text_color, int bg_color, bool button_style) -{ - active = false; - this->x = x; - this->y = y; - this->cols = (cols < 1 ? 1 : cols); - this->rows = (rows < 1 ? 1 : rows); - this->fontsize = fontsize; - // calc width by maximum number of chiffres (cols) + one blinking chiffre * average pixel_width of a chiffre (fontsize-3) + tolerance - // for borders - this->w = (this->cols + 1) * (fontsize - 3) + 4; - // calc height ----------------| this is the row_separator from CFont.cpp |---- + tolerance for borders - this->h = this->rows * (fontsize + (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4))) + 4; - this->text_color = text_color; - setColor(bg_color); - // allocate memory for the text: chiffres (cols) + '\n' for each line * rows + blinking chiffre + '\0' - text.resize((this->cols + 1) * this->rows + 2); - - Surf_Text = NULL; - needSurface = true; - needRender = true; - rendered = false; - this->button_style = button_style; - textObj = new CFont((const char*)NULL, x, y, fontsize, text_color); -} - -CTextfield::~CTextfield() -{ - SDL_FreeSurface(Surf_Text); - delete textObj; -} - -bool CTextfield::hasRendered() -{ - if(rendered) - { - rendered = false; - return true; - } else - return false; -} - -void CTextfield::setColor(int color) -{ - switch(color) - { - case BUTTON_GREY: - pic_foreground = BUTTON_GREY_DARK; - pic_background = BUTTON_GREY_BACKGROUND; - break; - - case BUTTON_RED1: - pic_foreground = BUTTON_RED1_DARK; - pic_background = BUTTON_RED1_BACKGROUND; - break; - - case BUTTON_GREEN1: - pic_foreground = BUTTON_GREEN1_DARK; - pic_background = BUTTON_GREEN1_BACKGROUND; - break; - - case BUTTON_GREEN2: - pic_foreground = BUTTON_GREEN2_DARK; - pic_background = BUTTON_GREEN2_BACKGROUND; - break; - - case BUTTON_RED2: - pic_foreground = BUTTON_RED2_DARK; - pic_background = BUTTON_RED2_BACKGROUND; - break; - - case BUTTON_STONE: - pic_foreground = BUTTON_STONE_DARK; - pic_background = BUTTON_STONE_BACKGROUND; - break; - - default: - pic_foreground = -1; - pic_background = -1; - break; - } - - needRender = true; -} - -void CTextfield::setText(const char* text) -{ - char* txtPtr = &this->text[0]; - int col_ctr = 1, row_ctr = 1; - - while(*text != '\0') - { - if(txtPtr >= &this->text.back() - 2) - break; - - if(col_ctr > cols) - { - if(row_ctr < rows) - { - *txtPtr = '\n'; - txtPtr++; - row_ctr++; - } else - break; - col_ctr = 1; - } - - *txtPtr++ = *text++; - col_ctr++; - } - *txtPtr = '\0'; -} - -void CTextfield::setMouseData(SDL_MouseButtonEvent button) -{ - // left button is pressed - if(button.button == SDL_BUTTON_LEFT) - { - // if mouse button is pressed ON the textfield, set active=true - if(button.state == SDL_PRESSED) - { - if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - active = true; - else - active = false; - } - } - needRender = true; -} - -void CTextfield::setKeyboardData(SDL_KeyboardEvent key) -{ - unsigned char chiffre = '\0'; - char* txtPtr = &text[0]; - int col_ctr = 1, row_ctr = 1; - - if(!active) - return; - - if(key.type == SDL_KEYDOWN) - { - // go to '\0' - while(*txtPtr != '\0') - { - col_ctr++; - if(*txtPtr == '\n') - { - row_ctr++; - col_ctr = 1; - } - txtPtr++; - } - // decrement col_ctr cause '\0' is not counted - col_ctr--; - // end of text memory reached? ( 'cols'-chiffres from the user + '\n' in each row * rows + blinking chiffre + '\0' -1 for pointer - // adress range - if(txtPtr >= &text.back() - 2) - { - // end reached, user may only delete chiffres - if(key.keysym.sym != SDLK_BACKSPACE) - return; - } - - switch(key.keysym.sym) - { - case SDLK_BACKSPACE: - if(txtPtr > &text[0]) - { - txtPtr--; - *txtPtr = '\0'; - } - break; - - case SDLK_RETURN: - if(row_ctr < rows) - { - *txtPtr = '\n'; - txtPtr++; - *txtPtr = '\0'; - } - break; - - default: - if(col_ctr >= cols) - { - if(row_ctr < rows) - { - *txtPtr = '\n'; - txtPtr++; - } else - break; - } - // decide which chiffre to save - if((key.keysym.sym >= 48 && key.keysym.sym <= 57) || key.keysym.sym == 32) - chiffre = (unsigned char)key.keysym.sym; - else if(key.keysym.sym >= 97 && key.keysym.sym <= 122) - { - chiffre = (unsigned char)key.keysym.sym; - // test for capital letters (small letter and shift pressed) - if(key.keysym.mod & KMOD_SHIFT) - chiffre -= 32; - } else if(key.keysym.sym == 45) - { - chiffre = (unsigned char)key.keysym.sym; - // test for '_' ('-' and shift pressed) - if(key.keysym.mod & KMOD_SHIFT) - chiffre = 95; - } else if(key.keysym.sym == 46 || key.keysym.sym == 47) - { - chiffre = (unsigned char)key.keysym.sym; - } - - if(chiffre != '\0') - { - *txtPtr = chiffre; - txtPtr++; - *txtPtr = '\0'; - } - break; - } - needRender = true; - } -} - -bool CTextfield::render() -{ - // position in the Surface 'Surf_Button' - Uint16 pos_x = 0; - Uint16 pos_y = 0; - // width and height of the button color source picture - Uint16 pic_w = 0; - Uint16 pic_h = 0; - // we save the time to let a chiffre blink - static Uint32 currentTime; - static Uint32 lastTime = SDL_GetTicks(); - static bool blinking_chiffre = false; - // if the textfield is active, we need to render to show the blinking chiffre - if(active) - { - currentTime = SDL_GetTicks(); - if(currentTime - lastTime > 500) - { - lastTime = currentTime; - - if(blinking_chiffre) - { - blinking_chiffre = false; - } else - { - blinking_chiffre = true; - } - } - needRender = true; - } - - // if we don't need to render, all is up to date, return true - if(!needRender) - return true; - needRender = false; - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_Text); - Surf_Text = NULL; - if((Surf_Text = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) - return false; - needSurface = false; - } - - // draw the pictures for background and foreground or, if not set, fill with black color - if(pic_background >= 0 && pic_foreground >= 0) - { - // in case the textfield should look like a button, we do it, otherwise we use pic_foreground for the background - int pic; - if(button_style) - pic = pic_background; - else - pic = pic_foreground; - - // at first completly fill the background (not the fastest way, but simplier) - if(w <= global::bmpArray[pic].w) - pic_w = w; - else - pic_w = global::bmpArray[pic].w; - - if(h <= global::bmpArray[pic].h) - pic_h = h; - else - pic_h = global::bmpArray[pic].h; - - while(pos_x + pic_w <= Surf_Text->w) - { - while(pos_y + pic_h <= Surf_Text->h) - { - CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); - pos_y += pic_h; - } - - if(Surf_Text->h - pos_y > 0) - CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Text->h - pos_y); - - pos_y = 0; - pos_x += pic_w; - } - - if(Surf_Text->w - pos_x > 0) - { - while(pos_y + pic_h <= Surf_Text->h) - { - CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_Text->w - pos_x, pic_h); - pos_y += pic_h; - } - - if(Surf_Text->h - pos_y > 0) - CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_Text->w - pos_x, Surf_Text->h - pos_y); - } - - // if not button_style, we are finished, otherwise continue drawing - if(button_style) - { - // draw partial black frame - if(active) - { - // black frame is left and up - // draw vertical line - pos_x = 0; - for(int y = 0; y < h; y++) - CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); - - // draw vertical line - pos_x = 1; - for(int y = 0; y < h - 1; y++) - CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); - - // draw horizontal line - pos_y = 0; - for(int x = 0; x < w; x++) - CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); - - // draw horizontal line - pos_y = 1; - for(int x = 0; x < w - 1; x++) - CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); - } else - { - // black frame is right and down - // draw vertical line - pos_x = w - 1; - for(int y = 0; y < h; y++) - CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); - - // draw vertical line - pos_x = w - 2; - for(int y = 1; y < h; y++) - CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); - - // draw horizontal line - pos_y = h - 1; - for(int x = 0; x < w; x++) - CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); - - // draw horizontal line - pos_y = h - 2; - for(int x = 1; x < w; x++) - CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); - } - - // draw the foreground --> at first the color (marked or unmarked) and then the picture or text - if(w <= global::bmpArray[pic_foreground].w) - pic_w = w; - else - pic_w = global::bmpArray[pic_foreground].w; - - if(h <= global::bmpArray[pic_foreground].h) - pic_h = h; - else - pic_h = global::bmpArray[pic_foreground].h; - - // beware overdrawing the left and upper frame - pos_x = 2; - pos_y = 2; - - // '-2' follows a few times, this means: beware overdrawing the right and lower frame - while(pos_x + pic_w <= Surf_Text->w - 2) - { - while(pos_y + pic_h <= Surf_Text->h - 2) - { - CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); - pos_y += pic_h; - } - - if(Surf_Text->h - 2 - pos_y > 0) - CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, pic_w, - Surf_Text->h - 2 - pos_y); - - pos_y = 2; - pos_x += pic_w; - } - - if(Surf_Text->w - 2 - pos_x > 0) - { - while(pos_y + pic_h <= Surf_Text->h - 2) - { - CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, Surf_Text->w - 2 - pos_x, - pic_h); - pos_y += pic_h; - } - - if(Surf_Text->h - 2 - pos_y > 0) - CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, Surf_Text->w - 2 - pos_x, - Surf_Text->h - 2 - pos_y); - } - } - } else - SDL_FillRect(Surf_Text, NULL, SDL_MapRGB(Surf_Text->format, 0, 0, 0)); - - char* txtPtr = &text[0]; - - // go to '\0' - while(*txtPtr != '\0') - txtPtr++; - // add blinking chiffre if necessary - if(blinking_chiffre && active) - { - *txtPtr = '>'; - txtPtr++; - *txtPtr = '\0'; - } - - // write text - // textObj->setText(text); - delete textObj; - textObj = NULL; - textObj = new CFont(&text[0], x, y, fontsize, text_color); - - // delete blinking chiffre (otherwise it could be written between user input chiffres) - if(blinking_chiffre && active) - { - txtPtr--; - *txtPtr = '\0'; - } - - // blit text surface - CSurface::Draw(Surf_Text, textObj->getSurface(), 2, 2); - - rendered = true; - - return true; -} +#include "CTextfield.h" +#include "../CSurface.h" +#include "../globals.h" +#include "CFont.h" + +CTextfield::CTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int fontsize, int text_color, int bg_color, bool button_style) +{ + active = false; + this->x = x; + this->y = y; + this->cols = (cols < 1 ? 1 : cols); + this->rows = (rows < 1 ? 1 : rows); + this->fontsize = fontsize; + // calc width by maximum number of chiffres (cols) + one blinking chiffre * average pixel_width of a chiffre (fontsize-3) + tolerance + // for borders + this->w = (this->cols + 1) * (fontsize - 3) + 4; + // calc height ----------------| this is the row_separator from CFont.cpp |---- + tolerance for borders + this->h = this->rows * (fontsize + (fontsize == 9 ? 1 : (fontsize == 11 ? 3 : 4))) + 4; + this->text_color = text_color; + setColor(bg_color); + // allocate memory for the text: chiffres (cols) + '\n' for each line * rows + blinking chiffre + '\0' + text.resize((this->cols + 1) * this->rows + 2); + + Surf_Text = NULL; + needSurface = true; + needRender = true; + rendered = false; + this->button_style = button_style; + textObj = new CFont((const char*)NULL, x, y, fontsize, text_color); +} + +CTextfield::~CTextfield() +{ + SDL_FreeSurface(Surf_Text); + delete textObj; +} + +bool CTextfield::hasRendered() +{ + if(rendered) + { + rendered = false; + return true; + } else + return false; +} + +void CTextfield::setColor(int color) +{ + switch(color) + { + case BUTTON_GREY: + pic_foreground = BUTTON_GREY_DARK; + pic_background = BUTTON_GREY_BACKGROUND; + break; + + case BUTTON_RED1: + pic_foreground = BUTTON_RED1_DARK; + pic_background = BUTTON_RED1_BACKGROUND; + break; + + case BUTTON_GREEN1: + pic_foreground = BUTTON_GREEN1_DARK; + pic_background = BUTTON_GREEN1_BACKGROUND; + break; + + case BUTTON_GREEN2: + pic_foreground = BUTTON_GREEN2_DARK; + pic_background = BUTTON_GREEN2_BACKGROUND; + break; + + case BUTTON_RED2: + pic_foreground = BUTTON_RED2_DARK; + pic_background = BUTTON_RED2_BACKGROUND; + break; + + case BUTTON_STONE: + pic_foreground = BUTTON_STONE_DARK; + pic_background = BUTTON_STONE_BACKGROUND; + break; + + default: + pic_foreground = -1; + pic_background = -1; + break; + } + + needRender = true; +} + +void CTextfield::setText(const char* text) +{ + char* txtPtr = &this->text[0]; + int col_ctr = 1, row_ctr = 1; + + while(*text != '\0') + { + if(txtPtr >= &this->text.back() - 2) + break; + + if(col_ctr > cols) + { + if(row_ctr < rows) + { + *txtPtr = '\n'; + txtPtr++; + row_ctr++; + } else + break; + col_ctr = 1; + } + + *txtPtr++ = *text++; + col_ctr++; + } + *txtPtr = '\0'; +} + +void CTextfield::setMouseData(SDL_MouseButtonEvent button) +{ + // left button is pressed + if(button.button == SDL_BUTTON_LEFT) + { + // if mouse button is pressed ON the textfield, set active=true + if(button.state == SDL_PRESSED) + { + if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + active = true; + else + active = false; + } + } + needRender = true; +} + +void CTextfield::setKeyboardData(SDL_KeyboardEvent key) +{ + unsigned char chiffre = '\0'; + char* txtPtr = &text[0]; + int col_ctr = 1, row_ctr = 1; + + if(!active) + return; + + if(key.type == SDL_KEYDOWN) + { + // go to '\0' + while(*txtPtr != '\0') + { + col_ctr++; + if(*txtPtr == '\n') + { + row_ctr++; + col_ctr = 1; + } + txtPtr++; + } + // decrement col_ctr cause '\0' is not counted + col_ctr--; + // end of text memory reached? ( 'cols'-chiffres from the user + '\n' in each row * rows + blinking chiffre + '\0' -1 for pointer + // adress range + if(txtPtr >= &text.back() - 2) + { + // end reached, user may only delete chiffres + if(key.keysym.sym != SDLK_BACKSPACE) + return; + } + + switch(key.keysym.sym) + { + case SDLK_BACKSPACE: + if(txtPtr > &text[0]) + { + txtPtr--; + *txtPtr = '\0'; + } + break; + + case SDLK_RETURN: + if(row_ctr < rows) + { + *txtPtr = '\n'; + txtPtr++; + *txtPtr = '\0'; + } + break; + + default: + if(col_ctr >= cols) + { + if(row_ctr < rows) + { + *txtPtr = '\n'; + txtPtr++; + } else + break; + } + // decide which chiffre to save + if((key.keysym.sym >= 48 && key.keysym.sym <= 57) || key.keysym.sym == 32) + chiffre = (unsigned char)key.keysym.sym; + else if(key.keysym.sym >= 97 && key.keysym.sym <= 122) + { + chiffre = (unsigned char)key.keysym.sym; + // test for capital letters (small letter and shift pressed) + if(key.keysym.mod & KMOD_SHIFT) + chiffre -= 32; + } else if(key.keysym.sym == 45) + { + chiffre = (unsigned char)key.keysym.sym; + // test for '_' ('-' and shift pressed) + if(key.keysym.mod & KMOD_SHIFT) + chiffre = 95; + } else if(key.keysym.sym == 46 || key.keysym.sym == 47) + { + chiffre = (unsigned char)key.keysym.sym; + } + + if(chiffre != '\0') + { + *txtPtr = chiffre; + txtPtr++; + *txtPtr = '\0'; + } + break; + } + needRender = true; + } +} + +bool CTextfield::render() +{ + // position in the Surface 'Surf_Button' + Uint16 pos_x = 0; + Uint16 pos_y = 0; + // width and height of the button color source picture + Uint16 pic_w = 0; + Uint16 pic_h = 0; + // we save the time to let a chiffre blink + static Uint32 currentTime; + static Uint32 lastTime = SDL_GetTicks(); + static bool blinking_chiffre = false; + // if the textfield is active, we need to render to show the blinking chiffre + if(active) + { + currentTime = SDL_GetTicks(); + if(currentTime - lastTime > 500) + { + lastTime = currentTime; + + if(blinking_chiffre) + { + blinking_chiffre = false; + } else + { + blinking_chiffre = true; + } + } + needRender = true; + } + + // if we don't need to render, all is up to date, return true + if(!needRender) + return true; + needRender = false; + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_Text); + Surf_Text = NULL; + if((Surf_Text = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) + return false; + needSurface = false; + } + + // draw the pictures for background and foreground or, if not set, fill with black color + if(pic_background >= 0 && pic_foreground >= 0) + { + // in case the textfield should look like a button, we do it, otherwise we use pic_foreground for the background + int pic; + if(button_style) + pic = pic_background; + else + pic = pic_foreground; + + // at first completly fill the background (not the fastest way, but simplier) + if(w <= global::bmpArray[pic].w) + pic_w = w; + else + pic_w = global::bmpArray[pic].w; + + if(h <= global::bmpArray[pic].h) + pic_h = h; + else + pic_h = global::bmpArray[pic].h; + + while(pos_x + pic_w <= Surf_Text->w) + { + while(pos_y + pic_h <= Surf_Text->h) + { + CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); + pos_y += pic_h; + } + + if(Surf_Text->h - pos_y > 0) + CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Text->h - pos_y); + + pos_y = 0; + pos_x += pic_w; + } + + if(Surf_Text->w - pos_x > 0) + { + while(pos_y + pic_h <= Surf_Text->h) + { + CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_Text->w - pos_x, pic_h); + pos_y += pic_h; + } + + if(Surf_Text->h - pos_y > 0) + CSurface::Draw(Surf_Text, global::bmpArray[pic].surface, pos_x, pos_y, 0, 0, Surf_Text->w - pos_x, Surf_Text->h - pos_y); + } + + // if not button_style, we are finished, otherwise continue drawing + if(button_style) + { + // draw partial black frame + if(active) + { + // black frame is left and up + // draw vertical line + pos_x = 0; + for(int y = 0; y < h; y++) + CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); + + // draw vertical line + pos_x = 1; + for(int y = 0; y < h - 1; y++) + CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); + + // draw horizontal line + pos_y = 0; + for(int x = 0; x < w; x++) + CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); + + // draw horizontal line + pos_y = 1; + for(int x = 0; x < w - 1; x++) + CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); + } else + { + // black frame is right and down + // draw vertical line + pos_x = w - 1; + for(int y = 0; y < h; y++) + CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); + + // draw vertical line + pos_x = w - 2; + for(int y = 1; y < h; y++) + CSurface::DrawPixel_RGB(Surf_Text, pos_x, y, 0, 0, 0); + + // draw horizontal line + pos_y = h - 1; + for(int x = 0; x < w; x++) + CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); + + // draw horizontal line + pos_y = h - 2; + for(int x = 1; x < w; x++) + CSurface::DrawPixel_RGB(Surf_Text, x, pos_y, 0, 0, 0); + } + + // draw the foreground --> at first the color (marked or unmarked) and then the picture or text + if(w <= global::bmpArray[pic_foreground].w) + pic_w = w; + else + pic_w = global::bmpArray[pic_foreground].w; + + if(h <= global::bmpArray[pic_foreground].h) + pic_h = h; + else + pic_h = global::bmpArray[pic_foreground].h; + + // beware overdrawing the left and upper frame + pos_x = 2; + pos_y = 2; + + // '-2' follows a few times, this means: beware overdrawing the right and lower frame + while(pos_x + pic_w <= Surf_Text->w - 2) + { + while(pos_y + pic_h <= Surf_Text->h - 2) + { + CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); + pos_y += pic_h; + } + + if(Surf_Text->h - 2 - pos_y > 0) + CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, pic_w, + Surf_Text->h - 2 - pos_y); + + pos_y = 2; + pos_x += pic_w; + } + + if(Surf_Text->w - 2 - pos_x > 0) + { + while(pos_y + pic_h <= Surf_Text->h - 2) + { + CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, Surf_Text->w - 2 - pos_x, + pic_h); + pos_y += pic_h; + } + + if(Surf_Text->h - 2 - pos_y > 0) + CSurface::Draw(Surf_Text, global::bmpArray[pic_foreground].surface, pos_x, pos_y, 0, 0, Surf_Text->w - 2 - pos_x, + Surf_Text->h - 2 - pos_y); + } + } + } else + SDL_FillRect(Surf_Text, NULL, SDL_MapRGB(Surf_Text->format, 0, 0, 0)); + + char* txtPtr = &text[0]; + + // go to '\0' + while(*txtPtr != '\0') + txtPtr++; + // add blinking chiffre if necessary + if(blinking_chiffre && active) + { + *txtPtr = '>'; + txtPtr++; + *txtPtr = '\0'; + } + + // write text + // textObj->setText(text); + delete textObj; + textObj = NULL; + textObj = new CFont(&text[0], x, y, fontsize, text_color); + + // delete blinking chiffre (otherwise it could be written between user input chiffres) + if(blinking_chiffre && active) + { + txtPtr--; + *txtPtr = '\0'; + } + + // blit text surface + CSurface::Draw(Surf_Text, textObj->getSurface(), 2, 2); + + rendered = true; + + return true; +} diff --git a/CIO/CTextfield.h b/CIO/CTextfield.h index 1b36963..c84c345 100644 --- a/CIO/CTextfield.h +++ b/CIO/CTextfield.h @@ -1,72 +1,72 @@ -#ifndef _CTEXTFIELD_H -#define _CTEXTFIELD_H - -#include "../includes.h" -#include - -class CFont; - -class CTextfield -{ - friend class CDebug; - -private: - SDL_Surface* Surf_Text; - CFont* textObj; - bool needSurface; - bool needRender; - Uint16 x; - Uint16 y; - Uint16 w; - Uint16 h; - Uint16 cols; - Uint16 rows; - int fontsize; - int pic_background; - int pic_foreground; - std::vector text; - int text_color; - // if active, keyboard data will be delivered and the cursor is blinking - bool active; - // we need this to say the window if it needs to render, otherwise no blinking cursor and no chiffres are shown - bool rendered; - // if true, the textfield looks like a button - bool button_style; - -public: - // Constructor - Destructor - CTextfield(Uint16 x = 0, Uint16 y = 0, Uint16 cols = 10, Uint16 rows = 1, int fontsize = 14, int text_color = FONT_YELLOW, - int bg_color = -1, bool button_style = false); - ~CTextfield(); - // Access - int getX() { return x; }; - int getY() { return y; }; - int getW() { return w; }; - int getH() { return h; }; - int getCols() { return cols; }; - int getRows() { return rows; }; - void setX(int x) { this->x = x; } - void setY(int y) { this->y = y; } - void setText(const char* text); - void setActive() { active = true; } - void setInactive() { active = false; } - bool isActive() { return active; } - bool hasRendered(); - void setMouseData(SDL_MouseButtonEvent button); - void setKeyboardData(SDL_KeyboardEvent key); - bool render(); - SDL_Surface* getSurface() - { - render(); - return Surf_Text; - } - void setColor(int color); - void setTextColor(int color) - { - text_color = color; - needRender = true; - } - const char* getText() { return &text[0]; } -}; - -#endif +#ifndef _CTEXTFIELD_H +#define _CTEXTFIELD_H + +#include "../includes.h" +#include + +class CFont; + +class CTextfield +{ + friend class CDebug; + +private: + SDL_Surface* Surf_Text; + CFont* textObj; + bool needSurface; + bool needRender; + Uint16 x; + Uint16 y; + Uint16 w; + Uint16 h; + Uint16 cols; + Uint16 rows; + int fontsize; + int pic_background; + int pic_foreground; + std::vector text; + int text_color; + // if active, keyboard data will be delivered and the cursor is blinking + bool active; + // we need this to say the window if it needs to render, otherwise no blinking cursor and no chiffres are shown + bool rendered; + // if true, the textfield looks like a button + bool button_style; + +public: + // Constructor - Destructor + CTextfield(Uint16 x = 0, Uint16 y = 0, Uint16 cols = 10, Uint16 rows = 1, int fontsize = 14, int text_color = FONT_YELLOW, + int bg_color = -1, bool button_style = false); + ~CTextfield(); + // Access + int getX() { return x; }; + int getY() { return y; }; + int getW() { return w; }; + int getH() { return h; }; + int getCols() { return cols; }; + int getRows() { return rows; }; + void setX(int x) { this->x = x; } + void setY(int y) { this->y = y; } + void setText(const char* text); + void setActive() { active = true; } + void setInactive() { active = false; } + bool isActive() { return active; } + bool hasRendered(); + void setMouseData(SDL_MouseButtonEvent button); + void setKeyboardData(SDL_KeyboardEvent key); + bool render(); + SDL_Surface* getSurface() + { + render(); + return Surf_Text; + } + void setColor(int color); + void setTextColor(int color) + { + text_color = color; + needRender = true; + } + const char* getText() { return &text[0]; } +}; + +#endif diff --git a/CIO/CWindow.cpp b/CIO/CWindow.cpp index 6fecc21..975db4a 100644 --- a/CIO/CWindow.cpp +++ b/CIO/CWindow.cpp @@ -1,837 +1,837 @@ -#include "CWindow.h" -#include "../CGame.h" -#include "../CSurface.h" -#include "../globals.h" -#include "CButton.h" -#include "CFont.h" -#include "CPicture.h" -#include "CSelectBox.h" -#include "CTextfield.h" - -CWindow::CWindow(void callback(int), int callbackQuitMessage, Uint16 x, Uint16 y, Uint16 w, Uint16 h, const char* title, int color, - Uint8 flags) -{ - marked = true; - clicked = false; - this->x = x; - this->y = y; - // ensure window is big enough to take all basic pictures needed - // if ( w < (global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + global::bmpArray[WINDOW_UPPER_FRAME].w + - // global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w) ) - // this->w = global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + global::bmpArray[WINDOW_UPPER_FRAME].w + - // global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w; - // else - this->w = w; - // if ( h < (global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h) ) - // this->h = global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h; - // else - this->h = h; - canMove = (flags & WINDOW_MOVE) ? true : false; - canClose = (flags & WINDOW_CLOSE) ? true : false; - canClose_marked = false; - canClose_clicked = false; - canMinimize = (flags & WINDOW_MINIMIZE) ? true : false; - canMinimize_marked = false; - canMinimize_clicked = false; - canResize = (flags & WINDOW_RESIZE) ? true : false; - canResize_marked = false; - canResize_clicked = false; - minimized = false; - priority = 0; - pic_background = color; - for(int i = 0; i < MAXBUTTONS; i++) - buttons[i] = NULL; - for(int i = 0; i < MAXTEXTS; i++) - texts[i] = NULL; - for(int i = 0; i < MAXPICTURES; i++) - pictures[i] = NULL; - for(int i = 0; i < MAXPICTURES; i++) - { - static_pictures[i].x = 0; - static_pictures[i].y = 0; - static_pictures[i].pic = -1; - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - textfields[i] = NULL; - for(int i = 0; i < MAXSELECTBOXES; i++) - selectboxes[i] = NULL; - - this->title = title; - this->callback = callback; - this->callbackQuitMessage = callbackQuitMessage; - Surf_Window = NULL; - needSurface = true; - needRender = true; - active = true; - waste = false; - moving = false; - resizing = false; -} - -CWindow::~CWindow() -{ - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - delete buttons[i]; - } - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] != NULL) - delete texts[i]; - } - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - delete pictures[i]; - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - delete textfields[i]; - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - delete selectboxes[i]; - } - SDL_FreeSurface(Surf_Window); -} - -void CWindow::setTitle(const char* title) -{ - this->title = title; - needRender = true; -} - -void CWindow::setColor(int color) -{ - pic_background = color; - needRender = true; -} - -bool CWindow::hasActiveInputElement() -{ - for(int i = 0; i < MAXTEXTFIELDS; i++) - if(textfields[i] != NULL && textfields[i]->isActive()) - return true; - return false; -} - -void CWindow::setMouseData(SDL_MouseMotionEvent motion) -{ - // cursor is on the title frame (+/-2 and +/-4 are only for a good optic) - if((motion.x >= x + global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + 2) - && (motion.x < x + w - global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w - 2) && (motion.y >= y + 4) - && (motion.y < y + +global::bmpArray[WINDOW_UPPER_FRAME].h - 4)) - { - // left button was pressed while moving - if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) - moving = true; - clicked = true; - } else if(!moving) - clicked = false; - - if(!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))) - moving = false; - if(moving && canMove) - { - x += motion.xrel; - y += motion.yrel; - // make sure to not move the window outside the display surface - if(x < 0) - x = 0; - if(x + w >= global::s2->getDisplaySurface()->w) - x = global::s2->getDisplaySurface()->w - w - 1; - if(y < 0) - y = 0; - if(y + h >= global::s2->getDisplaySurface()->h) - y = global::s2->getDisplaySurface()->h - h - 1; - } - - // check whats happen to the close button - if(canClose) - { - // cursor is on the button (+/-2 is only for the optic) - if((motion.x >= x + 2) && (motion.x < x + global::bmpArray[WINDOW_BUTTON_CLOSE].w - 2) && (motion.y >= y + 2) - && (motion.y < y + global::bmpArray[WINDOW_BUTTON_CLOSE].h - 2)) - canClose_marked = true; - else - canClose_marked = false; - } - // check whats happen to the minimize button - if(canMinimize) - { - // cursor is on the button (+/-2 is only for the optic) - if((motion.x >= x + w - global::bmpArray[WINDOW_BUTTON_MINIMIZE].w + 2) && (motion.x < x + w - 2) && (motion.y >= y + 2) - && (motion.y < y + global::bmpArray[WINDOW_BUTTON_MINIMIZE].h - 2)) - canMinimize_marked = true; - else - canMinimize_marked = false; - } - // check whats happen to the resize button - if(canResize) - { - // cursor is on the button (+/-2 is only for the optic) - if((motion.x >= x + w - global::bmpArray[WINDOW_BUTTON_RESIZE].w + 2) && (motion.x < x + w - 2) - && (motion.y >= y + h - global::bmpArray[WINDOW_BUTTON_RESIZE].h + 2) && (motion.y < y + h - 2)) - { - // left button was pressed while moving - if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) - resizing = true; - canResize_marked = true; - } else if(!resizing) - canResize_marked = false; - - if(!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))) - resizing = false; - if(resizing) - { - // only resize if not minimized - if(!minimized) - { - w += motion.xrel; - h += motion.yrel; - - // MISSING: we have to test if window size is under minimum - - // the window has resized, so we need a new surface - needSurface = true; - } - } - } - - // deliver mouse data to the content objects of the window (if mouse cursor is inside the window) - if((motion.x >= x) && (motion.x < x + w) && (motion.y >= y) && (motion.y < y + h)) - { - // IMPORTANT: we use the left upper corner of the window as (x,y)=(0,0), so we have to manipulate - // the motion-structure before give it to buttons, pictures....: x_absolute - x_window, y_absolute - y_window - motion.x -= x; - motion.y -= y; - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - pictures[i]->setMouseData(motion); - } - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - buttons[i]->setMouseData(motion); - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - selectboxes[i]->setMouseData(motion); - } - } - - // at least call the callback if a mouse button is pressed - if(motion.state == SDL_PRESSED) - callback(WINDOW_CLICKED_CALL); - - needRender = true; -} - -void CWindow::setMouseData(SDL_MouseButtonEvent button) -{ - // at first check if the right mouse button was pressed, cause in this case we will close the window - if(button.button == SDL_BUTTON_RIGHT && button.state == SDL_PRESSED) - { - callback(callbackQuitMessage); - return; - } - - // save width and height in case we minimize the window (the initializing values are for preventing any mistakes and compilerwarning --- - // in fact: uninitialized values are only a problem if the window is created minimized, but this will not happen) - static int maximized_h = global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h; - if(!minimized) - maximized_h = h; - - // left button is pressed - if(button.button == SDL_BUTTON_LEFT) - { - // cursor is on the title frame (+/-2 and +/-4 are only for a good optic) - if((button.x >= x + global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + 2) - && (button.x < x + w - global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w - 2) && (button.y >= y + 4) - && (button.y < y + +global::bmpArray[WINDOW_UPPER_FRAME].h - 4)) - { - marked = true; - clicked = true; - } - // pressed inside the window - if((button.state == SDL_PRESSED) && (button.x >= x) && (button.x <= x + w) && (button.y >= y) && (button.y <= y + h)) - marked = true; - // else pressed outside of the window - else if(button.state == SDL_PRESSED) - marked = false; - } - - // check whats happen to the close button - if(button.button == SDL_BUTTON_LEFT) - { - // only set 'clicked' if pressed AND cursor is ON the button (marked == true) - if(button.state == SDL_PRESSED && canClose_marked) - canClose_clicked = true; - else if(button.state == SDL_RELEASED) - { - canClose_clicked = false; - // if mouse button is released ON the close button (marked = true), then send the quit message to the callback - if(canClose_marked && callback != NULL) - { - callback(callbackQuitMessage); - return; - } - } - } - // check whats happen to the minimize button - if(button.button == SDL_BUTTON_LEFT) - { - // only set 'clicked' if pressed AND cursor is ON the button (marked == true) - if(button.state == SDL_PRESSED && canMinimize_marked) - canMinimize_clicked = true; - else if(button.state == SDL_RELEASED) - { - canMinimize_clicked = false; - // if mouse button is released ON the BUTTON (marked = true), then minimize or maximize the window - if(canMinimize_marked) - { - if(minimized) // maximize now - { - h = maximized_h; - // the window has resized, so we need a new surface - needSurface = true; - minimized = false; - } else // minimize now - { - h = global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h; - // the window has resized, so we need a new surface - needSurface = true; - minimized = true; - } - } - } - } - // check whats happen to the resize button - if(button.button == SDL_BUTTON_LEFT) - { - // only set 'clicked' if pressed AND cursor is ON the button (marked == true) - if(button.state == SDL_PRESSED && canResize_marked) - canResize_clicked = true; - else if(button.state == SDL_RELEASED) - canResize_clicked = false; - } - - // deliver mouse data to the content objects of the window (if mouse cursor is inside the window) - if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) - { - // IMPORTANT: we use the left upper corner of the window as (x,y)=(0,0), so we have to manipulate - // the motion-structure before give it to buttons, pictures....: x_absolute - x_window, y_absolute - y_window - button.x -= x; - button.y -= y; - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL) - pictures[i]->setMouseData(button); - } - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL) - buttons[i]->setMouseData(button); - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - textfields[i]->setMouseData(button); - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - selectboxes[i]->setMouseData(button); - } - } - - // at least call the callback - callback(WINDOW_CLICKED_CALL); - - needRender = true; -} - -void CWindow::setKeyboardData(SDL_KeyboardEvent key) -{ - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - textfields[i]->setKeyboardData(key); - } - needRender = true; -} - -CButton* CWindow::addButton(void callback(int), int clickedParam, Uint16 x, Uint16 y, Uint16 w, Uint16 h, int color, const char* text, - int picture) -{ - // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there - int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; - int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] == NULL) - { - buttons[i] = new CButton(callback, clickedParam, x_abs, y_abs, w, h, color, text, picture); - needRender = true; - return buttons[i]; - } - } - return NULL; -} - -bool CWindow::delButton(CButton* ButtonToDelete) -{ - if(ButtonToDelete == NULL) - return false; - - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] == ButtonToDelete) - { - delete buttons[i]; - buttons[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -CFont* CWindow::addText(const char* string, int x, int y, int fontsize, int color) -{ - // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there - int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; - int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] == NULL) - { - texts[i] = new CFont(string, x_abs, y_abs, fontsize, color); - needRender = true; - return texts[i]; - } - } - return NULL; -} - -bool CWindow::delText(CFont* TextToDelete) -{ - if(TextToDelete == NULL) - return false; - - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] == TextToDelete) - { - delete texts[i]; - texts[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -CPicture* CWindow::addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) -{ - // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there - int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; - int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] == NULL) - { - pictures[i] = new CPicture(callback, clickedParam, x_abs, y_abs, picture); - needRender = true; - return pictures[i]; - } - } - return NULL; -} - -bool CWindow::delPicture(CPicture* PictureToDelete) -{ - if(PictureToDelete == NULL) - return false; - - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] == PictureToDelete) - { - delete pictures[i]; - pictures[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -int CWindow::addStaticPicture(int x, int y, int picture) -{ - // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there - int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; - int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - - if(picture < 0) - return -1; - - for(int i = 0; i < MAXPICTURES; i++) - { - if(static_pictures[i].pic == -1) - { - static_pictures[i].pic = picture; - static_pictures[i].x = x_abs; - static_pictures[i].y = y_abs; - needRender = true; - return i; - } - } - return -1; -} - -bool CWindow::delStaticPicture(int ArrayIndex) -{ - if(ArrayIndex < 0 || ArrayIndex >= MAXPICTURES) - return false; - - static_pictures[ArrayIndex].pic = -1; - static_pictures[ArrayIndex].x = 0; - static_pictures[ArrayIndex].y = 0; - needRender = true; - - return true; -} - -CTextfield* CWindow::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int fontsize, int text_color, int bg_color, - bool button_style) -{ - // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there - int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; - int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; - - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] == NULL) - { - textfields[i] = new CTextfield(x_abs, y_abs, cols, rows, fontsize, text_color, bg_color, button_style); - needRender = true; - return textfields[i]; - } - } - return NULL; -} - -bool CWindow::delTextfield(CTextfield* TextfieldToDelete) -{ - if(TextfieldToDelete == NULL) - return false; - - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] == TextfieldToDelete) - { - delete textfields[i]; - textfields[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -CSelectBox* CWindow::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) -{ - if(Surf_Window != NULL && (x >= Surf_Window->w || y >= Surf_Window->h)) - return NULL; - - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] == NULL) - { - selectboxes[i] = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); - needRender = true; - return selectboxes[i]; - } - } - return NULL; -} - -bool CWindow::delSelectBox(CSelectBox* SelectBoxToDelete) -{ - if(SelectBoxToDelete == NULL) - return false; - - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] == SelectBoxToDelete) - { - delete selectboxes[i]; - selectboxes[i] = NULL; - needRender = true; - return true; - } - } - return false; -} - -bool CWindow::render() -{ - // position in the Surface 'Surf_Window' - Uint16 pos_x = 0; - Uint16 pos_y = 0; - // width and height of the window background color source picture - Uint16 pic_w = 0; - Uint16 pic_h = 0; - // upper frame (can be marked, clicked or normal) - int upperframe; - // close button (can be marked, clicked or normal) - int closebutton = WINDOW_BUTTON_CLOSE; - // minimize button (can be marked, clicked or normal) - int minimizebutton = WINDOW_BUTTON_MINIMIZE; - // resize button (can be marked, clicked or normal) - int resizebutton = WINDOW_BUTTON_RESIZE; - - // test if a textfield has changed - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - if(textfields[i]->hasRendered()) - needRender = true; - } - - // if we don't need to render, all is up to date, return true - if(!needRender) - return true; - needRender = false; - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_Window); - Surf_Window = NULL; - if((Surf_Window = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) - return false; - needSurface = false; - } - - // at first completly fill the background (not the fastest way, but simplier) - if(pic_background != WINDOW_NOTHING) - { - if(w <= global::bmpArray[pic_background].w) - pic_w = w; - else - pic_w = global::bmpArray[pic_background].w; - - if(h <= global::bmpArray[pic_background].h) - pic_h = h; - else - pic_h = global::bmpArray[pic_background].h; - - while(pos_x + pic_w <= Surf_Window->w) - { - while(pos_y + pic_h <= Surf_Window->h) - { - CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); - pos_y += pic_h; - } - - if(Surf_Window->h - pos_y > 0) - CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Window->h - pos_y); - - pos_y = 0; - pos_x += pic_w; - } - - if(Surf_Window->w - pos_x > 0) - { - while(pos_y + pic_h <= Surf_Window->h) - { - CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); - pos_y += pic_h; - } - - if(Surf_Window->h - pos_y > 0) - CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, - Surf_Window->h - pos_y); - } - } - - // if not minimized, draw the content now (this stands here to prevent the frames and corners from being overdrawn) - if(!minimized) - { - for(int i = 0; i < MAXBUTTONS; i++) - { - if(buttons[i] != NULL && buttons[i]->getX() < Surf_Window->w && buttons[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, buttons[i]->getSurface(), buttons[i]->getX(), buttons[i]->getY()); - } - for(int i = 0; i < MAXPICTURES; i++) - { - if(static_pictures[i].pic >= 0 && static_pictures[i].x < Surf_Window->w && static_pictures[i].y < Surf_Window->h) - CSurface::Draw(Surf_Window, global::bmpArray[static_pictures[i].pic].surface, static_pictures[i].x, static_pictures[i].y); - } - for(int i = 0; i < MAXPICTURES; i++) - { - if(pictures[i] != NULL && pictures[i]->getX() < Surf_Window->w && pictures[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, pictures[i]->getSurface(), pictures[i]->getX(), pictures[i]->getY()); - } - for(int i = 0; i < MAXTEXTS; i++) - { - if(texts[i] != NULL && texts[i]->getX() < Surf_Window->w && texts[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, texts[i]->getSurface(), texts[i]->getX(), texts[i]->getY()); - } - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL && textfields[i]->getX() < Surf_Window->w && textfields[i]->getY() < Surf_Window->h) - CSurface::Draw(Surf_Window, textfields[i]->getSurface(), textfields[i]->getX(), textfields[i]->getY()); - } - for(int i = 0; i < MAXSELECTBOXES; i++) - { - if(selectboxes[i] != NULL) - CSurface::Draw(Surf_Window, selectboxes[i]->getSurface(), selectboxes[i]->getX(), selectboxes[i]->getY()); - } - } - - // now draw the upper frame to the top - if(clicked) - upperframe = WINDOW_UPPER_FRAME_CLICKED; - else if(marked) - upperframe = WINDOW_UPPER_FRAME_MARKED; - else - upperframe = WINDOW_UPPER_FRAME; - - if(w <= global::bmpArray[upperframe].w) - pic_w = w; - else - pic_w = global::bmpArray[upperframe].w; - - pos_x = 0; - pos_y = 0; - while(pos_x + pic_w <= Surf_Window->w) - { - CSurface::Draw(Surf_Window, global::bmpArray[upperframe].surface, pos_x, pos_y); - pos_x += pic_w; - } - - if(Surf_Window->w - pos_x > 0) - CSurface::Draw(Surf_Window, global::bmpArray[upperframe].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); - // write text in the upper frame - if(title != NULL) - CFont::writeText(Surf_Window, title, (int)w / 2, (int)((global::bmpArray[WINDOW_UPPER_FRAME].h - 9) / 2), 9, FONT_YELLOW, - ALIGN_MIDDLE); - - // now draw the other frames (left, right, down) - // down - if(w <= global::bmpArray[WINDOW_LOWER_FRAME].w) - pic_w = w; - else - pic_w = global::bmpArray[WINDOW_LOWER_FRAME].w; - - pic_h = global::bmpArray[WINDOW_LOWER_FRAME].h; - pos_x = 0; - pos_y = h - global::bmpArray[WINDOW_LOWER_FRAME].h; - while(pos_x + pic_w <= Surf_Window->w) - { - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LOWER_FRAME].surface, pos_x, pos_y); - pos_x += pic_w; - } - if(Surf_Window->w - pos_x > 0) - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LOWER_FRAME].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); - // left - if(h <= global::bmpArray[WINDOW_LEFT_FRAME].h) - pic_h = h; - else - pic_h = global::bmpArray[WINDOW_LEFT_FRAME].h; - - pic_h = global::bmpArray[WINDOW_LEFT_FRAME].h; - pos_x = 0; - pos_y = 0; - while(pos_y + pic_h <= Surf_Window->h) - { - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LEFT_FRAME].surface, pos_x, pos_y); - pos_y += pic_h; - } - if(Surf_Window->w - pos_x > 0) - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LEFT_FRAME].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); - // right - if(h <= global::bmpArray[WINDOW_RIGHT_FRAME].h) - pic_h = h; - else - pic_h = global::bmpArray[WINDOW_RIGHT_FRAME].h; - - pic_h = global::bmpArray[WINDOW_RIGHT_FRAME].h; - pos_x = w - global::bmpArray[WINDOW_RIGHT_FRAME].w; - pos_y = 0; - while(pos_y + pic_h <= Surf_Window->h) - { - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_RIGHT_FRAME].surface, pos_x, pos_y); - pos_y += pic_h; - } - if(Surf_Window->w - pos_x > 0) - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_RIGHT_FRAME].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); - - // now draw the corners - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LEFT_UPPER_CORNER].surface, 0, 0); - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].surface, w - global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w, 0); - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_CORNER_RECTANGLE].surface, 0, h - global::bmpArray[WINDOW_CORNER_RECTANGLE].h); - CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_CORNER_RECTANGLE].surface, w - global::bmpArray[WINDOW_CORNER_RECTANGLE].w, - h - global::bmpArray[WINDOW_CORNER_RECTANGLE].h); - // now the corner buttons - // close - if(canClose) - { - if(canClose_clicked) - closebutton = WINDOW_BUTTON_CLOSE_CLICKED; - else if(canClose_marked) - closebutton = WINDOW_BUTTON_CLOSE_MARKED; - else - closebutton = WINDOW_BUTTON_CLOSE; - CSurface::Draw(Surf_Window, global::bmpArray[closebutton].surface, 0, 0); - } - // minimize - if(canMinimize) - { - if(canMinimize_clicked) - minimizebutton = WINDOW_BUTTON_MINIMIZE_CLICKED; - else if(canMinimize_marked) - minimizebutton = WINDOW_BUTTON_MINIMIZE_MARKED; - else - minimizebutton = WINDOW_BUTTON_MINIMIZE; - CSurface::Draw(Surf_Window, global::bmpArray[minimizebutton].surface, w - global::bmpArray[minimizebutton].w, 0); - } - // resize - if(canResize) - { - if(canResize_clicked) - resizebutton = WINDOW_BUTTON_RESIZE_CLICKED; - else if(canResize_marked) - resizebutton = WINDOW_BUTTON_RESIZE_MARKED; - else - resizebutton = WINDOW_BUTTON_RESIZE; - CSurface::Draw(Surf_Window, global::bmpArray[resizebutton].surface, w - global::bmpArray[resizebutton].w, - h - global::bmpArray[resizebutton].h); - } - - return true; -} - -void CWindow::setInactive() -{ - active = false; - clicked = false; - marked = false; - needRender = true; - - for(int i = 0; i < MAXTEXTFIELDS; i++) - { - if(textfields[i] != NULL) - textfields[i]->setInactive(); - } -} +#include "CWindow.h" +#include "../CGame.h" +#include "../CSurface.h" +#include "../globals.h" +#include "CButton.h" +#include "CFont.h" +#include "CPicture.h" +#include "CSelectBox.h" +#include "CTextfield.h" + +CWindow::CWindow(void callback(int), int callbackQuitMessage, Uint16 x, Uint16 y, Uint16 w, Uint16 h, const char* title, int color, + Uint8 flags) +{ + marked = true; + clicked = false; + this->x = x; + this->y = y; + // ensure window is big enough to take all basic pictures needed + // if ( w < (global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + global::bmpArray[WINDOW_UPPER_FRAME].w + + // global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w) ) + // this->w = global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + global::bmpArray[WINDOW_UPPER_FRAME].w + + // global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w; + // else + this->w = w; + // if ( h < (global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h) ) + // this->h = global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h; + // else + this->h = h; + canMove = (flags & WINDOW_MOVE) ? true : false; + canClose = (flags & WINDOW_CLOSE) ? true : false; + canClose_marked = false; + canClose_clicked = false; + canMinimize = (flags & WINDOW_MINIMIZE) ? true : false; + canMinimize_marked = false; + canMinimize_clicked = false; + canResize = (flags & WINDOW_RESIZE) ? true : false; + canResize_marked = false; + canResize_clicked = false; + minimized = false; + priority = 0; + pic_background = color; + for(int i = 0; i < MAXBUTTONS; i++) + buttons[i] = NULL; + for(int i = 0; i < MAXTEXTS; i++) + texts[i] = NULL; + for(int i = 0; i < MAXPICTURES; i++) + pictures[i] = NULL; + for(int i = 0; i < MAXPICTURES; i++) + { + static_pictures[i].x = 0; + static_pictures[i].y = 0; + static_pictures[i].pic = -1; + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + textfields[i] = NULL; + for(int i = 0; i < MAXSELECTBOXES; i++) + selectboxes[i] = NULL; + + this->title = title; + this->callback = callback; + this->callbackQuitMessage = callbackQuitMessage; + Surf_Window = NULL; + needSurface = true; + needRender = true; + active = true; + waste = false; + moving = false; + resizing = false; +} + +CWindow::~CWindow() +{ + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + delete buttons[i]; + } + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] != NULL) + delete texts[i]; + } + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + delete pictures[i]; + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + delete textfields[i]; + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + delete selectboxes[i]; + } + SDL_FreeSurface(Surf_Window); +} + +void CWindow::setTitle(const char* title) +{ + this->title = title; + needRender = true; +} + +void CWindow::setColor(int color) +{ + pic_background = color; + needRender = true; +} + +bool CWindow::hasActiveInputElement() +{ + for(int i = 0; i < MAXTEXTFIELDS; i++) + if(textfields[i] != NULL && textfields[i]->isActive()) + return true; + return false; +} + +void CWindow::setMouseData(SDL_MouseMotionEvent motion) +{ + // cursor is on the title frame (+/-2 and +/-4 are only for a good optic) + if((motion.x >= x + global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + 2) + && (motion.x < x + w - global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w - 2) && (motion.y >= y + 4) + && (motion.y < y + +global::bmpArray[WINDOW_UPPER_FRAME].h - 4)) + { + // left button was pressed while moving + if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) + moving = true; + clicked = true; + } else if(!moving) + clicked = false; + + if(!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))) + moving = false; + if(moving && canMove) + { + x += motion.xrel; + y += motion.yrel; + // make sure to not move the window outside the display surface + if(x < 0) + x = 0; + if(x + w >= global::s2->getDisplaySurface()->w) + x = global::s2->getDisplaySurface()->w - w - 1; + if(y < 0) + y = 0; + if(y + h >= global::s2->getDisplaySurface()->h) + y = global::s2->getDisplaySurface()->h - h - 1; + } + + // check whats happen to the close button + if(canClose) + { + // cursor is on the button (+/-2 is only for the optic) + if((motion.x >= x + 2) && (motion.x < x + global::bmpArray[WINDOW_BUTTON_CLOSE].w - 2) && (motion.y >= y + 2) + && (motion.y < y + global::bmpArray[WINDOW_BUTTON_CLOSE].h - 2)) + canClose_marked = true; + else + canClose_marked = false; + } + // check whats happen to the minimize button + if(canMinimize) + { + // cursor is on the button (+/-2 is only for the optic) + if((motion.x >= x + w - global::bmpArray[WINDOW_BUTTON_MINIMIZE].w + 2) && (motion.x < x + w - 2) && (motion.y >= y + 2) + && (motion.y < y + global::bmpArray[WINDOW_BUTTON_MINIMIZE].h - 2)) + canMinimize_marked = true; + else + canMinimize_marked = false; + } + // check whats happen to the resize button + if(canResize) + { + // cursor is on the button (+/-2 is only for the optic) + if((motion.x >= x + w - global::bmpArray[WINDOW_BUTTON_RESIZE].w + 2) && (motion.x < x + w - 2) + && (motion.y >= y + h - global::bmpArray[WINDOW_BUTTON_RESIZE].h + 2) && (motion.y < y + h - 2)) + { + // left button was pressed while moving + if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) + resizing = true; + canResize_marked = true; + } else if(!resizing) + canResize_marked = false; + + if(!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))) + resizing = false; + if(resizing) + { + // only resize if not minimized + if(!minimized) + { + w += motion.xrel; + h += motion.yrel; + + // MISSING: we have to test if window size is under minimum + + // the window has resized, so we need a new surface + needSurface = true; + } + } + } + + // deliver mouse data to the content objects of the window (if mouse cursor is inside the window) + if((motion.x >= x) && (motion.x < x + w) && (motion.y >= y) && (motion.y < y + h)) + { + // IMPORTANT: we use the left upper corner of the window as (x,y)=(0,0), so we have to manipulate + // the motion-structure before give it to buttons, pictures....: x_absolute - x_window, y_absolute - y_window + motion.x -= x; + motion.y -= y; + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + pictures[i]->setMouseData(motion); + } + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + buttons[i]->setMouseData(motion); + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + selectboxes[i]->setMouseData(motion); + } + } + + // at least call the callback if a mouse button is pressed + if(motion.state == SDL_PRESSED) + callback(WINDOW_CLICKED_CALL); + + needRender = true; +} + +void CWindow::setMouseData(SDL_MouseButtonEvent button) +{ + // at first check if the right mouse button was pressed, cause in this case we will close the window + if(button.button == SDL_BUTTON_RIGHT && button.state == SDL_PRESSED) + { + callback(callbackQuitMessage); + return; + } + + // save width and height in case we minimize the window (the initializing values are for preventing any mistakes and compilerwarning --- + // in fact: uninitialized values are only a problem if the window is created minimized, but this will not happen) + static int maximized_h = global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h; + if(!minimized) + maximized_h = h; + + // left button is pressed + if(button.button == SDL_BUTTON_LEFT) + { + // cursor is on the title frame (+/-2 and +/-4 are only for a good optic) + if((button.x >= x + global::bmpArray[WINDOW_LEFT_UPPER_CORNER].w + 2) + && (button.x < x + w - global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w - 2) && (button.y >= y + 4) + && (button.y < y + +global::bmpArray[WINDOW_UPPER_FRAME].h - 4)) + { + marked = true; + clicked = true; + } + // pressed inside the window + if((button.state == SDL_PRESSED) && (button.x >= x) && (button.x <= x + w) && (button.y >= y) && (button.y <= y + h)) + marked = true; + // else pressed outside of the window + else if(button.state == SDL_PRESSED) + marked = false; + } + + // check whats happen to the close button + if(button.button == SDL_BUTTON_LEFT) + { + // only set 'clicked' if pressed AND cursor is ON the button (marked == true) + if(button.state == SDL_PRESSED && canClose_marked) + canClose_clicked = true; + else if(button.state == SDL_RELEASED) + { + canClose_clicked = false; + // if mouse button is released ON the close button (marked = true), then send the quit message to the callback + if(canClose_marked && callback != NULL) + { + callback(callbackQuitMessage); + return; + } + } + } + // check whats happen to the minimize button + if(button.button == SDL_BUTTON_LEFT) + { + // only set 'clicked' if pressed AND cursor is ON the button (marked == true) + if(button.state == SDL_PRESSED && canMinimize_marked) + canMinimize_clicked = true; + else if(button.state == SDL_RELEASED) + { + canMinimize_clicked = false; + // if mouse button is released ON the BUTTON (marked = true), then minimize or maximize the window + if(canMinimize_marked) + { + if(minimized) // maximize now + { + h = maximized_h; + // the window has resized, so we need a new surface + needSurface = true; + minimized = false; + } else // minimize now + { + h = global::bmpArray[WINDOW_UPPER_FRAME].h + global::bmpArray[WINDOW_CORNER_RECTANGLE].h; + // the window has resized, so we need a new surface + needSurface = true; + minimized = true; + } + } + } + } + // check whats happen to the resize button + if(button.button == SDL_BUTTON_LEFT) + { + // only set 'clicked' if pressed AND cursor is ON the button (marked == true) + if(button.state == SDL_PRESSED && canResize_marked) + canResize_clicked = true; + else if(button.state == SDL_RELEASED) + canResize_clicked = false; + } + + // deliver mouse data to the content objects of the window (if mouse cursor is inside the window) + if((button.x >= x) && (button.x < x + w) && (button.y >= y) && (button.y < y + h)) + { + // IMPORTANT: we use the left upper corner of the window as (x,y)=(0,0), so we have to manipulate + // the motion-structure before give it to buttons, pictures....: x_absolute - x_window, y_absolute - y_window + button.x -= x; + button.y -= y; + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL) + pictures[i]->setMouseData(button); + } + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL) + buttons[i]->setMouseData(button); + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + textfields[i]->setMouseData(button); + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + selectboxes[i]->setMouseData(button); + } + } + + // at least call the callback + callback(WINDOW_CLICKED_CALL); + + needRender = true; +} + +void CWindow::setKeyboardData(SDL_KeyboardEvent key) +{ + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + textfields[i]->setKeyboardData(key); + } + needRender = true; +} + +CButton* CWindow::addButton(void callback(int), int clickedParam, Uint16 x, Uint16 y, Uint16 w, Uint16 h, int color, const char* text, + int picture) +{ + // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there + int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; + int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; + + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] == NULL) + { + buttons[i] = new CButton(callback, clickedParam, x_abs, y_abs, w, h, color, text, picture); + needRender = true; + return buttons[i]; + } + } + return NULL; +} + +bool CWindow::delButton(CButton* ButtonToDelete) +{ + if(ButtonToDelete == NULL) + return false; + + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] == ButtonToDelete) + { + delete buttons[i]; + buttons[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +CFont* CWindow::addText(const char* string, int x, int y, int fontsize, int color) +{ + // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there + int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; + int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; + + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] == NULL) + { + texts[i] = new CFont(string, x_abs, y_abs, fontsize, color); + needRender = true; + return texts[i]; + } + } + return NULL; +} + +bool CWindow::delText(CFont* TextToDelete) +{ + if(TextToDelete == NULL) + return false; + + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] == TextToDelete) + { + delete texts[i]; + texts[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +CPicture* CWindow::addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture) +{ + // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there + int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; + int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; + + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] == NULL) + { + pictures[i] = new CPicture(callback, clickedParam, x_abs, y_abs, picture); + needRender = true; + return pictures[i]; + } + } + return NULL; +} + +bool CWindow::delPicture(CPicture* PictureToDelete) +{ + if(PictureToDelete == NULL) + return false; + + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] == PictureToDelete) + { + delete pictures[i]; + pictures[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +int CWindow::addStaticPicture(int x, int y, int picture) +{ + // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there + int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; + int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; + + if(picture < 0) + return -1; + + for(int i = 0; i < MAXPICTURES; i++) + { + if(static_pictures[i].pic == -1) + { + static_pictures[i].pic = picture; + static_pictures[i].x = x_abs; + static_pictures[i].y = y_abs; + needRender = true; + return i; + } + } + return -1; +} + +bool CWindow::delStaticPicture(int ArrayIndex) +{ + if(ArrayIndex < 0 || ArrayIndex >= MAXPICTURES) + return false; + + static_pictures[ArrayIndex].pic = -1; + static_pictures[ArrayIndex].x = 0; + static_pictures[ArrayIndex].y = 0; + needRender = true; + + return true; +} + +CTextfield* CWindow::addTextfield(Uint16 x, Uint16 y, Uint16 cols, Uint16 rows, int fontsize, int text_color, int bg_color, + bool button_style) +{ + // x_abs and y_abs are not the left upper corner of the window, because the left and upper frames are there + int x_abs = x + global::bmpArray[WINDOW_LEFT_FRAME].w; + int y_abs = y + global::bmpArray[WINDOW_UPPER_FRAME].h; + + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] == NULL) + { + textfields[i] = new CTextfield(x_abs, y_abs, cols, rows, fontsize, text_color, bg_color, button_style); + needRender = true; + return textfields[i]; + } + } + return NULL; +} + +bool CWindow::delTextfield(CTextfield* TextfieldToDelete) +{ + if(TextfieldToDelete == NULL) + return false; + + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] == TextfieldToDelete) + { + delete textfields[i]; + textfields[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +CSelectBox* CWindow::addSelectBox(Uint16 x, Uint16 y, Uint16 w, Uint16 h, int fontsize, int text_color, int bg_color) +{ + if(Surf_Window != NULL && (x >= Surf_Window->w || y >= Surf_Window->h)) + return NULL; + + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] == NULL) + { + selectboxes[i] = new CSelectBox(x, y, w, h, fontsize, text_color, bg_color); + needRender = true; + return selectboxes[i]; + } + } + return NULL; +} + +bool CWindow::delSelectBox(CSelectBox* SelectBoxToDelete) +{ + if(SelectBoxToDelete == NULL) + return false; + + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] == SelectBoxToDelete) + { + delete selectboxes[i]; + selectboxes[i] = NULL; + needRender = true; + return true; + } + } + return false; +} + +bool CWindow::render() +{ + // position in the Surface 'Surf_Window' + Uint16 pos_x = 0; + Uint16 pos_y = 0; + // width and height of the window background color source picture + Uint16 pic_w = 0; + Uint16 pic_h = 0; + // upper frame (can be marked, clicked or normal) + int upperframe; + // close button (can be marked, clicked or normal) + int closebutton = WINDOW_BUTTON_CLOSE; + // minimize button (can be marked, clicked or normal) + int minimizebutton = WINDOW_BUTTON_MINIMIZE; + // resize button (can be marked, clicked or normal) + int resizebutton = WINDOW_BUTTON_RESIZE; + + // test if a textfield has changed + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + if(textfields[i]->hasRendered()) + needRender = true; + } + + // if we don't need to render, all is up to date, return true + if(!needRender) + return true; + needRender = false; + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_Window); + Surf_Window = NULL; + if((Surf_Window = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0)) == NULL) + return false; + needSurface = false; + } + + // at first completly fill the background (not the fastest way, but simplier) + if(pic_background != WINDOW_NOTHING) + { + if(w <= global::bmpArray[pic_background].w) + pic_w = w; + else + pic_w = global::bmpArray[pic_background].w; + + if(h <= global::bmpArray[pic_background].h) + pic_h = h; + else + pic_h = global::bmpArray[pic_background].h; + + while(pos_x + pic_w <= Surf_Window->w) + { + while(pos_y + pic_h <= Surf_Window->h) + { + CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, pic_h); + pos_y += pic_h; + } + + if(Surf_Window->h - pos_y > 0) + CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, pic_w, Surf_Window->h - pos_y); + + pos_y = 0; + pos_x += pic_w; + } + + if(Surf_Window->w - pos_x > 0) + { + while(pos_y + pic_h <= Surf_Window->h) + { + CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); + pos_y += pic_h; + } + + if(Surf_Window->h - pos_y > 0) + CSurface::Draw(Surf_Window, global::bmpArray[pic_background].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, + Surf_Window->h - pos_y); + } + } + + // if not minimized, draw the content now (this stands here to prevent the frames and corners from being overdrawn) + if(!minimized) + { + for(int i = 0; i < MAXBUTTONS; i++) + { + if(buttons[i] != NULL && buttons[i]->getX() < Surf_Window->w && buttons[i]->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, buttons[i]->getSurface(), buttons[i]->getX(), buttons[i]->getY()); + } + for(int i = 0; i < MAXPICTURES; i++) + { + if(static_pictures[i].pic >= 0 && static_pictures[i].x < Surf_Window->w && static_pictures[i].y < Surf_Window->h) + CSurface::Draw(Surf_Window, global::bmpArray[static_pictures[i].pic].surface, static_pictures[i].x, static_pictures[i].y); + } + for(int i = 0; i < MAXPICTURES; i++) + { + if(pictures[i] != NULL && pictures[i]->getX() < Surf_Window->w && pictures[i]->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, pictures[i]->getSurface(), pictures[i]->getX(), pictures[i]->getY()); + } + for(int i = 0; i < MAXTEXTS; i++) + { + if(texts[i] != NULL && texts[i]->getX() < Surf_Window->w && texts[i]->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, texts[i]->getSurface(), texts[i]->getX(), texts[i]->getY()); + } + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL && textfields[i]->getX() < Surf_Window->w && textfields[i]->getY() < Surf_Window->h) + CSurface::Draw(Surf_Window, textfields[i]->getSurface(), textfields[i]->getX(), textfields[i]->getY()); + } + for(int i = 0; i < MAXSELECTBOXES; i++) + { + if(selectboxes[i] != NULL) + CSurface::Draw(Surf_Window, selectboxes[i]->getSurface(), selectboxes[i]->getX(), selectboxes[i]->getY()); + } + } + + // now draw the upper frame to the top + if(clicked) + upperframe = WINDOW_UPPER_FRAME_CLICKED; + else if(marked) + upperframe = WINDOW_UPPER_FRAME_MARKED; + else + upperframe = WINDOW_UPPER_FRAME; + + if(w <= global::bmpArray[upperframe].w) + pic_w = w; + else + pic_w = global::bmpArray[upperframe].w; + + pos_x = 0; + pos_y = 0; + while(pos_x + pic_w <= Surf_Window->w) + { + CSurface::Draw(Surf_Window, global::bmpArray[upperframe].surface, pos_x, pos_y); + pos_x += pic_w; + } + + if(Surf_Window->w - pos_x > 0) + CSurface::Draw(Surf_Window, global::bmpArray[upperframe].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); + // write text in the upper frame + if(title != NULL) + CFont::writeText(Surf_Window, title, (int)w / 2, (int)((global::bmpArray[WINDOW_UPPER_FRAME].h - 9) / 2), 9, FONT_YELLOW, + ALIGN_MIDDLE); + + // now draw the other frames (left, right, down) + // down + if(w <= global::bmpArray[WINDOW_LOWER_FRAME].w) + pic_w = w; + else + pic_w = global::bmpArray[WINDOW_LOWER_FRAME].w; + + pic_h = global::bmpArray[WINDOW_LOWER_FRAME].h; + pos_x = 0; + pos_y = h - global::bmpArray[WINDOW_LOWER_FRAME].h; + while(pos_x + pic_w <= Surf_Window->w) + { + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LOWER_FRAME].surface, pos_x, pos_y); + pos_x += pic_w; + } + if(Surf_Window->w - pos_x > 0) + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LOWER_FRAME].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); + // left + if(h <= global::bmpArray[WINDOW_LEFT_FRAME].h) + pic_h = h; + else + pic_h = global::bmpArray[WINDOW_LEFT_FRAME].h; + + pic_h = global::bmpArray[WINDOW_LEFT_FRAME].h; + pos_x = 0; + pos_y = 0; + while(pos_y + pic_h <= Surf_Window->h) + { + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LEFT_FRAME].surface, pos_x, pos_y); + pos_y += pic_h; + } + if(Surf_Window->w - pos_x > 0) + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LEFT_FRAME].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); + // right + if(h <= global::bmpArray[WINDOW_RIGHT_FRAME].h) + pic_h = h; + else + pic_h = global::bmpArray[WINDOW_RIGHT_FRAME].h; + + pic_h = global::bmpArray[WINDOW_RIGHT_FRAME].h; + pos_x = w - global::bmpArray[WINDOW_RIGHT_FRAME].w; + pos_y = 0; + while(pos_y + pic_h <= Surf_Window->h) + { + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_RIGHT_FRAME].surface, pos_x, pos_y); + pos_y += pic_h; + } + if(Surf_Window->w - pos_x > 0) + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_RIGHT_FRAME].surface, pos_x, pos_y, 0, 0, Surf_Window->w - pos_x, pic_h); + + // now draw the corners + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_LEFT_UPPER_CORNER].surface, 0, 0); + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].surface, w - global::bmpArray[WINDOW_RIGHT_UPPER_CORNER].w, 0); + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_CORNER_RECTANGLE].surface, 0, h - global::bmpArray[WINDOW_CORNER_RECTANGLE].h); + CSurface::Draw(Surf_Window, global::bmpArray[WINDOW_CORNER_RECTANGLE].surface, w - global::bmpArray[WINDOW_CORNER_RECTANGLE].w, + h - global::bmpArray[WINDOW_CORNER_RECTANGLE].h); + // now the corner buttons + // close + if(canClose) + { + if(canClose_clicked) + closebutton = WINDOW_BUTTON_CLOSE_CLICKED; + else if(canClose_marked) + closebutton = WINDOW_BUTTON_CLOSE_MARKED; + else + closebutton = WINDOW_BUTTON_CLOSE; + CSurface::Draw(Surf_Window, global::bmpArray[closebutton].surface, 0, 0); + } + // minimize + if(canMinimize) + { + if(canMinimize_clicked) + minimizebutton = WINDOW_BUTTON_MINIMIZE_CLICKED; + else if(canMinimize_marked) + minimizebutton = WINDOW_BUTTON_MINIMIZE_MARKED; + else + minimizebutton = WINDOW_BUTTON_MINIMIZE; + CSurface::Draw(Surf_Window, global::bmpArray[minimizebutton].surface, w - global::bmpArray[minimizebutton].w, 0); + } + // resize + if(canResize) + { + if(canResize_clicked) + resizebutton = WINDOW_BUTTON_RESIZE_CLICKED; + else if(canResize_marked) + resizebutton = WINDOW_BUTTON_RESIZE_MARKED; + else + resizebutton = WINDOW_BUTTON_RESIZE; + CSurface::Draw(Surf_Window, global::bmpArray[resizebutton].surface, w - global::bmpArray[resizebutton].w, + h - global::bmpArray[resizebutton].h); + } + + return true; +} + +void CWindow::setInactive() +{ + active = false; + clicked = false; + marked = false; + needRender = true; + + for(int i = 0; i < MAXTEXTFIELDS; i++) + { + if(textfields[i] != NULL) + textfields[i]->setInactive(); + } +} diff --git a/CIO/CWindow.h b/CIO/CWindow.h index 8b197ae..7f68351 100644 --- a/CIO/CWindow.h +++ b/CIO/CWindow.h @@ -1,117 +1,117 @@ -#ifndef _CWINDOW_H -#define _CWINDOW_H - -#include "../includes.h" - -class CPicture; -class CTextfield; -class CSelectBox; -class CFont; -class CButton; - -class CWindow -{ - friend class CDebug; - -private: - // if active is false, the window will be render behind the active windows within the game loop - bool active; - // if waste is true, the window will be delete within the game loop - bool waste; - SDL_Surface* Surf_Window; - bool needSurface; - bool needRender; - Sint16 x; - Sint16 y; - Uint16 w; - Uint16 h; - int pic_background; - CButton* buttons[MAXBUTTONS]; - CFont* texts[MAXTEXTS]; - CPicture* pictures[MAXPICTURES]; - struct - { - int x, y, pic; - } static_pictures[MAXPICTURES]; - CTextfield* textfields[MAXTEXTFIELDS]; - CSelectBox* selectboxes[MAXSELECTBOXES]; - const char* title; - bool marked; - bool clicked; - bool canMove; - bool canClose; - bool canClose_marked; - bool canClose_clicked; - bool canMinimize; - bool canMinimize_marked; - bool canMinimize_clicked; - bool canResize; - bool canResize_marked; - bool canResize_clicked; - bool minimized; - bool moving; - bool resizing; - int priority; // for register, blit, event - void (*callback)(int); - int callbackQuitMessage; - -public: - // Constructor - Destructor - CWindow(void callback(int), int callbackQuitMessage, Uint16 x = 0, Uint16 y = 0, Uint16 w = 200, Uint16 h = 200, - const char* title = NULL, int color = WINDOW_GREEN1, Uint8 flags = 0); - ~CWindow(); - // Access - int getX() { return x; }; - int getY() { return y; }; - int getW() { return w; }; - int getH() { return h; }; - int getPriority() { return priority; } - void setPriority(int priority) { this->priority = priority; } - void setTitle(const char* title); - void setMouseData(SDL_MouseMotionEvent motion); - void setMouseData(SDL_MouseButtonEvent button); - void setKeyboardData(SDL_KeyboardEvent key); - SDL_Surface* getSurface() - { - render(); - return Surf_Window; - } - void setActive() - { - active = true; - marked = true; - needRender = true; - } - void setInactive(); - bool isActive() { return active; } - void setWaste() { waste = true; } - bool isWaste() { return waste; } - bool isMoving() { return moving; } - bool isResizing() { return resizing; } - bool isMarked() { return marked; } - // we can not trust this information, cause if minimized is false, it is possible, that we still have the old minimized surface - // bool isMinimized() { return minimized; }; - // we need an information if a input-element (textfield etc.) is active to not deliver the input to other gui-element in the event - // system - bool hasActiveInputElement(); - void setColor(int color); - // Methods - CButton* addButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 width = 20, Uint16 height = 20, - int color = BUTTON_GREY, const char* text = NULL, int picture = -1); - bool delButton(CButton* ButtonToDelete); - CFont* addText(const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW); - bool delText(CFont* TextToDelete); - CPicture* addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture); - bool delPicture(CPicture* PictureToDelete); - int addStaticPicture(int x, int y, int picture); - bool delStaticPicture(int ArrayIndex); - CTextfield* addTextfield(Uint16 x = 0, Uint16 y = 0, Uint16 cols = 10, Uint16 rows = 1, int fontsize = 14, int text_color = FONT_YELLOW, - int bg_color = -1, bool button_style = false); - bool delTextfield(CTextfield* TextfieldToDelete); - CSelectBox* addSelectBox(Uint16 x = 0, Uint16 y = 0, Uint16 w = 100, Uint16 h = 100, int fontsize = 14, int text_color = FONT_YELLOW, - int bg_color = -1); - bool delSelectBox(CSelectBox* SelectBoxToDelete); - bool render(); -}; - -#endif +#ifndef _CWINDOW_H +#define _CWINDOW_H + +#include "../includes.h" + +class CPicture; +class CTextfield; +class CSelectBox; +class CFont; +class CButton; + +class CWindow +{ + friend class CDebug; + +private: + // if active is false, the window will be render behind the active windows within the game loop + bool active; + // if waste is true, the window will be delete within the game loop + bool waste; + SDL_Surface* Surf_Window; + bool needSurface; + bool needRender; + Sint16 x; + Sint16 y; + Uint16 w; + Uint16 h; + int pic_background; + CButton* buttons[MAXBUTTONS]; + CFont* texts[MAXTEXTS]; + CPicture* pictures[MAXPICTURES]; + struct + { + int x, y, pic; + } static_pictures[MAXPICTURES]; + CTextfield* textfields[MAXTEXTFIELDS]; + CSelectBox* selectboxes[MAXSELECTBOXES]; + const char* title; + bool marked; + bool clicked; + bool canMove; + bool canClose; + bool canClose_marked; + bool canClose_clicked; + bool canMinimize; + bool canMinimize_marked; + bool canMinimize_clicked; + bool canResize; + bool canResize_marked; + bool canResize_clicked; + bool minimized; + bool moving; + bool resizing; + int priority; // for register, blit, event + void (*callback)(int); + int callbackQuitMessage; + +public: + // Constructor - Destructor + CWindow(void callback(int), int callbackQuitMessage, Uint16 x = 0, Uint16 y = 0, Uint16 w = 200, Uint16 h = 200, + const char* title = NULL, int color = WINDOW_GREEN1, Uint8 flags = 0); + ~CWindow(); + // Access + int getX() { return x; }; + int getY() { return y; }; + int getW() { return w; }; + int getH() { return h; }; + int getPriority() { return priority; } + void setPriority(int priority) { this->priority = priority; } + void setTitle(const char* title); + void setMouseData(SDL_MouseMotionEvent motion); + void setMouseData(SDL_MouseButtonEvent button); + void setKeyboardData(SDL_KeyboardEvent key); + SDL_Surface* getSurface() + { + render(); + return Surf_Window; + } + void setActive() + { + active = true; + marked = true; + needRender = true; + } + void setInactive(); + bool isActive() { return active; } + void setWaste() { waste = true; } + bool isWaste() { return waste; } + bool isMoving() { return moving; } + bool isResizing() { return resizing; } + bool isMarked() { return marked; } + // we can not trust this information, cause if minimized is false, it is possible, that we still have the old minimized surface + // bool isMinimized() { return minimized; }; + // we need an information if a input-element (textfield etc.) is active to not deliver the input to other gui-element in the event + // system + bool hasActiveInputElement(); + void setColor(int color); + // Methods + CButton* addButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 width = 20, Uint16 height = 20, + int color = BUTTON_GREY, const char* text = NULL, int picture = -1); + bool delButton(CButton* ButtonToDelete); + CFont* addText(const char* string, int x = 0, int y = 0, int fontsize = 9, int color = FONT_YELLOW); + bool delText(CFont* TextToDelete); + CPicture* addPicture(void callback(int), int clickedParam, Uint16 x, Uint16 y, int picture); + bool delPicture(CPicture* PictureToDelete); + int addStaticPicture(int x, int y, int picture); + bool delStaticPicture(int ArrayIndex); + CTextfield* addTextfield(Uint16 x = 0, Uint16 y = 0, Uint16 cols = 10, Uint16 rows = 1, int fontsize = 14, int text_color = FONT_YELLOW, + int bg_color = -1, bool button_style = false); + bool delTextfield(CTextfield* TextfieldToDelete); + CSelectBox* addSelectBox(Uint16 x = 0, Uint16 y = 0, Uint16 w = 100, Uint16 h = 100, int fontsize = 14, int text_color = FONT_YELLOW, + int bg_color = -1); + bool delSelectBox(CSelectBox* SelectBoxToDelete); + bool render(); +}; + +#endif diff --git a/CMap.cpp b/CMap.cpp index 36c2417..bf2e9af 100644 --- a/CMap.cpp +++ b/CMap.cpp @@ -1,3100 +1,3100 @@ -#include "CMap.h" -#include "CGame.h" -#include "CIO/CFile.h" -#include "CIO/CFont.h" -#include "CSurface.h" -#include "callbacks.h" -#include "globals.h" -#include -#include - -CMap::CMap(const std::string& filename) -{ - constructMap(filename); -} - -CMap::~CMap() -{ - destructMap(); -} - -void CMap::constructMap(const std::string& filename, int width, int height, int type, int texture, int border, int border_texture) -{ - map = NULL; - Surf_Map = NULL; - Surf_RightMenubar = NULL; - displayRect.x = 0; - displayRect.y = 0; - displayRect.w = global::s2->GameResolutionX; - displayRect.h = global::s2->GameResolutionY; - - if(!filename.empty()) - map = (bobMAP*)CFile::open_file(filename, WLD); - - if(map == NULL) - map = generateMap(width, height, type, texture, border, border_texture); - - // load the right MAP0x.LST for all pictures - loadMapPics(); - - CSurface::get_nodeVectors(map); -#ifdef _EDITORMODE - // for safety recalculate build and shadow data and test if fishes and water is correct - for(int i = 0; i < map->height; i++) - { - for(int j = 0; j < map->width; j++) - { - modifyBuild(j, i); - modifyShading(j, i); - modifyResource(j, i); - } - } -#endif - needSurface = true; - active = true; - VertexX = 10; - VertexY = 10; - RenderBuildHelp = false; - RenderBorders = true; - BitsPerPixel = 32; - MouseBlitX = correctMouseBlitX(VertexX, VertexY); - MouseBlitY = correctMouseBlitY(VertexX, VertexY); - ChangeSection = 1; - lastChangeSection = ChangeSection; - ChangeSectionHexagonMode = true; - VertexFillRSU = true; - VertexFillUSD = true; - VertexFillRandom = false; - VertexActivityRandom = false; - // calculate the maximum number of vertices for cursor - VertexCounter = 0; - for(int i = -MAX_CHANGE_SECTION; i <= MAX_CHANGE_SECTION; i++) - { - if(abs(i) % 2 == 0) - for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION; j++) - VertexCounter++; - else - for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++) - VertexCounter++; - } - Vertices = (struct cursorPoint*)malloc(VertexCounter * sizeof(struct cursorPoint)); - calculateVertices(); - setupVerticesActivity(); - mode = EDITOR_MODE_HEIGHT_RAISE; - lastMode = EDITOR_MODE_HEIGHT_RAISE; - modeContent = 0x00; - modeContent2 = 0x00; - modify = false; - 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; - } - - // 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; - // now for internal reasons save all players to a new array, also players with number greater than 7 - // initalize the internal array - for(int i = 0; i < MAXPLAYERS; i++) - { - PlayerHQx[i] = 0xFFFF; - PlayerHQy[i] = 0xFFFF; - } - // find out player positions - for(int y = 0; y < map->height; y++) - { - for(int x = 0; x < map->width; x++) - { - if(map->vertex[y * map->width + x].objectInfo == 0x80) - { - CountPlayers++; - // objectType is the number of the player - if(map->vertex[y * map->width + x].objectType < MAXPLAYERS) - { - PlayerHQx[map->vertex[y * map->width + x].objectType] = x; - PlayerHQy[map->vertex[y * map->width + x].objectType] = y; - - // for compatibility with original settlers 2 save the first 7 player positions to the map header - // NOTE: this is already done by map loading, but to prevent inconsistence we do it again this way - if(map->vertex[y * map->width + x].objectType < 0x07) - { - map->HQx[map->vertex[y * map->width + x].objectType] = x; - map->HQy[map->vertex[y * map->width + x].objectType] = y; - } - } - } - } - } - map->player = CountPlayers; - - HorizontalMovementLocked = false; - VerticalMovementLocked = false; -} -void CMap::destructMap() -{ - // free all surfaces that MAP0x.LST needed - unloadMapPics(); - // free concatenated list for "undo" and "do" - if(CurrPtr_savedVertices != NULL) - { - // go to the end - while(CurrPtr_savedVertices->next != NULL) - { - CurrPtr_savedVertices = CurrPtr_savedVertices->next; - } - // and now free all pointers from behind - while(CurrPtr_savedVertices->prev != NULL) - { - CurrPtr_savedVertices = CurrPtr_savedVertices->prev; - free(CurrPtr_savedVertices->next); - } - free(CurrPtr_savedVertices); - } - // free the map surface - SDL_FreeSurface(Surf_Map); - Surf_Map = NULL; - // free the surface of the right menubar - SDL_FreeSurface(Surf_RightMenubar); - Surf_RightMenubar = NULL; - // free vertex array - free(Vertices); - // free vertex memory - free(map->vertex); - // free map structure memory - free(map); -} - -bobMAP* CMap::generateMap(int width, int height, int type, int texture, int border, int border_texture) -{ - bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP)); - Uint8 heightFactor; - - strcpy(myMap->name, "Ohne Namen"); - myMap->width = width; - myMap->width_old = width; - myMap->width_pixel = myMap->width * TRIANGLE_WIDTH; - myMap->height = height; - myMap->height_old = height; - myMap->height_pixel = myMap->height * TRIANGLE_HEIGHT; - myMap->type = type; - myMap->player = 0; - strcpy(myMap->author, "Niemand"); - for(int i = 0; i < 7; i++) - { - myMap->HQx[i] = 0xFFFF; - myMap->HQy[i] = 0xFFFF; - } - - if((myMap->vertex = (struct point*)malloc(sizeof(struct point) * myMap->width * myMap->height)) == NULL) - { - free(myMap); - return NULL; - } - - int a; - int b = 0; - for(int j = 0; j < myMap->height; j++) - { - if(j % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int i = 0; i < myMap->width; i++) - { - myMap->vertex[j * myMap->width + i].VertexX = i; - myMap->vertex[j * myMap->width + i].VertexY = j; - heightFactor = 0x0A; - myMap->vertex[j * myMap->width + i].h = heightFactor; - myMap->vertex[j * myMap->width + i].x = a; - myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); - myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); - a += TRIANGLE_WIDTH; - - if((j < border || myMap->height - j <= border) || (i < border || myMap->width - i <= border)) - { - myMap->vertex[j * myMap->width + i].rsuTexture = border_texture; - myMap->vertex[j * myMap->width + i].usdTexture = border_texture; - } else - { - myMap->vertex[j * myMap->width + i].rsuTexture = texture; - myMap->vertex[j * myMap->width + i].usdTexture = texture; - } - - // initialize all other blocks -- outcommented blocks are recalculated at map load - myMap->vertex[j * myMap->width + i].road = 0x00; - myMap->vertex[j * myMap->width + i].objectType = 0x00; - myMap->vertex[j * myMap->width + i].objectInfo = 0x00; - myMap->vertex[j * myMap->width + i].animal = 0x00; - myMap->vertex[j * myMap->width + i].unknown1 = 0x00; - // myMap->vertex[j*myMap->width+i].build = 0x00; - myMap->vertex[j * myMap->width + i].unknown2 = 0x07; - myMap->vertex[j * myMap->width + i].unknown3 = 0x00; - // myMap->vertex[j*myMap->width+i].resource = 0x00; - // myMap->vertex[j*myMap->width+i].shading = 0x00; - myMap->vertex[j * myMap->width + i].unknown5 = 0x00; - } - b += TRIANGLE_HEIGHT; - } - - return myMap; -} - -void CMap::rotateMap() -{ - // we allocate memory for the new triangle field but with x equals the height and y equals the width - struct point* new_vertex = NULL; - if((new_vertex = (struct point*)malloc(map->height * map->width * sizeof(struct point))) == NULL) - return; - - // free concatenated list for "undo" and "do" - if(CurrPtr_savedVertices != NULL) - { - // go to the end - while(CurrPtr_savedVertices->next != NULL) - { - CurrPtr_savedVertices = CurrPtr_savedVertices->next; - } - // and now free all pointers from behind - while(CurrPtr_savedVertices->prev != NULL) - { - CurrPtr_savedVertices = CurrPtr_savedVertices->prev; - free(CurrPtr_savedVertices->next); - } - CurrPtr_savedVertices->next = NULL; - } - - // copy old to new while permuting x and y - for(int y = 0; y < map->height; y++) - { - for(int x = 0; x < map->width; x++) - { - memcpy(&new_vertex[x * map->height + (map->height - 1 - y)], &map->vertex[y * map->width + x], sizeof(struct point)); - } - } - - // release old map and point to new - free(map->vertex); - map->vertex = new_vertex; - - // permute width and height - Uint16 tmp_height = map->height; - Uint16 tmp_height_old = map->height_old; - Uint16 tmp_height_pixel = map->height_pixel; - Uint16 tmp_width = map->width; - Uint16 tmp_width_old = map->width_old; - Uint16 tmp_width_pixel = map->width_pixel; - - map->height = tmp_width; - map->height_old = tmp_width_old; - map->height_pixel = tmp_width_pixel; - map->width = tmp_height; - map->width_old = tmp_height_old; - map->width_pixel = tmp_height_pixel; - - // permute player positions - // at first the internal array - Uint16 tmpHQ[MAXPLAYERS]; - for(int i = 0; i < MAXPLAYERS; i++) - { - tmpHQ[i] = PlayerHQy[i]; - } - for(int i = 0; i < MAXPLAYERS; i++) - { - PlayerHQy[i] = PlayerHQx[i]; - PlayerHQx[i] = tmpHQ[i]; - } - // and now the map array - for(int i = 0; i < 7; i++) - { - tmpHQ[i] = map->HQy[i]; - } - for(int i = 0; i < 7; i++) - { - map->HQy[i] = map->HQx[i]; - map->HQx[i] = tmpHQ[i]; - } - - // recalculate some values - long int a; - long int b = 0; - for(int y = 0; y < map->height; y++) - { - if(y % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int x = 0; x < map->width; x++) - { - map->vertex[y * map->width + x].VertexX = x; - map->vertex[y * map->width + x].VertexY = y; - map->vertex[y * map->width + x].x = a; - map->vertex[y * map->width + x].y = b + (-TRIANGLE_INCREASE) * (map->vertex[y * map->width + x].h - 0x0A); - map->vertex[y * map->width + x].z = TRIANGLE_INCREASE * (map->vertex[y * map->width + x].h - 0x0A); - - modifyBuild(x, y); - modifyShading(x, y); - modifyResource(x, y); - CSurface::update_shading(map, x, y); - - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } - - // reset mouse and view position to prevent failures - VertexX = 12; - VertexY = 12; - MouseBlitX = correctMouseBlitX(VertexX, VertexY); - MouseBlitY = correctMouseBlitY(VertexX, VertexY); - calculateVertices(); - displayRect.x = 0; - displayRect.y = 0; -} - -void CMap::MirrorMapOnXAxis() -{ - for(int y = 1; y < map->height / 2; y++) - { - for(int x = 0; x < map->width; x++) - { - memcpy(&map->vertex[(map->height - 1 - y + 1) * map->width + x], &map->vertex[y * map->width + x], sizeof(struct point)); - } - } - - // recalculate some values - long int a; - long int b = 0; - for(int y = 0; y < map->height; y++) - { - if(y % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int x = 0; x < map->width; x++) - { - map->vertex[y * map->width + x].VertexX = x; - map->vertex[y * map->width + x].VertexY = y; - map->vertex[y * map->width + x].x = a; - map->vertex[y * map->width + x].y = b + (-TRIANGLE_INCREASE) * (map->vertex[y * map->width + x].h - 0x0A); - map->vertex[y * map->width + x].z = TRIANGLE_INCREASE * (map->vertex[y * map->width + x].h - 0x0A); - - modifyBuild(x, y); - modifyShading(x, y); - modifyResource(x, y); - CSurface::update_shading(map, x, y); - - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } -} - -void CMap::MirrorMapOnYAxis() -{ - for(int y = 0; y < map->height; y++) - { - for(int x = 0; x < map->width / 2; x++) - { - if(y % 2 != 0) - { - if(x != map->width / 2 - 1) - memcpy(&map->vertex[y * map->width + (map->width - 1 - x - 1)], &map->vertex[y * map->width + x], sizeof(struct point)); - } else - memcpy(&map->vertex[y * map->width + (map->width - 1 - x)], &map->vertex[y * map->width + x], sizeof(struct point)); - } - } - - // recalculate some values - long int a; - long int b = 0; - for(int y = 0; y < map->height; y++) - { - if(y % 2 == 0) - a = TRIANGLE_WIDTH / 2; - else - a = TRIANGLE_WIDTH; - - for(int x = 0; x < map->width; x++) - { - map->vertex[y * map->width + x].VertexX = x; - map->vertex[y * map->width + x].VertexY = y; - map->vertex[y * map->width + x].x = a; - map->vertex[y * map->width + x].y = b + (-TRIANGLE_INCREASE) * (map->vertex[y * map->width + x].h - 0x0A); - map->vertex[y * map->width + x].z = TRIANGLE_INCREASE * (map->vertex[y * map->width + x].h - 0x0A); - - modifyBuild(x, y); - modifyShading(x, y); - modifyResource(x, y); - CSurface::update_shading(map, x, y); - - a += TRIANGLE_WIDTH; - } - b += TRIANGLE_HEIGHT; - } -} - -void CMap::loadMapPics() -{ - std::string outputString1, outputString2, outputString3, picFile, palFile; - switch(map->type) - { - case 0: - outputString1 = "\nLoading palette from file: /DATA/MAP00.LST..."; - outputString2 = "\nLoading file: /DATA/MAP00.LST..."; - picFile = "/DATA/MAP00.LST"; - outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL5.BBM..."; - palFile = "/GFX/PALETTE/PAL5.BBM"; - break; - case 1: - outputString1 = "\nLoading palette from file: /DATA/MAP01.LST..."; - outputString2 = "\nLoading file: /DATA/MAP01.LST..."; - picFile = "/DATA/MAP01.LST"; - outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL6.BBM..."; - palFile = "/GFX/PALETTE/PAL6.BBM"; - break; - case 2: - outputString1 = "\nLoading palette from file: /DATA/MAP02.LST..."; - outputString2 = "\nLoading file: /DATA/MAP02.LST..."; - picFile = "/DATA/MAP02.LST"; - outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL7.BBM..."; - palFile = "/GFX/PALETTE/PAL7.BBM"; - break; - default: - outputString1 = "\nLoading palette from file: /DATA/MAP00.LST..."; - outputString2 = "\nLoading file: /DATA/MAP00.LST..."; - picFile = "/DATA/MAP00.LST"; - outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL5.BBM..."; - palFile = "/GFX/PALETTE/PAL5.BBM"; - break; - } - // load only the palette at this time from MAP0x.LST - std::cout << outputString1; - if(!CFile::open_file(global::gameDataFilePath + picFile, LST, true)) - { - std::cout << "failure"; - } - // set the right palette - CFile::set_palActual(CFile::get_palArray() - 1); - std::cout << outputString2; - if(!CFile::open_file(global::gameDataFilePath + picFile, LST)) - { - std::cout << "failure"; - } - // set back palette - // CFile::set_palActual(CFile::get_palArray()); - // std::cout << "\nLoading file: /DATA/MBOB/ROM_BOBS.LST..."; - // if ( !CFile::open_file(global::gameDataFilePath + "/DATA/MBOB/ROM_BOBS.LST", LST) ) - //{ - // std::cout << "failure"; - //} - // set back palette - CFile::set_palActual(CFile::get_palArray()); - // load palette file for the map (for precalculated shading) - std::cout << outputString3; - if(!CFile::open_file(global::gameDataFilePath + palFile, BBM, true)) - { - std::cout << "failure"; - } -} - -void CMap::unloadMapPics() -{ - for(int i = MAPPIC_ARROWCROSS_YELLOW; i <= MAPPIC_LAST_ENTRY; i++) - { - SDL_FreeSurface(global::bmpArray[i].surface); - global::bmpArray[i].surface = NULL; - } - // set back bmpArray-pointer, cause MAP0x.LST is no longer needed - CFile::set_bmpArray(&global::bmpArray[MAPPIC_ARROWCROSS_YELLOW]); - // set back palArray-pointer, cause PALx.BBM is no longer needed - CFile::set_palActual(&global::palArray[PAL_IO]); - CFile::set_palArray(&global::palArray[PAL_IO + 1]); -} - -void CMap::setMouseData(SDL_MouseMotionEvent motion) -{ - // following code important for blitting the right field of the map - static bool warping = false; - // SDL_Event TempEvent; - // is right mouse button pressed? - if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) - { - // this whole "warping-thing" is to prevent cursor-moving WITHIN the window while user moves over the map - if(warping == false) - { - if(!HorizontalMovementLocked) - displayRect.x += motion.xrel; - if(!VerticalMovementLocked) - displayRect.y += motion.yrel; - - // warping = true; - SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); - SDL_WarpMouse(motion.x - motion.xrel, motion.y - motion.yrel); - SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); - // SDL_PumpEvents(); - // SDL_PeepEvents(&TempEvent, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)); - } else - warping = false; - - // reset coords of displayRects when end of map is reached - if(displayRect.x >= map->width * TRIANGLE_WIDTH) - displayRect.x = 0; - else if(displayRect.x <= -displayRect.w) - displayRect.x = map->width * TRIANGLE_WIDTH - displayRect.w; - - if(displayRect.y >= map->height * TRIANGLE_HEIGHT) - displayRect.y = 0; - else if(displayRect.y <= -displayRect.h) - displayRect.y = map->height * TRIANGLE_HEIGHT - displayRect.h; - } - - saveVertex(motion.x, motion.y, motion.state); -} - -void CMap::setMouseData(SDL_MouseButtonEvent button) -{ - if(button.state == SDL_PRESSED) - { -#ifdef _EDITORMODE - // find out if user clicked on one of the game menu pictures - // we start with lower menubar - if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 236) && button.x <= (displayRect.w / 2 - 199) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the height-mode picture was clicked - mode = EDITOR_MODE_HEIGHT_RAISE; - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 199) && button.x <= (displayRect.w / 2 - 162) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the texture-mode picture was clicked - mode = EDITOR_MODE_TEXTURE; - callback::EditorTextureMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 162) && button.x <= (displayRect.w / 2 - 125) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the tree-mode picture was clicked - mode = EDITOR_MODE_TREE; - callback::EditorTreeMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 125) && button.x <= (displayRect.w / 2 - 88) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the resource-mode picture was clicked - mode = EDITOR_MODE_RESOURCE_RAISE; - callback::EditorResourceMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 88) && button.x <= (displayRect.w / 2 - 51) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the landscape-mode picture was clicked - mode = EDITOR_MODE_LANDSCAPE; - callback::EditorLandscapeMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 51) && button.x <= (displayRect.w / 2 - 14) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the animal-mode picture was clicked - mode = EDITOR_MODE_ANIMAL; - callback::EditorAnimalMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 14) && button.x <= (displayRect.w / 2 + 23) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the player-mode picture was clicked - mode = EDITOR_MODE_FLAG; - ChangeSection = 0; - setupVerticesActivity(); - callback::EditorPlayerMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 96) && button.x <= (displayRect.w / 2 + 133) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the build-help picture was clicked - RenderBuildHelp = !RenderBuildHelp; - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 131) && button.x <= (displayRect.w / 2 + 168) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the minimap picture was clicked - callback::MinimapMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 166) && button.x <= (displayRect.w / 2 + 203) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the create-world picture was clicked - callback::EditorCreateMenu(INITIALIZING_CALL); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 203) && button.x <= (displayRect.w / 2 + 240) - && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) - { - // the editor-main-menu picture was clicked - callback::EditorMainMenu(INITIALIZING_CALL); - return; - } - // now we check the right menubar - else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) - && button.y >= (displayRect.h / 2 + 162) && button.y <= (displayRect.h / 2 + 199)) - { - // the bugkill picture was clicked for quickload - callback::PleaseWait(INITIALIZING_CALL); - // we have to close the windows and initialize them again to prevent failures - callback::EditorCursorMenu(MAP_QUIT); - callback::EditorTextureMenu(MAP_QUIT); - callback::EditorTreeMenu(MAP_QUIT); - callback::EditorLandscapeMenu(MAP_QUIT); - callback::MinimapMenu(MAP_QUIT); - callback::EditorResourceMenu(MAP_QUIT); - callback::EditorAnimalMenu(MAP_QUIT); - callback::EditorPlayerMenu(MAP_QUIT); - - destructMap(); - constructMap(global::userMapsPath + "/quicksave.swd"); - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) - && button.y >= (displayRect.h / 2 + 200) && button.y <= (displayRect.h / 2 + 237)) - { - // the bugkill picture was clicked for quicksave - callback::PleaseWait(INITIALIZING_CALL); - if(!CFile::save_file(global::userMapsPath + "/quicksave.swd", SWD, map)) - { - callback::ShowStatus(INITIALIZING_CALL); - callback::ShowStatus(2); - } - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - return; - } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) - && button.y >= (displayRect.h / 2 - 239) && button.y <= (displayRect.h / 2 - 202)) - { - // the cursor picture was clicked - callback::EditorCursorMenu(INITIALIZING_CALL); - return; - } else - { - // no picture was clicked - - // touch vertex data - if(button.button == SDL_BUTTON_LEFT) - { - modify = true; - saveCurrentVertices = true; - } - } -#else - // find out if user clicked on one of the game menu pictures - if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 74) && button.x <= (displayRect.w / 2 - 37) - && button.y >= (displayRect.h - 37) && button.y <= (displayRect.h - 4)) - { - // the first picture was clicked - callback::GameMenu(INITIALIZING_CALL); - } -#endif - } else if(button.state == SDL_RELEASED) - { -#ifdef _EDITORMODE - // stop touching vertex data - if(button.button == SDL_BUTTON_LEFT) - modify = false; -#else - -#endif - } -} - -void CMap::setKeyboardData(SDL_KeyboardEvent key) -{ - if(key.type == SDL_KEYDOWN) - { - if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_HEIGHT_RAISE) - mode = EDITOR_MODE_HEIGHT_REDUCE; - else if(key.keysym.sym == SDLK_LALT && mode == EDITOR_MODE_HEIGHT_RAISE) - mode = EDITOR_MODE_HEIGHT_PLANE; - else if(key.keysym.sym == SDLK_INSERT && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) - { - if(MaxRaiseHeight > 0x00) - MaxRaiseHeight--; - } else if(key.keysym.sym == SDLK_HOME && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) - { - MaxRaiseHeight = 0x3C; - } else if(key.keysym.sym == SDLK_PAGEUP && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) - { - if(MaxRaiseHeight < 0x3C) - MaxRaiseHeight++; - } else if(key.keysym.sym == SDLK_DELETE && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) - { - if(MinReduceHeight > 0x00) - MinReduceHeight--; - } else if(key.keysym.sym == SDLK_END && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) - { - MinReduceHeight = 0x00; - } else if(key.keysym.sym == SDLK_PAGEDOWN && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) - { - if(MinReduceHeight < 0x3C) - MinReduceHeight++; - } else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_RESOURCE_RAISE) - mode = EDITOR_MODE_RESOURCE_REDUCE; - else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_FLAG) - mode = EDITOR_MODE_FLAG_DELETE; - else if(key.keysym.sym == SDLK_LCTRL) - { - lastMode = mode; - mode = EDITOR_MODE_CUT; - } else if(key.keysym.sym == SDLK_b && mode != EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE && mode != EDITOR_MODE_TEXTURE_MAKE_HARBOUR) - { - lastMode = mode; - lastChangeSection = ChangeSection; - ChangeSection = 0; - setupVerticesActivity(); - mode = EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE; - } else if(key.keysym.sym == SDLK_h && mode != EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE && mode != EDITOR_MODE_TEXTURE_MAKE_HARBOUR) - { - lastMode = mode; - lastChangeSection = ChangeSection; - ChangeSection = 0; - setupVerticesActivity(); - mode = EDITOR_MODE_TEXTURE_MAKE_HARBOUR; - } else if(key.keysym.sym == SDLK_r) - { - callback::PleaseWait(INITIALIZING_CALL); - - rotateMap(); - rotateMap(); - - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } else if(key.keysym.sym == SDLK_x) - { - callback::PleaseWait(INITIALIZING_CALL); - - MirrorMapOnXAxis(); - - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } else if(key.keysym.sym == SDLK_y) - { - callback::PleaseWait(INITIALIZING_CALL); - - MirrorMapOnYAxis(); - - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } else if(key.keysym.sym == SDLK_KP_PLUS) - { - if(ChangeSection < MAX_CHANGE_SECTION) - { - ChangeSection++; - setupVerticesActivity(); - } - } else if(key.keysym.sym == SDLK_KP_MINUS) - { - if(ChangeSection > 0) - { - ChangeSection--; - setupVerticesActivity(); - } - } else if(key.keysym.sym == SDLK_1 || key.keysym.sym == SDLK_KP1) - { - ChangeSection = 0; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_2 || key.keysym.sym == SDLK_KP2) - { - ChangeSection = 1; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_3 || key.keysym.sym == SDLK_KP3) - { - ChangeSection = 2; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_4 || key.keysym.sym == SDLK_KP4) - { - ChangeSection = 3; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_5 || key.keysym.sym == SDLK_KP5) - { - ChangeSection = 4; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_6 || key.keysym.sym == SDLK_KP6) - { - ChangeSection = 5; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_7 || key.keysym.sym == SDLK_KP7) - { - ChangeSection = 6; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_8 || key.keysym.sym == SDLK_KP8) - { - ChangeSection = 7; - setupVerticesActivity(); - } else if(key.keysym.sym == SDLK_9 || key.keysym.sym == SDLK_KP9) - { - ChangeSection = 8; - setupVerticesActivity(); - } - - else if(key.keysym.sym == SDLK_SPACE) - { - RenderBuildHelp = !RenderBuildHelp; - } else if(key.keysym.sym == SDLK_F11) - { - RenderBorders = !RenderBorders; - } else if(key.keysym.sym == SDLK_q) - { - if(!saveCurrentVertices) - { - if(CurrPtr_savedVertices != NULL && CurrPtr_savedVertices->prev != NULL) - { - CurrPtr_savedVertices = CurrPtr_savedVertices->prev; - // if (CurrPtr_savedVertices->next->empty && CurrPtr_savedVertices->prev != NULL) - // CurrPtr_savedVertices = CurrPtr_savedVertices->prev; - for(int i = CurrPtr_savedVertices->VertexX - MAX_CHANGE_SECTION - 10 - 2, k = 0; - i <= CurrPtr_savedVertices->VertexX + MAX_CHANGE_SECTION + 10 + 2; i++, k++) - { - for(int j = CurrPtr_savedVertices->VertexY - MAX_CHANGE_SECTION - 10 - 2, l = 0; - j <= CurrPtr_savedVertices->VertexY + MAX_CHANGE_SECTION + 10 + 2; j++, l++) - { - int m = i; - if(m < 0) - m += map->width; - else if(m >= map->width) - m -= map->width; - int n = j; - if(n < 0) - n += map->height; - else if(n >= map->height) - n -= map->height; - memcpy(&(map->vertex[n * map->width + m]), - &(CurrPtr_savedVertices->PointsArroundVertex[l * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) + k]), - sizeof(struct point)); - } - } - } - } - } - /*else if (key.keysym.sym == SDLK_w) - { - if (!saveCurrentVertices) - { - if (CurrPtr_savedVertices != NULL) - { - if (CurrPtr_savedVertices->next != NULL) - CurrPtr_savedVertices = CurrPtr_savedVertices->next; - if (!CurrPtr_savedVertices->empty) - { - for (int i = CurrPtr_savedVertices->VertexX-MAX_CHANGE_SECTION-10-2, k = 0; i <= - CurrPtr_savedVertices->VertexX+MAX_CHANGE_SECTION+10+2; i++, k++) - { - - for (int j = CurrPtr_savedVertices->VertexY-MAX_CHANGE_SECTION-10-2, l = 0; j <= - CurrPtr_savedVertices->VertexY+MAX_CHANGE_SECTION+10+2; j++, l++) - { - int m = i; - if (m < 0) m += map->width; - else if (m >= map->width) m -= map->width; - int n = j; - if (n < 0) n += map->height; - else if (n >= map->height) n -= map->height; - memcpy(&(map->vertex[n*map->width+m]), - &(CurrPtr_savedVertices->PointsArroundVertex[l*((MAX_CHANGE_SECTION+10+2)*2+1)+k]), sizeof(struct point)); - } - } - } - } - } - }*/ - else if(key.keysym.sym == SDLK_UP || key.keysym.sym == SDLK_DOWN || key.keysym.sym == SDLK_LEFT || key.keysym.sym == SDLK_RIGHT) - { - // move displayRect - displayRect.x += (key.keysym.sym == SDLK_LEFT ? -100 : (key.keysym.sym == SDLK_RIGHT ? 100 : 0)); - displayRect.y += (key.keysym.sym == SDLK_UP ? -100 : (key.keysym.sym == SDLK_DOWN ? 100 : 0)); - - // reset coords of displayRects when end of map is reached - if(displayRect.x >= map->width * TRIANGLE_WIDTH) - displayRect.x = 0; - else if(displayRect.x <= -displayRect.w) - displayRect.x = map->width * TRIANGLE_WIDTH - displayRect.w; - - if(displayRect.y >= map->height * TRIANGLE_HEIGHT) - displayRect.y = 0; - else if(displayRect.y <= -displayRect.h) - displayRect.y = map->height * TRIANGLE_HEIGHT - displayRect.h; - } -#ifdef _EDITORMODE - // help menu - else if(key.keysym.sym == SDLK_F1) - { - callback::EditorHelpMenu(INITIALIZING_CALL); - } - // convert map to greenland - else if(key.keysym.sym == SDLK_g) - { - callback::PleaseWait(INITIALIZING_CALL); - - // we have to close the windows and initialize them again to prevent failures - callback::EditorCursorMenu(MAP_QUIT); - callback::EditorTextureMenu(MAP_QUIT); - callback::EditorTreeMenu(MAP_QUIT); - callback::EditorLandscapeMenu(MAP_QUIT); - callback::MinimapMenu(MAP_QUIT); - callback::EditorResourceMenu(MAP_QUIT); - callback::EditorAnimalMenu(MAP_QUIT); - callback::EditorPlayerMenu(MAP_QUIT); - - map->type = 0; - unloadMapPics(); - loadMapPics(); - - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } - // convert map to wasteland - else if(key.keysym.sym == SDLK_o) - { - callback::PleaseWait(INITIALIZING_CALL); - - // we have to close the windows and initialize them again to prevent failures - callback::EditorCursorMenu(MAP_QUIT); - callback::EditorTextureMenu(MAP_QUIT); - callback::EditorTreeMenu(MAP_QUIT); - callback::EditorLandscapeMenu(MAP_QUIT); - callback::MinimapMenu(MAP_QUIT); - callback::EditorResourceMenu(MAP_QUIT); - callback::EditorAnimalMenu(MAP_QUIT); - callback::EditorPlayerMenu(MAP_QUIT); - - map->type = 1; - unloadMapPics(); - loadMapPics(); - - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } - // convert map to winterland - else if(key.keysym.sym == SDLK_w) - { - callback::PleaseWait(INITIALIZING_CALL); - - // we have to close the windows and initialize them again to prevent failures - callback::EditorCursorMenu(MAP_QUIT); - callback::EditorTextureMenu(MAP_QUIT); - callback::EditorTreeMenu(MAP_QUIT); - callback::EditorLandscapeMenu(MAP_QUIT); - callback::MinimapMenu(MAP_QUIT); - callback::EditorResourceMenu(MAP_QUIT); - callback::EditorAnimalMenu(MAP_QUIT); - callback::EditorPlayerMenu(MAP_QUIT); - - map->type = 2; - unloadMapPics(); - loadMapPics(); - - callback::PleaseWait(WINDOW_QUIT_MESSAGE); - } -#endif - else if(key.keysym.sym == SDLK_p) - { - if(BitsPerPixel == 8) - setBitsPerPixel(32); - else - setBitsPerPixel(8); - } - // lock horizontal movement - else if(key.keysym.sym == SDLK_F9) - { - HorizontalMovementLocked = !HorizontalMovementLocked; - } - // lock vertical movement - else if(key.keysym.sym == SDLK_F10) - { - VerticalMovementLocked = !VerticalMovementLocked; - } - } else if(key.type == SDL_KEYUP) - { - // user probably released EDITOR_MODE_HEIGHT_REDUCE - if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_HEIGHT_REDUCE) - mode = EDITOR_MODE_HEIGHT_RAISE; - // user probably released EDITOR_MODE_HEIGHT_PLANE - else if(key.keysym.sym == SDLK_LALT && mode == EDITOR_MODE_HEIGHT_PLANE) - mode = EDITOR_MODE_HEIGHT_RAISE; - // user probably released EDITOR_MODE_RESOURCE_REDUCE - else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_RESOURCE_REDUCE) - mode = EDITOR_MODE_RESOURCE_RAISE; - // user probably released EDITOR_MODE_FLAG_DELETE - else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_FLAG_DELETE) - mode = EDITOR_MODE_FLAG; - // user probably released EDITOR_MODE_CUT - else if(key.keysym.sym == SDLK_LCTRL) - mode = lastMode; - // user probably released EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE - else if(key.keysym.sym == SDLK_b) - { - mode = lastMode; - ChangeSection = lastChangeSection; - setupVerticesActivity(); - } - // user probably released EDITOR_MODE_TEXTURE_MAKE_HARBOUR - else if(key.keysym.sym == SDLK_h) - { - mode = lastMode; - ChangeSection = lastChangeSection; - setupVerticesActivity(); - } - } -} - -void CMap::saveVertex(Uint16 MouseX, Uint16 MouseY, Uint8 MouseState) -{ - // if user raises or reduces the height of a vertex, don't let the cursor jump to another vertex - // if ( (MouseState == SDL_PRESSED) && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE) ) - // return; - - int X = 0, Xeven = 0, Xuneven = 0; - int Y = 0, MousePosY = 0; - - // get X - // following out commented lines are the correct ones, but for tolerance (to prevent to early jumps of the cursor) we substract - // "TRIANGLE_WIDTH/2" Xeven = (MouseX + displayRect.x) / TRIANGLE_WIDTH; - Xeven = (MouseX + displayRect.x - TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH; - if(Xeven < 0) - Xeven += (map->width); - else if(Xeven > map->width - 1) - Xeven -= (map->width - 1); - Xuneven = (MouseX + displayRect.x + TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH; - // Xuneven = (MouseX + displayRect.x) / TRIANGLE_WIDTH; - if(Xuneven < 0) - Xuneven += (map->width - 1); - else if(Xuneven > map->width - 1) - Xuneven -= (map->width); - - MousePosY = MouseY + displayRect.y; - // correct mouse position Y if displayRect is outside map edges - if(MousePosY < 0) - MousePosY += map->height_pixel; - else if(MousePosY > map->height_pixel) - MousePosY = MouseY - (map->height_pixel - displayRect.y); - - // get Y - for(int j = 0; j < map->height; j++) - { - if(j % 2 == 0) - { - // substract "TRIANGLE_HEIGHT/2" is for tolerance, we did the same for X - if((MousePosY - TRIANGLE_HEIGHT / 2) > map->vertex[j * map->width + Xeven].y) - Y++; - else - { - X = Xuneven; - break; - } - } else - { - if((MousePosY - TRIANGLE_HEIGHT / 2) > map->vertex[j * map->width + Xuneven].y) - Y++; - else - { - X = Xeven; - break; - } - } - } - if(Y < 0) - Y += (map->height - 1); - else if(Y > map->height - 1) - Y -= (map->height - 1); - - VertexX = X; - VertexY = Y; - - MouseBlitX = correctMouseBlitX(VertexX, VertexY); - MouseBlitY = correctMouseBlitY(VertexX, VertexY); - - calculateVertices(); -} - -int CMap::correctMouseBlitX(int VertexX, int VertexY) -{ - int MouseBlitX = map->vertex[VertexY * map->width + VertexX].x; - if(MouseBlitX < displayRect.x) - MouseBlitX += map->width_pixel; - else if(MouseBlitX > (displayRect.x + displayRect.w)) - MouseBlitX -= map->width_pixel; - MouseBlitX -= displayRect.x; - - return MouseBlitX; -} -int CMap::correctMouseBlitY(int VertexX, int VertexY) -{ - int MouseBlitY = map->vertex[VertexY * map->width + VertexX].y; - if(MouseBlitY < displayRect.y) - MouseBlitY += map->height_pixel; - else if(MouseBlitY > (displayRect.y + displayRect.h)) - MouseBlitY -= map->height_pixel; - MouseBlitY -= displayRect.y; - - return MouseBlitY; -} - -void CMap::render() -{ - char textBuffer[100]; - - // check if gameresolution has been changed - if(displayRect.w != global::s2->GameResolutionX || displayRect.h != global::s2->GameResolutionY) - { - displayRect.w = global::s2->GameResolutionX; - displayRect.h = global::s2->GameResolutionY; - needSurface = true; - } - - // if we need a new surface - if(needSurface) - { - SDL_FreeSurface(Surf_Map); - Surf_Map = NULL; - if((Surf_Map = SDL_CreateRGBSurface(SDL_SWSURFACE, displayRect.w, displayRect.h, BitsPerPixel, 0, 0, 0, 0)) == NULL) - return; - if(BitsPerPixel == 8) - SDL_SetPalette(Surf_Map, SDL_LOGPAL, global::palArray[PAL_xBBM].colors, 0, 256); - needSurface = false; - } - // else - // clear the surface before drawing new (in normal case not needed) - // SDL_FillRect( Surf_Map, NULL, SDL_MapRGB(Surf_Map->format,0,0,0) ); - - // touch vertex data if user modifies it - if(modify) - modifyVertex(); - - if(map->vertex != NULL) - CSurface::DrawTriangleField(Surf_Map, displayRect, map); - - // draw pictures to cursor position -#ifdef _EDITORMODE - int symbol_index, symbol_index2 = -1; - switch(mode) - { - case EDITOR_MODE_CUT: symbol_index = CURSOR_SYMBOL_SCISSORS; break; - case EDITOR_MODE_TREE: symbol_index = CURSOR_SYMBOL_TREE; break; - case EDITOR_MODE_HEIGHT_RAISE: symbol_index = CURSOR_SYMBOL_ARROW_UP; break; - case EDITOR_MODE_HEIGHT_REDUCE: symbol_index = CURSOR_SYMBOL_ARROW_DOWN; break; - case EDITOR_MODE_HEIGHT_PLANE: - symbol_index = CURSOR_SYMBOL_ARROW_UP; - symbol_index2 = CURSOR_SYMBOL_ARROW_DOWN; - break; - case EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE: symbol_index = MAPPIC_ARROWCROSS_RED_HOUSE_BIG; break; - case EDITOR_MODE_TEXTURE: symbol_index = CURSOR_SYMBOL_TEXTURE; break; - case EDITOR_MODE_TEXTURE_MAKE_HARBOUR: symbol_index = MAPPIC_ARROWCROSS_RED_HOUSE_HARBOUR; break; - case EDITOR_MODE_LANDSCAPE: symbol_index = CURSOR_SYMBOL_LANDSCAPE; break; - case EDITOR_MODE_FLAG: symbol_index = CURSOR_SYMBOL_FLAG; break; - case EDITOR_MODE_FLAG_DELETE: symbol_index = CURSOR_SYMBOL_FLAG; break; - case EDITOR_MODE_RESOURCE_REDUCE: symbol_index = CURSOR_SYMBOL_PICKAXE_MINUS; break; - case EDITOR_MODE_RESOURCE_RAISE: symbol_index = CURSOR_SYMBOL_PICKAXE_PLUS; break; - case EDITOR_MODE_ANIMAL: symbol_index = CURSOR_SYMBOL_ANIMAL; break; - default: symbol_index = CURSOR_SYMBOL_ARROW_UP; break; - } - for(int i = 0; i < VertexCounter; i++) - { - if(Vertices[i].active) - { - CSurface::Draw(Surf_Map, global::bmpArray[symbol_index].surface, Vertices[i].blit_x - 10, Vertices[i].blit_y - 10); - if(symbol_index2 >= 0) - CSurface::Draw(Surf_Map, global::bmpArray[symbol_index2].surface, Vertices[i].blit_x, Vertices[i].blit_y - 7); - } - } - - // text for x and y of vertex (shown in upper left corner) - sprintf(textBuffer, "%d %d", VertexX, VertexY); - CFont::writeText(Surf_Map, textBuffer, 20, 20); - // text for MinReduceHeight and MaxRaiseHeight - sprintf(textBuffer, "min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A", MinReduceHeight, MaxRaiseHeight); - CFont::writeText(Surf_Map, textBuffer, 100, 20); - // text for MovementLocked - if(HorizontalMovementLocked && VerticalMovementLocked) - { - sprintf(textBuffer, "Movement locked (F9 or F10 to unlock)"); - CFont::writeText(Surf_Map, textBuffer, 20, 40, 14, FONT_ORANGE); - } else if(HorizontalMovementLocked) - { - sprintf(textBuffer, "Horizontal movement locked (F9 to unlock)"); - CFont::writeText(Surf_Map, textBuffer, 20, 40, 14, FONT_ORANGE); - } else if(VerticalMovementLocked) - { - sprintf(textBuffer, "Vertikal mvement locked (F10 to unlock)"); - CFont::writeText(Surf_Map, textBuffer, 20, 40, 14, FONT_ORANGE); - } - -#else - CSurface::Draw(Surf_Map, global::bmpArray[CIRCLE_FLAT_GREY].surface, MouseBlitX - 10, MouseBlitY - 10); -#endif - - // draw the frame - if(displayRect.w == 640 && displayRect.h == 480) - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, 0); - else if(displayRect.w == 800 && displayRect.h == 600) - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_800_600].surface, 0, 0); - else if(displayRect.w == 1024 && displayRect.h == 768) - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_1024_768].surface, 0, 0); - else if(displayRect.w == 1280 && displayRect.h == 1024) - { - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_LEFT_1280_1024].surface, 0, 0); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_RIGHT_1280_1024].surface, 640, 0); - } else - { - int x = 150, y = 150; - // draw the corners - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, 0, 0, 0, 150, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, displayRect.h - 150, 0, 480 - 150, 150, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 150, 0, 640 - 150, 0, 150, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 150, displayRect.h - 150, 640 - 150, - 480 - 150, 150, 150); - // draw the edges - while(x < displayRect.w - 150) - { - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, 0, 150, 0, 150, 12); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, displayRect.h - 12, 150, 0, 150, 12); - x += 150; - } - while(y < displayRect.h - 150) - { - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, y, 0, 150, 12, 150); - CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 12, y, 0, 150, 12, 150); - y += 150; - } - } - - // draw the statues at the frame - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_LEFT].surface, 12, 12); - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_RIGHT].surface, displayRect.w - global::bmpArray[STATUE_UP_RIGHT].w - 12, 12); - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_LEFT].surface, 12, displayRect.h - global::bmpArray[STATUE_DOWN_LEFT].h - 12); - CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_RIGHT].surface, displayRect.w - global::bmpArray[STATUE_DOWN_RIGHT].w - 12, - displayRect.h - global::bmpArray[STATUE_DOWN_RIGHT].h - 12); - - // lower menubar - // draw lower menubar - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR].surface, displayRect.w / 2 - global::bmpArray[MENUBAR].w / 2, - displayRect.h - global::bmpArray[MENUBAR].h); - - // draw pictures to lower menubar -#ifdef _EDITORMODE - // backgrounds - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 236, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 199, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 162, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 125, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 88, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 51, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 14, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 92, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 129, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 166, displayRect.h - 36, 0, 0, 37, 32); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 203, displayRect.h - 36, 0, 0, 37, 32); - // pictures - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_HEIGHT].surface, displayRect.w / 2 - 232, displayRect.h - 35); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TEXTURE].surface, displayRect.w / 2 - 195, displayRect.h - 35); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TREE].surface, displayRect.w / 2 - 158, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_RESOURCE].surface, displayRect.w / 2 - 121, displayRect.h - 32); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_LANDSCAPE].surface, displayRect.w / 2 - 84, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_ANIMAL].surface, displayRect.w / 2 - 48, displayRect.h - 36); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_PLAYER].surface, displayRect.w / 2 - 10, displayRect.h - 34); - - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUILDHELP].surface, displayRect.w / 2 + 96, displayRect.h - 35); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_MINIMAP].surface, displayRect.w / 2 + 131, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_NEWWORLD].surface, displayRect.w / 2 + 166, displayRect.h - 37); - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_COMPUTER].surface, displayRect.w / 2 + 207, displayRect.h - 35); -#else - -#endif - -#ifdef _EDITORMODE - // right menubar - // do we need a surface? - if(Surf_RightMenubar == NULL) - { - // we permute width and height, cause we want to rotate the menubar 90 degrees - if((Surf_RightMenubar = - SDL_CreateRGBSurface(SDL_SWSURFACE, global::bmpArray[MENUBAR].h, global::bmpArray[MENUBAR].w, 8, 0, 0, 0, 0)) - != NULL) - { - SDL_SetPalette(Surf_RightMenubar, SDL_LOGPAL, global::palArray[PAL_RESOURCE].colors, 0, 256); - SDL_SetColorKey(Surf_RightMenubar, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surf_RightMenubar->format, 0, 0, 0)); - CSurface::Draw(Surf_RightMenubar, global::bmpArray[MENUBAR].surface, 0, 0, 270); - } - } - // draw right menubar (remember permutation of width and height) - CSurface::Draw(Surf_Map, Surf_RightMenubar, displayRect.w - global::bmpArray[MENUBAR].h, - displayRect.h / 2 - global::bmpArray[MENUBAR].w / 2); - - // draw pictures to right menubar - // backgrounds - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 239, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 202, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 165, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 128, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 22, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 15, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 52, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 89, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 126, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 163, 0, 0, 32, 37); - CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 200, 0, 0, 32, 37); - // pictures - // four cursor menu pictures - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.w - 33, displayRect.h / 2 - 237); - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.w - 20, displayRect.h / 2 - 235); - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.w - 33, displayRect.h / 2 - 220); - CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.w - 20, displayRect.h / 2 - 220); - // bugkill picture for quickload with text - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.w - 37, displayRect.h / 2 + 162); - sprintf(textBuffer, "Load"); - CFont::writeText(Surf_Map, textBuffer, displayRect.w - 35, displayRect.h / 2 + 193); - // bugkill picture for quicksave with text - CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.w - 37, displayRect.h / 2 + 200); - sprintf(textBuffer, "Save"); - CFont::writeText(Surf_Map, textBuffer, displayRect.w - 35, displayRect.h / 2 + 231); - -#endif -} - -void CMap::drawMinimap(SDL_Surface* Window) -{ - Uint32* pixel; - Uint32* row; - - Uint8 r8, g8, b8; - Sint16 r, g, b; - - // this variables are needed to reduce the size of minimap-windows of big maps - int num_x = (map->width > 256 ? map->width / 256 : 1); - int num_y = (map->height > 256 ? map->height / 256 : 1); - - // make sure the minimap has the same proportions as the "real" map, so scale the same rate - num_x = (num_x > num_y ? num_x : num_y); - num_y = (num_x > num_y ? num_x : num_y); - - // if (Window->w < map->width || Window->h < map->height) - // return; - - for(int y = 0; y < map->height; y++) - { - if(y % num_y != 0) - continue; - - row = (Uint32*)Window->pixels + (y + 20) * Window->pitch / 4; - for(int x = 0; x < map->width; x++) - { - if(x % num_x != 0) - continue; - - switch(map->vertex[y * map->width + x].rsuTexture) - { - case TRIANGLE_TEXTURE_STEPPE_MEADOW1: - r = (map->type == 0x00 ? 100 : (map->type == 0x01 ? 68 : 160)); - g = (map->type == 0x00 ? 144 : (map->type == 0x01 ? 72 : 172)); - b = (map->type == 0x00 ? 20 : (map->type == 0x01 ? 80 : 204)); - break; - case TRIANGLE_TEXTURE_MINING1: - r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 112 : 84)); - g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 108 : 88)); - b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 84 : 108)); - break; - case TRIANGLE_TEXTURE_SNOW: - r = (map->type == 0x00 ? 180 : (map->type == 0x01 ? 132 : 0)); - g = (map->type == 0x00 ? 192 : (map->type == 0x01 ? 0 : 48)); - b = (map->type == 0x00 ? 200 : (map->type == 0x01 ? 0 : 104)); - break; - case TRIANGLE_TEXTURE_SWAMP: - r = (map->type == 0x00 ? 100 : (map->type == 0x01 ? 0 : 0)); - g = (map->type == 0x00 ? 144 : (map->type == 0x01 ? 24 : 40)); - b = (map->type == 0x00 ? 20 : (map->type == 0x01 ? 32 : 108)); - break; - case TRIANGLE_TEXTURE_STEPPE: - r = (map->type == 0x00 ? 192 : (map->type == 0x01 ? 156 : 0)); - g = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 124 : 112)); - b = (map->type == 0x00 ? 124 : (map->type == 0x01 ? 100 : 176)); - break; - case TRIANGLE_TEXTURE_WATER: - r = (map->type == 0x00 ? 16 : (map->type == 0x01 ? 68 : 0)); - g = (map->type == 0x00 ? 56 : (map->type == 0x01 ? 68 : 48)); - b = (map->type == 0x00 ? 164 : (map->type == 0x01 ? 44 : 104)); - break; - case TRIANGLE_TEXTURE_MEADOW1: - r = (map->type == 0x00 ? 72 : (map->type == 0x01 ? 92 : 176)); - g = (map->type == 0x00 ? 120 : (map->type == 0x01 ? 88 : 164)); - b = (map->type == 0x00 ? 12 : (map->type == 0x01 ? 64 : 148)); - break; - case TRIANGLE_TEXTURE_MEADOW2: - r = (map->type == 0x00 ? 100 : (map->type == 0x01 ? 100 : 180)); - g = (map->type == 0x00 ? 144 : (map->type == 0x01 ? 96 : 184)); - b = (map->type == 0x00 ? 20 : (map->type == 0x01 ? 72 : 180)); - break; - case TRIANGLE_TEXTURE_MEADOW3: - r = (map->type == 0x00 ? 64 : (map->type == 0x01 ? 100 : 160)); - g = (map->type == 0x00 ? 112 : (map->type == 0x01 ? 96 : 172)); - b = (map->type == 0x00 ? 8 : (map->type == 0x01 ? 72 : 204)); - break; - case TRIANGLE_TEXTURE_MINING2: - r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 112 : 96)); - g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 100 : 96)); - b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 84 : 124)); - break; - case TRIANGLE_TEXTURE_MINING3: - r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 104 : 104)); - g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 76 : 108)); - b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 36 : 140)); - break; - case TRIANGLE_TEXTURE_MINING4: - r = (map->type == 0x00 ? 140 : (map->type == 0x01 ? 104 : 104)); - g = (map->type == 0x00 ? 112 : (map->type == 0x01 ? 76 : 108)); - b = (map->type == 0x00 ? 72 : (map->type == 0x01 ? 36 : 140)); - break; - case TRIANGLE_TEXTURE_STEPPE_MEADOW2: - r = (map->type == 0x00 ? 136 : (map->type == 0x01 ? 112 : 100)); - g = (map->type == 0x00 ? 176 : (map->type == 0x01 ? 108 : 144)); - b = (map->type == 0x00 ? 40 : (map->type == 0x01 ? 84 : 20)); - break; - case TRIANGLE_TEXTURE_FLOWER: - r = (map->type == 0x00 ? 72 : (map->type == 0x01 ? 68 : 124)); - g = (map->type == 0x00 ? 120 : (map->type == 0x01 ? 72 : 132)); - b = (map->type == 0x00 ? 12 : (map->type == 0x01 ? 80 : 172)); - break; - case TRIANGLE_TEXTURE_LAVA: - r = (map->type == 0x00 ? 192 : (map->type == 0x01 ? 128 : 144)); - g = (map->type == 0x00 ? 32 : (map->type == 0x01 ? 20 : 44)); - b = (map->type == 0x00 ? 32 : (map->type == 0x01 ? 0 : 4)); - break; - case TRIANGLE_TEXTURE_MINING_MEADOW: - r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 0 : 148)); - g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 24 : 160)); - b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 32 : 192)); - break; - default: // color grey - r = 128; - g = 128; - b = 128; - break; - } - - row = (Uint32*)Window->pixels + (y / num_y + 20) * Window->pitch / 4; - //+6 because of the left window frame - pixel = row + x / num_x + 6; - - r = ((r * map->vertex[y * map->width + x].i) >> 16); - g = ((g * map->vertex[y * map->width + x].i) >> 16); - b = ((b * map->vertex[y * map->width + x].i) >> 16); - r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - *pixel = ((r8 << Window->format->Rshift) + (g8 << Window->format->Gshift) + (b8 << Window->format->Bshift)); - } - } - -#ifdef _EDITORMODE - // draw the player flags - char playerNumber[2]; - for(int i = 0; i < MAXPLAYERS; i++) - { - if(PlayerHQx[i] != 0xFFFF && PlayerHQx[i] != 0xFFFF) - { - // draw flag - //%7 cause in the original game there are only 7 players and 7 different flags - CSurface::Draw(Window, global::bmpArray[FLAG_BLUE_DARK + i % 7].surface, - 6 + PlayerHQx[i] / num_x - global::bmpArray[FLAG_BLUE_DARK + i % 7].nx, - 20 + PlayerHQy[i] / num_y - global::bmpArray[FLAG_BLUE_DARK + i % 7].ny); - // write player number - sprintf(playerNumber, "%d", i + 1); - CFont::writeText(Window, playerNumber, 6 + PlayerHQx[i] / num_x, 20 + PlayerHQy[i] / num_y, 9, FONT_MINTGREEN); - } - } -#endif - - // draw the arrow --> 6px is width of left window frame and 20px is the height of the upper window frame - CSurface::Draw(Window, global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].surface, - 6 + (displayRect.x + displayRect.w / 2) / TRIANGLE_WIDTH / num_x - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx, - 20 + (displayRect.y + displayRect.h / 2) / TRIANGLE_HEIGHT / num_y - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny); -} - -void CMap::modifyVertex() -{ - static Uint32 TimeOfLastModification = SDL_GetTicks(); - - if((SDL_GetTicks() - TimeOfLastModification) < 5) - return; - else - TimeOfLastModification = SDL_GetTicks(); - - // save vertices for "undo" and "do" - if(saveCurrentVertices) - { - if(CurrPtr_savedVertices != NULL) - { - CurrPtr_savedVertices->empty = false; - CurrPtr_savedVertices->VertexX = VertexX; - CurrPtr_savedVertices->VertexY = VertexY; - for(int i = VertexX - MAX_CHANGE_SECTION - 10 - 2, k = 0; i <= VertexX + MAX_CHANGE_SECTION + 10 + 2; i++, k++) - { - for(int j = VertexY - MAX_CHANGE_SECTION - 10 - 2, l = 0; j <= VertexY + MAX_CHANGE_SECTION + 10 + 2; j++, l++) - { - // i und j muessen wegen den mapraendern noch korrigiert werden! - int m = i; - if(m < 0) - m += map->width; - else if(m >= map->width) - m -= map->width; - int n = j; - if(n < 0) - n += map->height; - else if(n >= map->height) - n -= map->height; - // printf("\n X=%d Y=%d i=%d j=%d k=%d l=%d m=%d n=%d", VertexX, VertexY, i, j, k, l, m, n); - memcpy(&(CurrPtr_savedVertices->PointsArroundVertex[l * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) + k]), - &(map->vertex[n * map->width + m]), sizeof(struct point)); - // CurrPtr_savedVertices->PointsArroundVertex[l*map->width+k] = map->vertex[n*map->width+m]; - } - } - 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; - } - } else - CurrPtr_savedVertices = CurrPtr_savedVertices->next; - } - saveCurrentVertices = false; - } - - if(mode == EDITOR_MODE_HEIGHT_RAISE) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyHeightRaise(Vertices[i].x, Vertices[i].y); - } else if(mode == EDITOR_MODE_HEIGHT_REDUCE) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyHeightReduce(Vertices[i].x, Vertices[i].y); - } else if(mode == EDITOR_MODE_HEIGHT_PLANE) - { - // calculate height average over all vertices - int h_sum = 0; - int h_count = 0; - Uint8 h_avg = 0x00; - - for(int i = 0; i < VertexCounter; i++) - { - if(Vertices[i].active) - { - h_sum += map->vertex[Vertices[i].y * map->width + Vertices[i].x].h; - h_count++; - } - } - - h_avg = h_sum / h_count; - - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyHeightPlane(Vertices[i].x, Vertices[i].y, h_avg); - } else if(mode == EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE) - { - modifyHeightMakeBigHouse(VertexX, VertexY); - } else if(mode == EDITOR_MODE_TEXTURE_MAKE_HARBOUR) - { - modifyHeightMakeBigHouse(VertexX, VertexY); - modifyTextureMakeHarbour(VertexX, VertexY); - } - // at this time we need a modeContent to set - else if(mode == EDITOR_MODE_CUT) - { - for(int i = 0; i < VertexCounter; i++) - { - if(Vertices[i].active) - { - modifyObject(Vertices[i].x, Vertices[i].y); - modifyAnimal(Vertices[i].x, Vertices[i].y); - } - } - } else if(mode == EDITOR_MODE_TEXTURE) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyTexture(Vertices[i].x, Vertices[i].y, Vertices[i].fill_rsu, Vertices[i].fill_usd); - } else if(mode == EDITOR_MODE_TREE) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyObject(Vertices[i].x, Vertices[i].y); - } else if(mode == EDITOR_MODE_LANDSCAPE) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyObject(Vertices[i].x, Vertices[i].y); - } else if(mode == EDITOR_MODE_RESOURCE_RAISE || mode == EDITOR_MODE_RESOURCE_REDUCE) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyResource(Vertices[i].x, Vertices[i].y); - } else if(mode == EDITOR_MODE_ANIMAL) - { - for(int i = 0; i < VertexCounter; i++) - if(Vertices[i].active) - modifyAnimal(Vertices[i].x, Vertices[i].y); - } else if(mode == EDITOR_MODE_FLAG || mode == EDITOR_MODE_FLAG_DELETE) - { - modifyPlayer(VertexX, VertexY); - } -} - -void CMap::modifyHeightRaise(int VertexX, int VertexY) -{ - // vertex count for the points - int X, Y; - struct point* tempP = &map->vertex[VertexY * map->width + VertexX]; - // this is to setup the building depending on the vertices around - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - - bool even = false; - if(VertexY % 2 == 0) - even = true; - - // DO IT - if(tempP->z >= TRIANGLE_INCREASE * (MaxRaiseHeight - 0x0A)) // user specified maximum reached - return; - - if(tempP->z >= TRIANGLE_INCREASE * (0x3C - 0x0A)) // maximum reached (0x3C is max) - return; - - tempP->y -= TRIANGLE_INCREASE; - tempP->z += TRIANGLE_INCREASE; - tempP->h += 0x01; - CSurface::update_shading(map, VertexX, VertexY); - - // after (5*TRIANGLE_INCREASE) pixel all vertices around will be raised too - // update first vertex left upside - X = VertexX - (even ? 1 : 0); - if(X < 0) - X += map->width; - Y = VertexY - 1; - if(Y < 0) - Y += map->height; - // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) - if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) - modifyHeightRaise(X, Y); - // update second vertex right upside - X = VertexX + (even ? 0 : 1); - if(X >= map->width) - X -= map->width; - Y = VertexY - 1; - if(Y < 0) - Y += map->height; - // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) - if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) - modifyHeightRaise(X, Y); - // update third point bottom left - X = VertexX - 1; - if(X < 0) - X += map->width; - Y = VertexY; - // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) - if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) - modifyHeightRaise(X, Y); - // update fourth point bottom right - X = VertexX + 1; - if(X >= map->width) - X -= map->width; - Y = VertexY; - // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) - if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) - modifyHeightRaise(X, Y); - // update fifth point down left - X = VertexX - (even ? 1 : 0); - if(X < 0) - X += map->width; - Y = VertexY + 1; - if(Y >= map->height) - Y -= map->height; - // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) - if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) - modifyHeightRaise(X, Y); - // update sixth point down right - X = VertexX + (even ? 0 : 1); - if(X >= map->width) - X -= map->width; - Y = VertexY + 1; - if(Y >= map->height) - Y -= map->height; - // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) - if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) - modifyHeightRaise(X, Y); - - // at least setup the possible building and shading at the vertex and 2 sections around - for(int i = 0; i < 19; i++) - { - modifyBuild(tempVertices[i].x, tempVertices[i].y); - modifyShading(tempVertices[i].x, tempVertices[i].y); - } -} - -void CMap::modifyHeightReduce(int VertexX, int VertexY) -{ - // vertex count for the points - int X, Y; - struct point* tempP = &map->vertex[VertexY * map->width + VertexX]; - // this is to setup the building depending on the vertices around - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - - bool even = false; - if(VertexY % 2 == 0) - even = true; - - // DO IT - if(tempP->z <= TRIANGLE_INCREASE * (MinReduceHeight - 0x0A)) // user specified minimum reached - return; - - if(tempP->z <= TRIANGLE_INCREASE * (0x00 - 0x0A)) // minimum reached (0x00 is min) - return; - - tempP->y += TRIANGLE_INCREASE; - tempP->z -= TRIANGLE_INCREASE; - tempP->h -= 0x01; - CSurface::update_shading(map, VertexX, VertexY); - // after (5*TRIANGLE_INCREASE) pixel all vertices around will be reduced too - // update first vertex left upside - X = VertexX - (even ? 1 : 0); - if(X < 0) - X += map->width; - Y = VertexY - 1; - if(Y < 0) - Y += map->height; - // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) - if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) - modifyHeightReduce(X, Y); - // update second vertex right upside - X = VertexX + (even ? 0 : 1); - if(X >= map->width) - X -= map->width; - Y = VertexY - 1; - if(Y < 0) - Y += map->height; - // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) - if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) - modifyHeightReduce(X, Y); - // update third point bottom left - X = VertexX - 1; - if(X < 0) - X += map->width; - Y = VertexY; - // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) - if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) - modifyHeightReduce(X, Y); - // update fourth point bottom right - X = VertexX + 1; - if(X >= map->width) - X -= map->width; - Y = VertexY; - // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) - if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) - modifyHeightReduce(X, Y); - // update fifth point down left - X = VertexX - (even ? 1 : 0); - if(X < 0) - X += map->width; - Y = VertexY + 1; - if(Y >= map->height) - Y -= map->height; - // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) - if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) - modifyHeightReduce(X, Y); - // update sixth point down right - X = VertexX + (even ? 0 : 1); - if(X >= map->width) - X -= map->width; - Y = VertexY + 1; - if(Y >= map->height) - Y -= map->height; - // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) - if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) - modifyHeightReduce(X, Y); - - // at least setup the possible building and shading at the vertex and 2 sections around - for(int i = 0; i < 19; i++) - { - modifyBuild(tempVertices[i].x, tempVertices[i].y); - modifyShading(tempVertices[i].x, tempVertices[i].y); - } -} - -void CMap::modifyHeightPlane(int VertexX, int VertexY, Uint8 h) -{ - // we could do "while" but "if" looks better during planing (optical effect) - if(map->vertex[VertexY * map->width + VertexX].h < h) - modifyHeightRaise(VertexX, VertexY); - // we could do "while" but "if" looks better during planing (optical effect) - if(map->vertex[VertexY * map->width + VertexX].h > h) - modifyHeightReduce(VertexX, VertexY); -} - -void CMap::modifyHeightMakeBigHouse(int VertexX, int VertexY) -{ - // at first save all vertices we need to calculate the new building - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - - Uint8 height = map->vertex[VertexY * map->width + VertexX].h; - - // calculate the building using the height of the vertices - - // test the whole section - for(int i = 0; i < 6; i++) - { - while(height - map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h >= 0x04) - modifyHeightRaise(tempVertices[i].x, tempVertices[i].y); - - while(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h - height >= 0x04) - modifyHeightReduce(tempVertices[i].x, tempVertices[i].y); - } - - // test vertex lower right - while(height - map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h >= 0x04) - modifyHeightRaise(tempVertices[6].x, tempVertices[6].y); - - while(map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h - height >= 0x02) - modifyHeightReduce(tempVertices[6].x, tempVertices[6].y); - - // now test the second section around the vertex - - // test the whole section - for(int i = 7; i < 19; i++) - { - while(height - map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h >= 0x03) - modifyHeightRaise(tempVertices[i].x, tempVertices[i].y); - - while(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h - height >= 0x03) - modifyHeightReduce(tempVertices[i].x, tempVertices[i].y); - } - - // remove harbour if there is one - if(map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - { - map->vertex[VertexY * map->width + VertexX].rsuTexture -= 0x40; - } -} - -void CMap::modifyShading(int VertexX, int VertexY) -{ - // temporary to keep the lines short - int X, Y; - // this is to setup the shading depending on the vertices around (2 sections from the cursor) - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - - // shading stakes - int A, B, C, D, Result; - - // shading stake of point right upside (first section) - X = tempVertices[2].x; - Y = tempVertices[2].y; - A = 9 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); - // shading stake of point left (first section) - X = tempVertices[3].x; - Y = tempVertices[3].y; - B = -6 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); - // shading stake of point left (second section) - X = tempVertices[12].x; - Y = tempVertices[12].y; - C = -3 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); - // shading stake of point bottom/middle left (second section) - X = tempVertices[14].x; - Y = tempVertices[14].y; - D = -9 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); - - Result = 0x40 + A + B + C + D; - if(Result > 0x80) - Result = 0x80; - else if(Result < 0x00) - Result = 0x00; - - map->vertex[VertexY * map->width + VertexX].shading = Result; -} - -void CMap::modifyTexture(int VertexX, int VertexY, bool rsu, bool usd) -{ - if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED || modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR) - { - int newContent = rand() % 3; - if(newContent == 0) - { - if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED) - newContent = TRIANGLE_TEXTURE_MEADOW1; - else - newContent = TRIANGLE_TEXTURE_MEADOW1_HARBOUR; - } else if(newContent == 1) - { - if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED) - newContent = TRIANGLE_TEXTURE_MEADOW2; - else - newContent = TRIANGLE_TEXTURE_MEADOW2_HARBOUR; - } else - { - if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED) - newContent = TRIANGLE_TEXTURE_MEADOW3; - else - newContent = TRIANGLE_TEXTURE_MEADOW3_HARBOUR; - } - if(rsu) - map->vertex[VertexY * map->width + VertexX].rsuTexture = newContent; - if(usd) - map->vertex[VertexY * map->width + VertexX].usdTexture = newContent; - } else - { - if(rsu) - map->vertex[VertexY * map->width + VertexX].rsuTexture = modeContent; - if(usd) - map->vertex[VertexY * map->width + VertexX].usdTexture = modeContent; - } - - // at least setup the possible building and the resources at the vertex and 1 section/2 sections around - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - for(int i = 0; i < 19; i++) - { - if(i < 7) - modifyBuild(tempVertices[i].x, tempVertices[i].y); - modifyResource(tempVertices[i].x, tempVertices[i].y); - } -} - -void CMap::modifyTextureMakeHarbour(int VertexX, int VertexY) -{ - if(map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW) - { - map->vertex[VertexY * map->width + VertexX].rsuTexture += 0x40; - } -} - -void CMap::modifyObject(int VertexX, int VertexY) -{ - if(mode == EDITOR_MODE_CUT) - { - // prevent cutting a player position - if(map->vertex[VertexY * map->width + VertexX].objectInfo != 0x80) - { - map->vertex[VertexY * map->width + VertexX].objectType = 0x00; - map->vertex[VertexY * map->width + VertexX].objectInfo = 0x00; - } - } else if(mode == EDITOR_MODE_TREE) - { - // if there is another object at the vertex, return - if(map->vertex[VertexY * map->width + VertexX].objectInfo != 0x00) - return; - if(modeContent == 0xFF) - { - // mixed wood - if(modeContent2 == 0xC4) - { - int newContent = rand() % 3; - if(newContent == 0) - newContent = 0x30; - else if(newContent == 1) - newContent = 0x70; - else - newContent = 0xB0; - // we set different start pictures for the tree, cause the trees should move different, so we add a random value that walks - // from 0 to 7 - map->vertex[VertexY * map->width + VertexX].objectType = newContent + rand() % 8; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } - // mixed palm - else // if (modeContent2 == 0xC5) - { - int newContent = rand() % 2; - int newContent2; - if(newContent == 0) - { - newContent = 0x30; - newContent2 = 0xC5; - } else - { - newContent = 0xF0; - newContent2 = 0xC4; - } - // we set different start pictures for the tree, cause the trees should move different, so we add a random value that walks - // from 0 to 7 - map->vertex[VertexY * map->width + VertexX].objectType = newContent + rand() % 8; - map->vertex[VertexY * map->width + VertexX].objectInfo = newContent2; - } - } else - { - // we set different start pictures for the tree, cause the trees should move different, so we add a random value that walks from - // 0 to 7 - map->vertex[VertexY * map->width + VertexX].objectType = modeContent + rand() % 8; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } - } else if(mode == EDITOR_MODE_LANDSCAPE) - { - // if there is another object at the vertex, return - if(map->vertex[VertexY * map->width + VertexX].objectInfo != 0x00) - return; - - if(modeContent == 0x01) - { - int newContent = modeContent + rand() % 6; - int newContent2 = 0xCC + rand() % 2; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = newContent2; - - // now set up the buildings around the granite - modifyBuild(VertexX, VertexY); - } else if(modeContent == 0x05) - { - int newContent = modeContent + rand() % 2; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x02) - { - int newContent = modeContent + rand() % 3; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x0C) - { - int newContent = modeContent + rand() % 2; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x25) - { - int newContent = modeContent + rand() % 3; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x10) - { - int newContent = rand() % 4; - if(newContent == 0) - newContent = 0x10; - else if(newContent == 1) - newContent = 0x11; - else if(newContent == 2) - newContent = 0x12; - else - newContent = 0x0A; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x0E) - { - int newContent = rand() % 4; - if(newContent == 0) - newContent = 0x0E; - else if(newContent == 1) - newContent = 0x0F; - else if(newContent == 2) - newContent = 0x13; - else - newContent = 0x14; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x07) - { - int newContent = modeContent + rand() % 2; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x00) - { - int newContent = rand() % 3; - if(newContent == 0) - newContent = 0x00; - else if(newContent == 1) - newContent = 0x01; - else - newContent = 0x22; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x18) - { - int newContent = modeContent + rand() % 7; - - map->vertex[VertexY * map->width + VertexX].objectType = newContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } else if(modeContent == 0x09) - { - map->vertex[VertexY * map->width + VertexX].objectType = modeContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; - } - } - // at least setup the possible building at the vertex and 1 section around - cursorPoint tempVertices[7]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 1); - for(int i = 0; i < 7; i++) - modifyBuild(tempVertices[i].x, tempVertices[i].y); -} - -void CMap::modifyAnimal(int VertexX, int VertexY) -{ - if(mode == EDITOR_MODE_CUT) - { - map->vertex[VertexY * map->width + VertexX].animal = 0x00; - } else if(mode == EDITOR_MODE_ANIMAL) - { - // if there is another object at the vertex, return - if(map->vertex[VertexY * map->width + VertexX].animal != 0x00) - return; - - if(modeContent > 0x00 && modeContent <= 0x06) - map->vertex[VertexY * map->width + VertexX].animal = modeContent; - } -} - -void CMap::modifyBuild(int VertexX, int VertexY) -{ - // at first save all vertices we need to calculate the new building - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - - /// evtl. keine festen werte sondern addition und subtraktion wegen originalkompatibilitaet (bei baeumen bspw. keine 0x00 sondern 0x68) - - Uint8 building; - Uint8 height = map->vertex[VertexY * map->width + VertexX].h, temp; - - // calculate the building using the height of the vertices - // this building is a mine - if(map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING4) - { - building = 0x05; - // test vertex lower right - temp = map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h; - if(temp - height >= 0x04) - building = 0x01; - } - // not a mine - else - { - building = 0x04; - // test the whole section - for(int i = 0; i < 6; i++) - { - temp = map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h; - if(height - temp >= 0x04 || temp - height >= 0x04) - building = 0x01; - } - - // test vertex lower right - temp = map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h; - if(height - temp >= 0x04 || temp - height >= 0x02) - building = 0x01; - - // now test the second section around the vertex - if(building > 0x02) - { - // test the whole section - for(int i = 7; i < 19; i++) - { - temp = map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h; - if(height - temp >= 0x03 || temp - height >= 0x03) - building = 0x02; - } - } - } - - // test if there is an object AROUND the vertex (trees or granite) - if(building > 0x01) - { - for(int i = 1; i < 7; i++) - { - if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xC4 // tree - || map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xC5 // tree - || map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xC6 // tree - ) - { - // if lower right - if(i == 6) - { - building = 0x01; - break; - } else - building = 0x02; - } else if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xCC // granite - || map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xCD // granite - ) - { - building = 0x01; - break; - } - } - } - - // test if there is an object AT the vertex (trees or granite) - if(building > 0x00) - { - if(map->vertex[VertexY * map->width + VertexX].objectInfo == 0xC4 // tree - || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xC5 // tree - || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xC6 // tree - || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xCC // granite - || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xCD // granite - ) - { - building = 0x00; - } - } - - // test if there is snow or lava at the vertex or around the vertex and touching the vertex (first section) - if(building > 0x00) - { - if(map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_LAVA) - { - building = 0x00; - } - } - - // test if there is snow or lava on the right side (RSU), in lower left (USD) or in lower right (first section) - if(building > 0x01) - { - if(map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].rsuTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].rsuTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].usdTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].usdTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].rsuTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].usdTexture == TRIANGLE_TEXTURE_SNOW - || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].rsuTexture == TRIANGLE_TEXTURE_LAVA - || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].usdTexture == TRIANGLE_TEXTURE_LAVA) - { - building = 0x01; - } - } - - // test if vertex is surrounded by water or swamp - if(building > 0x00) - { - if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) - && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) - && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) - && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_SWAMP)) - { - building = 0x00; - } else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) - || (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) - || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) - || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) - || (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) - || (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_SWAMP)) - { - building = 0x01; - } - } - - // test if there is steppe at the vertex or touching the vertex - if(building > 0x01) - { - if(map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE) - { - building = 0x01; - } - } - - // test if vertex is surrounded by mining-textures - if(building > 0x01) - { - if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING4)) - { - building = 0x05; - } else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - || (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING4) - || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING4) - || (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - || (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING4)) - { - building = 0x01; - } - } - - // test for headquarters around the point - // NOTE: In EDITORMODE don't test AT the point, cause in Original game we need a big house AT the point, otherwise the game wouldn't set - // a player there - if(building > 0x00) - { - for(int i = 1; i < 7; i++) - { - if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0x80) - building = 0x00; - } - } -#ifndef _EDITORMODE - if(building > 0x00) - { - if(map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].objectInfo == 0x80) - building = 0x00; - } -#endif - - // test for headquarters around (second section) - if(building > 0x01) - { - for(int i = 7; i < 19; i++) - { - if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0x80) - { - if(i == 15 || i == 17 || i == 18) - building = 0x01; - else - { - // make middle house, but only if it's not a mine - if(building > 0x03 && building < 0x05) - building = 0x03; - } - } - } - } - - // Some additional information for "ingame"-building-calculation: - // There is no difference between small, middle and big houses. If you set a small house on a vertex, the - // buildings around will change like this where a middle or a big house. - // Only a flag has another algorithm. - //--Flagge einfuegen!!! - - map->vertex[VertexY * map->width + VertexX].build = building; -} - -void CMap::modifyResource(int VertexX, int VertexY) -{ - // at first save all vertices we need to check - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - - // SPECIAL CASE: test if we should set water only - // test if vertex is surrounded by meadow and meadow-like textures - if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_FLOWER - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR)) - { - map->vertex[VertexY * map->width + VertexX].resource = 0x21; - } - // SPECIAL CASE: test if we should set fishes only - // test if vertex is surrounded by water (first section) and at least one non-water texture in the second section - else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_WATER) - && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_WATER) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_WATER) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_WATER) - && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_WATER) - && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_WATER) - && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[7].y * map->width + tempVertices[7].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[7].y * map->width + tempVertices[7].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[8].y * map->width + tempVertices[8].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[8].y * map->width + tempVertices[8].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[9].y * map->width + tempVertices[9].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[10].y * map->width + tempVertices[10].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[10].y * map->width + tempVertices[10].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[11].y * map->width + tempVertices[11].x].rsuTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[12].y * map->width + tempVertices[12].x].usdTexture != TRIANGLE_TEXTURE_WATER - || map->vertex[tempVertices[14].y * map->width + tempVertices[14].x].usdTexture != TRIANGLE_TEXTURE_WATER)) - { - map->vertex[VertexY * map->width + VertexX].resource = 0x87; - } - // test if vertex is surrounded by mining textures - else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) - && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING1 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING2 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING3 - || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING4)) - { - // check which resource to set - if(mode == EDITOR_MODE_RESOURCE_RAISE) - { - // if there is no or another resource at the moment - if(map->vertex[VertexY * map->width + VertexX].resource == 0x40 - || map->vertex[VertexY * map->width + VertexX].resource < modeContent - || map->vertex[VertexY * map->width + VertexX].resource > modeContent + 6) - { - map->vertex[VertexY * map->width + VertexX].resource = modeContent; - } else if(map->vertex[VertexY * map->width + VertexX].resource >= modeContent - && map->vertex[VertexY * map->width + VertexX].resource <= modeContent + 6) - { - // maximum not reached? - if(map->vertex[VertexY * map->width + VertexX].resource != modeContent + 6) - map->vertex[VertexY * map->width + VertexX].resource++; - } - } else if(mode == EDITOR_MODE_RESOURCE_REDUCE) - { - // minimum not reached? - if(map->vertex[VertexY * map->width + VertexX].resource != 0x40) - { - map->vertex[VertexY * map->width + VertexX].resource--; - // minimum now reached? if so, set it to 0x40 - if(map->vertex[VertexY * map->width + VertexX].resource == 0x48 - || map->vertex[VertexY * map->width + VertexX].resource == 0x50 - || map->vertex[VertexY * map->width + VertexX].resource == 0x58 - // in case of coal we already have a 0x40, so don't check this - //|| map->vertex[VertexY*map->width+VertexX].resource == 0x40 - ) - map->vertex[VertexY * map->width + VertexX].resource = 0x40; - } - } else if(map->vertex[VertexY * map->width + VertexX].resource == 0x00) - map->vertex[VertexY * map->width + VertexX].resource = 0x40; - } else - map->vertex[VertexY * map->width + VertexX].resource = 0x00; -} - -void CMap::modifyPlayer(int VertexX, int VertexY) -{ - // if we have repositioned a player, we need the old position to recalculate the buildings there - bool PlayerRePositioned = false; - int oldPositionX = 0; - int oldPositionY = 0; - - // set player position - if(mode == EDITOR_MODE_FLAG) - { - // only allowed on big houses (0x04) --> but in cheat mode within the game also small houses (0x02) are allowed - if(/*map->vertex[VertexY*map->width+VertexX].objectType == 0x00 - && map->vertex[VertexY*map->width+VertexX].objectInfo == 0x00 - &&*/ map->vertex[VertexY * map->width + VertexX] - .build - % 8 - == 0x04 - && map->vertex[VertexY * map->width + VertexX].objectInfo != 0x80) - { - map->vertex[VertexY * map->width + VertexX].objectType = modeContent; - map->vertex[VertexY * map->width + VertexX].objectInfo = 0x80; - - // save old position if exists - if(PlayerHQx[modeContent] != 0xFFFF && PlayerHQy[modeContent] != 0xFFFF) - { - oldPositionX = PlayerHQx[modeContent]; - oldPositionY = PlayerHQy[modeContent]; - map->vertex[oldPositionY * map->width + oldPositionX].objectType = 0x00; - map->vertex[oldPositionY * map->width + oldPositionX].objectInfo = 0x00; - PlayerRePositioned = true; - } - PlayerHQx[modeContent] = VertexX; - PlayerHQy[modeContent] = VertexY; - - // for compatibility with original settlers 2 we write the headquarters positions to the map header (for the first 7 players) - if(modeContent >= 0 && modeContent < 7) - { - map->HQx[modeContent] = VertexX; - map->HQy[modeContent] = VertexY; - } - - // setup number of players in map header - if(!PlayerRePositioned) - map->player++; - } - } - // delete player position - else if(mode == EDITOR_MODE_FLAG_DELETE) - { - if(map->vertex[VertexY * map->width + VertexX].objectInfo == 0x80) - { - // at first delete the player position using the number of the player as saved in objectType - if(map->vertex[VertexY * map->width + VertexX].objectType < MAXPLAYERS) - { - PlayerHQx[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; - PlayerHQy[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; - - // for compatibility with original settlers 2 we write the headquarters positions to the map header (for the first 7 - // players) - if(modeContent >= 0 && modeContent < 7) - { - map->HQx[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; - map->HQy[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; - } - } - - map->vertex[VertexY * map->width + VertexX].objectType = 0x00; - map->vertex[VertexY * map->width + VertexX].objectInfo = 0x00; - - // setup number of players in map header - map->player--; - } - } - - // at least setup the possible building at the vertex and 2 sections around - cursorPoint tempVertices[19]; - calculateVerticesAround(tempVertices, VertexX, VertexY, 2); - for(int i = 0; i < 19; i++) - modifyBuild(tempVertices[i].x, tempVertices[i].y); - - if(PlayerRePositioned) - { - calculateVerticesAround(tempVertices, oldPositionX, oldPositionY, 2); - for(int i = 0; i < 19; i++) - modifyBuild(tempVertices[i].x, tempVertices[i].y); - } -} - -int CMap::getActiveVertices(int tempChangeSection) -{ - int total = 0; - for(int i = tempChangeSection; i > 0; i--) - total += i; - return (6 * total + 1); -} - -void CMap::calculateVertices() -{ - bool even = false; - if(VertexY % 2 == 0) - even = true; - - int index = 0; - for(int i = -MAX_CHANGE_SECTION; i <= MAX_CHANGE_SECTION; i++) - { - if(abs(i) % 2 == 0) - { - for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION; j++, index++) - { - Vertices[index].x = VertexX + j; - if(Vertices[index].x < 0) - Vertices[index].x += map->width; - else if(Vertices[index].x >= map->width) - Vertices[index].x -= map->width; - Vertices[index].y = VertexY + i; - if(Vertices[index].y < 0) - Vertices[index].y += map->height; - else if(Vertices[index].y >= map->height) - Vertices[index].y -= map->height; - Vertices[index].blit_x = correctMouseBlitX(Vertices[index].x, Vertices[index].y); - Vertices[index].blit_y = correctMouseBlitY(Vertices[index].x, Vertices[index].y); - } - } else - { - for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++, index++) - { - Vertices[index].x = VertexX + (even ? j : j + 1); - if(Vertices[index].x < 0) - Vertices[index].x += map->width; - else if(Vertices[index].x >= map->width) - Vertices[index].x -= map->width; - Vertices[index].y = VertexY + i; - if(Vertices[index].y < 0) - Vertices[index].y += map->height; - else if(Vertices[index].y >= map->height) - Vertices[index].y -= map->height; - Vertices[index].blit_x = correctMouseBlitX(Vertices[index].x, Vertices[index].y); - Vertices[index].blit_y = correctMouseBlitY(Vertices[index].x, Vertices[index].y); - } - } - } - // check if cursor vertices should change randomly - if(VertexActivityRandom || VertexFillRandom) - setupVerticesActivity(); -} - -void CMap::calculateVerticesAround(cursorPoint Vertices[], int VertexX, int VertexY, int ChangeSection) -{ - bool even = false; - if(VertexY % 2 == 0) - even = true; - - Vertices[0].x = VertexX; - Vertices[0].y = VertexY; - Vertices[0].blit_x = MouseBlitX; - Vertices[0].blit_y = MouseBlitY; - - if(ChangeSection > 0) - { - Vertices[1].x = VertexX - (even ? 1 : 0); - if(Vertices[1].x < 0) - Vertices[1].x += map->width; - Vertices[1].y = VertexY - 1; - if(Vertices[1].y < 0) - Vertices[1].y += map->height; - Vertices[1].blit_x = correctMouseBlitX(Vertices[1].x, Vertices[1].y); - Vertices[1].blit_y = correctMouseBlitY(Vertices[1].x, Vertices[1].y); - Vertices[2].x = VertexX + (even ? 0 : 1); - if(Vertices[2].x >= map->width) - Vertices[2].x -= map->width; - Vertices[2].y = VertexY - 1; - if(Vertices[2].y < 0) - Vertices[2].y += map->height; - Vertices[2].blit_x = correctMouseBlitX(Vertices[2].x, Vertices[2].y); - Vertices[2].blit_y = correctMouseBlitY(Vertices[2].x, Vertices[2].y); - Vertices[3].x = VertexX - 1; - if(Vertices[3].x < 0) - Vertices[3].x += map->width; - Vertices[3].y = VertexY; - Vertices[3].blit_x = correctMouseBlitX(Vertices[3].x, Vertices[3].y); - Vertices[3].blit_y = correctMouseBlitY(Vertices[3].x, Vertices[3].y); - Vertices[4].x = VertexX + 1; - if(Vertices[4].x >= map->width) - Vertices[4].x -= map->width; - Vertices[4].y = VertexY; - Vertices[4].blit_x = correctMouseBlitX(Vertices[4].x, Vertices[4].y); - Vertices[4].blit_y = correctMouseBlitY(Vertices[4].x, Vertices[4].y); - Vertices[5].x = VertexX - (even ? 1 : 0); - if(Vertices[5].x < 0) - Vertices[5].x += map->width; - Vertices[5].y = VertexY + 1; - if(Vertices[5].y >= map->height) - Vertices[5].y -= map->height; - Vertices[5].blit_x = correctMouseBlitX(Vertices[5].x, Vertices[5].y); - Vertices[5].blit_y = correctMouseBlitY(Vertices[5].x, Vertices[5].y); - Vertices[6].x = VertexX + (even ? 0 : 1); - if(Vertices[6].x >= map->width) - Vertices[6].x -= map->width; - Vertices[6].y = VertexY + 1; - if(Vertices[6].y >= map->height) - Vertices[6].y -= map->height; - Vertices[6].blit_x = correctMouseBlitX(Vertices[6].x, Vertices[6].y); - Vertices[6].blit_y = correctMouseBlitY(Vertices[6].x, Vertices[6].y); - } - if(ChangeSection > 1) - { - Vertices[7].x = VertexX - 1; - if(Vertices[7].x < 0) - Vertices[7].x += map->width; - Vertices[7].y = VertexY - 2; - if(Vertices[7].y < 0) - Vertices[7].y += map->height; - Vertices[7].blit_x = correctMouseBlitX(Vertices[7].x, Vertices[7].y); - Vertices[7].blit_y = correctMouseBlitY(Vertices[7].x, Vertices[7].y); - Vertices[8].x = VertexX; - Vertices[8].y = VertexY - 2; - if(Vertices[8].y < 0) - Vertices[8].y += map->height; - Vertices[8].blit_x = correctMouseBlitX(Vertices[8].x, Vertices[8].y); - Vertices[8].blit_y = correctMouseBlitY(Vertices[8].x, Vertices[8].y); - Vertices[9].x = VertexX + 1; - if(Vertices[9].x >= map->width) - Vertices[9].x -= map->width; - Vertices[9].y = VertexY - 2; - if(Vertices[9].y < 0) - Vertices[9].y += map->height; - Vertices[9].blit_x = correctMouseBlitX(Vertices[9].x, Vertices[9].y); - Vertices[9].blit_y = correctMouseBlitY(Vertices[9].x, Vertices[9].y); - Vertices[10].x = VertexX - (even ? 2 : 1); - if(Vertices[10].x < 0) - Vertices[10].x += map->width; - Vertices[10].y = VertexY - 1; - if(Vertices[10].y < 0) - Vertices[10].y += map->height; - Vertices[10].blit_x = correctMouseBlitX(Vertices[10].x, Vertices[10].y); - Vertices[10].blit_y = correctMouseBlitY(Vertices[10].x, Vertices[10].y); - Vertices[11].x = VertexX + (even ? 1 : 2); - if(Vertices[11].x >= map->width) - Vertices[11].x -= map->width; - Vertices[11].y = VertexY - 1; - if(Vertices[11].y < 0) - Vertices[11].y += map->height; - Vertices[11].blit_x = correctMouseBlitX(Vertices[11].x, Vertices[11].y); - Vertices[11].blit_y = correctMouseBlitY(Vertices[11].x, Vertices[11].y); - Vertices[12].x = VertexX - 2; - if(Vertices[12].x < 0) - Vertices[12].x += map->width; - Vertices[12].y = VertexY; - Vertices[12].blit_x = correctMouseBlitX(Vertices[12].x, Vertices[12].y); - Vertices[12].blit_y = correctMouseBlitY(Vertices[12].x, Vertices[12].y); - Vertices[13].x = VertexX + 2; - if(Vertices[13].x >= map->width) - Vertices[13].x -= map->width; - Vertices[13].y = VertexY; - Vertices[13].blit_x = correctMouseBlitX(Vertices[13].x, Vertices[13].y); - Vertices[13].blit_y = correctMouseBlitY(Vertices[13].x, Vertices[13].y); - Vertices[14].x = VertexX - (even ? 2 : 1); - if(Vertices[14].x < 0) - Vertices[14].x += map->width; - Vertices[14].y = VertexY + 1; - if(Vertices[14].y >= map->height) - Vertices[14].y -= map->height; - Vertices[14].blit_x = correctMouseBlitX(Vertices[14].x, Vertices[14].y); - Vertices[14].blit_y = correctMouseBlitY(Vertices[14].x, Vertices[14].y); - Vertices[15].x = VertexX + (even ? 1 : 2); - if(Vertices[15].x >= map->width) - Vertices[15].x -= map->width; - Vertices[15].y = VertexY + 1; - if(Vertices[15].y >= map->height) - Vertices[15].y -= map->height; - Vertices[15].blit_x = correctMouseBlitX(Vertices[15].x, Vertices[15].y); - Vertices[15].blit_y = correctMouseBlitY(Vertices[15].x, Vertices[15].y); - Vertices[16].x = VertexX - 1; - if(Vertices[16].x < 0) - Vertices[16].x += map->width; - Vertices[16].y = VertexY + 2; - if(Vertices[16].y >= map->height) - Vertices[16].y -= map->height; - Vertices[16].blit_x = correctMouseBlitX(Vertices[16].x, Vertices[16].y); - Vertices[16].blit_y = correctMouseBlitY(Vertices[16].x, Vertices[16].y); - Vertices[17].x = VertexX; - Vertices[17].y = VertexY + 2; - if(Vertices[17].y >= map->height) - Vertices[17].y -= map->height; - Vertices[17].blit_x = correctMouseBlitX(Vertices[17].x, Vertices[17].y); - Vertices[17].blit_y = correctMouseBlitY(Vertices[17].x, Vertices[17].y); - Vertices[18].x = VertexX + 1; - if(Vertices[18].x >= map->width) - Vertices[18].x -= map->width; - Vertices[18].y = VertexY + 2; - if(Vertices[18].y >= map->height) - Vertices[18].y -= map->height; - Vertices[18].blit_x = correctMouseBlitX(Vertices[18].x, Vertices[18].y); - Vertices[18].blit_y = correctMouseBlitY(Vertices[18].x, Vertices[18].y); - } -} - -void CMap::setupVerticesActivity() -{ - int index = 0; - for(int i = -MAX_CHANGE_SECTION; i <= MAX_CHANGE_SECTION; i++) - { - if(abs(i) % 2 == 0) - { - for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION; j++, index++) - { - if(abs(i) <= ChangeSection && abs(j) <= ChangeSection - (ChangeSectionHexagonMode ? abs(i / 2) : 0)) - { - // check if cursor vertices should change randomly - if(VertexActivityRandom) - Vertices[index].active = (rand() % 2 == 1 ? true : false); - else - Vertices[index].active = true; - - // decide which triangle-textures will be filled at this vertex (necessary for border) - Vertices[index].fill_rsu = (VertexFillRSU ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); - Vertices[index].fill_usd = (VertexFillUSD ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); - - // if we have a ChangeSection greater than zero - if(ChangeSection) - { - // if we are in hexagon mode - if(ChangeSectionHexagonMode) - { - // if we walk through the upper rows of the cursor field - if(i < 0) - { - // right vertex of the row - if(j == ChangeSection - abs(i / 2)) - Vertices[index].fill_usd = false; - } - // if we are at the last lower row - else if(i == ChangeSection) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - // if we walk through the lower rows of the cursor field - else // if (i >= 0 && i != ChangeSection) - { - // left vertex of the row - if(j == -ChangeSection + abs(i / 2)) - Vertices[index].fill_rsu = false; - // right vertex of the row - else if(j == ChangeSection - abs(i / 2)) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - } - } - // we are in square mode - else - { - // if we are at the last lower row - if(i == ChangeSection) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - // left vertex of the row - else if(j == -ChangeSection) - Vertices[index].fill_rsu = false; - // right vertex of the row - else if(j == ChangeSection) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - } - } - } else - { - Vertices[index].active = false; - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - } - } else - { - for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++, index++) - { - if(abs(i) <= ChangeSection - && (j < 0 ? abs(j) <= ChangeSection - (ChangeSectionHexagonMode ? abs(i / 2) : 0) : - j <= ChangeSection - 1 - (ChangeSectionHexagonMode ? abs(i / 2) : 0))) - { - // check if cursor vertices should change randomly - if(VertexActivityRandom) - Vertices[index].active = (rand() % 2 == 1 ? true : false); - else - Vertices[index].active = true; - - // decide which triangle-textures will be filled at this vertex (necessary for border) - Vertices[index].fill_rsu = (VertexFillRSU ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); - Vertices[index].fill_usd = (VertexFillUSD ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); - - // if we have a ChangeSection greater than zero - if(ChangeSection) - { - // if we are in hexagon mode - if(ChangeSectionHexagonMode) - { - // if we walk through the upper rows of the cursor field - if(i < 0) - { - // right vertex of the row - if(j == ChangeSection - 1 - abs(i / 2)) - Vertices[index].fill_usd = false; - } - // if we are at the last lower row - else if(i == ChangeSection) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - // if we walk through the lower rows of the cursor field - else // if (i >= 0 && i != ChangeSection) - { - // left vertex of the row - if(j == -ChangeSection + abs(i / 2)) - Vertices[index].fill_rsu = false; - // right vertex of the row - else if(j == ChangeSection - 1 - abs(i / 2)) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - } - } - // we are in square mode - else - { - // if we are at the last lower row - if(i == ChangeSection) - { - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - // right vertex of the row - else if(j == ChangeSection - 1) - Vertices[index].fill_usd = false; - } - } - } else - { - Vertices[index].active = false; - Vertices[index].fill_rsu = false; - Vertices[index].fill_usd = false; - } - } - } - } - // NOTE: to understand this '-(ChangeSectionHexagonMode ? abs(i/2) : 0)' - // if we don't change the cursor size in square-mode, but in hexagon mode, - // at each row there have to be missing as much vertices as the row number is - // i = row number --> so at the left side of the row there are missing i/2 - // and at the right side there are missing i/2. That makes it look like an hexagon. -} +#include "CMap.h" +#include "CGame.h" +#include "CIO/CFile.h" +#include "CIO/CFont.h" +#include "CSurface.h" +#include "callbacks.h" +#include "globals.h" +#include +#include + +CMap::CMap(const std::string& filename) +{ + constructMap(filename); +} + +CMap::~CMap() +{ + destructMap(); +} + +void CMap::constructMap(const std::string& filename, int width, int height, int type, int texture, int border, int border_texture) +{ + map = NULL; + Surf_Map = NULL; + Surf_RightMenubar = NULL; + displayRect.x = 0; + displayRect.y = 0; + displayRect.w = global::s2->GameResolutionX; + displayRect.h = global::s2->GameResolutionY; + + if(!filename.empty()) + map = (bobMAP*)CFile::open_file(filename, WLD); + + if(map == NULL) + map = generateMap(width, height, type, texture, border, border_texture); + + // load the right MAP0x.LST for all pictures + loadMapPics(); + + CSurface::get_nodeVectors(map); +#ifdef _EDITORMODE + // for safety recalculate build and shadow data and test if fishes and water is correct + for(int i = 0; i < map->height; i++) + { + for(int j = 0; j < map->width; j++) + { + modifyBuild(j, i); + modifyShading(j, i); + modifyResource(j, i); + } + } +#endif + needSurface = true; + active = true; + VertexX = 10; + VertexY = 10; + RenderBuildHelp = false; + RenderBorders = true; + BitsPerPixel = 32; + MouseBlitX = correctMouseBlitX(VertexX, VertexY); + MouseBlitY = correctMouseBlitY(VertexX, VertexY); + ChangeSection = 1; + lastChangeSection = ChangeSection; + ChangeSectionHexagonMode = true; + VertexFillRSU = true; + VertexFillUSD = true; + VertexFillRandom = false; + VertexActivityRandom = false; + // calculate the maximum number of vertices for cursor + VertexCounter = 0; + for(int i = -MAX_CHANGE_SECTION; i <= MAX_CHANGE_SECTION; i++) + { + if(abs(i) % 2 == 0) + for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION; j++) + VertexCounter++; + else + for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++) + VertexCounter++; + } + Vertices = (struct cursorPoint*)malloc(VertexCounter * sizeof(struct cursorPoint)); + calculateVertices(); + setupVerticesActivity(); + mode = EDITOR_MODE_HEIGHT_RAISE; + lastMode = EDITOR_MODE_HEIGHT_RAISE; + modeContent = 0x00; + modeContent2 = 0x00; + modify = false; + 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; + } + + // 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; + // now for internal reasons save all players to a new array, also players with number greater than 7 + // initalize the internal array + for(int i = 0; i < MAXPLAYERS; i++) + { + PlayerHQx[i] = 0xFFFF; + PlayerHQy[i] = 0xFFFF; + } + // find out player positions + for(int y = 0; y < map->height; y++) + { + for(int x = 0; x < map->width; x++) + { + if(map->vertex[y * map->width + x].objectInfo == 0x80) + { + CountPlayers++; + // objectType is the number of the player + if(map->vertex[y * map->width + x].objectType < MAXPLAYERS) + { + PlayerHQx[map->vertex[y * map->width + x].objectType] = x; + PlayerHQy[map->vertex[y * map->width + x].objectType] = y; + + // for compatibility with original settlers 2 save the first 7 player positions to the map header + // NOTE: this is already done by map loading, but to prevent inconsistence we do it again this way + if(map->vertex[y * map->width + x].objectType < 0x07) + { + map->HQx[map->vertex[y * map->width + x].objectType] = x; + map->HQy[map->vertex[y * map->width + x].objectType] = y; + } + } + } + } + } + map->player = CountPlayers; + + HorizontalMovementLocked = false; + VerticalMovementLocked = false; +} +void CMap::destructMap() +{ + // free all surfaces that MAP0x.LST needed + unloadMapPics(); + // free concatenated list for "undo" and "do" + if(CurrPtr_savedVertices != NULL) + { + // go to the end + while(CurrPtr_savedVertices->next != NULL) + { + CurrPtr_savedVertices = CurrPtr_savedVertices->next; + } + // and now free all pointers from behind + while(CurrPtr_savedVertices->prev != NULL) + { + CurrPtr_savedVertices = CurrPtr_savedVertices->prev; + free(CurrPtr_savedVertices->next); + } + free(CurrPtr_savedVertices); + } + // free the map surface + SDL_FreeSurface(Surf_Map); + Surf_Map = NULL; + // free the surface of the right menubar + SDL_FreeSurface(Surf_RightMenubar); + Surf_RightMenubar = NULL; + // free vertex array + free(Vertices); + // free vertex memory + free(map->vertex); + // free map structure memory + free(map); +} + +bobMAP* CMap::generateMap(int width, int height, int type, int texture, int border, int border_texture) +{ + bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP)); + Uint8 heightFactor; + + strcpy(myMap->name, "Ohne Namen"); + myMap->width = width; + myMap->width_old = width; + myMap->width_pixel = myMap->width * TRIANGLE_WIDTH; + myMap->height = height; + myMap->height_old = height; + myMap->height_pixel = myMap->height * TRIANGLE_HEIGHT; + myMap->type = type; + myMap->player = 0; + strcpy(myMap->author, "Niemand"); + for(int i = 0; i < 7; i++) + { + myMap->HQx[i] = 0xFFFF; + myMap->HQy[i] = 0xFFFF; + } + + if((myMap->vertex = (struct point*)malloc(sizeof(struct point) * myMap->width * myMap->height)) == NULL) + { + free(myMap); + return NULL; + } + + int a; + int b = 0; + for(int j = 0; j < myMap->height; j++) + { + if(j % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int i = 0; i < myMap->width; i++) + { + myMap->vertex[j * myMap->width + i].VertexX = i; + myMap->vertex[j * myMap->width + i].VertexY = j; + heightFactor = 0x0A; + myMap->vertex[j * myMap->width + i].h = heightFactor; + myMap->vertex[j * myMap->width + i].x = a; + myMap->vertex[j * myMap->width + i].y = b + (-TRIANGLE_INCREASE) * (heightFactor - 0x0A); + myMap->vertex[j * myMap->width + i].z = TRIANGLE_INCREASE * (heightFactor - 0x0A); + a += TRIANGLE_WIDTH; + + if((j < border || myMap->height - j <= border) || (i < border || myMap->width - i <= border)) + { + myMap->vertex[j * myMap->width + i].rsuTexture = border_texture; + myMap->vertex[j * myMap->width + i].usdTexture = border_texture; + } else + { + myMap->vertex[j * myMap->width + i].rsuTexture = texture; + myMap->vertex[j * myMap->width + i].usdTexture = texture; + } + + // initialize all other blocks -- outcommented blocks are recalculated at map load + myMap->vertex[j * myMap->width + i].road = 0x00; + myMap->vertex[j * myMap->width + i].objectType = 0x00; + myMap->vertex[j * myMap->width + i].objectInfo = 0x00; + myMap->vertex[j * myMap->width + i].animal = 0x00; + myMap->vertex[j * myMap->width + i].unknown1 = 0x00; + // myMap->vertex[j*myMap->width+i].build = 0x00; + myMap->vertex[j * myMap->width + i].unknown2 = 0x07; + myMap->vertex[j * myMap->width + i].unknown3 = 0x00; + // myMap->vertex[j*myMap->width+i].resource = 0x00; + // myMap->vertex[j*myMap->width+i].shading = 0x00; + myMap->vertex[j * myMap->width + i].unknown5 = 0x00; + } + b += TRIANGLE_HEIGHT; + } + + return myMap; +} + +void CMap::rotateMap() +{ + // we allocate memory for the new triangle field but with x equals the height and y equals the width + struct point* new_vertex = NULL; + if((new_vertex = (struct point*)malloc(map->height * map->width * sizeof(struct point))) == NULL) + return; + + // free concatenated list for "undo" and "do" + if(CurrPtr_savedVertices != NULL) + { + // go to the end + while(CurrPtr_savedVertices->next != NULL) + { + CurrPtr_savedVertices = CurrPtr_savedVertices->next; + } + // and now free all pointers from behind + while(CurrPtr_savedVertices->prev != NULL) + { + CurrPtr_savedVertices = CurrPtr_savedVertices->prev; + free(CurrPtr_savedVertices->next); + } + CurrPtr_savedVertices->next = NULL; + } + + // copy old to new while permuting x and y + for(int y = 0; y < map->height; y++) + { + for(int x = 0; x < map->width; x++) + { + memcpy(&new_vertex[x * map->height + (map->height - 1 - y)], &map->vertex[y * map->width + x], sizeof(struct point)); + } + } + + // release old map and point to new + free(map->vertex); + map->vertex = new_vertex; + + // permute width and height + Uint16 tmp_height = map->height; + Uint16 tmp_height_old = map->height_old; + Uint16 tmp_height_pixel = map->height_pixel; + Uint16 tmp_width = map->width; + Uint16 tmp_width_old = map->width_old; + Uint16 tmp_width_pixel = map->width_pixel; + + map->height = tmp_width; + map->height_old = tmp_width_old; + map->height_pixel = tmp_width_pixel; + map->width = tmp_height; + map->width_old = tmp_height_old; + map->width_pixel = tmp_height_pixel; + + // permute player positions + // at first the internal array + Uint16 tmpHQ[MAXPLAYERS]; + for(int i = 0; i < MAXPLAYERS; i++) + { + tmpHQ[i] = PlayerHQy[i]; + } + for(int i = 0; i < MAXPLAYERS; i++) + { + PlayerHQy[i] = PlayerHQx[i]; + PlayerHQx[i] = tmpHQ[i]; + } + // and now the map array + for(int i = 0; i < 7; i++) + { + tmpHQ[i] = map->HQy[i]; + } + for(int i = 0; i < 7; i++) + { + map->HQy[i] = map->HQx[i]; + map->HQx[i] = tmpHQ[i]; + } + + // recalculate some values + long int a; + long int b = 0; + for(int y = 0; y < map->height; y++) + { + if(y % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int x = 0; x < map->width; x++) + { + map->vertex[y * map->width + x].VertexX = x; + map->vertex[y * map->width + x].VertexY = y; + map->vertex[y * map->width + x].x = a; + map->vertex[y * map->width + x].y = b + (-TRIANGLE_INCREASE) * (map->vertex[y * map->width + x].h - 0x0A); + map->vertex[y * map->width + x].z = TRIANGLE_INCREASE * (map->vertex[y * map->width + x].h - 0x0A); + + modifyBuild(x, y); + modifyShading(x, y); + modifyResource(x, y); + CSurface::update_shading(map, x, y); + + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } + + // reset mouse and view position to prevent failures + VertexX = 12; + VertexY = 12; + MouseBlitX = correctMouseBlitX(VertexX, VertexY); + MouseBlitY = correctMouseBlitY(VertexX, VertexY); + calculateVertices(); + displayRect.x = 0; + displayRect.y = 0; +} + +void CMap::MirrorMapOnXAxis() +{ + for(int y = 1; y < map->height / 2; y++) + { + for(int x = 0; x < map->width; x++) + { + memcpy(&map->vertex[(map->height - 1 - y + 1) * map->width + x], &map->vertex[y * map->width + x], sizeof(struct point)); + } + } + + // recalculate some values + long int a; + long int b = 0; + for(int y = 0; y < map->height; y++) + { + if(y % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int x = 0; x < map->width; x++) + { + map->vertex[y * map->width + x].VertexX = x; + map->vertex[y * map->width + x].VertexY = y; + map->vertex[y * map->width + x].x = a; + map->vertex[y * map->width + x].y = b + (-TRIANGLE_INCREASE) * (map->vertex[y * map->width + x].h - 0x0A); + map->vertex[y * map->width + x].z = TRIANGLE_INCREASE * (map->vertex[y * map->width + x].h - 0x0A); + + modifyBuild(x, y); + modifyShading(x, y); + modifyResource(x, y); + CSurface::update_shading(map, x, y); + + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } +} + +void CMap::MirrorMapOnYAxis() +{ + for(int y = 0; y < map->height; y++) + { + for(int x = 0; x < map->width / 2; x++) + { + if(y % 2 != 0) + { + if(x != map->width / 2 - 1) + memcpy(&map->vertex[y * map->width + (map->width - 1 - x - 1)], &map->vertex[y * map->width + x], sizeof(struct point)); + } else + memcpy(&map->vertex[y * map->width + (map->width - 1 - x)], &map->vertex[y * map->width + x], sizeof(struct point)); + } + } + + // recalculate some values + long int a; + long int b = 0; + for(int y = 0; y < map->height; y++) + { + if(y % 2 == 0) + a = TRIANGLE_WIDTH / 2; + else + a = TRIANGLE_WIDTH; + + for(int x = 0; x < map->width; x++) + { + map->vertex[y * map->width + x].VertexX = x; + map->vertex[y * map->width + x].VertexY = y; + map->vertex[y * map->width + x].x = a; + map->vertex[y * map->width + x].y = b + (-TRIANGLE_INCREASE) * (map->vertex[y * map->width + x].h - 0x0A); + map->vertex[y * map->width + x].z = TRIANGLE_INCREASE * (map->vertex[y * map->width + x].h - 0x0A); + + modifyBuild(x, y); + modifyShading(x, y); + modifyResource(x, y); + CSurface::update_shading(map, x, y); + + a += TRIANGLE_WIDTH; + } + b += TRIANGLE_HEIGHT; + } +} + +void CMap::loadMapPics() +{ + std::string outputString1, outputString2, outputString3, picFile, palFile; + switch(map->type) + { + case 0: + outputString1 = "\nLoading palette from file: /DATA/MAP00.LST..."; + outputString2 = "\nLoading file: /DATA/MAP00.LST..."; + picFile = "/DATA/MAP00.LST"; + outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL5.BBM..."; + palFile = "/GFX/PALETTE/PAL5.BBM"; + break; + case 1: + outputString1 = "\nLoading palette from file: /DATA/MAP01.LST..."; + outputString2 = "\nLoading file: /DATA/MAP01.LST..."; + picFile = "/DATA/MAP01.LST"; + outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL6.BBM..."; + palFile = "/GFX/PALETTE/PAL6.BBM"; + break; + case 2: + outputString1 = "\nLoading palette from file: /DATA/MAP02.LST..."; + outputString2 = "\nLoading file: /DATA/MAP02.LST..."; + picFile = "/DATA/MAP02.LST"; + outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL7.BBM..."; + palFile = "/GFX/PALETTE/PAL7.BBM"; + break; + default: + outputString1 = "\nLoading palette from file: /DATA/MAP00.LST..."; + outputString2 = "\nLoading file: /DATA/MAP00.LST..."; + picFile = "/DATA/MAP00.LST"; + outputString3 = "\nLoading palette from file: /GFX/PALETTE/PAL5.BBM..."; + palFile = "/GFX/PALETTE/PAL5.BBM"; + break; + } + // load only the palette at this time from MAP0x.LST + std::cout << outputString1; + if(!CFile::open_file(global::gameDataFilePath + picFile, LST, true)) + { + std::cout << "failure"; + } + // set the right palette + CFile::set_palActual(CFile::get_palArray() - 1); + std::cout << outputString2; + if(!CFile::open_file(global::gameDataFilePath + picFile, LST)) + { + std::cout << "failure"; + } + // set back palette + // CFile::set_palActual(CFile::get_palArray()); + // std::cout << "\nLoading file: /DATA/MBOB/ROM_BOBS.LST..."; + // if ( !CFile::open_file(global::gameDataFilePath + "/DATA/MBOB/ROM_BOBS.LST", LST) ) + //{ + // std::cout << "failure"; + //} + // set back palette + CFile::set_palActual(CFile::get_palArray()); + // load palette file for the map (for precalculated shading) + std::cout << outputString3; + if(!CFile::open_file(global::gameDataFilePath + palFile, BBM, true)) + { + std::cout << "failure"; + } +} + +void CMap::unloadMapPics() +{ + for(int i = MAPPIC_ARROWCROSS_YELLOW; i <= MAPPIC_LAST_ENTRY; i++) + { + SDL_FreeSurface(global::bmpArray[i].surface); + global::bmpArray[i].surface = NULL; + } + // set back bmpArray-pointer, cause MAP0x.LST is no longer needed + CFile::set_bmpArray(&global::bmpArray[MAPPIC_ARROWCROSS_YELLOW]); + // set back palArray-pointer, cause PALx.BBM is no longer needed + CFile::set_palActual(&global::palArray[PAL_IO]); + CFile::set_palArray(&global::palArray[PAL_IO + 1]); +} + +void CMap::setMouseData(SDL_MouseMotionEvent motion) +{ + // following code important for blitting the right field of the map + static bool warping = false; + // SDL_Event TempEvent; + // is right mouse button pressed? + if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) + { + // this whole "warping-thing" is to prevent cursor-moving WITHIN the window while user moves over the map + if(warping == false) + { + if(!HorizontalMovementLocked) + displayRect.x += motion.xrel; + if(!VerticalMovementLocked) + displayRect.y += motion.yrel; + + // warping = true; + SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); + SDL_WarpMouse(motion.x - motion.xrel, motion.y - motion.yrel); + SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); + // SDL_PumpEvents(); + // SDL_PeepEvents(&TempEvent, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)); + } else + warping = false; + + // reset coords of displayRects when end of map is reached + if(displayRect.x >= map->width * TRIANGLE_WIDTH) + displayRect.x = 0; + else if(displayRect.x <= -displayRect.w) + displayRect.x = map->width * TRIANGLE_WIDTH - displayRect.w; + + if(displayRect.y >= map->height * TRIANGLE_HEIGHT) + displayRect.y = 0; + else if(displayRect.y <= -displayRect.h) + displayRect.y = map->height * TRIANGLE_HEIGHT - displayRect.h; + } + + saveVertex(motion.x, motion.y, motion.state); +} + +void CMap::setMouseData(SDL_MouseButtonEvent button) +{ + if(button.state == SDL_PRESSED) + { +#ifdef _EDITORMODE + // find out if user clicked on one of the game menu pictures + // we start with lower menubar + if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 236) && button.x <= (displayRect.w / 2 - 199) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the height-mode picture was clicked + mode = EDITOR_MODE_HEIGHT_RAISE; + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 199) && button.x <= (displayRect.w / 2 - 162) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the texture-mode picture was clicked + mode = EDITOR_MODE_TEXTURE; + callback::EditorTextureMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 162) && button.x <= (displayRect.w / 2 - 125) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the tree-mode picture was clicked + mode = EDITOR_MODE_TREE; + callback::EditorTreeMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 125) && button.x <= (displayRect.w / 2 - 88) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the resource-mode picture was clicked + mode = EDITOR_MODE_RESOURCE_RAISE; + callback::EditorResourceMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 88) && button.x <= (displayRect.w / 2 - 51) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the landscape-mode picture was clicked + mode = EDITOR_MODE_LANDSCAPE; + callback::EditorLandscapeMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 51) && button.x <= (displayRect.w / 2 - 14) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the animal-mode picture was clicked + mode = EDITOR_MODE_ANIMAL; + callback::EditorAnimalMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 14) && button.x <= (displayRect.w / 2 + 23) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the player-mode picture was clicked + mode = EDITOR_MODE_FLAG; + ChangeSection = 0; + setupVerticesActivity(); + callback::EditorPlayerMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 96) && button.x <= (displayRect.w / 2 + 133) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the build-help picture was clicked + RenderBuildHelp = !RenderBuildHelp; + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 131) && button.x <= (displayRect.w / 2 + 168) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the minimap picture was clicked + callback::MinimapMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 166) && button.x <= (displayRect.w / 2 + 203) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the create-world picture was clicked + callback::EditorCreateMenu(INITIALIZING_CALL); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 + 203) && button.x <= (displayRect.w / 2 + 240) + && button.y >= (displayRect.h - 35) && button.y <= (displayRect.h - 3)) + { + // the editor-main-menu picture was clicked + callback::EditorMainMenu(INITIALIZING_CALL); + return; + } + // now we check the right menubar + else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) + && button.y >= (displayRect.h / 2 + 162) && button.y <= (displayRect.h / 2 + 199)) + { + // the bugkill picture was clicked for quickload + callback::PleaseWait(INITIALIZING_CALL); + // we have to close the windows and initialize them again to prevent failures + callback::EditorCursorMenu(MAP_QUIT); + callback::EditorTextureMenu(MAP_QUIT); + callback::EditorTreeMenu(MAP_QUIT); + callback::EditorLandscapeMenu(MAP_QUIT); + callback::MinimapMenu(MAP_QUIT); + callback::EditorResourceMenu(MAP_QUIT); + callback::EditorAnimalMenu(MAP_QUIT); + callback::EditorPlayerMenu(MAP_QUIT); + + destructMap(); + constructMap(global::userMapsPath + "/quicksave.swd"); + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) + && button.y >= (displayRect.h / 2 + 200) && button.y <= (displayRect.h / 2 + 237)) + { + // the bugkill picture was clicked for quicksave + callback::PleaseWait(INITIALIZING_CALL); + if(!CFile::save_file(global::userMapsPath + "/quicksave.swd", SWD, map)) + { + callback::ShowStatus(INITIALIZING_CALL); + callback::ShowStatus(2); + } + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + return; + } else if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w - 37) && button.x <= (displayRect.w) + && button.y >= (displayRect.h / 2 - 239) && button.y <= (displayRect.h / 2 - 202)) + { + // the cursor picture was clicked + callback::EditorCursorMenu(INITIALIZING_CALL); + return; + } else + { + // no picture was clicked + + // touch vertex data + if(button.button == SDL_BUTTON_LEFT) + { + modify = true; + saveCurrentVertices = true; + } + } +#else + // find out if user clicked on one of the game menu pictures + if(button.button == SDL_BUTTON_LEFT && button.x >= (displayRect.w / 2 - 74) && button.x <= (displayRect.w / 2 - 37) + && button.y >= (displayRect.h - 37) && button.y <= (displayRect.h - 4)) + { + // the first picture was clicked + callback::GameMenu(INITIALIZING_CALL); + } +#endif + } else if(button.state == SDL_RELEASED) + { +#ifdef _EDITORMODE + // stop touching vertex data + if(button.button == SDL_BUTTON_LEFT) + modify = false; +#else + +#endif + } +} + +void CMap::setKeyboardData(SDL_KeyboardEvent key) +{ + if(key.type == SDL_KEYDOWN) + { + if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_HEIGHT_RAISE) + mode = EDITOR_MODE_HEIGHT_REDUCE; + else if(key.keysym.sym == SDLK_LALT && mode == EDITOR_MODE_HEIGHT_RAISE) + mode = EDITOR_MODE_HEIGHT_PLANE; + else if(key.keysym.sym == SDLK_INSERT && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) + { + if(MaxRaiseHeight > 0x00) + MaxRaiseHeight--; + } else if(key.keysym.sym == SDLK_HOME && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) + { + MaxRaiseHeight = 0x3C; + } else if(key.keysym.sym == SDLK_PAGEUP && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) + { + if(MaxRaiseHeight < 0x3C) + MaxRaiseHeight++; + } else if(key.keysym.sym == SDLK_DELETE && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) + { + if(MinReduceHeight > 0x00) + MinReduceHeight--; + } else if(key.keysym.sym == SDLK_END && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) + { + MinReduceHeight = 0x00; + } else if(key.keysym.sym == SDLK_PAGEDOWN && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE)) + { + if(MinReduceHeight < 0x3C) + MinReduceHeight++; + } else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_RESOURCE_RAISE) + mode = EDITOR_MODE_RESOURCE_REDUCE; + else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_FLAG) + mode = EDITOR_MODE_FLAG_DELETE; + else if(key.keysym.sym == SDLK_LCTRL) + { + lastMode = mode; + mode = EDITOR_MODE_CUT; + } else if(key.keysym.sym == SDLK_b && mode != EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE && mode != EDITOR_MODE_TEXTURE_MAKE_HARBOUR) + { + lastMode = mode; + lastChangeSection = ChangeSection; + ChangeSection = 0; + setupVerticesActivity(); + mode = EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE; + } else if(key.keysym.sym == SDLK_h && mode != EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE && mode != EDITOR_MODE_TEXTURE_MAKE_HARBOUR) + { + lastMode = mode; + lastChangeSection = ChangeSection; + ChangeSection = 0; + setupVerticesActivity(); + mode = EDITOR_MODE_TEXTURE_MAKE_HARBOUR; + } else if(key.keysym.sym == SDLK_r) + { + callback::PleaseWait(INITIALIZING_CALL); + + rotateMap(); + rotateMap(); + + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } else if(key.keysym.sym == SDLK_x) + { + callback::PleaseWait(INITIALIZING_CALL); + + MirrorMapOnXAxis(); + + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } else if(key.keysym.sym == SDLK_y) + { + callback::PleaseWait(INITIALIZING_CALL); + + MirrorMapOnYAxis(); + + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } else if(key.keysym.sym == SDLK_KP_PLUS) + { + if(ChangeSection < MAX_CHANGE_SECTION) + { + ChangeSection++; + setupVerticesActivity(); + } + } else if(key.keysym.sym == SDLK_KP_MINUS) + { + if(ChangeSection > 0) + { + ChangeSection--; + setupVerticesActivity(); + } + } else if(key.keysym.sym == SDLK_1 || key.keysym.sym == SDLK_KP1) + { + ChangeSection = 0; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_2 || key.keysym.sym == SDLK_KP2) + { + ChangeSection = 1; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_3 || key.keysym.sym == SDLK_KP3) + { + ChangeSection = 2; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_4 || key.keysym.sym == SDLK_KP4) + { + ChangeSection = 3; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_5 || key.keysym.sym == SDLK_KP5) + { + ChangeSection = 4; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_6 || key.keysym.sym == SDLK_KP6) + { + ChangeSection = 5; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_7 || key.keysym.sym == SDLK_KP7) + { + ChangeSection = 6; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_8 || key.keysym.sym == SDLK_KP8) + { + ChangeSection = 7; + setupVerticesActivity(); + } else if(key.keysym.sym == SDLK_9 || key.keysym.sym == SDLK_KP9) + { + ChangeSection = 8; + setupVerticesActivity(); + } + + else if(key.keysym.sym == SDLK_SPACE) + { + RenderBuildHelp = !RenderBuildHelp; + } else if(key.keysym.sym == SDLK_F11) + { + RenderBorders = !RenderBorders; + } else if(key.keysym.sym == SDLK_q) + { + if(!saveCurrentVertices) + { + if(CurrPtr_savedVertices != NULL && CurrPtr_savedVertices->prev != NULL) + { + CurrPtr_savedVertices = CurrPtr_savedVertices->prev; + // if (CurrPtr_savedVertices->next->empty && CurrPtr_savedVertices->prev != NULL) + // CurrPtr_savedVertices = CurrPtr_savedVertices->prev; + for(int i = CurrPtr_savedVertices->VertexX - MAX_CHANGE_SECTION - 10 - 2, k = 0; + i <= CurrPtr_savedVertices->VertexX + MAX_CHANGE_SECTION + 10 + 2; i++, k++) + { + for(int j = CurrPtr_savedVertices->VertexY - MAX_CHANGE_SECTION - 10 - 2, l = 0; + j <= CurrPtr_savedVertices->VertexY + MAX_CHANGE_SECTION + 10 + 2; j++, l++) + { + int m = i; + if(m < 0) + m += map->width; + else if(m >= map->width) + m -= map->width; + int n = j; + if(n < 0) + n += map->height; + else if(n >= map->height) + n -= map->height; + memcpy(&(map->vertex[n * map->width + m]), + &(CurrPtr_savedVertices->PointsArroundVertex[l * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) + k]), + sizeof(struct point)); + } + } + } + } + } + /*else if (key.keysym.sym == SDLK_w) + { + if (!saveCurrentVertices) + { + if (CurrPtr_savedVertices != NULL) + { + if (CurrPtr_savedVertices->next != NULL) + CurrPtr_savedVertices = CurrPtr_savedVertices->next; + if (!CurrPtr_savedVertices->empty) + { + for (int i = CurrPtr_savedVertices->VertexX-MAX_CHANGE_SECTION-10-2, k = 0; i <= + CurrPtr_savedVertices->VertexX+MAX_CHANGE_SECTION+10+2; i++, k++) + { + + for (int j = CurrPtr_savedVertices->VertexY-MAX_CHANGE_SECTION-10-2, l = 0; j <= + CurrPtr_savedVertices->VertexY+MAX_CHANGE_SECTION+10+2; j++, l++) + { + int m = i; + if (m < 0) m += map->width; + else if (m >= map->width) m -= map->width; + int n = j; + if (n < 0) n += map->height; + else if (n >= map->height) n -= map->height; + memcpy(&(map->vertex[n*map->width+m]), + &(CurrPtr_savedVertices->PointsArroundVertex[l*((MAX_CHANGE_SECTION+10+2)*2+1)+k]), sizeof(struct point)); + } + } + } + } + } + }*/ + else if(key.keysym.sym == SDLK_UP || key.keysym.sym == SDLK_DOWN || key.keysym.sym == SDLK_LEFT || key.keysym.sym == SDLK_RIGHT) + { + // move displayRect + displayRect.x += (key.keysym.sym == SDLK_LEFT ? -100 : (key.keysym.sym == SDLK_RIGHT ? 100 : 0)); + displayRect.y += (key.keysym.sym == SDLK_UP ? -100 : (key.keysym.sym == SDLK_DOWN ? 100 : 0)); + + // reset coords of displayRects when end of map is reached + if(displayRect.x >= map->width * TRIANGLE_WIDTH) + displayRect.x = 0; + else if(displayRect.x <= -displayRect.w) + displayRect.x = map->width * TRIANGLE_WIDTH - displayRect.w; + + if(displayRect.y >= map->height * TRIANGLE_HEIGHT) + displayRect.y = 0; + else if(displayRect.y <= -displayRect.h) + displayRect.y = map->height * TRIANGLE_HEIGHT - displayRect.h; + } +#ifdef _EDITORMODE + // help menu + else if(key.keysym.sym == SDLK_F1) + { + callback::EditorHelpMenu(INITIALIZING_CALL); + } + // convert map to greenland + else if(key.keysym.sym == SDLK_g) + { + callback::PleaseWait(INITIALIZING_CALL); + + // we have to close the windows and initialize them again to prevent failures + callback::EditorCursorMenu(MAP_QUIT); + callback::EditorTextureMenu(MAP_QUIT); + callback::EditorTreeMenu(MAP_QUIT); + callback::EditorLandscapeMenu(MAP_QUIT); + callback::MinimapMenu(MAP_QUIT); + callback::EditorResourceMenu(MAP_QUIT); + callback::EditorAnimalMenu(MAP_QUIT); + callback::EditorPlayerMenu(MAP_QUIT); + + map->type = 0; + unloadMapPics(); + loadMapPics(); + + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } + // convert map to wasteland + else if(key.keysym.sym == SDLK_o) + { + callback::PleaseWait(INITIALIZING_CALL); + + // we have to close the windows and initialize them again to prevent failures + callback::EditorCursorMenu(MAP_QUIT); + callback::EditorTextureMenu(MAP_QUIT); + callback::EditorTreeMenu(MAP_QUIT); + callback::EditorLandscapeMenu(MAP_QUIT); + callback::MinimapMenu(MAP_QUIT); + callback::EditorResourceMenu(MAP_QUIT); + callback::EditorAnimalMenu(MAP_QUIT); + callback::EditorPlayerMenu(MAP_QUIT); + + map->type = 1; + unloadMapPics(); + loadMapPics(); + + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } + // convert map to winterland + else if(key.keysym.sym == SDLK_w) + { + callback::PleaseWait(INITIALIZING_CALL); + + // we have to close the windows and initialize them again to prevent failures + callback::EditorCursorMenu(MAP_QUIT); + callback::EditorTextureMenu(MAP_QUIT); + callback::EditorTreeMenu(MAP_QUIT); + callback::EditorLandscapeMenu(MAP_QUIT); + callback::MinimapMenu(MAP_QUIT); + callback::EditorResourceMenu(MAP_QUIT); + callback::EditorAnimalMenu(MAP_QUIT); + callback::EditorPlayerMenu(MAP_QUIT); + + map->type = 2; + unloadMapPics(); + loadMapPics(); + + callback::PleaseWait(WINDOW_QUIT_MESSAGE); + } +#endif + else if(key.keysym.sym == SDLK_p) + { + if(BitsPerPixel == 8) + setBitsPerPixel(32); + else + setBitsPerPixel(8); + } + // lock horizontal movement + else if(key.keysym.sym == SDLK_F9) + { + HorizontalMovementLocked = !HorizontalMovementLocked; + } + // lock vertical movement + else if(key.keysym.sym == SDLK_F10) + { + VerticalMovementLocked = !VerticalMovementLocked; + } + } else if(key.type == SDL_KEYUP) + { + // user probably released EDITOR_MODE_HEIGHT_REDUCE + if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_HEIGHT_REDUCE) + mode = EDITOR_MODE_HEIGHT_RAISE; + // user probably released EDITOR_MODE_HEIGHT_PLANE + else if(key.keysym.sym == SDLK_LALT && mode == EDITOR_MODE_HEIGHT_PLANE) + mode = EDITOR_MODE_HEIGHT_RAISE; + // user probably released EDITOR_MODE_RESOURCE_REDUCE + else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_RESOURCE_REDUCE) + mode = EDITOR_MODE_RESOURCE_RAISE; + // user probably released EDITOR_MODE_FLAG_DELETE + else if(key.keysym.sym == SDLK_LSHIFT && mode == EDITOR_MODE_FLAG_DELETE) + mode = EDITOR_MODE_FLAG; + // user probably released EDITOR_MODE_CUT + else if(key.keysym.sym == SDLK_LCTRL) + mode = lastMode; + // user probably released EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE + else if(key.keysym.sym == SDLK_b) + { + mode = lastMode; + ChangeSection = lastChangeSection; + setupVerticesActivity(); + } + // user probably released EDITOR_MODE_TEXTURE_MAKE_HARBOUR + else if(key.keysym.sym == SDLK_h) + { + mode = lastMode; + ChangeSection = lastChangeSection; + setupVerticesActivity(); + } + } +} + +void CMap::saveVertex(Uint16 MouseX, Uint16 MouseY, Uint8 MouseState) +{ + // if user raises or reduces the height of a vertex, don't let the cursor jump to another vertex + // if ( (MouseState == SDL_PRESSED) && (mode == EDITOR_MODE_HEIGHT_RAISE || mode == EDITOR_MODE_HEIGHT_REDUCE) ) + // return; + + int X = 0, Xeven = 0, Xuneven = 0; + int Y = 0, MousePosY = 0; + + // get X + // following out commented lines are the correct ones, but for tolerance (to prevent to early jumps of the cursor) we substract + // "TRIANGLE_WIDTH/2" Xeven = (MouseX + displayRect.x) / TRIANGLE_WIDTH; + Xeven = (MouseX + displayRect.x - TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH; + if(Xeven < 0) + Xeven += (map->width); + else if(Xeven > map->width - 1) + Xeven -= (map->width - 1); + Xuneven = (MouseX + displayRect.x + TRIANGLE_WIDTH / 2) / TRIANGLE_WIDTH; + // Xuneven = (MouseX + displayRect.x) / TRIANGLE_WIDTH; + if(Xuneven < 0) + Xuneven += (map->width - 1); + else if(Xuneven > map->width - 1) + Xuneven -= (map->width); + + MousePosY = MouseY + displayRect.y; + // correct mouse position Y if displayRect is outside map edges + if(MousePosY < 0) + MousePosY += map->height_pixel; + else if(MousePosY > map->height_pixel) + MousePosY = MouseY - (map->height_pixel - displayRect.y); + + // get Y + for(int j = 0; j < map->height; j++) + { + if(j % 2 == 0) + { + // substract "TRIANGLE_HEIGHT/2" is for tolerance, we did the same for X + if((MousePosY - TRIANGLE_HEIGHT / 2) > map->vertex[j * map->width + Xeven].y) + Y++; + else + { + X = Xuneven; + break; + } + } else + { + if((MousePosY - TRIANGLE_HEIGHT / 2) > map->vertex[j * map->width + Xuneven].y) + Y++; + else + { + X = Xeven; + break; + } + } + } + if(Y < 0) + Y += (map->height - 1); + else if(Y > map->height - 1) + Y -= (map->height - 1); + + VertexX = X; + VertexY = Y; + + MouseBlitX = correctMouseBlitX(VertexX, VertexY); + MouseBlitY = correctMouseBlitY(VertexX, VertexY); + + calculateVertices(); +} + +int CMap::correctMouseBlitX(int VertexX, int VertexY) +{ + int MouseBlitX = map->vertex[VertexY * map->width + VertexX].x; + if(MouseBlitX < displayRect.x) + MouseBlitX += map->width_pixel; + else if(MouseBlitX > (displayRect.x + displayRect.w)) + MouseBlitX -= map->width_pixel; + MouseBlitX -= displayRect.x; + + return MouseBlitX; +} +int CMap::correctMouseBlitY(int VertexX, int VertexY) +{ + int MouseBlitY = map->vertex[VertexY * map->width + VertexX].y; + if(MouseBlitY < displayRect.y) + MouseBlitY += map->height_pixel; + else if(MouseBlitY > (displayRect.y + displayRect.h)) + MouseBlitY -= map->height_pixel; + MouseBlitY -= displayRect.y; + + return MouseBlitY; +} + +void CMap::render() +{ + char textBuffer[100]; + + // check if gameresolution has been changed + if(displayRect.w != global::s2->GameResolutionX || displayRect.h != global::s2->GameResolutionY) + { + displayRect.w = global::s2->GameResolutionX; + displayRect.h = global::s2->GameResolutionY; + needSurface = true; + } + + // if we need a new surface + if(needSurface) + { + SDL_FreeSurface(Surf_Map); + Surf_Map = NULL; + if((Surf_Map = SDL_CreateRGBSurface(SDL_SWSURFACE, displayRect.w, displayRect.h, BitsPerPixel, 0, 0, 0, 0)) == NULL) + return; + if(BitsPerPixel == 8) + SDL_SetPalette(Surf_Map, SDL_LOGPAL, global::palArray[PAL_xBBM].colors, 0, 256); + needSurface = false; + } + // else + // clear the surface before drawing new (in normal case not needed) + // SDL_FillRect( Surf_Map, NULL, SDL_MapRGB(Surf_Map->format,0,0,0) ); + + // touch vertex data if user modifies it + if(modify) + modifyVertex(); + + if(map->vertex != NULL) + CSurface::DrawTriangleField(Surf_Map, displayRect, map); + + // draw pictures to cursor position +#ifdef _EDITORMODE + int symbol_index, symbol_index2 = -1; + switch(mode) + { + case EDITOR_MODE_CUT: symbol_index = CURSOR_SYMBOL_SCISSORS; break; + case EDITOR_MODE_TREE: symbol_index = CURSOR_SYMBOL_TREE; break; + case EDITOR_MODE_HEIGHT_RAISE: symbol_index = CURSOR_SYMBOL_ARROW_UP; break; + case EDITOR_MODE_HEIGHT_REDUCE: symbol_index = CURSOR_SYMBOL_ARROW_DOWN; break; + case EDITOR_MODE_HEIGHT_PLANE: + symbol_index = CURSOR_SYMBOL_ARROW_UP; + symbol_index2 = CURSOR_SYMBOL_ARROW_DOWN; + break; + case EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE: symbol_index = MAPPIC_ARROWCROSS_RED_HOUSE_BIG; break; + case EDITOR_MODE_TEXTURE: symbol_index = CURSOR_SYMBOL_TEXTURE; break; + case EDITOR_MODE_TEXTURE_MAKE_HARBOUR: symbol_index = MAPPIC_ARROWCROSS_RED_HOUSE_HARBOUR; break; + case EDITOR_MODE_LANDSCAPE: symbol_index = CURSOR_SYMBOL_LANDSCAPE; break; + case EDITOR_MODE_FLAG: symbol_index = CURSOR_SYMBOL_FLAG; break; + case EDITOR_MODE_FLAG_DELETE: symbol_index = CURSOR_SYMBOL_FLAG; break; + case EDITOR_MODE_RESOURCE_REDUCE: symbol_index = CURSOR_SYMBOL_PICKAXE_MINUS; break; + case EDITOR_MODE_RESOURCE_RAISE: symbol_index = CURSOR_SYMBOL_PICKAXE_PLUS; break; + case EDITOR_MODE_ANIMAL: symbol_index = CURSOR_SYMBOL_ANIMAL; break; + default: symbol_index = CURSOR_SYMBOL_ARROW_UP; break; + } + for(int i = 0; i < VertexCounter; i++) + { + if(Vertices[i].active) + { + CSurface::Draw(Surf_Map, global::bmpArray[symbol_index].surface, Vertices[i].blit_x - 10, Vertices[i].blit_y - 10); + if(symbol_index2 >= 0) + CSurface::Draw(Surf_Map, global::bmpArray[symbol_index2].surface, Vertices[i].blit_x, Vertices[i].blit_y - 7); + } + } + + // text for x and y of vertex (shown in upper left corner) + sprintf(textBuffer, "%d %d", VertexX, VertexY); + CFont::writeText(Surf_Map, textBuffer, 20, 20); + // text for MinReduceHeight and MaxRaiseHeight + sprintf(textBuffer, "min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A", MinReduceHeight, MaxRaiseHeight); + CFont::writeText(Surf_Map, textBuffer, 100, 20); + // text for MovementLocked + if(HorizontalMovementLocked && VerticalMovementLocked) + { + sprintf(textBuffer, "Movement locked (F9 or F10 to unlock)"); + CFont::writeText(Surf_Map, textBuffer, 20, 40, 14, FONT_ORANGE); + } else if(HorizontalMovementLocked) + { + sprintf(textBuffer, "Horizontal movement locked (F9 to unlock)"); + CFont::writeText(Surf_Map, textBuffer, 20, 40, 14, FONT_ORANGE); + } else if(VerticalMovementLocked) + { + sprintf(textBuffer, "Vertikal mvement locked (F10 to unlock)"); + CFont::writeText(Surf_Map, textBuffer, 20, 40, 14, FONT_ORANGE); + } + +#else + CSurface::Draw(Surf_Map, global::bmpArray[CIRCLE_FLAT_GREY].surface, MouseBlitX - 10, MouseBlitY - 10); +#endif + + // draw the frame + if(displayRect.w == 640 && displayRect.h == 480) + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, 0); + else if(displayRect.w == 800 && displayRect.h == 600) + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_800_600].surface, 0, 0); + else if(displayRect.w == 1024 && displayRect.h == 768) + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_1024_768].surface, 0, 0); + else if(displayRect.w == 1280 && displayRect.h == 1024) + { + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_LEFT_1280_1024].surface, 0, 0); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_RIGHT_1280_1024].surface, 640, 0); + } else + { + int x = 150, y = 150; + // draw the corners + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, 0, 0, 0, 150, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, displayRect.h - 150, 0, 480 - 150, 150, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 150, 0, 640 - 150, 0, 150, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 150, displayRect.h - 150, 640 - 150, + 480 - 150, 150, 150); + // draw the edges + while(x < displayRect.w - 150) + { + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, 0, 150, 0, 150, 12); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, x, displayRect.h - 12, 150, 0, 150, 12); + x += 150; + } + while(y < displayRect.h - 150) + { + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, 0, y, 0, 150, 12, 150); + CSurface::Draw(Surf_Map, global::bmpArray[MAINFRAME_640_480].surface, displayRect.w - 12, y, 0, 150, 12, 150); + y += 150; + } + } + + // draw the statues at the frame + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_LEFT].surface, 12, 12); + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_UP_RIGHT].surface, displayRect.w - global::bmpArray[STATUE_UP_RIGHT].w - 12, 12); + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_LEFT].surface, 12, displayRect.h - global::bmpArray[STATUE_DOWN_LEFT].h - 12); + CSurface::Draw(Surf_Map, global::bmpArray[STATUE_DOWN_RIGHT].surface, displayRect.w - global::bmpArray[STATUE_DOWN_RIGHT].w - 12, + displayRect.h - global::bmpArray[STATUE_DOWN_RIGHT].h - 12); + + // lower menubar + // draw lower menubar + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR].surface, displayRect.w / 2 - global::bmpArray[MENUBAR].w / 2, + displayRect.h - global::bmpArray[MENUBAR].h); + + // draw pictures to lower menubar +#ifdef _EDITORMODE + // backgrounds + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 236, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 199, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 162, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 125, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 88, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 51, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 - 14, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 92, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 129, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 166, displayRect.h - 36, 0, 0, 37, 32); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w / 2 + 203, displayRect.h - 36, 0, 0, 37, 32); + // pictures + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_HEIGHT].surface, displayRect.w / 2 - 232, displayRect.h - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TEXTURE].surface, displayRect.w / 2 - 195, displayRect.h - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_TREE].surface, displayRect.w / 2 - 158, displayRect.h - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_RESOURCE].surface, displayRect.w / 2 - 121, displayRect.h - 32); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_LANDSCAPE].surface, displayRect.w / 2 - 84, displayRect.h - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_ANIMAL].surface, displayRect.w / 2 - 48, displayRect.h - 36); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_PLAYER].surface, displayRect.w / 2 - 10, displayRect.h - 34); + + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUILDHELP].surface, displayRect.w / 2 + 96, displayRect.h - 35); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_MINIMAP].surface, displayRect.w / 2 + 131, displayRect.h - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_NEWWORLD].surface, displayRect.w / 2 + 166, displayRect.h - 37); + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_COMPUTER].surface, displayRect.w / 2 + 207, displayRect.h - 35); +#else + +#endif + +#ifdef _EDITORMODE + // right menubar + // do we need a surface? + if(Surf_RightMenubar == NULL) + { + // we permute width and height, cause we want to rotate the menubar 90 degrees + if((Surf_RightMenubar = + SDL_CreateRGBSurface(SDL_SWSURFACE, global::bmpArray[MENUBAR].h, global::bmpArray[MENUBAR].w, 8, 0, 0, 0, 0)) + != NULL) + { + SDL_SetPalette(Surf_RightMenubar, SDL_LOGPAL, global::palArray[PAL_RESOURCE].colors, 0, 256); + SDL_SetColorKey(Surf_RightMenubar, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surf_RightMenubar->format, 0, 0, 0)); + CSurface::Draw(Surf_RightMenubar, global::bmpArray[MENUBAR].surface, 0, 0, 270); + } + } + // draw right menubar (remember permutation of width and height) + CSurface::Draw(Surf_Map, Surf_RightMenubar, displayRect.w - global::bmpArray[MENUBAR].h, + displayRect.h / 2 - global::bmpArray[MENUBAR].w / 2); + + // draw pictures to right menubar + // backgrounds + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 239, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 202, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 165, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 128, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 - 22, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 15, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 52, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 89, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 126, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 163, 0, 0, 32, 37); + CSurface::Draw(Surf_Map, global::bmpArray[BUTTON_GREEN1_DARK].surface, displayRect.w - 36, displayRect.h / 2 + 200, 0, 0, 32, 37); + // pictures + // four cursor menu pictures + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.w - 33, displayRect.h / 2 - 237); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.w - 20, displayRect.h / 2 - 235); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_DOWN].surface, displayRect.w - 33, displayRect.h / 2 - 220); + CSurface::Draw(Surf_Map, global::bmpArray[CURSOR_SYMBOL_ARROW_UP].surface, displayRect.w - 20, displayRect.h / 2 - 220); + // bugkill picture for quickload with text + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.w - 37, displayRect.h / 2 + 162); + sprintf(textBuffer, "Load"); + CFont::writeText(Surf_Map, textBuffer, displayRect.w - 35, displayRect.h / 2 + 193); + // bugkill picture for quicksave with text + CSurface::Draw(Surf_Map, global::bmpArray[MENUBAR_BUGKILL].surface, displayRect.w - 37, displayRect.h / 2 + 200); + sprintf(textBuffer, "Save"); + CFont::writeText(Surf_Map, textBuffer, displayRect.w - 35, displayRect.h / 2 + 231); + +#endif +} + +void CMap::drawMinimap(SDL_Surface* Window) +{ + Uint32* pixel; + Uint32* row; + + Uint8 r8, g8, b8; + Sint16 r, g, b; + + // this variables are needed to reduce the size of minimap-windows of big maps + int num_x = (map->width > 256 ? map->width / 256 : 1); + int num_y = (map->height > 256 ? map->height / 256 : 1); + + // make sure the minimap has the same proportions as the "real" map, so scale the same rate + num_x = (num_x > num_y ? num_x : num_y); + num_y = (num_x > num_y ? num_x : num_y); + + // if (Window->w < map->width || Window->h < map->height) + // return; + + for(int y = 0; y < map->height; y++) + { + if(y % num_y != 0) + continue; + + row = (Uint32*)Window->pixels + (y + 20) * Window->pitch / 4; + for(int x = 0; x < map->width; x++) + { + if(x % num_x != 0) + continue; + + switch(map->vertex[y * map->width + x].rsuTexture) + { + case TRIANGLE_TEXTURE_STEPPE_MEADOW1: + r = (map->type == 0x00 ? 100 : (map->type == 0x01 ? 68 : 160)); + g = (map->type == 0x00 ? 144 : (map->type == 0x01 ? 72 : 172)); + b = (map->type == 0x00 ? 20 : (map->type == 0x01 ? 80 : 204)); + break; + case TRIANGLE_TEXTURE_MINING1: + r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 112 : 84)); + g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 108 : 88)); + b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 84 : 108)); + break; + case TRIANGLE_TEXTURE_SNOW: + r = (map->type == 0x00 ? 180 : (map->type == 0x01 ? 132 : 0)); + g = (map->type == 0x00 ? 192 : (map->type == 0x01 ? 0 : 48)); + b = (map->type == 0x00 ? 200 : (map->type == 0x01 ? 0 : 104)); + break; + case TRIANGLE_TEXTURE_SWAMP: + r = (map->type == 0x00 ? 100 : (map->type == 0x01 ? 0 : 0)); + g = (map->type == 0x00 ? 144 : (map->type == 0x01 ? 24 : 40)); + b = (map->type == 0x00 ? 20 : (map->type == 0x01 ? 32 : 108)); + break; + case TRIANGLE_TEXTURE_STEPPE: + r = (map->type == 0x00 ? 192 : (map->type == 0x01 ? 156 : 0)); + g = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 124 : 112)); + b = (map->type == 0x00 ? 124 : (map->type == 0x01 ? 100 : 176)); + break; + case TRIANGLE_TEXTURE_WATER: + r = (map->type == 0x00 ? 16 : (map->type == 0x01 ? 68 : 0)); + g = (map->type == 0x00 ? 56 : (map->type == 0x01 ? 68 : 48)); + b = (map->type == 0x00 ? 164 : (map->type == 0x01 ? 44 : 104)); + break; + case TRIANGLE_TEXTURE_MEADOW1: + r = (map->type == 0x00 ? 72 : (map->type == 0x01 ? 92 : 176)); + g = (map->type == 0x00 ? 120 : (map->type == 0x01 ? 88 : 164)); + b = (map->type == 0x00 ? 12 : (map->type == 0x01 ? 64 : 148)); + break; + case TRIANGLE_TEXTURE_MEADOW2: + r = (map->type == 0x00 ? 100 : (map->type == 0x01 ? 100 : 180)); + g = (map->type == 0x00 ? 144 : (map->type == 0x01 ? 96 : 184)); + b = (map->type == 0x00 ? 20 : (map->type == 0x01 ? 72 : 180)); + break; + case TRIANGLE_TEXTURE_MEADOW3: + r = (map->type == 0x00 ? 64 : (map->type == 0x01 ? 100 : 160)); + g = (map->type == 0x00 ? 112 : (map->type == 0x01 ? 96 : 172)); + b = (map->type == 0x00 ? 8 : (map->type == 0x01 ? 72 : 204)); + break; + case TRIANGLE_TEXTURE_MINING2: + r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 112 : 96)); + g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 100 : 96)); + b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 84 : 124)); + break; + case TRIANGLE_TEXTURE_MINING3: + r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 104 : 104)); + g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 76 : 108)); + b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 36 : 140)); + break; + case TRIANGLE_TEXTURE_MINING4: + r = (map->type == 0x00 ? 140 : (map->type == 0x01 ? 104 : 104)); + g = (map->type == 0x00 ? 112 : (map->type == 0x01 ? 76 : 108)); + b = (map->type == 0x00 ? 72 : (map->type == 0x01 ? 36 : 140)); + break; + case TRIANGLE_TEXTURE_STEPPE_MEADOW2: + r = (map->type == 0x00 ? 136 : (map->type == 0x01 ? 112 : 100)); + g = (map->type == 0x00 ? 176 : (map->type == 0x01 ? 108 : 144)); + b = (map->type == 0x00 ? 40 : (map->type == 0x01 ? 84 : 20)); + break; + case TRIANGLE_TEXTURE_FLOWER: + r = (map->type == 0x00 ? 72 : (map->type == 0x01 ? 68 : 124)); + g = (map->type == 0x00 ? 120 : (map->type == 0x01 ? 72 : 132)); + b = (map->type == 0x00 ? 12 : (map->type == 0x01 ? 80 : 172)); + break; + case TRIANGLE_TEXTURE_LAVA: + r = (map->type == 0x00 ? 192 : (map->type == 0x01 ? 128 : 144)); + g = (map->type == 0x00 ? 32 : (map->type == 0x01 ? 20 : 44)); + b = (map->type == 0x00 ? 32 : (map->type == 0x01 ? 0 : 4)); + break; + case TRIANGLE_TEXTURE_MINING_MEADOW: + r = (map->type == 0x00 ? 156 : (map->type == 0x01 ? 0 : 148)); + g = (map->type == 0x00 ? 128 : (map->type == 0x01 ? 24 : 160)); + b = (map->type == 0x00 ? 88 : (map->type == 0x01 ? 32 : 192)); + break; + default: // color grey + r = 128; + g = 128; + b = 128; + break; + } + + row = (Uint32*)Window->pixels + (y / num_y + 20) * Window->pitch / 4; + //+6 because of the left window frame + pixel = row + x / num_x + 6; + + r = ((r * map->vertex[y * map->width + x].i) >> 16); + g = ((g * map->vertex[y * map->width + x].i) >> 16); + b = ((b * map->vertex[y * map->width + x].i) >> 16); + r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); + g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); + b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); + *pixel = ((r8 << Window->format->Rshift) + (g8 << Window->format->Gshift) + (b8 << Window->format->Bshift)); + } + } + +#ifdef _EDITORMODE + // draw the player flags + char playerNumber[2]; + for(int i = 0; i < MAXPLAYERS; i++) + { + if(PlayerHQx[i] != 0xFFFF && PlayerHQx[i] != 0xFFFF) + { + // draw flag + //%7 cause in the original game there are only 7 players and 7 different flags + CSurface::Draw(Window, global::bmpArray[FLAG_BLUE_DARK + i % 7].surface, + 6 + PlayerHQx[i] / num_x - global::bmpArray[FLAG_BLUE_DARK + i % 7].nx, + 20 + PlayerHQy[i] / num_y - global::bmpArray[FLAG_BLUE_DARK + i % 7].ny); + // write player number + sprintf(playerNumber, "%d", i + 1); + CFont::writeText(Window, playerNumber, 6 + PlayerHQx[i] / num_x, 20 + PlayerHQy[i] / num_y, 9, FONT_MINTGREEN); + } + } +#endif + + // draw the arrow --> 6px is width of left window frame and 20px is the height of the upper window frame + CSurface::Draw(Window, global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].surface, + 6 + (displayRect.x + displayRect.w / 2) / TRIANGLE_WIDTH / num_x - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx, + 20 + (displayRect.y + displayRect.h / 2) / TRIANGLE_HEIGHT / num_y - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny); +} + +void CMap::modifyVertex() +{ + static Uint32 TimeOfLastModification = SDL_GetTicks(); + + if((SDL_GetTicks() - TimeOfLastModification) < 5) + return; + else + TimeOfLastModification = SDL_GetTicks(); + + // save vertices for "undo" and "do" + if(saveCurrentVertices) + { + if(CurrPtr_savedVertices != NULL) + { + CurrPtr_savedVertices->empty = false; + CurrPtr_savedVertices->VertexX = VertexX; + CurrPtr_savedVertices->VertexY = VertexY; + for(int i = VertexX - MAX_CHANGE_SECTION - 10 - 2, k = 0; i <= VertexX + MAX_CHANGE_SECTION + 10 + 2; i++, k++) + { + for(int j = VertexY - MAX_CHANGE_SECTION - 10 - 2, l = 0; j <= VertexY + MAX_CHANGE_SECTION + 10 + 2; j++, l++) + { + // i und j muessen wegen den mapraendern noch korrigiert werden! + int m = i; + if(m < 0) + m += map->width; + else if(m >= map->width) + m -= map->width; + int n = j; + if(n < 0) + n += map->height; + else if(n >= map->height) + n -= map->height; + // printf("\n X=%d Y=%d i=%d j=%d k=%d l=%d m=%d n=%d", VertexX, VertexY, i, j, k, l, m, n); + memcpy(&(CurrPtr_savedVertices->PointsArroundVertex[l * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) + k]), + &(map->vertex[n * map->width + m]), sizeof(struct point)); + // CurrPtr_savedVertices->PointsArroundVertex[l*map->width+k] = map->vertex[n*map->width+m]; + } + } + 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; + } + } else + CurrPtr_savedVertices = CurrPtr_savedVertices->next; + } + saveCurrentVertices = false; + } + + if(mode == EDITOR_MODE_HEIGHT_RAISE) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyHeightRaise(Vertices[i].x, Vertices[i].y); + } else if(mode == EDITOR_MODE_HEIGHT_REDUCE) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyHeightReduce(Vertices[i].x, Vertices[i].y); + } else if(mode == EDITOR_MODE_HEIGHT_PLANE) + { + // calculate height average over all vertices + int h_sum = 0; + int h_count = 0; + Uint8 h_avg = 0x00; + + for(int i = 0; i < VertexCounter; i++) + { + if(Vertices[i].active) + { + h_sum += map->vertex[Vertices[i].y * map->width + Vertices[i].x].h; + h_count++; + } + } + + h_avg = h_sum / h_count; + + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyHeightPlane(Vertices[i].x, Vertices[i].y, h_avg); + } else if(mode == EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE) + { + modifyHeightMakeBigHouse(VertexX, VertexY); + } else if(mode == EDITOR_MODE_TEXTURE_MAKE_HARBOUR) + { + modifyHeightMakeBigHouse(VertexX, VertexY); + modifyTextureMakeHarbour(VertexX, VertexY); + } + // at this time we need a modeContent to set + else if(mode == EDITOR_MODE_CUT) + { + for(int i = 0; i < VertexCounter; i++) + { + if(Vertices[i].active) + { + modifyObject(Vertices[i].x, Vertices[i].y); + modifyAnimal(Vertices[i].x, Vertices[i].y); + } + } + } else if(mode == EDITOR_MODE_TEXTURE) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyTexture(Vertices[i].x, Vertices[i].y, Vertices[i].fill_rsu, Vertices[i].fill_usd); + } else if(mode == EDITOR_MODE_TREE) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyObject(Vertices[i].x, Vertices[i].y); + } else if(mode == EDITOR_MODE_LANDSCAPE) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyObject(Vertices[i].x, Vertices[i].y); + } else if(mode == EDITOR_MODE_RESOURCE_RAISE || mode == EDITOR_MODE_RESOURCE_REDUCE) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyResource(Vertices[i].x, Vertices[i].y); + } else if(mode == EDITOR_MODE_ANIMAL) + { + for(int i = 0; i < VertexCounter; i++) + if(Vertices[i].active) + modifyAnimal(Vertices[i].x, Vertices[i].y); + } else if(mode == EDITOR_MODE_FLAG || mode == EDITOR_MODE_FLAG_DELETE) + { + modifyPlayer(VertexX, VertexY); + } +} + +void CMap::modifyHeightRaise(int VertexX, int VertexY) +{ + // vertex count for the points + int X, Y; + struct point* tempP = &map->vertex[VertexY * map->width + VertexX]; + // this is to setup the building depending on the vertices around + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + + bool even = false; + if(VertexY % 2 == 0) + even = true; + + // DO IT + if(tempP->z >= TRIANGLE_INCREASE * (MaxRaiseHeight - 0x0A)) // user specified maximum reached + return; + + if(tempP->z >= TRIANGLE_INCREASE * (0x3C - 0x0A)) // maximum reached (0x3C is max) + return; + + tempP->y -= TRIANGLE_INCREASE; + tempP->z += TRIANGLE_INCREASE; + tempP->h += 0x01; + CSurface::update_shading(map, VertexX, VertexY); + + // after (5*TRIANGLE_INCREASE) pixel all vertices around will be raised too + // update first vertex left upside + X = VertexX - (even ? 1 : 0); + if(X < 0) + X += map->width; + Y = VertexY - 1; + if(Y < 0) + Y += map->height; + // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) + if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) + modifyHeightRaise(X, Y); + // update second vertex right upside + X = VertexX + (even ? 0 : 1); + if(X >= map->width) + X -= map->width; + Y = VertexY - 1; + if(Y < 0) + Y += map->height; + // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) + if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) + modifyHeightRaise(X, Y); + // update third point bottom left + X = VertexX - 1; + if(X < 0) + X += map->width; + Y = VertexY; + // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) + if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) + modifyHeightRaise(X, Y); + // update fourth point bottom right + X = VertexX + 1; + if(X >= map->width) + X -= map->width; + Y = VertexY; + // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) + if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) + modifyHeightRaise(X, Y); + // update fifth point down left + X = VertexX - (even ? 1 : 0); + if(X < 0) + X += map->width; + Y = VertexY + 1; + if(Y >= map->height) + Y -= map->height; + // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) + if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) + modifyHeightRaise(X, Y); + // update sixth point down right + X = VertexX + (even ? 0 : 1); + if(X >= map->width) + X -= map->width; + Y = VertexY + 1; + if(Y >= map->height) + Y -= map->height; + // only modify if the other point is lower than the middle point of the hexagon (-5 cause point was raised a few lines before) + if(map->vertex[Y * map->width + X].z < tempP->z - (5 * TRIANGLE_INCREASE)) + modifyHeightRaise(X, Y); + + // at least setup the possible building and shading at the vertex and 2 sections around + for(int i = 0; i < 19; i++) + { + modifyBuild(tempVertices[i].x, tempVertices[i].y); + modifyShading(tempVertices[i].x, tempVertices[i].y); + } +} + +void CMap::modifyHeightReduce(int VertexX, int VertexY) +{ + // vertex count for the points + int X, Y; + struct point* tempP = &map->vertex[VertexY * map->width + VertexX]; + // this is to setup the building depending on the vertices around + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + + bool even = false; + if(VertexY % 2 == 0) + even = true; + + // DO IT + if(tempP->z <= TRIANGLE_INCREASE * (MinReduceHeight - 0x0A)) // user specified minimum reached + return; + + if(tempP->z <= TRIANGLE_INCREASE * (0x00 - 0x0A)) // minimum reached (0x00 is min) + return; + + tempP->y += TRIANGLE_INCREASE; + tempP->z -= TRIANGLE_INCREASE; + tempP->h -= 0x01; + CSurface::update_shading(map, VertexX, VertexY); + // after (5*TRIANGLE_INCREASE) pixel all vertices around will be reduced too + // update first vertex left upside + X = VertexX - (even ? 1 : 0); + if(X < 0) + X += map->width; + Y = VertexY - 1; + if(Y < 0) + Y += map->height; + // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) + if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) + modifyHeightReduce(X, Y); + // update second vertex right upside + X = VertexX + (even ? 0 : 1); + if(X >= map->width) + X -= map->width; + Y = VertexY - 1; + if(Y < 0) + Y += map->height; + // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) + if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) + modifyHeightReduce(X, Y); + // update third point bottom left + X = VertexX - 1; + if(X < 0) + X += map->width; + Y = VertexY; + // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) + if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) + modifyHeightReduce(X, Y); + // update fourth point bottom right + X = VertexX + 1; + if(X >= map->width) + X -= map->width; + Y = VertexY; + // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) + if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) + modifyHeightReduce(X, Y); + // update fifth point down left + X = VertexX - (even ? 1 : 0); + if(X < 0) + X += map->width; + Y = VertexY + 1; + if(Y >= map->height) + Y -= map->height; + // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) + if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) + modifyHeightReduce(X, Y); + // update sixth point down right + X = VertexX + (even ? 0 : 1); + if(X >= map->width) + X -= map->width; + Y = VertexY + 1; + if(Y >= map->height) + Y -= map->height; + // only modify if the other point is higher than the middle point of the hexagon (+5 cause point was reduced a few lines before) + if(map->vertex[Y * map->width + X].z > tempP->z + (5 * TRIANGLE_INCREASE)) + modifyHeightReduce(X, Y); + + // at least setup the possible building and shading at the vertex and 2 sections around + for(int i = 0; i < 19; i++) + { + modifyBuild(tempVertices[i].x, tempVertices[i].y); + modifyShading(tempVertices[i].x, tempVertices[i].y); + } +} + +void CMap::modifyHeightPlane(int VertexX, int VertexY, Uint8 h) +{ + // we could do "while" but "if" looks better during planing (optical effect) + if(map->vertex[VertexY * map->width + VertexX].h < h) + modifyHeightRaise(VertexX, VertexY); + // we could do "while" but "if" looks better during planing (optical effect) + if(map->vertex[VertexY * map->width + VertexX].h > h) + modifyHeightReduce(VertexX, VertexY); +} + +void CMap::modifyHeightMakeBigHouse(int VertexX, int VertexY) +{ + // at first save all vertices we need to calculate the new building + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + + Uint8 height = map->vertex[VertexY * map->width + VertexX].h; + + // calculate the building using the height of the vertices + + // test the whole section + for(int i = 0; i < 6; i++) + { + while(height - map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h >= 0x04) + modifyHeightRaise(tempVertices[i].x, tempVertices[i].y); + + while(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h - height >= 0x04) + modifyHeightReduce(tempVertices[i].x, tempVertices[i].y); + } + + // test vertex lower right + while(height - map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h >= 0x04) + modifyHeightRaise(tempVertices[6].x, tempVertices[6].y); + + while(map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h - height >= 0x02) + modifyHeightReduce(tempVertices[6].x, tempVertices[6].y); + + // now test the second section around the vertex + + // test the whole section + for(int i = 7; i < 19; i++) + { + while(height - map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h >= 0x03) + modifyHeightRaise(tempVertices[i].x, tempVertices[i].y); + + while(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h - height >= 0x03) + modifyHeightReduce(tempVertices[i].x, tempVertices[i].y); + } + + // remove harbour if there is one + if(map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + { + map->vertex[VertexY * map->width + VertexX].rsuTexture -= 0x40; + } +} + +void CMap::modifyShading(int VertexX, int VertexY) +{ + // temporary to keep the lines short + int X, Y; + // this is to setup the shading depending on the vertices around (2 sections from the cursor) + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + + // shading stakes + int A, B, C, D, Result; + + // shading stake of point right upside (first section) + X = tempVertices[2].x; + Y = tempVertices[2].y; + A = 9 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); + // shading stake of point left (first section) + X = tempVertices[3].x; + Y = tempVertices[3].y; + B = -6 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); + // shading stake of point left (second section) + X = tempVertices[12].x; + Y = tempVertices[12].y; + C = -3 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); + // shading stake of point bottom/middle left (second section) + X = tempVertices[14].x; + Y = tempVertices[14].y; + D = -9 * (map->vertex[Y * map->width + X].h - map->vertex[VertexY * map->width + VertexX].h); + + Result = 0x40 + A + B + C + D; + if(Result > 0x80) + Result = 0x80; + else if(Result < 0x00) + Result = 0x00; + + map->vertex[VertexY * map->width + VertexX].shading = Result; +} + +void CMap::modifyTexture(int VertexX, int VertexY, bool rsu, bool usd) +{ + if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED || modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR) + { + int newContent = rand() % 3; + if(newContent == 0) + { + if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED) + newContent = TRIANGLE_TEXTURE_MEADOW1; + else + newContent = TRIANGLE_TEXTURE_MEADOW1_HARBOUR; + } else if(newContent == 1) + { + if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED) + newContent = TRIANGLE_TEXTURE_MEADOW2; + else + newContent = TRIANGLE_TEXTURE_MEADOW2_HARBOUR; + } else + { + if(modeContent == TRIANGLE_TEXTURE_MEADOW_MIXED) + newContent = TRIANGLE_TEXTURE_MEADOW3; + else + newContent = TRIANGLE_TEXTURE_MEADOW3_HARBOUR; + } + if(rsu) + map->vertex[VertexY * map->width + VertexX].rsuTexture = newContent; + if(usd) + map->vertex[VertexY * map->width + VertexX].usdTexture = newContent; + } else + { + if(rsu) + map->vertex[VertexY * map->width + VertexX].rsuTexture = modeContent; + if(usd) + map->vertex[VertexY * map->width + VertexX].usdTexture = modeContent; + } + + // at least setup the possible building and the resources at the vertex and 1 section/2 sections around + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + for(int i = 0; i < 19; i++) + { + if(i < 7) + modifyBuild(tempVertices[i].x, tempVertices[i].y); + modifyResource(tempVertices[i].x, tempVertices[i].y); + } +} + +void CMap::modifyTextureMakeHarbour(int VertexX, int VertexY) +{ + if(map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW) + { + map->vertex[VertexY * map->width + VertexX].rsuTexture += 0x40; + } +} + +void CMap::modifyObject(int VertexX, int VertexY) +{ + if(mode == EDITOR_MODE_CUT) + { + // prevent cutting a player position + if(map->vertex[VertexY * map->width + VertexX].objectInfo != 0x80) + { + map->vertex[VertexY * map->width + VertexX].objectType = 0x00; + map->vertex[VertexY * map->width + VertexX].objectInfo = 0x00; + } + } else if(mode == EDITOR_MODE_TREE) + { + // if there is another object at the vertex, return + if(map->vertex[VertexY * map->width + VertexX].objectInfo != 0x00) + return; + if(modeContent == 0xFF) + { + // mixed wood + if(modeContent2 == 0xC4) + { + int newContent = rand() % 3; + if(newContent == 0) + newContent = 0x30; + else if(newContent == 1) + newContent = 0x70; + else + newContent = 0xB0; + // we set different start pictures for the tree, cause the trees should move different, so we add a random value that walks + // from 0 to 7 + map->vertex[VertexY * map->width + VertexX].objectType = newContent + rand() % 8; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } + // mixed palm + else // if (modeContent2 == 0xC5) + { + int newContent = rand() % 2; + int newContent2; + if(newContent == 0) + { + newContent = 0x30; + newContent2 = 0xC5; + } else + { + newContent = 0xF0; + newContent2 = 0xC4; + } + // we set different start pictures for the tree, cause the trees should move different, so we add a random value that walks + // from 0 to 7 + map->vertex[VertexY * map->width + VertexX].objectType = newContent + rand() % 8; + map->vertex[VertexY * map->width + VertexX].objectInfo = newContent2; + } + } else + { + // we set different start pictures for the tree, cause the trees should move different, so we add a random value that walks from + // 0 to 7 + map->vertex[VertexY * map->width + VertexX].objectType = modeContent + rand() % 8; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } + } else if(mode == EDITOR_MODE_LANDSCAPE) + { + // if there is another object at the vertex, return + if(map->vertex[VertexY * map->width + VertexX].objectInfo != 0x00) + return; + + if(modeContent == 0x01) + { + int newContent = modeContent + rand() % 6; + int newContent2 = 0xCC + rand() % 2; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = newContent2; + + // now set up the buildings around the granite + modifyBuild(VertexX, VertexY); + } else if(modeContent == 0x05) + { + int newContent = modeContent + rand() % 2; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x02) + { + int newContent = modeContent + rand() % 3; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x0C) + { + int newContent = modeContent + rand() % 2; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x25) + { + int newContent = modeContent + rand() % 3; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x10) + { + int newContent = rand() % 4; + if(newContent == 0) + newContent = 0x10; + else if(newContent == 1) + newContent = 0x11; + else if(newContent == 2) + newContent = 0x12; + else + newContent = 0x0A; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x0E) + { + int newContent = rand() % 4; + if(newContent == 0) + newContent = 0x0E; + else if(newContent == 1) + newContent = 0x0F; + else if(newContent == 2) + newContent = 0x13; + else + newContent = 0x14; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x07) + { + int newContent = modeContent + rand() % 2; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x00) + { + int newContent = rand() % 3; + if(newContent == 0) + newContent = 0x00; + else if(newContent == 1) + newContent = 0x01; + else + newContent = 0x22; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x18) + { + int newContent = modeContent + rand() % 7; + + map->vertex[VertexY * map->width + VertexX].objectType = newContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } else if(modeContent == 0x09) + { + map->vertex[VertexY * map->width + VertexX].objectType = modeContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = modeContent2; + } + } + // at least setup the possible building at the vertex and 1 section around + cursorPoint tempVertices[7]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 1); + for(int i = 0; i < 7; i++) + modifyBuild(tempVertices[i].x, tempVertices[i].y); +} + +void CMap::modifyAnimal(int VertexX, int VertexY) +{ + if(mode == EDITOR_MODE_CUT) + { + map->vertex[VertexY * map->width + VertexX].animal = 0x00; + } else if(mode == EDITOR_MODE_ANIMAL) + { + // if there is another object at the vertex, return + if(map->vertex[VertexY * map->width + VertexX].animal != 0x00) + return; + + if(modeContent > 0x00 && modeContent <= 0x06) + map->vertex[VertexY * map->width + VertexX].animal = modeContent; + } +} + +void CMap::modifyBuild(int VertexX, int VertexY) +{ + // at first save all vertices we need to calculate the new building + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + + /// evtl. keine festen werte sondern addition und subtraktion wegen originalkompatibilitaet (bei baeumen bspw. keine 0x00 sondern 0x68) + + Uint8 building; + Uint8 height = map->vertex[VertexY * map->width + VertexX].h, temp; + + // calculate the building using the height of the vertices + // this building is a mine + if(map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[VertexY * map->width + VertexX].rsuTexture == TRIANGLE_TEXTURE_MINING4) + { + building = 0x05; + // test vertex lower right + temp = map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h; + if(temp - height >= 0x04) + building = 0x01; + } + // not a mine + else + { + building = 0x04; + // test the whole section + for(int i = 0; i < 6; i++) + { + temp = map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h; + if(height - temp >= 0x04 || temp - height >= 0x04) + building = 0x01; + } + + // test vertex lower right + temp = map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].h; + if(height - temp >= 0x04 || temp - height >= 0x02) + building = 0x01; + + // now test the second section around the vertex + if(building > 0x02) + { + // test the whole section + for(int i = 7; i < 19; i++) + { + temp = map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].h; + if(height - temp >= 0x03 || temp - height >= 0x03) + building = 0x02; + } + } + } + + // test if there is an object AROUND the vertex (trees or granite) + if(building > 0x01) + { + for(int i = 1; i < 7; i++) + { + if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xC4 // tree + || map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xC5 // tree + || map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xC6 // tree + ) + { + // if lower right + if(i == 6) + { + building = 0x01; + break; + } else + building = 0x02; + } else if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xCC // granite + || map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0xCD // granite + ) + { + building = 0x01; + break; + } + } + } + + // test if there is an object AT the vertex (trees or granite) + if(building > 0x00) + { + if(map->vertex[VertexY * map->width + VertexX].objectInfo == 0xC4 // tree + || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xC5 // tree + || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xC6 // tree + || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xCC // granite + || map->vertex[VertexY * map->width + VertexX].objectInfo == 0xCD // granite + ) + { + building = 0x00; + } + } + + // test if there is snow or lava at the vertex or around the vertex and touching the vertex (first section) + if(building > 0x00) + { + if(map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_LAVA) + { + building = 0x00; + } + } + + // test if there is snow or lava on the right side (RSU), in lower left (USD) or in lower right (first section) + if(building > 0x01) + { + if(map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].rsuTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].rsuTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].usdTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].usdTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].rsuTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].usdTexture == TRIANGLE_TEXTURE_SNOW + || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].rsuTexture == TRIANGLE_TEXTURE_LAVA + || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].usdTexture == TRIANGLE_TEXTURE_LAVA) + { + building = 0x01; + } + } + + // test if vertex is surrounded by water or swamp + if(building > 0x00) + { + if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) + && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) + && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) + && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_SWAMP)) + { + building = 0x00; + } else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) + || (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) + || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) + || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_SWAMP) + || (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_SWAMP) + || (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_SWAMP)) + { + building = 0x01; + } + } + + // test if there is steppe at the vertex or touching the vertex + if(building > 0x01) + { + if(map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE) + { + building = 0x01; + } + } + + // test if vertex is surrounded by mining-textures + if(building > 0x01) + { + if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING4)) + { + building = 0x05; + } else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + || (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING4) + || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + || (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING4) + || (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + || (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING4)) + { + building = 0x01; + } + } + + // test for headquarters around the point + // NOTE: In EDITORMODE don't test AT the point, cause in Original game we need a big house AT the point, otherwise the game wouldn't set + // a player there + if(building > 0x00) + { + for(int i = 1; i < 7; i++) + { + if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0x80) + building = 0x00; + } + } +#ifndef _EDITORMODE + if(building > 0x00) + { + if(map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].objectInfo == 0x80) + building = 0x00; + } +#endif + + // test for headquarters around (second section) + if(building > 0x01) + { + for(int i = 7; i < 19; i++) + { + if(map->vertex[tempVertices[i].y * map->width + tempVertices[i].x].objectInfo == 0x80) + { + if(i == 15 || i == 17 || i == 18) + building = 0x01; + else + { + // make middle house, but only if it's not a mine + if(building > 0x03 && building < 0x05) + building = 0x03; + } + } + } + } + + // Some additional information for "ingame"-building-calculation: + // There is no difference between small, middle and big houses. If you set a small house on a vertex, the + // buildings around will change like this where a middle or a big house. + // Only a flag has another algorithm. + //--Flagge einfuegen!!! + + map->vertex[VertexY * map->width + VertexX].build = building; +} + +void CMap::modifyResource(int VertexX, int VertexY) +{ + // at first save all vertices we need to check + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + + // SPECIAL CASE: test if we should set water only + // test if vertex is surrounded by meadow and meadow-like textures + if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_FLOWER + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR)) + { + map->vertex[VertexY * map->width + VertexX].resource = 0x21; + } + // SPECIAL CASE: test if we should set fishes only + // test if vertex is surrounded by water (first section) and at least one non-water texture in the second section + else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_WATER) + && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_WATER) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_WATER) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_WATER) + && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_WATER) + && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_WATER) + && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[4].y * map->width + tempVertices[4].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[5].y * map->width + tempVertices[5].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[6].y * map->width + tempVertices[6].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[7].y * map->width + tempVertices[7].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[7].y * map->width + tempVertices[7].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[8].y * map->width + tempVertices[8].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[8].y * map->width + tempVertices[8].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[9].y * map->width + tempVertices[9].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[10].y * map->width + tempVertices[10].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[10].y * map->width + tempVertices[10].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[11].y * map->width + tempVertices[11].x].rsuTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[12].y * map->width + tempVertices[12].x].usdTexture != TRIANGLE_TEXTURE_WATER + || map->vertex[tempVertices[14].y * map->width + tempVertices[14].x].usdTexture != TRIANGLE_TEXTURE_WATER)) + { + map->vertex[VertexY * map->width + VertexX].resource = 0x87; + } + // test if vertex is surrounded by mining textures + else if((map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[0].y * map->width + tempVertices[0].x].usdTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[1].y * map->width + tempVertices[1].x].usdTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[2].y * map->width + tempVertices[2].x].rsuTexture == TRIANGLE_TEXTURE_MINING4) + && (map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING1 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING2 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING3 + || map->vertex[tempVertices[3].y * map->width + tempVertices[3].x].usdTexture == TRIANGLE_TEXTURE_MINING4)) + { + // check which resource to set + if(mode == EDITOR_MODE_RESOURCE_RAISE) + { + // if there is no or another resource at the moment + if(map->vertex[VertexY * map->width + VertexX].resource == 0x40 + || map->vertex[VertexY * map->width + VertexX].resource < modeContent + || map->vertex[VertexY * map->width + VertexX].resource > modeContent + 6) + { + map->vertex[VertexY * map->width + VertexX].resource = modeContent; + } else if(map->vertex[VertexY * map->width + VertexX].resource >= modeContent + && map->vertex[VertexY * map->width + VertexX].resource <= modeContent + 6) + { + // maximum not reached? + if(map->vertex[VertexY * map->width + VertexX].resource != modeContent + 6) + map->vertex[VertexY * map->width + VertexX].resource++; + } + } else if(mode == EDITOR_MODE_RESOURCE_REDUCE) + { + // minimum not reached? + if(map->vertex[VertexY * map->width + VertexX].resource != 0x40) + { + map->vertex[VertexY * map->width + VertexX].resource--; + // minimum now reached? if so, set it to 0x40 + if(map->vertex[VertexY * map->width + VertexX].resource == 0x48 + || map->vertex[VertexY * map->width + VertexX].resource == 0x50 + || map->vertex[VertexY * map->width + VertexX].resource == 0x58 + // in case of coal we already have a 0x40, so don't check this + //|| map->vertex[VertexY*map->width+VertexX].resource == 0x40 + ) + map->vertex[VertexY * map->width + VertexX].resource = 0x40; + } + } else if(map->vertex[VertexY * map->width + VertexX].resource == 0x00) + map->vertex[VertexY * map->width + VertexX].resource = 0x40; + } else + map->vertex[VertexY * map->width + VertexX].resource = 0x00; +} + +void CMap::modifyPlayer(int VertexX, int VertexY) +{ + // if we have repositioned a player, we need the old position to recalculate the buildings there + bool PlayerRePositioned = false; + int oldPositionX = 0; + int oldPositionY = 0; + + // set player position + if(mode == EDITOR_MODE_FLAG) + { + // only allowed on big houses (0x04) --> but in cheat mode within the game also small houses (0x02) are allowed + if(/*map->vertex[VertexY*map->width+VertexX].objectType == 0x00 + && map->vertex[VertexY*map->width+VertexX].objectInfo == 0x00 + &&*/ map->vertex[VertexY * map->width + VertexX] + .build + % 8 + == 0x04 + && map->vertex[VertexY * map->width + VertexX].objectInfo != 0x80) + { + map->vertex[VertexY * map->width + VertexX].objectType = modeContent; + map->vertex[VertexY * map->width + VertexX].objectInfo = 0x80; + + // save old position if exists + if(PlayerHQx[modeContent] != 0xFFFF && PlayerHQy[modeContent] != 0xFFFF) + { + oldPositionX = PlayerHQx[modeContent]; + oldPositionY = PlayerHQy[modeContent]; + map->vertex[oldPositionY * map->width + oldPositionX].objectType = 0x00; + map->vertex[oldPositionY * map->width + oldPositionX].objectInfo = 0x00; + PlayerRePositioned = true; + } + PlayerHQx[modeContent] = VertexX; + PlayerHQy[modeContent] = VertexY; + + // for compatibility with original settlers 2 we write the headquarters positions to the map header (for the first 7 players) + if(modeContent >= 0 && modeContent < 7) + { + map->HQx[modeContent] = VertexX; + map->HQy[modeContent] = VertexY; + } + + // setup number of players in map header + if(!PlayerRePositioned) + map->player++; + } + } + // delete player position + else if(mode == EDITOR_MODE_FLAG_DELETE) + { + if(map->vertex[VertexY * map->width + VertexX].objectInfo == 0x80) + { + // at first delete the player position using the number of the player as saved in objectType + if(map->vertex[VertexY * map->width + VertexX].objectType < MAXPLAYERS) + { + PlayerHQx[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; + PlayerHQy[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; + + // for compatibility with original settlers 2 we write the headquarters positions to the map header (for the first 7 + // players) + if(modeContent >= 0 && modeContent < 7) + { + map->HQx[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; + map->HQy[map->vertex[VertexY * map->width + VertexX].objectType] = 0xFFFF; + } + } + + map->vertex[VertexY * map->width + VertexX].objectType = 0x00; + map->vertex[VertexY * map->width + VertexX].objectInfo = 0x00; + + // setup number of players in map header + map->player--; + } + } + + // at least setup the possible building at the vertex and 2 sections around + cursorPoint tempVertices[19]; + calculateVerticesAround(tempVertices, VertexX, VertexY, 2); + for(int i = 0; i < 19; i++) + modifyBuild(tempVertices[i].x, tempVertices[i].y); + + if(PlayerRePositioned) + { + calculateVerticesAround(tempVertices, oldPositionX, oldPositionY, 2); + for(int i = 0; i < 19; i++) + modifyBuild(tempVertices[i].x, tempVertices[i].y); + } +} + +int CMap::getActiveVertices(int tempChangeSection) +{ + int total = 0; + for(int i = tempChangeSection; i > 0; i--) + total += i; + return (6 * total + 1); +} + +void CMap::calculateVertices() +{ + bool even = false; + if(VertexY % 2 == 0) + even = true; + + int index = 0; + for(int i = -MAX_CHANGE_SECTION; i <= MAX_CHANGE_SECTION; i++) + { + if(abs(i) % 2 == 0) + { + for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION; j++, index++) + { + Vertices[index].x = VertexX + j; + if(Vertices[index].x < 0) + Vertices[index].x += map->width; + else if(Vertices[index].x >= map->width) + Vertices[index].x -= map->width; + Vertices[index].y = VertexY + i; + if(Vertices[index].y < 0) + Vertices[index].y += map->height; + else if(Vertices[index].y >= map->height) + Vertices[index].y -= map->height; + Vertices[index].blit_x = correctMouseBlitX(Vertices[index].x, Vertices[index].y); + Vertices[index].blit_y = correctMouseBlitY(Vertices[index].x, Vertices[index].y); + } + } else + { + for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++, index++) + { + Vertices[index].x = VertexX + (even ? j : j + 1); + if(Vertices[index].x < 0) + Vertices[index].x += map->width; + else if(Vertices[index].x >= map->width) + Vertices[index].x -= map->width; + Vertices[index].y = VertexY + i; + if(Vertices[index].y < 0) + Vertices[index].y += map->height; + else if(Vertices[index].y >= map->height) + Vertices[index].y -= map->height; + Vertices[index].blit_x = correctMouseBlitX(Vertices[index].x, Vertices[index].y); + Vertices[index].blit_y = correctMouseBlitY(Vertices[index].x, Vertices[index].y); + } + } + } + // check if cursor vertices should change randomly + if(VertexActivityRandom || VertexFillRandom) + setupVerticesActivity(); +} + +void CMap::calculateVerticesAround(cursorPoint Vertices[], int VertexX, int VertexY, int ChangeSection) +{ + bool even = false; + if(VertexY % 2 == 0) + even = true; + + Vertices[0].x = VertexX; + Vertices[0].y = VertexY; + Vertices[0].blit_x = MouseBlitX; + Vertices[0].blit_y = MouseBlitY; + + if(ChangeSection > 0) + { + Vertices[1].x = VertexX - (even ? 1 : 0); + if(Vertices[1].x < 0) + Vertices[1].x += map->width; + Vertices[1].y = VertexY - 1; + if(Vertices[1].y < 0) + Vertices[1].y += map->height; + Vertices[1].blit_x = correctMouseBlitX(Vertices[1].x, Vertices[1].y); + Vertices[1].blit_y = correctMouseBlitY(Vertices[1].x, Vertices[1].y); + Vertices[2].x = VertexX + (even ? 0 : 1); + if(Vertices[2].x >= map->width) + Vertices[2].x -= map->width; + Vertices[2].y = VertexY - 1; + if(Vertices[2].y < 0) + Vertices[2].y += map->height; + Vertices[2].blit_x = correctMouseBlitX(Vertices[2].x, Vertices[2].y); + Vertices[2].blit_y = correctMouseBlitY(Vertices[2].x, Vertices[2].y); + Vertices[3].x = VertexX - 1; + if(Vertices[3].x < 0) + Vertices[3].x += map->width; + Vertices[3].y = VertexY; + Vertices[3].blit_x = correctMouseBlitX(Vertices[3].x, Vertices[3].y); + Vertices[3].blit_y = correctMouseBlitY(Vertices[3].x, Vertices[3].y); + Vertices[4].x = VertexX + 1; + if(Vertices[4].x >= map->width) + Vertices[4].x -= map->width; + Vertices[4].y = VertexY; + Vertices[4].blit_x = correctMouseBlitX(Vertices[4].x, Vertices[4].y); + Vertices[4].blit_y = correctMouseBlitY(Vertices[4].x, Vertices[4].y); + Vertices[5].x = VertexX - (even ? 1 : 0); + if(Vertices[5].x < 0) + Vertices[5].x += map->width; + Vertices[5].y = VertexY + 1; + if(Vertices[5].y >= map->height) + Vertices[5].y -= map->height; + Vertices[5].blit_x = correctMouseBlitX(Vertices[5].x, Vertices[5].y); + Vertices[5].blit_y = correctMouseBlitY(Vertices[5].x, Vertices[5].y); + Vertices[6].x = VertexX + (even ? 0 : 1); + if(Vertices[6].x >= map->width) + Vertices[6].x -= map->width; + Vertices[6].y = VertexY + 1; + if(Vertices[6].y >= map->height) + Vertices[6].y -= map->height; + Vertices[6].blit_x = correctMouseBlitX(Vertices[6].x, Vertices[6].y); + Vertices[6].blit_y = correctMouseBlitY(Vertices[6].x, Vertices[6].y); + } + if(ChangeSection > 1) + { + Vertices[7].x = VertexX - 1; + if(Vertices[7].x < 0) + Vertices[7].x += map->width; + Vertices[7].y = VertexY - 2; + if(Vertices[7].y < 0) + Vertices[7].y += map->height; + Vertices[7].blit_x = correctMouseBlitX(Vertices[7].x, Vertices[7].y); + Vertices[7].blit_y = correctMouseBlitY(Vertices[7].x, Vertices[7].y); + Vertices[8].x = VertexX; + Vertices[8].y = VertexY - 2; + if(Vertices[8].y < 0) + Vertices[8].y += map->height; + Vertices[8].blit_x = correctMouseBlitX(Vertices[8].x, Vertices[8].y); + Vertices[8].blit_y = correctMouseBlitY(Vertices[8].x, Vertices[8].y); + Vertices[9].x = VertexX + 1; + if(Vertices[9].x >= map->width) + Vertices[9].x -= map->width; + Vertices[9].y = VertexY - 2; + if(Vertices[9].y < 0) + Vertices[9].y += map->height; + Vertices[9].blit_x = correctMouseBlitX(Vertices[9].x, Vertices[9].y); + Vertices[9].blit_y = correctMouseBlitY(Vertices[9].x, Vertices[9].y); + Vertices[10].x = VertexX - (even ? 2 : 1); + if(Vertices[10].x < 0) + Vertices[10].x += map->width; + Vertices[10].y = VertexY - 1; + if(Vertices[10].y < 0) + Vertices[10].y += map->height; + Vertices[10].blit_x = correctMouseBlitX(Vertices[10].x, Vertices[10].y); + Vertices[10].blit_y = correctMouseBlitY(Vertices[10].x, Vertices[10].y); + Vertices[11].x = VertexX + (even ? 1 : 2); + if(Vertices[11].x >= map->width) + Vertices[11].x -= map->width; + Vertices[11].y = VertexY - 1; + if(Vertices[11].y < 0) + Vertices[11].y += map->height; + Vertices[11].blit_x = correctMouseBlitX(Vertices[11].x, Vertices[11].y); + Vertices[11].blit_y = correctMouseBlitY(Vertices[11].x, Vertices[11].y); + Vertices[12].x = VertexX - 2; + if(Vertices[12].x < 0) + Vertices[12].x += map->width; + Vertices[12].y = VertexY; + Vertices[12].blit_x = correctMouseBlitX(Vertices[12].x, Vertices[12].y); + Vertices[12].blit_y = correctMouseBlitY(Vertices[12].x, Vertices[12].y); + Vertices[13].x = VertexX + 2; + if(Vertices[13].x >= map->width) + Vertices[13].x -= map->width; + Vertices[13].y = VertexY; + Vertices[13].blit_x = correctMouseBlitX(Vertices[13].x, Vertices[13].y); + Vertices[13].blit_y = correctMouseBlitY(Vertices[13].x, Vertices[13].y); + Vertices[14].x = VertexX - (even ? 2 : 1); + if(Vertices[14].x < 0) + Vertices[14].x += map->width; + Vertices[14].y = VertexY + 1; + if(Vertices[14].y >= map->height) + Vertices[14].y -= map->height; + Vertices[14].blit_x = correctMouseBlitX(Vertices[14].x, Vertices[14].y); + Vertices[14].blit_y = correctMouseBlitY(Vertices[14].x, Vertices[14].y); + Vertices[15].x = VertexX + (even ? 1 : 2); + if(Vertices[15].x >= map->width) + Vertices[15].x -= map->width; + Vertices[15].y = VertexY + 1; + if(Vertices[15].y >= map->height) + Vertices[15].y -= map->height; + Vertices[15].blit_x = correctMouseBlitX(Vertices[15].x, Vertices[15].y); + Vertices[15].blit_y = correctMouseBlitY(Vertices[15].x, Vertices[15].y); + Vertices[16].x = VertexX - 1; + if(Vertices[16].x < 0) + Vertices[16].x += map->width; + Vertices[16].y = VertexY + 2; + if(Vertices[16].y >= map->height) + Vertices[16].y -= map->height; + Vertices[16].blit_x = correctMouseBlitX(Vertices[16].x, Vertices[16].y); + Vertices[16].blit_y = correctMouseBlitY(Vertices[16].x, Vertices[16].y); + Vertices[17].x = VertexX; + Vertices[17].y = VertexY + 2; + if(Vertices[17].y >= map->height) + Vertices[17].y -= map->height; + Vertices[17].blit_x = correctMouseBlitX(Vertices[17].x, Vertices[17].y); + Vertices[17].blit_y = correctMouseBlitY(Vertices[17].x, Vertices[17].y); + Vertices[18].x = VertexX + 1; + if(Vertices[18].x >= map->width) + Vertices[18].x -= map->width; + Vertices[18].y = VertexY + 2; + if(Vertices[18].y >= map->height) + Vertices[18].y -= map->height; + Vertices[18].blit_x = correctMouseBlitX(Vertices[18].x, Vertices[18].y); + Vertices[18].blit_y = correctMouseBlitY(Vertices[18].x, Vertices[18].y); + } +} + +void CMap::setupVerticesActivity() +{ + int index = 0; + for(int i = -MAX_CHANGE_SECTION; i <= MAX_CHANGE_SECTION; i++) + { + if(abs(i) % 2 == 0) + { + for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION; j++, index++) + { + if(abs(i) <= ChangeSection && abs(j) <= ChangeSection - (ChangeSectionHexagonMode ? abs(i / 2) : 0)) + { + // check if cursor vertices should change randomly + if(VertexActivityRandom) + Vertices[index].active = (rand() % 2 == 1 ? true : false); + else + Vertices[index].active = true; + + // decide which triangle-textures will be filled at this vertex (necessary for border) + Vertices[index].fill_rsu = (VertexFillRSU ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); + Vertices[index].fill_usd = (VertexFillUSD ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); + + // if we have a ChangeSection greater than zero + if(ChangeSection) + { + // if we are in hexagon mode + if(ChangeSectionHexagonMode) + { + // if we walk through the upper rows of the cursor field + if(i < 0) + { + // right vertex of the row + if(j == ChangeSection - abs(i / 2)) + Vertices[index].fill_usd = false; + } + // if we are at the last lower row + else if(i == ChangeSection) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + // if we walk through the lower rows of the cursor field + else // if (i >= 0 && i != ChangeSection) + { + // left vertex of the row + if(j == -ChangeSection + abs(i / 2)) + Vertices[index].fill_rsu = false; + // right vertex of the row + else if(j == ChangeSection - abs(i / 2)) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + } + } + // we are in square mode + else + { + // if we are at the last lower row + if(i == ChangeSection) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + // left vertex of the row + else if(j == -ChangeSection) + Vertices[index].fill_rsu = false; + // right vertex of the row + else if(j == ChangeSection) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + } + } + } else + { + Vertices[index].active = false; + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + } + } else + { + for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++, index++) + { + if(abs(i) <= ChangeSection + && (j < 0 ? abs(j) <= ChangeSection - (ChangeSectionHexagonMode ? abs(i / 2) : 0) : + j <= ChangeSection - 1 - (ChangeSectionHexagonMode ? abs(i / 2) : 0))) + { + // check if cursor vertices should change randomly + if(VertexActivityRandom) + Vertices[index].active = (rand() % 2 == 1 ? true : false); + else + Vertices[index].active = true; + + // decide which triangle-textures will be filled at this vertex (necessary for border) + Vertices[index].fill_rsu = (VertexFillRSU ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); + Vertices[index].fill_usd = (VertexFillUSD ? true : (VertexFillRandom ? (rand() % 2 == 1 ? true : false) : false)); + + // if we have a ChangeSection greater than zero + if(ChangeSection) + { + // if we are in hexagon mode + if(ChangeSectionHexagonMode) + { + // if we walk through the upper rows of the cursor field + if(i < 0) + { + // right vertex of the row + if(j == ChangeSection - 1 - abs(i / 2)) + Vertices[index].fill_usd = false; + } + // if we are at the last lower row + else if(i == ChangeSection) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + // if we walk through the lower rows of the cursor field + else // if (i >= 0 && i != ChangeSection) + { + // left vertex of the row + if(j == -ChangeSection + abs(i / 2)) + Vertices[index].fill_rsu = false; + // right vertex of the row + else if(j == ChangeSection - 1 - abs(i / 2)) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + } + } + // we are in square mode + else + { + // if we are at the last lower row + if(i == ChangeSection) + { + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + // right vertex of the row + else if(j == ChangeSection - 1) + Vertices[index].fill_usd = false; + } + } + } else + { + Vertices[index].active = false; + Vertices[index].fill_rsu = false; + Vertices[index].fill_usd = false; + } + } + } + } + // NOTE: to understand this '-(ChangeSectionHexagonMode ? abs(i/2) : 0)' + // if we don't change the cursor size in square-mode, but in hexagon mode, + // at each row there have to be missing as much vertices as the row number is + // i = row number --> so at the left side of the row there are missing i/2 + // and at the right side there are missing i/2. That makes it look like an hexagon. +} diff --git a/CMap.h b/CMap.h index 92ba5fe..3eb24ca 100644 --- a/CMap.h +++ b/CMap.h @@ -1,196 +1,196 @@ -#ifndef _CMAP_H -#define _CMAP_H - -#include "includes.h" -#include - -class CMap -{ - friend class CDebug; - friend class CSurface; - -private: - SDL_Surface* Surf_Map; - SDL_Surface* Surf_RightMenubar; - bobMAP* map; - DisplayRectangle displayRect; - bool active; - bool needSurface; - int VertexX, VertexY; - bool RenderBuildHelp; - bool RenderBorders; - int BitsPerPixel; - // editor mode variables - int mode; - // necessary for release the EDITOR_MODE_CUT (set back to last used mode) - int lastMode; - // these variables are used by the callback functions to define what new data should go into the vertex - int modeContent; - int modeContent2; - // is the user currently modifying? - bool modify; - // necessary for "undo"- and "do"-function - bool saveCurrentVertices; - struct savedVertices - { - bool empty; - int VertexX, VertexY; - // MAX_CHANGE_SECTION * 2 + 1 = number of vertices in one row or col - //+ 10 because if we raise a vertex then the other vertices will be raised too after 5 times - // this ranges up to 10 vertices - //+ 2 because modifications on a vertex will touch building and shading around - point PointsArroundVertex[((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1)]; - 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); - // blitting coords for the mouse cursor - int MouseBlitX; - int MouseBlitY; - // counts the distance from the cursor vertex to the farest vertex that can be involved in changes (0 - only cursor vertex, 1 - six - // vertices around the cursor vertex ....) (editor mode) - int ChangeSection; - // in some cases we change the ChangeSection manually but want to reset it (this is user friendly) - int lastChangeSection; - // decides what to do if user presses '+' or '-', if true, then cursor will increase like an hexagon, otherwise like a square - bool ChangeSectionHexagonMode; - // user can decide that only RSU-Triangles will be filled (within the cursor field) - bool VertexFillRSU; - // user can decide that only USD-Triangles will be filled (within the cursor field) - bool VertexFillUSD; - // user can decide that all triangles will be filled randomly (within the cursor field) - bool VertexFillRandom; - // user can set activity to random, so all active cursor vertices (within the ChangeSection) will change each gameloop - bool VertexActivityRandom; - // 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; - // 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]; - // maximum value of height (user can modify this) - Uint8 MaxRaiseHeight; - Uint8 MinReduceHeight; - // lock vertical or horizontal movement - bool HorizontalMovementLocked; - bool VerticalMovementLocked; - -public: - CMap(const std::string& filename); - ~CMap(); - void constructMap(const std::string& filename, int width = 32, int height = 32, int type = 0, int texture = TRIANGLE_TEXTURE_MEADOW1, - int border = 4, int border_texture = TRIANGLE_TEXTURE_WATER); - void destructMap(); - bobMAP* generateMap(int width, int height, int type, int texture, int border, int border_texture); - void loadMapPics(); - void unloadMapPics(); - - void setMouseData(SDL_MouseMotionEvent motion); - void setMouseData(SDL_MouseButtonEvent button); - void setKeyboardData(SDL_KeyboardEvent key); - void setActive() { active = true; } - void setInactive() { active = false; } - bool isActive() { return active; } - int getVertexX() { return VertexX; } - int getVertexY() { return VertexY; } - bool getRenderBuildHelp() { return RenderBuildHelp; } - bool getRenderBorders() { return RenderBorders; } - int getBitsPerPixel() { return BitsPerPixel; } - void setBitsPerPixel(int bbp) - { - BitsPerPixel = bbp; - needSurface = true; - } - void setMode(int mode) { this->mode = mode; } - int getMode() { return mode; } - void setModeContent(int modeContent) { this->modeContent = modeContent; } - void setModeContent2(int modeContent2) { this->modeContent2 = modeContent2; } - int getModeContent() { return modeContent; } - int getModeContent2() { return modeContent2; } - bobMAP* getMap() { return map; } - SDL_Surface* getSurface() - { - render(); - return Surf_Map; - } - DisplayRectangle getDisplayRect() { return displayRect; } - void setDisplayRect(DisplayRectangle displayRect) { this->displayRect = displayRect; } - Uint16* getPlayerHQx() { return PlayerHQx; } - Uint16* getPlayerHQy() { return PlayerHQy; } - const char* getMapname() { return map->name; } - void setMapname(const char* name) { strcpy(map->name, name); } - const char* getAuthor() { return map->author; } - void setAuthor(const char* author) { strcpy(map->author, author); } - - void drawMinimap(SDL_Surface* Window); - void render(); - // get and set some variables necessary for cursor behavior - void setHexagonMode(bool HexagonMode) - { - ChangeSectionHexagonMode = HexagonMode; - setupVerticesActivity(); - } - bool getHexagonMode() { return ChangeSectionHexagonMode; } - void setVertexFillRSU(bool fillRSU) - { - VertexFillRSU = fillRSU; - setupVerticesActivity(); - } - bool getVertexFillRSU() { return VertexFillRSU; } - void setVertexFillUSD(bool fillUSD) - { - VertexFillUSD = fillUSD; - setupVerticesActivity(); - } - bool getVertexFillUSD() { return VertexFillUSD; } - void setVertexFillRandom(bool fillRandom) - { - VertexFillRandom = fillRandom; - setupVerticesActivity(); - } - bool getVertexFillRandom() { return VertexFillRandom; } - void setVertexActivityRandom(bool activityRandom) - { - VertexActivityRandom = activityRandom; - setupVerticesActivity(); - } - bool getVertexActivityRandom() { return VertexActivityRandom; } - -private: - // returns count of the vertices that are involved in changes (editor mode) -->THIS FUNCTION IS OUTDATED - int getActiveVertices(int tempChangeSection); - // this will calculate ALL vertices for the whole square - void calculateVertices(); - // this will calculate the vertices two sections around one vertex (like a great hexagon) --> necessary to calculate the possible - // building for a vertex view this pic to understand the indices - // X=7 X=8 X=9 - // X=10 X=1 X=2 X=11 - // X=12 X=3 X=0 X=4 X=13 - // X=14 X=5 X=6 X=15 - // X=16 X=17 X=18 - void calculateVerticesAround(cursorPoint Vertices[], int VertexX, int VertexY, int ChangeSection); - // this will setup the 'active' variable of each vertices depending on 'ChangeSection' - void setupVerticesActivity(); - int correctMouseBlitX(int VertexX, int VertexY); - int correctMouseBlitY(int VertexX, int VertexY); - void modifyVertex(); - void modifyHeightRaise(int VertexX, int VertexY); - void modifyHeightReduce(int VertexX, int VertexY); - void modifyHeightPlane(int VertexX, int VertexY, Uint8 h); - void modifyHeightMakeBigHouse(int VertexX, int VertexY); - void modifyShading(int VertexX, int VertexY); - void modifyTexture(int VertexX, int VertexY, bool rsu, bool usd); - void modifyTextureMakeHarbour(int VertexX, int VertexY); - void modifyObject(int VertexX, int VertexY); - void modifyAnimal(int VertexX, int VertexY); - void modifyBuild(int VertexX, int VertexY); - void modifyResource(int VertexX, int VertexY); - void modifyPlayer(int VertexX, int VertexY); - void rotateMap(); - void MirrorMapOnXAxis(); - void MirrorMapOnYAxis(); -}; - -#endif +#ifndef _CMAP_H +#define _CMAP_H + +#include "includes.h" +#include + +class CMap +{ + friend class CDebug; + friend class CSurface; + +private: + SDL_Surface* Surf_Map; + SDL_Surface* Surf_RightMenubar; + bobMAP* map; + DisplayRectangle displayRect; + bool active; + bool needSurface; + int VertexX, VertexY; + bool RenderBuildHelp; + bool RenderBorders; + int BitsPerPixel; + // editor mode variables + int mode; + // necessary for release the EDITOR_MODE_CUT (set back to last used mode) + int lastMode; + // these variables are used by the callback functions to define what new data should go into the vertex + int modeContent; + int modeContent2; + // is the user currently modifying? + bool modify; + // necessary for "undo"- and "do"-function + bool saveCurrentVertices; + struct savedVertices + { + bool empty; + int VertexX, VertexY; + // MAX_CHANGE_SECTION * 2 + 1 = number of vertices in one row or col + //+ 10 because if we raise a vertex then the other vertices will be raised too after 5 times + // this ranges up to 10 vertices + //+ 2 because modifications on a vertex will touch building and shading around + point PointsArroundVertex[((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1)]; + 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); + // blitting coords for the mouse cursor + int MouseBlitX; + int MouseBlitY; + // counts the distance from the cursor vertex to the farest vertex that can be involved in changes (0 - only cursor vertex, 1 - six + // vertices around the cursor vertex ....) (editor mode) + int ChangeSection; + // in some cases we change the ChangeSection manually but want to reset it (this is user friendly) + int lastChangeSection; + // decides what to do if user presses '+' or '-', if true, then cursor will increase like an hexagon, otherwise like a square + bool ChangeSectionHexagonMode; + // user can decide that only RSU-Triangles will be filled (within the cursor field) + bool VertexFillRSU; + // user can decide that only USD-Triangles will be filled (within the cursor field) + bool VertexFillUSD; + // user can decide that all triangles will be filled randomly (within the cursor field) + bool VertexFillRandom; + // user can set activity to random, so all active cursor vertices (within the ChangeSection) will change each gameloop + bool VertexActivityRandom; + // 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; + // 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]; + // maximum value of height (user can modify this) + Uint8 MaxRaiseHeight; + Uint8 MinReduceHeight; + // lock vertical or horizontal movement + bool HorizontalMovementLocked; + bool VerticalMovementLocked; + +public: + CMap(const std::string& filename); + ~CMap(); + void constructMap(const std::string& filename, int width = 32, int height = 32, int type = 0, int texture = TRIANGLE_TEXTURE_MEADOW1, + int border = 4, int border_texture = TRIANGLE_TEXTURE_WATER); + void destructMap(); + bobMAP* generateMap(int width, int height, int type, int texture, int border, int border_texture); + void loadMapPics(); + void unloadMapPics(); + + void setMouseData(SDL_MouseMotionEvent motion); + void setMouseData(SDL_MouseButtonEvent button); + void setKeyboardData(SDL_KeyboardEvent key); + void setActive() { active = true; } + void setInactive() { active = false; } + bool isActive() { return active; } + int getVertexX() { return VertexX; } + int getVertexY() { return VertexY; } + bool getRenderBuildHelp() { return RenderBuildHelp; } + bool getRenderBorders() { return RenderBorders; } + int getBitsPerPixel() { return BitsPerPixel; } + void setBitsPerPixel(int bbp) + { + BitsPerPixel = bbp; + needSurface = true; + } + void setMode(int mode) { this->mode = mode; } + int getMode() { return mode; } + void setModeContent(int modeContent) { this->modeContent = modeContent; } + void setModeContent2(int modeContent2) { this->modeContent2 = modeContent2; } + int getModeContent() { return modeContent; } + int getModeContent2() { return modeContent2; } + bobMAP* getMap() { return map; } + SDL_Surface* getSurface() + { + render(); + return Surf_Map; + } + DisplayRectangle getDisplayRect() { return displayRect; } + void setDisplayRect(DisplayRectangle displayRect) { this->displayRect = displayRect; } + Uint16* getPlayerHQx() { return PlayerHQx; } + Uint16* getPlayerHQy() { return PlayerHQy; } + const char* getMapname() { return map->name; } + void setMapname(const char* name) { strcpy(map->name, name); } + const char* getAuthor() { return map->author; } + void setAuthor(const char* author) { strcpy(map->author, author); } + + void drawMinimap(SDL_Surface* Window); + void render(); + // get and set some variables necessary for cursor behavior + void setHexagonMode(bool HexagonMode) + { + ChangeSectionHexagonMode = HexagonMode; + setupVerticesActivity(); + } + bool getHexagonMode() { return ChangeSectionHexagonMode; } + void setVertexFillRSU(bool fillRSU) + { + VertexFillRSU = fillRSU; + setupVerticesActivity(); + } + bool getVertexFillRSU() { return VertexFillRSU; } + void setVertexFillUSD(bool fillUSD) + { + VertexFillUSD = fillUSD; + setupVerticesActivity(); + } + bool getVertexFillUSD() { return VertexFillUSD; } + void setVertexFillRandom(bool fillRandom) + { + VertexFillRandom = fillRandom; + setupVerticesActivity(); + } + bool getVertexFillRandom() { return VertexFillRandom; } + void setVertexActivityRandom(bool activityRandom) + { + VertexActivityRandom = activityRandom; + setupVerticesActivity(); + } + bool getVertexActivityRandom() { return VertexActivityRandom; } + +private: + // returns count of the vertices that are involved in changes (editor mode) -->THIS FUNCTION IS OUTDATED + int getActiveVertices(int tempChangeSection); + // this will calculate ALL vertices for the whole square + void calculateVertices(); + // this will calculate the vertices two sections around one vertex (like a great hexagon) --> necessary to calculate the possible + // building for a vertex view this pic to understand the indices + // X=7 X=8 X=9 + // X=10 X=1 X=2 X=11 + // X=12 X=3 X=0 X=4 X=13 + // X=14 X=5 X=6 X=15 + // X=16 X=17 X=18 + void calculateVerticesAround(cursorPoint Vertices[], int VertexX, int VertexY, int ChangeSection); + // this will setup the 'active' variable of each vertices depending on 'ChangeSection' + void setupVerticesActivity(); + int correctMouseBlitX(int VertexX, int VertexY); + int correctMouseBlitY(int VertexX, int VertexY); + void modifyVertex(); + void modifyHeightRaise(int VertexX, int VertexY); + void modifyHeightReduce(int VertexX, int VertexY); + void modifyHeightPlane(int VertexX, int VertexY, Uint8 h); + void modifyHeightMakeBigHouse(int VertexX, int VertexY); + void modifyShading(int VertexX, int VertexY); + void modifyTexture(int VertexX, int VertexY, bool rsu, bool usd); + void modifyTextureMakeHarbour(int VertexX, int VertexY); + void modifyObject(int VertexX, int VertexY); + void modifyAnimal(int VertexX, int VertexY); + void modifyBuild(int VertexX, int VertexY); + void modifyResource(int VertexX, int VertexY); + void modifyPlayer(int VertexX, int VertexY); + void rotateMap(); + void MirrorMapOnXAxis(); + void MirrorMapOnYAxis(); +}; + +#endif diff --git a/CSurface.cpp b/CSurface.cpp index 89d7ee5..7e8cbe9 100644 --- a/CSurface.cpp +++ b/CSurface.cpp @@ -1,2004 +1,2004 @@ -#include "CSurface.h" -#include "CGame.h" -#include "CMap.h" -#include "globals.h" - -bool CSurface::drawTextures = false; -bool CSurface::useOpenGL = false; - -CSurface::CSurface() {} - -bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y) -{ - if(Surf_Dest == NULL || Surf_Src == NULL) - return false; - - SDL_Rect DestR; - - DestR.x = X; - DestR.y = Y; - - SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestR); - - return true; -} - -bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int angle) -{ - if(Surf_Dest == NULL || Surf_Src == NULL) - return false; - - Uint16 px, py; - - switch(angle) - { - case 90: - px = 0; - py = Surf_Src->h - 1; - break; - case 180: - px = Surf_Src->w - 1; - py = Surf_Src->h - 1; - break; - case 270: - px = Surf_Src->w - 1; - py = 0; - break; - default: return false; - } - - sge_transform(Surf_Src, Surf_Dest, (float)angle, 1.0, 1.0, px, py, X, Y, SGE_TSAFE); - - return true; -} - -bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H) -{ - if(Surf_Dest == NULL || Surf_Src == NULL) - return false; - - SDL_Rect DestR; - - DestR.x = X; - DestR.y = Y; - - SDL_Rect SrcR; - - SrcR.x = X2; - SrcR.y = Y2; - SrcR.w = W; - SrcR.h = H; - - SDL_BlitSurface(Surf_Src, &SrcR, Surf_Dest, &DestR); - - return true; -} - -// this is the example function from the sdl-documentation to draw pixels -void CSurface::DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color) -{ - if(SDL_MUSTLOCK(screen)) - SDL_LockSurface(screen); - - switch(screen->format->BytesPerPixel) - { - case 1: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x; - *bufp = color; - } - break; - - case 2: - { - Uint16* bufp; - - bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; - *bufp = color; - } - break; - - case 3: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } else - { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } - } - break; - - case 4: - { - Uint32* bufp; - - bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; - *bufp = color; - } - break; - } - - if(SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); -} - -// this is the example function from the sdl-documentation to draw pixels -void CSurface::DrawPixel_RGB(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) -{ - if(SDL_MUSTLOCK(screen)) - SDL_LockSurface(screen); - - Uint32 color = SDL_MapRGB(screen->format, R, G, B); - - switch(screen->format->BytesPerPixel) - { - case 1: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x; - *bufp = color; - } - break; - - case 2: - { - Uint16* bufp; - - bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; - *bufp = color; - } - break; - - case 3: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } else - { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } - } - break; - - case 4: - { - Uint32* bufp; - - bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; - *bufp = color; - } - break; - } - - if(SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); -} - -void CSurface::DrawPixel_RGBA(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A) -{ - if(SDL_MUSTLOCK(screen)) - SDL_LockSurface(screen); - - Uint32 color = SDL_MapRGBA(screen->format, R, G, B, A); - - switch(screen->format->BytesPerPixel) - { - case 1: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x; - *bufp = color; - } - break; - - case 2: - { - Uint16* bufp; - - bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; - *bufp = color; - } - break; - - case 3: - { - Uint8* bufp; - - bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } else - { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } - } - break; - - case 4: - { - Uint32* bufp; - - bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; - *bufp = color; - } - break; - } - - if(SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); -} - -Uint32 CSurface::GetPixel(SDL_Surface* surface, int x, int y) -{ - int bpp = surface->format->BytesPerPixel; - /* Here p is the address to the pixel we want to retrieve */ - Uint8* p = (Uint8*)surface->pixels + y * surface->pitch + x * bpp; - switch(bpp) - { - case 1: return *p; - - case 2: return *(Uint16*)p; - - case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - return p[0] << 16 | p[1] << 8 | p[2]; - else - return p[0] | p[1] << 8 | p[2] << 16; - - case 4: return *(Uint32*)p; - - default: - return 0; /* shouldn't happen, but avoids warnings */ - } -} - -void CSurface::DrawTriangleField(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap) -{ - Uint16 width = myMap->width; - Uint16 height = myMap->height; - Uint8 type = myMap->type; - struct point* vertex = myMap->vertex; - point tempP1, tempP2, tempP3; - - int row_start; - int row_end; - int col_start; - int col_end; - bool view_outside_edges; - - // draw triangle field - // NOTE: WE DO THIS TWICE, AT FIRST ONLY TRIANGLE-TEXTURES, AT SECOND THE TEXTURE-BORDERS AND OBJECTS - for(int i = 0; i < 2; i++) - { - if(i == 0) - drawTextures = true; - else /*if (i == 1)*/ - drawTextures = false; - - for(int k = 0; k < 4; k++) - { - // beware calling DrawTriangle for each triangle - - // IMPORTANT: integer values like +8 or -1 are for tolerance to beware of high triangles are not shown - - // at first call DrawTriangle for all triangles inside the map edges - row_start = (displayRect.y > 2 * TRIANGLE_HEIGHT ? displayRect.y : 2 * TRIANGLE_HEIGHT) / TRIANGLE_HEIGHT - 2; - row_end = (displayRect.y + displayRect.h) / TRIANGLE_HEIGHT + 8; - col_start = (displayRect.x > TRIANGLE_WIDTH ? displayRect.x : TRIANGLE_WIDTH) / TRIANGLE_WIDTH - 1; - col_end = (displayRect.x + displayRect.w) / TRIANGLE_WIDTH + 1; - - if(k > 0) - { - // now call DrawTriangle for all triangles outside the map edges - view_outside_edges = false; - - if(k == 1 || k == 3) - { - // at first call DrawTriangle for all triangles up or down outside - if(displayRect.y < 0) - { - row_start = height - 1 - (-displayRect.y / TRIANGLE_HEIGHT) - 1; - row_end = height - 1; - view_outside_edges = true; - } - - else if((displayRect.y + displayRect.h) > myMap->height_pixel) - { - row_start = 0; - row_end = ((displayRect.y + displayRect.h) - myMap->height_pixel) / TRIANGLE_HEIGHT + 8; - view_outside_edges = true; - } else if(displayRect.y <= 2 * TRIANGLE_HEIGHT) - { - // this is for draw triangles that are reduced under the lower map edge (have bigger y-coords as - // myMap->height_pixel) - row_start = height - 3; - row_end = height - 1; - view_outside_edges = true; - } else if((displayRect.y + displayRect.h) >= (myMap->height_pixel - 8 * TRIANGLE_HEIGHT)) - { - // this is for draw triangles that are raised over the upper map edge (have negative y-coords) - row_start = 0; - row_end = 8; - view_outside_edges = true; - } - } - - if(k == 2 || k == 3) - { - // now call DrawTriangle for all triangles left or right outside - if(displayRect.x <= 0) - { - col_start = width - 1 - (-displayRect.x / TRIANGLE_WIDTH) - 1; - col_end = width - 1; - view_outside_edges = true; - } else if(displayRect.x > 0 && displayRect.x < TRIANGLE_WIDTH) - { - col_start = width - 2; - col_end = width - 1; - view_outside_edges = true; - } else if((displayRect.x + displayRect.w) > myMap->width_pixel) - { - col_start = 0; - col_end = ((displayRect.x + displayRect.w) - myMap->width_pixel) / TRIANGLE_WIDTH + 1; - view_outside_edges = true; - } - } - - // if displayRect is not outside the map edges, there is nothing to do - if(!view_outside_edges) - continue; - } - - for(int j = /*0*/ row_start; j < height - 1 && j <= row_end; j++) - { - if(j % 2 == 0) - { - // first RightSideUp - tempP2.x = 0; - tempP2.y = vertex[(j + 1) * width + width - 1].y; - tempP2.z = vertex[(j + 1) * width + width - 1].z; - tempP2.i = vertex[(j + 1) * width + width - 1].i; - DrawTriangle(display, displayRect, myMap, type, vertex[j * width + 0], tempP2, vertex[(j + 1) * width + 0]); - for(int i = /*1*/ (col_start > 0 ? col_start : 1); i < width && i <= col_end; i++) - { - // RightSideUp - DrawTriangle(display, displayRect, myMap, type, vertex[j * width + i], vertex[(j + 1) * width + i - 1], - vertex[(j + 1) * width + i]); - // UpSideDown - if(i < width) - DrawTriangle(display, displayRect, myMap, type, vertex[(j + 1) * width + i - 1], vertex[j * width + i - 1], - vertex[j * width + i]); - } - // last UpSideDown - tempP3.x = vertex[j * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = vertex[j * width + 0].y; - tempP3.z = vertex[j * width + 0].z; - tempP3.i = vertex[j * width + 0].i; - DrawTriangle(display, displayRect, myMap, type, vertex[(j + 1) * width + width - 1], vertex[j * width + width - 1], - tempP3); - } else - { - for(int i = /*0*/ col_start; i < width - 1 && i <= col_end; i++) - { - // RightSideUp - DrawTriangle(display, displayRect, myMap, type, vertex[j * width + i], vertex[(j + 1) * width + i], - vertex[(j + 1) * width + i + 1]); - // UpSideDown - DrawTriangle(display, displayRect, myMap, type, vertex[(j + 1) * width + i + 1], vertex[j * width + i], - vertex[j * width + i + 1]); - } - // last RightSideUp - tempP3.x = vertex[(j + 1) * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = vertex[(j + 1) * width + 0].y; - tempP3.z = vertex[(j + 1) * width + 0].z; - tempP3.i = vertex[(j + 1) * width + 0].i; - DrawTriangle(display, displayRect, myMap, type, vertex[j * width + width - 1], vertex[(j + 1) * width + width - 1], - tempP3); - // last UpSideDown - tempP1.x = vertex[(j + 1) * width + width - 1].x + TRIANGLE_WIDTH; - tempP1.y = vertex[(j + 1) * width + 0].y; - tempP1.z = vertex[(j + 1) * width + 0].z; - tempP1.i = vertex[(j + 1) * width + 0].i; - tempP3.x = vertex[j * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = vertex[j * width + 0].y; - tempP3.z = vertex[j * width + 0].z; - tempP3.i = vertex[j * width + 0].i; - DrawTriangle(display, displayRect, myMap, type, tempP1, vertex[j * width + width - 1], tempP3); - } - } - - // draw last line - for(int i = /*0*/ col_start; i < width - 1 && i <= col_end; i++) - { - // RightSideUp - tempP2.x = vertex[0 * width + i].x; - tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i].y; - tempP2.z = vertex[0 * width + i].z; - tempP2.i = vertex[0 * width + i].i; - tempP3.x = vertex[0 * width + i + 1].x; - tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i + 1].y; - tempP3.z = vertex[0 * width + i + 1].z; - tempP3.i = vertex[0 * width + i + 1].i; - DrawTriangle(display, displayRect, myMap, type, vertex[(height - 1) * width + i], tempP2, tempP3); - // UpSideDown - tempP1.x = vertex[0 * width + i + 1].x; - tempP1.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i + 1].y; - tempP1.z = vertex[0 * width + i + 1].z; - tempP1.i = vertex[0 * width + i + 1].i; - DrawTriangle(display, displayRect, myMap, type, tempP1, vertex[(height - 1) * width + i], - vertex[(height - 1) * width + i + 1]); - } - } - - // last RightSideUp - tempP2.x = vertex[0 * width + width - 1].x; - tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + width - 1].y; - tempP2.z = vertex[0 * width + width - 1].z; - tempP2.i = vertex[0 * width + width - 1].i; - tempP3.x = vertex[0 * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + 0].y; - tempP3.z = vertex[0 * width + 0].z; - tempP3.i = vertex[0 * width + 0].i; - DrawTriangle(display, displayRect, myMap, type, vertex[(height - 1) * width + width - 1], tempP2, tempP3); - // last UpSideDown - tempP1.x = vertex[0 * width + width - 1].x + TRIANGLE_WIDTH; - tempP1.y = height * TRIANGLE_HEIGHT + vertex[0 * width + 0].y; - tempP1.z = vertex[0 * width + 0].z; - tempP1.i = vertex[0 * width + 0].i; - tempP3.x = vertex[(height - 1) * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = vertex[(height - 1) * width + 0].y; - tempP3.z = vertex[(height - 1) * width + 0].z; - tempP3.i = vertex[(height - 1) * width + 0].i; - DrawTriangle(display, displayRect, myMap, type, tempP1, vertex[(height - 1) * width + width - 1], tempP3); - } -} - -void CSurface::DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap, Uint8 type, point P1, point P2, point P3) -{ - // prevent drawing triangles that are not shown - if(((P1.x < displayRect.x && P2.x < displayRect.x && P3.x < displayRect.x) - || (P1.x > (displayRect.x + displayRect.w) && P2.x > (displayRect.x + displayRect.w) && P3.x > (displayRect.x + displayRect.w))) - || ((P1.y < displayRect.y && P2.y < displayRect.y && P3.y < displayRect.y) - || (P1.y > (displayRect.y + displayRect.h) && P2.y > (displayRect.y + displayRect.h) && P3.y > (displayRect.y + displayRect.h)))) - { - bool triangle_shown = false; - - if(displayRect.x <= 0) - { - int outside_x = displayRect.x; - int outside_w = -displayRect.x; - if((((P1.x - myMap->width_pixel) >= (outside_x)) && ((P1.x - myMap->width_pixel) <= (outside_x + outside_w))) - || (((P2.x - myMap->width_pixel) >= (outside_x)) && ((P2.x - myMap->width_pixel) <= (outside_x + outside_w))) - || (((P3.x - myMap->width_pixel) >= (outside_x)) && ((P3.x - myMap->width_pixel) <= (outside_x + outside_w)))) - { - P1.x -= myMap->width_pixel; - P2.x -= myMap->width_pixel; - P3.x -= myMap->width_pixel; - triangle_shown = true; - } - } else if(displayRect.x > 0 && displayRect.x < TRIANGLE_WIDTH) - { - int outside_x = displayRect.x; - int outside_w = TRIANGLE_WIDTH; - if((((P1.x - myMap->width_pixel) >= (outside_x)) && ((P1.x - myMap->width_pixel) <= (outside_x + outside_w))) - || (((P2.x - myMap->width_pixel) >= (outside_x)) && ((P2.x - myMap->width_pixel) <= (outside_x + outside_w))) - || (((P3.x - myMap->width_pixel) >= (outside_x)) && ((P3.x - myMap->width_pixel) <= (outside_x + outside_w)))) - { - P1.x -= myMap->width_pixel; - P2.x -= myMap->width_pixel; - P3.x -= myMap->width_pixel; - triangle_shown = true; - } - } else if((displayRect.x + displayRect.w) > (myMap->width_pixel)) - { - int outside_x = myMap->width_pixel; - int outside_w = displayRect.x + displayRect.w - myMap->width_pixel; - if((((P1.x + myMap->width_pixel) >= (outside_x)) && ((P1.x + myMap->width_pixel) <= (outside_x + outside_w))) - || (((P2.x + myMap->width_pixel) >= (outside_x)) && ((P2.x + myMap->width_pixel) <= (outside_x + outside_w))) - || (((P3.x + myMap->width_pixel) >= (outside_x)) && ((P3.x + myMap->width_pixel) <= (outside_x + outside_w)))) - { - P1.x += myMap->width_pixel; - P2.x += myMap->width_pixel; - P3.x += myMap->width_pixel; - triangle_shown = true; - } - } - - if(displayRect.y < 0) - { - int outside_y = displayRect.y; - int outside_h = -displayRect.y; - if((((P1.y - myMap->height_pixel) >= (outside_y)) && ((P1.y - myMap->height_pixel) <= (outside_y + outside_h))) - || (((P2.y - myMap->height_pixel) >= (outside_y)) && ((P2.y - myMap->height_pixel) <= (outside_y + outside_h))) - || (((P3.y - myMap->height_pixel) >= (outside_y)) && ((P3.y - myMap->height_pixel) <= (outside_y + outside_h)))) - { - P1.y -= myMap->height_pixel; - P2.y -= myMap->height_pixel; - P3.y -= myMap->height_pixel; - triangle_shown = true; - } - } else if((displayRect.y + displayRect.h) > (myMap->height_pixel)) - { - int outside_y = myMap->height_pixel; - int outside_h = displayRect.y + displayRect.h - myMap->height_pixel; - if((((P1.y + myMap->height_pixel) >= (outside_y)) && ((P1.y + myMap->height_pixel) <= (outside_y + outside_h))) - || (((P2.y + myMap->height_pixel) >= (outside_y)) && ((P2.y + myMap->height_pixel) <= (outside_y + outside_h))) - || (((P3.y + myMap->height_pixel) >= (outside_y)) && ((P3.y + myMap->height_pixel) <= (outside_y + outside_h)))) - { - P1.y += myMap->height_pixel; - P2.y += myMap->height_pixel; - P3.y += myMap->height_pixel; - triangle_shown = true; - } - } - - // now test if triangle has negative y-coords cause it's raised over the upper map edge - if(P1.y < 0 || P2.y < 0 || P3.y < 0) - { - if((((P1.y + myMap->height_pixel) >= displayRect.y) && ((P1.y + myMap->height_pixel) <= (displayRect.y + displayRect.h))) - || (((P2.y + myMap->height_pixel) >= displayRect.y) && ((P2.y + myMap->height_pixel) <= (displayRect.y + displayRect.h))) - || (((P3.y + myMap->height_pixel) >= displayRect.y) && ((P3.y + myMap->height_pixel) <= (displayRect.y + displayRect.h)))) - { - P1.y += myMap->height_pixel; - P2.y += myMap->height_pixel; - P3.y += myMap->height_pixel; - triangle_shown = true; - } - } - - // now test if triangle has bigger y-coords as myMap->height_pixel cause it's reduced under the lower map edge - if(P1.y > myMap->height_pixel || P2.y > myMap->height_pixel || P3.y > myMap->height_pixel) - { - if((((P1.y - myMap->height_pixel) >= displayRect.y) && ((P1.y - myMap->height_pixel) <= (displayRect.y + displayRect.h))) - || (((P2.y - myMap->height_pixel) >= displayRect.y) && ((P2.y - myMap->height_pixel) <= (displayRect.y + displayRect.h))) - || (((P3.y - myMap->height_pixel) >= displayRect.y) && ((P3.y - myMap->height_pixel) <= (displayRect.y + displayRect.h)))) - { - P1.y -= myMap->height_pixel; - P2.y -= myMap->height_pixel; - P3.y -= myMap->height_pixel; - triangle_shown = true; - } - } - - if(!triangle_shown) - return; - } - - // 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; - - // for moving water, lava, objects and so on - // This is very tricky: there are ice floes in the winterland and the water under this floes is moving. - // I don't know how this works in original settlers 2 but i solved it this way: - // i texture the triangle with normal water and then draw the floe over it. To Extract the floe - // from it's surrounded water, i use this color keys below. These are the color values for the water texture. - // I wrote a special SGE-Function that uses these color keys and ignores them in the Surf_Tileset. - static Uint32 colorkeys[5] = {14191, 14195, 13167, 13159, 11119}; - static int keycount = 5; - static int texture_move = 0; - static int roundCount = 0; - static Uint32 roundTimeObjects = SDL_GetTicks(); - static Uint32 roundTimeTextures = SDL_GetTicks(); - if(SDL_GetTicks() - roundTimeObjects > 30) - { - roundTimeObjects = SDL_GetTicks(); - if(roundCount >= 7) - roundCount = 0; - else - roundCount++; - } - if(SDL_GetTicks() - roundTimeTextures > 170) - { - roundTimeTextures = SDL_GetTicks(); - texture_move++; - if(texture_move > 14) - texture_move = 0; - } - - switch(type) - { - case MAP_GREENLAND: - Surf_Tileset = - global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_GREENLAND_8BPP : TILESET_GREENLAND_32BPP].surface; - break; - case MAP_WASTELAND: - Surf_Tileset = - global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_WASTELAND_8BPP : TILESET_WASTELAND_32BPP].surface; - break; - case MAP_WINTERLAND: - Surf_Tileset = - global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_WINTERLAND_8BPP : TILESET_WINTERLAND_32BPP] - .surface; - break; - default: - Surf_Tileset = - global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_GREENLAND_8BPP : TILESET_GREENLAND_32BPP].surface; - break; - } - - if(P1.y < P2.y) - texture = P1.rsuTexture; - else - texture = P2.usdTexture; - texture_raw = texture; - if(texture_raw >= 0x40) - // it's a harbour - texture_raw -= 0x40; - - Point16 shiftedP1, shiftedP2, shiftedP3; - shiftedP1.x = static_cast(P1.x - displayRect.x); - shiftedP1.y = static_cast(P1.y - displayRect.y); - shiftedP2.x = static_cast(P2.x - displayRect.x); - shiftedP2.y = static_cast(P2.y - displayRect.y); - shiftedP3.x = static_cast(P3.x - displayRect.x); - shiftedP3.y = static_cast(P3.y - displayRect.y); - - if(drawTextures) - { - switch(texture_raw) - { - // in case of USD-Triangle "upperX" and "upperY" means "lowerX" and "lowerY" - case TRIANGLE_TEXTURE_STEPPE_MEADOW1: - upperX = 17; - upperY = 96; - leftX = 0; - leftY = 126; - rightX = 35; - rightY = 126; - break; - case TRIANGLE_TEXTURE_MINING1: - upperX = 17; - upperY = 48; - leftX = 0; - leftY = 78; - rightX = 35; - rightY = 78; - break; - case TRIANGLE_TEXTURE_SNOW: - if(P1.y < P2.y) - { - upperX = 17; - upperY = 0; - leftX = 0; - leftY = 30; - rightX = 35; - rightY = 30; - } else - { - upperX = 17; - upperY = 28; - leftX = 0; - leftY = 0; - rightX = 37; - rightY = 0; - } - if(type == MAP_WINTERLAND) - { - if(P1.y < P2.y) - { - upperX2 = 231 - texture_move; - upperY2 = 61 + texture_move; - leftX2 = 207 - texture_move; - leftY2 = 62 + texture_move; - rightX2 = 223 - texture_move; - rightY2 = 78 + texture_move; - } else - { - upperX2 = 224 - texture_move; - upperY2 = 79 + texture_move; - leftX2 = 232 - texture_move; - leftY2 = 62 + texture_move; - rightX2 = 245 - texture_move; - rightY2 = 76 + texture_move; - } - } - break; - case TRIANGLE_TEXTURE_SWAMP: - upperX = 113; - upperY = 0; - leftX = 96; - leftY = 30; - rightX = 131; - rightY = 30; - if(type == MAP_WINTERLAND) - { - if(P1.y < P2.y) - { - upperX2 = 231 - texture_move; - upperY2 = 61 + texture_move; - leftX2 = 207 - texture_move; - leftY2 = 62 + texture_move; - rightX2 = 223 - texture_move; - rightY2 = 78 + texture_move; - } else - { - upperX2 = 224 - texture_move; - upperY2 = 79 + texture_move; - leftX2 = 232 - texture_move; - leftY2 = 62 + texture_move; - rightX2 = 245 - texture_move; - rightY2 = 76 + texture_move; - } - } - break; - case TRIANGLE_TEXTURE_STEPPE: - upperX = 65; - upperY = 0; - leftX = 48; - leftY = 30; - rightX = 83; - rightY = 30; - break; - case TRIANGLE_TEXTURE_STEPPE_: - upperX = 65; - upperY = 0; - leftX = 48; - leftY = 30; - rightX = 83; - rightY = 30; - break; - case TRIANGLE_TEXTURE_STEPPE__: - upperX = 65; - upperY = 0; - leftX = 48; - leftY = 30; - rightX = 83; - rightY = 30; - break; - case TRIANGLE_TEXTURE_STEPPE___: - upperX = 65; - upperY = 0; - leftX = 48; - leftY = 30; - rightX = 83; - rightY = 30; - break; - case TRIANGLE_TEXTURE_WATER: - if(P1.y < P2.y) - { - upperX = 231 - texture_move; - upperY = 61 + texture_move; - leftX = 207 - texture_move; - leftY = 62 + texture_move; - rightX = 223 - texture_move; - rightY = 78 + texture_move; - } else - { - upperX = 224 - texture_move; - upperY = 79 + texture_move; - leftX = 232 - texture_move; - leftY = 62 + texture_move; - rightX = 245 - texture_move; - rightY = 76 + texture_move; - } - case TRIANGLE_TEXTURE_WATER_: - if(P1.y < P2.y) - { - upperX = 231 - texture_move; - upperY = 61 + texture_move; - leftX = 207 - texture_move; - leftY = 62 + texture_move; - rightX = 223 - texture_move; - rightY = 78 + texture_move; - } else - { - upperX = 224 - texture_move; - upperY = 79 + texture_move; - leftX = 232 - texture_move; - leftY = 62 + texture_move; - rightX = 245 - texture_move; - rightY = 76 + texture_move; - } - break; - case TRIANGLE_TEXTURE_WATER__: - if(P1.y < P2.y) - { - upperX = 231 - texture_move; - upperY = 61 + texture_move; - leftX = 207 - texture_move; - leftY = 62 + texture_move; - rightX = 223 - texture_move; - rightY = 78 + texture_move; - } else - { - upperX = 224 - texture_move; - upperY = 79 + texture_move; - leftX = 232 - texture_move; - leftY = 62 + texture_move; - rightX = 245 - texture_move; - rightY = 76 + texture_move; - } - break; - case TRIANGLE_TEXTURE_MEADOW1: - upperX = 65; - upperY = 96; - leftX = 48; - leftY = 126; - rightX = 83; - rightY = 126; - break; - case TRIANGLE_TEXTURE_MEADOW2: - upperX = 113; - upperY = 96; - leftX = 96; - leftY = 126; - rightX = 131; - rightY = 126; - break; - case TRIANGLE_TEXTURE_MEADOW3: - upperX = 161; - upperY = 96; - leftX = 144; - leftY = 126; - rightX = 179; - rightY = 126; - break; - case TRIANGLE_TEXTURE_MINING2: - upperX = 65; - upperY = 48; - leftX = 48; - leftY = 78; - rightX = 83; - rightY = 78; - break; - case TRIANGLE_TEXTURE_MINING3: - upperX = 113; - upperY = 48; - leftX = 96; - leftY = 78; - rightX = 131; - rightY = 78; - break; - case TRIANGLE_TEXTURE_MINING4: - upperX = 161; - upperY = 48; - leftX = 144; - leftY = 78; - rightX = 179; - rightY = 78; - break; - case TRIANGLE_TEXTURE_STEPPE_MEADOW2: - upperX = 17; - upperY = 144; - leftX = 0; - leftY = 174; - rightX = 35; - rightY = 174; - break; - case TRIANGLE_TEXTURE_FLOWER: - upperX = 161; - upperY = 0; - leftX = 144; - leftY = 30; - rightX = 179; - rightY = 30; - break; - case TRIANGLE_TEXTURE_LAVA: - if(P1.y < P2.y) - { - upperX = 231 - texture_move; - upperY = 117 + texture_move; - leftX = 207 - texture_move; - leftY = 118 + texture_move; - rightX = 223 - texture_move; - rightY = 134 + texture_move; - } else - { - upperX = 224 - texture_move; - upperY = 135 + texture_move; - leftX = 232 - texture_move; - leftY = 118 + texture_move; - rightX = 245 - texture_move; - rightY = 132 + texture_move; - } - break; - case TRIANGLE_TEXTURE_MINING_MEADOW: - upperX = 65; - upperY = 144; - leftX = 48; - leftY = 174; - rightX = 83; - rightY = 174; - break; - default: // TRIANGLE_TEXTURE_FLOWER - upperX = 161; - upperY = 0; - leftX = 144; - leftY = 30; - rightX = 179; - rightY = 30; - break; - } - - // draw the triangle - // do not shade water and lava - if(texture == TRIANGLE_TEXTURE_WATER || texture == TRIANGLE_TEXTURE_LAVA) - sge_TexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, Surf_Tileset, upperX, - upperY, leftX, leftY, rightX, rightY); - else - { - // draw special winterland textures with moving water (ice floe textures) - if(type == MAP_WINTERLAND && (texture == TRIANGLE_TEXTURE_SNOW || texture == TRIANGLE_TEXTURE_SWAMP)) - { - sge_TexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, Surf_Tileset, - upperX2, upperY2, leftX2, leftY2, rightX2, rightY2); - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedTrigonColorKeys( - display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, Surf_Tileset, upperX, upperY, - leftX, leftY, rightX, rightY, P1.shading << 8, P2.shading << 8, P3.shading << 8, gouData[type], colorkeys, keycount); - else - sge_FadedTexturedTrigonColorKeys(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, - Surf_Tileset, upperX, upperY, leftX, leftY, rightX, rightY, P1.i, P2.i, P3.i, - colorkeys, keycount); - } else - { - if(global::s2->getMapObj()->getBitsPerPixel() == 8) - sge_PreCalcFadedTexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, - Surf_Tileset, upperX, upperY, leftX, leftY, rightX, rightY, P1.shading << 8, - P2.shading << 8, P3.shading << 8, gouData[type]); - else - sge_FadedTexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, - Surf_Tileset, upperX, upperY, leftX, leftY, rightX, rightY, P1.i, P2.i, P3.i); - } - } - return; - } - - // blit borders - /// 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; - point 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 - Uint16 col = (P1.VertexX - 1 < 0 ? myMap->width - 1 : P1.VertexX - 1); - tempP = myMap->vertex[P1.VertexY * myMap->width + col]; - - // 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)))) - { - Border1 = false; - Border2 = false; - - 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); - } - } - } - // 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)))) - { - Border1 = false; - Border2 = false; - - // 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; - } - - 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); - } - } - - // decide which border to blit (top/bottom) - therefore get the rsu-texture one line above to compare - Uint16 row = (P2.VertexY - 1 < 0 ? myMap->height - 1 : P2.VertexY - 1); - Uint16 col = (P2.VertexY % 2 == 0 ? P2.VertexX : (P2.VertexX + 1 > myMap->width - 1 ? 0 : P2.VertexX + 1)); - tempP = myMap->vertex[row * myMap->width + col]; - - // 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)))) - { - 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); - } - } - } - - // blit picture to vertex (trees, animals, buildings and so on) --> BUT ONLY AT P1 ON RIGHTSIDEUP-TRIANGLES - - // blit objects - if(P2.y < P1.y) - { - int objIdx = 0; - switch(P2.objectInfo) - { - // tree - case 0xC4: - if(P2.objectType >= 0x30 && P2.objectType <= 0x37) - { - if(P2.objectType + roundCount > 0x37) - objIdx = MAPPIC_TREE_PINE + (P2.objectType - 0x30) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_PINE + (P2.objectType - 0x30) + roundCount; - - } else if(P2.objectType >= 0x70 && P2.objectType <= 0x77) - { - if(P2.objectType + roundCount > 0x77) - objIdx = MAPPIC_TREE_BIRCH + (P2.objectType - 0x70) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_BIRCH + (P2.objectType - 0x70) + roundCount; - } else if(P2.objectType >= 0xB0 && P2.objectType <= 0xB7) - { - if(P2.objectType + roundCount > 0xB7) - objIdx = MAPPIC_TREE_OAK + (P2.objectType - 0xB0) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_OAK + (P2.objectType - 0xB0) + roundCount; - } else if(P2.objectType >= 0xF0 && P2.objectType <= 0xF7) - { - if(P2.objectType + roundCount > 0xF7) - objIdx = MAPPIC_TREE_PALM1 + (P2.objectType - 0xF0) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_PALM1 + (P2.objectType - 0xF0) + roundCount; - } - break; - // tree - case 0xC5: - if(P2.objectType >= 0x30 && P2.objectType <= 0x37) - { - if(P2.objectType + roundCount > 0x37) - objIdx = MAPPIC_TREE_PALM2 + (P2.objectType - 0x30) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_PALM2 + (P2.objectType - 0x30) + roundCount; - - } else if(P2.objectType >= 0x70 && P2.objectType <= 0x77) - { - if(P2.objectType + roundCount > 0x77) - objIdx = MAPPIC_TREE_PINEAPPLE + (P2.objectType - 0x70) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_PINEAPPLE + (P2.objectType - 0x70) + roundCount; - } else if(P2.objectType >= 0xB0 && P2.objectType <= 0xB7) - { - if(P2.objectType + roundCount > 0xB7) - objIdx = MAPPIC_TREE_CYPRESS + (P2.objectType - 0xB0) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_CYPRESS + (P2.objectType - 0xB0) + roundCount; - } else if(P2.objectType >= 0xF0 && P2.objectType <= 0xF7) - { - if(P2.objectType + roundCount > 0xF7) - objIdx = MAPPIC_TREE_CHERRY + (P2.objectType - 0xF0) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_CHERRY + (P2.objectType - 0xF0) + roundCount; - } - break; - // tree - case 0xC6: - if(P2.objectType >= 0x30 && P2.objectType <= 0x37) - { - if(P2.objectType + roundCount > 0x37) - objIdx = MAPPIC_TREE_FIR + (P2.objectType - 0x30) + (roundCount - 7); - else - objIdx = MAPPIC_TREE_FIR + (P2.objectType - 0x30) + roundCount; - } - break; - // landscape - case 0xC8: - switch(P2.objectType) - { - case 0x00: objIdx = MAPPIC_MUSHROOM1; break; - case 0x01: objIdx = MAPPIC_MUSHROOM2; break; - case 0x02: objIdx = MAPPIC_STONE1; break; - case 0x03: objIdx = MAPPIC_STONE2; break; - case 0x04: objIdx = MAPPIC_STONE3; break; - case 0x05: objIdx = MAPPIC_TREE_TRUNK_DEAD; break; - case 0x06: objIdx = MAPPIC_TREE_DEAD; break; - case 0x07: objIdx = MAPPIC_BONE1; break; - case 0x08: objIdx = MAPPIC_BONE2; break; - case 0x09: objIdx = MAPPIC_FLOWERS; break; - case 0x10: objIdx = MAPPIC_BUSH2; break; - case 0x11: objIdx = MAPPIC_BUSH3; break; - case 0x12: objIdx = MAPPIC_BUSH4; break; - - case 0x0A: objIdx = MAPPIC_BUSH1; break; - - case 0x0C: objIdx = MAPPIC_CACTUS1; break; - case 0x0D: objIdx = MAPPIC_CACTUS2; break; - case 0x0E: objIdx = MAPPIC_SHRUB1; break; - case 0x0F: objIdx = MAPPIC_SHRUB2; break; - - case 0x13: objIdx = MAPPIC_SHRUB3; break; - case 0x14: objIdx = MAPPIC_SHRUB4; break; - - case 0x16: objIdx = MAPPIC_DOOR; break; - - case 0x18: objIdx = MIS1BOBS_STONE1; break; - case 0x19: objIdx = MIS1BOBS_STONE2; break; - case 0x1A: objIdx = MIS1BOBS_STONE3; break; - case 0x1B: objIdx = MIS1BOBS_STONE4; break; - case 0x1C: objIdx = MIS1BOBS_STONE5; break; - case 0x1D: objIdx = MIS1BOBS_STONE6; break; - case 0x1E: objIdx = MIS1BOBS_STONE7; break; - - case 0x22: objIdx = MAPPIC_MUSHROOM3; break; - - case 0x25: objIdx = MAPPIC_PEBBLE1; break; - case 0x26: objIdx = MAPPIC_PEBBLE2; break; - case 0x27: objIdx = MAPPIC_PEBBLE3; break; - default: break; - } - break; - // stone - case 0xCC: - objIdx = MAPPIC_GRANITE_1_1 + (P2.objectType - 0x01); - break; - // stone - case 0xCD: - objIdx = MAPPIC_GRANITE_2_1 + (P2.objectType - 0x01); - break; - // headquarter - case 0x80: // P2.objectType is the number of the player beginning with 0x00 -//%7 cause in the original game there are only 7 players and 7 different flags -#ifdef _EDITORMODE - objIdx = FLAG_BLUE_DARK + P2.objectType % 7; -#endif - break; - - default: break; - } - if(objIdx != 0) - Draw(display, global::bmpArray[objIdx].surface, (int)(P2.x - displayRect.x - global::bmpArray[objIdx].nx), - (int)(P2.y - displayRect.y - global::bmpArray[objIdx].ny)); - } - -#ifdef _EDITORMODE - // blit resources - if(P2.y < P1.y) - { - if(P2.resource >= 0x41 && P2.resource <= 0x47) - { - for(char i = 0x41; i <= P2.resource; i++) - Draw(display, global::bmpArray[PICTURE_RESOURCE_COAL].surface, - (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_COAL].nx), - (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_COAL].ny - (4 * (i - 0x40)))); - } else if(P2.resource >= 0x49 && P2.resource <= 0x4F) - { - for(char i = 0x49; i <= P2.resource; i++) - Draw(display, global::bmpArray[PICTURE_RESOURCE_ORE].surface, - (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_ORE].nx), - (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_ORE].ny - (4 * (i - 0x48)))); - } - if(P2.resource >= 0x51 && P2.resource <= 0x57) - { - for(char i = 0x51; i <= P2.resource; i++) - Draw(display, global::bmpArray[PICTURE_RESOURCE_GOLD].surface, - (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_GOLD].nx), - (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_GOLD].ny - (4 * (i - 0x50)))); - } - if(P2.resource >= 0x59 && P2.resource <= 0x5F) - { - for(char i = 0x59; i <= P2.resource; i++) - Draw(display, global::bmpArray[PICTURE_RESOURCE_GRANITE].surface, - (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_GRANITE].nx), - (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_GRANITE].ny - (4 * (i - 0x58)))); - } - } - // blit animals - if(P2.y < P1.y) - { - if(P2.animal > 0x00 && P2.animal <= 0x06) - { - Draw(display, global::bmpArray[PICTURE_SMALL_BEAR + P2.animal].surface, - (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_SMALL_BEAR + P2.animal].nx), - (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_SMALL_BEAR + P2.animal].ny)); - } - } -#endif - - // blit buildings - if(global::s2->getMapObj()->getRenderBuildHelp()) - { - if(P2.y < P1.y) - { - switch(P2.build % 8) - { - case 0x01: - Draw(display, global::bmpArray[MAPPIC_FLAG].surface, (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_FLAG].nx), - (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_FLAG].ny)); - break; - case 0x02: - Draw(display, global::bmpArray[MAPPIC_HOUSE_SMALL].surface, - (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_SMALL].nx), - (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_SMALL].ny)); - break; - case 0x03: - Draw(display, global::bmpArray[MAPPIC_HOUSE_MIDDLE].surface, - (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_MIDDLE].nx), - (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_MIDDLE].ny)); - break; - case 0x04: - if(P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || P2.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) - Draw(display, global::bmpArray[MAPPIC_HOUSE_HARBOUR].surface, - (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_HARBOUR].nx), - (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_HARBOUR].ny)); - else - Draw(display, global::bmpArray[MAPPIC_HOUSE_BIG].surface, - (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_BIG].nx), - (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_BIG].ny)); - break; - case 0x05: - Draw(display, global::bmpArray[MAPPIC_MINE].surface, (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_MINE].nx), - (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_MINE].ny)); - break; - default: break; - } - } - } -} - -void CSurface::get_nodeVectors(bobMAP* myMap) -{ - // prepare triangle field - int height = myMap->height; - int width = myMap->width; - struct point* vertex = myMap->vertex; - struct point /*tempP1,*/ tempP2, tempP3; - - // get flat vectors - for(int j = 0; j < height - 1; j++) - { - if(j % 2 == 0) - { - // vector of first triangle - tempP2.x = 0; - tempP2.y = vertex[(j + 1) * width + width - 1].y; - tempP2.z = vertex[(j + 1) * width + width - 1].z; - vertex[j * width + 0].flatVector = get_flatVector(&vertex[j * width + 0], &tempP2, &vertex[(j + 1) * width + 0]); - - for(int i = 1; i < width; i++) - vertex[j * width + i].flatVector = - get_flatVector(&vertex[j * width + i], &vertex[(j + 1) * width + i - 1], &vertex[(j + 1) * width + i]); - } else - { - for(int i = 0; i < width - 1; i++) - vertex[j * width + i].flatVector = - get_flatVector(&vertex[j * width + i], &vertex[(j + 1) * width + i], &vertex[(j + 1) * width + i + 1]); - - // vector of last triangle - tempP3.x = vertex[(j + 1) * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = vertex[(j + 1) * width + 0].y; - tempP3.z = vertex[(j + 1) * width + 0].z; - vertex[j * width + width - 1].flatVector = - get_flatVector(&vertex[j * width + width - 1], &vertex[(j + 1) * width + width - 1], &tempP3); - } - } - // flat vectors of last line - for(int i = 0; i < width - 1; i++) - { - tempP2.x = vertex[0 * width + i].x; - tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i].y; - tempP2.z = vertex[0 * width + i].z; - tempP3.x = vertex[0 * width + i + 1].x; - tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i + 1].y; - tempP3.z = vertex[0 * width + i + 1].z; - vertex[(height - 1) * width + i].flatVector = get_flatVector(&vertex[(height - 1) * width + i], &tempP2, &tempP3); - } - // vector of last Triangle - tempP2.x = vertex[0 * width + width - 1].x; - tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + width - 1].y; - tempP2.z = vertex[0 * width + width - 1].z; - tempP3.x = vertex[0 * width + width - 1].x + TRIANGLE_WIDTH; - tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + 0].y; - tempP3.z = vertex[0 * width + 0].z; - vertex[(height - 1) * width + width - 1].flatVector = get_flatVector(&vertex[(height - 1) * width + width - 1], &tempP2, &tempP3); - - // now get the vector at each node and save it to vertex[j*width+i].normVector - // temporary index - int index, index2; - for(int j = 0; j < height; j++) - { - if(j % 2 == 0) - { - for(int i = 0; i < width; i++) - { - index = (i - 1 < 0 ? width - 1 : i - 1); - if(j == 0) // first line - vertex[j * width + i].normVector = - get_nodeVector(vertex[(height - 1) * width + index].flatVector, vertex[(height - 1) * width + i].flatVector, - vertex[j * width + i].flatVector); - else - vertex[j * width + i].normVector = get_nodeVector( - vertex[(j - 1) * width + index].flatVector, vertex[(j - 1) * width + i].flatVector, vertex[j * width + i].flatVector); - vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); - } - } else - { - for(int i = 0; i < width; i++) - { - if(i - 1 < 0) - index = width - 1; - else - index = i - 1; - - if(i + 1 >= width) - index2 = 0; - else - index2 = i + 1; - - vertex[j * width + i].normVector = get_nodeVector( - vertex[(j - 1) * width + i].flatVector, vertex[(j - 1) * width + index2].flatVector, vertex[j * width + i].flatVector); - vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); - } - } - } -} - -Sint32 CSurface::get_LightIntensity(vector node) -{ - // we calculate the light intensity right now - float I, Ip = 1.1f, kd = 1, light_const = 1.0f; - vector L = {-10, 5, 0.5f}; - L = get_normVector(L); - I = Ip * kd * (node.x * L.x + node.y * L.y + node.z * L.z) + light_const; - return (Sint32)(I * pow(2, 16)); -} - -vector CSurface::get_nodeVector(vector v1, vector v2, vector v3) -{ - vector node; - // dividing through 3 is not necessary cause normal vector would be the same - node.x = v1.x + v2.x + v3.x; - node.y = v1.y + v2.y + v3.y; - node.z = v1.z + v2.z + v3.z; - node = get_normVector(node); - return node; -} - -vector CSurface::get_normVector(vector v) -{ - vector normal; - float length = static_cast(sqrt(pow(v.x, 2) + pow(v.y, 2) + pow(v.z, 2))); - // in case vector length equals 0 (should not happen) - if(length == 0) - { - normal.x = 0; - normal.y = 0; - normal.z = 1; - } else - { - normal = v; - normal.x /= length; - normal.y /= length; - normal.z /= length; - } - - return normal; -} - -vector CSurface::get_flatVector(struct point* P1, struct point* P2, struct point* P3) -{ - // vector components - float vax, vay, vaz, vbx, vby, vbz; - // cross product - vector cross; - - vax = static_cast(P1->x - P2->x); - vay = static_cast(P1->y - P2->y); - vaz = static_cast(P1->z - P2->z); - vbx = static_cast(P3->x - P2->x); - vby = static_cast(P3->y - P2->y); - vbz = static_cast(P3->z - P2->z); - - cross.x = (vay * vbz - vaz * vby); - cross.y = (vaz * vbx - vax * vbz); - cross.z = (vax * vby - vay * vbx); - // normalize - cross = get_normVector(cross); - - return cross; -} - -void CSurface::update_shading(bobMAP* myMap, int VertexX, int VertexY) -{ - // vertex count for the points - int X, Y; - - bool even = false; - if(VertexY % 2 == 0) - even = true; - - update_flatVectors(myMap, VertexX, VertexY); - update_nodeVector(myMap, VertexX, VertexY); - - // now update all nodeVectors around VertexX and VertexY - // update first vertex left upside - X = VertexX - (even ? 1 : 0); - if(X < 0) - X += myMap->width; - Y = VertexY - 1; - if(Y < 0) - Y += myMap->height; - update_nodeVector(myMap, X, Y); - // update second vertex right upside - X = VertexX + (even ? 0 : 1); - if(X >= myMap->width) - X -= myMap->width; - Y = VertexY - 1; - if(Y < 0) - Y += myMap->height; - update_nodeVector(myMap, X, Y); - // update third point bottom left - X = VertexX - 1; - if(X < 0) - X += myMap->width; - Y = VertexY; - update_nodeVector(myMap, X, Y); - // update fourth point bottom right - X = VertexX + 1; - if(X >= myMap->width) - X -= myMap->width; - Y = VertexY; - update_nodeVector(myMap, X, Y); - // update fifth point down left - X = VertexX - (even ? 1 : 0); - if(X < 0) - X += myMap->width; - Y = VertexY + 1; - if(Y >= myMap->height) - Y -= myMap->height; - update_nodeVector(myMap, X, Y); - // update sixth point down right - X = VertexX + (even ? 0 : 1); - if(X >= myMap->width) - X -= myMap->width; - Y = VertexY + 1; - if(Y >= myMap->height) - Y -= myMap->height; - update_nodeVector(myMap, X, Y); -} - -void CSurface::update_flatVectors(bobMAP* myMap, int VertexX, int VertexY) -{ - // point structures for the triangles, Pmiddle is the point in the middle of the hexagon we will update - struct point *P1, *P2, *P3, *Pmiddle; - // vertex count for the points - int P1x, P1y, P2x, P2y, P3x, P3y; - - bool even = false; - if(VertexY % 2 == 0) - even = true; - - Pmiddle = &myMap->vertex[VertexY * myMap->width + VertexX]; - - // update first triangle left upside - P1x = VertexX - (even ? 1 : 0); - if(P1x < 0) - P1x += myMap->width; - P1y = VertexY - 1; - if(P1y < 0) - P1y += myMap->height; - P1 = &myMap->vertex[P1y * myMap->width + P1x]; - P2x = VertexX - 1; - if(P2x < 0) - P2x += myMap->width; - P2y = VertexY; - P2 = &myMap->vertex[P2y * myMap->width + P2x]; - P3 = Pmiddle; - P1->flatVector = get_flatVector(P1, P2, P3); - - // update second triangle right upside - P1x = VertexX + (even ? 0 : 1); - if(P1x >= myMap->width) - P1x -= myMap->width; - P1y = VertexY - 1; - if(P1y < 0) - P1y += myMap->height; - P1 = &myMap->vertex[P1y * myMap->width + P1x]; - P2 = Pmiddle; - P3x = VertexX + 1; - if(P3x >= myMap->width) - P3x -= myMap->width; - P3y = VertexY; - P3 = &myMap->vertex[P3y * myMap->width + P3x]; - P1->flatVector = get_flatVector(P1, P2, P3); - - // update third triangle down middle - P1 = Pmiddle; - P2x = VertexX - (even ? 1 : 0); - if(P2x < 0) - P2x += myMap->width; - P2y = VertexY + 1; - if(P2y >= myMap->height) - P2y -= myMap->height; - P2 = &myMap->vertex[P2y * myMap->width + P2x]; - P3x = VertexX + (even ? 0 : 1); - if(P3x >= myMap->width) - P3x -= myMap->width; - P3y = VertexY + 1; - if(P3y >= myMap->height) - P3y -= myMap->height; - P3 = &myMap->vertex[P3y * myMap->width + P3x]; - P1->flatVector = get_flatVector(P1, P2, P3); -} - -void CSurface::update_nodeVector(bobMAP* myMap, int VertexX, int VertexY) -{ - int j = VertexY; - int i = VertexX; - int width = myMap->width; - int height = myMap->height; - struct point* vertex = myMap->vertex; - - // temporary index - int index, index2; - - if(j % 2 == 0) - { - index = (i - 1 < 0 ? width - 1 : i - 1); - if(j == 0) // first line - vertex[j * width + i].normVector = - get_nodeVector(vertex[(height - 1) * width + index].flatVector, vertex[(height - 1) * width + i].flatVector, - vertex[j * width + i].flatVector); - else - vertex[j * width + i].normVector = get_nodeVector(vertex[(j - 1) * width + index].flatVector, - vertex[(j - 1) * width + i].flatVector, vertex[j * width + i].flatVector); - vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); - } else - { - if(i - 1 < 0) - index = width - 1; - else - index = i - 1; - - if(i + 1 >= width) - index2 = 0; - else - index2 = i + 1; - - vertex[j * width + i].normVector = get_nodeVector(vertex[(j - 1) * width + i].flatVector, - vertex[(j - 1) * width + index2].flatVector, vertex[j * width + i].flatVector); - vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); - } -} - -float CSurface::absf(float a) -{ - if(a >= 0) - return a; - else - return a * (-1); -} +#include "CSurface.h" +#include "CGame.h" +#include "CMap.h" +#include "globals.h" + +bool CSurface::drawTextures = false; +bool CSurface::useOpenGL = false; + +CSurface::CSurface() {} + +bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y) +{ + if(Surf_Dest == NULL || Surf_Src == NULL) + return false; + + SDL_Rect DestR; + + DestR.x = X; + DestR.y = Y; + + SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestR); + + return true; +} + +bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int angle) +{ + if(Surf_Dest == NULL || Surf_Src == NULL) + return false; + + Uint16 px, py; + + switch(angle) + { + case 90: + px = 0; + py = Surf_Src->h - 1; + break; + case 180: + px = Surf_Src->w - 1; + py = Surf_Src->h - 1; + break; + case 270: + px = Surf_Src->w - 1; + py = 0; + break; + default: return false; + } + + sge_transform(Surf_Src, Surf_Dest, (float)angle, 1.0, 1.0, px, py, X, Y, SGE_TSAFE); + + return true; +} + +bool CSurface::Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H) +{ + if(Surf_Dest == NULL || Surf_Src == NULL) + return false; + + SDL_Rect DestR; + + DestR.x = X; + DestR.y = Y; + + SDL_Rect SrcR; + + SrcR.x = X2; + SrcR.y = Y2; + SrcR.w = W; + SrcR.h = H; + + SDL_BlitSurface(Surf_Src, &SrcR, Surf_Dest, &DestR); + + return true; +} + +// this is the example function from the sdl-documentation to draw pixels +void CSurface::DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color) +{ + if(SDL_MUSTLOCK(screen)) + SDL_LockSurface(screen); + + switch(screen->format->BytesPerPixel) + { + case 1: + { + Uint8* bufp; + + bufp = (Uint8*)screen->pixels + y * screen->pitch + x; + *bufp = color; + } + break; + + case 2: + { + Uint16* bufp; + + bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; + *bufp = color; + } + break; + + case 3: + { + Uint8* bufp; + + bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; + if(SDL_BYTEORDER == SDL_LIL_ENDIAN) + { + bufp[0] = color; + bufp[1] = color >> 8; + bufp[2] = color >> 16; + } else + { + bufp[2] = color; + bufp[1] = color >> 8; + bufp[0] = color >> 16; + } + } + break; + + case 4: + { + Uint32* bufp; + + bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; + *bufp = color; + } + break; + } + + if(SDL_MUSTLOCK(screen)) + SDL_UnlockSurface(screen); +} + +// this is the example function from the sdl-documentation to draw pixels +void CSurface::DrawPixel_RGB(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) +{ + if(SDL_MUSTLOCK(screen)) + SDL_LockSurface(screen); + + Uint32 color = SDL_MapRGB(screen->format, R, G, B); + + switch(screen->format->BytesPerPixel) + { + case 1: + { + Uint8* bufp; + + bufp = (Uint8*)screen->pixels + y * screen->pitch + x; + *bufp = color; + } + break; + + case 2: + { + Uint16* bufp; + + bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; + *bufp = color; + } + break; + + case 3: + { + Uint8* bufp; + + bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; + if(SDL_BYTEORDER == SDL_LIL_ENDIAN) + { + bufp[0] = color; + bufp[1] = color >> 8; + bufp[2] = color >> 16; + } else + { + bufp[2] = color; + bufp[1] = color >> 8; + bufp[0] = color >> 16; + } + } + break; + + case 4: + { + Uint32* bufp; + + bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; + *bufp = color; + } + break; + } + + if(SDL_MUSTLOCK(screen)) + SDL_UnlockSurface(screen); +} + +void CSurface::DrawPixel_RGBA(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A) +{ + if(SDL_MUSTLOCK(screen)) + SDL_LockSurface(screen); + + Uint32 color = SDL_MapRGBA(screen->format, R, G, B, A); + + switch(screen->format->BytesPerPixel) + { + case 1: + { + Uint8* bufp; + + bufp = (Uint8*)screen->pixels + y * screen->pitch + x; + *bufp = color; + } + break; + + case 2: + { + Uint16* bufp; + + bufp = (Uint16*)screen->pixels + y * screen->pitch / 2 + x; + *bufp = color; + } + break; + + case 3: + { + Uint8* bufp; + + bufp = (Uint8*)screen->pixels + y * screen->pitch + x * 3; + if(SDL_BYTEORDER == SDL_LIL_ENDIAN) + { + bufp[0] = color; + bufp[1] = color >> 8; + bufp[2] = color >> 16; + } else + { + bufp[2] = color; + bufp[1] = color >> 8; + bufp[0] = color >> 16; + } + } + break; + + case 4: + { + Uint32* bufp; + + bufp = (Uint32*)screen->pixels + y * screen->pitch / 4 + x; + *bufp = color; + } + break; + } + + if(SDL_MUSTLOCK(screen)) + SDL_UnlockSurface(screen); +} + +Uint32 CSurface::GetPixel(SDL_Surface* surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to retrieve */ + Uint8* p = (Uint8*)surface->pixels + y * surface->pitch + x * bpp; + switch(bpp) + { + case 1: return *p; + + case 2: return *(Uint16*)p; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + + case 4: return *(Uint32*)p; + + default: + return 0; /* shouldn't happen, but avoids warnings */ + } +} + +void CSurface::DrawTriangleField(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap) +{ + Uint16 width = myMap->width; + Uint16 height = myMap->height; + Uint8 type = myMap->type; + struct point* vertex = myMap->vertex; + point tempP1, tempP2, tempP3; + + int row_start; + int row_end; + int col_start; + int col_end; + bool view_outside_edges; + + // draw triangle field + // NOTE: WE DO THIS TWICE, AT FIRST ONLY TRIANGLE-TEXTURES, AT SECOND THE TEXTURE-BORDERS AND OBJECTS + for(int i = 0; i < 2; i++) + { + if(i == 0) + drawTextures = true; + else /*if (i == 1)*/ + drawTextures = false; + + for(int k = 0; k < 4; k++) + { + // beware calling DrawTriangle for each triangle + + // IMPORTANT: integer values like +8 or -1 are for tolerance to beware of high triangles are not shown + + // at first call DrawTriangle for all triangles inside the map edges + row_start = (displayRect.y > 2 * TRIANGLE_HEIGHT ? displayRect.y : 2 * TRIANGLE_HEIGHT) / TRIANGLE_HEIGHT - 2; + row_end = (displayRect.y + displayRect.h) / TRIANGLE_HEIGHT + 8; + col_start = (displayRect.x > TRIANGLE_WIDTH ? displayRect.x : TRIANGLE_WIDTH) / TRIANGLE_WIDTH - 1; + col_end = (displayRect.x + displayRect.w) / TRIANGLE_WIDTH + 1; + + if(k > 0) + { + // now call DrawTriangle for all triangles outside the map edges + view_outside_edges = false; + + if(k == 1 || k == 3) + { + // at first call DrawTriangle for all triangles up or down outside + if(displayRect.y < 0) + { + row_start = height - 1 - (-displayRect.y / TRIANGLE_HEIGHT) - 1; + row_end = height - 1; + view_outside_edges = true; + } + + else if((displayRect.y + displayRect.h) > myMap->height_pixel) + { + row_start = 0; + row_end = ((displayRect.y + displayRect.h) - myMap->height_pixel) / TRIANGLE_HEIGHT + 8; + view_outside_edges = true; + } else if(displayRect.y <= 2 * TRIANGLE_HEIGHT) + { + // this is for draw triangles that are reduced under the lower map edge (have bigger y-coords as + // myMap->height_pixel) + row_start = height - 3; + row_end = height - 1; + view_outside_edges = true; + } else if((displayRect.y + displayRect.h) >= (myMap->height_pixel - 8 * TRIANGLE_HEIGHT)) + { + // this is for draw triangles that are raised over the upper map edge (have negative y-coords) + row_start = 0; + row_end = 8; + view_outside_edges = true; + } + } + + if(k == 2 || k == 3) + { + // now call DrawTriangle for all triangles left or right outside + if(displayRect.x <= 0) + { + col_start = width - 1 - (-displayRect.x / TRIANGLE_WIDTH) - 1; + col_end = width - 1; + view_outside_edges = true; + } else if(displayRect.x > 0 && displayRect.x < TRIANGLE_WIDTH) + { + col_start = width - 2; + col_end = width - 1; + view_outside_edges = true; + } else if((displayRect.x + displayRect.w) > myMap->width_pixel) + { + col_start = 0; + col_end = ((displayRect.x + displayRect.w) - myMap->width_pixel) / TRIANGLE_WIDTH + 1; + view_outside_edges = true; + } + } + + // if displayRect is not outside the map edges, there is nothing to do + if(!view_outside_edges) + continue; + } + + for(int j = /*0*/ row_start; j < height - 1 && j <= row_end; j++) + { + if(j % 2 == 0) + { + // first RightSideUp + tempP2.x = 0; + tempP2.y = vertex[(j + 1) * width + width - 1].y; + tempP2.z = vertex[(j + 1) * width + width - 1].z; + tempP2.i = vertex[(j + 1) * width + width - 1].i; + DrawTriangle(display, displayRect, myMap, type, vertex[j * width + 0], tempP2, vertex[(j + 1) * width + 0]); + for(int i = /*1*/ (col_start > 0 ? col_start : 1); i < width && i <= col_end; i++) + { + // RightSideUp + DrawTriangle(display, displayRect, myMap, type, vertex[j * width + i], vertex[(j + 1) * width + i - 1], + vertex[(j + 1) * width + i]); + // UpSideDown + if(i < width) + DrawTriangle(display, displayRect, myMap, type, vertex[(j + 1) * width + i - 1], vertex[j * width + i - 1], + vertex[j * width + i]); + } + // last UpSideDown + tempP3.x = vertex[j * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = vertex[j * width + 0].y; + tempP3.z = vertex[j * width + 0].z; + tempP3.i = vertex[j * width + 0].i; + DrawTriangle(display, displayRect, myMap, type, vertex[(j + 1) * width + width - 1], vertex[j * width + width - 1], + tempP3); + } else + { + for(int i = /*0*/ col_start; i < width - 1 && i <= col_end; i++) + { + // RightSideUp + DrawTriangle(display, displayRect, myMap, type, vertex[j * width + i], vertex[(j + 1) * width + i], + vertex[(j + 1) * width + i + 1]); + // UpSideDown + DrawTriangle(display, displayRect, myMap, type, vertex[(j + 1) * width + i + 1], vertex[j * width + i], + vertex[j * width + i + 1]); + } + // last RightSideUp + tempP3.x = vertex[(j + 1) * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = vertex[(j + 1) * width + 0].y; + tempP3.z = vertex[(j + 1) * width + 0].z; + tempP3.i = vertex[(j + 1) * width + 0].i; + DrawTriangle(display, displayRect, myMap, type, vertex[j * width + width - 1], vertex[(j + 1) * width + width - 1], + tempP3); + // last UpSideDown + tempP1.x = vertex[(j + 1) * width + width - 1].x + TRIANGLE_WIDTH; + tempP1.y = vertex[(j + 1) * width + 0].y; + tempP1.z = vertex[(j + 1) * width + 0].z; + tempP1.i = vertex[(j + 1) * width + 0].i; + tempP3.x = vertex[j * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = vertex[j * width + 0].y; + tempP3.z = vertex[j * width + 0].z; + tempP3.i = vertex[j * width + 0].i; + DrawTriangle(display, displayRect, myMap, type, tempP1, vertex[j * width + width - 1], tempP3); + } + } + + // draw last line + for(int i = /*0*/ col_start; i < width - 1 && i <= col_end; i++) + { + // RightSideUp + tempP2.x = vertex[0 * width + i].x; + tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i].y; + tempP2.z = vertex[0 * width + i].z; + tempP2.i = vertex[0 * width + i].i; + tempP3.x = vertex[0 * width + i + 1].x; + tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i + 1].y; + tempP3.z = vertex[0 * width + i + 1].z; + tempP3.i = vertex[0 * width + i + 1].i; + DrawTriangle(display, displayRect, myMap, type, vertex[(height - 1) * width + i], tempP2, tempP3); + // UpSideDown + tempP1.x = vertex[0 * width + i + 1].x; + tempP1.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i + 1].y; + tempP1.z = vertex[0 * width + i + 1].z; + tempP1.i = vertex[0 * width + i + 1].i; + DrawTriangle(display, displayRect, myMap, type, tempP1, vertex[(height - 1) * width + i], + vertex[(height - 1) * width + i + 1]); + } + } + + // last RightSideUp + tempP2.x = vertex[0 * width + width - 1].x; + tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + width - 1].y; + tempP2.z = vertex[0 * width + width - 1].z; + tempP2.i = vertex[0 * width + width - 1].i; + tempP3.x = vertex[0 * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + 0].y; + tempP3.z = vertex[0 * width + 0].z; + tempP3.i = vertex[0 * width + 0].i; + DrawTriangle(display, displayRect, myMap, type, vertex[(height - 1) * width + width - 1], tempP2, tempP3); + // last UpSideDown + tempP1.x = vertex[0 * width + width - 1].x + TRIANGLE_WIDTH; + tempP1.y = height * TRIANGLE_HEIGHT + vertex[0 * width + 0].y; + tempP1.z = vertex[0 * width + 0].z; + tempP1.i = vertex[0 * width + 0].i; + tempP3.x = vertex[(height - 1) * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = vertex[(height - 1) * width + 0].y; + tempP3.z = vertex[(height - 1) * width + 0].z; + tempP3.i = vertex[(height - 1) * width + 0].i; + DrawTriangle(display, displayRect, myMap, type, tempP1, vertex[(height - 1) * width + width - 1], tempP3); + } +} + +void CSurface::DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap, Uint8 type, point P1, point P2, point P3) +{ + // prevent drawing triangles that are not shown + if(((P1.x < displayRect.x && P2.x < displayRect.x && P3.x < displayRect.x) + || (P1.x > (displayRect.x + displayRect.w) && P2.x > (displayRect.x + displayRect.w) && P3.x > (displayRect.x + displayRect.w))) + || ((P1.y < displayRect.y && P2.y < displayRect.y && P3.y < displayRect.y) + || (P1.y > (displayRect.y + displayRect.h) && P2.y > (displayRect.y + displayRect.h) && P3.y > (displayRect.y + displayRect.h)))) + { + bool triangle_shown = false; + + if(displayRect.x <= 0) + { + int outside_x = displayRect.x; + int outside_w = -displayRect.x; + if((((P1.x - myMap->width_pixel) >= (outside_x)) && ((P1.x - myMap->width_pixel) <= (outside_x + outside_w))) + || (((P2.x - myMap->width_pixel) >= (outside_x)) && ((P2.x - myMap->width_pixel) <= (outside_x + outside_w))) + || (((P3.x - myMap->width_pixel) >= (outside_x)) && ((P3.x - myMap->width_pixel) <= (outside_x + outside_w)))) + { + P1.x -= myMap->width_pixel; + P2.x -= myMap->width_pixel; + P3.x -= myMap->width_pixel; + triangle_shown = true; + } + } else if(displayRect.x > 0 && displayRect.x < TRIANGLE_WIDTH) + { + int outside_x = displayRect.x; + int outside_w = TRIANGLE_WIDTH; + if((((P1.x - myMap->width_pixel) >= (outside_x)) && ((P1.x - myMap->width_pixel) <= (outside_x + outside_w))) + || (((P2.x - myMap->width_pixel) >= (outside_x)) && ((P2.x - myMap->width_pixel) <= (outside_x + outside_w))) + || (((P3.x - myMap->width_pixel) >= (outside_x)) && ((P3.x - myMap->width_pixel) <= (outside_x + outside_w)))) + { + P1.x -= myMap->width_pixel; + P2.x -= myMap->width_pixel; + P3.x -= myMap->width_pixel; + triangle_shown = true; + } + } else if((displayRect.x + displayRect.w) > (myMap->width_pixel)) + { + int outside_x = myMap->width_pixel; + int outside_w = displayRect.x + displayRect.w - myMap->width_pixel; + if((((P1.x + myMap->width_pixel) >= (outside_x)) && ((P1.x + myMap->width_pixel) <= (outside_x + outside_w))) + || (((P2.x + myMap->width_pixel) >= (outside_x)) && ((P2.x + myMap->width_pixel) <= (outside_x + outside_w))) + || (((P3.x + myMap->width_pixel) >= (outside_x)) && ((P3.x + myMap->width_pixel) <= (outside_x + outside_w)))) + { + P1.x += myMap->width_pixel; + P2.x += myMap->width_pixel; + P3.x += myMap->width_pixel; + triangle_shown = true; + } + } + + if(displayRect.y < 0) + { + int outside_y = displayRect.y; + int outside_h = -displayRect.y; + if((((P1.y - myMap->height_pixel) >= (outside_y)) && ((P1.y - myMap->height_pixel) <= (outside_y + outside_h))) + || (((P2.y - myMap->height_pixel) >= (outside_y)) && ((P2.y - myMap->height_pixel) <= (outside_y + outside_h))) + || (((P3.y - myMap->height_pixel) >= (outside_y)) && ((P3.y - myMap->height_pixel) <= (outside_y + outside_h)))) + { + P1.y -= myMap->height_pixel; + P2.y -= myMap->height_pixel; + P3.y -= myMap->height_pixel; + triangle_shown = true; + } + } else if((displayRect.y + displayRect.h) > (myMap->height_pixel)) + { + int outside_y = myMap->height_pixel; + int outside_h = displayRect.y + displayRect.h - myMap->height_pixel; + if((((P1.y + myMap->height_pixel) >= (outside_y)) && ((P1.y + myMap->height_pixel) <= (outside_y + outside_h))) + || (((P2.y + myMap->height_pixel) >= (outside_y)) && ((P2.y + myMap->height_pixel) <= (outside_y + outside_h))) + || (((P3.y + myMap->height_pixel) >= (outside_y)) && ((P3.y + myMap->height_pixel) <= (outside_y + outside_h)))) + { + P1.y += myMap->height_pixel; + P2.y += myMap->height_pixel; + P3.y += myMap->height_pixel; + triangle_shown = true; + } + } + + // now test if triangle has negative y-coords cause it's raised over the upper map edge + if(P1.y < 0 || P2.y < 0 || P3.y < 0) + { + if((((P1.y + myMap->height_pixel) >= displayRect.y) && ((P1.y + myMap->height_pixel) <= (displayRect.y + displayRect.h))) + || (((P2.y + myMap->height_pixel) >= displayRect.y) && ((P2.y + myMap->height_pixel) <= (displayRect.y + displayRect.h))) + || (((P3.y + myMap->height_pixel) >= displayRect.y) && ((P3.y + myMap->height_pixel) <= (displayRect.y + displayRect.h)))) + { + P1.y += myMap->height_pixel; + P2.y += myMap->height_pixel; + P3.y += myMap->height_pixel; + triangle_shown = true; + } + } + + // now test if triangle has bigger y-coords as myMap->height_pixel cause it's reduced under the lower map edge + if(P1.y > myMap->height_pixel || P2.y > myMap->height_pixel || P3.y > myMap->height_pixel) + { + if((((P1.y - myMap->height_pixel) >= displayRect.y) && ((P1.y - myMap->height_pixel) <= (displayRect.y + displayRect.h))) + || (((P2.y - myMap->height_pixel) >= displayRect.y) && ((P2.y - myMap->height_pixel) <= (displayRect.y + displayRect.h))) + || (((P3.y - myMap->height_pixel) >= displayRect.y) && ((P3.y - myMap->height_pixel) <= (displayRect.y + displayRect.h)))) + { + P1.y -= myMap->height_pixel; + P2.y -= myMap->height_pixel; + P3.y -= myMap->height_pixel; + triangle_shown = true; + } + } + + if(!triangle_shown) + return; + } + + // 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; + + // for moving water, lava, objects and so on + // This is very tricky: there are ice floes in the winterland and the water under this floes is moving. + // I don't know how this works in original settlers 2 but i solved it this way: + // i texture the triangle with normal water and then draw the floe over it. To Extract the floe + // from it's surrounded water, i use this color keys below. These are the color values for the water texture. + // I wrote a special SGE-Function that uses these color keys and ignores them in the Surf_Tileset. + static Uint32 colorkeys[5] = {14191, 14195, 13167, 13159, 11119}; + static int keycount = 5; + static int texture_move = 0; + static int roundCount = 0; + static Uint32 roundTimeObjects = SDL_GetTicks(); + static Uint32 roundTimeTextures = SDL_GetTicks(); + if(SDL_GetTicks() - roundTimeObjects > 30) + { + roundTimeObjects = SDL_GetTicks(); + if(roundCount >= 7) + roundCount = 0; + else + roundCount++; + } + if(SDL_GetTicks() - roundTimeTextures > 170) + { + roundTimeTextures = SDL_GetTicks(); + texture_move++; + if(texture_move > 14) + texture_move = 0; + } + + switch(type) + { + case MAP_GREENLAND: + Surf_Tileset = + global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_GREENLAND_8BPP : TILESET_GREENLAND_32BPP].surface; + break; + case MAP_WASTELAND: + Surf_Tileset = + global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_WASTELAND_8BPP : TILESET_WASTELAND_32BPP].surface; + break; + case MAP_WINTERLAND: + Surf_Tileset = + global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_WINTERLAND_8BPP : TILESET_WINTERLAND_32BPP] + .surface; + break; + default: + Surf_Tileset = + global::bmpArray[global::s2->getMapObj()->getBitsPerPixel() == 8 ? TILESET_GREENLAND_8BPP : TILESET_GREENLAND_32BPP].surface; + break; + } + + if(P1.y < P2.y) + texture = P1.rsuTexture; + else + texture = P2.usdTexture; + texture_raw = texture; + if(texture_raw >= 0x40) + // it's a harbour + texture_raw -= 0x40; + + Point16 shiftedP1, shiftedP2, shiftedP3; + shiftedP1.x = static_cast(P1.x - displayRect.x); + shiftedP1.y = static_cast(P1.y - displayRect.y); + shiftedP2.x = static_cast(P2.x - displayRect.x); + shiftedP2.y = static_cast(P2.y - displayRect.y); + shiftedP3.x = static_cast(P3.x - displayRect.x); + shiftedP3.y = static_cast(P3.y - displayRect.y); + + if(drawTextures) + { + switch(texture_raw) + { + // in case of USD-Triangle "upperX" and "upperY" means "lowerX" and "lowerY" + case TRIANGLE_TEXTURE_STEPPE_MEADOW1: + upperX = 17; + upperY = 96; + leftX = 0; + leftY = 126; + rightX = 35; + rightY = 126; + break; + case TRIANGLE_TEXTURE_MINING1: + upperX = 17; + upperY = 48; + leftX = 0; + leftY = 78; + rightX = 35; + rightY = 78; + break; + case TRIANGLE_TEXTURE_SNOW: + if(P1.y < P2.y) + { + upperX = 17; + upperY = 0; + leftX = 0; + leftY = 30; + rightX = 35; + rightY = 30; + } else + { + upperX = 17; + upperY = 28; + leftX = 0; + leftY = 0; + rightX = 37; + rightY = 0; + } + if(type == MAP_WINTERLAND) + { + if(P1.y < P2.y) + { + upperX2 = 231 - texture_move; + upperY2 = 61 + texture_move; + leftX2 = 207 - texture_move; + leftY2 = 62 + texture_move; + rightX2 = 223 - texture_move; + rightY2 = 78 + texture_move; + } else + { + upperX2 = 224 - texture_move; + upperY2 = 79 + texture_move; + leftX2 = 232 - texture_move; + leftY2 = 62 + texture_move; + rightX2 = 245 - texture_move; + rightY2 = 76 + texture_move; + } + } + break; + case TRIANGLE_TEXTURE_SWAMP: + upperX = 113; + upperY = 0; + leftX = 96; + leftY = 30; + rightX = 131; + rightY = 30; + if(type == MAP_WINTERLAND) + { + if(P1.y < P2.y) + { + upperX2 = 231 - texture_move; + upperY2 = 61 + texture_move; + leftX2 = 207 - texture_move; + leftY2 = 62 + texture_move; + rightX2 = 223 - texture_move; + rightY2 = 78 + texture_move; + } else + { + upperX2 = 224 - texture_move; + upperY2 = 79 + texture_move; + leftX2 = 232 - texture_move; + leftY2 = 62 + texture_move; + rightX2 = 245 - texture_move; + rightY2 = 76 + texture_move; + } + } + break; + case TRIANGLE_TEXTURE_STEPPE: + upperX = 65; + upperY = 0; + leftX = 48; + leftY = 30; + rightX = 83; + rightY = 30; + break; + case TRIANGLE_TEXTURE_STEPPE_: + upperX = 65; + upperY = 0; + leftX = 48; + leftY = 30; + rightX = 83; + rightY = 30; + break; + case TRIANGLE_TEXTURE_STEPPE__: + upperX = 65; + upperY = 0; + leftX = 48; + leftY = 30; + rightX = 83; + rightY = 30; + break; + case TRIANGLE_TEXTURE_STEPPE___: + upperX = 65; + upperY = 0; + leftX = 48; + leftY = 30; + rightX = 83; + rightY = 30; + break; + case TRIANGLE_TEXTURE_WATER: + if(P1.y < P2.y) + { + upperX = 231 - texture_move; + upperY = 61 + texture_move; + leftX = 207 - texture_move; + leftY = 62 + texture_move; + rightX = 223 - texture_move; + rightY = 78 + texture_move; + } else + { + upperX = 224 - texture_move; + upperY = 79 + texture_move; + leftX = 232 - texture_move; + leftY = 62 + texture_move; + rightX = 245 - texture_move; + rightY = 76 + texture_move; + } + case TRIANGLE_TEXTURE_WATER_: + if(P1.y < P2.y) + { + upperX = 231 - texture_move; + upperY = 61 + texture_move; + leftX = 207 - texture_move; + leftY = 62 + texture_move; + rightX = 223 - texture_move; + rightY = 78 + texture_move; + } else + { + upperX = 224 - texture_move; + upperY = 79 + texture_move; + leftX = 232 - texture_move; + leftY = 62 + texture_move; + rightX = 245 - texture_move; + rightY = 76 + texture_move; + } + break; + case TRIANGLE_TEXTURE_WATER__: + if(P1.y < P2.y) + { + upperX = 231 - texture_move; + upperY = 61 + texture_move; + leftX = 207 - texture_move; + leftY = 62 + texture_move; + rightX = 223 - texture_move; + rightY = 78 + texture_move; + } else + { + upperX = 224 - texture_move; + upperY = 79 + texture_move; + leftX = 232 - texture_move; + leftY = 62 + texture_move; + rightX = 245 - texture_move; + rightY = 76 + texture_move; + } + break; + case TRIANGLE_TEXTURE_MEADOW1: + upperX = 65; + upperY = 96; + leftX = 48; + leftY = 126; + rightX = 83; + rightY = 126; + break; + case TRIANGLE_TEXTURE_MEADOW2: + upperX = 113; + upperY = 96; + leftX = 96; + leftY = 126; + rightX = 131; + rightY = 126; + break; + case TRIANGLE_TEXTURE_MEADOW3: + upperX = 161; + upperY = 96; + leftX = 144; + leftY = 126; + rightX = 179; + rightY = 126; + break; + case TRIANGLE_TEXTURE_MINING2: + upperX = 65; + upperY = 48; + leftX = 48; + leftY = 78; + rightX = 83; + rightY = 78; + break; + case TRIANGLE_TEXTURE_MINING3: + upperX = 113; + upperY = 48; + leftX = 96; + leftY = 78; + rightX = 131; + rightY = 78; + break; + case TRIANGLE_TEXTURE_MINING4: + upperX = 161; + upperY = 48; + leftX = 144; + leftY = 78; + rightX = 179; + rightY = 78; + break; + case TRIANGLE_TEXTURE_STEPPE_MEADOW2: + upperX = 17; + upperY = 144; + leftX = 0; + leftY = 174; + rightX = 35; + rightY = 174; + break; + case TRIANGLE_TEXTURE_FLOWER: + upperX = 161; + upperY = 0; + leftX = 144; + leftY = 30; + rightX = 179; + rightY = 30; + break; + case TRIANGLE_TEXTURE_LAVA: + if(P1.y < P2.y) + { + upperX = 231 - texture_move; + upperY = 117 + texture_move; + leftX = 207 - texture_move; + leftY = 118 + texture_move; + rightX = 223 - texture_move; + rightY = 134 + texture_move; + } else + { + upperX = 224 - texture_move; + upperY = 135 + texture_move; + leftX = 232 - texture_move; + leftY = 118 + texture_move; + rightX = 245 - texture_move; + rightY = 132 + texture_move; + } + break; + case TRIANGLE_TEXTURE_MINING_MEADOW: + upperX = 65; + upperY = 144; + leftX = 48; + leftY = 174; + rightX = 83; + rightY = 174; + break; + default: // TRIANGLE_TEXTURE_FLOWER + upperX = 161; + upperY = 0; + leftX = 144; + leftY = 30; + rightX = 179; + rightY = 30; + break; + } + + // draw the triangle + // do not shade water and lava + if(texture == TRIANGLE_TEXTURE_WATER || texture == TRIANGLE_TEXTURE_LAVA) + sge_TexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, Surf_Tileset, upperX, + upperY, leftX, leftY, rightX, rightY); + else + { + // draw special winterland textures with moving water (ice floe textures) + if(type == MAP_WINTERLAND && (texture == TRIANGLE_TEXTURE_SNOW || texture == TRIANGLE_TEXTURE_SWAMP)) + { + sge_TexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, Surf_Tileset, + upperX2, upperY2, leftX2, leftY2, rightX2, rightY2); + if(global::s2->getMapObj()->getBitsPerPixel() == 8) + sge_PreCalcFadedTexturedTrigonColorKeys( + display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, Surf_Tileset, upperX, upperY, + leftX, leftY, rightX, rightY, P1.shading << 8, P2.shading << 8, P3.shading << 8, gouData[type], colorkeys, keycount); + else + sge_FadedTexturedTrigonColorKeys(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, + Surf_Tileset, upperX, upperY, leftX, leftY, rightX, rightY, P1.i, P2.i, P3.i, + colorkeys, keycount); + } else + { + if(global::s2->getMapObj()->getBitsPerPixel() == 8) + sge_PreCalcFadedTexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, + Surf_Tileset, upperX, upperY, leftX, leftY, rightX, rightY, P1.shading << 8, + P2.shading << 8, P3.shading << 8, gouData[type]); + else + sge_FadedTexturedTrigon(display, shiftedP1.x, shiftedP1.y, shiftedP2.x, shiftedP2.y, shiftedP3.x, shiftedP3.y, + Surf_Tileset, upperX, upperY, leftX, leftY, rightX, rightY, P1.i, P2.i, P3.i); + } + } + return; + } + + // blit borders + /// 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; + point 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 + Uint16 col = (P1.VertexX - 1 < 0 ? myMap->width - 1 : P1.VertexX - 1); + tempP = myMap->vertex[P1.VertexY * myMap->width + col]; + + // 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)))) + { + Border1 = false; + Border2 = false; + + 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); + } + } + } + // 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)))) + { + Border1 = false; + Border2 = false; + + // 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; + } + + 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); + } + } + + // decide which border to blit (top/bottom) - therefore get the rsu-texture one line above to compare + Uint16 row = (P2.VertexY - 1 < 0 ? myMap->height - 1 : P2.VertexY - 1); + Uint16 col = (P2.VertexY % 2 == 0 ? P2.VertexX : (P2.VertexX + 1 > myMap->width - 1 ? 0 : P2.VertexX + 1)); + tempP = myMap->vertex[row * myMap->width + col]; + + // 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)))) + { + 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); + } + } + } + + // blit picture to vertex (trees, animals, buildings and so on) --> BUT ONLY AT P1 ON RIGHTSIDEUP-TRIANGLES + + // blit objects + if(P2.y < P1.y) + { + int objIdx = 0; + switch(P2.objectInfo) + { + // tree + case 0xC4: + if(P2.objectType >= 0x30 && P2.objectType <= 0x37) + { + if(P2.objectType + roundCount > 0x37) + objIdx = MAPPIC_TREE_PINE + (P2.objectType - 0x30) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_PINE + (P2.objectType - 0x30) + roundCount; + + } else if(P2.objectType >= 0x70 && P2.objectType <= 0x77) + { + if(P2.objectType + roundCount > 0x77) + objIdx = MAPPIC_TREE_BIRCH + (P2.objectType - 0x70) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_BIRCH + (P2.objectType - 0x70) + roundCount; + } else if(P2.objectType >= 0xB0 && P2.objectType <= 0xB7) + { + if(P2.objectType + roundCount > 0xB7) + objIdx = MAPPIC_TREE_OAK + (P2.objectType - 0xB0) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_OAK + (P2.objectType - 0xB0) + roundCount; + } else if(P2.objectType >= 0xF0 && P2.objectType <= 0xF7) + { + if(P2.objectType + roundCount > 0xF7) + objIdx = MAPPIC_TREE_PALM1 + (P2.objectType - 0xF0) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_PALM1 + (P2.objectType - 0xF0) + roundCount; + } + break; + // tree + case 0xC5: + if(P2.objectType >= 0x30 && P2.objectType <= 0x37) + { + if(P2.objectType + roundCount > 0x37) + objIdx = MAPPIC_TREE_PALM2 + (P2.objectType - 0x30) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_PALM2 + (P2.objectType - 0x30) + roundCount; + + } else if(P2.objectType >= 0x70 && P2.objectType <= 0x77) + { + if(P2.objectType + roundCount > 0x77) + objIdx = MAPPIC_TREE_PINEAPPLE + (P2.objectType - 0x70) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_PINEAPPLE + (P2.objectType - 0x70) + roundCount; + } else if(P2.objectType >= 0xB0 && P2.objectType <= 0xB7) + { + if(P2.objectType + roundCount > 0xB7) + objIdx = MAPPIC_TREE_CYPRESS + (P2.objectType - 0xB0) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_CYPRESS + (P2.objectType - 0xB0) + roundCount; + } else if(P2.objectType >= 0xF0 && P2.objectType <= 0xF7) + { + if(P2.objectType + roundCount > 0xF7) + objIdx = MAPPIC_TREE_CHERRY + (P2.objectType - 0xF0) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_CHERRY + (P2.objectType - 0xF0) + roundCount; + } + break; + // tree + case 0xC6: + if(P2.objectType >= 0x30 && P2.objectType <= 0x37) + { + if(P2.objectType + roundCount > 0x37) + objIdx = MAPPIC_TREE_FIR + (P2.objectType - 0x30) + (roundCount - 7); + else + objIdx = MAPPIC_TREE_FIR + (P2.objectType - 0x30) + roundCount; + } + break; + // landscape + case 0xC8: + switch(P2.objectType) + { + case 0x00: objIdx = MAPPIC_MUSHROOM1; break; + case 0x01: objIdx = MAPPIC_MUSHROOM2; break; + case 0x02: objIdx = MAPPIC_STONE1; break; + case 0x03: objIdx = MAPPIC_STONE2; break; + case 0x04: objIdx = MAPPIC_STONE3; break; + case 0x05: objIdx = MAPPIC_TREE_TRUNK_DEAD; break; + case 0x06: objIdx = MAPPIC_TREE_DEAD; break; + case 0x07: objIdx = MAPPIC_BONE1; break; + case 0x08: objIdx = MAPPIC_BONE2; break; + case 0x09: objIdx = MAPPIC_FLOWERS; break; + case 0x10: objIdx = MAPPIC_BUSH2; break; + case 0x11: objIdx = MAPPIC_BUSH3; break; + case 0x12: objIdx = MAPPIC_BUSH4; break; + + case 0x0A: objIdx = MAPPIC_BUSH1; break; + + case 0x0C: objIdx = MAPPIC_CACTUS1; break; + case 0x0D: objIdx = MAPPIC_CACTUS2; break; + case 0x0E: objIdx = MAPPIC_SHRUB1; break; + case 0x0F: objIdx = MAPPIC_SHRUB2; break; + + case 0x13: objIdx = MAPPIC_SHRUB3; break; + case 0x14: objIdx = MAPPIC_SHRUB4; break; + + case 0x16: objIdx = MAPPIC_DOOR; break; + + case 0x18: objIdx = MIS1BOBS_STONE1; break; + case 0x19: objIdx = MIS1BOBS_STONE2; break; + case 0x1A: objIdx = MIS1BOBS_STONE3; break; + case 0x1B: objIdx = MIS1BOBS_STONE4; break; + case 0x1C: objIdx = MIS1BOBS_STONE5; break; + case 0x1D: objIdx = MIS1BOBS_STONE6; break; + case 0x1E: objIdx = MIS1BOBS_STONE7; break; + + case 0x22: objIdx = MAPPIC_MUSHROOM3; break; + + case 0x25: objIdx = MAPPIC_PEBBLE1; break; + case 0x26: objIdx = MAPPIC_PEBBLE2; break; + case 0x27: objIdx = MAPPIC_PEBBLE3; break; + default: break; + } + break; + // stone + case 0xCC: + objIdx = MAPPIC_GRANITE_1_1 + (P2.objectType - 0x01); + break; + // stone + case 0xCD: + objIdx = MAPPIC_GRANITE_2_1 + (P2.objectType - 0x01); + break; + // headquarter + case 0x80: // P2.objectType is the number of the player beginning with 0x00 +//%7 cause in the original game there are only 7 players and 7 different flags +#ifdef _EDITORMODE + objIdx = FLAG_BLUE_DARK + P2.objectType % 7; +#endif + break; + + default: break; + } + if(objIdx != 0) + Draw(display, global::bmpArray[objIdx].surface, (int)(P2.x - displayRect.x - global::bmpArray[objIdx].nx), + (int)(P2.y - displayRect.y - global::bmpArray[objIdx].ny)); + } + +#ifdef _EDITORMODE + // blit resources + if(P2.y < P1.y) + { + if(P2.resource >= 0x41 && P2.resource <= 0x47) + { + for(char i = 0x41; i <= P2.resource; i++) + Draw(display, global::bmpArray[PICTURE_RESOURCE_COAL].surface, + (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_COAL].nx), + (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_COAL].ny - (4 * (i - 0x40)))); + } else if(P2.resource >= 0x49 && P2.resource <= 0x4F) + { + for(char i = 0x49; i <= P2.resource; i++) + Draw(display, global::bmpArray[PICTURE_RESOURCE_ORE].surface, + (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_ORE].nx), + (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_ORE].ny - (4 * (i - 0x48)))); + } + if(P2.resource >= 0x51 && P2.resource <= 0x57) + { + for(char i = 0x51; i <= P2.resource; i++) + Draw(display, global::bmpArray[PICTURE_RESOURCE_GOLD].surface, + (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_GOLD].nx), + (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_GOLD].ny - (4 * (i - 0x50)))); + } + if(P2.resource >= 0x59 && P2.resource <= 0x5F) + { + for(char i = 0x59; i <= P2.resource; i++) + Draw(display, global::bmpArray[PICTURE_RESOURCE_GRANITE].surface, + (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_RESOURCE_GRANITE].nx), + (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_RESOURCE_GRANITE].ny - (4 * (i - 0x58)))); + } + } + // blit animals + if(P2.y < P1.y) + { + if(P2.animal > 0x00 && P2.animal <= 0x06) + { + Draw(display, global::bmpArray[PICTURE_SMALL_BEAR + P2.animal].surface, + (int)(P2.x - displayRect.x - global::bmpArray[PICTURE_SMALL_BEAR + P2.animal].nx), + (int)(P2.y - displayRect.y - global::bmpArray[PICTURE_SMALL_BEAR + P2.animal].ny)); + } + } +#endif + + // blit buildings + if(global::s2->getMapObj()->getRenderBuildHelp()) + { + if(P2.y < P1.y) + { + switch(P2.build % 8) + { + case 0x01: + Draw(display, global::bmpArray[MAPPIC_FLAG].surface, (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_FLAG].nx), + (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_FLAG].ny)); + break; + case 0x02: + Draw(display, global::bmpArray[MAPPIC_HOUSE_SMALL].surface, + (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_SMALL].nx), + (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_SMALL].ny)); + break; + case 0x03: + Draw(display, global::bmpArray[MAPPIC_HOUSE_MIDDLE].surface, + (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_MIDDLE].nx), + (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_MIDDLE].ny)); + break; + case 0x04: + if(P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW2_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || P2.rsuTexture == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR || P2.rsuTexture == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || P2.rsuTexture == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR) + Draw(display, global::bmpArray[MAPPIC_HOUSE_HARBOUR].surface, + (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_HARBOUR].nx), + (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_HARBOUR].ny)); + else + Draw(display, global::bmpArray[MAPPIC_HOUSE_BIG].surface, + (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_HOUSE_BIG].nx), + (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_HOUSE_BIG].ny)); + break; + case 0x05: + Draw(display, global::bmpArray[MAPPIC_MINE].surface, (int)(P2.x - displayRect.x - global::bmpArray[MAPPIC_MINE].nx), + (int)(P2.y - displayRect.y - global::bmpArray[MAPPIC_MINE].ny)); + break; + default: break; + } + } + } +} + +void CSurface::get_nodeVectors(bobMAP* myMap) +{ + // prepare triangle field + int height = myMap->height; + int width = myMap->width; + struct point* vertex = myMap->vertex; + struct point /*tempP1,*/ tempP2, tempP3; + + // get flat vectors + for(int j = 0; j < height - 1; j++) + { + if(j % 2 == 0) + { + // vector of first triangle + tempP2.x = 0; + tempP2.y = vertex[(j + 1) * width + width - 1].y; + tempP2.z = vertex[(j + 1) * width + width - 1].z; + vertex[j * width + 0].flatVector = get_flatVector(&vertex[j * width + 0], &tempP2, &vertex[(j + 1) * width + 0]); + + for(int i = 1; i < width; i++) + vertex[j * width + i].flatVector = + get_flatVector(&vertex[j * width + i], &vertex[(j + 1) * width + i - 1], &vertex[(j + 1) * width + i]); + } else + { + for(int i = 0; i < width - 1; i++) + vertex[j * width + i].flatVector = + get_flatVector(&vertex[j * width + i], &vertex[(j + 1) * width + i], &vertex[(j + 1) * width + i + 1]); + + // vector of last triangle + tempP3.x = vertex[(j + 1) * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = vertex[(j + 1) * width + 0].y; + tempP3.z = vertex[(j + 1) * width + 0].z; + vertex[j * width + width - 1].flatVector = + get_flatVector(&vertex[j * width + width - 1], &vertex[(j + 1) * width + width - 1], &tempP3); + } + } + // flat vectors of last line + for(int i = 0; i < width - 1; i++) + { + tempP2.x = vertex[0 * width + i].x; + tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i].y; + tempP2.z = vertex[0 * width + i].z; + tempP3.x = vertex[0 * width + i + 1].x; + tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + i + 1].y; + tempP3.z = vertex[0 * width + i + 1].z; + vertex[(height - 1) * width + i].flatVector = get_flatVector(&vertex[(height - 1) * width + i], &tempP2, &tempP3); + } + // vector of last Triangle + tempP2.x = vertex[0 * width + width - 1].x; + tempP2.y = height * TRIANGLE_HEIGHT + vertex[0 * width + width - 1].y; + tempP2.z = vertex[0 * width + width - 1].z; + tempP3.x = vertex[0 * width + width - 1].x + TRIANGLE_WIDTH; + tempP3.y = height * TRIANGLE_HEIGHT + vertex[0 * width + 0].y; + tempP3.z = vertex[0 * width + 0].z; + vertex[(height - 1) * width + width - 1].flatVector = get_flatVector(&vertex[(height - 1) * width + width - 1], &tempP2, &tempP3); + + // now get the vector at each node and save it to vertex[j*width+i].normVector + // temporary index + int index, index2; + for(int j = 0; j < height; j++) + { + if(j % 2 == 0) + { + for(int i = 0; i < width; i++) + { + index = (i - 1 < 0 ? width - 1 : i - 1); + if(j == 0) // first line + vertex[j * width + i].normVector = + get_nodeVector(vertex[(height - 1) * width + index].flatVector, vertex[(height - 1) * width + i].flatVector, + vertex[j * width + i].flatVector); + else + vertex[j * width + i].normVector = get_nodeVector( + vertex[(j - 1) * width + index].flatVector, vertex[(j - 1) * width + i].flatVector, vertex[j * width + i].flatVector); + vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); + } + } else + { + for(int i = 0; i < width; i++) + { + if(i - 1 < 0) + index = width - 1; + else + index = i - 1; + + if(i + 1 >= width) + index2 = 0; + else + index2 = i + 1; + + vertex[j * width + i].normVector = get_nodeVector( + vertex[(j - 1) * width + i].flatVector, vertex[(j - 1) * width + index2].flatVector, vertex[j * width + i].flatVector); + vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); + } + } + } +} + +Sint32 CSurface::get_LightIntensity(vector node) +{ + // we calculate the light intensity right now + float I, Ip = 1.1f, kd = 1, light_const = 1.0f; + vector L = {-10, 5, 0.5f}; + L = get_normVector(L); + I = Ip * kd * (node.x * L.x + node.y * L.y + node.z * L.z) + light_const; + return (Sint32)(I * pow(2, 16)); +} + +vector CSurface::get_nodeVector(vector v1, vector v2, vector v3) +{ + vector node; + // dividing through 3 is not necessary cause normal vector would be the same + node.x = v1.x + v2.x + v3.x; + node.y = v1.y + v2.y + v3.y; + node.z = v1.z + v2.z + v3.z; + node = get_normVector(node); + return node; +} + +vector CSurface::get_normVector(vector v) +{ + vector normal; + float length = static_cast(sqrt(pow(v.x, 2) + pow(v.y, 2) + pow(v.z, 2))); + // in case vector length equals 0 (should not happen) + if(length == 0) + { + normal.x = 0; + normal.y = 0; + normal.z = 1; + } else + { + normal = v; + normal.x /= length; + normal.y /= length; + normal.z /= length; + } + + return normal; +} + +vector CSurface::get_flatVector(struct point* P1, struct point* P2, struct point* P3) +{ + // vector components + float vax, vay, vaz, vbx, vby, vbz; + // cross product + vector cross; + + vax = static_cast(P1->x - P2->x); + vay = static_cast(P1->y - P2->y); + vaz = static_cast(P1->z - P2->z); + vbx = static_cast(P3->x - P2->x); + vby = static_cast(P3->y - P2->y); + vbz = static_cast(P3->z - P2->z); + + cross.x = (vay * vbz - vaz * vby); + cross.y = (vaz * vbx - vax * vbz); + cross.z = (vax * vby - vay * vbx); + // normalize + cross = get_normVector(cross); + + return cross; +} + +void CSurface::update_shading(bobMAP* myMap, int VertexX, int VertexY) +{ + // vertex count for the points + int X, Y; + + bool even = false; + if(VertexY % 2 == 0) + even = true; + + update_flatVectors(myMap, VertexX, VertexY); + update_nodeVector(myMap, VertexX, VertexY); + + // now update all nodeVectors around VertexX and VertexY + // update first vertex left upside + X = VertexX - (even ? 1 : 0); + if(X < 0) + X += myMap->width; + Y = VertexY - 1; + if(Y < 0) + Y += myMap->height; + update_nodeVector(myMap, X, Y); + // update second vertex right upside + X = VertexX + (even ? 0 : 1); + if(X >= myMap->width) + X -= myMap->width; + Y = VertexY - 1; + if(Y < 0) + Y += myMap->height; + update_nodeVector(myMap, X, Y); + // update third point bottom left + X = VertexX - 1; + if(X < 0) + X += myMap->width; + Y = VertexY; + update_nodeVector(myMap, X, Y); + // update fourth point bottom right + X = VertexX + 1; + if(X >= myMap->width) + X -= myMap->width; + Y = VertexY; + update_nodeVector(myMap, X, Y); + // update fifth point down left + X = VertexX - (even ? 1 : 0); + if(X < 0) + X += myMap->width; + Y = VertexY + 1; + if(Y >= myMap->height) + Y -= myMap->height; + update_nodeVector(myMap, X, Y); + // update sixth point down right + X = VertexX + (even ? 0 : 1); + if(X >= myMap->width) + X -= myMap->width; + Y = VertexY + 1; + if(Y >= myMap->height) + Y -= myMap->height; + update_nodeVector(myMap, X, Y); +} + +void CSurface::update_flatVectors(bobMAP* myMap, int VertexX, int VertexY) +{ + // point structures for the triangles, Pmiddle is the point in the middle of the hexagon we will update + struct point *P1, *P2, *P3, *Pmiddle; + // vertex count for the points + int P1x, P1y, P2x, P2y, P3x, P3y; + + bool even = false; + if(VertexY % 2 == 0) + even = true; + + Pmiddle = &myMap->vertex[VertexY * myMap->width + VertexX]; + + // update first triangle left upside + P1x = VertexX - (even ? 1 : 0); + if(P1x < 0) + P1x += myMap->width; + P1y = VertexY - 1; + if(P1y < 0) + P1y += myMap->height; + P1 = &myMap->vertex[P1y * myMap->width + P1x]; + P2x = VertexX - 1; + if(P2x < 0) + P2x += myMap->width; + P2y = VertexY; + P2 = &myMap->vertex[P2y * myMap->width + P2x]; + P3 = Pmiddle; + P1->flatVector = get_flatVector(P1, P2, P3); + + // update second triangle right upside + P1x = VertexX + (even ? 0 : 1); + if(P1x >= myMap->width) + P1x -= myMap->width; + P1y = VertexY - 1; + if(P1y < 0) + P1y += myMap->height; + P1 = &myMap->vertex[P1y * myMap->width + P1x]; + P2 = Pmiddle; + P3x = VertexX + 1; + if(P3x >= myMap->width) + P3x -= myMap->width; + P3y = VertexY; + P3 = &myMap->vertex[P3y * myMap->width + P3x]; + P1->flatVector = get_flatVector(P1, P2, P3); + + // update third triangle down middle + P1 = Pmiddle; + P2x = VertexX - (even ? 1 : 0); + if(P2x < 0) + P2x += myMap->width; + P2y = VertexY + 1; + if(P2y >= myMap->height) + P2y -= myMap->height; + P2 = &myMap->vertex[P2y * myMap->width + P2x]; + P3x = VertexX + (even ? 0 : 1); + if(P3x >= myMap->width) + P3x -= myMap->width; + P3y = VertexY + 1; + if(P3y >= myMap->height) + P3y -= myMap->height; + P3 = &myMap->vertex[P3y * myMap->width + P3x]; + P1->flatVector = get_flatVector(P1, P2, P3); +} + +void CSurface::update_nodeVector(bobMAP* myMap, int VertexX, int VertexY) +{ + int j = VertexY; + int i = VertexX; + int width = myMap->width; + int height = myMap->height; + struct point* vertex = myMap->vertex; + + // temporary index + int index, index2; + + if(j % 2 == 0) + { + index = (i - 1 < 0 ? width - 1 : i - 1); + if(j == 0) // first line + vertex[j * width + i].normVector = + get_nodeVector(vertex[(height - 1) * width + index].flatVector, vertex[(height - 1) * width + i].flatVector, + vertex[j * width + i].flatVector); + else + vertex[j * width + i].normVector = get_nodeVector(vertex[(j - 1) * width + index].flatVector, + vertex[(j - 1) * width + i].flatVector, vertex[j * width + i].flatVector); + vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); + } else + { + if(i - 1 < 0) + index = width - 1; + else + index = i - 1; + + if(i + 1 >= width) + index2 = 0; + else + index2 = i + 1; + + vertex[j * width + i].normVector = get_nodeVector(vertex[(j - 1) * width + i].flatVector, + vertex[(j - 1) * width + index2].flatVector, vertex[j * width + i].flatVector); + vertex[j * width + i].i = get_LightIntensity(vertex[j * width + i].normVector); + } +} + +float CSurface::absf(float a) +{ + if(a >= 0) + return a; + else + return a * (-1); +} diff --git a/CSurface.h b/CSurface.h index 801fac7..b869d8a 100644 --- a/CSurface.h +++ b/CSurface.h @@ -1,44 +1,44 @@ -#ifndef _CSURFACE_H -#define _CSURFACE_H - -#include "includes.h" - -class CSurface -{ - friend class CDebug; - -public: - CSurface(); - // blits from source on destination to position X,Y - static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y); - // blits from source on destination to position X,Y and rotates (angle --> degrees --> 90, 180, 270) - static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int angle); - // blits rectangle (X2,Y2,W,H) from source on destination to position X,Y - static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H); - static void DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color); - static void DrawPixel_RGB(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B); - static void DrawPixel_RGBA(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A); - static Uint32 GetPixel(SDL_Surface* surface, int x, int y); - static void DrawTriangleField(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap); - static void DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap, Uint8 type, point P1, point P2, point P3); - static void get_nodeVectors(bobMAP* myMap); - static void update_shading(bobMAP* myMap, int VertexX, int VertexY); - - static bool useOpenGL; - -private: - // to decide what to draw, triangle-textures or objects and texture-borders - static bool drawTextures; - - static vector get_nodeVector(vector v1, vector v2, vector v3); - static vector get_normVector(vector v); - static vector get_flatVector(struct point* P1, struct point* P2, struct point* P3); - static Sint32 get_LightIntensity(vector node); - static float absf(float a); - // update flatVectors around a vertex - static void update_flatVectors(bobMAP* myMap, int VertexX, int VertexY); - // update nodeVector based on new flatVectors around it - static void update_nodeVector(bobMAP* myMap, int VertexX, int VertexY); -}; - -#endif +#ifndef _CSURFACE_H +#define _CSURFACE_H + +#include "includes.h" + +class CSurface +{ + friend class CDebug; + +public: + CSurface(); + // blits from source on destination to position X,Y + static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y); + // blits from source on destination to position X,Y and rotates (angle --> degrees --> 90, 180, 270) + static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int angle); + // blits rectangle (X2,Y2,W,H) from source on destination to position X,Y + static bool Draw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H); + static void DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color); + static void DrawPixel_RGB(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B); + static void DrawPixel_RGBA(SDL_Surface* screen, int x, int y, Uint8 R, Uint8 G, Uint8 B, Uint8 A); + static Uint32 GetPixel(SDL_Surface* surface, int x, int y); + static void DrawTriangleField(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap); + static void DrawTriangle(SDL_Surface* display, DisplayRectangle displayRect, bobMAP* myMap, Uint8 type, point P1, point P2, point P3); + static void get_nodeVectors(bobMAP* myMap); + static void update_shading(bobMAP* myMap, int VertexX, int VertexY); + + static bool useOpenGL; + +private: + // to decide what to draw, triangle-textures or objects and texture-borders + static bool drawTextures; + + static vector get_nodeVector(vector v1, vector v2, vector v3); + static vector get_normVector(vector v); + static vector get_flatVector(struct point* P1, struct point* P2, struct point* P3); + static Sint32 get_LightIntensity(vector node); + static float absf(float a); + // update flatVectors around a vertex + static void update_flatVectors(bobMAP* myMap, int VertexX, int VertexY); + // update nodeVector based on new flatVectors around it + static void update_nodeVector(bobMAP* myMap, int VertexX, int VertexY); +}; + +#endif diff --git a/callbacks.cpp b/callbacks.cpp index d7c868d..8a4ec89 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -1,3572 +1,3572 @@ -#include "callbacks.h" -#include "CDebug.h" -#include "CGame.h" -#include "CIO/CButton.h" -#include "CIO/CFile.h" -#include "CIO/CFont.h" -#include "CIO/CMenu.h" -#include "CIO/CPicture.h" -#include "CIO/CSelectBox.h" -#include "CIO/CTextfield.h" -#include "CIO/CWindow.h" -#include "CMap.h" -#include "CSurface.h" -#include "globals.h" - -void callback::PleaseWait(int Param) -{ - // NOTE: This "Please wait"-window is shown until the PleaseWait-callback is called with 'WINDOW_QUIT_MESSAGE'. - // The window will be registered by the game. To do it the other way (create and then let it automatically - // destroy by the gameloop), you don't need to register the window, but register the callback. - - static CWindow* WNDWait; - - enum - { - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDWait != NULL) - break; - WNDWait = new CWindow(PleaseWait, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 106, - global::s2->getDisplaySurface()->h / 2 - 35, 212, 70, "Please wait"); - if(global::s2->RegisterWindow(WNDWait)) - { - // we don't register this window cause we will destroy it manually if we need - // global::s2->RegisterCallback(PleaseWait); - - WNDWait->addText("Please wait ...", 10, 10, 14); - // we need to render this window NOW, cause the render loop will do it too late (when the operation - // is done and we don't need the "Please wait"-window anymore) - CSurface::Draw(global::s2->getDisplaySurface(), WNDWait->getSurface(), global::s2->getDisplaySurface()->w / 2 - 106, - global::s2->getDisplaySurface()->h / 2 - 35); - SDL_Flip(global::s2->getDisplaySurface()); - } else - { - delete WNDWait; - WNDWait = NULL; - return; - } - break; - - case CALL_FROM_GAMELOOP: // This window gives a "Please Wait"-string, so it is shown while there is an intensive operation - // during ONE gameloop. Therefore it is only shown DURING this ONE operation. If the next gameloop - // appears, the operation MUST have been finished and we can destroy this window. - if(WNDWait != NULL) - { - global::s2->UnregisterCallback(PleaseWait); - WNDWait->setWaste(); - WNDWait = NULL; - } - break; - - case WINDOW_QUIT_MESSAGE: // this is the global window quit message, callback is explicit called with this value, so destroy the - // window - if(WNDWait != NULL) - { - WNDWait->setWaste(); - WNDWait = NULL; - } - break; - - default: break; - } -} - -void callback::ShowStatus(int Param) -{ - static CWindow* WND = NULL; - static CFont* txt = NULL; - - enum - { - WINDOWQUIT, - SHOW_SUCCESS, - SHOW_FAILURE - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WND != NULL) - break; - WND = - new CWindow(ShowStatus, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 106, global::s2->getDisplaySurface()->h / 2 - 35, - 250, 90, "Status", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WND)) - { - txt = WND->addText("", 26, 20, 14, FONT_YELLOW); - } else - { - delete WND; - WND = NULL; - return; - } - break; - case SHOW_SUCCESS: - txt->setText("Operation finished successfully"); - txt->setColor(FONT_GREEN); - break; - case SHOW_FAILURE: - txt->setText("Operation failed! :("); - txt->setColor(FONT_RED_BRIGHT); - break; - - case WINDOWQUIT: - case MAP_QUIT: - if(WND != NULL) - { - WND->setWaste(); - WND = NULL; - } - break; - - default: break; - } -} - -void callback::mainmenu(int Param) -{ - static CMenu* MainMenu = NULL; - - enum - { - ENDGAME = 1, - STARTEDITOR, - OPTIONS - }; - - switch(Param) - { - case INITIALIZING_CALL: - MainMenu = new CMenu(SPLASHSCREEN_MAINMENU); - if(!global::s2->RegisterMenu(MainMenu)) - { - delete MainMenu; - MainMenu = NULL; - return; - } - MainMenu->addButton(mainmenu, ENDGAME, 50, 400, 200, 20, BUTTON_RED1, "Quit program"); -#ifdef _ADMINMODE - MainMenu->addButton(submenu1, INITIALIZING_CALL, 50, 200, 200, 20, BUTTON_GREY, "Submenu_1"); -#endif - MainMenu->addButton(mainmenu, STARTEDITOR, 50, 160, 200, 20, BUTTON_RED1, "Start editor"); - MainMenu->addButton(mainmenu, OPTIONS, 50, 370, 200, 20, BUTTON_GREEN2, "Options"); - break; - - case CALL_FROM_GAMELOOP: break; - - case ENDGAME: - MainMenu->setWaste(); - MainMenu = NULL; - global::s2->Running = false; - break; - - case STARTEDITOR: - PleaseWait(INITIALIZING_CALL); - global::s2->setMapObj(new CMap("")); - MainMenu->setWaste(); - MainMenu = NULL; - PleaseWait(WINDOW_QUIT_MESSAGE); - break; - - case OPTIONS: - MainMenu->setWaste(); - MainMenu = NULL; - submenuOptions(INITIALIZING_CALL); - - default: break; - } -} - -void callback::submenuOptions(int Param) -{ - static CMenu* SubMenu = NULL; - static CFont* TextResolution = NULL; - static CButton* ButtonFullscreen = NULL; - static CButton* ButtonOpenGL = NULL; - char puffer[80]; - static CSelectBox* SelectBoxRes = NULL; - - enum - { - MAINMENU = 1, - FULLSCREEN, - OPENGL, - GRAPHICS_CHANGE, - SELECTBOX_800_600, - SELECTBOX_832_624, - SELECTBOX_960_540, - SELECTBOX_964_544, - SELECTBOX_960_640, - SELECTBOX_960_720, - SELECTBOX_1024_576, - SELECTBOX_1024_600, - SELECTBOX_1072_600, - SELECTBOX_1152_768, - SELECTBOX_1024_768, - SELECTBOX_1152_864, - SELECTBOX_1152_870, - SELECTBOX_1152_900, - SELECTBOX_1200_800, - SELECTBOX_1200_900, - SELECTBOX_1280_720, - SELECTBOX_1280_768, - SELECTBOX_1280_800, - SELECTBOX_1280_854, - SELECTBOX_1360_768, - SELECTBOX_1366_768, - SELECTBOX_1376_768, - SELECTBOX_1400_900, - SELECTBOX_1440_900, - SELECTBOX_1440_960, - SELECTBOX_1280_960, - SELECTBOX_1280_1024, - SELECTBOX_1360_1024, - SELECTBOX_1366_1024, - SELECTBOX_1600_768, - SELECTBOX_1600_900, - SELECTBOX_1600_1024, - SELECTBOX_1400_1050, - SELECTBOX_1680_1050, - SELECTBOX_1600_1200, - SELECTBOX_1920_1080, - SELECTBOX_1920_1200, - SELECTBOX_1920_1400, - SELECTBOX_1920_1440, - SELECTBOX_2048_1152, - SELECTBOX_2048_1536 - }; - - switch(Param) - { - case INITIALIZING_CALL: - SubMenu = new CMenu(SPLASHSCREEN_SUBMENU3); - if(!global::s2->RegisterMenu(SubMenu)) - { - delete SubMenu; - TextResolution = NULL; - ButtonFullscreen = NULL; - SelectBoxRes = NULL; - SubMenu = NULL; - return; - } - // add button for "back to main menu" - SubMenu->addButton(submenuOptions, MAINMENU, (int)(global::s2->GameResolutionX / 2 - 100), 440, 200, 20, BUTTON_RED1, "back"); - // add menu title - SubMenu->addText("Options", (int)(global::s2->GameResolutionX / 2 - 20), 10, 14); - // add screen resolution - if(TextResolution != NULL) - SubMenu->delText(TextResolution); - sprintf(puffer, "Game Resolution: %d*%d / %s", global::s2->GameResolutionX, global::s2->GameResolutionY, - (global::s2->fullscreen ? "Fullscreen" : "Window")); - TextResolution = SubMenu->addText(puffer, (int)(global::s2->GameResolutionX / 2 - 110), 50, 11); - if(ButtonFullscreen != NULL) - SubMenu->delButton(ButtonFullscreen); - ButtonFullscreen = SubMenu->addButton(submenuOptions, FULLSCREEN, (int)(global::s2->GameResolutionX / 2 - 100), 190, 200, 20, - BUTTON_RED1, (global::s2->fullscreen ? "WINDOW" : "FULLSCREEN")); - if(ButtonOpenGL != NULL) - SubMenu->delButton(ButtonOpenGL); - // ButtonOpenGL = SubMenu->addButton(submenuOptions, OPENGL, (int)(global::s2->GameResolutionX/2-100), 210, 200, 20, - // BUTTON_RED1, (CSurface::useOpenGL ? "Software-Rendering" : "OpenGL")); add selectbox for resolutions - SelectBoxRes = SubMenu->addSelectBox((int)(global::s2->GameResolutionX / 2 - 100), 70, 200, 110, 11, FONT_YELLOW, BUTTON_GREY); - SelectBoxRes->setOption("800 x 600 (SVGA)", submenuOptions, SELECTBOX_800_600); - SelectBoxRes->setOption("832 x 624 (Half Megapixel)", submenuOptions, SELECTBOX_832_624); - SelectBoxRes->setOption("960 x 540 (QHD)", submenuOptions, SELECTBOX_960_540); - SelectBoxRes->setOption("964 x 544", submenuOptions, SELECTBOX_964_544); - SelectBoxRes->setOption("960 x 640 (DVGA)", submenuOptions, SELECTBOX_960_640); - SelectBoxRes->setOption("960 x 720", submenuOptions, SELECTBOX_960_720); - SelectBoxRes->setOption("1024 x 576 (WXGA)", submenuOptions, SELECTBOX_1024_576); - SelectBoxRes->setOption("1024 x 600 (WSVGA)", submenuOptions, SELECTBOX_1024_600); - SelectBoxRes->setOption("1072 x 600 (WSVGA)", submenuOptions, SELECTBOX_1072_600); - SelectBoxRes->setOption("1152 x 768", submenuOptions, SELECTBOX_1152_768); - SelectBoxRes->setOption("1024 x 768 (EVGA)", submenuOptions, SELECTBOX_1024_768); - SelectBoxRes->setOption("1152 x 864 (XGA)", submenuOptions, SELECTBOX_1152_864); - SelectBoxRes->setOption("1152 x 870 (XGA)", submenuOptions, SELECTBOX_1152_870); - SelectBoxRes->setOption("1152 x 900 (XGA)", submenuOptions, SELECTBOX_1152_900); - SelectBoxRes->setOption("1200 x 800 (DSVGA)", submenuOptions, SELECTBOX_1200_800); - SelectBoxRes->setOption("1200 x 900 (OLPC)", submenuOptions, SELECTBOX_1200_900); - SelectBoxRes->setOption("1280 x 720 (720p)", submenuOptions, SELECTBOX_1280_720); - SelectBoxRes->setOption("1280 x 768 (WXGA)", submenuOptions, SELECTBOX_1280_768); - SelectBoxRes->setOption("1280 x 800 (WXGA)", submenuOptions, SELECTBOX_1280_800); - SelectBoxRes->setOption("1280 x 854 (WXGA)", submenuOptions, SELECTBOX_1280_854); - SelectBoxRes->setOption("1360 x 768 (WXGA)", submenuOptions, SELECTBOX_1360_768); - SelectBoxRes->setOption("1366 x 768 (WXGA)", submenuOptions, SELECTBOX_1366_768); - SelectBoxRes->setOption("1376 x 768 (WXGA)", submenuOptions, SELECTBOX_1376_768); - SelectBoxRes->setOption("1400 x 900 (WXGA+)", submenuOptions, SELECTBOX_1400_900); - SelectBoxRes->setOption("1440 x 900 (WXGA+)", submenuOptions, SELECTBOX_1440_900); - SelectBoxRes->setOption("1440 x 960", submenuOptions, SELECTBOX_1440_960); - SelectBoxRes->setOption("1280 x 960 (SXGA)", submenuOptions, SELECTBOX_1280_960); - SelectBoxRes->setOption("1280 x 1024 (SXGA)", submenuOptions, SELECTBOX_1280_1024); - SelectBoxRes->setOption("1360 x 1024 (XGA-2)", submenuOptions, SELECTBOX_1360_1024); - SelectBoxRes->setOption("1366 x 1024 (XGA-2)", submenuOptions, SELECTBOX_1366_1024); - SelectBoxRes->setOption("1600 x 768 (UWXGA)", submenuOptions, SELECTBOX_1600_768); - SelectBoxRes->setOption("1600 x 900 (WSXGA)", submenuOptions, SELECTBOX_1600_900); - SelectBoxRes->setOption("1600 x 1024 (WSXGA)", submenuOptions, SELECTBOX_1600_1024); - SelectBoxRes->setOption("1400 x 1050 (SXGA+)", submenuOptions, SELECTBOX_1400_1050); - SelectBoxRes->setOption("1680 x 1050 (WSXGA+)", submenuOptions, SELECTBOX_1680_1050); - SelectBoxRes->setOption("1600 x 1200 (UXGA)", submenuOptions, SELECTBOX_1600_1200); - SelectBoxRes->setOption("1920 x 1080 (1080p)", submenuOptions, SELECTBOX_1920_1080); - SelectBoxRes->setOption("1920 x 1200 (WUXGA)", submenuOptions, SELECTBOX_1920_1200); - SelectBoxRes->setOption("1920 x 1400 (TXGA)", submenuOptions, SELECTBOX_1920_1400); - SelectBoxRes->setOption("1920 x 1440", submenuOptions, SELECTBOX_1920_1440); - SelectBoxRes->setOption("2048 x 1152 (QWXGA)", submenuOptions, SELECTBOX_2048_1152); - SelectBoxRes->setOption("2048 x 1536 (SUXGA)", submenuOptions, SELECTBOX_2048_1536); - break; - - case MAINMENU: - SubMenu->setWaste(); - TextResolution = NULL; - ButtonFullscreen = NULL; - ButtonOpenGL = NULL; - SelectBoxRes = NULL; - SubMenu = NULL; - mainmenu(INITIALIZING_CALL); - break; - - case FULLSCREEN: - if(global::s2->fullscreen) - global::s2->fullscreen = false; - else - global::s2->fullscreen = true; - - submenuOptions(GRAPHICS_CHANGE); - break; - - case OPENGL: - if(CSurface::useOpenGL) - CSurface::useOpenGL = false; - else - CSurface::useOpenGL = true; - - submenuOptions(GRAPHICS_CHANGE); - break; - - case GRAPHICS_CHANGE: - SubMenu->setWaste(); - TextResolution = NULL; - ButtonFullscreen = NULL; - ButtonOpenGL = NULL; - SelectBoxRes = NULL; - SubMenu = NULL; - submenuOptions(INITIALIZING_CALL); - break; - - case SELECTBOX_800_600: - global::s2->GameResolutionX = 800; - global::s2->GameResolutionY = 600; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_832_624: - global::s2->GameResolutionX = 832; - global::s2->GameResolutionY = 624; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_960_540: - global::s2->GameResolutionX = 960; - global::s2->GameResolutionY = 540; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_964_544: - global::s2->GameResolutionX = 964; - global::s2->GameResolutionY = 544; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_960_640: - global::s2->GameResolutionX = 960; - global::s2->GameResolutionY = 640; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_960_720: - global::s2->GameResolutionX = 960; - global::s2->GameResolutionY = 720; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1024_576: - global::s2->GameResolutionX = 1024; - global::s2->GameResolutionY = 576; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1024_600: - global::s2->GameResolutionX = 1024; - global::s2->GameResolutionY = 600; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1072_600: - global::s2->GameResolutionX = 1072; - global::s2->GameResolutionY = 600; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1152_768: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1024_768: - global::s2->GameResolutionX = 1024; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1152_864: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 864; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1152_870: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 870; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1152_900: - global::s2->GameResolutionX = 1152; - global::s2->GameResolutionY = 900; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1200_800: - global::s2->GameResolutionX = 1200; - global::s2->GameResolutionY = 800; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1200_900: - global::s2->GameResolutionX = 1200; - global::s2->GameResolutionY = 900; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1280_720: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 720; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1280_768: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1280_800: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 800; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1280_854: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 854; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1360_768: - global::s2->GameResolutionX = 1360; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1366_768: - global::s2->GameResolutionX = 1366; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1376_768: - global::s2->GameResolutionX = 1376; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1400_900: - global::s2->GameResolutionX = 1400; - global::s2->GameResolutionY = 900; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1440_900: - global::s2->GameResolutionX = 1440; - global::s2->GameResolutionY = 900; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1440_960: - global::s2->GameResolutionX = 1440; - global::s2->GameResolutionY = 960; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1280_960: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 960; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1280_1024: - global::s2->GameResolutionX = 1280; - global::s2->GameResolutionY = 1024; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1360_1024: - global::s2->GameResolutionX = 1360; - global::s2->GameResolutionY = 1024; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1366_1024: - global::s2->GameResolutionX = 1366; - global::s2->GameResolutionY = 1024; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1600_768: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 768; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1600_900: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 900; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1600_1024: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 1024; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1400_1050: - global::s2->GameResolutionX = 1400; - global::s2->GameResolutionY = 1050; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1680_1050: - global::s2->GameResolutionX = 1680; - global::s2->GameResolutionY = 1050; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1600_1200: - global::s2->GameResolutionX = 1600; - global::s2->GameResolutionY = 1200; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1920_1080: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1080; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1920_1200: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1200; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1920_1400: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1400; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_1920_1440: - global::s2->GameResolutionX = 1920; - global::s2->GameResolutionY = 1440; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_2048_1152: - global::s2->GameResolutionX = 2048; - global::s2->GameResolutionY = 1152; - submenuOptions(GRAPHICS_CHANGE); - break; - - case SELECTBOX_2048_1536: - global::s2->GameResolutionX = 2048; - global::s2->GameResolutionY = 1536; - submenuOptions(GRAPHICS_CHANGE); - break; - - default: break; - } -} - -#ifdef _EDITORMODE -// now the editor callbacks will follow (editor mode) - -void callback::EditorHelpMenu(int Param) -{ - // NOTE: This "Please wait"-window is shown until the PleaseWait-callback is called with 'WINDOW_QUIT_MESSAGE'. - // The window will be registered by the game. To do it the other way (create and then let it automatically - // destroy by the gameloop), you don't need to register the window, but register the callback. - - static CWindow* WNDHelp; - static CSelectBox* SelectBoxHelp; - - enum - { - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDHelp != NULL) - break; - WNDHelp = new CWindow(EditorHelpMenu, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 320, - global::s2->getDisplaySurface()->h / 2 - 240, 640, 380, "Hilfe", WINDOW_GREEN2, - WINDOW_CLOSE | WINDOW_MOVE | WINDOW_RESIZE | WINDOW_MINIMIZE); - if(global::s2->RegisterWindow(WNDHelp)) - { - // we don't register this window cause we will destroy it manually if we need - // global::s2->RegisterCallback(PleaseWait); - - SelectBoxHelp = WNDHelp->addSelectBox(0, 20, 635, 345, 11, FONT_YELLOW, BUTTON_GREEN1); - SelectBoxHelp->setOption( - "Help-Menu......................................................................................................F1\n"); - SelectBoxHelp->setOption( - "Window/Fullscreen........................................................................................F2\n"); - SelectBoxHelp->setOption("Zoom in/normal/out " - "(experimental)..............................................................F5/F6/" - "F7\n"); - SelectBoxHelp->setOption("Scroll..........................................................................................." - "..................Arrow keys\n"); - SelectBoxHelp->setOption( - "Cursor size 1-9 (of 11)....................................................................................1-9\n"); - SelectBoxHelp->setOption( - "Make Cursor bigger/smaller........................................................................+/-\n"); - SelectBoxHelp->setOption( - "Scissors-Mode...............................................................................................Ctrl\n"); - SelectBoxHelp->setOption( - "Invert mode....................................................................................................Shift\n"); - SelectBoxHelp->setOption("(e.g. Lower altitude, remove player, lower resources)\n"); - SelectBoxHelp->setOption( - "Plane mode.....................................................................................................Alt\n"); - SelectBoxHelp->setOption( - "Reduce/default/enlarge maximum height.....................................................Ins/Pos1/" - "PageUp\n"); - SelectBoxHelp->setOption("(can't increase beyond this)\n"); - SelectBoxHelp->setOption("Reduce/default/enlarge minimum " - "height......................................................Del/End/" - "PageDown\n"); - SelectBoxHelp->setOption("(can't decrease below this)\n"); - SelectBoxHelp->setOption("Undo............................................................................................." - "...................Q\n"); - SelectBoxHelp->setOption("(just actions made with the cursor)\n"); - SelectBoxHelp->setOption( - "Build help on/off.............................................................................................Space\n"); - SelectBoxHelp->setOption( - "Castle-Mode....................................................................................................B\n"); - SelectBoxHelp->setOption("(planes the surrounding terrain\n"); - SelectBoxHelp->setOption(" so a castle can be build)\n"); - SelectBoxHelp->setOption( - "Harbour-Mode................................................................................................H\n"); - SelectBoxHelp->setOption("(changes the surrounding terrian,\n"); - SelectBoxHelp->setOption(" so that a harbour can be build)\n"); - SelectBoxHelp->setOption("Convert map \"on-the-fly\" (Greenland/Winterworld/Wasteland..................G/W/O\n"); - SelectBoxHelp->setOption( - "New/Original shadows (experimental)..........................................................P\n"); - SelectBoxHelp->setOption( - "Lock/Unlock horizontal movement................................................................F9\n"); - SelectBoxHelp->setOption( - "Lock/Unlock vertical movement....................................................................F10\n"); - SelectBoxHelp->setOption( - "Turn borders on/off......................................................................................F11\n"); - } else - { - delete WNDHelp; - WNDHelp = NULL; - SelectBoxHelp = NULL; - return; - } - break; - - case CALL_FROM_GAMELOOP: break; - - case WINDOW_QUIT_MESSAGE: // this is the global window quit message, callback is explicit called with this value, so destroy the - // window - if(WNDHelp != NULL) - { - WNDHelp->setWaste(); - WNDHelp = NULL; - SelectBoxHelp = NULL; - } - break; - - case WINDOWQUIT: // this is the own window quit message of the callback - if(WNDHelp != NULL) - { - WNDHelp->setWaste(); - WNDHelp = NULL; - SelectBoxHelp = NULL; - } - break; - - case MAP_QUIT: // this is the global window quit message, callback is explicit called with this value, so destroy the window - if(WNDHelp != NULL) - { - WNDHelp->setWaste(); - WNDHelp = NULL; - SelectBoxHelp = NULL; - } - break; - - default: break; - } -} - -void callback::EditorMainMenu(int Param) -{ - static CWindow* WNDMain = NULL; - - enum - { - LOADMENU, - SAVEMENU, - QUITMENU, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDMain != NULL) - break; - WNDMain = new CWindow(EditorMainMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 110, global::s2->GameResolutionY / 2 - 160, - 220, 320, "Main menu", WINDOW_GREEN1, WINDOW_CLOSE); - if(global::s2->RegisterWindow(WNDMain)) - { - WNDMain->addButton(EditorMainMenu, LOADMENU, 8, 100, 190, 20, BUTTON_GREEN2, "Load map"); - WNDMain->addButton(EditorMainMenu, SAVEMENU, 8, 125, 190, 20, BUTTON_GREEN2, "Save map"); - - WNDMain->addButton(EditorMainMenu, QUITMENU, 8, 260, 190, 20, BUTTON_GREEN2, "Leave editor"); - } else - { - delete WNDMain; - WNDMain = NULL; - return; - } - break; - - case WINDOWQUIT: - if(WNDMain != NULL) - { - WNDMain->setWaste(); - WNDMain = NULL; - } - break; - - case MAP_QUIT: - if(WNDMain != NULL) - { - WNDMain->setWaste(); - WNDMain = NULL; - } - break; - - case QUITMENU: EditorQuitMenu(INITIALIZING_CALL); break; - - case LOADMENU: EditorLoadMenu(INITIALIZING_CALL); break; - - case SAVEMENU: EditorSaveMenu(INITIALIZING_CALL); break; - - default: break; - } -} - -void callback::EditorLoadMenu(int Param) -{ - static CWindow* WNDLoad = NULL; - static CTextfield* TXTF_Filename = NULL; - static CMap* MapObj = NULL; - - enum - { - LOADMAP, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDLoad != NULL) - break; - WNDLoad = new CWindow(EditorLoadMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 140, global::s2->GameResolutionY / 2 - 45, - 280, 120, "Load", WINDOW_GREEN1, WINDOW_CLOSE); - if(global::s2->RegisterWindow(WNDLoad)) - { - MapObj = global::s2->getMapObj(); - - TXTF_Filename = WNDLoad->addTextfield(10, 10, 21, 1); - TXTF_Filename->setText("MyMap.WLD"); - WNDLoad->addButton(EditorLoadMenu, LOADMAP, 170, 40, 90, 20, BUTTON_GREY, "Load"); - WNDLoad->addButton(EditorLoadMenu, WINDOWQUIT, 170, 65, 90, 20, BUTTON_RED1, "Abort"); - } else - { - delete WNDLoad; - WNDLoad = NULL; - return; - } - break; - - case WINDOWQUIT: - if(WNDLoad != NULL) - { - WNDLoad->setWaste(); - WNDLoad = NULL; - } - TXTF_Filename = NULL; - break; - - case MAP_QUIT: - if(WNDLoad != NULL) - { - WNDLoad->setWaste(); - WNDLoad = NULL; - } - TXTF_Filename = NULL; - break; - - case LOADMAP: - PleaseWait(INITIALIZING_CALL); - - // we have to close the windows and initialize them again to prevent failures - EditorCursorMenu(MAP_QUIT); - EditorTextureMenu(MAP_QUIT); - EditorTreeMenu(MAP_QUIT); - EditorLandscapeMenu(MAP_QUIT); - MinimapMenu(MAP_QUIT); - EditorResourceMenu(MAP_QUIT); - EditorAnimalMenu(MAP_QUIT); - EditorPlayerMenu(MAP_QUIT); - - MapObj->destructMap(); - MapObj->constructMap(global::userMapsPath + "/" + TXTF_Filename->getText()); - - // we need to check which of these windows was active before - /* - EditorCursorMenu(INITIALIZING_CALL); - EditorTextureMenu(INITIALIZING_CALL); - EditorTreeMenu(INITIALIZING_CALL); - EditorLandscapeMenu(INITIALIZING_CALL); - MinimapMenu(INITIALIZING_CALL); - EditorResourceMenu(INITIALIZING_CALL); - EditorAnimalMenu(INITIALIZING_CALL); - EditorPlayerMenu(INITIALIZING_CALL); - */ - - PleaseWait(WINDOW_QUIT_MESSAGE); - EditorLoadMenu(WINDOWQUIT); - break; - - default: break; - } -} - -void callback::EditorSaveMenu(int Param) -{ - static CWindow* WNDSave = NULL; - static CTextfield* TXTF_Filename = NULL; - static CTextfield* TXTF_Mapname = NULL; - static CTextfield* TXTF_Author = NULL; - static CMap* MapObj = NULL; - - enum - { - SAVEMAP, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDSave != NULL) - break; - WNDSave = new CWindow(EditorSaveMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 140, global::s2->GameResolutionY / 2 - 100, - 280, 200, "Save", WINDOW_GREEN1, WINDOW_CLOSE); - if(global::s2->RegisterWindow(WNDSave)) - { - MapObj = global::s2->getMapObj(); - - WNDSave->addText("Filename", 100, 2, 9); - TXTF_Filename = WNDSave->addTextfield(10, 13, 21, 1); - TXTF_Filename->setText("MyMap.WLD"); - WNDSave->addText("Mapname", 98, 38, 9); - TXTF_Mapname = WNDSave->addTextfield(10, 50, 19, 1); - TXTF_Mapname->setText(MapObj->getMapname()); - WNDSave->addText("Author", 110, 75, 9); - TXTF_Author = WNDSave->addTextfield(10, 87, 19, 1); - TXTF_Author->setText(MapObj->getAuthor()); - WNDSave->addButton(EditorSaveMenu, SAVEMAP, 170, 120, 90, 20, BUTTON_GREY, "Save"); - WNDSave->addButton(EditorSaveMenu, WINDOWQUIT, 170, 145, 90, 20, BUTTON_RED1, "Abort"); - } else - { - delete WNDSave; - WNDSave = NULL; - return; - } - break; - - case WINDOWQUIT: - if(WNDSave != NULL) - { - WNDSave->setWaste(); - WNDSave = NULL; - } - TXTF_Filename = NULL; - TXTF_Mapname = NULL; - TXTF_Author = NULL; - break; - - case MAP_QUIT: - if(WNDSave != NULL) - { - WNDSave->setWaste(); - WNDSave = NULL; - } - TXTF_Filename = NULL; - TXTF_Mapname = NULL; - TXTF_Author = NULL; - break; - - case SAVEMAP: - { - PleaseWait(INITIALIZING_CALL); - - MapObj->setMapname(TXTF_Mapname->getText()); - MapObj->setAuthor(TXTF_Author->getText()); - bool result = CFile::save_file(global::userMapsPath + "/" + TXTF_Filename->getText(), WLD, MapObj->getMap()); - - ShowStatus(INITIALIZING_CALL); - ShowStatus(result ? 1 : 2); - - PleaseWait(WINDOW_QUIT_MESSAGE); - EditorSaveMenu(WINDOWQUIT); - break; - } - - default: break; - } -} - -void callback::EditorQuitMenu(int Param) -{ - static CWindow* WNDBackToMainMenu = NULL; - - enum - { - BACKTOMAIN = 1, - NOTBACKTOMAIN, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDBackToMainMenu != NULL) - break; - WNDBackToMainMenu = new CWindow(EditorQuitMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 106, - global::s2->GameResolutionY / 2 - 55, 212, 110, "Exit?"); - if(global::s2->RegisterWindow(WNDBackToMainMenu)) - { - WNDBackToMainMenu->addButton(EditorQuitMenu, BACKTOMAIN, 0, 0, 100, 80, BUTTON_GREEN2, NULL, PICTURE_SMALL_TICK); - WNDBackToMainMenu->addButton(EditorQuitMenu, NOTBACKTOMAIN, 100, 0, 100, 80, BUTTON_RED1, NULL, PICTURE_SMALL_CROSS); - } else - { - delete WNDBackToMainMenu; - WNDBackToMainMenu = NULL; - return; - } - break; - - case BACKTOMAIN: - if(global::s2->getMapObj() != NULL) - global::s2->delMapObj(); - WNDBackToMainMenu->setWaste(); - WNDBackToMainMenu = NULL; - // now call all EditorMenu callbacks (from the menubar) with MAP_QUIT - EditorHelpMenu(MAP_QUIT); - EditorMainMenu(MAP_QUIT); - EditorLoadMenu(MAP_QUIT); - EditorSaveMenu(MAP_QUIT); - EditorTextureMenu(MAP_QUIT); - EditorTreeMenu(MAP_QUIT); - EditorLandscapeMenu(MAP_QUIT); - MinimapMenu(MAP_QUIT); - EditorCursorMenu(MAP_QUIT); - EditorResourceMenu(MAP_QUIT); - EditorAnimalMenu(MAP_QUIT); - EditorPlayerMenu(MAP_QUIT); - EditorCreateMenu(MAP_QUIT); - // go to main menu - mainmenu(INITIALIZING_CALL); - break; - - case NOTBACKTOMAIN: - if(WNDBackToMainMenu != NULL) - { - WNDBackToMainMenu->setWaste(); - WNDBackToMainMenu = NULL; - } - break; - - default: break; - } -} - -void callback::EditorTextureMenu(int Param) -{ - static CWindow* WNDTexture = NULL; - static CMap* MapObj = NULL; - static bobMAP* map = NULL; - static int textureIndex = 0; - static int harbourPictureCross = 0; // this have to be -1 if we use the harbour button - static int lastContent = 0x00; - static int PosX = 0, PosY = 0; - - enum - { - WINDOWQUIT, - HARBOUR, - PICSNOW, - PICSTEPPE, - PICSWAMP, - PICFLOWER, - PICMINING1, - PICMINING2, - PICMINING3, - PICMINING4, - PICSTEPPE_MEADOW1, - PICMEADOW1, - PICMEADOW2, - PICMEADOW3, - PICSTEPPE_MEADOW2, - PICMINING_MEADOW, - PICWATER, - PICLAVA, - PICMEADOW_MIXED - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDTexture != NULL) - break; - WNDTexture = new CWindow(EditorTextureMenu, WINDOWQUIT, PosX, PosY, 220, 133, "Terrain", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDTexture)) - { - MapObj = global::s2->getMapObj(); - map = MapObj->getMap(); - switch(map->type) - { - case MAP_GREENLAND: textureIndex = PICTURE_GREENLAND_TEXTURE_SNOW; break; - case MAP_WASTELAND: textureIndex = PICTURE_WASTELAND_TEXTURE_SNOW; break; - case MAP_WINTERLAND: textureIndex = PICTURE_WINTERLAND_TEXTURE_SNOW; break; - default: textureIndex = PICTURE_GREENLAND_TEXTURE_SNOW; break; - } - MapObj->setMode(EDITOR_MODE_TEXTURE); - MapObj->setModeContent(TRIANGLE_TEXTURE_SNOW); - lastContent = TRIANGLE_TEXTURE_SNOW; - - WNDTexture->addPicture(EditorTextureMenu, PICSNOW, 2, 2, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICSTEPPE, 36, 2, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICSWAMP, 70, 2, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICFLOWER, 104, 2, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMINING1, 138, 2, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMINING2, 172, 2, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMINING3, 2, 36, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMINING4, 36, 36, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICSTEPPE_MEADOW1, 70, 36, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMEADOW1, 104, 36, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMEADOW2, 138, 36, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMEADOW3, 172, 36, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICSTEPPE_MEADOW2, 2, 70, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICMINING_MEADOW, 36, 70, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICWATER, 70, 70, textureIndex++); - WNDTexture->addPicture(EditorTextureMenu, PICLAVA, 104, 70, textureIndex++); - if(map->type != MAP_WASTELAND) - WNDTexture->addPicture(EditorTextureMenu, PICMEADOW_MIXED, 138, 70, textureIndex); - - // WNDTexture->addButton(EditorTextureMenu, HARBOUR, 172, 70, 32, 32, BUTTON_GREY, NULL, MAPPIC_HOUSE_HARBOUR); - // harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - } else - { - delete WNDTexture; - WNDTexture = NULL; - return; - } - break; - - case HARBOUR: // harbour mode is active - if(harbourPictureCross == -1) - { - if(MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW1_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW2_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW3_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_FLOWER_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR) - { - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - MapObj->setModeContent(MapObj->getModeContent() - 0x40); - lastContent = MapObj->getModeContent(); - } - } - // harbour mode is inactive - else - { - if(MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW1 || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW1 - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW2 || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW3 - || MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || MapObj->getModeContent() == TRIANGLE_TEXTURE_FLOWER - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MINING_MEADOW - || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW_MIXED) - { - WNDTexture->delStaticPicture(harbourPictureCross); - harbourPictureCross = -1; - MapObj->setModeContent(MapObj->getModeContent() + 0x40); - lastContent = MapObj->getModeContent(); - } - } - break; - case PICSNOW: - MapObj->setModeContent(TRIANGLE_TEXTURE_SNOW); - lastContent = TRIANGLE_TEXTURE_SNOW; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICSTEPPE: - MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE); - lastContent = TRIANGLE_TEXTURE_STEPPE; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICSWAMP: - MapObj->setModeContent(TRIANGLE_TEXTURE_SWAMP); - lastContent = TRIANGLE_TEXTURE_SWAMP; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICFLOWER: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_FLOWER_HARBOUR); - lastContent = TRIANGLE_TEXTURE_FLOWER_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_FLOWER); - lastContent = TRIANGLE_TEXTURE_FLOWER; - } - break; - case PICMINING1: - MapObj->setModeContent(TRIANGLE_TEXTURE_MINING1); - lastContent = TRIANGLE_TEXTURE_MINING1; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICMINING2: - MapObj->setModeContent(TRIANGLE_TEXTURE_MINING2); - lastContent = TRIANGLE_TEXTURE_MINING2; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICMINING3: - MapObj->setModeContent(TRIANGLE_TEXTURE_MINING3); - lastContent = TRIANGLE_TEXTURE_MINING3; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICMINING4: - MapObj->setModeContent(TRIANGLE_TEXTURE_MINING4); - lastContent = TRIANGLE_TEXTURE_MINING4; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICSTEPPE_MEADOW1: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR); - lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW1); - lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW1; - } - break; - case PICMEADOW1: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW1_HARBOUR); - lastContent = TRIANGLE_TEXTURE_MEADOW1_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW1); - lastContent = TRIANGLE_TEXTURE_MEADOW1; - } - break; - case PICMEADOW2: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW2_HARBOUR); - lastContent = TRIANGLE_TEXTURE_MEADOW2_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW2); - lastContent = TRIANGLE_TEXTURE_MEADOW2; - } - break; - case PICMEADOW3: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW3_HARBOUR); - lastContent = TRIANGLE_TEXTURE_MEADOW3_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW3); - lastContent = TRIANGLE_TEXTURE_MEADOW3; - } - break; - case PICSTEPPE_MEADOW2: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR); - lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW2); - lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW2; - } - break; - case PICMINING_MEADOW: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR); - lastContent = TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MINING_MEADOW); - lastContent = TRIANGLE_TEXTURE_MINING_MEADOW; - } - break; - case PICWATER: - MapObj->setModeContent(TRIANGLE_TEXTURE_WATER); - lastContent = TRIANGLE_TEXTURE_WATER; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICLAVA: - MapObj->setModeContent(TRIANGLE_TEXTURE_LAVA); - lastContent = TRIANGLE_TEXTURE_LAVA; - if(harbourPictureCross == -1) - harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); - break; - case PICMEADOW_MIXED: - if(harbourPictureCross == -1) - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR); - lastContent = TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR; - } else - { - MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW_MIXED); - lastContent = TRIANGLE_TEXTURE_MEADOW_MIXED; - } - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - MapObj->setMode(EDITOR_MODE_TEXTURE); - MapObj->setModeContent(lastContent); - } - break; - - case WINDOWQUIT: - if(WNDTexture != NULL) - { - PosX = WNDTexture->getX(); - PosY = WNDTexture->getY(); - WNDTexture->setWaste(); - WNDTexture = NULL; - } - MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); - MapObj->setModeContent(0x00); - lastContent = 0x00; - MapObj = NULL; - map = NULL; - textureIndex = 0; - harbourPictureCross = 0; // this have to be -1 if we use the harbour button - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDTexture != NULL) - { - PosX = WNDTexture->getX(); - PosY = WNDTexture->getY(); - WNDTexture->setWaste(); - WNDTexture = NULL; - } - lastContent = 0x00; - MapObj = NULL; - map = NULL; - textureIndex = 0; - harbourPictureCross = 0; // this have to be -1 if we use the harbour button - break; - - default: break; - } -} - -void callback::EditorTreeMenu(int Param) -{ - static CWindow* WNDTree = NULL; - static CMap* MapObj = NULL; - static bobMAP* map = NULL; - static int lastContent = 0x00; - static int lastContent2 = 0x00; - static int PosX = 230, PosY = 0; - - enum - { - WINDOWQUIT, - PICPINE, - PICBIRCH, - PICOAK, - PICPALM1, - PICPALM2, - PICPINEAPPLE, - PICCYPRESS, - PICCHERRY, - PICFIR, - PICSPIDER, - PICFLAPHAT, - PICWOOD_MIXED, - PICPALM_MIXED - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDTree != NULL) - break; - WNDTree = new CWindow(EditorTreeMenu, WINDOWQUIT, PosX, PosY, 148, 140, "Trees", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDTree)) - { - MapObj = global::s2->getMapObj(); - map = MapObj->getMap(); - switch(map->type) - { - case MAP_GREENLAND: - WNDTree->addPicture(EditorTreeMenu, PICPINE, 2, 2, PICTURE_TREE_PINE); - WNDTree->addPicture(EditorTreeMenu, PICBIRCH, 36, 2, PICTURE_TREE_BIRCH); - WNDTree->addPicture(EditorTreeMenu, PICOAK, 70, 2, PICTURE_TREE_OAK); - WNDTree->addPicture(EditorTreeMenu, PICPALM1, 104, 2, PICTURE_TREE_PALM1); - WNDTree->addPicture(EditorTreeMenu, PICPALM2, 2, 36, PICTURE_TREE_PALM2); - WNDTree->addPicture(EditorTreeMenu, PICPINEAPPLE, 36, 36, PICTURE_TREE_PINEAPPLE); - WNDTree->addPicture(EditorTreeMenu, PICCYPRESS, 70, 36, PICTURE_TREE_CYPRESS); - WNDTree->addPicture(EditorTreeMenu, PICCHERRY, 104, 36, PICTURE_TREE_CHERRY); - WNDTree->addPicture(EditorTreeMenu, PICFIR, 2, 72, PICTURE_TREE_FIR); - WNDTree->addPicture(EditorTreeMenu, PICWOOD_MIXED, 36, 70, PICTURE_TREE_WOOD_MIXED); - WNDTree->addPicture(EditorTreeMenu, PICPALM_MIXED, 70, 70, PICTURE_TREE_PALM_MIXED); - break; - case MAP_WASTELAND: - WNDTree->addPicture(EditorTreeMenu, PICFLAPHAT, 2, 2, PICTURE_TREE_FLAPHAT); - WNDTree->addPicture(EditorTreeMenu, PICSPIDER, 36, 2, PICTURE_TREE_SPIDER); - WNDTree->addPicture(EditorTreeMenu, PICPINEAPPLE, 70, 2, PICTURE_TREE_PINEAPPLE); - WNDTree->addPicture(EditorTreeMenu, PICCHERRY, 104, 2, PICTURE_TREE_CHERRY); - break; - case MAP_WINTERLAND: - WNDTree->addPicture(EditorTreeMenu, PICPINE, 2, 2, PICTURE_TREE_PINE); - WNDTree->addPicture(EditorTreeMenu, PICBIRCH, 36, 2, PICTURE_TREE_BIRCH); - WNDTree->addPicture(EditorTreeMenu, PICCYPRESS, 70, 2, PICTURE_TREE_CYPRESS); - WNDTree->addPicture(EditorTreeMenu, PICFIR, 104, 2, PICTURE_TREE_FIR); - WNDTree->addPicture(EditorTreeMenu, PICWOOD_MIXED, 2, 36, PICTURE_TREE_WOOD_MIXED); - break; - default: // should not happen - break; - } - MapObj->setMode(EDITOR_MODE_TREE); - MapObj->setModeContent(0x30); - MapObj->setModeContent2(0xC4); - lastContent = 0x30; - lastContent2 = 0xC4; - } else - { - delete WNDTree; - WNDTree = NULL; - return; - } - break; - - case PICPINE: - MapObj->setModeContent(0x30); - MapObj->setModeContent2(0xC4); - lastContent = 0x30; - lastContent2 = 0xC4; - break; - case PICBIRCH: - MapObj->setModeContent(0x70); - MapObj->setModeContent2(0xC4); - lastContent = 0x70; - lastContent2 = 0xC4; - break; - case PICOAK: - MapObj->setModeContent(0xB0); - MapObj->setModeContent2(0xC4); - lastContent = 0xB0; - lastContent2 = 0xC4; - break; - case PICPALM1: - MapObj->setModeContent(0xF0); - MapObj->setModeContent2(0xC4); - lastContent = 0xF0; - lastContent2 = 0xC4; - break; - case PICPALM2: - MapObj->setModeContent(0x30); - MapObj->setModeContent2(0xC5); - lastContent = 0x30; - lastContent2 = 0xC5; - break; - case PICPINEAPPLE: - MapObj->setModeContent(0x70); - MapObj->setModeContent2(0xC5); - lastContent = 0x70; - lastContent2 = 0xC5; - break; - case PICCYPRESS: - MapObj->setModeContent(0xB0); - MapObj->setModeContent2(0xC5); - lastContent = 0xB0; - lastContent2 = 0xC5; - break; - case PICCHERRY: - MapObj->setModeContent(0xF0); - MapObj->setModeContent2(0xC5); - lastContent = 0xF0; - lastContent2 = 0xC5; - break; - case PICFIR: - MapObj->setModeContent(0x30); - MapObj->setModeContent2(0xC6); - lastContent = 0x30; - lastContent2 = 0xC6; - break; - case PICFLAPHAT: - MapObj->setModeContent(0x70); - MapObj->setModeContent2(0xC4); - lastContent = 0x70; - lastContent2 = 0xC4; - break; - case PICSPIDER: - MapObj->setModeContent(0x30); - MapObj->setModeContent2(0xC4); - lastContent = 0x30; - lastContent2 = 0xC4; - break; - case PICWOOD_MIXED: - MapObj->setModeContent(0xFF); - MapObj->setModeContent2(0xC4); - lastContent = 0xFF; - lastContent2 = 0xC4; - break; - case PICPALM_MIXED: - MapObj->setModeContent(0xFF); - MapObj->setModeContent2(0xC5); - lastContent = 0xFF; - lastContent2 = 0xC5; - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - MapObj->setMode(EDITOR_MODE_TREE); - MapObj->setModeContent(lastContent); - MapObj->setModeContent2(lastContent2); - } - break; - - case WINDOWQUIT: - if(WNDTree != NULL) - { - PosX = WNDTree->getX(); - PosY = WNDTree->getY(); - WNDTree->setWaste(); - WNDTree = NULL; - } - MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); - MapObj->setModeContent(0x00); - MapObj->setModeContent2(0x00); - lastContent = 0x00; - lastContent2 = 0x00; - MapObj = NULL; - map = NULL; - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDTree != NULL) - { - PosX = WNDTree->getX(); - PosY = WNDTree->getY(); - WNDTree->setWaste(); - WNDTree = NULL; - } - lastContent = 0x00; - lastContent2 = 0x00; - MapObj = NULL; - map = NULL; - break; - - default: break; - } -} - -void callback::EditorResourceMenu(int Param) -{ - static CWindow* WNDResource = NULL; - static CMap* MapObj = NULL; - static int lastContent = 0x00; - static int PosX = 0, PosY = 140; - - enum - { - WINDOWQUIT, - PICGOLD, - PICORE, - PICCOAL, - PICGRANITE - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDResource != NULL) - break; - WNDResource = new CWindow(EditorResourceMenu, WINDOWQUIT, PosX, PosY, 148, 55, "Resources", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDResource)) - { - MapObj = global::s2->getMapObj(); - - WNDResource->addPicture(EditorResourceMenu, PICGOLD, 2, 2, PICTURE_RESOURCE_GOLD); - WNDResource->addPicture(EditorResourceMenu, PICORE, 36, 2, PICTURE_RESOURCE_ORE); - WNDResource->addPicture(EditorResourceMenu, PICCOAL, 70, 2, PICTURE_RESOURCE_COAL); - WNDResource->addPicture(EditorResourceMenu, PICGRANITE, 104, 2, PICTURE_RESOURCE_GRANITE); - - MapObj->setMode(EDITOR_MODE_RESOURCE_RAISE); - MapObj->setModeContent(0x51); - lastContent = 0x51; - } else - { - delete WNDResource; - WNDResource = NULL; - return; - } - break; - - case PICGOLD: - MapObj->setModeContent(0x51); - lastContent = 0x51; - break; - case PICORE: - MapObj->setModeContent(0x49); - lastContent = 0x49; - break; - case PICCOAL: - MapObj->setModeContent(0x41); - lastContent = 0x41; - break; - case PICGRANITE: - MapObj->setModeContent(0x59); - lastContent = 0x59; - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - MapObj->setMode(EDITOR_MODE_RESOURCE_RAISE); - MapObj->setModeContent(lastContent); - } - break; - - case WINDOWQUIT: - if(WNDResource != NULL) - { - PosX = WNDResource->getX(); - PosY = WNDResource->getY(); - WNDResource->setWaste(); - WNDResource = NULL; - } - MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); - MapObj->setModeContent(0x00); - lastContent = 0x00; - MapObj = NULL; - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDResource != NULL) - { - PosX = WNDResource->getX(); - PosY = WNDResource->getY(); - WNDResource->setWaste(); - WNDResource = NULL; - } - lastContent = 0x00; - MapObj = NULL; - break; - - default: break; - } -} - -void callback::EditorLandscapeMenu(int Param) -{ - static CWindow* WNDLandscape = NULL; - static CMap* MapObj = NULL; - static bobMAP* map = NULL; - static int lastContent = 0x00; - static int lastContent2 = 0x00; - static int PosX = 390, PosY = 0; - - enum - { - WINDOWQUIT, - PICGRANITE, - PICTREEDEAD, - PICSTONE, - PICCACTUS, - PICPEBBLE, - PICBUSH, - PICSHRUB, - PICBONE, - PICMUSHROOM, - PICSTALAGMITE, - PICFLOWERS - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDLandscape != NULL) - break; - WNDLandscape = new CWindow(EditorLandscapeMenu, WINDOWQUIT, PosX, PosY, 112, 174, "Landscape", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDLandscape)) - { - MapObj = global::s2->getMapObj(); - map = MapObj->getMap(); - switch(map->type) - { - case MAP_GREENLAND: - WNDLandscape->addPicture(EditorLandscapeMenu, PICGRANITE, 2, 2, PICTURE_LANDSCAPE_GRANITE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICTREEDEAD, 36, 2, PICTURE_LANDSCAPE_TREE_DEAD); - WNDLandscape->addPicture(EditorLandscapeMenu, PICSTONE, 70, 2, PICTURE_LANDSCAPE_STONE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICCACTUS, 2, 36, PICTURE_LANDSCAPE_CACTUS); - WNDLandscape->addPicture(EditorLandscapeMenu, PICPEBBLE, 36, 36, PICTURE_LANDSCAPE_PEBBLE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICBUSH, 70, 36, PICTURE_LANDSCAPE_BUSH); - WNDLandscape->addPicture(EditorLandscapeMenu, PICSHRUB, 2, 70, PICTURE_LANDSCAPE_SHRUB); - WNDLandscape->addPicture(EditorLandscapeMenu, PICBONE, 36, 70, PICTURE_LANDSCAPE_BONE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICMUSHROOM, 70, 70, PICTURE_LANDSCAPE_MUSHROOM); - WNDLandscape->addPicture(EditorLandscapeMenu, PICFLOWERS, 5, 107, MAPPIC_FLOWERS); - break; - case MAP_WASTELAND: - WNDLandscape->addPicture(EditorLandscapeMenu, PICGRANITE, 2, 2, PICTURE_LANDSCAPE_GRANITE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICTREEDEAD, 36, 2, PICTURE_LANDSCAPE_TREE_DEAD); - WNDLandscape->addPicture(EditorLandscapeMenu, PICSTONE, 70, 2, PICTURE_LANDSCAPE_STONE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICSTALAGMITE, 2, 36, PICTURE_LANDSCAPE_STALAGMITE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICPEBBLE, 36, 36, PICTURE_LANDSCAPE_PEBBLE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICBUSH, 70, 36, PICTURE_LANDSCAPE_BUSH); - WNDLandscape->addPicture(EditorLandscapeMenu, PICSHRUB, 2, 70, PICTURE_LANDSCAPE_SHRUB); - WNDLandscape->addPicture(EditorLandscapeMenu, PICBONE, 36, 70, PICTURE_LANDSCAPE_BONE); - WNDLandscape->addPicture(EditorLandscapeMenu, PICMUSHROOM, 70, 70, PICTURE_LANDSCAPE_MUSHROOM); - WNDLandscape->addPicture(EditorLandscapeMenu, PICFLOWERS, 5, 107, MAPPIC_FLOWERS); - break; - case MAP_WINTERLAND: - WNDLandscape->addPicture(EditorLandscapeMenu, PICGRANITE, 2, 2, PICTURE_LANDSCAPE_GRANITE_WINTER); - WNDLandscape->addPicture(EditorLandscapeMenu, PICTREEDEAD, 36, 2, PICTURE_LANDSCAPE_TREE_DEAD_WINTER); - WNDLandscape->addPicture(EditorLandscapeMenu, PICSTONE, 70, 2, PICTURE_LANDSCAPE_STONE_WINTER); - WNDLandscape->addPicture(EditorLandscapeMenu, PICPEBBLE, 2, 36, PICTURE_LANDSCAPE_PEBBLE_WINTER); - WNDLandscape->addPicture(EditorLandscapeMenu, PICBONE, 36, 36, PICTURE_LANDSCAPE_BONE_WINTER); - WNDLandscape->addPicture(EditorLandscapeMenu, PICMUSHROOM, 70, 36, PICTURE_LANDSCAPE_MUSHROOM_WINTER); - WNDLandscape->addPicture(EditorLandscapeMenu, PICFLOWERS, 73, 73, MAPPIC_FLOWERS); - break; - default: // should not happen - break; - } - MapObj->setMode(EDITOR_MODE_LANDSCAPE); - MapObj->setModeContent(0x01); - MapObj->setModeContent2(0xCC); - lastContent = 0x01; - lastContent2 = 0xCC; - } else - { - delete WNDLandscape; - WNDLandscape = NULL; - return; - } - break; - - case PICGRANITE: - MapObj->setModeContent(0x01); - MapObj->setModeContent2(0xCC); - lastContent = 0x01; - lastContent2 = 0xCC; - break; - case PICTREEDEAD: - MapObj->setModeContent(0x05); - MapObj->setModeContent2(0xC8); - lastContent = 0x05; - lastContent2 = 0xC8; - break; - case PICSTONE: - MapObj->setModeContent(0x02); - MapObj->setModeContent2(0xC8); - lastContent = 0x02; - lastContent2 = 0xC8; - break; - case PICCACTUS: - MapObj->setModeContent(0x0C); - MapObj->setModeContent2(0xC8); - lastContent = 0x0C; - lastContent2 = 0xC8; - break; - case PICPEBBLE: - MapObj->setModeContent(0x25); - MapObj->setModeContent2(0xC8); - lastContent = 0x25; - lastContent2 = 0xC8; - break; - case PICBUSH: - MapObj->setModeContent(0x10); - MapObj->setModeContent2(0xC8); - lastContent = 0x10; - lastContent2 = 0xC8; - break; - case PICSHRUB: - MapObj->setModeContent(0x0E); - MapObj->setModeContent2(0xC8); - lastContent = 0x0E; - lastContent2 = 0xC8; - break; - case PICBONE: - MapObj->setModeContent(0x07); - MapObj->setModeContent2(0xC8); - lastContent = 0x07; - lastContent2 = 0xC8; - break; - case PICMUSHROOM: - MapObj->setModeContent(0x00); - MapObj->setModeContent2(0xC8); - lastContent = 0x00; - lastContent2 = 0xC8; - break; - case PICSTALAGMITE: - MapObj->setModeContent(0x18); - MapObj->setModeContent2(0xC8); - lastContent = 0x18; - lastContent2 = 0xC8; - break; - case PICFLOWERS: - MapObj->setModeContent(0x09); - MapObj->setModeContent2(0xC8); - lastContent = 0x09; - lastContent2 = 0xC8; - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - MapObj->setMode(EDITOR_MODE_LANDSCAPE); - MapObj->setModeContent(lastContent); - MapObj->setModeContent2(lastContent2); - } - break; - - case WINDOWQUIT: - if(WNDLandscape != NULL) - { - PosX = WNDLandscape->getX(); - PosY = WNDLandscape->getY(); - WNDLandscape->setWaste(); - WNDLandscape = NULL; - } - MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); - MapObj->setModeContent(0x00); - MapObj->setModeContent2(0x00); - lastContent = 0x00; - lastContent2 = 0x00; - MapObj = NULL; - map = NULL; - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDLandscape != NULL) - { - PosX = WNDLandscape->getX(); - PosY = WNDLandscape->getY(); - WNDLandscape->setWaste(); - WNDLandscape = NULL; - } - lastContent = 0x00; - lastContent2 = 0x00; - MapObj = NULL; - map = NULL; - break; - - default: break; - } -} - -void callback::EditorAnimalMenu(int Param) -{ - static CWindow* WNDAnimal = NULL; - static CMap* MapObj = NULL; - static int lastContent = 0x00; - static int PosX = 510, PosY = 0; - - enum - { - WINDOWQUIT, - PICRABBIT, - PICFOX, - PICSTAG, - PICROE, - PICDUCK, - PICSHEEP - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDAnimal != NULL) - break; - WNDAnimal = new CWindow(EditorAnimalMenu, WINDOWQUIT, PosX, PosY, 116, 106, "Animals", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDAnimal)) - { - WNDAnimal->addPicture(EditorAnimalMenu, PICRABBIT, 2, 2, PICTURE_ANIMAL_RABBIT); - WNDAnimal->addPicture(EditorAnimalMenu, PICFOX, 36, 2, PICTURE_ANIMAL_FOX); - WNDAnimal->addPicture(EditorAnimalMenu, PICSTAG, 70, 2, PICTURE_ANIMAL_STAG); - WNDAnimal->addPicture(EditorAnimalMenu, PICROE, 2, 36, PICTURE_ANIMAL_ROE); - WNDAnimal->addPicture(EditorAnimalMenu, PICDUCK, 36, 36, PICTURE_ANIMAL_DUCK); - WNDAnimal->addPicture(EditorAnimalMenu, PICSHEEP, 70, 36, PICTURE_ANIMAL_SHEEP); - - MapObj = global::s2->getMapObj(); - MapObj->setMode(EDITOR_MODE_ANIMAL); - MapObj->setModeContent(0x01); - lastContent = 0x01; - } else - { - delete WNDAnimal; - WNDAnimal = NULL; - return; - } - break; - - case PICRABBIT: - MapObj->setModeContent(0x01); - lastContent = 0x01; - break; - case PICFOX: - MapObj->setModeContent(0x02); - lastContent = 0x02; - break; - case PICSTAG: - MapObj->setModeContent(0x03); - lastContent = 0x03; - break; - case PICROE: - MapObj->setModeContent(0x04); - lastContent = 0x04; - break; - case PICDUCK: - MapObj->setModeContent(0x05); - lastContent = 0x05; - break; - case PICSHEEP: - MapObj->setModeContent(0x06); - lastContent = 0x06; - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - MapObj->setMode(EDITOR_MODE_ANIMAL); - MapObj->setModeContent(lastContent); - } - break; - - case WINDOWQUIT: - if(WNDAnimal != NULL) - { - PosX = WNDAnimal->getX(); - PosY = WNDAnimal->getY(); - WNDAnimal->setWaste(); - WNDAnimal = NULL; - } - MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); - MapObj->setModeContent(0x00); - lastContent = 0x00; - MapObj = NULL; - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDAnimal != NULL) - { - PosX = WNDAnimal->getX(); - PosY = WNDAnimal->getY(); - WNDAnimal->setWaste(); - WNDAnimal = NULL; - } - lastContent = 0x00; - MapObj = NULL; - break; - - default: break; - } -} - -void callback::EditorPlayerMenu(int Param) -{ - static CWindow* WNDPlayer = NULL; - static CMap* MapObj = NULL; - static int PlayerNumber = 0x00; - static CFont* PlayerNumberText = NULL; - char puffer[30]; - static DisplayRectangle tempRect; - static Uint16* PlayerHQx = NULL; - static Uint16* PlayerHQy = NULL; - static int PosX = 0, PosY = 200; - - enum - { - PLAYER_REDUCE = 0, - PLAYER_RAISE, - GOTO_PLAYER, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDPlayer != NULL) - break; - WNDPlayer = new CWindow(EditorPlayerMenu, WINDOWQUIT, PosX, PosY, 100, 80, "Players", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDPlayer)) - { - MapObj = global::s2->getMapObj(); - tempRect = MapObj->getDisplayRect(); - PlayerHQx = MapObj->getPlayerHQx(); - PlayerHQy = MapObj->getPlayerHQy(); - - MapObj->setMode(EDITOR_MODE_FLAG); - MapObj->setModeContent(PlayerNumber); - - WNDPlayer->addButton(EditorPlayerMenu, PLAYER_REDUCE, 0, 0, 20, 20, BUTTON_GREY, "-"); - sprintf(puffer, "%d", PlayerNumber + 1); - PlayerNumberText = WNDPlayer->addText(puffer, 26, 4, 14, FONT_ORANGE); - WNDPlayer->addButton(EditorPlayerMenu, PLAYER_RAISE, 40, 0, 20, 20, BUTTON_GREY, "+"); - WNDPlayer->addButton(EditorPlayerMenu, GOTO_PLAYER, 0, 20, 60, 20, BUTTON_GREY, "Go to"); - } else - { - delete WNDPlayer; - WNDPlayer = NULL; - return; - } - break; - - case PLAYER_REDUCE: - if(PlayerNumber > 0) - { - PlayerNumber--; - MapObj->setModeContent(PlayerNumber); - WNDPlayer->delText(PlayerNumberText); - sprintf(puffer, "%d", PlayerNumber + 1); - PlayerNumberText = WNDPlayer->addText(puffer, 26, 4, 14, FONT_ORANGE); - } - break; - - case PLAYER_RAISE: - if(PlayerNumber < MAXPLAYERS - 1) - { - PlayerNumber++; - MapObj->setModeContent(PlayerNumber); - WNDPlayer->delText(PlayerNumberText); - sprintf(puffer, "%d", PlayerNumber + 1); - PlayerNumberText = WNDPlayer->addText(puffer, 26, 4, 14, FONT_ORANGE); - } - break; - - case GOTO_PLAYER: // test if player exists on map - if(PlayerHQx[PlayerNumber] != 0xFFFF && PlayerHQy[PlayerNumber] != 0xFFFF) - { - tempRect = MapObj->getDisplayRect(); - tempRect.x = PlayerHQx[PlayerNumber] * TRIANGLE_WIDTH - tempRect.w / 2; - tempRect.y = PlayerHQy[PlayerNumber] * TRIANGLE_HEIGHT - tempRect.h / 2; - MapObj->setDisplayRect(tempRect); - } - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - MapObj->setMode(EDITOR_MODE_FLAG); - MapObj->setModeContent(PlayerNumber); - } - break; - - case WINDOWQUIT: - if(WNDPlayer != NULL) - { - PosX = WNDPlayer->getX(); - PosY = WNDPlayer->getY(); - WNDPlayer->setWaste(); - WNDPlayer = NULL; - } - MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); - MapObj->setModeContent(0x00); - MapObj->setModeContent2(0x00); - MapObj = NULL; - PlayerNumber = 0x01; - PlayerNumberText = NULL; - PlayerHQx = NULL; - PlayerHQy = NULL; - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead - if(WNDPlayer != NULL) - { - PosX = WNDPlayer->getX(); - PosY = WNDPlayer->getY(); - WNDPlayer->setWaste(); - WNDPlayer = NULL; - } - MapObj = NULL; - PlayerNumber = 0x01; - PlayerNumberText = NULL; - PlayerHQx = NULL; - PlayerHQy = NULL; - break; - - default: break; - } -} - -void callback::EditorCursorMenu(int Param) -{ - static CWindow* WNDCursor = NULL; - static CMap* MapObj = NULL; - static int trianglePictureArrowUp = -1; - static int trianglePictureArrowDown = -1; - static int trianglePictureRandom = -1; - static CButton* CursorModeButton = NULL; - static CButton* CursorRandomButton = NULL; - static int PosX = 0, PosY = 0; - - enum - { - WINDOWQUIT, - TRIANGLE, - CURSORMODE, - CURSORRANDOM - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDCursor != NULL) - break; - WNDCursor = new CWindow(EditorCursorMenu, WINDOWQUIT, PosX, PosY, 210, 130, "Cursor", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDCursor)) - { - MapObj = global::s2->getMapObj(); - - WNDCursor->addButton(EditorCursorMenu, TRIANGLE, 2, 66, 32, 32, BUTTON_GREY, NULL); - trianglePictureArrowUp = WNDCursor->addStaticPicture(8, 74, CURSOR_SYMBOL_ARROW_UP); - trianglePictureArrowDown = WNDCursor->addStaticPicture(17, 77, CURSOR_SYMBOL_ARROW_DOWN); - CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Hexagon"); - CursorRandomButton = - WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: static"); - if(MapObj != NULL) - { - MapObj->setVertexFillRSU(true); - MapObj->setVertexFillUSD(true); - MapObj->setVertexFillRandom(false); - MapObj->setHexagonMode(true); - MapObj->setVertexActivityRandom(false); - } - } else - { - delete WNDCursor; - WNDCursor = NULL; - return; - } - break; - - case TRIANGLE: - if(trianglePictureArrowUp != -1 && trianglePictureArrowDown != -1) - { - // both arrows are shown, so set to random - // delete arrow up - WNDCursor->delStaticPicture(trianglePictureArrowUp); - trianglePictureArrowUp = -1; - // delete arrow down - WNDCursor->delStaticPicture(trianglePictureArrowDown); - trianglePictureArrowDown = -1; - // add random if necessary - if(trianglePictureRandom == -1) - trianglePictureRandom = WNDCursor->addStaticPicture(14, 76, FONT14_SPACE + 31 * 7 + 5); // Interrogation point - MapObj->setVertexFillRSU(false); - MapObj->setVertexFillUSD(false); - MapObj->setVertexFillRandom(true); - } else if(trianglePictureArrowUp == -1 && trianglePictureRandom == -1) - { - // only arrow down is shown, so upgrade to both arrows - // add arrow up - trianglePictureArrowUp = WNDCursor->addStaticPicture(8, 74, CURSOR_SYMBOL_ARROW_UP); - // add arrow down if necessary - if(trianglePictureArrowDown == -1) - trianglePictureArrowDown = WNDCursor->addStaticPicture(17, 77, CURSOR_SYMBOL_ARROW_DOWN); - MapObj->setVertexFillRSU(true); - MapObj->setVertexFillUSD(true); - MapObj->setVertexFillRandom(false); - } else if(trianglePictureArrowDown == -1 && trianglePictureRandom == -1) - { - // only arrow up is shown, so delete arrow up and add arrow down - // delete arrow up if necessary - if(trianglePictureArrowUp != -1) - { - WNDCursor->delStaticPicture(trianglePictureArrowUp); - trianglePictureArrowUp = -1; - } - trianglePictureArrowDown = WNDCursor->addStaticPicture(17, 77, CURSOR_SYMBOL_ARROW_DOWN); - MapObj->setVertexFillRSU(false); - MapObj->setVertexFillUSD(true); - MapObj->setVertexFillRandom(false); - } else - { - // the interrogation point is shown, so set to arrow up - WNDCursor->delStaticPicture(trianglePictureRandom); - trianglePictureRandom = -1; - // add arrow up if necessary - if(trianglePictureArrowUp == -1) - trianglePictureArrowUp = WNDCursor->addStaticPicture(8, 74, CURSOR_SYMBOL_ARROW_UP); - // delete arrow down if necessary - if(trianglePictureArrowDown != -1) - { - WNDCursor->delStaticPicture(trianglePictureArrowDown); - trianglePictureArrowDown = -1; - } - MapObj->setVertexFillRSU(true); - MapObj->setVertexFillUSD(false); - MapObj->setVertexFillRandom(false); - } - break; - - case CURSORMODE: - if(CursorModeButton != NULL) - { - WNDCursor->delButton(CursorModeButton); - CursorModeButton = NULL; - } - if(MapObj->getHexagonMode()) - { - CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Square"); - MapObj->setHexagonMode(false); - } else - { - CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Hexagon"); - MapObj->setHexagonMode(true); - } - break; - case CURSORRANDOM: - if(CursorRandomButton != NULL) - { - WNDCursor->delButton(CursorRandomButton); - CursorRandomButton = NULL; - } - if(MapObj->getVertexActivityRandom()) - { - CursorRandomButton = - WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: static"); - MapObj->setVertexActivityRandom(false); - } else - { - CursorRandomButton = - WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: random"); - MapObj->setVertexActivityRandom(true); - } - break; - - case WINDOW_CLICKED_CALL: break; - - case WINDOWQUIT: - if(WNDCursor != NULL) - { - PosX = WNDCursor->getX(); - PosY = WNDCursor->getY(); - WNDCursor->setWaste(); - WNDCursor = NULL; - } - MapObj = NULL; - trianglePictureArrowUp = -1; - trianglePictureArrowDown = -1; - trianglePictureRandom = -1; - CursorModeButton = NULL; - CursorRandomButton = NULL; - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT - if(WNDCursor != NULL) - { - PosX = WNDCursor->getX(); - PosY = WNDCursor->getY(); - WNDCursor->setWaste(); - WNDCursor = NULL; - } - MapObj = NULL; - trianglePictureArrowUp = -1; - trianglePictureArrowDown = -1; - trianglePictureRandom = -1; - CursorModeButton = NULL; - CursorRandomButton = NULL; - break; - - default: break; - } -} - -//"create world" menu -void callback::EditorCreateMenu(int Param) -{ - static CWindow* WNDCreate = NULL; - static CMap* MapObj = NULL; - static CFont* TextWidth = NULL; - static int width = 32; - static CFont* TextHeight = NULL; - static int height = 32; - static CButton* ButtonLandscape = NULL; - static int LandscapeType = 0; // 0 = Greenland, 1 = Wasteland, 2 = Winterland - static int PicTextureIndex = -1; - static int PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - static int texture = TRIANGLE_TEXTURE_SNOW; - static int PicBorderTextureIndex = -1; - static int PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - static CFont* TextBorder = NULL; - static int border = 0; - static int border_texture = TRIANGLE_TEXTURE_SNOW; - static char puffer[5]; - int PosX = global::s2->GameResolutionX / 2 - 125, PosY = global::s2->GameResolutionY / 2 - 175; - - enum - { - REDUCE_WIDTH_128, - REDUCE_WIDTH_16, - REDUCE_WIDTH_2, - RAISE_WIDTH_2, - RAISE_WIDTH_16, - RAISE_WIDTH_128, - REDUCE_HEIGHT_128, - REDUCE_HEIGHT_16, - REDUCE_HEIGHT_2, - RAISE_HEIGHT_2, - RAISE_HEIGHT_16, - RAISE_HEIGHT_128, - CHANGE_LANDSCAPE, - TEXTURE_PREVIOUS, - TEXTURE_NEXT, - BORDER_TEXTURE_PREVIOUS, - BORDER_TEXTURE_NEXT, - REDUCE_BORDER, - RAISE_BORDER, - CREATE_WORLD, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDCreate != NULL) - break; - WNDCreate = new CWindow(EditorCreateMenu, WINDOWQUIT, PosX, PosY, 250, 350, "Create world", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE); - if(global::s2->RegisterWindow(WNDCreate)) - { - MapObj = global::s2->getMapObj(); - - WNDCreate->addText("Width", 95, 4, 9, FONT_YELLOW); - WNDCreate->addButton(EditorCreateMenu, REDUCE_WIDTH_128, 0, 15, 35, 20, BUTTON_GREY, "128<-"); - WNDCreate->addButton(EditorCreateMenu, REDUCE_WIDTH_16, 35, 15, 35, 20, BUTTON_GREY, "16<-"); - WNDCreate->addButton(EditorCreateMenu, REDUCE_WIDTH_2, 70, 15, 25, 20, BUTTON_GREY, "2<-"); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - TextWidth->setText(puffer); - WNDCreate->addButton(EditorCreateMenu, RAISE_WIDTH_2, 143, 15, 25, 20, BUTTON_GREY, "->2"); - WNDCreate->addButton(EditorCreateMenu, RAISE_WIDTH_16, 168, 15, 35, 20, BUTTON_GREY, "->16"); - WNDCreate->addButton(EditorCreateMenu, RAISE_WIDTH_128, 203, 15, 35, 20, BUTTON_GREY, "->128"); - - WNDCreate->addText("Height", 100, 40, 9, FONT_YELLOW); - WNDCreate->addButton(EditorCreateMenu, REDUCE_HEIGHT_128, 0, 49, 35, 20, BUTTON_GREY, "128<-"); - WNDCreate->addButton(EditorCreateMenu, REDUCE_HEIGHT_16, 35, 49, 35, 20, BUTTON_GREY, "16<-"); - WNDCreate->addButton(EditorCreateMenu, REDUCE_HEIGHT_2, 70, 49, 25, 20, BUTTON_GREY, "2<-"); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - TextHeight->setText(puffer); - WNDCreate->addButton(EditorCreateMenu, RAISE_HEIGHT_2, 143, 49, 25, 20, BUTTON_GREY, "->2"); - WNDCreate->addButton(EditorCreateMenu, RAISE_HEIGHT_16, 168, 49, 35, 20, BUTTON_GREY, "->16"); - WNDCreate->addButton(EditorCreateMenu, RAISE_HEIGHT_128, 203, 49, 35, 20, BUTTON_GREY, "->128"); - - WNDCreate->addText("Landscape", 85, 80, 9, FONT_YELLOW); - ButtonLandscape = - WNDCreate->addButton(EditorCreateMenu, CHANGE_LANDSCAPE, 64, 93, 110, 20, BUTTON_GREY, - (LandscapeType == 0 ? "Greenland" : (LandscapeType == 1 ? "Wasteland" : "Winterworld"))); - - WNDCreate->addText("Main area", 82, 120, 9, FONT_YELLOW); - WNDCreate->addButton(EditorCreateMenu, TEXTURE_PREVIOUS, 45, 139, 35, 20, BUTTON_GREY, "-"); - PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); - WNDCreate->addButton(EditorCreateMenu, TEXTURE_NEXT, 158, 139, 35, 20, BUTTON_GREY, "+"); - - WNDCreate->addText("Border size", 103, 175, 9, FONT_YELLOW); - WNDCreate->addButton(EditorCreateMenu, REDUCE_BORDER, 45, 186, 35, 20, BUTTON_GREY, "-"); - sprintf(puffer, "%d", border); - TextBorder = WNDCreate->addText(puffer, 112, 188, 14, FONT_YELLOW); - WNDCreate->addButton(EditorCreateMenu, RAISE_BORDER, 158, 186, 35, 20, BUTTON_GREY, "+"); - - WNDCreate->addText("Border area", 65, 215, 9, FONT_YELLOW); - WNDCreate->addButton(EditorCreateMenu, BORDER_TEXTURE_PREVIOUS, 45, 234, 35, 20, BUTTON_GREY, "-"); - PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); - WNDCreate->addButton(EditorCreateMenu, BORDER_TEXTURE_NEXT, 158, 234, 35, 20, BUTTON_GREY, "+"); - - WNDCreate->addButton(EditorCreateMenu, CREATE_WORLD, 44, 275, 150, 40, BUTTON_GREY, "Create world"); - } else - { - delete WNDCreate; - WNDCreate = NULL; - return; - } - break; - - case CALL_FROM_GAMELOOP: break; - - case REDUCE_WIDTH_128: - if(width - 128 >= 32) - width -= 128; - else - width = 32; - WNDCreate->delText(TextWidth); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - break; - case REDUCE_WIDTH_16: - if(width - 16 >= 32) - width -= 16; - else - width = 32; - WNDCreate->delText(TextWidth); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - break; - case REDUCE_WIDTH_2: - if(width - 2 >= 32) - width -= 2; - else - width = 32; - WNDCreate->delText(TextWidth); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - break; - case RAISE_WIDTH_2: - if(width + 2 <= MAXMAPWIDTH) - width += 2; - else - width = MAXMAPWIDTH; - WNDCreate->delText(TextWidth); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - break; - case RAISE_WIDTH_16: - if(width + 16 <= MAXMAPWIDTH) - width += 16; - else - width = MAXMAPWIDTH; - WNDCreate->delText(TextWidth); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - break; - case RAISE_WIDTH_128: - if(width + 128 <= MAXMAPWIDTH) - width += 128; - else - width = MAXMAPWIDTH; - WNDCreate->delText(TextWidth); - sprintf(puffer, "%d", width); - TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); - break; - case REDUCE_HEIGHT_128: - if(height - 128 >= 32) - height -= 128; - else - height = 32; - WNDCreate->delText(TextHeight); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - break; - case REDUCE_HEIGHT_16: - if(height - 16 >= 32) - height -= 16; - else - height = 32; - WNDCreate->delText(TextHeight); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - break; - case REDUCE_HEIGHT_2: - if(height - 2 >= 32) - height -= 2; - else - height = 32; - WNDCreate->delText(TextHeight); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - break; - case RAISE_HEIGHT_2: - if(height + 2 <= MAXMAPHEIGHT) - height += 2; - else - height = MAXMAPHEIGHT; - WNDCreate->delText(TextHeight); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - break; - case RAISE_HEIGHT_16: - if(height + 16 <= MAXMAPHEIGHT) - height += 16; - else - height = MAXMAPHEIGHT; - WNDCreate->delText(TextHeight); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - break; - case RAISE_HEIGHT_128: - if(height + 128 <= MAXMAPHEIGHT) - height += 128; - else - height = MAXMAPHEIGHT; - WNDCreate->delText(TextHeight); - sprintf(puffer, "%d", height); - TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); - break; - - case CHANGE_LANDSCAPE: - LandscapeType++; - if(LandscapeType > 2) - LandscapeType = 0; - WNDCreate->delButton(ButtonLandscape); - ButtonLandscape = WNDCreate->addButton(EditorCreateMenu, CHANGE_LANDSCAPE, 64, 93, 110, 20, BUTTON_GREY, - (LandscapeType == 0 ? "Greenland" : (LandscapeType == 1 ? "Wasteland" : "Winterworld"))); - switch(LandscapeType) - { - case 0: - PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - break; - case 1: - PicTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; - PicBorderTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; - break; - case 2: - PicTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; - PicBorderTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; - break; - default: break; - } - WNDCreate->delStaticPicture(PicTextureIndex); - WNDCreate->delStaticPicture(PicBorderTextureIndex); - PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); - PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); - break; - - case TEXTURE_PREVIOUS: - PicTextureIndexGlobal--; - switch(LandscapeType) - { - case 0: - if(PicTextureIndexGlobal < PICTURE_GREENLAND_TEXTURE_SNOW) - PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - break; - case 1: - if(PicTextureIndexGlobal < PICTURE_WASTELAND_TEXTURE_SNOW) - PicTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; - break; - case 2: - if(PicTextureIndexGlobal < PICTURE_WINTERLAND_TEXTURE_SNOW) - PicTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; - break; - default: break; - } - if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) - { - texture = TRIANGLE_TEXTURE_SNOW; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) - { - texture = TRIANGLE_TEXTURE_STEPPE; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) - { - texture = TRIANGLE_TEXTURE_SWAMP; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) - { - texture = TRIANGLE_TEXTURE_FLOWER; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) - { - texture = TRIANGLE_TEXTURE_MINING1; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) - { - texture = TRIANGLE_TEXTURE_MINING2; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) - { - texture = TRIANGLE_TEXTURE_MINING3; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) - { - texture = TRIANGLE_TEXTURE_MINING4; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) - { - texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) - { - texture = TRIANGLE_TEXTURE_MEADOW1; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) - { - texture = TRIANGLE_TEXTURE_MEADOW2; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) - { - texture = TRIANGLE_TEXTURE_MEADOW3; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) - { - texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) - { - texture = TRIANGLE_TEXTURE_MINING_MEADOW; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) - { - texture = TRIANGLE_TEXTURE_WATER; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) - { - texture = TRIANGLE_TEXTURE_LAVA; - } - WNDCreate->delStaticPicture(PicTextureIndex); - PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); - break; - case TEXTURE_NEXT: - PicTextureIndexGlobal++; - switch(LandscapeType) - { - case 0: - if(PicTextureIndexGlobal > PICTURE_GREENLAND_TEXTURE_LAVA) - PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_LAVA; - break; - case 1: - if(PicTextureIndexGlobal > PICTURE_WASTELAND_TEXTURE_LAVA) - PicTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_LAVA; - break; - case 2: - if(PicTextureIndexGlobal > PICTURE_WINTERLAND_TEXTURE_LAVA) - PicTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_LAVA; - break; - default: break; - } - if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) - { - texture = TRIANGLE_TEXTURE_SNOW; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) - { - texture = TRIANGLE_TEXTURE_STEPPE; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) - { - texture = TRIANGLE_TEXTURE_SWAMP; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) - { - texture = TRIANGLE_TEXTURE_FLOWER; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) - { - texture = TRIANGLE_TEXTURE_MINING1; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) - { - texture = TRIANGLE_TEXTURE_MINING2; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) - { - texture = TRIANGLE_TEXTURE_MINING3; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) - { - texture = TRIANGLE_TEXTURE_MINING4; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) - { - texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) - { - texture = TRIANGLE_TEXTURE_MEADOW1; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) - { - texture = TRIANGLE_TEXTURE_MEADOW2; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) - { - texture = TRIANGLE_TEXTURE_MEADOW3; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) - { - texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW - || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) - { - texture = TRIANGLE_TEXTURE_MINING_MEADOW; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) - { - texture = TRIANGLE_TEXTURE_WATER; - } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA - || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) - { - texture = TRIANGLE_TEXTURE_LAVA; - } - WNDCreate->delStaticPicture(PicTextureIndex); - PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); - break; - - case REDUCE_BORDER: - if(border - 1 >= 0) - border -= 1; - else - border = 0; - WNDCreate->delText(TextBorder); - sprintf(puffer, "%d", border); - TextBorder = WNDCreate->addText(puffer, 112, 188, 14, FONT_YELLOW); - break; - case RAISE_BORDER: - if(border + 1 <= 12) - border += 1; - else - border = 12; - WNDCreate->delText(TextBorder); - sprintf(puffer, "%d", border); - TextBorder = WNDCreate->addText(puffer, 112, 188, 14, FONT_YELLOW); - break; - - case BORDER_TEXTURE_PREVIOUS: - PicBorderTextureIndexGlobal--; - switch(LandscapeType) - { - case 0: - if(PicBorderTextureIndexGlobal < PICTURE_GREENLAND_TEXTURE_SNOW) - PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - break; - case 1: - if(PicBorderTextureIndexGlobal < PICTURE_WASTELAND_TEXTURE_SNOW) - PicBorderTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; - break; - case 2: - if(PicBorderTextureIndexGlobal < PICTURE_WINTERLAND_TEXTURE_SNOW) - PicBorderTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; - break; - default: break; - } - if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) - { - border_texture = TRIANGLE_TEXTURE_SNOW; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) - { - border_texture = TRIANGLE_TEXTURE_STEPPE; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) - { - border_texture = TRIANGLE_TEXTURE_SWAMP; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) - { - border_texture = TRIANGLE_TEXTURE_FLOWER; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) - { - border_texture = TRIANGLE_TEXTURE_MINING1; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) - { - border_texture = TRIANGLE_TEXTURE_MINING2; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) - { - border_texture = TRIANGLE_TEXTURE_MINING3; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) - { - border_texture = TRIANGLE_TEXTURE_MINING4; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) - { - border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) - { - border_texture = TRIANGLE_TEXTURE_MEADOW1; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) - { - border_texture = TRIANGLE_TEXTURE_MEADOW2; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) - { - border_texture = TRIANGLE_TEXTURE_MEADOW3; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) - { - border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) - { - border_texture = TRIANGLE_TEXTURE_MINING_MEADOW; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) - { - border_texture = TRIANGLE_TEXTURE_WATER; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) - { - border_texture = TRIANGLE_TEXTURE_LAVA; - } - WNDCreate->delStaticPicture(PicBorderTextureIndex); - PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); - break; - case BORDER_TEXTURE_NEXT: - PicBorderTextureIndexGlobal++; - switch(LandscapeType) - { - case 0: - if(PicBorderTextureIndexGlobal > PICTURE_GREENLAND_TEXTURE_LAVA) - PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_LAVA; - break; - case 1: - if(PicBorderTextureIndexGlobal > PICTURE_WASTELAND_TEXTURE_LAVA) - PicBorderTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_LAVA; - break; - case 2: - if(PicBorderTextureIndexGlobal > PICTURE_WINTERLAND_TEXTURE_LAVA) - PicBorderTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_LAVA; - break; - default: break; - } - if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) - { - border_texture = TRIANGLE_TEXTURE_SNOW; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) - { - border_texture = TRIANGLE_TEXTURE_STEPPE; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) - { - border_texture = TRIANGLE_TEXTURE_SWAMP; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) - { - border_texture = TRIANGLE_TEXTURE_FLOWER; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) - { - border_texture = TRIANGLE_TEXTURE_MINING1; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) - { - border_texture = TRIANGLE_TEXTURE_MINING2; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) - { - border_texture = TRIANGLE_TEXTURE_MINING3; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) - { - border_texture = TRIANGLE_TEXTURE_MINING4; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) - { - border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) - { - border_texture = TRIANGLE_TEXTURE_MEADOW1; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) - { - border_texture = TRIANGLE_TEXTURE_MEADOW2; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) - { - border_texture = TRIANGLE_TEXTURE_MEADOW3; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) - { - border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) - { - border_texture = TRIANGLE_TEXTURE_MINING_MEADOW; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) - { - border_texture = TRIANGLE_TEXTURE_WATER; - } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA - || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA - || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) - { - border_texture = TRIANGLE_TEXTURE_LAVA; - } - WNDCreate->delStaticPicture(PicBorderTextureIndex); - PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); - break; - - case CREATE_WORLD: - PleaseWait(INITIALIZING_CALL); - - // we have to close the windows and initialize them again to prevent failures - EditorCursorMenu(MAP_QUIT); - EditorTextureMenu(MAP_QUIT); - EditorTreeMenu(MAP_QUIT); - EditorLandscapeMenu(MAP_QUIT); - MinimapMenu(MAP_QUIT); - EditorResourceMenu(MAP_QUIT); - EditorAnimalMenu(MAP_QUIT); - EditorPlayerMenu(MAP_QUIT); - - MapObj->destructMap(); - MapObj->constructMap("", width, height, LandscapeType, texture, border, border_texture); - - // we need to check which of these windows was active before - /* - EditorCursorMenu(INITIALIZING_CALL); - EditorTextureMenu(INITIALIZING_CALL); - EditorTreeMenu(INITIALIZING_CALL); - EditorLandscapeMenu(INITIALIZING_CALL); - MinimapMenu(INITIALIZING_CALL); - EditorResourceMenu(INITIALIZING_CALL); - EditorAnimalMenu(INITIALIZING_CALL); - EditorPlayerMenu(INITIALIZING_CALL); - */ - - PleaseWait(WINDOW_QUIT_MESSAGE); - break; - - case MAP_QUIT: - if(WNDCreate != NULL) - { - PosX = WNDCreate->getX(); - PosY = WNDCreate->getY(); - WNDCreate->setWaste(); - WNDCreate = NULL; - } - MapObj = NULL; - TextWidth = NULL; - width = 32; - TextHeight = NULL; - height = 32; - ButtonLandscape = NULL; - LandscapeType = 0; - PicTextureIndex = -1; - PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - texture = TRIANGLE_TEXTURE_SNOW; - PicBorderTextureIndex = -1; - PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - TextBorder = NULL; - border = 0; - border_texture = TRIANGLE_TEXTURE_SNOW; - break; - - case WINDOWQUIT: - if(WNDCreate != NULL) - { - PosX = WNDCreate->getX(); - PosY = WNDCreate->getY(); - WNDCreate->setWaste(); - WNDCreate = NULL; - } - MapObj = NULL; - TextWidth = NULL; - width = 32; - TextHeight = NULL; - height = 32; - ButtonLandscape = NULL; - LandscapeType = 0; - PicTextureIndex = -1; - PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - texture = TRIANGLE_TEXTURE_SNOW; - PicBorderTextureIndex = -1; - PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; - TextBorder = NULL; - border = 0; - border_texture = TRIANGLE_TEXTURE_SNOW; - break; - - default: break; - } -} - -#else -// now the 4 game callbacks from the menubar will follow - -void callback::GameMenu(int Param) -{ - static CWindow* WNDBackToMainMenu = NULL; - - enum - { - BACKTOMAIN = 1, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDBackToMainMenu != NULL) - break; - WNDBackToMainMenu = - new CWindow(GameMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 125, global::s2->GameResolutionY / 2 - 60, 250, 140, - "Back to the main menu?", WINDOW_GREEN1, WINDOW_CLOSE); - if(global::s2->RegisterWindow(WNDBackToMainMenu)) - { - WNDBackToMainMenu->addButton(GameMenu, BACKTOMAIN, 20, 20, 200, 80, BUTTON_RED2, "Yes"); - } else - { - delete WNDBackToMainMenu; - WNDBackToMainMenu = NULL; - return; - } - break; - - case BACKTOMAIN: - if(global::s2->getMapObj() != NULL) - global::s2->delMapObj(); - WNDBackToMainMenu->setWaste(); - WNDBackToMainMenu = NULL; - mainmenu(INITIALIZING_CALL); - break; - - case WINDOWQUIT: - if(WNDBackToMainMenu != NULL) - { - WNDBackToMainMenu->setWaste(); - WNDBackToMainMenu = NULL; - } - break; - - default: break; - } -} -#endif - -void callback::MinimapMenu(int Param) -{ - static CWindow* WNDMinimap = NULL; - static CMap* MapObj = NULL; - static SDL_Surface* WndSurface = NULL; - static int num_x = 1, num_y = 1; - // only in case INITIALIZING_CALL needed to create the window - int width; - int height; - - enum - { - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDMinimap != NULL) - break; - - // this variables are needed to reduce the size of minimap-windows of big maps - num_x = (global::s2->getMapObj()->getMap()->width > 256 ? global::s2->getMapObj()->getMap()->width / 256 : 1); - num_y = (global::s2->getMapObj()->getMap()->height > 256 ? global::s2->getMapObj()->getMap()->height / 256 : 1); - - // make sure the minimap has the same proportions as the "real" map, so scale the same rate - num_x = (num_x > num_y ? num_x : num_y); - num_y = (num_x > num_y ? num_x : num_y); - - width = global::s2->getMapObj()->getMap()->width / num_x; - height = global::s2->getMapObj()->getMap()->height / num_y; - //--> 12px is width of left and right window frame and 30px is height of the upper and lower window frame - if((global::s2->getDisplaySurface()->w - 12 < width) || (global::s2->getDisplaySurface()->h - 30 < height)) - break; - WNDMinimap = new CWindow(MinimapMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - width / 2 - 6, - global::s2->GameResolutionY / 2 - height / 2 - 15, width + 12, height + 30, "Overview", WINDOW_NOTHING, - WINDOW_CLOSE | WINDOW_MOVE); - if(global::s2->RegisterWindow(WNDMinimap) && global::s2->RegisterCallback(MinimapMenu)) - { - WndSurface = WNDMinimap->getSurface(); - MapObj = global::s2->getMapObj(); - } else - { - delete WNDMinimap; - WNDMinimap = NULL; - return; - } - break; - - case CALL_FROM_GAMELOOP: - if(MapObj != NULL && WndSurface != NULL) - MapObj->drawMinimap(WndSurface); - break; - - case WINDOW_CLICKED_CALL: - if(MapObj != NULL) - { - int MouseX, MouseY; - if(SDL_GetMouseState(&MouseX, &MouseY) & SDL_BUTTON(1)) - { - if(MouseX > (WNDMinimap->getX() + 6) && MouseX < (WNDMinimap->getX() + WNDMinimap->getW() - 6) - && MouseY > (WNDMinimap->getY() + 20) && MouseY < (WNDMinimap->getY() + WNDMinimap->getH() - 10)) - { - DisplayRectangle displayRect = MapObj->getDisplayRect(); - displayRect.x = - (MouseX - WNDMinimap->getX() - 6 - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx) * TRIANGLE_WIDTH * num_x; - displayRect.y = - (MouseY - WNDMinimap->getY() - 20 - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny) * TRIANGLE_HEIGHT * num_y; - MapObj->setDisplayRect(displayRect); - } - } - } - break; - - case WINDOWQUIT: - if(WNDMinimap != NULL) - { - WNDMinimap->setWaste(); - WNDMinimap = NULL; - } - MapObj = NULL; - WndSurface = NULL; - global::s2->UnregisterCallback(MinimapMenu); - break; - - case MAP_QUIT: - // we do the same like in case WINDOWQUIT - if(WNDMinimap != NULL) - { - WNDMinimap->setWaste(); - WNDMinimap = NULL; - } - MapObj = NULL; - WndSurface = NULL; - global::s2->UnregisterCallback(MinimapMenu); - break; - - default: break; - } -} - -#ifdef _ADMINMODE -// the debugger is an object and a friend class of all other classes -// debugger-function only will construct a new debugger and if debugger-function gets a window-quit-message -// then the debugger-function will destruct the object -void callback::debugger(int Param) -{ - static CDebug* Debugger = NULL; - - switch(Param) - { - case INITIALIZING_CALL: - if(Debugger != NULL) - break; - Debugger = new CDebug(debugger, DEBUGGER_QUIT); - break; - - case DEBUGGER_QUIT: - delete Debugger; - Debugger = NULL; - break; - - default: - if(Debugger != NULL) - Debugger->sendParam(Param); - break; - } -} - -// this is the picture-viewer -void callback::viewer(int Param) -{ - static CWindow* WNDViewer = NULL; - static int index = 0; - static int PicInWndIndex = -1; - static char PicInfos[50]; - static CFont* PicInfosText = NULL; - - enum - { - BACKWARD_1, - BACKWARD_10, - BACKWARD_100, - FORWARD_1, - FORWARD_10, - FORWARD_100, - WINDOWQUIT - }; - - switch(Param) - { - case INITIALIZING_CALL: - if(WNDViewer != NULL) - break; - WNDViewer = new CWindow(viewer, WINDOWQUIT, 0, 0, 250, 140, "Viewer", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MOVE | WINDOW_RESIZE | WINDOW_MINIMIZE); - if(global::s2->RegisterWindow(WNDViewer)) - { - global::s2->RegisterCallback(viewer); - WNDViewer->addButton(viewer, BACKWARD_100, 0, 0, 35, 20, BUTTON_GREY, "100<-"); - WNDViewer->addButton(viewer, BACKWARD_10, 35, 0, 35, 20, BUTTON_GREY, "10<-"); - WNDViewer->addButton(viewer, BACKWARD_1, 70, 0, 35, 20, BUTTON_GREY, "1<-"); - WNDViewer->addButton(viewer, FORWARD_1, 105, 0, 35, 20, BUTTON_GREY, "->1"); - WNDViewer->addButton(viewer, FORWARD_10, 140, 0, 35, 20, BUTTON_GREY, "->10"); - WNDViewer->addButton(viewer, FORWARD_100, 175, 0, 35, 20, BUTTON_GREY, "->100"); - } else - { - delete WNDViewer; - WNDViewer = NULL; - return; - } - break; - - case CALL_FROM_GAMELOOP: - if(PicInWndIndex >= 0) - WNDViewer->delStaticPicture(PicInWndIndex); - PicInWndIndex = WNDViewer->addStaticPicture(5, 30, index); - - if(PicInfosText != NULL) - { - WNDViewer->delText(PicInfosText); - PicInfosText = NULL; - } - if(PicInfosText == NULL) - { - sprintf(PicInfos, "index=%d, w=%d, h=%d, nx=%d, ny=%d", index, global::bmpArray[index].w, global::bmpArray[index].h, - global::bmpArray[index].nx, global::bmpArray[index].ny); - PicInfosText = WNDViewer->addText(PicInfos, 220, 3, 14, FONT_RED); - } - - break; - - case BACKWARD_100: - if(index - 100 >= 0) - index -= 100; - else - index = 0; - break; - case BACKWARD_10: - if(index - 10 >= 0) - index -= 10; - else - index = 0; - break; - case BACKWARD_1: - if(index - 1 >= 0) - index -= 1; - else - index = 0; - break; - case FORWARD_1: - if(index < MAXBOBBMP - 1) - index++; - break; - case FORWARD_10: - if(index + 10 < MAXBOBBMP - 1) - index += 10; - break; - case FORWARD_100: - if(index + 100 < MAXBOBBMP - 1) - index += 100; - break; - - case WINDOWQUIT: - if(WNDViewer != NULL) - { - WNDViewer->setWaste(); - WNDViewer = NULL; - global::s2->UnregisterCallback(viewer); - index = 0; - PicInWndIndex = -1; - } - break; - - default: break; - } -} - -// this is a submenu for testing -void callback::submenu1(int Param) -{ - static CMenu* SubMenu = NULL; - static CButton* greatMoon = NULL; - static CFont* greatMoonText = NULL; - static CFont* counterText = NULL; - static CPicture* picObject = NULL; - static int counter = 0; - static CWindow* testWindow = NULL; - static CWindow* testWindow2 = NULL; - static CPicture* testWindowPicture = NULL; - static CFont* testWindowText = NULL; - static CFont* testWindowText2 = NULL; - static CTextfield* testTextfield = NULL; - static CFont* TextFrom_testTextfield = NULL; - static CTextfield* testTextfield_testWindow = NULL; - static CSelectBox* testSelectBox = NULL; - - static int picIndex = -1; - char puffer[80]; - - // if this is the first time the function is called - if(Param == INITIALIZING_CALL) - global::s2->RegisterCallback(submenu1); - - enum - { - MAINMENU = 1, - GREATMOON, - SMALLMOON, - TOOSMALL, - CREATEWINDOW, - GREATMOONENTRY, - GREATMOONLEAVE, - PICOBJECT, - PICOBJECTENTRY, - PICOBJECTLEAVE, - TESTWINDOWPICTURE, - TESTWINDOWPICTUREENTRY, - TESTWINDOWPICTURELEAVE, - TESTWINDOWQUITMESSAGE, - TESTWINDOW2QUITMESSAGE, - SELECTBOX_OPTION1, - SELECTBOX_OPTION2, - SELECTBOX_OPTION3 - }; - - switch(Param) - { - case INITIALIZING_CALL: - SubMenu = new CMenu(SPLASHSCREEN_SUBMENU1); - if(!global::s2->RegisterMenu(SubMenu)) - { - delete SubMenu; - SubMenu = NULL; - return; - } - SubMenu->addButton(submenu1, MAINMENU, 400, 440, 200, 20, BUTTON_RED1, "back"); - greatMoon = SubMenu->addButton(submenu1, GREATMOON, 100, 100, 200, 200, BUTTON_STONE, NULL, MOON); - greatMoon->setMotionParams(GREATMOONENTRY, GREATMOONLEAVE); - SubMenu->addButton(submenu1, SMALLMOON, 100, 350, global::bmpArray[MOON].w, global::bmpArray[MOON].h, BUTTON_STONE, NULL, MOON); - SubMenu->addButton(submenu1, TOOSMALL, 100, 400, global::bmpArray[MOON].w - 1, global::bmpArray[MOON].h - 1, BUTTON_STONE, NULL, - MOON); - SubMenu->addButton(submenu1, CREATEWINDOW, 500, 10, 130, 30, BUTTON_GREEN1, "Create window"); - picObject = SubMenu->addPicture(submenu1, PICOBJECT, 200, 30, MIS0BOBS_SHIP); - picObject->setMotionParams(PICOBJECTENTRY, PICOBJECTLEAVE); - // text block with \n - sprintf(puffer, "\nTextblock:\n\nNeue Zeile\nNoch eine neue Zeile"); - SubMenu->addText(puffer, 400, 200, 14); - testTextfield = SubMenu->addTextfield(400, 300, 10, 3); - testSelectBox = SubMenu->addSelectBox(500, 500, 300, 200); - testSelectBox->setOption("Erste Option", submenu1, SELECTBOX_OPTION1); - testSelectBox->setOption("Zweite Option", submenu1, SELECTBOX_OPTION2); - testSelectBox->setOption("Dritte Option", submenu1, SELECTBOX_OPTION3); - break; - - case MAINMENU: - SubMenu->setWaste(); - SubMenu = NULL; - greatMoon = NULL; - greatMoonText = NULL; - counterText = NULL; - testWindowPicture = NULL; - testWindowText = NULL; - testWindowText2 = NULL; - testTextfield = NULL; - TextFrom_testTextfield = NULL; - testTextfield_testWindow = NULL; - testSelectBox = NULL; - global::s2->UnregisterCallback(submenu1); - if(testWindow != NULL) - { - testWindow->setWaste(); - testWindow = NULL; - } - if(testWindow2 != NULL) - { - testWindow2->setWaste(); - testWindow2 = NULL; - } - picIndex = -1; - break; - - case GREATMOON: - SubMenu->addText("Title!", 300, 10, 14); - sprintf(puffer, "Window X: %d Window Y: %d", global::s2->GameResolutionX, global::s2->GameResolutionY); - SubMenu->addText(puffer, 10, 10, 14); - break; - - case SMALLMOON: - SubMenu->delButton(greatMoon); - SubMenu->delStaticPicture(picIndex); - picIndex = -1; - break; - - case TOOSMALL: - if(picIndex == -1) - picIndex = SubMenu->addStaticPicture(0, 0, MAINFRAME_640_480); - break; - - case CREATEWINDOW: - if(testWindow == NULL) - { - testWindow = new CWindow(submenu1, TESTWINDOWQUITMESSAGE, 5, 5, 350, 240, "Window", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); - if(global::s2->RegisterWindow(testWindow)) - { - testWindow->addText("Text inside the window", 10, 10, 14); - testWindow->addButton(submenu1, -10, 150, 100, 210, 30, BUTTON_GREEN2, "Button inside the window"); - testWindowPicture = testWindow->addPicture(submenu1, TESTWINDOWPICTURE, 10, 60, MIS2BOBS_FORTRESS); - testWindowPicture->setMotionParams(TESTWINDOWPICTUREENTRY, TESTWINDOWPICTURELEAVE); - testTextfield_testWindow = testWindow->addTextfield(130, 30, 10, 3, 14, FONT_RED, BUTTON_GREY, true); - testTextfield_testWindow->setText( - "This is a very long test text in order to destroy the text field completely once and for all"); - } else - { - delete testWindow; - testWindow = NULL; - return; - } - } - if(testWindow2 == NULL) - { - testWindow2 = new CWindow(submenu1, TESTWINDOW2QUITMESSAGE, 200, 5, 350, 240, "Another Window", WINDOW_GREEN1, - WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); - if(global::s2->RegisterWindow(testWindow2)) - { - testWindow2->addText("Text inside the window", 50, 40, 9); - testWindow2->addButton(submenu1, -10, 100, 100, 100, 20, BUTTON_GREEN2, "Button"); - } else - { - delete testWindow2; - testWindow2 = NULL; - return; - } - } - break; - - case GREATMOONENTRY: - if(greatMoonText == NULL) - greatMoonText = SubMenu->addText("Test-Text", 100, 10, 14); - break; - - case GREATMOONLEAVE: - if(greatMoonText != NULL) - { - SubMenu->delText(greatMoonText); - greatMoonText = NULL; - } - break; - - case PICOBJECT: - if(greatMoon != NULL) - { - SubMenu->delButton(greatMoon); - greatMoon = NULL; - } - break; - - case PICOBJECTENTRY: - if(greatMoonText == NULL) - greatMoonText = SubMenu->addText("Test-Text", 100, 10, 14); - break; - - case PICOBJECTLEAVE: - if(greatMoonText != NULL) - { - SubMenu->delText(greatMoonText); - greatMoonText = NULL; - } - break; - - case TESTWINDOWPICTURE: - if(testWindowText == NULL) - testWindowText = testWindow->addText("Clicked on castle", 10, 200, 11); - else - { - testWindow->delText(testWindowText); - testWindowText = NULL; - } - break; - - case TESTWINDOWPICTUREENTRY: - if(testWindowText2 != NULL) - { - testWindow->delText(testWindowText2); - testWindowText2 = NULL; - } - testWindowText2 = testWindow->addText("Bildbereich betreten", 10, 220, 11); - break; - - case TESTWINDOWPICTURELEAVE: - if(testWindowText2 != NULL) - { - testWindow->delText(testWindowText2); - testWindowText2 = NULL; - } - testWindowText2 = testWindow->addText("Bildbereich verlassen", 10, 220, 11); - break; - - case TESTWINDOWQUITMESSAGE: - testWindow->setWaste(); - testWindow = NULL; - break; - - case TESTWINDOW2QUITMESSAGE: - testWindow2->setWaste(); - testWindow2 = NULL; - break; - - case CALL_FROM_GAMELOOP: - if(counter % 10 == 0) - { - if(counterText != NULL) - { - SubMenu->delText(counterText); - counterText = NULL; - } - if(counterText == NULL) - { - sprintf(puffer, "counter: %d", counter); - counterText = SubMenu->addText(puffer, 100, 20, 9); - } - - if(TextFrom_testTextfield != NULL) - { - SubMenu->delText(TextFrom_testTextfield); - TextFrom_testTextfield = NULL; - } - sprintf(puffer, "Der Text im Textfeld lautet: %s", testTextfield->getText()); - TextFrom_testTextfield = SubMenu->addText(puffer, 200, 400, 14); - } - counter++; - break; - - default: break; - } -} -#endif +#include "callbacks.h" +#include "CDebug.h" +#include "CGame.h" +#include "CIO/CButton.h" +#include "CIO/CFile.h" +#include "CIO/CFont.h" +#include "CIO/CMenu.h" +#include "CIO/CPicture.h" +#include "CIO/CSelectBox.h" +#include "CIO/CTextfield.h" +#include "CIO/CWindow.h" +#include "CMap.h" +#include "CSurface.h" +#include "globals.h" + +void callback::PleaseWait(int Param) +{ + // NOTE: This "Please wait"-window is shown until the PleaseWait-callback is called with 'WINDOW_QUIT_MESSAGE'. + // The window will be registered by the game. To do it the other way (create and then let it automatically + // destroy by the gameloop), you don't need to register the window, but register the callback. + + static CWindow* WNDWait; + + enum + { + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDWait != NULL) + break; + WNDWait = new CWindow(PleaseWait, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 106, + global::s2->getDisplaySurface()->h / 2 - 35, 212, 70, "Please wait"); + if(global::s2->RegisterWindow(WNDWait)) + { + // we don't register this window cause we will destroy it manually if we need + // global::s2->RegisterCallback(PleaseWait); + + WNDWait->addText("Please wait ...", 10, 10, 14); + // we need to render this window NOW, cause the render loop will do it too late (when the operation + // is done and we don't need the "Please wait"-window anymore) + CSurface::Draw(global::s2->getDisplaySurface(), WNDWait->getSurface(), global::s2->getDisplaySurface()->w / 2 - 106, + global::s2->getDisplaySurface()->h / 2 - 35); + SDL_Flip(global::s2->getDisplaySurface()); + } else + { + delete WNDWait; + WNDWait = NULL; + return; + } + break; + + case CALL_FROM_GAMELOOP: // This window gives a "Please Wait"-string, so it is shown while there is an intensive operation + // during ONE gameloop. Therefore it is only shown DURING this ONE operation. If the next gameloop + // appears, the operation MUST have been finished and we can destroy this window. + if(WNDWait != NULL) + { + global::s2->UnregisterCallback(PleaseWait); + WNDWait->setWaste(); + WNDWait = NULL; + } + break; + + case WINDOW_QUIT_MESSAGE: // this is the global window quit message, callback is explicit called with this value, so destroy the + // window + if(WNDWait != NULL) + { + WNDWait->setWaste(); + WNDWait = NULL; + } + break; + + default: break; + } +} + +void callback::ShowStatus(int Param) +{ + static CWindow* WND = NULL; + static CFont* txt = NULL; + + enum + { + WINDOWQUIT, + SHOW_SUCCESS, + SHOW_FAILURE + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WND != NULL) + break; + WND = + new CWindow(ShowStatus, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 106, global::s2->getDisplaySurface()->h / 2 - 35, + 250, 90, "Status", WINDOW_GREEN1, WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WND)) + { + txt = WND->addText("", 26, 20, 14, FONT_YELLOW); + } else + { + delete WND; + WND = NULL; + return; + } + break; + case SHOW_SUCCESS: + txt->setText("Operation finished successfully"); + txt->setColor(FONT_GREEN); + break; + case SHOW_FAILURE: + txt->setText("Operation failed! :("); + txt->setColor(FONT_RED_BRIGHT); + break; + + case WINDOWQUIT: + case MAP_QUIT: + if(WND != NULL) + { + WND->setWaste(); + WND = NULL; + } + break; + + default: break; + } +} + +void callback::mainmenu(int Param) +{ + static CMenu* MainMenu = NULL; + + enum + { + ENDGAME = 1, + STARTEDITOR, + OPTIONS + }; + + switch(Param) + { + case INITIALIZING_CALL: + MainMenu = new CMenu(SPLASHSCREEN_MAINMENU); + if(!global::s2->RegisterMenu(MainMenu)) + { + delete MainMenu; + MainMenu = NULL; + return; + } + MainMenu->addButton(mainmenu, ENDGAME, 50, 400, 200, 20, BUTTON_RED1, "Quit program"); +#ifdef _ADMINMODE + MainMenu->addButton(submenu1, INITIALIZING_CALL, 50, 200, 200, 20, BUTTON_GREY, "Submenu_1"); +#endif + MainMenu->addButton(mainmenu, STARTEDITOR, 50, 160, 200, 20, BUTTON_RED1, "Start editor"); + MainMenu->addButton(mainmenu, OPTIONS, 50, 370, 200, 20, BUTTON_GREEN2, "Options"); + break; + + case CALL_FROM_GAMELOOP: break; + + case ENDGAME: + MainMenu->setWaste(); + MainMenu = NULL; + global::s2->Running = false; + break; + + case STARTEDITOR: + PleaseWait(INITIALIZING_CALL); + global::s2->setMapObj(new CMap("")); + MainMenu->setWaste(); + MainMenu = NULL; + PleaseWait(WINDOW_QUIT_MESSAGE); + break; + + case OPTIONS: + MainMenu->setWaste(); + MainMenu = NULL; + submenuOptions(INITIALIZING_CALL); + + default: break; + } +} + +void callback::submenuOptions(int Param) +{ + static CMenu* SubMenu = NULL; + static CFont* TextResolution = NULL; + static CButton* ButtonFullscreen = NULL; + static CButton* ButtonOpenGL = NULL; + char puffer[80]; + static CSelectBox* SelectBoxRes = NULL; + + enum + { + MAINMENU = 1, + FULLSCREEN, + OPENGL, + GRAPHICS_CHANGE, + SELECTBOX_800_600, + SELECTBOX_832_624, + SELECTBOX_960_540, + SELECTBOX_964_544, + SELECTBOX_960_640, + SELECTBOX_960_720, + SELECTBOX_1024_576, + SELECTBOX_1024_600, + SELECTBOX_1072_600, + SELECTBOX_1152_768, + SELECTBOX_1024_768, + SELECTBOX_1152_864, + SELECTBOX_1152_870, + SELECTBOX_1152_900, + SELECTBOX_1200_800, + SELECTBOX_1200_900, + SELECTBOX_1280_720, + SELECTBOX_1280_768, + SELECTBOX_1280_800, + SELECTBOX_1280_854, + SELECTBOX_1360_768, + SELECTBOX_1366_768, + SELECTBOX_1376_768, + SELECTBOX_1400_900, + SELECTBOX_1440_900, + SELECTBOX_1440_960, + SELECTBOX_1280_960, + SELECTBOX_1280_1024, + SELECTBOX_1360_1024, + SELECTBOX_1366_1024, + SELECTBOX_1600_768, + SELECTBOX_1600_900, + SELECTBOX_1600_1024, + SELECTBOX_1400_1050, + SELECTBOX_1680_1050, + SELECTBOX_1600_1200, + SELECTBOX_1920_1080, + SELECTBOX_1920_1200, + SELECTBOX_1920_1400, + SELECTBOX_1920_1440, + SELECTBOX_2048_1152, + SELECTBOX_2048_1536 + }; + + switch(Param) + { + case INITIALIZING_CALL: + SubMenu = new CMenu(SPLASHSCREEN_SUBMENU3); + if(!global::s2->RegisterMenu(SubMenu)) + { + delete SubMenu; + TextResolution = NULL; + ButtonFullscreen = NULL; + SelectBoxRes = NULL; + SubMenu = NULL; + return; + } + // add button for "back to main menu" + SubMenu->addButton(submenuOptions, MAINMENU, (int)(global::s2->GameResolutionX / 2 - 100), 440, 200, 20, BUTTON_RED1, "back"); + // add menu title + SubMenu->addText("Options", (int)(global::s2->GameResolutionX / 2 - 20), 10, 14); + // add screen resolution + if(TextResolution != NULL) + SubMenu->delText(TextResolution); + sprintf(puffer, "Game Resolution: %d*%d / %s", global::s2->GameResolutionX, global::s2->GameResolutionY, + (global::s2->fullscreen ? "Fullscreen" : "Window")); + TextResolution = SubMenu->addText(puffer, (int)(global::s2->GameResolutionX / 2 - 110), 50, 11); + if(ButtonFullscreen != NULL) + SubMenu->delButton(ButtonFullscreen); + ButtonFullscreen = SubMenu->addButton(submenuOptions, FULLSCREEN, (int)(global::s2->GameResolutionX / 2 - 100), 190, 200, 20, + BUTTON_RED1, (global::s2->fullscreen ? "WINDOW" : "FULLSCREEN")); + if(ButtonOpenGL != NULL) + SubMenu->delButton(ButtonOpenGL); + // ButtonOpenGL = SubMenu->addButton(submenuOptions, OPENGL, (int)(global::s2->GameResolutionX/2-100), 210, 200, 20, + // BUTTON_RED1, (CSurface::useOpenGL ? "Software-Rendering" : "OpenGL")); add selectbox for resolutions + SelectBoxRes = SubMenu->addSelectBox((int)(global::s2->GameResolutionX / 2 - 100), 70, 200, 110, 11, FONT_YELLOW, BUTTON_GREY); + SelectBoxRes->setOption("800 x 600 (SVGA)", submenuOptions, SELECTBOX_800_600); + SelectBoxRes->setOption("832 x 624 (Half Megapixel)", submenuOptions, SELECTBOX_832_624); + SelectBoxRes->setOption("960 x 540 (QHD)", submenuOptions, SELECTBOX_960_540); + SelectBoxRes->setOption("964 x 544", submenuOptions, SELECTBOX_964_544); + SelectBoxRes->setOption("960 x 640 (DVGA)", submenuOptions, SELECTBOX_960_640); + SelectBoxRes->setOption("960 x 720", submenuOptions, SELECTBOX_960_720); + SelectBoxRes->setOption("1024 x 576 (WXGA)", submenuOptions, SELECTBOX_1024_576); + SelectBoxRes->setOption("1024 x 600 (WSVGA)", submenuOptions, SELECTBOX_1024_600); + SelectBoxRes->setOption("1072 x 600 (WSVGA)", submenuOptions, SELECTBOX_1072_600); + SelectBoxRes->setOption("1152 x 768", submenuOptions, SELECTBOX_1152_768); + SelectBoxRes->setOption("1024 x 768 (EVGA)", submenuOptions, SELECTBOX_1024_768); + SelectBoxRes->setOption("1152 x 864 (XGA)", submenuOptions, SELECTBOX_1152_864); + SelectBoxRes->setOption("1152 x 870 (XGA)", submenuOptions, SELECTBOX_1152_870); + SelectBoxRes->setOption("1152 x 900 (XGA)", submenuOptions, SELECTBOX_1152_900); + SelectBoxRes->setOption("1200 x 800 (DSVGA)", submenuOptions, SELECTBOX_1200_800); + SelectBoxRes->setOption("1200 x 900 (OLPC)", submenuOptions, SELECTBOX_1200_900); + SelectBoxRes->setOption("1280 x 720 (720p)", submenuOptions, SELECTBOX_1280_720); + SelectBoxRes->setOption("1280 x 768 (WXGA)", submenuOptions, SELECTBOX_1280_768); + SelectBoxRes->setOption("1280 x 800 (WXGA)", submenuOptions, SELECTBOX_1280_800); + SelectBoxRes->setOption("1280 x 854 (WXGA)", submenuOptions, SELECTBOX_1280_854); + SelectBoxRes->setOption("1360 x 768 (WXGA)", submenuOptions, SELECTBOX_1360_768); + SelectBoxRes->setOption("1366 x 768 (WXGA)", submenuOptions, SELECTBOX_1366_768); + SelectBoxRes->setOption("1376 x 768 (WXGA)", submenuOptions, SELECTBOX_1376_768); + SelectBoxRes->setOption("1400 x 900 (WXGA+)", submenuOptions, SELECTBOX_1400_900); + SelectBoxRes->setOption("1440 x 900 (WXGA+)", submenuOptions, SELECTBOX_1440_900); + SelectBoxRes->setOption("1440 x 960", submenuOptions, SELECTBOX_1440_960); + SelectBoxRes->setOption("1280 x 960 (SXGA)", submenuOptions, SELECTBOX_1280_960); + SelectBoxRes->setOption("1280 x 1024 (SXGA)", submenuOptions, SELECTBOX_1280_1024); + SelectBoxRes->setOption("1360 x 1024 (XGA-2)", submenuOptions, SELECTBOX_1360_1024); + SelectBoxRes->setOption("1366 x 1024 (XGA-2)", submenuOptions, SELECTBOX_1366_1024); + SelectBoxRes->setOption("1600 x 768 (UWXGA)", submenuOptions, SELECTBOX_1600_768); + SelectBoxRes->setOption("1600 x 900 (WSXGA)", submenuOptions, SELECTBOX_1600_900); + SelectBoxRes->setOption("1600 x 1024 (WSXGA)", submenuOptions, SELECTBOX_1600_1024); + SelectBoxRes->setOption("1400 x 1050 (SXGA+)", submenuOptions, SELECTBOX_1400_1050); + SelectBoxRes->setOption("1680 x 1050 (WSXGA+)", submenuOptions, SELECTBOX_1680_1050); + SelectBoxRes->setOption("1600 x 1200 (UXGA)", submenuOptions, SELECTBOX_1600_1200); + SelectBoxRes->setOption("1920 x 1080 (1080p)", submenuOptions, SELECTBOX_1920_1080); + SelectBoxRes->setOption("1920 x 1200 (WUXGA)", submenuOptions, SELECTBOX_1920_1200); + SelectBoxRes->setOption("1920 x 1400 (TXGA)", submenuOptions, SELECTBOX_1920_1400); + SelectBoxRes->setOption("1920 x 1440", submenuOptions, SELECTBOX_1920_1440); + SelectBoxRes->setOption("2048 x 1152 (QWXGA)", submenuOptions, SELECTBOX_2048_1152); + SelectBoxRes->setOption("2048 x 1536 (SUXGA)", submenuOptions, SELECTBOX_2048_1536); + break; + + case MAINMENU: + SubMenu->setWaste(); + TextResolution = NULL; + ButtonFullscreen = NULL; + ButtonOpenGL = NULL; + SelectBoxRes = NULL; + SubMenu = NULL; + mainmenu(INITIALIZING_CALL); + break; + + case FULLSCREEN: + if(global::s2->fullscreen) + global::s2->fullscreen = false; + else + global::s2->fullscreen = true; + + submenuOptions(GRAPHICS_CHANGE); + break; + + case OPENGL: + if(CSurface::useOpenGL) + CSurface::useOpenGL = false; + else + CSurface::useOpenGL = true; + + submenuOptions(GRAPHICS_CHANGE); + break; + + case GRAPHICS_CHANGE: + SubMenu->setWaste(); + TextResolution = NULL; + ButtonFullscreen = NULL; + ButtonOpenGL = NULL; + SelectBoxRes = NULL; + SubMenu = NULL; + submenuOptions(INITIALIZING_CALL); + break; + + case SELECTBOX_800_600: + global::s2->GameResolutionX = 800; + global::s2->GameResolutionY = 600; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_832_624: + global::s2->GameResolutionX = 832; + global::s2->GameResolutionY = 624; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_960_540: + global::s2->GameResolutionX = 960; + global::s2->GameResolutionY = 540; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_964_544: + global::s2->GameResolutionX = 964; + global::s2->GameResolutionY = 544; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_960_640: + global::s2->GameResolutionX = 960; + global::s2->GameResolutionY = 640; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_960_720: + global::s2->GameResolutionX = 960; + global::s2->GameResolutionY = 720; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1024_576: + global::s2->GameResolutionX = 1024; + global::s2->GameResolutionY = 576; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1024_600: + global::s2->GameResolutionX = 1024; + global::s2->GameResolutionY = 600; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1072_600: + global::s2->GameResolutionX = 1072; + global::s2->GameResolutionY = 600; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1152_768: + global::s2->GameResolutionX = 1152; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1024_768: + global::s2->GameResolutionX = 1024; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1152_864: + global::s2->GameResolutionX = 1152; + global::s2->GameResolutionY = 864; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1152_870: + global::s2->GameResolutionX = 1152; + global::s2->GameResolutionY = 870; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1152_900: + global::s2->GameResolutionX = 1152; + global::s2->GameResolutionY = 900; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1200_800: + global::s2->GameResolutionX = 1200; + global::s2->GameResolutionY = 800; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1200_900: + global::s2->GameResolutionX = 1200; + global::s2->GameResolutionY = 900; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1280_720: + global::s2->GameResolutionX = 1280; + global::s2->GameResolutionY = 720; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1280_768: + global::s2->GameResolutionX = 1280; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1280_800: + global::s2->GameResolutionX = 1280; + global::s2->GameResolutionY = 800; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1280_854: + global::s2->GameResolutionX = 1280; + global::s2->GameResolutionY = 854; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1360_768: + global::s2->GameResolutionX = 1360; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1366_768: + global::s2->GameResolutionX = 1366; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1376_768: + global::s2->GameResolutionX = 1376; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1400_900: + global::s2->GameResolutionX = 1400; + global::s2->GameResolutionY = 900; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1440_900: + global::s2->GameResolutionX = 1440; + global::s2->GameResolutionY = 900; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1440_960: + global::s2->GameResolutionX = 1440; + global::s2->GameResolutionY = 960; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1280_960: + global::s2->GameResolutionX = 1280; + global::s2->GameResolutionY = 960; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1280_1024: + global::s2->GameResolutionX = 1280; + global::s2->GameResolutionY = 1024; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1360_1024: + global::s2->GameResolutionX = 1360; + global::s2->GameResolutionY = 1024; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1366_1024: + global::s2->GameResolutionX = 1366; + global::s2->GameResolutionY = 1024; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1600_768: + global::s2->GameResolutionX = 1600; + global::s2->GameResolutionY = 768; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1600_900: + global::s2->GameResolutionX = 1600; + global::s2->GameResolutionY = 900; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1600_1024: + global::s2->GameResolutionX = 1600; + global::s2->GameResolutionY = 1024; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1400_1050: + global::s2->GameResolutionX = 1400; + global::s2->GameResolutionY = 1050; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1680_1050: + global::s2->GameResolutionX = 1680; + global::s2->GameResolutionY = 1050; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1600_1200: + global::s2->GameResolutionX = 1600; + global::s2->GameResolutionY = 1200; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1920_1080: + global::s2->GameResolutionX = 1920; + global::s2->GameResolutionY = 1080; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1920_1200: + global::s2->GameResolutionX = 1920; + global::s2->GameResolutionY = 1200; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1920_1400: + global::s2->GameResolutionX = 1920; + global::s2->GameResolutionY = 1400; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_1920_1440: + global::s2->GameResolutionX = 1920; + global::s2->GameResolutionY = 1440; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_2048_1152: + global::s2->GameResolutionX = 2048; + global::s2->GameResolutionY = 1152; + submenuOptions(GRAPHICS_CHANGE); + break; + + case SELECTBOX_2048_1536: + global::s2->GameResolutionX = 2048; + global::s2->GameResolutionY = 1536; + submenuOptions(GRAPHICS_CHANGE); + break; + + default: break; + } +} + +#ifdef _EDITORMODE +// now the editor callbacks will follow (editor mode) + +void callback::EditorHelpMenu(int Param) +{ + // NOTE: This "Please wait"-window is shown until the PleaseWait-callback is called with 'WINDOW_QUIT_MESSAGE'. + // The window will be registered by the game. To do it the other way (create and then let it automatically + // destroy by the gameloop), you don't need to register the window, but register the callback. + + static CWindow* WNDHelp; + static CSelectBox* SelectBoxHelp; + + enum + { + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDHelp != NULL) + break; + WNDHelp = new CWindow(EditorHelpMenu, WINDOWQUIT, global::s2->getDisplaySurface()->w / 2 - 320, + global::s2->getDisplaySurface()->h / 2 - 240, 640, 380, "Hilfe", WINDOW_GREEN2, + WINDOW_CLOSE | WINDOW_MOVE | WINDOW_RESIZE | WINDOW_MINIMIZE); + if(global::s2->RegisterWindow(WNDHelp)) + { + // we don't register this window cause we will destroy it manually if we need + // global::s2->RegisterCallback(PleaseWait); + + SelectBoxHelp = WNDHelp->addSelectBox(0, 20, 635, 345, 11, FONT_YELLOW, BUTTON_GREEN1); + SelectBoxHelp->setOption( + "Help-Menu......................................................................................................F1\n"); + SelectBoxHelp->setOption( + "Window/Fullscreen........................................................................................F2\n"); + SelectBoxHelp->setOption("Zoom in/normal/out " + "(experimental)..............................................................F5/F6/" + "F7\n"); + SelectBoxHelp->setOption("Scroll..........................................................................................." + "..................Arrow keys\n"); + SelectBoxHelp->setOption( + "Cursor size 1-9 (of 11)....................................................................................1-9\n"); + SelectBoxHelp->setOption( + "Make Cursor bigger/smaller........................................................................+/-\n"); + SelectBoxHelp->setOption( + "Scissors-Mode...............................................................................................Ctrl\n"); + SelectBoxHelp->setOption( + "Invert mode....................................................................................................Shift\n"); + SelectBoxHelp->setOption("(e.g. Lower altitude, remove player, lower resources)\n"); + SelectBoxHelp->setOption( + "Plane mode.....................................................................................................Alt\n"); + SelectBoxHelp->setOption( + "Reduce/default/enlarge maximum height.....................................................Ins/Pos1/" + "PageUp\n"); + SelectBoxHelp->setOption("(can't increase beyond this)\n"); + SelectBoxHelp->setOption("Reduce/default/enlarge minimum " + "height......................................................Del/End/" + "PageDown\n"); + SelectBoxHelp->setOption("(can't decrease below this)\n"); + SelectBoxHelp->setOption("Undo............................................................................................." + "...................Q\n"); + SelectBoxHelp->setOption("(just actions made with the cursor)\n"); + SelectBoxHelp->setOption( + "Build help on/off.............................................................................................Space\n"); + SelectBoxHelp->setOption( + "Castle-Mode....................................................................................................B\n"); + SelectBoxHelp->setOption("(planes the surrounding terrain\n"); + SelectBoxHelp->setOption(" so a castle can be build)\n"); + SelectBoxHelp->setOption( + "Harbour-Mode................................................................................................H\n"); + SelectBoxHelp->setOption("(changes the surrounding terrian,\n"); + SelectBoxHelp->setOption(" so that a harbour can be build)\n"); + SelectBoxHelp->setOption("Convert map \"on-the-fly\" (Greenland/Winterworld/Wasteland..................G/W/O\n"); + SelectBoxHelp->setOption( + "New/Original shadows (experimental)..........................................................P\n"); + SelectBoxHelp->setOption( + "Lock/Unlock horizontal movement................................................................F9\n"); + SelectBoxHelp->setOption( + "Lock/Unlock vertical movement....................................................................F10\n"); + SelectBoxHelp->setOption( + "Turn borders on/off......................................................................................F11\n"); + } else + { + delete WNDHelp; + WNDHelp = NULL; + SelectBoxHelp = NULL; + return; + } + break; + + case CALL_FROM_GAMELOOP: break; + + case WINDOW_QUIT_MESSAGE: // this is the global window quit message, callback is explicit called with this value, so destroy the + // window + if(WNDHelp != NULL) + { + WNDHelp->setWaste(); + WNDHelp = NULL; + SelectBoxHelp = NULL; + } + break; + + case WINDOWQUIT: // this is the own window quit message of the callback + if(WNDHelp != NULL) + { + WNDHelp->setWaste(); + WNDHelp = NULL; + SelectBoxHelp = NULL; + } + break; + + case MAP_QUIT: // this is the global window quit message, callback is explicit called with this value, so destroy the window + if(WNDHelp != NULL) + { + WNDHelp->setWaste(); + WNDHelp = NULL; + SelectBoxHelp = NULL; + } + break; + + default: break; + } +} + +void callback::EditorMainMenu(int Param) +{ + static CWindow* WNDMain = NULL; + + enum + { + LOADMENU, + SAVEMENU, + QUITMENU, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDMain != NULL) + break; + WNDMain = new CWindow(EditorMainMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 110, global::s2->GameResolutionY / 2 - 160, + 220, 320, "Main menu", WINDOW_GREEN1, WINDOW_CLOSE); + if(global::s2->RegisterWindow(WNDMain)) + { + WNDMain->addButton(EditorMainMenu, LOADMENU, 8, 100, 190, 20, BUTTON_GREEN2, "Load map"); + WNDMain->addButton(EditorMainMenu, SAVEMENU, 8, 125, 190, 20, BUTTON_GREEN2, "Save map"); + + WNDMain->addButton(EditorMainMenu, QUITMENU, 8, 260, 190, 20, BUTTON_GREEN2, "Leave editor"); + } else + { + delete WNDMain; + WNDMain = NULL; + return; + } + break; + + case WINDOWQUIT: + if(WNDMain != NULL) + { + WNDMain->setWaste(); + WNDMain = NULL; + } + break; + + case MAP_QUIT: + if(WNDMain != NULL) + { + WNDMain->setWaste(); + WNDMain = NULL; + } + break; + + case QUITMENU: EditorQuitMenu(INITIALIZING_CALL); break; + + case LOADMENU: EditorLoadMenu(INITIALIZING_CALL); break; + + case SAVEMENU: EditorSaveMenu(INITIALIZING_CALL); break; + + default: break; + } +} + +void callback::EditorLoadMenu(int Param) +{ + static CWindow* WNDLoad = NULL; + static CTextfield* TXTF_Filename = NULL; + static CMap* MapObj = NULL; + + enum + { + LOADMAP, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDLoad != NULL) + break; + WNDLoad = new CWindow(EditorLoadMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 140, global::s2->GameResolutionY / 2 - 45, + 280, 120, "Load", WINDOW_GREEN1, WINDOW_CLOSE); + if(global::s2->RegisterWindow(WNDLoad)) + { + MapObj = global::s2->getMapObj(); + + TXTF_Filename = WNDLoad->addTextfield(10, 10, 21, 1); + TXTF_Filename->setText("MyMap.WLD"); + WNDLoad->addButton(EditorLoadMenu, LOADMAP, 170, 40, 90, 20, BUTTON_GREY, "Load"); + WNDLoad->addButton(EditorLoadMenu, WINDOWQUIT, 170, 65, 90, 20, BUTTON_RED1, "Abort"); + } else + { + delete WNDLoad; + WNDLoad = NULL; + return; + } + break; + + case WINDOWQUIT: + if(WNDLoad != NULL) + { + WNDLoad->setWaste(); + WNDLoad = NULL; + } + TXTF_Filename = NULL; + break; + + case MAP_QUIT: + if(WNDLoad != NULL) + { + WNDLoad->setWaste(); + WNDLoad = NULL; + } + TXTF_Filename = NULL; + break; + + case LOADMAP: + PleaseWait(INITIALIZING_CALL); + + // we have to close the windows and initialize them again to prevent failures + EditorCursorMenu(MAP_QUIT); + EditorTextureMenu(MAP_QUIT); + EditorTreeMenu(MAP_QUIT); + EditorLandscapeMenu(MAP_QUIT); + MinimapMenu(MAP_QUIT); + EditorResourceMenu(MAP_QUIT); + EditorAnimalMenu(MAP_QUIT); + EditorPlayerMenu(MAP_QUIT); + + MapObj->destructMap(); + MapObj->constructMap(global::userMapsPath + "/" + TXTF_Filename->getText()); + + // we need to check which of these windows was active before + /* + EditorCursorMenu(INITIALIZING_CALL); + EditorTextureMenu(INITIALIZING_CALL); + EditorTreeMenu(INITIALIZING_CALL); + EditorLandscapeMenu(INITIALIZING_CALL); + MinimapMenu(INITIALIZING_CALL); + EditorResourceMenu(INITIALIZING_CALL); + EditorAnimalMenu(INITIALIZING_CALL); + EditorPlayerMenu(INITIALIZING_CALL); + */ + + PleaseWait(WINDOW_QUIT_MESSAGE); + EditorLoadMenu(WINDOWQUIT); + break; + + default: break; + } +} + +void callback::EditorSaveMenu(int Param) +{ + static CWindow* WNDSave = NULL; + static CTextfield* TXTF_Filename = NULL; + static CTextfield* TXTF_Mapname = NULL; + static CTextfield* TXTF_Author = NULL; + static CMap* MapObj = NULL; + + enum + { + SAVEMAP, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDSave != NULL) + break; + WNDSave = new CWindow(EditorSaveMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 140, global::s2->GameResolutionY / 2 - 100, + 280, 200, "Save", WINDOW_GREEN1, WINDOW_CLOSE); + if(global::s2->RegisterWindow(WNDSave)) + { + MapObj = global::s2->getMapObj(); + + WNDSave->addText("Filename", 100, 2, 9); + TXTF_Filename = WNDSave->addTextfield(10, 13, 21, 1); + TXTF_Filename->setText("MyMap.WLD"); + WNDSave->addText("Mapname", 98, 38, 9); + TXTF_Mapname = WNDSave->addTextfield(10, 50, 19, 1); + TXTF_Mapname->setText(MapObj->getMapname()); + WNDSave->addText("Author", 110, 75, 9); + TXTF_Author = WNDSave->addTextfield(10, 87, 19, 1); + TXTF_Author->setText(MapObj->getAuthor()); + WNDSave->addButton(EditorSaveMenu, SAVEMAP, 170, 120, 90, 20, BUTTON_GREY, "Save"); + WNDSave->addButton(EditorSaveMenu, WINDOWQUIT, 170, 145, 90, 20, BUTTON_RED1, "Abort"); + } else + { + delete WNDSave; + WNDSave = NULL; + return; + } + break; + + case WINDOWQUIT: + if(WNDSave != NULL) + { + WNDSave->setWaste(); + WNDSave = NULL; + } + TXTF_Filename = NULL; + TXTF_Mapname = NULL; + TXTF_Author = NULL; + break; + + case MAP_QUIT: + if(WNDSave != NULL) + { + WNDSave->setWaste(); + WNDSave = NULL; + } + TXTF_Filename = NULL; + TXTF_Mapname = NULL; + TXTF_Author = NULL; + break; + + case SAVEMAP: + { + PleaseWait(INITIALIZING_CALL); + + MapObj->setMapname(TXTF_Mapname->getText()); + MapObj->setAuthor(TXTF_Author->getText()); + bool result = CFile::save_file(global::userMapsPath + "/" + TXTF_Filename->getText(), WLD, MapObj->getMap()); + + ShowStatus(INITIALIZING_CALL); + ShowStatus(result ? 1 : 2); + + PleaseWait(WINDOW_QUIT_MESSAGE); + EditorSaveMenu(WINDOWQUIT); + break; + } + + default: break; + } +} + +void callback::EditorQuitMenu(int Param) +{ + static CWindow* WNDBackToMainMenu = NULL; + + enum + { + BACKTOMAIN = 1, + NOTBACKTOMAIN, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDBackToMainMenu != NULL) + break; + WNDBackToMainMenu = new CWindow(EditorQuitMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 106, + global::s2->GameResolutionY / 2 - 55, 212, 110, "Exit?"); + if(global::s2->RegisterWindow(WNDBackToMainMenu)) + { + WNDBackToMainMenu->addButton(EditorQuitMenu, BACKTOMAIN, 0, 0, 100, 80, BUTTON_GREEN2, NULL, PICTURE_SMALL_TICK); + WNDBackToMainMenu->addButton(EditorQuitMenu, NOTBACKTOMAIN, 100, 0, 100, 80, BUTTON_RED1, NULL, PICTURE_SMALL_CROSS); + } else + { + delete WNDBackToMainMenu; + WNDBackToMainMenu = NULL; + return; + } + break; + + case BACKTOMAIN: + if(global::s2->getMapObj() != NULL) + global::s2->delMapObj(); + WNDBackToMainMenu->setWaste(); + WNDBackToMainMenu = NULL; + // now call all EditorMenu callbacks (from the menubar) with MAP_QUIT + EditorHelpMenu(MAP_QUIT); + EditorMainMenu(MAP_QUIT); + EditorLoadMenu(MAP_QUIT); + EditorSaveMenu(MAP_QUIT); + EditorTextureMenu(MAP_QUIT); + EditorTreeMenu(MAP_QUIT); + EditorLandscapeMenu(MAP_QUIT); + MinimapMenu(MAP_QUIT); + EditorCursorMenu(MAP_QUIT); + EditorResourceMenu(MAP_QUIT); + EditorAnimalMenu(MAP_QUIT); + EditorPlayerMenu(MAP_QUIT); + EditorCreateMenu(MAP_QUIT); + // go to main menu + mainmenu(INITIALIZING_CALL); + break; + + case NOTBACKTOMAIN: + if(WNDBackToMainMenu != NULL) + { + WNDBackToMainMenu->setWaste(); + WNDBackToMainMenu = NULL; + } + break; + + default: break; + } +} + +void callback::EditorTextureMenu(int Param) +{ + static CWindow* WNDTexture = NULL; + static CMap* MapObj = NULL; + static bobMAP* map = NULL; + static int textureIndex = 0; + static int harbourPictureCross = 0; // this have to be -1 if we use the harbour button + static int lastContent = 0x00; + static int PosX = 0, PosY = 0; + + enum + { + WINDOWQUIT, + HARBOUR, + PICSNOW, + PICSTEPPE, + PICSWAMP, + PICFLOWER, + PICMINING1, + PICMINING2, + PICMINING3, + PICMINING4, + PICSTEPPE_MEADOW1, + PICMEADOW1, + PICMEADOW2, + PICMEADOW3, + PICSTEPPE_MEADOW2, + PICMINING_MEADOW, + PICWATER, + PICLAVA, + PICMEADOW_MIXED + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDTexture != NULL) + break; + WNDTexture = new CWindow(EditorTextureMenu, WINDOWQUIT, PosX, PosY, 220, 133, "Terrain", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDTexture)) + { + MapObj = global::s2->getMapObj(); + map = MapObj->getMap(); + switch(map->type) + { + case MAP_GREENLAND: textureIndex = PICTURE_GREENLAND_TEXTURE_SNOW; break; + case MAP_WASTELAND: textureIndex = PICTURE_WASTELAND_TEXTURE_SNOW; break; + case MAP_WINTERLAND: textureIndex = PICTURE_WINTERLAND_TEXTURE_SNOW; break; + default: textureIndex = PICTURE_GREENLAND_TEXTURE_SNOW; break; + } + MapObj->setMode(EDITOR_MODE_TEXTURE); + MapObj->setModeContent(TRIANGLE_TEXTURE_SNOW); + lastContent = TRIANGLE_TEXTURE_SNOW; + + WNDTexture->addPicture(EditorTextureMenu, PICSNOW, 2, 2, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICSTEPPE, 36, 2, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICSWAMP, 70, 2, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICFLOWER, 104, 2, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMINING1, 138, 2, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMINING2, 172, 2, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMINING3, 2, 36, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMINING4, 36, 36, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICSTEPPE_MEADOW1, 70, 36, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMEADOW1, 104, 36, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMEADOW2, 138, 36, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMEADOW3, 172, 36, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICSTEPPE_MEADOW2, 2, 70, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICMINING_MEADOW, 36, 70, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICWATER, 70, 70, textureIndex++); + WNDTexture->addPicture(EditorTextureMenu, PICLAVA, 104, 70, textureIndex++); + if(map->type != MAP_WASTELAND) + WNDTexture->addPicture(EditorTextureMenu, PICMEADOW_MIXED, 138, 70, textureIndex); + + // WNDTexture->addButton(EditorTextureMenu, HARBOUR, 172, 70, 32, 32, BUTTON_GREY, NULL, MAPPIC_HOUSE_HARBOUR); + // harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + } else + { + delete WNDTexture; + WNDTexture = NULL; + return; + } + break; + + case HARBOUR: // harbour mode is active + if(harbourPictureCross == -1) + { + if(MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW1_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW2_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW3_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_FLOWER_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR) + { + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + MapObj->setModeContent(MapObj->getModeContent() - 0x40); + lastContent = MapObj->getModeContent(); + } + } + // harbour mode is inactive + else + { + if(MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW1 || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW1 + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW2 || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW3 + || MapObj->getModeContent() == TRIANGLE_TEXTURE_STEPPE_MEADOW2 || MapObj->getModeContent() == TRIANGLE_TEXTURE_FLOWER + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MINING_MEADOW + || MapObj->getModeContent() == TRIANGLE_TEXTURE_MEADOW_MIXED) + { + WNDTexture->delStaticPicture(harbourPictureCross); + harbourPictureCross = -1; + MapObj->setModeContent(MapObj->getModeContent() + 0x40); + lastContent = MapObj->getModeContent(); + } + } + break; + case PICSNOW: + MapObj->setModeContent(TRIANGLE_TEXTURE_SNOW); + lastContent = TRIANGLE_TEXTURE_SNOW; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICSTEPPE: + MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE); + lastContent = TRIANGLE_TEXTURE_STEPPE; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICSWAMP: + MapObj->setModeContent(TRIANGLE_TEXTURE_SWAMP); + lastContent = TRIANGLE_TEXTURE_SWAMP; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICFLOWER: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_FLOWER_HARBOUR); + lastContent = TRIANGLE_TEXTURE_FLOWER_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_FLOWER); + lastContent = TRIANGLE_TEXTURE_FLOWER; + } + break; + case PICMINING1: + MapObj->setModeContent(TRIANGLE_TEXTURE_MINING1); + lastContent = TRIANGLE_TEXTURE_MINING1; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICMINING2: + MapObj->setModeContent(TRIANGLE_TEXTURE_MINING2); + lastContent = TRIANGLE_TEXTURE_MINING2; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICMINING3: + MapObj->setModeContent(TRIANGLE_TEXTURE_MINING3); + lastContent = TRIANGLE_TEXTURE_MINING3; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICMINING4: + MapObj->setModeContent(TRIANGLE_TEXTURE_MINING4); + lastContent = TRIANGLE_TEXTURE_MINING4; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICSTEPPE_MEADOW1: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR); + lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW1); + lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW1; + } + break; + case PICMEADOW1: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW1_HARBOUR); + lastContent = TRIANGLE_TEXTURE_MEADOW1_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW1); + lastContent = TRIANGLE_TEXTURE_MEADOW1; + } + break; + case PICMEADOW2: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW2_HARBOUR); + lastContent = TRIANGLE_TEXTURE_MEADOW2_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW2); + lastContent = TRIANGLE_TEXTURE_MEADOW2; + } + break; + case PICMEADOW3: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW3_HARBOUR); + lastContent = TRIANGLE_TEXTURE_MEADOW3_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW3); + lastContent = TRIANGLE_TEXTURE_MEADOW3; + } + break; + case PICSTEPPE_MEADOW2: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR); + lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_STEPPE_MEADOW2); + lastContent = TRIANGLE_TEXTURE_STEPPE_MEADOW2; + } + break; + case PICMINING_MEADOW: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR); + lastContent = TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MINING_MEADOW); + lastContent = TRIANGLE_TEXTURE_MINING_MEADOW; + } + break; + case PICWATER: + MapObj->setModeContent(TRIANGLE_TEXTURE_WATER); + lastContent = TRIANGLE_TEXTURE_WATER; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICLAVA: + MapObj->setModeContent(TRIANGLE_TEXTURE_LAVA); + lastContent = TRIANGLE_TEXTURE_LAVA; + if(harbourPictureCross == -1) + harbourPictureCross = WNDTexture->addStaticPicture(185, 80, PICTURE_SMALL_CROSS); + break; + case PICMEADOW_MIXED: + if(harbourPictureCross == -1) + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR); + lastContent = TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR; + } else + { + MapObj->setModeContent(TRIANGLE_TEXTURE_MEADOW_MIXED); + lastContent = TRIANGLE_TEXTURE_MEADOW_MIXED; + } + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + MapObj->setMode(EDITOR_MODE_TEXTURE); + MapObj->setModeContent(lastContent); + } + break; + + case WINDOWQUIT: + if(WNDTexture != NULL) + { + PosX = WNDTexture->getX(); + PosY = WNDTexture->getY(); + WNDTexture->setWaste(); + WNDTexture = NULL; + } + MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); + MapObj->setModeContent(0x00); + lastContent = 0x00; + MapObj = NULL; + map = NULL; + textureIndex = 0; + harbourPictureCross = 0; // this have to be -1 if we use the harbour button + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead + if(WNDTexture != NULL) + { + PosX = WNDTexture->getX(); + PosY = WNDTexture->getY(); + WNDTexture->setWaste(); + WNDTexture = NULL; + } + lastContent = 0x00; + MapObj = NULL; + map = NULL; + textureIndex = 0; + harbourPictureCross = 0; // this have to be -1 if we use the harbour button + break; + + default: break; + } +} + +void callback::EditorTreeMenu(int Param) +{ + static CWindow* WNDTree = NULL; + static CMap* MapObj = NULL; + static bobMAP* map = NULL; + static int lastContent = 0x00; + static int lastContent2 = 0x00; + static int PosX = 230, PosY = 0; + + enum + { + WINDOWQUIT, + PICPINE, + PICBIRCH, + PICOAK, + PICPALM1, + PICPALM2, + PICPINEAPPLE, + PICCYPRESS, + PICCHERRY, + PICFIR, + PICSPIDER, + PICFLAPHAT, + PICWOOD_MIXED, + PICPALM_MIXED + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDTree != NULL) + break; + WNDTree = new CWindow(EditorTreeMenu, WINDOWQUIT, PosX, PosY, 148, 140, "Trees", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDTree)) + { + MapObj = global::s2->getMapObj(); + map = MapObj->getMap(); + switch(map->type) + { + case MAP_GREENLAND: + WNDTree->addPicture(EditorTreeMenu, PICPINE, 2, 2, PICTURE_TREE_PINE); + WNDTree->addPicture(EditorTreeMenu, PICBIRCH, 36, 2, PICTURE_TREE_BIRCH); + WNDTree->addPicture(EditorTreeMenu, PICOAK, 70, 2, PICTURE_TREE_OAK); + WNDTree->addPicture(EditorTreeMenu, PICPALM1, 104, 2, PICTURE_TREE_PALM1); + WNDTree->addPicture(EditorTreeMenu, PICPALM2, 2, 36, PICTURE_TREE_PALM2); + WNDTree->addPicture(EditorTreeMenu, PICPINEAPPLE, 36, 36, PICTURE_TREE_PINEAPPLE); + WNDTree->addPicture(EditorTreeMenu, PICCYPRESS, 70, 36, PICTURE_TREE_CYPRESS); + WNDTree->addPicture(EditorTreeMenu, PICCHERRY, 104, 36, PICTURE_TREE_CHERRY); + WNDTree->addPicture(EditorTreeMenu, PICFIR, 2, 72, PICTURE_TREE_FIR); + WNDTree->addPicture(EditorTreeMenu, PICWOOD_MIXED, 36, 70, PICTURE_TREE_WOOD_MIXED); + WNDTree->addPicture(EditorTreeMenu, PICPALM_MIXED, 70, 70, PICTURE_TREE_PALM_MIXED); + break; + case MAP_WASTELAND: + WNDTree->addPicture(EditorTreeMenu, PICFLAPHAT, 2, 2, PICTURE_TREE_FLAPHAT); + WNDTree->addPicture(EditorTreeMenu, PICSPIDER, 36, 2, PICTURE_TREE_SPIDER); + WNDTree->addPicture(EditorTreeMenu, PICPINEAPPLE, 70, 2, PICTURE_TREE_PINEAPPLE); + WNDTree->addPicture(EditorTreeMenu, PICCHERRY, 104, 2, PICTURE_TREE_CHERRY); + break; + case MAP_WINTERLAND: + WNDTree->addPicture(EditorTreeMenu, PICPINE, 2, 2, PICTURE_TREE_PINE); + WNDTree->addPicture(EditorTreeMenu, PICBIRCH, 36, 2, PICTURE_TREE_BIRCH); + WNDTree->addPicture(EditorTreeMenu, PICCYPRESS, 70, 2, PICTURE_TREE_CYPRESS); + WNDTree->addPicture(EditorTreeMenu, PICFIR, 104, 2, PICTURE_TREE_FIR); + WNDTree->addPicture(EditorTreeMenu, PICWOOD_MIXED, 2, 36, PICTURE_TREE_WOOD_MIXED); + break; + default: // should not happen + break; + } + MapObj->setMode(EDITOR_MODE_TREE); + MapObj->setModeContent(0x30); + MapObj->setModeContent2(0xC4); + lastContent = 0x30; + lastContent2 = 0xC4; + } else + { + delete WNDTree; + WNDTree = NULL; + return; + } + break; + + case PICPINE: + MapObj->setModeContent(0x30); + MapObj->setModeContent2(0xC4); + lastContent = 0x30; + lastContent2 = 0xC4; + break; + case PICBIRCH: + MapObj->setModeContent(0x70); + MapObj->setModeContent2(0xC4); + lastContent = 0x70; + lastContent2 = 0xC4; + break; + case PICOAK: + MapObj->setModeContent(0xB0); + MapObj->setModeContent2(0xC4); + lastContent = 0xB0; + lastContent2 = 0xC4; + break; + case PICPALM1: + MapObj->setModeContent(0xF0); + MapObj->setModeContent2(0xC4); + lastContent = 0xF0; + lastContent2 = 0xC4; + break; + case PICPALM2: + MapObj->setModeContent(0x30); + MapObj->setModeContent2(0xC5); + lastContent = 0x30; + lastContent2 = 0xC5; + break; + case PICPINEAPPLE: + MapObj->setModeContent(0x70); + MapObj->setModeContent2(0xC5); + lastContent = 0x70; + lastContent2 = 0xC5; + break; + case PICCYPRESS: + MapObj->setModeContent(0xB0); + MapObj->setModeContent2(0xC5); + lastContent = 0xB0; + lastContent2 = 0xC5; + break; + case PICCHERRY: + MapObj->setModeContent(0xF0); + MapObj->setModeContent2(0xC5); + lastContent = 0xF0; + lastContent2 = 0xC5; + break; + case PICFIR: + MapObj->setModeContent(0x30); + MapObj->setModeContent2(0xC6); + lastContent = 0x30; + lastContent2 = 0xC6; + break; + case PICFLAPHAT: + MapObj->setModeContent(0x70); + MapObj->setModeContent2(0xC4); + lastContent = 0x70; + lastContent2 = 0xC4; + break; + case PICSPIDER: + MapObj->setModeContent(0x30); + MapObj->setModeContent2(0xC4); + lastContent = 0x30; + lastContent2 = 0xC4; + break; + case PICWOOD_MIXED: + MapObj->setModeContent(0xFF); + MapObj->setModeContent2(0xC4); + lastContent = 0xFF; + lastContent2 = 0xC4; + break; + case PICPALM_MIXED: + MapObj->setModeContent(0xFF); + MapObj->setModeContent2(0xC5); + lastContent = 0xFF; + lastContent2 = 0xC5; + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + MapObj->setMode(EDITOR_MODE_TREE); + MapObj->setModeContent(lastContent); + MapObj->setModeContent2(lastContent2); + } + break; + + case WINDOWQUIT: + if(WNDTree != NULL) + { + PosX = WNDTree->getX(); + PosY = WNDTree->getY(); + WNDTree->setWaste(); + WNDTree = NULL; + } + MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); + MapObj->setModeContent(0x00); + MapObj->setModeContent2(0x00); + lastContent = 0x00; + lastContent2 = 0x00; + MapObj = NULL; + map = NULL; + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead + if(WNDTree != NULL) + { + PosX = WNDTree->getX(); + PosY = WNDTree->getY(); + WNDTree->setWaste(); + WNDTree = NULL; + } + lastContent = 0x00; + lastContent2 = 0x00; + MapObj = NULL; + map = NULL; + break; + + default: break; + } +} + +void callback::EditorResourceMenu(int Param) +{ + static CWindow* WNDResource = NULL; + static CMap* MapObj = NULL; + static int lastContent = 0x00; + static int PosX = 0, PosY = 140; + + enum + { + WINDOWQUIT, + PICGOLD, + PICORE, + PICCOAL, + PICGRANITE + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDResource != NULL) + break; + WNDResource = new CWindow(EditorResourceMenu, WINDOWQUIT, PosX, PosY, 148, 55, "Resources", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDResource)) + { + MapObj = global::s2->getMapObj(); + + WNDResource->addPicture(EditorResourceMenu, PICGOLD, 2, 2, PICTURE_RESOURCE_GOLD); + WNDResource->addPicture(EditorResourceMenu, PICORE, 36, 2, PICTURE_RESOURCE_ORE); + WNDResource->addPicture(EditorResourceMenu, PICCOAL, 70, 2, PICTURE_RESOURCE_COAL); + WNDResource->addPicture(EditorResourceMenu, PICGRANITE, 104, 2, PICTURE_RESOURCE_GRANITE); + + MapObj->setMode(EDITOR_MODE_RESOURCE_RAISE); + MapObj->setModeContent(0x51); + lastContent = 0x51; + } else + { + delete WNDResource; + WNDResource = NULL; + return; + } + break; + + case PICGOLD: + MapObj->setModeContent(0x51); + lastContent = 0x51; + break; + case PICORE: + MapObj->setModeContent(0x49); + lastContent = 0x49; + break; + case PICCOAL: + MapObj->setModeContent(0x41); + lastContent = 0x41; + break; + case PICGRANITE: + MapObj->setModeContent(0x59); + lastContent = 0x59; + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + MapObj->setMode(EDITOR_MODE_RESOURCE_RAISE); + MapObj->setModeContent(lastContent); + } + break; + + case WINDOWQUIT: + if(WNDResource != NULL) + { + PosX = WNDResource->getX(); + PosY = WNDResource->getY(); + WNDResource->setWaste(); + WNDResource = NULL; + } + MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); + MapObj->setModeContent(0x00); + lastContent = 0x00; + MapObj = NULL; + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead + if(WNDResource != NULL) + { + PosX = WNDResource->getX(); + PosY = WNDResource->getY(); + WNDResource->setWaste(); + WNDResource = NULL; + } + lastContent = 0x00; + MapObj = NULL; + break; + + default: break; + } +} + +void callback::EditorLandscapeMenu(int Param) +{ + static CWindow* WNDLandscape = NULL; + static CMap* MapObj = NULL; + static bobMAP* map = NULL; + static int lastContent = 0x00; + static int lastContent2 = 0x00; + static int PosX = 390, PosY = 0; + + enum + { + WINDOWQUIT, + PICGRANITE, + PICTREEDEAD, + PICSTONE, + PICCACTUS, + PICPEBBLE, + PICBUSH, + PICSHRUB, + PICBONE, + PICMUSHROOM, + PICSTALAGMITE, + PICFLOWERS + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDLandscape != NULL) + break; + WNDLandscape = new CWindow(EditorLandscapeMenu, WINDOWQUIT, PosX, PosY, 112, 174, "Landscape", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDLandscape)) + { + MapObj = global::s2->getMapObj(); + map = MapObj->getMap(); + switch(map->type) + { + case MAP_GREENLAND: + WNDLandscape->addPicture(EditorLandscapeMenu, PICGRANITE, 2, 2, PICTURE_LANDSCAPE_GRANITE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICTREEDEAD, 36, 2, PICTURE_LANDSCAPE_TREE_DEAD); + WNDLandscape->addPicture(EditorLandscapeMenu, PICSTONE, 70, 2, PICTURE_LANDSCAPE_STONE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICCACTUS, 2, 36, PICTURE_LANDSCAPE_CACTUS); + WNDLandscape->addPicture(EditorLandscapeMenu, PICPEBBLE, 36, 36, PICTURE_LANDSCAPE_PEBBLE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICBUSH, 70, 36, PICTURE_LANDSCAPE_BUSH); + WNDLandscape->addPicture(EditorLandscapeMenu, PICSHRUB, 2, 70, PICTURE_LANDSCAPE_SHRUB); + WNDLandscape->addPicture(EditorLandscapeMenu, PICBONE, 36, 70, PICTURE_LANDSCAPE_BONE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICMUSHROOM, 70, 70, PICTURE_LANDSCAPE_MUSHROOM); + WNDLandscape->addPicture(EditorLandscapeMenu, PICFLOWERS, 5, 107, MAPPIC_FLOWERS); + break; + case MAP_WASTELAND: + WNDLandscape->addPicture(EditorLandscapeMenu, PICGRANITE, 2, 2, PICTURE_LANDSCAPE_GRANITE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICTREEDEAD, 36, 2, PICTURE_LANDSCAPE_TREE_DEAD); + WNDLandscape->addPicture(EditorLandscapeMenu, PICSTONE, 70, 2, PICTURE_LANDSCAPE_STONE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICSTALAGMITE, 2, 36, PICTURE_LANDSCAPE_STALAGMITE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICPEBBLE, 36, 36, PICTURE_LANDSCAPE_PEBBLE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICBUSH, 70, 36, PICTURE_LANDSCAPE_BUSH); + WNDLandscape->addPicture(EditorLandscapeMenu, PICSHRUB, 2, 70, PICTURE_LANDSCAPE_SHRUB); + WNDLandscape->addPicture(EditorLandscapeMenu, PICBONE, 36, 70, PICTURE_LANDSCAPE_BONE); + WNDLandscape->addPicture(EditorLandscapeMenu, PICMUSHROOM, 70, 70, PICTURE_LANDSCAPE_MUSHROOM); + WNDLandscape->addPicture(EditorLandscapeMenu, PICFLOWERS, 5, 107, MAPPIC_FLOWERS); + break; + case MAP_WINTERLAND: + WNDLandscape->addPicture(EditorLandscapeMenu, PICGRANITE, 2, 2, PICTURE_LANDSCAPE_GRANITE_WINTER); + WNDLandscape->addPicture(EditorLandscapeMenu, PICTREEDEAD, 36, 2, PICTURE_LANDSCAPE_TREE_DEAD_WINTER); + WNDLandscape->addPicture(EditorLandscapeMenu, PICSTONE, 70, 2, PICTURE_LANDSCAPE_STONE_WINTER); + WNDLandscape->addPicture(EditorLandscapeMenu, PICPEBBLE, 2, 36, PICTURE_LANDSCAPE_PEBBLE_WINTER); + WNDLandscape->addPicture(EditorLandscapeMenu, PICBONE, 36, 36, PICTURE_LANDSCAPE_BONE_WINTER); + WNDLandscape->addPicture(EditorLandscapeMenu, PICMUSHROOM, 70, 36, PICTURE_LANDSCAPE_MUSHROOM_WINTER); + WNDLandscape->addPicture(EditorLandscapeMenu, PICFLOWERS, 73, 73, MAPPIC_FLOWERS); + break; + default: // should not happen + break; + } + MapObj->setMode(EDITOR_MODE_LANDSCAPE); + MapObj->setModeContent(0x01); + MapObj->setModeContent2(0xCC); + lastContent = 0x01; + lastContent2 = 0xCC; + } else + { + delete WNDLandscape; + WNDLandscape = NULL; + return; + } + break; + + case PICGRANITE: + MapObj->setModeContent(0x01); + MapObj->setModeContent2(0xCC); + lastContent = 0x01; + lastContent2 = 0xCC; + break; + case PICTREEDEAD: + MapObj->setModeContent(0x05); + MapObj->setModeContent2(0xC8); + lastContent = 0x05; + lastContent2 = 0xC8; + break; + case PICSTONE: + MapObj->setModeContent(0x02); + MapObj->setModeContent2(0xC8); + lastContent = 0x02; + lastContent2 = 0xC8; + break; + case PICCACTUS: + MapObj->setModeContent(0x0C); + MapObj->setModeContent2(0xC8); + lastContent = 0x0C; + lastContent2 = 0xC8; + break; + case PICPEBBLE: + MapObj->setModeContent(0x25); + MapObj->setModeContent2(0xC8); + lastContent = 0x25; + lastContent2 = 0xC8; + break; + case PICBUSH: + MapObj->setModeContent(0x10); + MapObj->setModeContent2(0xC8); + lastContent = 0x10; + lastContent2 = 0xC8; + break; + case PICSHRUB: + MapObj->setModeContent(0x0E); + MapObj->setModeContent2(0xC8); + lastContent = 0x0E; + lastContent2 = 0xC8; + break; + case PICBONE: + MapObj->setModeContent(0x07); + MapObj->setModeContent2(0xC8); + lastContent = 0x07; + lastContent2 = 0xC8; + break; + case PICMUSHROOM: + MapObj->setModeContent(0x00); + MapObj->setModeContent2(0xC8); + lastContent = 0x00; + lastContent2 = 0xC8; + break; + case PICSTALAGMITE: + MapObj->setModeContent(0x18); + MapObj->setModeContent2(0xC8); + lastContent = 0x18; + lastContent2 = 0xC8; + break; + case PICFLOWERS: + MapObj->setModeContent(0x09); + MapObj->setModeContent2(0xC8); + lastContent = 0x09; + lastContent2 = 0xC8; + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + MapObj->setMode(EDITOR_MODE_LANDSCAPE); + MapObj->setModeContent(lastContent); + MapObj->setModeContent2(lastContent2); + } + break; + + case WINDOWQUIT: + if(WNDLandscape != NULL) + { + PosX = WNDLandscape->getX(); + PosY = WNDLandscape->getY(); + WNDLandscape->setWaste(); + WNDLandscape = NULL; + } + MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); + MapObj->setModeContent(0x00); + MapObj->setModeContent2(0x00); + lastContent = 0x00; + lastContent2 = 0x00; + MapObj = NULL; + map = NULL; + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead + if(WNDLandscape != NULL) + { + PosX = WNDLandscape->getX(); + PosY = WNDLandscape->getY(); + WNDLandscape->setWaste(); + WNDLandscape = NULL; + } + lastContent = 0x00; + lastContent2 = 0x00; + MapObj = NULL; + map = NULL; + break; + + default: break; + } +} + +void callback::EditorAnimalMenu(int Param) +{ + static CWindow* WNDAnimal = NULL; + static CMap* MapObj = NULL; + static int lastContent = 0x00; + static int PosX = 510, PosY = 0; + + enum + { + WINDOWQUIT, + PICRABBIT, + PICFOX, + PICSTAG, + PICROE, + PICDUCK, + PICSHEEP + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDAnimal != NULL) + break; + WNDAnimal = new CWindow(EditorAnimalMenu, WINDOWQUIT, PosX, PosY, 116, 106, "Animals", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDAnimal)) + { + WNDAnimal->addPicture(EditorAnimalMenu, PICRABBIT, 2, 2, PICTURE_ANIMAL_RABBIT); + WNDAnimal->addPicture(EditorAnimalMenu, PICFOX, 36, 2, PICTURE_ANIMAL_FOX); + WNDAnimal->addPicture(EditorAnimalMenu, PICSTAG, 70, 2, PICTURE_ANIMAL_STAG); + WNDAnimal->addPicture(EditorAnimalMenu, PICROE, 2, 36, PICTURE_ANIMAL_ROE); + WNDAnimal->addPicture(EditorAnimalMenu, PICDUCK, 36, 36, PICTURE_ANIMAL_DUCK); + WNDAnimal->addPicture(EditorAnimalMenu, PICSHEEP, 70, 36, PICTURE_ANIMAL_SHEEP); + + MapObj = global::s2->getMapObj(); + MapObj->setMode(EDITOR_MODE_ANIMAL); + MapObj->setModeContent(0x01); + lastContent = 0x01; + } else + { + delete WNDAnimal; + WNDAnimal = NULL; + return; + } + break; + + case PICRABBIT: + MapObj->setModeContent(0x01); + lastContent = 0x01; + break; + case PICFOX: + MapObj->setModeContent(0x02); + lastContent = 0x02; + break; + case PICSTAG: + MapObj->setModeContent(0x03); + lastContent = 0x03; + break; + case PICROE: + MapObj->setModeContent(0x04); + lastContent = 0x04; + break; + case PICDUCK: + MapObj->setModeContent(0x05); + lastContent = 0x05; + break; + case PICSHEEP: + MapObj->setModeContent(0x06); + lastContent = 0x06; + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + MapObj->setMode(EDITOR_MODE_ANIMAL); + MapObj->setModeContent(lastContent); + } + break; + + case WINDOWQUIT: + if(WNDAnimal != NULL) + { + PosX = WNDAnimal->getX(); + PosY = WNDAnimal->getY(); + WNDAnimal->setWaste(); + WNDAnimal = NULL; + } + MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); + MapObj->setModeContent(0x00); + lastContent = 0x00; + MapObj = NULL; + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead + if(WNDAnimal != NULL) + { + PosX = WNDAnimal->getX(); + PosY = WNDAnimal->getY(); + WNDAnimal->setWaste(); + WNDAnimal = NULL; + } + lastContent = 0x00; + MapObj = NULL; + break; + + default: break; + } +} + +void callback::EditorPlayerMenu(int Param) +{ + static CWindow* WNDPlayer = NULL; + static CMap* MapObj = NULL; + static int PlayerNumber = 0x00; + static CFont* PlayerNumberText = NULL; + char puffer[30]; + static DisplayRectangle tempRect; + static Uint16* PlayerHQx = NULL; + static Uint16* PlayerHQy = NULL; + static int PosX = 0, PosY = 200; + + enum + { + PLAYER_REDUCE = 0, + PLAYER_RAISE, + GOTO_PLAYER, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDPlayer != NULL) + break; + WNDPlayer = new CWindow(EditorPlayerMenu, WINDOWQUIT, PosX, PosY, 100, 80, "Players", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDPlayer)) + { + MapObj = global::s2->getMapObj(); + tempRect = MapObj->getDisplayRect(); + PlayerHQx = MapObj->getPlayerHQx(); + PlayerHQy = MapObj->getPlayerHQy(); + + MapObj->setMode(EDITOR_MODE_FLAG); + MapObj->setModeContent(PlayerNumber); + + WNDPlayer->addButton(EditorPlayerMenu, PLAYER_REDUCE, 0, 0, 20, 20, BUTTON_GREY, "-"); + sprintf(puffer, "%d", PlayerNumber + 1); + PlayerNumberText = WNDPlayer->addText(puffer, 26, 4, 14, FONT_ORANGE); + WNDPlayer->addButton(EditorPlayerMenu, PLAYER_RAISE, 40, 0, 20, 20, BUTTON_GREY, "+"); + WNDPlayer->addButton(EditorPlayerMenu, GOTO_PLAYER, 0, 20, 60, 20, BUTTON_GREY, "Go to"); + } else + { + delete WNDPlayer; + WNDPlayer = NULL; + return; + } + break; + + case PLAYER_REDUCE: + if(PlayerNumber > 0) + { + PlayerNumber--; + MapObj->setModeContent(PlayerNumber); + WNDPlayer->delText(PlayerNumberText); + sprintf(puffer, "%d", PlayerNumber + 1); + PlayerNumberText = WNDPlayer->addText(puffer, 26, 4, 14, FONT_ORANGE); + } + break; + + case PLAYER_RAISE: + if(PlayerNumber < MAXPLAYERS - 1) + { + PlayerNumber++; + MapObj->setModeContent(PlayerNumber); + WNDPlayer->delText(PlayerNumberText); + sprintf(puffer, "%d", PlayerNumber + 1); + PlayerNumberText = WNDPlayer->addText(puffer, 26, 4, 14, FONT_ORANGE); + } + break; + + case GOTO_PLAYER: // test if player exists on map + if(PlayerHQx[PlayerNumber] != 0xFFFF && PlayerHQy[PlayerNumber] != 0xFFFF) + { + tempRect = MapObj->getDisplayRect(); + tempRect.x = PlayerHQx[PlayerNumber] * TRIANGLE_WIDTH - tempRect.w / 2; + tempRect.y = PlayerHQy[PlayerNumber] * TRIANGLE_HEIGHT - tempRect.h / 2; + MapObj->setDisplayRect(tempRect); + } + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + MapObj->setMode(EDITOR_MODE_FLAG); + MapObj->setModeContent(PlayerNumber); + } + break; + + case WINDOWQUIT: + if(WNDPlayer != NULL) + { + PosX = WNDPlayer->getX(); + PosY = WNDPlayer->getY(); + WNDPlayer->setWaste(); + WNDPlayer = NULL; + } + MapObj->setMode(EDITOR_MODE_HEIGHT_RAISE); + MapObj->setModeContent(0x00); + MapObj->setModeContent2(0x00); + MapObj = NULL; + PlayerNumber = 0x01; + PlayerNumberText = NULL; + PlayerHQx = NULL; + PlayerHQy = NULL; + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT, but we won't setMode(EDITOR_MODE_HEIGHT_RAISE), cause map is dead + if(WNDPlayer != NULL) + { + PosX = WNDPlayer->getX(); + PosY = WNDPlayer->getY(); + WNDPlayer->setWaste(); + WNDPlayer = NULL; + } + MapObj = NULL; + PlayerNumber = 0x01; + PlayerNumberText = NULL; + PlayerHQx = NULL; + PlayerHQy = NULL; + break; + + default: break; + } +} + +void callback::EditorCursorMenu(int Param) +{ + static CWindow* WNDCursor = NULL; + static CMap* MapObj = NULL; + static int trianglePictureArrowUp = -1; + static int trianglePictureArrowDown = -1; + static int trianglePictureRandom = -1; + static CButton* CursorModeButton = NULL; + static CButton* CursorRandomButton = NULL; + static int PosX = 0, PosY = 0; + + enum + { + WINDOWQUIT, + TRIANGLE, + CURSORMODE, + CURSORRANDOM + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDCursor != NULL) + break; + WNDCursor = new CWindow(EditorCursorMenu, WINDOWQUIT, PosX, PosY, 210, 130, "Cursor", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MINIMIZE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDCursor)) + { + MapObj = global::s2->getMapObj(); + + WNDCursor->addButton(EditorCursorMenu, TRIANGLE, 2, 66, 32, 32, BUTTON_GREY, NULL); + trianglePictureArrowUp = WNDCursor->addStaticPicture(8, 74, CURSOR_SYMBOL_ARROW_UP); + trianglePictureArrowDown = WNDCursor->addStaticPicture(17, 77, CURSOR_SYMBOL_ARROW_DOWN); + CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Hexagon"); + CursorRandomButton = + WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: static"); + if(MapObj != NULL) + { + MapObj->setVertexFillRSU(true); + MapObj->setVertexFillUSD(true); + MapObj->setVertexFillRandom(false); + MapObj->setHexagonMode(true); + MapObj->setVertexActivityRandom(false); + } + } else + { + delete WNDCursor; + WNDCursor = NULL; + return; + } + break; + + case TRIANGLE: + if(trianglePictureArrowUp != -1 && trianglePictureArrowDown != -1) + { + // both arrows are shown, so set to random + // delete arrow up + WNDCursor->delStaticPicture(trianglePictureArrowUp); + trianglePictureArrowUp = -1; + // delete arrow down + WNDCursor->delStaticPicture(trianglePictureArrowDown); + trianglePictureArrowDown = -1; + // add random if necessary + if(trianglePictureRandom == -1) + trianglePictureRandom = WNDCursor->addStaticPicture(14, 76, FONT14_SPACE + 31 * 7 + 5); // Interrogation point + MapObj->setVertexFillRSU(false); + MapObj->setVertexFillUSD(false); + MapObj->setVertexFillRandom(true); + } else if(trianglePictureArrowUp == -1 && trianglePictureRandom == -1) + { + // only arrow down is shown, so upgrade to both arrows + // add arrow up + trianglePictureArrowUp = WNDCursor->addStaticPicture(8, 74, CURSOR_SYMBOL_ARROW_UP); + // add arrow down if necessary + if(trianglePictureArrowDown == -1) + trianglePictureArrowDown = WNDCursor->addStaticPicture(17, 77, CURSOR_SYMBOL_ARROW_DOWN); + MapObj->setVertexFillRSU(true); + MapObj->setVertexFillUSD(true); + MapObj->setVertexFillRandom(false); + } else if(trianglePictureArrowDown == -1 && trianglePictureRandom == -1) + { + // only arrow up is shown, so delete arrow up and add arrow down + // delete arrow up if necessary + if(trianglePictureArrowUp != -1) + { + WNDCursor->delStaticPicture(trianglePictureArrowUp); + trianglePictureArrowUp = -1; + } + trianglePictureArrowDown = WNDCursor->addStaticPicture(17, 77, CURSOR_SYMBOL_ARROW_DOWN); + MapObj->setVertexFillRSU(false); + MapObj->setVertexFillUSD(true); + MapObj->setVertexFillRandom(false); + } else + { + // the interrogation point is shown, so set to arrow up + WNDCursor->delStaticPicture(trianglePictureRandom); + trianglePictureRandom = -1; + // add arrow up if necessary + if(trianglePictureArrowUp == -1) + trianglePictureArrowUp = WNDCursor->addStaticPicture(8, 74, CURSOR_SYMBOL_ARROW_UP); + // delete arrow down if necessary + if(trianglePictureArrowDown != -1) + { + WNDCursor->delStaticPicture(trianglePictureArrowDown); + trianglePictureArrowDown = -1; + } + MapObj->setVertexFillRSU(true); + MapObj->setVertexFillUSD(false); + MapObj->setVertexFillRandom(false); + } + break; + + case CURSORMODE: + if(CursorModeButton != NULL) + { + WNDCursor->delButton(CursorModeButton); + CursorModeButton = NULL; + } + if(MapObj->getHexagonMode()) + { + CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Square"); + MapObj->setHexagonMode(false); + } else + { + CursorModeButton = WNDCursor->addButton(EditorCursorMenu, CURSORMODE, 2, 2, 96, 32, BUTTON_GREY, "Hexagon"); + MapObj->setHexagonMode(true); + } + break; + case CURSORRANDOM: + if(CursorRandomButton != NULL) + { + WNDCursor->delButton(CursorRandomButton); + CursorRandomButton = NULL; + } + if(MapObj->getVertexActivityRandom()) + { + CursorRandomButton = + WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: static"); + MapObj->setVertexActivityRandom(false); + } else + { + CursorRandomButton = + WNDCursor->addButton(EditorCursorMenu, CURSORRANDOM, 2, 34, 196, 32, BUTTON_GREY, "Cursor-Activity: random"); + MapObj->setVertexActivityRandom(true); + } + break; + + case WINDOW_CLICKED_CALL: break; + + case WINDOWQUIT: + if(WNDCursor != NULL) + { + PosX = WNDCursor->getX(); + PosY = WNDCursor->getY(); + WNDCursor->setWaste(); + WNDCursor = NULL; + } + MapObj = NULL; + trianglePictureArrowUp = -1; + trianglePictureArrowDown = -1; + trianglePictureRandom = -1; + CursorModeButton = NULL; + CursorRandomButton = NULL; + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT + if(WNDCursor != NULL) + { + PosX = WNDCursor->getX(); + PosY = WNDCursor->getY(); + WNDCursor->setWaste(); + WNDCursor = NULL; + } + MapObj = NULL; + trianglePictureArrowUp = -1; + trianglePictureArrowDown = -1; + trianglePictureRandom = -1; + CursorModeButton = NULL; + CursorRandomButton = NULL; + break; + + default: break; + } +} + +//"create world" menu +void callback::EditorCreateMenu(int Param) +{ + static CWindow* WNDCreate = NULL; + static CMap* MapObj = NULL; + static CFont* TextWidth = NULL; + static int width = 32; + static CFont* TextHeight = NULL; + static int height = 32; + static CButton* ButtonLandscape = NULL; + static int LandscapeType = 0; // 0 = Greenland, 1 = Wasteland, 2 = Winterland + static int PicTextureIndex = -1; + static int PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + static int texture = TRIANGLE_TEXTURE_SNOW; + static int PicBorderTextureIndex = -1; + static int PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + static CFont* TextBorder = NULL; + static int border = 0; + static int border_texture = TRIANGLE_TEXTURE_SNOW; + static char puffer[5]; + int PosX = global::s2->GameResolutionX / 2 - 125, PosY = global::s2->GameResolutionY / 2 - 175; + + enum + { + REDUCE_WIDTH_128, + REDUCE_WIDTH_16, + REDUCE_WIDTH_2, + RAISE_WIDTH_2, + RAISE_WIDTH_16, + RAISE_WIDTH_128, + REDUCE_HEIGHT_128, + REDUCE_HEIGHT_16, + REDUCE_HEIGHT_2, + RAISE_HEIGHT_2, + RAISE_HEIGHT_16, + RAISE_HEIGHT_128, + CHANGE_LANDSCAPE, + TEXTURE_PREVIOUS, + TEXTURE_NEXT, + BORDER_TEXTURE_PREVIOUS, + BORDER_TEXTURE_NEXT, + REDUCE_BORDER, + RAISE_BORDER, + CREATE_WORLD, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDCreate != NULL) + break; + WNDCreate = new CWindow(EditorCreateMenu, WINDOWQUIT, PosX, PosY, 250, 350, "Create world", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE); + if(global::s2->RegisterWindow(WNDCreate)) + { + MapObj = global::s2->getMapObj(); + + WNDCreate->addText("Width", 95, 4, 9, FONT_YELLOW); + WNDCreate->addButton(EditorCreateMenu, REDUCE_WIDTH_128, 0, 15, 35, 20, BUTTON_GREY, "128<-"); + WNDCreate->addButton(EditorCreateMenu, REDUCE_WIDTH_16, 35, 15, 35, 20, BUTTON_GREY, "16<-"); + WNDCreate->addButton(EditorCreateMenu, REDUCE_WIDTH_2, 70, 15, 25, 20, BUTTON_GREY, "2<-"); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + TextWidth->setText(puffer); + WNDCreate->addButton(EditorCreateMenu, RAISE_WIDTH_2, 143, 15, 25, 20, BUTTON_GREY, "->2"); + WNDCreate->addButton(EditorCreateMenu, RAISE_WIDTH_16, 168, 15, 35, 20, BUTTON_GREY, "->16"); + WNDCreate->addButton(EditorCreateMenu, RAISE_WIDTH_128, 203, 15, 35, 20, BUTTON_GREY, "->128"); + + WNDCreate->addText("Height", 100, 40, 9, FONT_YELLOW); + WNDCreate->addButton(EditorCreateMenu, REDUCE_HEIGHT_128, 0, 49, 35, 20, BUTTON_GREY, "128<-"); + WNDCreate->addButton(EditorCreateMenu, REDUCE_HEIGHT_16, 35, 49, 35, 20, BUTTON_GREY, "16<-"); + WNDCreate->addButton(EditorCreateMenu, REDUCE_HEIGHT_2, 70, 49, 25, 20, BUTTON_GREY, "2<-"); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + TextHeight->setText(puffer); + WNDCreate->addButton(EditorCreateMenu, RAISE_HEIGHT_2, 143, 49, 25, 20, BUTTON_GREY, "->2"); + WNDCreate->addButton(EditorCreateMenu, RAISE_HEIGHT_16, 168, 49, 35, 20, BUTTON_GREY, "->16"); + WNDCreate->addButton(EditorCreateMenu, RAISE_HEIGHT_128, 203, 49, 35, 20, BUTTON_GREY, "->128"); + + WNDCreate->addText("Landscape", 85, 80, 9, FONT_YELLOW); + ButtonLandscape = + WNDCreate->addButton(EditorCreateMenu, CHANGE_LANDSCAPE, 64, 93, 110, 20, BUTTON_GREY, + (LandscapeType == 0 ? "Greenland" : (LandscapeType == 1 ? "Wasteland" : "Winterworld"))); + + WNDCreate->addText("Main area", 82, 120, 9, FONT_YELLOW); + WNDCreate->addButton(EditorCreateMenu, TEXTURE_PREVIOUS, 45, 139, 35, 20, BUTTON_GREY, "-"); + PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); + WNDCreate->addButton(EditorCreateMenu, TEXTURE_NEXT, 158, 139, 35, 20, BUTTON_GREY, "+"); + + WNDCreate->addText("Border size", 103, 175, 9, FONT_YELLOW); + WNDCreate->addButton(EditorCreateMenu, REDUCE_BORDER, 45, 186, 35, 20, BUTTON_GREY, "-"); + sprintf(puffer, "%d", border); + TextBorder = WNDCreate->addText(puffer, 112, 188, 14, FONT_YELLOW); + WNDCreate->addButton(EditorCreateMenu, RAISE_BORDER, 158, 186, 35, 20, BUTTON_GREY, "+"); + + WNDCreate->addText("Border area", 65, 215, 9, FONT_YELLOW); + WNDCreate->addButton(EditorCreateMenu, BORDER_TEXTURE_PREVIOUS, 45, 234, 35, 20, BUTTON_GREY, "-"); + PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); + WNDCreate->addButton(EditorCreateMenu, BORDER_TEXTURE_NEXT, 158, 234, 35, 20, BUTTON_GREY, "+"); + + WNDCreate->addButton(EditorCreateMenu, CREATE_WORLD, 44, 275, 150, 40, BUTTON_GREY, "Create world"); + } else + { + delete WNDCreate; + WNDCreate = NULL; + return; + } + break; + + case CALL_FROM_GAMELOOP: break; + + case REDUCE_WIDTH_128: + if(width - 128 >= 32) + width -= 128; + else + width = 32; + WNDCreate->delText(TextWidth); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + break; + case REDUCE_WIDTH_16: + if(width - 16 >= 32) + width -= 16; + else + width = 32; + WNDCreate->delText(TextWidth); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + break; + case REDUCE_WIDTH_2: + if(width - 2 >= 32) + width -= 2; + else + width = 32; + WNDCreate->delText(TextWidth); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + break; + case RAISE_WIDTH_2: + if(width + 2 <= MAXMAPWIDTH) + width += 2; + else + width = MAXMAPWIDTH; + WNDCreate->delText(TextWidth); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + break; + case RAISE_WIDTH_16: + if(width + 16 <= MAXMAPWIDTH) + width += 16; + else + width = MAXMAPWIDTH; + WNDCreate->delText(TextWidth); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + break; + case RAISE_WIDTH_128: + if(width + 128 <= MAXMAPWIDTH) + width += 128; + else + width = MAXMAPWIDTH; + WNDCreate->delText(TextWidth); + sprintf(puffer, "%d", width); + TextWidth = WNDCreate->addText(puffer, 105, 17, 14, FONT_YELLOW); + break; + case REDUCE_HEIGHT_128: + if(height - 128 >= 32) + height -= 128; + else + height = 32; + WNDCreate->delText(TextHeight); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + break; + case REDUCE_HEIGHT_16: + if(height - 16 >= 32) + height -= 16; + else + height = 32; + WNDCreate->delText(TextHeight); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + break; + case REDUCE_HEIGHT_2: + if(height - 2 >= 32) + height -= 2; + else + height = 32; + WNDCreate->delText(TextHeight); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + break; + case RAISE_HEIGHT_2: + if(height + 2 <= MAXMAPHEIGHT) + height += 2; + else + height = MAXMAPHEIGHT; + WNDCreate->delText(TextHeight); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + break; + case RAISE_HEIGHT_16: + if(height + 16 <= MAXMAPHEIGHT) + height += 16; + else + height = MAXMAPHEIGHT; + WNDCreate->delText(TextHeight); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + break; + case RAISE_HEIGHT_128: + if(height + 128 <= MAXMAPHEIGHT) + height += 128; + else + height = MAXMAPHEIGHT; + WNDCreate->delText(TextHeight); + sprintf(puffer, "%d", height); + TextHeight = WNDCreate->addText(puffer, 105, 51, 14, FONT_YELLOW); + break; + + case CHANGE_LANDSCAPE: + LandscapeType++; + if(LandscapeType > 2) + LandscapeType = 0; + WNDCreate->delButton(ButtonLandscape); + ButtonLandscape = WNDCreate->addButton(EditorCreateMenu, CHANGE_LANDSCAPE, 64, 93, 110, 20, BUTTON_GREY, + (LandscapeType == 0 ? "Greenland" : (LandscapeType == 1 ? "Wasteland" : "Winterworld"))); + switch(LandscapeType) + { + case 0: + PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + break; + case 1: + PicTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; + PicBorderTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; + break; + case 2: + PicTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; + PicBorderTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; + break; + default: break; + } + WNDCreate->delStaticPicture(PicTextureIndex); + WNDCreate->delStaticPicture(PicBorderTextureIndex); + PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); + PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); + break; + + case TEXTURE_PREVIOUS: + PicTextureIndexGlobal--; + switch(LandscapeType) + { + case 0: + if(PicTextureIndexGlobal < PICTURE_GREENLAND_TEXTURE_SNOW) + PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + break; + case 1: + if(PicTextureIndexGlobal < PICTURE_WASTELAND_TEXTURE_SNOW) + PicTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; + break; + case 2: + if(PicTextureIndexGlobal < PICTURE_WINTERLAND_TEXTURE_SNOW) + PicTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; + break; + default: break; + } + if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) + { + texture = TRIANGLE_TEXTURE_SNOW; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) + { + texture = TRIANGLE_TEXTURE_STEPPE; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) + { + texture = TRIANGLE_TEXTURE_SWAMP; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) + { + texture = TRIANGLE_TEXTURE_FLOWER; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) + { + texture = TRIANGLE_TEXTURE_MINING1; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) + { + texture = TRIANGLE_TEXTURE_MINING2; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) + { + texture = TRIANGLE_TEXTURE_MINING3; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) + { + texture = TRIANGLE_TEXTURE_MINING4; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) + { + texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) + { + texture = TRIANGLE_TEXTURE_MEADOW1; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) + { + texture = TRIANGLE_TEXTURE_MEADOW2; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) + { + texture = TRIANGLE_TEXTURE_MEADOW3; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) + { + texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) + { + texture = TRIANGLE_TEXTURE_MINING_MEADOW; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) + { + texture = TRIANGLE_TEXTURE_WATER; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) + { + texture = TRIANGLE_TEXTURE_LAVA; + } + WNDCreate->delStaticPicture(PicTextureIndex); + PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); + break; + case TEXTURE_NEXT: + PicTextureIndexGlobal++; + switch(LandscapeType) + { + case 0: + if(PicTextureIndexGlobal > PICTURE_GREENLAND_TEXTURE_LAVA) + PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_LAVA; + break; + case 1: + if(PicTextureIndexGlobal > PICTURE_WASTELAND_TEXTURE_LAVA) + PicTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_LAVA; + break; + case 2: + if(PicTextureIndexGlobal > PICTURE_WINTERLAND_TEXTURE_LAVA) + PicTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_LAVA; + break; + default: break; + } + if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) + { + texture = TRIANGLE_TEXTURE_SNOW; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) + { + texture = TRIANGLE_TEXTURE_STEPPE; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) + { + texture = TRIANGLE_TEXTURE_SWAMP; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) + { + texture = TRIANGLE_TEXTURE_FLOWER; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) + { + texture = TRIANGLE_TEXTURE_MINING1; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) + { + texture = TRIANGLE_TEXTURE_MINING2; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) + { + texture = TRIANGLE_TEXTURE_MINING3; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) + { + texture = TRIANGLE_TEXTURE_MINING4; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) + { + texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) + { + texture = TRIANGLE_TEXTURE_MEADOW1; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) + { + texture = TRIANGLE_TEXTURE_MEADOW2; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) + { + texture = TRIANGLE_TEXTURE_MEADOW3; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) + { + texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW + || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) + { + texture = TRIANGLE_TEXTURE_MINING_MEADOW; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) + { + texture = TRIANGLE_TEXTURE_WATER; + } else if(PicTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA || PicTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA + || PicTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) + { + texture = TRIANGLE_TEXTURE_LAVA; + } + WNDCreate->delStaticPicture(PicTextureIndex); + PicTextureIndex = WNDCreate->addStaticPicture(102, 133, PicTextureIndexGlobal); + break; + + case REDUCE_BORDER: + if(border - 1 >= 0) + border -= 1; + else + border = 0; + WNDCreate->delText(TextBorder); + sprintf(puffer, "%d", border); + TextBorder = WNDCreate->addText(puffer, 112, 188, 14, FONT_YELLOW); + break; + case RAISE_BORDER: + if(border + 1 <= 12) + border += 1; + else + border = 12; + WNDCreate->delText(TextBorder); + sprintf(puffer, "%d", border); + TextBorder = WNDCreate->addText(puffer, 112, 188, 14, FONT_YELLOW); + break; + + case BORDER_TEXTURE_PREVIOUS: + PicBorderTextureIndexGlobal--; + switch(LandscapeType) + { + case 0: + if(PicBorderTextureIndexGlobal < PICTURE_GREENLAND_TEXTURE_SNOW) + PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + break; + case 1: + if(PicBorderTextureIndexGlobal < PICTURE_WASTELAND_TEXTURE_SNOW) + PicBorderTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_SNOW; + break; + case 2: + if(PicBorderTextureIndexGlobal < PICTURE_WINTERLAND_TEXTURE_SNOW) + PicBorderTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_SNOW; + break; + default: break; + } + if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) + { + border_texture = TRIANGLE_TEXTURE_SNOW; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) + { + border_texture = TRIANGLE_TEXTURE_STEPPE; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) + { + border_texture = TRIANGLE_TEXTURE_SWAMP; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) + { + border_texture = TRIANGLE_TEXTURE_FLOWER; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) + { + border_texture = TRIANGLE_TEXTURE_MINING1; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) + { + border_texture = TRIANGLE_TEXTURE_MINING2; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) + { + border_texture = TRIANGLE_TEXTURE_MINING3; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) + { + border_texture = TRIANGLE_TEXTURE_MINING4; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) + { + border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) + { + border_texture = TRIANGLE_TEXTURE_MEADOW1; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) + { + border_texture = TRIANGLE_TEXTURE_MEADOW2; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) + { + border_texture = TRIANGLE_TEXTURE_MEADOW3; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) + { + border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) + { + border_texture = TRIANGLE_TEXTURE_MINING_MEADOW; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) + { + border_texture = TRIANGLE_TEXTURE_WATER; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) + { + border_texture = TRIANGLE_TEXTURE_LAVA; + } + WNDCreate->delStaticPicture(PicBorderTextureIndex); + PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); + break; + case BORDER_TEXTURE_NEXT: + PicBorderTextureIndexGlobal++; + switch(LandscapeType) + { + case 0: + if(PicBorderTextureIndexGlobal > PICTURE_GREENLAND_TEXTURE_LAVA) + PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_LAVA; + break; + case 1: + if(PicBorderTextureIndexGlobal > PICTURE_WASTELAND_TEXTURE_LAVA) + PicBorderTextureIndexGlobal = PICTURE_WASTELAND_TEXTURE_LAVA; + break; + case 2: + if(PicBorderTextureIndexGlobal > PICTURE_WINTERLAND_TEXTURE_LAVA) + PicBorderTextureIndexGlobal = PICTURE_WINTERLAND_TEXTURE_LAVA; + break; + default: break; + } + if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SNOW + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SNOW + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SNOW) + { + border_texture = TRIANGLE_TEXTURE_SNOW; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE) + { + border_texture = TRIANGLE_TEXTURE_STEPPE; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_SWAMP + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_SWAMP + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_SWAMP) + { + border_texture = TRIANGLE_TEXTURE_SWAMP; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_FLOWER + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_FLOWER + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_FLOWER) + { + border_texture = TRIANGLE_TEXTURE_FLOWER; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING1 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING1 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING1) + { + border_texture = TRIANGLE_TEXTURE_MINING1; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING2 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING2 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING2) + { + border_texture = TRIANGLE_TEXTURE_MINING2; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING3 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING3 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING3) + { + border_texture = TRIANGLE_TEXTURE_MINING3; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING4 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING4 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING4) + { + border_texture = TRIANGLE_TEXTURE_MINING4; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1) + { + border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW1; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW1 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW1) + { + border_texture = TRIANGLE_TEXTURE_MEADOW1; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW2) + { + border_texture = TRIANGLE_TEXTURE_MEADOW2; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MEADOW3 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MEADOW3 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MEADOW3) + { + border_texture = TRIANGLE_TEXTURE_MEADOW3; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2 + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2) + { + border_texture = TRIANGLE_TEXTURE_STEPPE_MEADOW2; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_MINING_MEADOW + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_MINING_MEADOW + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW) + { + border_texture = TRIANGLE_TEXTURE_MINING_MEADOW; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_WATER + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_WATER + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_WATER) + { + border_texture = TRIANGLE_TEXTURE_WATER; + } else if(PicBorderTextureIndexGlobal == PICTURE_GREENLAND_TEXTURE_LAVA + || PicBorderTextureIndexGlobal == PICTURE_WASTELAND_TEXTURE_LAVA + || PicBorderTextureIndexGlobal == PICTURE_WINTERLAND_TEXTURE_LAVA) + { + border_texture = TRIANGLE_TEXTURE_LAVA; + } + WNDCreate->delStaticPicture(PicBorderTextureIndex); + PicBorderTextureIndex = WNDCreate->addStaticPicture(102, 228, PicBorderTextureIndexGlobal); + break; + + case CREATE_WORLD: + PleaseWait(INITIALIZING_CALL); + + // we have to close the windows and initialize them again to prevent failures + EditorCursorMenu(MAP_QUIT); + EditorTextureMenu(MAP_QUIT); + EditorTreeMenu(MAP_QUIT); + EditorLandscapeMenu(MAP_QUIT); + MinimapMenu(MAP_QUIT); + EditorResourceMenu(MAP_QUIT); + EditorAnimalMenu(MAP_QUIT); + EditorPlayerMenu(MAP_QUIT); + + MapObj->destructMap(); + MapObj->constructMap("", width, height, LandscapeType, texture, border, border_texture); + + // we need to check which of these windows was active before + /* + EditorCursorMenu(INITIALIZING_CALL); + EditorTextureMenu(INITIALIZING_CALL); + EditorTreeMenu(INITIALIZING_CALL); + EditorLandscapeMenu(INITIALIZING_CALL); + MinimapMenu(INITIALIZING_CALL); + EditorResourceMenu(INITIALIZING_CALL); + EditorAnimalMenu(INITIALIZING_CALL); + EditorPlayerMenu(INITIALIZING_CALL); + */ + + PleaseWait(WINDOW_QUIT_MESSAGE); + break; + + case MAP_QUIT: + if(WNDCreate != NULL) + { + PosX = WNDCreate->getX(); + PosY = WNDCreate->getY(); + WNDCreate->setWaste(); + WNDCreate = NULL; + } + MapObj = NULL; + TextWidth = NULL; + width = 32; + TextHeight = NULL; + height = 32; + ButtonLandscape = NULL; + LandscapeType = 0; + PicTextureIndex = -1; + PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + texture = TRIANGLE_TEXTURE_SNOW; + PicBorderTextureIndex = -1; + PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + TextBorder = NULL; + border = 0; + border_texture = TRIANGLE_TEXTURE_SNOW; + break; + + case WINDOWQUIT: + if(WNDCreate != NULL) + { + PosX = WNDCreate->getX(); + PosY = WNDCreate->getY(); + WNDCreate->setWaste(); + WNDCreate = NULL; + } + MapObj = NULL; + TextWidth = NULL; + width = 32; + TextHeight = NULL; + height = 32; + ButtonLandscape = NULL; + LandscapeType = 0; + PicTextureIndex = -1; + PicTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + texture = TRIANGLE_TEXTURE_SNOW; + PicBorderTextureIndex = -1; + PicBorderTextureIndexGlobal = PICTURE_GREENLAND_TEXTURE_SNOW; + TextBorder = NULL; + border = 0; + border_texture = TRIANGLE_TEXTURE_SNOW; + break; + + default: break; + } +} + +#else +// now the 4 game callbacks from the menubar will follow + +void callback::GameMenu(int Param) +{ + static CWindow* WNDBackToMainMenu = NULL; + + enum + { + BACKTOMAIN = 1, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDBackToMainMenu != NULL) + break; + WNDBackToMainMenu = + new CWindow(GameMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - 125, global::s2->GameResolutionY / 2 - 60, 250, 140, + "Back to the main menu?", WINDOW_GREEN1, WINDOW_CLOSE); + if(global::s2->RegisterWindow(WNDBackToMainMenu)) + { + WNDBackToMainMenu->addButton(GameMenu, BACKTOMAIN, 20, 20, 200, 80, BUTTON_RED2, "Yes"); + } else + { + delete WNDBackToMainMenu; + WNDBackToMainMenu = NULL; + return; + } + break; + + case BACKTOMAIN: + if(global::s2->getMapObj() != NULL) + global::s2->delMapObj(); + WNDBackToMainMenu->setWaste(); + WNDBackToMainMenu = NULL; + mainmenu(INITIALIZING_CALL); + break; + + case WINDOWQUIT: + if(WNDBackToMainMenu != NULL) + { + WNDBackToMainMenu->setWaste(); + WNDBackToMainMenu = NULL; + } + break; + + default: break; + } +} +#endif + +void callback::MinimapMenu(int Param) +{ + static CWindow* WNDMinimap = NULL; + static CMap* MapObj = NULL; + static SDL_Surface* WndSurface = NULL; + static int num_x = 1, num_y = 1; + // only in case INITIALIZING_CALL needed to create the window + int width; + int height; + + enum + { + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDMinimap != NULL) + break; + + // this variables are needed to reduce the size of minimap-windows of big maps + num_x = (global::s2->getMapObj()->getMap()->width > 256 ? global::s2->getMapObj()->getMap()->width / 256 : 1); + num_y = (global::s2->getMapObj()->getMap()->height > 256 ? global::s2->getMapObj()->getMap()->height / 256 : 1); + + // make sure the minimap has the same proportions as the "real" map, so scale the same rate + num_x = (num_x > num_y ? num_x : num_y); + num_y = (num_x > num_y ? num_x : num_y); + + width = global::s2->getMapObj()->getMap()->width / num_x; + height = global::s2->getMapObj()->getMap()->height / num_y; + //--> 12px is width of left and right window frame and 30px is height of the upper and lower window frame + if((global::s2->getDisplaySurface()->w - 12 < width) || (global::s2->getDisplaySurface()->h - 30 < height)) + break; + WNDMinimap = new CWindow(MinimapMenu, WINDOWQUIT, global::s2->GameResolutionX / 2 - width / 2 - 6, + global::s2->GameResolutionY / 2 - height / 2 - 15, width + 12, height + 30, "Overview", WINDOW_NOTHING, + WINDOW_CLOSE | WINDOW_MOVE); + if(global::s2->RegisterWindow(WNDMinimap) && global::s2->RegisterCallback(MinimapMenu)) + { + WndSurface = WNDMinimap->getSurface(); + MapObj = global::s2->getMapObj(); + } else + { + delete WNDMinimap; + WNDMinimap = NULL; + return; + } + break; + + case CALL_FROM_GAMELOOP: + if(MapObj != NULL && WndSurface != NULL) + MapObj->drawMinimap(WndSurface); + break; + + case WINDOW_CLICKED_CALL: + if(MapObj != NULL) + { + int MouseX, MouseY; + if(SDL_GetMouseState(&MouseX, &MouseY) & SDL_BUTTON(1)) + { + if(MouseX > (WNDMinimap->getX() + 6) && MouseX < (WNDMinimap->getX() + WNDMinimap->getW() - 6) + && MouseY > (WNDMinimap->getY() + 20) && MouseY < (WNDMinimap->getY() + WNDMinimap->getH() - 10)) + { + DisplayRectangle displayRect = MapObj->getDisplayRect(); + displayRect.x = + (MouseX - WNDMinimap->getX() - 6 - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].nx) * TRIANGLE_WIDTH * num_x; + displayRect.y = + (MouseY - WNDMinimap->getY() - 20 - global::bmpArray[MAPPIC_ARROWCROSS_ORANGE].ny) * TRIANGLE_HEIGHT * num_y; + MapObj->setDisplayRect(displayRect); + } + } + } + break; + + case WINDOWQUIT: + if(WNDMinimap != NULL) + { + WNDMinimap->setWaste(); + WNDMinimap = NULL; + } + MapObj = NULL; + WndSurface = NULL; + global::s2->UnregisterCallback(MinimapMenu); + break; + + case MAP_QUIT: + // we do the same like in case WINDOWQUIT + if(WNDMinimap != NULL) + { + WNDMinimap->setWaste(); + WNDMinimap = NULL; + } + MapObj = NULL; + WndSurface = NULL; + global::s2->UnregisterCallback(MinimapMenu); + break; + + default: break; + } +} + +#ifdef _ADMINMODE +// the debugger is an object and a friend class of all other classes +// debugger-function only will construct a new debugger and if debugger-function gets a window-quit-message +// then the debugger-function will destruct the object +void callback::debugger(int Param) +{ + static CDebug* Debugger = NULL; + + switch(Param) + { + case INITIALIZING_CALL: + if(Debugger != NULL) + break; + Debugger = new CDebug(debugger, DEBUGGER_QUIT); + break; + + case DEBUGGER_QUIT: + delete Debugger; + Debugger = NULL; + break; + + default: + if(Debugger != NULL) + Debugger->sendParam(Param); + break; + } +} + +// this is the picture-viewer +void callback::viewer(int Param) +{ + static CWindow* WNDViewer = NULL; + static int index = 0; + static int PicInWndIndex = -1; + static char PicInfos[50]; + static CFont* PicInfosText = NULL; + + enum + { + BACKWARD_1, + BACKWARD_10, + BACKWARD_100, + FORWARD_1, + FORWARD_10, + FORWARD_100, + WINDOWQUIT + }; + + switch(Param) + { + case INITIALIZING_CALL: + if(WNDViewer != NULL) + break; + WNDViewer = new CWindow(viewer, WINDOWQUIT, 0, 0, 250, 140, "Viewer", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MOVE | WINDOW_RESIZE | WINDOW_MINIMIZE); + if(global::s2->RegisterWindow(WNDViewer)) + { + global::s2->RegisterCallback(viewer); + WNDViewer->addButton(viewer, BACKWARD_100, 0, 0, 35, 20, BUTTON_GREY, "100<-"); + WNDViewer->addButton(viewer, BACKWARD_10, 35, 0, 35, 20, BUTTON_GREY, "10<-"); + WNDViewer->addButton(viewer, BACKWARD_1, 70, 0, 35, 20, BUTTON_GREY, "1<-"); + WNDViewer->addButton(viewer, FORWARD_1, 105, 0, 35, 20, BUTTON_GREY, "->1"); + WNDViewer->addButton(viewer, FORWARD_10, 140, 0, 35, 20, BUTTON_GREY, "->10"); + WNDViewer->addButton(viewer, FORWARD_100, 175, 0, 35, 20, BUTTON_GREY, "->100"); + } else + { + delete WNDViewer; + WNDViewer = NULL; + return; + } + break; + + case CALL_FROM_GAMELOOP: + if(PicInWndIndex >= 0) + WNDViewer->delStaticPicture(PicInWndIndex); + PicInWndIndex = WNDViewer->addStaticPicture(5, 30, index); + + if(PicInfosText != NULL) + { + WNDViewer->delText(PicInfosText); + PicInfosText = NULL; + } + if(PicInfosText == NULL) + { + sprintf(PicInfos, "index=%d, w=%d, h=%d, nx=%d, ny=%d", index, global::bmpArray[index].w, global::bmpArray[index].h, + global::bmpArray[index].nx, global::bmpArray[index].ny); + PicInfosText = WNDViewer->addText(PicInfos, 220, 3, 14, FONT_RED); + } + + break; + + case BACKWARD_100: + if(index - 100 >= 0) + index -= 100; + else + index = 0; + break; + case BACKWARD_10: + if(index - 10 >= 0) + index -= 10; + else + index = 0; + break; + case BACKWARD_1: + if(index - 1 >= 0) + index -= 1; + else + index = 0; + break; + case FORWARD_1: + if(index < MAXBOBBMP - 1) + index++; + break; + case FORWARD_10: + if(index + 10 < MAXBOBBMP - 1) + index += 10; + break; + case FORWARD_100: + if(index + 100 < MAXBOBBMP - 1) + index += 100; + break; + + case WINDOWQUIT: + if(WNDViewer != NULL) + { + WNDViewer->setWaste(); + WNDViewer = NULL; + global::s2->UnregisterCallback(viewer); + index = 0; + PicInWndIndex = -1; + } + break; + + default: break; + } +} + +// this is a submenu for testing +void callback::submenu1(int Param) +{ + static CMenu* SubMenu = NULL; + static CButton* greatMoon = NULL; + static CFont* greatMoonText = NULL; + static CFont* counterText = NULL; + static CPicture* picObject = NULL; + static int counter = 0; + static CWindow* testWindow = NULL; + static CWindow* testWindow2 = NULL; + static CPicture* testWindowPicture = NULL; + static CFont* testWindowText = NULL; + static CFont* testWindowText2 = NULL; + static CTextfield* testTextfield = NULL; + static CFont* TextFrom_testTextfield = NULL; + static CTextfield* testTextfield_testWindow = NULL; + static CSelectBox* testSelectBox = NULL; + + static int picIndex = -1; + char puffer[80]; + + // if this is the first time the function is called + if(Param == INITIALIZING_CALL) + global::s2->RegisterCallback(submenu1); + + enum + { + MAINMENU = 1, + GREATMOON, + SMALLMOON, + TOOSMALL, + CREATEWINDOW, + GREATMOONENTRY, + GREATMOONLEAVE, + PICOBJECT, + PICOBJECTENTRY, + PICOBJECTLEAVE, + TESTWINDOWPICTURE, + TESTWINDOWPICTUREENTRY, + TESTWINDOWPICTURELEAVE, + TESTWINDOWQUITMESSAGE, + TESTWINDOW2QUITMESSAGE, + SELECTBOX_OPTION1, + SELECTBOX_OPTION2, + SELECTBOX_OPTION3 + }; + + switch(Param) + { + case INITIALIZING_CALL: + SubMenu = new CMenu(SPLASHSCREEN_SUBMENU1); + if(!global::s2->RegisterMenu(SubMenu)) + { + delete SubMenu; + SubMenu = NULL; + return; + } + SubMenu->addButton(submenu1, MAINMENU, 400, 440, 200, 20, BUTTON_RED1, "back"); + greatMoon = SubMenu->addButton(submenu1, GREATMOON, 100, 100, 200, 200, BUTTON_STONE, NULL, MOON); + greatMoon->setMotionParams(GREATMOONENTRY, GREATMOONLEAVE); + SubMenu->addButton(submenu1, SMALLMOON, 100, 350, global::bmpArray[MOON].w, global::bmpArray[MOON].h, BUTTON_STONE, NULL, MOON); + SubMenu->addButton(submenu1, TOOSMALL, 100, 400, global::bmpArray[MOON].w - 1, global::bmpArray[MOON].h - 1, BUTTON_STONE, NULL, + MOON); + SubMenu->addButton(submenu1, CREATEWINDOW, 500, 10, 130, 30, BUTTON_GREEN1, "Create window"); + picObject = SubMenu->addPicture(submenu1, PICOBJECT, 200, 30, MIS0BOBS_SHIP); + picObject->setMotionParams(PICOBJECTENTRY, PICOBJECTLEAVE); + // text block with \n + sprintf(puffer, "\nTextblock:\n\nNeue Zeile\nNoch eine neue Zeile"); + SubMenu->addText(puffer, 400, 200, 14); + testTextfield = SubMenu->addTextfield(400, 300, 10, 3); + testSelectBox = SubMenu->addSelectBox(500, 500, 300, 200); + testSelectBox->setOption("Erste Option", submenu1, SELECTBOX_OPTION1); + testSelectBox->setOption("Zweite Option", submenu1, SELECTBOX_OPTION2); + testSelectBox->setOption("Dritte Option", submenu1, SELECTBOX_OPTION3); + break; + + case MAINMENU: + SubMenu->setWaste(); + SubMenu = NULL; + greatMoon = NULL; + greatMoonText = NULL; + counterText = NULL; + testWindowPicture = NULL; + testWindowText = NULL; + testWindowText2 = NULL; + testTextfield = NULL; + TextFrom_testTextfield = NULL; + testTextfield_testWindow = NULL; + testSelectBox = NULL; + global::s2->UnregisterCallback(submenu1); + if(testWindow != NULL) + { + testWindow->setWaste(); + testWindow = NULL; + } + if(testWindow2 != NULL) + { + testWindow2->setWaste(); + testWindow2 = NULL; + } + picIndex = -1; + break; + + case GREATMOON: + SubMenu->addText("Title!", 300, 10, 14); + sprintf(puffer, "Window X: %d Window Y: %d", global::s2->GameResolutionX, global::s2->GameResolutionY); + SubMenu->addText(puffer, 10, 10, 14); + break; + + case SMALLMOON: + SubMenu->delButton(greatMoon); + SubMenu->delStaticPicture(picIndex); + picIndex = -1; + break; + + case TOOSMALL: + if(picIndex == -1) + picIndex = SubMenu->addStaticPicture(0, 0, MAINFRAME_640_480); + break; + + case CREATEWINDOW: + if(testWindow == NULL) + { + testWindow = new CWindow(submenu1, TESTWINDOWQUITMESSAGE, 5, 5, 350, 240, "Window", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); + if(global::s2->RegisterWindow(testWindow)) + { + testWindow->addText("Text inside the window", 10, 10, 14); + testWindow->addButton(submenu1, -10, 150, 100, 210, 30, BUTTON_GREEN2, "Button inside the window"); + testWindowPicture = testWindow->addPicture(submenu1, TESTWINDOWPICTURE, 10, 60, MIS2BOBS_FORTRESS); + testWindowPicture->setMotionParams(TESTWINDOWPICTUREENTRY, TESTWINDOWPICTURELEAVE); + testTextfield_testWindow = testWindow->addTextfield(130, 30, 10, 3, 14, FONT_RED, BUTTON_GREY, true); + testTextfield_testWindow->setText( + "This is a very long test text in order to destroy the text field completely once and for all"); + } else + { + delete testWindow; + testWindow = NULL; + return; + } + } + if(testWindow2 == NULL) + { + testWindow2 = new CWindow(submenu1, TESTWINDOW2QUITMESSAGE, 200, 5, 350, 240, "Another Window", WINDOW_GREEN1, + WINDOW_CLOSE | WINDOW_MOVE | WINDOW_MINIMIZE | WINDOW_RESIZE); + if(global::s2->RegisterWindow(testWindow2)) + { + testWindow2->addText("Text inside the window", 50, 40, 9); + testWindow2->addButton(submenu1, -10, 100, 100, 100, 20, BUTTON_GREEN2, "Button"); + } else + { + delete testWindow2; + testWindow2 = NULL; + return; + } + } + break; + + case GREATMOONENTRY: + if(greatMoonText == NULL) + greatMoonText = SubMenu->addText("Test-Text", 100, 10, 14); + break; + + case GREATMOONLEAVE: + if(greatMoonText != NULL) + { + SubMenu->delText(greatMoonText); + greatMoonText = NULL; + } + break; + + case PICOBJECT: + if(greatMoon != NULL) + { + SubMenu->delButton(greatMoon); + greatMoon = NULL; + } + break; + + case PICOBJECTENTRY: + if(greatMoonText == NULL) + greatMoonText = SubMenu->addText("Test-Text", 100, 10, 14); + break; + + case PICOBJECTLEAVE: + if(greatMoonText != NULL) + { + SubMenu->delText(greatMoonText); + greatMoonText = NULL; + } + break; + + case TESTWINDOWPICTURE: + if(testWindowText == NULL) + testWindowText = testWindow->addText("Clicked on castle", 10, 200, 11); + else + { + testWindow->delText(testWindowText); + testWindowText = NULL; + } + break; + + case TESTWINDOWPICTUREENTRY: + if(testWindowText2 != NULL) + { + testWindow->delText(testWindowText2); + testWindowText2 = NULL; + } + testWindowText2 = testWindow->addText("Bildbereich betreten", 10, 220, 11); + break; + + case TESTWINDOWPICTURELEAVE: + if(testWindowText2 != NULL) + { + testWindow->delText(testWindowText2); + testWindowText2 = NULL; + } + testWindowText2 = testWindow->addText("Bildbereich verlassen", 10, 220, 11); + break; + + case TESTWINDOWQUITMESSAGE: + testWindow->setWaste(); + testWindow = NULL; + break; + + case TESTWINDOW2QUITMESSAGE: + testWindow2->setWaste(); + testWindow2 = NULL; + break; + + case CALL_FROM_GAMELOOP: + if(counter % 10 == 0) + { + if(counterText != NULL) + { + SubMenu->delText(counterText); + counterText = NULL; + } + if(counterText == NULL) + { + sprintf(puffer, "counter: %d", counter); + counterText = SubMenu->addText(puffer, 100, 20, 9); + } + + if(TextFrom_testTextfield != NULL) + { + SubMenu->delText(TextFrom_testTextfield); + TextFrom_testTextfield = NULL; + } + sprintf(puffer, "Der Text im Textfeld lautet: %s", testTextfield->getText()); + TextFrom_testTextfield = SubMenu->addText(puffer, 200, 400, 14); + } + counter++; + break; + + default: break; + } +} +#endif diff --git a/callbacks.h b/callbacks.h index 85203f6..8e1e398 100644 --- a/callbacks.h +++ b/callbacks.h @@ -1,45 +1,45 @@ -// NOTE: negative callbackParams are reserved: -1 = callback is called first time, -2 = used by gameloop for registered -// callbacks (callbacks that will additionally execute WITHIN the gameloop) - -// NOTE: don't forget that if the map quits (Param: MAP_QUIT), there are many windows that have to be closed. -// This happens for example if a new Map will be loaded or user goes to main menu. So if you add a new window, don't forget -// to add it to this "close lists" if it's necessary (also in the file CMap.cpp, function setMouseData(Button)). - -#ifndef _CALLBACKS_H -#define _CALLBACKS_H - -#include "includes.h" - -namespace callback { -// PleaseWait creates a small window (not moveable, not resizeable, not minimizable, not closeable) with the String "Please wait..." -void PleaseWait(int Param); -void ShowStatus(int Param); -void mainmenu(int Param); -void submenuOptions(int Param); -void MinimapMenu(int Param); -#ifdef _EDITORMODE -void EditorHelpMenu(int Param); -void EditorMainMenu(int Param); -void EditorLoadMenu(int Param); -void EditorSaveMenu(int Param); -void EditorQuitMenu(int Param); -void EditorTextureMenu(int Param); -void EditorTreeMenu(int Param); -void EditorResourceMenu(int Param); -void EditorLandscapeMenu(int Param); -void EditorAnimalMenu(int Param); -void EditorPlayerMenu(int Param); -void EditorCreateMenu(int Param); -void EditorCursorMenu(int Param); -#else -void GameMenu(int Param); -#endif - -#ifdef _ADMINMODE -void debugger(int Param); -void viewer(int Param); -void submenu1(int Param); -#endif -} // namespace callback - -#endif +// NOTE: negative callbackParams are reserved: -1 = callback is called first time, -2 = used by gameloop for registered +// callbacks (callbacks that will additionally execute WITHIN the gameloop) + +// NOTE: don't forget that if the map quits (Param: MAP_QUIT), there are many windows that have to be closed. +// This happens for example if a new Map will be loaded or user goes to main menu. So if you add a new window, don't forget +// to add it to this "close lists" if it's necessary (also in the file CMap.cpp, function setMouseData(Button)). + +#ifndef _CALLBACKS_H +#define _CALLBACKS_H + +#include "includes.h" + +namespace callback { +// PleaseWait creates a small window (not moveable, not resizeable, not minimizable, not closeable) with the String "Please wait..." +void PleaseWait(int Param); +void ShowStatus(int Param); +void mainmenu(int Param); +void submenuOptions(int Param); +void MinimapMenu(int Param); +#ifdef _EDITORMODE +void EditorHelpMenu(int Param); +void EditorMainMenu(int Param); +void EditorLoadMenu(int Param); +void EditorSaveMenu(int Param); +void EditorQuitMenu(int Param); +void EditorTextureMenu(int Param); +void EditorTreeMenu(int Param); +void EditorResourceMenu(int Param); +void EditorLandscapeMenu(int Param); +void EditorAnimalMenu(int Param); +void EditorPlayerMenu(int Param); +void EditorCreateMenu(int Param); +void EditorCursorMenu(int Param); +#else +void GameMenu(int Param); +#endif + +#ifdef _ADMINMODE +void debugger(int Param); +void viewer(int Param); +void submenu1(int Param); +#endif +} // namespace callback + +#endif diff --git a/defines.h b/defines.h index 4ea8fab..0af7324 100644 --- a/defines.h +++ b/defines.h @@ -1,1243 +1,1243 @@ -#ifndef _DEFINES_H -#define _DEFINES_H - -// 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 -//#define _ADMINMODE -// in editor mode there is the possibility to load, edit and save created maps -//#define _EDITORMODE - -// callback parameters -enum -{ - // NOTE: we don't have a global WINDOW_QUIT_MESSAGE, cause if there were more than one window created by a callback function - // we wouldn't know which window was closed by the user. so we need a specified quit-message for each window. - - // first call of a callback function - INITIALIZING_CALL = -1, - // a callback that is registered at the gameloop will be called from the gameloop with this value - CALL_FROM_GAMELOOP = -2, - // if user goes to main menu, all menubar callbacks will be called with MAP_QUIT - MAP_QUIT = -3, - // parameter for closing the debugger window - DEBUGGER_QUIT = -4, - // this will happen every time the user clicks anywhere on the window - WINDOW_CLICKED_CALL = -5, - // this window quit message is ONLY useable to call a callback function explicit with this value - WINDOW_QUIT_MESSAGE = -6 -}; - -// BOBTYPES -enum -{ - BOBTYPE01 = 1, - BOBTYPE02 = 2, - BOBTYPE03 = 3, - BOBTYPE04 = 4, - BOBTYPE05 = 5, - BOBTYPE07 = 7, - BOBTYPE14 = 14 -}; - -// FILE ENDINGS -enum -{ - LST = 0, - BOB, - IDX, - BBM, - LBM, - WLD, - SWD, - GOU -}; - -// Structure for Bobtypes 2 (RLE-Bitmaps), 4 (specific Bitmaps), 14 (uncompressed Bitmaps) -struct bobBMP -{ - Uint16 nx; - Uint16 ny; - Uint16 w; - Uint16 h; - SDL_Surface* surface; -}; - -// Structure for Bobtype 5 (Palette) -struct bobPAL -{ - SDL_Color colors[256]; -}; - -// Structure for Bobtype 7 (Shadow-Bitmaps) -struct bobSHADOW -{ - Uint16 nx; - Uint16 ny; - Uint16 w; - Uint16 h; - SDL_Surface* surface; -}; - -// Datatypes for the Map -// vector structure -struct vector -{ - float x, y, z; -}; -// structure for the 250 9Byte-Items from die 2250Bytes long map header -struct MapHeaderItem -{ - Uint8 type; // land or water (snow, swamp and lava are not counted) - Uint16 x; - Uint16 y; - Uint32 area; // number of vertices this area has -}; -// point structure -struct point -{ - Uint16 VertexX; /* number of the vertex on x-axis */ - Uint16 VertexY; /* number of the vertex on y-axis */ - Sint32 x; - Sint32 y; /* calculated with section 1 */ - int z; /* calculated with section 1 */ - Uint8 h; /* section 1 */ - Sint32 i; /* calculated light values for new shading by SGE (a 16 bit integer shifted left 16 times --> fixed point math for speed) */ - vector flatVector; - vector normVector; - Uint8 rsuTexture; /* section 2 */ - Uint8 usdTexture; /* section 3 */ - Uint8 road; /* section 4 */ - Uint8 objectType; /* section 5 */ - Uint8 objectInfo; /* section 6 */ - Uint8 animal; /* section 7 */ - Uint8 unknown1; /* section 8 */ - Uint8 build; /* section 9 */ - Uint8 unknown2; /* section 10 */ - Uint8 unknown3; /* section 11 */ - Uint8 resource; /* section 12 */ - Uint8 shading; /* section 13 */ - Uint8 unknown5; /* section 14 */ -}; -// structure for display, cause SDL_Rect's datatypes are too small -struct DisplayRectangle -{ - Sint32 x, y; - Sint32 w, h; -}; -struct Point16 -{ - Sint16 x, y; -}; -// map strutcture -struct bobMAP -{ - char name[20]; - Uint16 height; - Uint16 height_old; - Uint16 height_pixel; - Uint16 width; - Uint16 width_old; - Uint16 width_pixel; - Uint8 type; - Uint8 player; - // these are the original values - Uint16 HQx[7]; - Uint16 HQy[7]; - char author[20]; - // 250 items from the big map header - MapHeaderItem header[250]; - struct point* vertex; -}; -// map types -#define MAP_GREENLAND 0x00 -#define MAP_WASTELAND 0x01 -#define MAP_WINTERLAND 0x02 -// structure to save vertex coordinates -struct cursorPoint -{ - int x; - int y; - int blit_x; - int blit_y; - bool active; - bool fill_rsu; - bool fill_usd; -}; - -// IMPORTANT: for enumerating the contents of loaded files put the constants in the right order here. -// if the order of file loading changes, so change the constants in the same way! -// (these are the array-indices for an array of BobtypeBMP-Structures) - -// enumeration for BobtypePAL (palettes) -enum -{ - RESOURCE_PALETTE = 0, - IO_PALETTE -}; - -// font alignment (after all used by CFont and other objects using CFont) -enum -{ - ALIGN_LEFT = 0, - ALIGN_MIDDLE, - ALIGN_RIGHT -}; -// i put some color values here, cause we need FONT_COLOR_COUNT in the next enumeration -// font color (after all used by CFont and other objects using CFont) -enum -{ - FONT_BLUE = 0, - FONT_RED, - FONT_ORANGE, - FONT_GREEN, - FONT_MINTGREEN, - FONT_YELLOW, - FONT_RED_BRIGHT, - - FONT_COLOR_COUNT -}; -// player colors, necessary for the read_bob03- and read_bob04-function -enum -{ - PLAYER_BLUE = 0x80, - PLAYER_RED = 0x88, - PLAYER_ORANGE = 0x04, - PLAYER_GREEN = 0x85, - PLAYER_MINTGREEN = 0x94, - PLAYER_YELLOW = 0x01, - PLAYER_RED_BRIGHT = 0x10 -}; - -// enumeration for BobtypeBMP (pics) -enum -{ - // BEGIN: /GFX/PICS/SETUP997.LBM - SPLASHSCREEN_LOADING_S2SCREEN = 0, - // END: /GFX/PICS/SETUP997.LBM - - // BEGIN: /GFX/PICS/SETUP000.LBM - SPLASHSCREEN_MAINMENU_BROWN, - // END: /GFX/PICS/SETUP000.LBM - - // BEGIN: /GFX/PICS/SETUP010.LBM - SPLASHSCREEN_MAINMENU, - // END: /GFX/PICS/SETUP010.LBM - - // BEGIN: /GFX/PICS/SETUP011.LBM - SPLASHSCREEN_SUBMENU1, - // END: /GFX/PICS/SETUP011.LBM - - // BEGIN: /GFX/PICS/SETUP012.LBM - SPLASHSCREEN_SUBMENU2, - // END: /GFX/PICS/SETUP012.LBM - - // BEGIN: /GFX/PICS/SETUP013.LBM - SPLASHSCREEN_SUBMENU3, - // END: /GFX/PICS/SETUP013.LBM - - // BEGIN: /GFX/PICS/SETUP014.LBM - SPLASHSCREEN_SUBMENU4, - // END: /GFX/PICS/SETUP014.LBM - - // BEGIN: /GFX/PICS/SETUP015.LBM - SPLASHSCREEN_SUBMENU5, - // END: /GFX/PICS/SETUP015.LBM - - // BEGIN: /GFX/PICS/SETUP666.LBM - SPLASHSCREEN_UNIVERSE1, - // END: /GFX/PICS/SETUP666.LBM - - // BEGIN: /GFX/PICS/SETUP667.LBM - SPLASHSCREEN_SUN1, - // END: /GFX/PICS/SETUP667.LBM - - // BEGIN: /GFX/PICS/SETUP801.LBM - SPLASHSCREEN_SETUP801, - // END: /GFX/PICS/SETUP801.LBM - - // BEGIN: /GFX/PICS/SETUP802.LBM - SPLASHSCREEN_LOADING_STANDARD, - // END: /GFX/PICS/SETUP802.LBM - - // BEGIN: /GFX/PICS/SETUP803.LBM - SPLASHSCREEN_LOADING_GREENLAND1, - // END: /GFX/PICS/SETUP803.LBM - - // BEGIN: /GFX/PICS/SETUP804.LBM - SPLASHSCREEN_LOADING_WASTELAND, - // END: /GFX/PICS/SETUP804.LBM - - // BEGIN: /GFX/PICS/SETUP805.LBM - SPLASHSCREEN_LOADING_GREENLAND2, - // END: /GFX/PICS/SETUP805.LBM - - // BEGIN: /GFX/PICS/SETUP806.LBM - SPLASHSCREEN_LOADING_GREENLAND3, - // END: /GFX/PICS/SETUP806.LBM - - // BEGIN: /GFX/PICS/SETUP810.LBM - SPLASHSCREEN_LOADING_WINTER1, - // END: /GFX/PICS/SETUP810.LBM - - // BEGIN: /GFX/PICS/SETUP811.LBM - SPLASHSCREEN_LOADING_WINTER2, - // END: /GFX/PICS/SETUP811.LBM - - // BEGIN: /GFX/PICS/SETUP895.LBM - SPLASHSCREEN_LOADING_SETUP895, - // END: /GFX/PICS/SETUP895.LBM - - // BEGIN: /GFX/PICS/SETUP896.LBM - SPLASHSCREEN_LOADING_ROMANCAMPAIGN1, - // END: /GFX/PICS/SETUP896.LBM - - // BEGIN: /GFX/PICS/SETUP897.LBM - SPLASHSCREEN_LOADING_ROMANCAMPAIGN2, - // END: /GFX/PICS/SETUP897.LBM - - // BEGIN: /GFX/PICS/SETUP898.LBM - SPLASHSCREEN_LOADING_ROMANCAMPAIGN3, - // END: /GFX/PICS/SETUP898.LBM - - // BEGIN: /GFX/PICS/SETUP899.LBM - SPLASHSCREEN_LOADING_ROMANCAMPAIGN_GREY, - // END: /GFX/PICS/SETUP899.LBM - - // BEGIN: /GFX/PICS/SETUP990.LBM - SPLASHSCREEN_SETUP990, - // END: /GFX/PICS/SETUP990.LBM - - // BEGIN: /GFX/PICS/WORLD.LBM - SPLASHSCREEN_WORLDCAMPAIGN, - // END: /GFX/PICS/WORLD.LBM - - // BEGIN: /GFX/PICS/WORLDMSK.LBM - SPLASHSCREEN_WORLDCAMPAIGN_SECTIONS, - // END: /GFX/PICS/WORLDMSK.LBM - - // BEGIN: /DATA/RESOURCE.IDX (AND /DATA/RESOURCE.DAT) OR /DATA/EDITRES.IDX (AND /DATA/EDITRES.DAT) - // BEGIN: FONT - - /// IMPORTANT: BECAUSE OF MULTIPLE COLORS FOR EACH CHARACTER THIS FONT-ENUMERATION IS NO LONGER CONSISTENT. - /// ONLY THE START-VALUES (FONT9_SPACE, FONT11_SPACE, FONT14_SPACE) HAVE THE RIGHT INDEX! - - // fontsize 11 - FONT11_SPACE, // spacebar - FONT11_EXCLAMATION_POINT, // ! - FONT11_DOUBLE_QUOTES, // " - FONT11_SHARP, // # - FONT11_DOLLAR, // $ - FONT11_PERCENT, // % - FONT11_AMPERSAND, // & - FONT11_SINGLE_QUOTES, // ' - FONT11_ROUND_BRACKET_OPEN, // ( - FONT11_ROUND_BRACKET_CLOSE, // ) - FONT11_STAR, // * - FONT11_PLUS, // + - FONT11_COMMA, // , - FONT11_MINUS, // - - FONT11_DOT, // . - FONT11_SLASH, // / - FONT11_0, // 0 - FONT11_1, // 1 - FONT11_2, // 2 - FONT11_3, // 3 - FONT11_4, // 4 - FONT11_5, // 5 - FONT11_6, // 6 - FONT11_7, // 7 - FONT11_8, // 8 - FONT11_9, // 9 - FONT11_COLON, // : - FONT11_SEMICOLON, // ; - FONT11_ARROW_BRACKET_OPEN, // < - FONT11_EQUAL, // = - FONT11_ARROW_BRACKET_CLOSE, // > - FONT11_INTERROGATION_POINT, // ? - FONT11_AT, // @ - FONT11_A, // A - FONT11_B, // B - FONT11_C, // C - FONT11_D, // D - FONT11_E, // E - FONT11_F, // F - FONT11_G, // G - FONT11_H, // H - FONT11_I, // I - FONT11_J, // J - FONT11_K, // K - FONT11_L, // L - FONT11_M, // M - FONT11_N, // N - FONT11_O, // O - FONT11_P, // P - FONT11_Q, // Q - FONT11_R, // R - FONT11_S, // S - FONT11_T, // T - FONT11_U, // U - FONT11_V, // V - FONT11_W, // W - FONT11_X, // X - FONT11_Y, // Y - FONT11_Z, // Z - FONT11_BACKSLASH, /* \ */ - FONT11_UNDERSCORE, // _ - FONT11_a, // a - FONT11_b, // b - FONT11_c, // c - FONT11_d, // d - FONT11_e, // e - FONT11_f, // f - FONT11_g, // g - FONT11_h, // h - FONT11_i, // i - FONT11_j, // j - FONT11_k, // k - FONT11_l, // l - FONT11_m, // m - FONT11_n, // n - FONT11_o, // o - FONT11_p, // p - FONT11_q, // q - FONT11_r, // r - FONT11_s, // s - FONT11_t, // t - FONT11_u, // u - FONT11_v, // v - FONT11_w, // w - FONT11_x, // x - FONT11_y, // y - FONT11_z, // z - FONT11_ANSI_199, // Ç - FONT11_ANSI_252, // ü - FONT11_ANSI_233, // é - FONT11_ANSI_226, // â - FONT11_ANSI_228, // ä - FONT11_ANSI_224, // à - FONT11_ANSI_231, // ç - FONT11_ANSI_234, // ê - FONT11_ANSI_235, // ë - FONT11_ANSI_232, // è - FONT11_ANSI_239, // ï - FONT11_ANSI_238, // î - FONT11_ANSI_236, // ì - FONT11_ANSI_196, // Ä - FONT11_ANSI_244, // ô - FONT11_ANSI_246, // ö - FONT11_ANSI_242, // ò - FONT11_ANSI_251, // û - FONT11_ANSI_249, // ù - FONT11_ANSI_214, // Ö - FONT11_ANSI_220, // Ü - FONT11_ANSI_225, // á - FONT11_ANSI_237, // í - FONT11_ANSI_243, // ó - FONT11_ANSI_250, // ú - FONT11_ANSI_241, // ñ - FONT11_ANSI_223, // ß - FONT11_ANSI_169, // © - // fontsize 9 - FONT9_SPACE = FONT11_SPACE + FONT_COLOR_COUNT * 115, // spacebar - FONT9_EXCLAMATION_POINT, // ! - FONT9_DOUBLE_QUOTES, // " - FONT9_SHARP, // # - FONT9_DOLLAR, // $ - FONT9_PERCENT, // % - FONT9_AMPERSAND, // & - FONT9_SINGLE_QUOTES, // ' - FONT9_ROUND_BRACKET_OPEN, // ( - FONT9_ROUND_BRACKET_CLOSE, // ) - FONT9_STAR, // * - FONT9_PLUS, // + - FONT9_COMMA, // , - FONT9_MINUS, // - - FONT9_DOT, // . - FONT9_SLASH, // / - FONT9_0, // 0 - FONT9_1, // 1 - FONT9_2, // 2 - FONT9_3, // 3 - FONT9_4, // 4 - FONT9_5, // 5 - FONT9_6, // 6 - FONT9_7, // 7 - FONT9_8, // 8 - FONT9_9, // 9 - FONT9_COLON, // : - FONT9_SEMICOLON, // ; - FONT9_ARROW_BRACKET_OPEN, // < - FONT9_EQUAL, // = - FONT9_ARROW_BRACKET_CLOSE, // > - FONT9_INTERROGATION_POINT, // ? - FONT9_AT, // @ - FONT9_A, // A - FONT9_B, // B - FONT9_C, // C - FONT9_D, // D - FONT9_E, // E - FONT9_F, // F - FONT9_G, // G - FONT9_H, // H - FONT9_I, // I - FONT9_J, // J - FONT9_K, // K - FONT9_L, // L - FONT9_M, // M - FONT9_N, // N - FONT9_O, // O - FONT9_P, // P - FONT9_Q, // Q - FONT9_R, // R - FONT9_S, // S - FONT9_T, // T - FONT9_U, // U - FONT9_V, // V - FONT9_W, // W - FONT9_X, // X - FONT9_Y, // Y - FONT9_Z, // Z - FONT9_BACKSLASH, /* \ */ - FONT9_UNDERSCORE, // _ - FONT9_a, // a - FONT9_b, // b - FONT9_c, // c - FONT9_d, // d - FONT9_e, // e - FONT9_f, // f - FONT9_g, // g - FONT9_h, // h - FONT9_i, // i - FONT9_j, // j - FONT9_k, // k - FONT9_l, // l - FONT9_m, // m - FONT9_n, // n - FONT9_o, // o - FONT9_p, // p - FONT9_q, // q - FONT9_r, // r - FONT9_s, // s - FONT9_t, // t - FONT9_u, // u - FONT9_v, // v - FONT9_w, // w - FONT9_x, // x - FONT9_y, // y - FONT9_z, // z - FONT9_ANSI_199, // Ç - FONT9_ANSI_252, // ü - FONT9_ANSI_233, // é - FONT9_ANSI_226, // â - FONT9_ANSI_228, // ä - FONT9_ANSI_224, // à - FONT9_ANSI_231, // ç - FONT9_ANSI_234, // ê - FONT9_ANSI_235, // ë - FONT9_ANSI_232, // è - FONT9_ANSI_239, // ï - FONT9_ANSI_238, // î - FONT9_ANSI_236, // ì - FONT9_ANSI_196, // Ä - FONT9_ANSI_244, // ô - FONT9_ANSI_246, // ö - FONT9_ANSI_242, // ò - FONT9_ANSI_251, // û - FONT9_ANSI_249, // ù - FONT9_ANSI_214, // Ö - FONT9_ANSI_220, // Ü - FONT9_ANSI_225, // á - FONT9_ANSI_237, // í - FONT9_ANSI_243, // ó - FONT9_ANSI_250, // ú - FONT9_ANSI_241, // ñ - FONT9_ANSI_223, // ß - FONT9_ANSI_169, // © - // fontsize 14 - FONT14_SPACE = FONT9_SPACE + FONT_COLOR_COUNT * 115, // spacebar - FONT14_EXCLAMATION_POINT, // ! - FONT14_DOUBLE_QUOTES, // " - FONT14_SHARP, // # - FONT14_DOLLAR, // $ - FONT14_PERCENT, // % - FONT14_AMPERSAND, // & - FONT14_SINGLE_QUOTES, // ' - FONT14_ROUND_BRACKET_OPEN, // ( - FONT14_ROUND_BRACKET_CLOSE, // ) - FONT14_STAR, // * - FONT14_PLUS, // + - FONT14_COMMA, // , - FONT14_MINUS, // - - FONT14_DOT, // . - FONT14_SLASH, // / - FONT14_0, // 0 - FONT14_1, // 1 - FONT14_2, // 2 - FONT14_3, // 3 - FONT14_4, // 4 - FONT14_5, // 5 - FONT14_6, // 6 - FONT14_7, // 7 - FONT14_8, // 8 - FONT14_9, // 9 - FONT14_COLON, // : - FONT14_SEMICOLON, // ; - FONT14_ARROW_BRACKET_OPEN, // < - FONT14_EQUAL, // = - FONT14_ARROW_BRACKET_CLOSE, // > - FONT14_INTERROGATION_POINT, // ? - FONT14_AT, // @ - FONT14_A, // A - FONT14_B, // B - FONT14_C, // C - FONT14_D, // D - FONT14_E, // E - FONT14_F, // F - FONT14_G, // G - FONT14_H, // H - FONT14_I, // I - FONT14_J, // J - FONT14_K, // K - FONT14_L, // L - FONT14_M, // M - FONT14_N, // N - FONT14_O, // O - FONT14_P, // P - FONT14_Q, // Q - FONT14_R, // R - FONT14_S, // S - FONT14_T, // T - FONT14_U, // U - FONT14_V, // V - FONT14_W, // W - FONT14_X, // X - FONT14_Y, // Y - FONT14_Z, // Z - FONT14_BACKSLASH, /* \ */ - FONT14_UNDERSCORE, // _ - FONT14_a, // a - FONT14_b, // b - FONT14_c, // c - FONT14_d, // d - FONT14_e, // e - FONT14_f, // f - FONT14_g, // g - FONT14_h, // h - FONT14_i, // i - FONT14_j, // j - FONT14_k, // k - FONT14_l, // l - FONT14_m, // m - FONT14_n, // n - FONT14_o, // o - FONT14_p, // p - FONT14_q, // q - FONT14_r, // r - FONT14_s, // s - FONT14_t, // t - FONT14_u, // u - FONT14_v, // v - FONT14_w, // w - FONT14_x, // x - FONT14_y, // y - FONT14_z, // z - FONT14_ANSI_199, // Ç - FONT14_ANSI_252, // ü - FONT14_ANSI_233, // é - FONT14_ANSI_226, // â - FONT14_ANSI_228, // ä - FONT14_ANSI_224, // à - FONT14_ANSI_231, // ç - FONT14_ANSI_234, // ê - FONT14_ANSI_235, // ë - FONT14_ANSI_232, // è - FONT14_ANSI_239, // ï - FONT14_ANSI_238, // î - FONT14_ANSI_236, // ì - FONT14_ANSI_196, // Ä - FONT14_ANSI_244, // ô - FONT14_ANSI_246, // ö - FONT14_ANSI_242, // ò - FONT14_ANSI_251, // û - FONT14_ANSI_249, // ù - FONT14_ANSI_214, // Ö - FONT14_ANSI_220, // Ü - FONT14_ANSI_225, // á - FONT14_ANSI_237, // í - FONT14_ANSI_243, // ó - FONT14_ANSI_250, // ú - FONT14_ANSI_241, // ñ - FONT14_ANSI_223, // ß - FONT14_ANSI_169, // © - // END: FONT - - // now the main resources will follow (frames, cursor, ...) - // resolution behind means not resolution of the pic but window resolution the pic belongs to - MAINFRAME_640_480 = 2441, - SPLITFRAME_LEFT_640_480, - SPLITFRAME_RIGHT_640_480, - MAINFRAME_800_600, - SPLITFRAME_LEFT_800_600, - SPLITFRAME_RIGHT_800_600, - MAINFRAME_1024_768, - SPLITFRAME_LEFT_1024_768, - SPLITFRAME_RIGHT_1024_768, - MAINFRAME_LEFT_1280_1024, - MAINFRAME_RIGHT_1280_1024, - SPLITFRAME_LEFT_1280_1024, - SPLITFRAME_RIGHT_1280_1024, - STATUE_UP_LEFT, - STATUE_UP_RIGHT, - STATUE_DOWN_LEFT, - STATUE_DOWN_RIGHT, - SPLITFRAME_ADDITIONAL_LEFT_640_480, - SPLITFRAME_ADDITIONAL_RIGHT_640_480, - SPLITFRAME_ADDITIONAL_LEFT_800_600, - SPLITFRAME_ADDITIONAL_RIGHT_800_600, - SPLITFRAME_ADDITIONAL_LEFT_1024_768, - SPLITFRAME_ADDITIONAL_RIGHT_1024_768, - SPLITFRAME_ADDITIONAL_LEFT_1280_1024, - SPLITFRAME_ADDITIONAL_RIGHT_1280_1024, - MENUBAR, - CURSOR, - CURSOR_CLICKED, - CROSS, - MOON, - CIRCLE_HIGH_GREY, - CIRCLE_FLAT_GREY, - WINDOW_LEFT_UPPER_CORNER, - WINDOW_RIGHT_UPPER_CORNER, - WINDOW_LEFT_FRAME, - WINDOW_RIGHT_FRAME, - WINDOW_LOWER_FRAME, - WINDOW_BACKGROUND, - WINDOW_UPPER_FRAME, - WINDOW_UPPER_FRAME_MARKED, - WINDOW_UPPER_FRAME_CLICKED, - WINDOW_CORNER_RECTANGLE, - WINDOW_BUTTON_RESIZE, - WINDOW_BUTTON_CLOSE, - WINDOW_BUTTON_MINIMIZE, - WINDOW_CORNER_RECTANGLE_2, // unknown function - WINDOW_BUTTON_RESIZE_CLICKED, - WINDOW_BUTTON_CLOSE_CLICKED, - WINDOW_BUTTON_MINIMIZE_CLICKED, - WINDOW_CORNER_RECTANGLE_3, // unknown function - WINDOW_BUTTON_RESIZE_MARKED, - WINDOW_BUTTON_CLOSE_MARKED, - WINDOW_BUTTON_MINIMIZE_MARKED, - WINDOW_BUTTON_MINIMIZE_MARKED_DOUBLE_ENTRY, // double entry, picture is two times in the file -// END: /DATA/RESOURCE.IDX (AND /DATA/RESOURCE.DAT) OR /DATA/EDITRES.IDX (AND /DATA/EDITRES.DAT) - -#ifdef _EDITORMODE - // BEGIN: /DATA/IO/EDITIO.IDX (AND /DATA/IO/EDITIO.DAT) - BUTTON_GREY_BRIGHT, - BUTTON_GREY_DARK, - BUTTON_RED1_BRIGHT, - BUTTON_RED1_DARK, - BUTTON_GREEN1_BRIGHT, - BUTTON_GREEN1_DARK, - BUTTON_GREEN2_BRIGHT, - BUTTON_GREEN2_DARK, - BUTTON_RED2_BRIGHT, - BUTTON_RED2_DARK, - BUTTON_STONE_BRIGHT, - BUTTON_STONE_DARK, - BUTTON_GREY_BACKGROUND, - BUTTON_RED1_BACKGROUND, - BUTTON_GREEN1_BACKGROUND, - BUTTON_GREEN2_BACKGROUND, - BUTTON_RED2_BACKGROUND, - BUTTON_STONE_BACKGROUND, - MENUBAR_BUILDHELP, - PICTURE_SHOW_POLITICAL_EDGES, - CIRCLE_BANG, - MENUBAR_BUGKILL, - PICTURE_SMALL_ARROW_UP, - PICTURE_SMALL_ARROW_DOWN, - PICTURE_SMALL_CIRCLE, - PICTURE_TROWEL, - MENUBAR_COMPUTER, - MENUBAR_LOUPE, - PICTURE_SMALL_TICK, - PICTURE_SMALL_CROSS, - MENUBAR_MINIMAP, - PICTURE_SMALL_ARROW_LEFT, - PICTURE_SMALL_ARROW_RIGHT, - PICTURE_LETTER_I, - PICTURE_GREENLAND_TEXTURE_SNOW, - PICTURE_GREENLAND_TEXTURE_STEPPE, - PICTURE_GREENLAND_TEXTURE_SWAMP, - PICTURE_GREENLAND_TEXTURE_FLOWER, - PICTURE_GREENLAND_TEXTURE_MINING1, - PICTURE_GREENLAND_TEXTURE_MINING2, - PICTURE_GREENLAND_TEXTURE_MINING3, - PICTURE_GREENLAND_TEXTURE_MINING4, - PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1, - PICTURE_GREENLAND_TEXTURE_MEADOW1, - PICTURE_GREENLAND_TEXTURE_MEADOW2, - PICTURE_GREENLAND_TEXTURE_MEADOW3, - PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2, - PICTURE_GREENLAND_TEXTURE_MINING_MEADOW, - PICTURE_GREENLAND_TEXTURE_WATER, - PICTURE_GREENLAND_TEXTURE_LAVA, - PICTURE_GREENLAND_TEXTURE_MEADOW_MIXED, - PICTURE_WASTELAND_TEXTURE_SNOW, - PICTURE_WASTELAND_TEXTURE_STEPPE, - PICTURE_WASTELAND_TEXTURE_SWAMP, - PICTURE_WASTELAND_TEXTURE_FLOWER, - PICTURE_WASTELAND_TEXTURE_MINING1, - PICTURE_WASTELAND_TEXTURE_MINING2, - PICTURE_WASTELAND_TEXTURE_MINING3, - PICTURE_WASTELAND_TEXTURE_MINING4, - PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1, - PICTURE_WASTELAND_TEXTURE_MEADOW1, - PICTURE_WASTELAND_TEXTURE_MEADOW2, - PICTURE_WASTELAND_TEXTURE_MEADOW3, - PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2, - PICTURE_WASTELAND_TEXTURE_MINING_MEADOW, - PICTURE_WASTELAND_TEXTURE_WATER, - PICTURE_WASTELAND_TEXTURE_LAVA, - PICTURE_WINTERLAND_TEXTURE_SNOW, - PICTURE_WINTERLAND_TEXTURE_STEPPE, - PICTURE_WINTERLAND_TEXTURE_SWAMP, - PICTURE_WINTERLAND_TEXTURE_FLOWER, - PICTURE_WINTERLAND_TEXTURE_MINING1, - PICTURE_WINTERLAND_TEXTURE_MINING2, - PICTURE_WINTERLAND_TEXTURE_MINING3, - PICTURE_WINTERLAND_TEXTURE_MINING4, - PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1, - PICTURE_WINTERLAND_TEXTURE_MEADOW1, - PICTURE_WINTERLAND_TEXTURE_MEADOW2, - PICTURE_WINTERLAND_TEXTURE_MEADOW3, - PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2, - PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW, - PICTURE_WINTERLAND_TEXTURE_WATER, - PICTURE_WINTERLAND_TEXTURE_LAVA, - PICTURE_WINTERLAND_TEXTURE_MEADOW_MIXED, - PICTURE_TREE_CYPRESS, - PICTURE_TREE_PINE, - PICTURE_TREE_PALM2, - PICTURE_TREE_PINEAPPLE, - PICTURE_TREE_FIR, - PICTURE_TREE_OAK, - PICTURE_TREE_BIRCH, - PICTURE_TREE_CHERRY, - PICTURE_TREE_PALM1, - PICTURE_TREE_FLAPHAT, - PICTURE_TREE_SPIDER, - PICTURE_TREE_WOOD_MIXED, - PICTURE_TREE_PALM_MIXED, - PICTURE_SQUARE_CIRCLE1, - PICTURE_SQUARE_CIRCLE2, - PICTURE_SQUARE_CIRCLE3, - PICTURE_SQUARE_CIRCLE4, - PICTURE_RESOURCE_GOLD, - PICTURE_RESOURCE_ORE, - PICTURE_RESOURCE_COAL, - PICTURE_RESOURCE_GRANITE, - // some bobtype 14 pictures missing here - MENUBAR_TREE = 538 + 2070, - MENUBAR_RESOURCE, - MENUBAR_TEXTURE, - MENUBAR_HEIGHT, - MENUBAR_PLAYER, - MENUBAR_LANDSCAPE, - MENUBAR_ANIMAL, - MENUBAR_NEWWORLD, - PICTURE_EYE_CROSS, - MENUBAR_COMPUTER_DOUBLE_ENTRY, - // some bobtype 14 pictures missing here - PICTURE_LANDSCAPE_GRANITE = MENUBAR_COMPUTER_DOUBLE_ENTRY + 4, - PICTURE_LANDSCAPE_TREE_DEAD, - PICTURE_LANDSCAPE_STONE, - PICTURE_LANDSCAPE_CACTUS, - PICTURE_LANDSCAPE_PEBBLE, - PICTURE_LANDSCAPE_BUSH, - PICTURE_LANDSCAPE_SHRUB, - PICTURE_LANDSCAPE_BONE, - PICTURE_LANDSCAPE_MUSHROOM, - PICTURE_LANDSCAPE_STALAGMITE, - PICTURE_LANDSCAPE_GRANITE_WINTER, - PICTURE_LANDSCAPE_TREE_DEAD_WINTER, - PICTURE_LANDSCAPE_STONE_WINTER, - PICTURE_LANDSCAPE_PEBBLE_WINTER, - PICTURE_LANDSCAPE_BONE_WINTER, - PICTURE_LANDSCAPE_MUSHROOM_WINTER, - PICTURE_ANIMAL_BEAR, - PICTURE_ANIMAL_RABBIT, - PICTURE_ANIMAL_FOX, - PICTURE_ANIMAL_STAG, - PICTURE_ANIMAL_ROE, - PICTURE_ANIMAL_DUCK, - PICTURE_ANIMAL_SHEEP, - PICTURE_ANIMAL_SHEEP_DOUBLE_ENTRY, - // END: /DATA/IO/EDITIO.IDX (AND /DATA/IO/EDITIO.DAT) - - // BEGIN: /DATA/EDITBOB.LST - CURSOR_SYMBOL_SCISSORS, - CURSOR_SYMBOL_TREE, - CURSOR_SYMBOL_ARROW_UP, - CURSOR_SYMBOL_ARROW_DOWN, - CURSOR_SYMBOL_TEXTURE, - CURSOR_SYMBOL_LANDSCAPE, - CURSOR_SYMBOL_FLAG, - CURSOR_SYMBOL_PICKAXE_MINUS, - CURSOR_SYMBOL_PICKAXE_PLUS, - CURSOR_SYMBOL_ANIMAL, - FLAG_BLUE_DARK, - FLAG_YELLOW, - FLAG_RED, - FLAG_BLUE_BRIGHT, - FLAG_GREEN_DARK, - FLAG_GREEN_BRIGHT, - FLAG_ORANGE, - PICTURE_SMALL_BEAR, - PICTURE_SMALL_RABBIT, - PICTURE_SMALL_FOX, - PICTURE_SMALL_STAG, - PICTURE_SMALL_DEER, - PICTURE_SMALL_DUCK, - PICTURE_SMALL_SHEEP, -// END: /DATA/EDITBOB.LST -#else - // BEGIN: /DATA/IO/IO.IDX (AND /DATA/IO/IO.DAT) - BUTTON_GREY_BRIGHT, - BUTTON_GREY_DARK, - BUTTON_RED1_BRIGHT, - BUTTON_RED1_DARK, - BUTTON_GREEN1_BRIGHT, - BUTTON_GREEN1_DARK, - BUTTON_GREEN2_BRIGHT, - BUTTON_GREEN2_DARK, - BUTTON_RED2_BRIGHT, - BUTTON_RED2_DARK, - BUTTON_STONE_BRIGHT, - BUTTON_STONE_DARK, - BUTTON_GREY_BACKGROUND, - BUTTON_RED1_BACKGROUND, - BUTTON_GREEN1_BACKGROUND, - BUTTON_GREEN2_BACKGROUND, - BUTTON_RED2_BACKGROUND, - BUTTON_STONE_BACKGROUND, - // some bobtype 14 pictures missing here - AVATAR_OCTAVIANUS_SMALL = 688 + 2070, - AVATAR_OCTAVIANUS_SMALL_DOUBLE_ENTRY = 689 + 2070, -// END: /DATA/IO/IO.IDX (AND /DATA/IO/IO.DAT) -#endif - - // BEGIN: /GFX/TEXTURES/TEX5.LBM - TILESET_GREENLAND_8BPP, - TILESET_GREENLAND_32BPP, - // END: /GFX/TEXTURES/TEX5.LBM - - // BEGIN: /GFX/TEXTURES/TEX6.LBM - TILESET_WASTELAND_8BPP, - TILESET_WASTELAND_32BPP, - // END: /GFX/TEXTURES/TEX6.LBM - - // BEGIN: /GFX/TEXTURES/TEX7.LBM - TILESET_WINTERLAND_8BPP, - TILESET_WINTERLAND_32BPP, - // END: /GFX/TEXTURES/TEX7.LBM - - // BEGIN: /DATA/MIS*BOBS.LST * = 0,1,2,3,4,5 - MIS0BOBS_SHIP, - MIS0BOBS_TENT, - MIS1BOBS_STONE1, - MIS1BOBS_STONE2, - MIS1BOBS_STONE3, - MIS1BOBS_STONE4, - MIS1BOBS_STONE5, - MIS1BOBS_STONE6, - MIS1BOBS_STONE7, - MIS1BOBS_TREE1, - MIS1BOBS_TREE2, - MIS1BOBS_SKELETON, - MIS2BOBS_TENT, - MIS2BOBS_GUARDHOUSE, - MIS2BOBS_GUARDTOWER, - MIS2BOBS_FORTRESS, - MIS2BOBS_PUPPY, - MIS3BOBS_VIKING, - MIS4BOBS_SCROLLS, - MIS5BOBS_SKELETON1, - MIS5BOBS_SKELETON2, - MIS5BOBS_CAVE, - MIS5BOBS_VIKING, - // END: /DATA/MIS*BOBS.LST - - // BEGIN: /DATA/MAP00.LST (ONLY IF A MAP IS ACTIVE) - MAPPIC_ARROWCROSS_YELLOW, - MAPPIC_CIRCLE_YELLOW, - MAPPIC_ARROWCROSS_RED, - MAPPIC_ARROWCROSS_ORANGE, - MAPPIC_ARROWCROSS_RED_FLAG, - MAPPIC_ARROWCROSS_RED_MINE, - MAPPIC_ARROWCROSS_RED_HOUSE_SMALL, - MAPPIC_ARROWCROSS_RED_HOUSE_MIDDLE, - MAPPIC_ARROWCROSS_RED_HOUSE_BIG, - MAPPIC_ARROWCROSS_RED_HOUSE_HARBOUR, - MAPPIC_PAPER_RED_CROSS, - MAPPIC_FLAG, - MAPPIC_HOUSE_SMALL, - MAPPIC_HOUSE_MIDDLE, - MAPPIC_HOUSE_BIG, - MAPPIC_MINE, - MAPPIC_HOUSE_HARBOUR, -// some pictures missing here -#ifdef _EDITORMODE - MAPPIC_TREE_PINE = 654 + 2070, -#else - MAPPIC_TREE_PINE = 745 + 2070, -#endif - MAPPIC_TREE_BIRCH = MAPPIC_TREE_PINE + 15, - MAPPIC_TREE_OAK = MAPPIC_TREE_PINE + 30, - MAPPIC_TREE_PALM1 = MAPPIC_TREE_PINE + 45, - MAPPIC_TREE_PALM2 = MAPPIC_TREE_PINE + 60, - MAPPIC_TREE_PINEAPPLE = MAPPIC_TREE_PINE + 75, - MAPPIC_TREE_CYPRESS = MAPPIC_TREE_PINE + 83, - MAPPIC_TREE_CHERRY = MAPPIC_TREE_PINE + 98, - MAPPIC_TREE_FIR = MAPPIC_TREE_PINE + 113, - MAPPIC_MUSHROOM1 = MAPPIC_TREE_FIR + 15, - MAPPIC_MUSHROOM2, - MAPPIC_STONE1, - MAPPIC_STONE2, - MAPPIC_STONE3, - MAPPIC_TREE_TRUNK_DEAD, - MAPPIC_TREE_DEAD, - MAPPIC_BONE1, - MAPPIC_BONE2, - MAPPIC_FLOWERS, - MAPPIC_BUSH1, - MAPPIC_ROCK4, - MAPPIC_CACTUS1, - MAPPIC_CACTUS2, - MAPPIC_SHRUB1, - MAPPIC_SHRUB2, - MAPPIC_GRANITE_1_1, - MAPPIC_GRANITE_1_2, - MAPPIC_GRANITE_1_3, - MAPPIC_GRANITE_1_4, - MAPPIC_GRANITE_1_5, - MAPPIC_GRANITE_1_6, - MAPPIC_GRANITE_2_1, - MAPPIC_GRANITE_2_2, - MAPPIC_GRANITE_2_3, - MAPPIC_GRANITE_2_4, - MAPPIC_GRANITE_2_5, - MAPPIC_GRANITE_2_6, - MAPPIC_UNKNOWN_PICTURE, - MAPPIC_FIELD_1_1, - MAPPIC_FIELD_1_2, - MAPPIC_FIELD_1_3, - MAPPIC_FIELD_1_4, - MAPPIC_FIELD_1_5, - MAPPIC_FIELD_2_1, - MAPPIC_FIELD_2_2, - MAPPIC_FIELD_2_3, - MAPPIC_FIELD_2_4, - MAPPIC_FIELD_2_5, - MAPPIC_BUSH2, - MAPPIC_BUSH3, - MAPPIC_BUSH4, - MAPPIC_SHRUB3, - MAPPIC_SHRUB4, - MAPPIC_BONE3, - MAPPIC_BONE4, - MAPPIC_MUSHROOM3, - MAPPIC_STONE4, - MAPPIC_STONE5, - MAPPIC_PEBBLE1, - MAPPIC_PEBBLE2, - MAPPIC_PEBBLE3, - MAPPIC_SHRUB5, - MAPPIC_SHRUB6, - MAPPIC_SHRUB7, - MAPPIC_SNOWMAN, - MAPPIC_DOOR, -// some pictures missing here -#ifdef _EDITORMODE - MAPPIC_LAST_ENTRY = 1433 + 2070 -#else - MAPPIC_LAST_ENTRY = 1524 + 2070 -#endif - // END: /DATA/MAP00.LST -}; - -// enumeration for BobtypeSHADOW (shadows for the pics) -enum -{ - MIS0BOBS_SHIP_SHADOW = 0, - MIS0BOBS_TENT_SHADOW, - MIS1BOBS_STONE1_SHADOW, - MIS1BOBS_STONE2_SHADOW, - MIS1BOBS_STONE3_SHADOW, - MIS1BOBS_STONE4_SHADOW, - MIS1BOBS_STONE5_SHADOW, - MIS1BOBS_STONE6_SHADOW, - MIS1BOBS_STONE7_SHADOW, - MIS1BOBS_TREE1_SHADOW, - MIS1BOBS_TREE2_SHADOW, - MIS1BOBS_SKELETON_SHADOW, - MIS2BOBS_TENT_SHADOW, - MIS2BOBS_GUARDHOUSE_SHADOW, - MIS2BOBS_GUARDTOWER_SHADOW, - MIS2BOBS_FORTRESS_SHADOW, - MIS2BOBS_PUPPY_SHADOW, - MIS3BOBS_VIKING_SHADOW, - MIS4BOBS_SCROLLS_SHADOW, - MIS5BOBS_SKELETON1_SHADOW, - MIS5BOBS_SKELETON2_SHADOW, - MIS5BOBS_CAVE_SHADOW, - MIS5BOBS_VIKING_SHADOW -}; - -// enumeration for BobtypePAL (palettes for the pics) -enum -{ - PAL_RESOURCE = 0, - PAL_IO, - PAL_MAPxx, - PAL_xBBM -}; - -// Button-Colors (after all used by CButton and other Objects using CButton) -enum -{ - BUTTON_GREY = BUTTON_GREY_BRIGHT, - BUTTON_RED1 = BUTTON_RED1_BRIGHT, - BUTTON_GREEN1 = BUTTON_GREEN1_BRIGHT, - BUTTON_GREEN2 = BUTTON_GREEN2_BRIGHT, - BUTTON_RED2 = BUTTON_RED2_BRIGHT, - BUTTON_STONE = BUTTON_STONE_BRIGHT -}; - -// some necessary data for CWindow -// background color -enum -{ - WINDOW_NOTHING = -1, - WINDOW_GREEN1 = WINDOW_BACKGROUND, - WINDOW_GREEN2 = BUTTON_GREEN1_DARK, - WINDOW_GREEN3 = BUTTON_GREEN1_BRIGHT, - WINDOW_GREEN4 = BUTTON_GREEN1_BACKGROUND, - WINDOW_GREEN5 = BUTTON_GREEN2_DARK, - WINDOW_GREEN6 = BUTTON_GREEN2_BRIGHT, - WINDOW_GREEN7 = BUTTON_GREEN2_BACKGROUND, - WINDOW_GREY1 = BUTTON_GREY_DARK, - WINDOW_GREY2 = BUTTON_GREY_BRIGHT, - WINDOW_GREY3 = BUTTON_GREY_BACKGROUND, - WINDOW_RED1 = BUTTON_RED1_DARK, - WINDOW_RED2 = BUTTON_RED1_BRIGHT, - WINDOW_RED3 = BUTTON_RED1_BACKGROUND, - WINDOW_RED4 = BUTTON_RED2_DARK, - WINDOW_RED5 = BUTTON_RED2_BRIGHT, - WINDOW_RED6 = BUTTON_RED2_BACKGROUND, - WINDOW_STONE1 = BUTTON_STONE_DARK, - WINDOW_STONE2 = BUTTON_STONE_BRIGHT, - WINDOW_STONE3 = BUTTON_STONE_BACKGROUND -}; -// flags -enum -{ - WINDOW_MOVE = 1, - WINDOW_CLOSE = 2, - WINDOW_MINIMIZE = 4, - WINDOW_RESIZE = 8 -}; - -// modes for editor (what will happen if user clicks somewhere on the map in editor mode) -enum -{ - EDITOR_MODE_CUT = 0, - EDITOR_MODE_TREE, - EDITOR_MODE_HEIGHT_RAISE, - EDITOR_MODE_HEIGHT_REDUCE, - EDITOR_MODE_HEIGHT_PLANE, - EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE, - EDITOR_MODE_TEXTURE, - EDITOR_MODE_TEXTURE_MAKE_HARBOUR, - EDITOR_MODE_LANDSCAPE, - EDITOR_MODE_FLAG, - EDITOR_MODE_FLAG_DELETE, - EDITOR_MODE_RESOURCE_RAISE, - EDITOR_MODE_RESOURCE_REDUCE, - EDITOR_MODE_ANIMAL -}; - -// maximum range for the cursor in editor mode (user can increase or decrease by pressing '+' or '-') --> Must be >= 0. -#define MAX_CHANGE_SECTION 10 - -// maximum values for global arrays -// maximum pics -#define MAXBOBBMP 5000 -// maximum shadows -#define MAXBOBSHADOW 5000 -// maximum palettes -#define MAXBOBPAL 100 - -// maximum values for GUI stuff -// maximum number of menus -#define MAXMENUS 20 -// maximum number of windows -#define MAXWINDOWS 100 -// maximum number of callbacks -#define MAXCALLBACKS 100 -// maximum number of buttons that can be created WITHIN a menu or window -#define MAXBUTTONS 50 -// maximum number of texts that can be written WITHIN a menu or window -#define MAXTEXTS 100 -// maximum number of pictures that can be shown WITHIN a menu or window -#define MAXPICTURES 100 -// maximum number of textfields that can be created WITHIN a menu or window -#define MAXTEXTFIELDS 20 -// maximum number of selectboxes that can be created WITHIN a menu or window -#define MAXSELECTBOXES 20 - -// maximum players for a map -#define MAXPLAYERS 16 -// maximum map size -#define MAXMAPWIDTH 1024 -#define MAXMAPHEIGHT 1024 - -// triangle values -// these values are now handled in globals.h and globals.cpp, cause they must be changeable for the zoom mode -//#define TRIANGLE_HEIGHT 28 //30 --> old value, 28 is the right -//#define TRIANGLE_WIDTH 56 //54 --> old value, 56 is the right -//#define TRIANGLE_INCREASE 5 //depends on TRIANGLE_HEIGHT --> TRIANGLE_HEIGHT/TRIANGLE_INCREASE must be greater than 5 - -#define TRIANGLE_TEXTURE_STEPPE_MEADOW1 0x00 -#define TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR 0x40 -#define TRIANGLE_TEXTURE_MINING1 0x01 -#define TRIANGLE_TEXTURE_SNOW 0x02 -#define TRIANGLE_TEXTURE_SWAMP 0x03 -#define TRIANGLE_TEXTURE_STEPPE 0x04 -#define TRIANGLE_TEXTURE_WATER 0x05 -#define TRIANGLE_TEXTURE_WATER_ 0x06 -#define TRIANGLE_TEXTURE_STEPPE_ 0x07 -#define TRIANGLE_TEXTURE_MEADOW1 0x08 -#define TRIANGLE_TEXTURE_MEADOW1_HARBOUR 0x48 -#define TRIANGLE_TEXTURE_MEADOW2 0x09 -#define TRIANGLE_TEXTURE_MEADOW2_HARBOUR 0x49 -#define TRIANGLE_TEXTURE_MEADOW3 0x0A -#define TRIANGLE_TEXTURE_MEADOW3_HARBOUR 0x4A -#define TRIANGLE_TEXTURE_MINING2 0x0B -#define TRIANGLE_TEXTURE_MINING3 0x0C -#define TRIANGLE_TEXTURE_MINING4 0x0D -#define TRIANGLE_TEXTURE_STEPPE_MEADOW2 0x0E -#define TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR 0x4E -#define TRIANGLE_TEXTURE_FLOWER 0x0F -#define TRIANGLE_TEXTURE_FLOWER_HARBOUR 0x4F -#define TRIANGLE_TEXTURE_LAVA 0x10 -#define TRIANGLE_TEXTURE_COLOR 0x11 -#define TRIANGLE_TEXTURE_MINING_MEADOW 0x12 -#define TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR 0x52 -#define TRIANGLE_TEXTURE_WATER__ 0x13 -#define TRIANGLE_TEXTURE_STEPPE__ 0x80 -#define TRIANGLE_TEXTURE_STEPPE___ 0x84 -#define TRIANGLE_TEXTURE_MEADOW_MIXED 0xBF // this will not be written to map-files, it is only a indicator for mixed meadow in editor mode -#define TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR \ - 0xFF // this will not be written to map-files, it is only a indicator for mixed meadow in editor mode - -#endif +#ifndef _DEFINES_H +#define _DEFINES_H + +// 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 +//#define _ADMINMODE +// in editor mode there is the possibility to load, edit and save created maps +//#define _EDITORMODE + +// callback parameters +enum +{ + // NOTE: we don't have a global WINDOW_QUIT_MESSAGE, cause if there were more than one window created by a callback function + // we wouldn't know which window was closed by the user. so we need a specified quit-message for each window. + + // first call of a callback function + INITIALIZING_CALL = -1, + // a callback that is registered at the gameloop will be called from the gameloop with this value + CALL_FROM_GAMELOOP = -2, + // if user goes to main menu, all menubar callbacks will be called with MAP_QUIT + MAP_QUIT = -3, + // parameter for closing the debugger window + DEBUGGER_QUIT = -4, + // this will happen every time the user clicks anywhere on the window + WINDOW_CLICKED_CALL = -5, + // this window quit message is ONLY useable to call a callback function explicit with this value + WINDOW_QUIT_MESSAGE = -6 +}; + +// BOBTYPES +enum +{ + BOBTYPE01 = 1, + BOBTYPE02 = 2, + BOBTYPE03 = 3, + BOBTYPE04 = 4, + BOBTYPE05 = 5, + BOBTYPE07 = 7, + BOBTYPE14 = 14 +}; + +// FILE ENDINGS +enum +{ + LST = 0, + BOB, + IDX, + BBM, + LBM, + WLD, + SWD, + GOU +}; + +// Structure for Bobtypes 2 (RLE-Bitmaps), 4 (specific Bitmaps), 14 (uncompressed Bitmaps) +struct bobBMP +{ + Uint16 nx; + Uint16 ny; + Uint16 w; + Uint16 h; + SDL_Surface* surface; +}; + +// Structure for Bobtype 5 (Palette) +struct bobPAL +{ + SDL_Color colors[256]; +}; + +// Structure for Bobtype 7 (Shadow-Bitmaps) +struct bobSHADOW +{ + Uint16 nx; + Uint16 ny; + Uint16 w; + Uint16 h; + SDL_Surface* surface; +}; + +// Datatypes for the Map +// vector structure +struct vector +{ + float x, y, z; +}; +// structure for the 250 9Byte-Items from die 2250Bytes long map header +struct MapHeaderItem +{ + Uint8 type; // land or water (snow, swamp and lava are not counted) + Uint16 x; + Uint16 y; + Uint32 area; // number of vertices this area has +}; +// point structure +struct point +{ + Uint16 VertexX; /* number of the vertex on x-axis */ + Uint16 VertexY; /* number of the vertex on y-axis */ + Sint32 x; + Sint32 y; /* calculated with section 1 */ + int z; /* calculated with section 1 */ + Uint8 h; /* section 1 */ + Sint32 i; /* calculated light values for new shading by SGE (a 16 bit integer shifted left 16 times --> fixed point math for speed) */ + vector flatVector; + vector normVector; + Uint8 rsuTexture; /* section 2 */ + Uint8 usdTexture; /* section 3 */ + Uint8 road; /* section 4 */ + Uint8 objectType; /* section 5 */ + Uint8 objectInfo; /* section 6 */ + Uint8 animal; /* section 7 */ + Uint8 unknown1; /* section 8 */ + Uint8 build; /* section 9 */ + Uint8 unknown2; /* section 10 */ + Uint8 unknown3; /* section 11 */ + Uint8 resource; /* section 12 */ + Uint8 shading; /* section 13 */ + Uint8 unknown5; /* section 14 */ +}; +// structure for display, cause SDL_Rect's datatypes are too small +struct DisplayRectangle +{ + Sint32 x, y; + Sint32 w, h; +}; +struct Point16 +{ + Sint16 x, y; +}; +// map strutcture +struct bobMAP +{ + char name[20]; + Uint16 height; + Uint16 height_old; + Uint16 height_pixel; + Uint16 width; + Uint16 width_old; + Uint16 width_pixel; + Uint8 type; + Uint8 player; + // these are the original values + Uint16 HQx[7]; + Uint16 HQy[7]; + char author[20]; + // 250 items from the big map header + MapHeaderItem header[250]; + struct point* vertex; +}; +// map types +#define MAP_GREENLAND 0x00 +#define MAP_WASTELAND 0x01 +#define MAP_WINTERLAND 0x02 +// structure to save vertex coordinates +struct cursorPoint +{ + int x; + int y; + int blit_x; + int blit_y; + bool active; + bool fill_rsu; + bool fill_usd; +}; + +// IMPORTANT: for enumerating the contents of loaded files put the constants in the right order here. +// if the order of file loading changes, so change the constants in the same way! +// (these are the array-indices for an array of BobtypeBMP-Structures) + +// enumeration for BobtypePAL (palettes) +enum +{ + RESOURCE_PALETTE = 0, + IO_PALETTE +}; + +// font alignment (after all used by CFont and other objects using CFont) +enum +{ + ALIGN_LEFT = 0, + ALIGN_MIDDLE, + ALIGN_RIGHT +}; +// i put some color values here, cause we need FONT_COLOR_COUNT in the next enumeration +// font color (after all used by CFont and other objects using CFont) +enum +{ + FONT_BLUE = 0, + FONT_RED, + FONT_ORANGE, + FONT_GREEN, + FONT_MINTGREEN, + FONT_YELLOW, + FONT_RED_BRIGHT, + + FONT_COLOR_COUNT +}; +// player colors, necessary for the read_bob03- and read_bob04-function +enum +{ + PLAYER_BLUE = 0x80, + PLAYER_RED = 0x88, + PLAYER_ORANGE = 0x04, + PLAYER_GREEN = 0x85, + PLAYER_MINTGREEN = 0x94, + PLAYER_YELLOW = 0x01, + PLAYER_RED_BRIGHT = 0x10 +}; + +// enumeration for BobtypeBMP (pics) +enum +{ + // BEGIN: /GFX/PICS/SETUP997.LBM + SPLASHSCREEN_LOADING_S2SCREEN = 0, + // END: /GFX/PICS/SETUP997.LBM + + // BEGIN: /GFX/PICS/SETUP000.LBM + SPLASHSCREEN_MAINMENU_BROWN, + // END: /GFX/PICS/SETUP000.LBM + + // BEGIN: /GFX/PICS/SETUP010.LBM + SPLASHSCREEN_MAINMENU, + // END: /GFX/PICS/SETUP010.LBM + + // BEGIN: /GFX/PICS/SETUP011.LBM + SPLASHSCREEN_SUBMENU1, + // END: /GFX/PICS/SETUP011.LBM + + // BEGIN: /GFX/PICS/SETUP012.LBM + SPLASHSCREEN_SUBMENU2, + // END: /GFX/PICS/SETUP012.LBM + + // BEGIN: /GFX/PICS/SETUP013.LBM + SPLASHSCREEN_SUBMENU3, + // END: /GFX/PICS/SETUP013.LBM + + // BEGIN: /GFX/PICS/SETUP014.LBM + SPLASHSCREEN_SUBMENU4, + // END: /GFX/PICS/SETUP014.LBM + + // BEGIN: /GFX/PICS/SETUP015.LBM + SPLASHSCREEN_SUBMENU5, + // END: /GFX/PICS/SETUP015.LBM + + // BEGIN: /GFX/PICS/SETUP666.LBM + SPLASHSCREEN_UNIVERSE1, + // END: /GFX/PICS/SETUP666.LBM + + // BEGIN: /GFX/PICS/SETUP667.LBM + SPLASHSCREEN_SUN1, + // END: /GFX/PICS/SETUP667.LBM + + // BEGIN: /GFX/PICS/SETUP801.LBM + SPLASHSCREEN_SETUP801, + // END: /GFX/PICS/SETUP801.LBM + + // BEGIN: /GFX/PICS/SETUP802.LBM + SPLASHSCREEN_LOADING_STANDARD, + // END: /GFX/PICS/SETUP802.LBM + + // BEGIN: /GFX/PICS/SETUP803.LBM + SPLASHSCREEN_LOADING_GREENLAND1, + // END: /GFX/PICS/SETUP803.LBM + + // BEGIN: /GFX/PICS/SETUP804.LBM + SPLASHSCREEN_LOADING_WASTELAND, + // END: /GFX/PICS/SETUP804.LBM + + // BEGIN: /GFX/PICS/SETUP805.LBM + SPLASHSCREEN_LOADING_GREENLAND2, + // END: /GFX/PICS/SETUP805.LBM + + // BEGIN: /GFX/PICS/SETUP806.LBM + SPLASHSCREEN_LOADING_GREENLAND3, + // END: /GFX/PICS/SETUP806.LBM + + // BEGIN: /GFX/PICS/SETUP810.LBM + SPLASHSCREEN_LOADING_WINTER1, + // END: /GFX/PICS/SETUP810.LBM + + // BEGIN: /GFX/PICS/SETUP811.LBM + SPLASHSCREEN_LOADING_WINTER2, + // END: /GFX/PICS/SETUP811.LBM + + // BEGIN: /GFX/PICS/SETUP895.LBM + SPLASHSCREEN_LOADING_SETUP895, + // END: /GFX/PICS/SETUP895.LBM + + // BEGIN: /GFX/PICS/SETUP896.LBM + SPLASHSCREEN_LOADING_ROMANCAMPAIGN1, + // END: /GFX/PICS/SETUP896.LBM + + // BEGIN: /GFX/PICS/SETUP897.LBM + SPLASHSCREEN_LOADING_ROMANCAMPAIGN2, + // END: /GFX/PICS/SETUP897.LBM + + // BEGIN: /GFX/PICS/SETUP898.LBM + SPLASHSCREEN_LOADING_ROMANCAMPAIGN3, + // END: /GFX/PICS/SETUP898.LBM + + // BEGIN: /GFX/PICS/SETUP899.LBM + SPLASHSCREEN_LOADING_ROMANCAMPAIGN_GREY, + // END: /GFX/PICS/SETUP899.LBM + + // BEGIN: /GFX/PICS/SETUP990.LBM + SPLASHSCREEN_SETUP990, + // END: /GFX/PICS/SETUP990.LBM + + // BEGIN: /GFX/PICS/WORLD.LBM + SPLASHSCREEN_WORLDCAMPAIGN, + // END: /GFX/PICS/WORLD.LBM + + // BEGIN: /GFX/PICS/WORLDMSK.LBM + SPLASHSCREEN_WORLDCAMPAIGN_SECTIONS, + // END: /GFX/PICS/WORLDMSK.LBM + + // BEGIN: /DATA/RESOURCE.IDX (AND /DATA/RESOURCE.DAT) OR /DATA/EDITRES.IDX (AND /DATA/EDITRES.DAT) + // BEGIN: FONT + + /// IMPORTANT: BECAUSE OF MULTIPLE COLORS FOR EACH CHARACTER THIS FONT-ENUMERATION IS NO LONGER CONSISTENT. + /// ONLY THE START-VALUES (FONT9_SPACE, FONT11_SPACE, FONT14_SPACE) HAVE THE RIGHT INDEX! + + // fontsize 11 + FONT11_SPACE, // spacebar + FONT11_EXCLAMATION_POINT, // ! + FONT11_DOUBLE_QUOTES, // " + FONT11_SHARP, // # + FONT11_DOLLAR, // $ + FONT11_PERCENT, // % + FONT11_AMPERSAND, // & + FONT11_SINGLE_QUOTES, // ' + FONT11_ROUND_BRACKET_OPEN, // ( + FONT11_ROUND_BRACKET_CLOSE, // ) + FONT11_STAR, // * + FONT11_PLUS, // + + FONT11_COMMA, // , + FONT11_MINUS, // - + FONT11_DOT, // . + FONT11_SLASH, // / + FONT11_0, // 0 + FONT11_1, // 1 + FONT11_2, // 2 + FONT11_3, // 3 + FONT11_4, // 4 + FONT11_5, // 5 + FONT11_6, // 6 + FONT11_7, // 7 + FONT11_8, // 8 + FONT11_9, // 9 + FONT11_COLON, // : + FONT11_SEMICOLON, // ; + FONT11_ARROW_BRACKET_OPEN, // < + FONT11_EQUAL, // = + FONT11_ARROW_BRACKET_CLOSE, // > + FONT11_INTERROGATION_POINT, // ? + FONT11_AT, // @ + FONT11_A, // A + FONT11_B, // B + FONT11_C, // C + FONT11_D, // D + FONT11_E, // E + FONT11_F, // F + FONT11_G, // G + FONT11_H, // H + FONT11_I, // I + FONT11_J, // J + FONT11_K, // K + FONT11_L, // L + FONT11_M, // M + FONT11_N, // N + FONT11_O, // O + FONT11_P, // P + FONT11_Q, // Q + FONT11_R, // R + FONT11_S, // S + FONT11_T, // T + FONT11_U, // U + FONT11_V, // V + FONT11_W, // W + FONT11_X, // X + FONT11_Y, // Y + FONT11_Z, // Z + FONT11_BACKSLASH, /* \ */ + FONT11_UNDERSCORE, // _ + FONT11_a, // a + FONT11_b, // b + FONT11_c, // c + FONT11_d, // d + FONT11_e, // e + FONT11_f, // f + FONT11_g, // g + FONT11_h, // h + FONT11_i, // i + FONT11_j, // j + FONT11_k, // k + FONT11_l, // l + FONT11_m, // m + FONT11_n, // n + FONT11_o, // o + FONT11_p, // p + FONT11_q, // q + FONT11_r, // r + FONT11_s, // s + FONT11_t, // t + FONT11_u, // u + FONT11_v, // v + FONT11_w, // w + FONT11_x, // x + FONT11_y, // y + FONT11_z, // z + FONT11_ANSI_199, // Ç + FONT11_ANSI_252, // ü + FONT11_ANSI_233, // é + FONT11_ANSI_226, // â + FONT11_ANSI_228, // ä + FONT11_ANSI_224, // à + FONT11_ANSI_231, // ç + FONT11_ANSI_234, // ê + FONT11_ANSI_235, // ë + FONT11_ANSI_232, // è + FONT11_ANSI_239, // ï + FONT11_ANSI_238, // î + FONT11_ANSI_236, // ì + FONT11_ANSI_196, // Ä + FONT11_ANSI_244, // ô + FONT11_ANSI_246, // ö + FONT11_ANSI_242, // ò + FONT11_ANSI_251, // û + FONT11_ANSI_249, // ù + FONT11_ANSI_214, // Ö + FONT11_ANSI_220, // Ü + FONT11_ANSI_225, // á + FONT11_ANSI_237, // í + FONT11_ANSI_243, // ó + FONT11_ANSI_250, // ú + FONT11_ANSI_241, // ñ + FONT11_ANSI_223, // ß + FONT11_ANSI_169, // © + // fontsize 9 + FONT9_SPACE = FONT11_SPACE + FONT_COLOR_COUNT * 115, // spacebar + FONT9_EXCLAMATION_POINT, // ! + FONT9_DOUBLE_QUOTES, // " + FONT9_SHARP, // # + FONT9_DOLLAR, // $ + FONT9_PERCENT, // % + FONT9_AMPERSAND, // & + FONT9_SINGLE_QUOTES, // ' + FONT9_ROUND_BRACKET_OPEN, // ( + FONT9_ROUND_BRACKET_CLOSE, // ) + FONT9_STAR, // * + FONT9_PLUS, // + + FONT9_COMMA, // , + FONT9_MINUS, // - + FONT9_DOT, // . + FONT9_SLASH, // / + FONT9_0, // 0 + FONT9_1, // 1 + FONT9_2, // 2 + FONT9_3, // 3 + FONT9_4, // 4 + FONT9_5, // 5 + FONT9_6, // 6 + FONT9_7, // 7 + FONT9_8, // 8 + FONT9_9, // 9 + FONT9_COLON, // : + FONT9_SEMICOLON, // ; + FONT9_ARROW_BRACKET_OPEN, // < + FONT9_EQUAL, // = + FONT9_ARROW_BRACKET_CLOSE, // > + FONT9_INTERROGATION_POINT, // ? + FONT9_AT, // @ + FONT9_A, // A + FONT9_B, // B + FONT9_C, // C + FONT9_D, // D + FONT9_E, // E + FONT9_F, // F + FONT9_G, // G + FONT9_H, // H + FONT9_I, // I + FONT9_J, // J + FONT9_K, // K + FONT9_L, // L + FONT9_M, // M + FONT9_N, // N + FONT9_O, // O + FONT9_P, // P + FONT9_Q, // Q + FONT9_R, // R + FONT9_S, // S + FONT9_T, // T + FONT9_U, // U + FONT9_V, // V + FONT9_W, // W + FONT9_X, // X + FONT9_Y, // Y + FONT9_Z, // Z + FONT9_BACKSLASH, /* \ */ + FONT9_UNDERSCORE, // _ + FONT9_a, // a + FONT9_b, // b + FONT9_c, // c + FONT9_d, // d + FONT9_e, // e + FONT9_f, // f + FONT9_g, // g + FONT9_h, // h + FONT9_i, // i + FONT9_j, // j + FONT9_k, // k + FONT9_l, // l + FONT9_m, // m + FONT9_n, // n + FONT9_o, // o + FONT9_p, // p + FONT9_q, // q + FONT9_r, // r + FONT9_s, // s + FONT9_t, // t + FONT9_u, // u + FONT9_v, // v + FONT9_w, // w + FONT9_x, // x + FONT9_y, // y + FONT9_z, // z + FONT9_ANSI_199, // Ç + FONT9_ANSI_252, // ü + FONT9_ANSI_233, // é + FONT9_ANSI_226, // â + FONT9_ANSI_228, // ä + FONT9_ANSI_224, // à + FONT9_ANSI_231, // ç + FONT9_ANSI_234, // ê + FONT9_ANSI_235, // ë + FONT9_ANSI_232, // è + FONT9_ANSI_239, // ï + FONT9_ANSI_238, // î + FONT9_ANSI_236, // ì + FONT9_ANSI_196, // Ä + FONT9_ANSI_244, // ô + FONT9_ANSI_246, // ö + FONT9_ANSI_242, // ò + FONT9_ANSI_251, // û + FONT9_ANSI_249, // ù + FONT9_ANSI_214, // Ö + FONT9_ANSI_220, // Ü + FONT9_ANSI_225, // á + FONT9_ANSI_237, // í + FONT9_ANSI_243, // ó + FONT9_ANSI_250, // ú + FONT9_ANSI_241, // ñ + FONT9_ANSI_223, // ß + FONT9_ANSI_169, // © + // fontsize 14 + FONT14_SPACE = FONT9_SPACE + FONT_COLOR_COUNT * 115, // spacebar + FONT14_EXCLAMATION_POINT, // ! + FONT14_DOUBLE_QUOTES, // " + FONT14_SHARP, // # + FONT14_DOLLAR, // $ + FONT14_PERCENT, // % + FONT14_AMPERSAND, // & + FONT14_SINGLE_QUOTES, // ' + FONT14_ROUND_BRACKET_OPEN, // ( + FONT14_ROUND_BRACKET_CLOSE, // ) + FONT14_STAR, // * + FONT14_PLUS, // + + FONT14_COMMA, // , + FONT14_MINUS, // - + FONT14_DOT, // . + FONT14_SLASH, // / + FONT14_0, // 0 + FONT14_1, // 1 + FONT14_2, // 2 + FONT14_3, // 3 + FONT14_4, // 4 + FONT14_5, // 5 + FONT14_6, // 6 + FONT14_7, // 7 + FONT14_8, // 8 + FONT14_9, // 9 + FONT14_COLON, // : + FONT14_SEMICOLON, // ; + FONT14_ARROW_BRACKET_OPEN, // < + FONT14_EQUAL, // = + FONT14_ARROW_BRACKET_CLOSE, // > + FONT14_INTERROGATION_POINT, // ? + FONT14_AT, // @ + FONT14_A, // A + FONT14_B, // B + FONT14_C, // C + FONT14_D, // D + FONT14_E, // E + FONT14_F, // F + FONT14_G, // G + FONT14_H, // H + FONT14_I, // I + FONT14_J, // J + FONT14_K, // K + FONT14_L, // L + FONT14_M, // M + FONT14_N, // N + FONT14_O, // O + FONT14_P, // P + FONT14_Q, // Q + FONT14_R, // R + FONT14_S, // S + FONT14_T, // T + FONT14_U, // U + FONT14_V, // V + FONT14_W, // W + FONT14_X, // X + FONT14_Y, // Y + FONT14_Z, // Z + FONT14_BACKSLASH, /* \ */ + FONT14_UNDERSCORE, // _ + FONT14_a, // a + FONT14_b, // b + FONT14_c, // c + FONT14_d, // d + FONT14_e, // e + FONT14_f, // f + FONT14_g, // g + FONT14_h, // h + FONT14_i, // i + FONT14_j, // j + FONT14_k, // k + FONT14_l, // l + FONT14_m, // m + FONT14_n, // n + FONT14_o, // o + FONT14_p, // p + FONT14_q, // q + FONT14_r, // r + FONT14_s, // s + FONT14_t, // t + FONT14_u, // u + FONT14_v, // v + FONT14_w, // w + FONT14_x, // x + FONT14_y, // y + FONT14_z, // z + FONT14_ANSI_199, // Ç + FONT14_ANSI_252, // ü + FONT14_ANSI_233, // é + FONT14_ANSI_226, // â + FONT14_ANSI_228, // ä + FONT14_ANSI_224, // à + FONT14_ANSI_231, // ç + FONT14_ANSI_234, // ê + FONT14_ANSI_235, // ë + FONT14_ANSI_232, // è + FONT14_ANSI_239, // ï + FONT14_ANSI_238, // î + FONT14_ANSI_236, // ì + FONT14_ANSI_196, // Ä + FONT14_ANSI_244, // ô + FONT14_ANSI_246, // ö + FONT14_ANSI_242, // ò + FONT14_ANSI_251, // û + FONT14_ANSI_249, // ù + FONT14_ANSI_214, // Ö + FONT14_ANSI_220, // Ü + FONT14_ANSI_225, // á + FONT14_ANSI_237, // í + FONT14_ANSI_243, // ó + FONT14_ANSI_250, // ú + FONT14_ANSI_241, // ñ + FONT14_ANSI_223, // ß + FONT14_ANSI_169, // © + // END: FONT + + // now the main resources will follow (frames, cursor, ...) + // resolution behind means not resolution of the pic but window resolution the pic belongs to + MAINFRAME_640_480 = 2441, + SPLITFRAME_LEFT_640_480, + SPLITFRAME_RIGHT_640_480, + MAINFRAME_800_600, + SPLITFRAME_LEFT_800_600, + SPLITFRAME_RIGHT_800_600, + MAINFRAME_1024_768, + SPLITFRAME_LEFT_1024_768, + SPLITFRAME_RIGHT_1024_768, + MAINFRAME_LEFT_1280_1024, + MAINFRAME_RIGHT_1280_1024, + SPLITFRAME_LEFT_1280_1024, + SPLITFRAME_RIGHT_1280_1024, + STATUE_UP_LEFT, + STATUE_UP_RIGHT, + STATUE_DOWN_LEFT, + STATUE_DOWN_RIGHT, + SPLITFRAME_ADDITIONAL_LEFT_640_480, + SPLITFRAME_ADDITIONAL_RIGHT_640_480, + SPLITFRAME_ADDITIONAL_LEFT_800_600, + SPLITFRAME_ADDITIONAL_RIGHT_800_600, + SPLITFRAME_ADDITIONAL_LEFT_1024_768, + SPLITFRAME_ADDITIONAL_RIGHT_1024_768, + SPLITFRAME_ADDITIONAL_LEFT_1280_1024, + SPLITFRAME_ADDITIONAL_RIGHT_1280_1024, + MENUBAR, + CURSOR, + CURSOR_CLICKED, + CROSS, + MOON, + CIRCLE_HIGH_GREY, + CIRCLE_FLAT_GREY, + WINDOW_LEFT_UPPER_CORNER, + WINDOW_RIGHT_UPPER_CORNER, + WINDOW_LEFT_FRAME, + WINDOW_RIGHT_FRAME, + WINDOW_LOWER_FRAME, + WINDOW_BACKGROUND, + WINDOW_UPPER_FRAME, + WINDOW_UPPER_FRAME_MARKED, + WINDOW_UPPER_FRAME_CLICKED, + WINDOW_CORNER_RECTANGLE, + WINDOW_BUTTON_RESIZE, + WINDOW_BUTTON_CLOSE, + WINDOW_BUTTON_MINIMIZE, + WINDOW_CORNER_RECTANGLE_2, // unknown function + WINDOW_BUTTON_RESIZE_CLICKED, + WINDOW_BUTTON_CLOSE_CLICKED, + WINDOW_BUTTON_MINIMIZE_CLICKED, + WINDOW_CORNER_RECTANGLE_3, // unknown function + WINDOW_BUTTON_RESIZE_MARKED, + WINDOW_BUTTON_CLOSE_MARKED, + WINDOW_BUTTON_MINIMIZE_MARKED, + WINDOW_BUTTON_MINIMIZE_MARKED_DOUBLE_ENTRY, // double entry, picture is two times in the file +// END: /DATA/RESOURCE.IDX (AND /DATA/RESOURCE.DAT) OR /DATA/EDITRES.IDX (AND /DATA/EDITRES.DAT) + +#ifdef _EDITORMODE + // BEGIN: /DATA/IO/EDITIO.IDX (AND /DATA/IO/EDITIO.DAT) + BUTTON_GREY_BRIGHT, + BUTTON_GREY_DARK, + BUTTON_RED1_BRIGHT, + BUTTON_RED1_DARK, + BUTTON_GREEN1_BRIGHT, + BUTTON_GREEN1_DARK, + BUTTON_GREEN2_BRIGHT, + BUTTON_GREEN2_DARK, + BUTTON_RED2_BRIGHT, + BUTTON_RED2_DARK, + BUTTON_STONE_BRIGHT, + BUTTON_STONE_DARK, + BUTTON_GREY_BACKGROUND, + BUTTON_RED1_BACKGROUND, + BUTTON_GREEN1_BACKGROUND, + BUTTON_GREEN2_BACKGROUND, + BUTTON_RED2_BACKGROUND, + BUTTON_STONE_BACKGROUND, + MENUBAR_BUILDHELP, + PICTURE_SHOW_POLITICAL_EDGES, + CIRCLE_BANG, + MENUBAR_BUGKILL, + PICTURE_SMALL_ARROW_UP, + PICTURE_SMALL_ARROW_DOWN, + PICTURE_SMALL_CIRCLE, + PICTURE_TROWEL, + MENUBAR_COMPUTER, + MENUBAR_LOUPE, + PICTURE_SMALL_TICK, + PICTURE_SMALL_CROSS, + MENUBAR_MINIMAP, + PICTURE_SMALL_ARROW_LEFT, + PICTURE_SMALL_ARROW_RIGHT, + PICTURE_LETTER_I, + PICTURE_GREENLAND_TEXTURE_SNOW, + PICTURE_GREENLAND_TEXTURE_STEPPE, + PICTURE_GREENLAND_TEXTURE_SWAMP, + PICTURE_GREENLAND_TEXTURE_FLOWER, + PICTURE_GREENLAND_TEXTURE_MINING1, + PICTURE_GREENLAND_TEXTURE_MINING2, + PICTURE_GREENLAND_TEXTURE_MINING3, + PICTURE_GREENLAND_TEXTURE_MINING4, + PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW1, + PICTURE_GREENLAND_TEXTURE_MEADOW1, + PICTURE_GREENLAND_TEXTURE_MEADOW2, + PICTURE_GREENLAND_TEXTURE_MEADOW3, + PICTURE_GREENLAND_TEXTURE_STEPPE_MEADOW2, + PICTURE_GREENLAND_TEXTURE_MINING_MEADOW, + PICTURE_GREENLAND_TEXTURE_WATER, + PICTURE_GREENLAND_TEXTURE_LAVA, + PICTURE_GREENLAND_TEXTURE_MEADOW_MIXED, + PICTURE_WASTELAND_TEXTURE_SNOW, + PICTURE_WASTELAND_TEXTURE_STEPPE, + PICTURE_WASTELAND_TEXTURE_SWAMP, + PICTURE_WASTELAND_TEXTURE_FLOWER, + PICTURE_WASTELAND_TEXTURE_MINING1, + PICTURE_WASTELAND_TEXTURE_MINING2, + PICTURE_WASTELAND_TEXTURE_MINING3, + PICTURE_WASTELAND_TEXTURE_MINING4, + PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW1, + PICTURE_WASTELAND_TEXTURE_MEADOW1, + PICTURE_WASTELAND_TEXTURE_MEADOW2, + PICTURE_WASTELAND_TEXTURE_MEADOW3, + PICTURE_WASTELAND_TEXTURE_STEPPE_MEADOW2, + PICTURE_WASTELAND_TEXTURE_MINING_MEADOW, + PICTURE_WASTELAND_TEXTURE_WATER, + PICTURE_WASTELAND_TEXTURE_LAVA, + PICTURE_WINTERLAND_TEXTURE_SNOW, + PICTURE_WINTERLAND_TEXTURE_STEPPE, + PICTURE_WINTERLAND_TEXTURE_SWAMP, + PICTURE_WINTERLAND_TEXTURE_FLOWER, + PICTURE_WINTERLAND_TEXTURE_MINING1, + PICTURE_WINTERLAND_TEXTURE_MINING2, + PICTURE_WINTERLAND_TEXTURE_MINING3, + PICTURE_WINTERLAND_TEXTURE_MINING4, + PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW1, + PICTURE_WINTERLAND_TEXTURE_MEADOW1, + PICTURE_WINTERLAND_TEXTURE_MEADOW2, + PICTURE_WINTERLAND_TEXTURE_MEADOW3, + PICTURE_WINTERLAND_TEXTURE_STEPPE_MEADOW2, + PICTURE_WINTERLAND_TEXTURE_MINING_MEADOW, + PICTURE_WINTERLAND_TEXTURE_WATER, + PICTURE_WINTERLAND_TEXTURE_LAVA, + PICTURE_WINTERLAND_TEXTURE_MEADOW_MIXED, + PICTURE_TREE_CYPRESS, + PICTURE_TREE_PINE, + PICTURE_TREE_PALM2, + PICTURE_TREE_PINEAPPLE, + PICTURE_TREE_FIR, + PICTURE_TREE_OAK, + PICTURE_TREE_BIRCH, + PICTURE_TREE_CHERRY, + PICTURE_TREE_PALM1, + PICTURE_TREE_FLAPHAT, + PICTURE_TREE_SPIDER, + PICTURE_TREE_WOOD_MIXED, + PICTURE_TREE_PALM_MIXED, + PICTURE_SQUARE_CIRCLE1, + PICTURE_SQUARE_CIRCLE2, + PICTURE_SQUARE_CIRCLE3, + PICTURE_SQUARE_CIRCLE4, + PICTURE_RESOURCE_GOLD, + PICTURE_RESOURCE_ORE, + PICTURE_RESOURCE_COAL, + PICTURE_RESOURCE_GRANITE, + // some bobtype 14 pictures missing here + MENUBAR_TREE = 538 + 2070, + MENUBAR_RESOURCE, + MENUBAR_TEXTURE, + MENUBAR_HEIGHT, + MENUBAR_PLAYER, + MENUBAR_LANDSCAPE, + MENUBAR_ANIMAL, + MENUBAR_NEWWORLD, + PICTURE_EYE_CROSS, + MENUBAR_COMPUTER_DOUBLE_ENTRY, + // some bobtype 14 pictures missing here + PICTURE_LANDSCAPE_GRANITE = MENUBAR_COMPUTER_DOUBLE_ENTRY + 4, + PICTURE_LANDSCAPE_TREE_DEAD, + PICTURE_LANDSCAPE_STONE, + PICTURE_LANDSCAPE_CACTUS, + PICTURE_LANDSCAPE_PEBBLE, + PICTURE_LANDSCAPE_BUSH, + PICTURE_LANDSCAPE_SHRUB, + PICTURE_LANDSCAPE_BONE, + PICTURE_LANDSCAPE_MUSHROOM, + PICTURE_LANDSCAPE_STALAGMITE, + PICTURE_LANDSCAPE_GRANITE_WINTER, + PICTURE_LANDSCAPE_TREE_DEAD_WINTER, + PICTURE_LANDSCAPE_STONE_WINTER, + PICTURE_LANDSCAPE_PEBBLE_WINTER, + PICTURE_LANDSCAPE_BONE_WINTER, + PICTURE_LANDSCAPE_MUSHROOM_WINTER, + PICTURE_ANIMAL_BEAR, + PICTURE_ANIMAL_RABBIT, + PICTURE_ANIMAL_FOX, + PICTURE_ANIMAL_STAG, + PICTURE_ANIMAL_ROE, + PICTURE_ANIMAL_DUCK, + PICTURE_ANIMAL_SHEEP, + PICTURE_ANIMAL_SHEEP_DOUBLE_ENTRY, + // END: /DATA/IO/EDITIO.IDX (AND /DATA/IO/EDITIO.DAT) + + // BEGIN: /DATA/EDITBOB.LST + CURSOR_SYMBOL_SCISSORS, + CURSOR_SYMBOL_TREE, + CURSOR_SYMBOL_ARROW_UP, + CURSOR_SYMBOL_ARROW_DOWN, + CURSOR_SYMBOL_TEXTURE, + CURSOR_SYMBOL_LANDSCAPE, + CURSOR_SYMBOL_FLAG, + CURSOR_SYMBOL_PICKAXE_MINUS, + CURSOR_SYMBOL_PICKAXE_PLUS, + CURSOR_SYMBOL_ANIMAL, + FLAG_BLUE_DARK, + FLAG_YELLOW, + FLAG_RED, + FLAG_BLUE_BRIGHT, + FLAG_GREEN_DARK, + FLAG_GREEN_BRIGHT, + FLAG_ORANGE, + PICTURE_SMALL_BEAR, + PICTURE_SMALL_RABBIT, + PICTURE_SMALL_FOX, + PICTURE_SMALL_STAG, + PICTURE_SMALL_DEER, + PICTURE_SMALL_DUCK, + PICTURE_SMALL_SHEEP, +// END: /DATA/EDITBOB.LST +#else + // BEGIN: /DATA/IO/IO.IDX (AND /DATA/IO/IO.DAT) + BUTTON_GREY_BRIGHT, + BUTTON_GREY_DARK, + BUTTON_RED1_BRIGHT, + BUTTON_RED1_DARK, + BUTTON_GREEN1_BRIGHT, + BUTTON_GREEN1_DARK, + BUTTON_GREEN2_BRIGHT, + BUTTON_GREEN2_DARK, + BUTTON_RED2_BRIGHT, + BUTTON_RED2_DARK, + BUTTON_STONE_BRIGHT, + BUTTON_STONE_DARK, + BUTTON_GREY_BACKGROUND, + BUTTON_RED1_BACKGROUND, + BUTTON_GREEN1_BACKGROUND, + BUTTON_GREEN2_BACKGROUND, + BUTTON_RED2_BACKGROUND, + BUTTON_STONE_BACKGROUND, + // some bobtype 14 pictures missing here + AVATAR_OCTAVIANUS_SMALL = 688 + 2070, + AVATAR_OCTAVIANUS_SMALL_DOUBLE_ENTRY = 689 + 2070, +// END: /DATA/IO/IO.IDX (AND /DATA/IO/IO.DAT) +#endif + + // BEGIN: /GFX/TEXTURES/TEX5.LBM + TILESET_GREENLAND_8BPP, + TILESET_GREENLAND_32BPP, + // END: /GFX/TEXTURES/TEX5.LBM + + // BEGIN: /GFX/TEXTURES/TEX6.LBM + TILESET_WASTELAND_8BPP, + TILESET_WASTELAND_32BPP, + // END: /GFX/TEXTURES/TEX6.LBM + + // BEGIN: /GFX/TEXTURES/TEX7.LBM + TILESET_WINTERLAND_8BPP, + TILESET_WINTERLAND_32BPP, + // END: /GFX/TEXTURES/TEX7.LBM + + // BEGIN: /DATA/MIS*BOBS.LST * = 0,1,2,3,4,5 + MIS0BOBS_SHIP, + MIS0BOBS_TENT, + MIS1BOBS_STONE1, + MIS1BOBS_STONE2, + MIS1BOBS_STONE3, + MIS1BOBS_STONE4, + MIS1BOBS_STONE5, + MIS1BOBS_STONE6, + MIS1BOBS_STONE7, + MIS1BOBS_TREE1, + MIS1BOBS_TREE2, + MIS1BOBS_SKELETON, + MIS2BOBS_TENT, + MIS2BOBS_GUARDHOUSE, + MIS2BOBS_GUARDTOWER, + MIS2BOBS_FORTRESS, + MIS2BOBS_PUPPY, + MIS3BOBS_VIKING, + MIS4BOBS_SCROLLS, + MIS5BOBS_SKELETON1, + MIS5BOBS_SKELETON2, + MIS5BOBS_CAVE, + MIS5BOBS_VIKING, + // END: /DATA/MIS*BOBS.LST + + // BEGIN: /DATA/MAP00.LST (ONLY IF A MAP IS ACTIVE) + MAPPIC_ARROWCROSS_YELLOW, + MAPPIC_CIRCLE_YELLOW, + MAPPIC_ARROWCROSS_RED, + MAPPIC_ARROWCROSS_ORANGE, + MAPPIC_ARROWCROSS_RED_FLAG, + MAPPIC_ARROWCROSS_RED_MINE, + MAPPIC_ARROWCROSS_RED_HOUSE_SMALL, + MAPPIC_ARROWCROSS_RED_HOUSE_MIDDLE, + MAPPIC_ARROWCROSS_RED_HOUSE_BIG, + MAPPIC_ARROWCROSS_RED_HOUSE_HARBOUR, + MAPPIC_PAPER_RED_CROSS, + MAPPIC_FLAG, + MAPPIC_HOUSE_SMALL, + MAPPIC_HOUSE_MIDDLE, + MAPPIC_HOUSE_BIG, + MAPPIC_MINE, + MAPPIC_HOUSE_HARBOUR, +// some pictures missing here +#ifdef _EDITORMODE + MAPPIC_TREE_PINE = 654 + 2070, +#else + MAPPIC_TREE_PINE = 745 + 2070, +#endif + MAPPIC_TREE_BIRCH = MAPPIC_TREE_PINE + 15, + MAPPIC_TREE_OAK = MAPPIC_TREE_PINE + 30, + MAPPIC_TREE_PALM1 = MAPPIC_TREE_PINE + 45, + MAPPIC_TREE_PALM2 = MAPPIC_TREE_PINE + 60, + MAPPIC_TREE_PINEAPPLE = MAPPIC_TREE_PINE + 75, + MAPPIC_TREE_CYPRESS = MAPPIC_TREE_PINE + 83, + MAPPIC_TREE_CHERRY = MAPPIC_TREE_PINE + 98, + MAPPIC_TREE_FIR = MAPPIC_TREE_PINE + 113, + MAPPIC_MUSHROOM1 = MAPPIC_TREE_FIR + 15, + MAPPIC_MUSHROOM2, + MAPPIC_STONE1, + MAPPIC_STONE2, + MAPPIC_STONE3, + MAPPIC_TREE_TRUNK_DEAD, + MAPPIC_TREE_DEAD, + MAPPIC_BONE1, + MAPPIC_BONE2, + MAPPIC_FLOWERS, + MAPPIC_BUSH1, + MAPPIC_ROCK4, + MAPPIC_CACTUS1, + MAPPIC_CACTUS2, + MAPPIC_SHRUB1, + MAPPIC_SHRUB2, + MAPPIC_GRANITE_1_1, + MAPPIC_GRANITE_1_2, + MAPPIC_GRANITE_1_3, + MAPPIC_GRANITE_1_4, + MAPPIC_GRANITE_1_5, + MAPPIC_GRANITE_1_6, + MAPPIC_GRANITE_2_1, + MAPPIC_GRANITE_2_2, + MAPPIC_GRANITE_2_3, + MAPPIC_GRANITE_2_4, + MAPPIC_GRANITE_2_5, + MAPPIC_GRANITE_2_6, + MAPPIC_UNKNOWN_PICTURE, + MAPPIC_FIELD_1_1, + MAPPIC_FIELD_1_2, + MAPPIC_FIELD_1_3, + MAPPIC_FIELD_1_4, + MAPPIC_FIELD_1_5, + MAPPIC_FIELD_2_1, + MAPPIC_FIELD_2_2, + MAPPIC_FIELD_2_3, + MAPPIC_FIELD_2_4, + MAPPIC_FIELD_2_5, + MAPPIC_BUSH2, + MAPPIC_BUSH3, + MAPPIC_BUSH4, + MAPPIC_SHRUB3, + MAPPIC_SHRUB4, + MAPPIC_BONE3, + MAPPIC_BONE4, + MAPPIC_MUSHROOM3, + MAPPIC_STONE4, + MAPPIC_STONE5, + MAPPIC_PEBBLE1, + MAPPIC_PEBBLE2, + MAPPIC_PEBBLE3, + MAPPIC_SHRUB5, + MAPPIC_SHRUB6, + MAPPIC_SHRUB7, + MAPPIC_SNOWMAN, + MAPPIC_DOOR, +// some pictures missing here +#ifdef _EDITORMODE + MAPPIC_LAST_ENTRY = 1433 + 2070 +#else + MAPPIC_LAST_ENTRY = 1524 + 2070 +#endif + // END: /DATA/MAP00.LST +}; + +// enumeration for BobtypeSHADOW (shadows for the pics) +enum +{ + MIS0BOBS_SHIP_SHADOW = 0, + MIS0BOBS_TENT_SHADOW, + MIS1BOBS_STONE1_SHADOW, + MIS1BOBS_STONE2_SHADOW, + MIS1BOBS_STONE3_SHADOW, + MIS1BOBS_STONE4_SHADOW, + MIS1BOBS_STONE5_SHADOW, + MIS1BOBS_STONE6_SHADOW, + MIS1BOBS_STONE7_SHADOW, + MIS1BOBS_TREE1_SHADOW, + MIS1BOBS_TREE2_SHADOW, + MIS1BOBS_SKELETON_SHADOW, + MIS2BOBS_TENT_SHADOW, + MIS2BOBS_GUARDHOUSE_SHADOW, + MIS2BOBS_GUARDTOWER_SHADOW, + MIS2BOBS_FORTRESS_SHADOW, + MIS2BOBS_PUPPY_SHADOW, + MIS3BOBS_VIKING_SHADOW, + MIS4BOBS_SCROLLS_SHADOW, + MIS5BOBS_SKELETON1_SHADOW, + MIS5BOBS_SKELETON2_SHADOW, + MIS5BOBS_CAVE_SHADOW, + MIS5BOBS_VIKING_SHADOW +}; + +// enumeration for BobtypePAL (palettes for the pics) +enum +{ + PAL_RESOURCE = 0, + PAL_IO, + PAL_MAPxx, + PAL_xBBM +}; + +// Button-Colors (after all used by CButton and other Objects using CButton) +enum +{ + BUTTON_GREY = BUTTON_GREY_BRIGHT, + BUTTON_RED1 = BUTTON_RED1_BRIGHT, + BUTTON_GREEN1 = BUTTON_GREEN1_BRIGHT, + BUTTON_GREEN2 = BUTTON_GREEN2_BRIGHT, + BUTTON_RED2 = BUTTON_RED2_BRIGHT, + BUTTON_STONE = BUTTON_STONE_BRIGHT +}; + +// some necessary data for CWindow +// background color +enum +{ + WINDOW_NOTHING = -1, + WINDOW_GREEN1 = WINDOW_BACKGROUND, + WINDOW_GREEN2 = BUTTON_GREEN1_DARK, + WINDOW_GREEN3 = BUTTON_GREEN1_BRIGHT, + WINDOW_GREEN4 = BUTTON_GREEN1_BACKGROUND, + WINDOW_GREEN5 = BUTTON_GREEN2_DARK, + WINDOW_GREEN6 = BUTTON_GREEN2_BRIGHT, + WINDOW_GREEN7 = BUTTON_GREEN2_BACKGROUND, + WINDOW_GREY1 = BUTTON_GREY_DARK, + WINDOW_GREY2 = BUTTON_GREY_BRIGHT, + WINDOW_GREY3 = BUTTON_GREY_BACKGROUND, + WINDOW_RED1 = BUTTON_RED1_DARK, + WINDOW_RED2 = BUTTON_RED1_BRIGHT, + WINDOW_RED3 = BUTTON_RED1_BACKGROUND, + WINDOW_RED4 = BUTTON_RED2_DARK, + WINDOW_RED5 = BUTTON_RED2_BRIGHT, + WINDOW_RED6 = BUTTON_RED2_BACKGROUND, + WINDOW_STONE1 = BUTTON_STONE_DARK, + WINDOW_STONE2 = BUTTON_STONE_BRIGHT, + WINDOW_STONE3 = BUTTON_STONE_BACKGROUND +}; +// flags +enum +{ + WINDOW_MOVE = 1, + WINDOW_CLOSE = 2, + WINDOW_MINIMIZE = 4, + WINDOW_RESIZE = 8 +}; + +// modes for editor (what will happen if user clicks somewhere on the map in editor mode) +enum +{ + EDITOR_MODE_CUT = 0, + EDITOR_MODE_TREE, + EDITOR_MODE_HEIGHT_RAISE, + EDITOR_MODE_HEIGHT_REDUCE, + EDITOR_MODE_HEIGHT_PLANE, + EDITOR_MODE_HEIGHT_MAKE_BIG_HOUSE, + EDITOR_MODE_TEXTURE, + EDITOR_MODE_TEXTURE_MAKE_HARBOUR, + EDITOR_MODE_LANDSCAPE, + EDITOR_MODE_FLAG, + EDITOR_MODE_FLAG_DELETE, + EDITOR_MODE_RESOURCE_RAISE, + EDITOR_MODE_RESOURCE_REDUCE, + EDITOR_MODE_ANIMAL +}; + +// maximum range for the cursor in editor mode (user can increase or decrease by pressing '+' or '-') --> Must be >= 0. +#define MAX_CHANGE_SECTION 10 + +// maximum values for global arrays +// maximum pics +#define MAXBOBBMP 5000 +// maximum shadows +#define MAXBOBSHADOW 5000 +// maximum palettes +#define MAXBOBPAL 100 + +// maximum values for GUI stuff +// maximum number of menus +#define MAXMENUS 20 +// maximum number of windows +#define MAXWINDOWS 100 +// maximum number of callbacks +#define MAXCALLBACKS 100 +// maximum number of buttons that can be created WITHIN a menu or window +#define MAXBUTTONS 50 +// maximum number of texts that can be written WITHIN a menu or window +#define MAXTEXTS 100 +// maximum number of pictures that can be shown WITHIN a menu or window +#define MAXPICTURES 100 +// maximum number of textfields that can be created WITHIN a menu or window +#define MAXTEXTFIELDS 20 +// maximum number of selectboxes that can be created WITHIN a menu or window +#define MAXSELECTBOXES 20 + +// maximum players for a map +#define MAXPLAYERS 16 +// maximum map size +#define MAXMAPWIDTH 1024 +#define MAXMAPHEIGHT 1024 + +// triangle values +// these values are now handled in globals.h and globals.cpp, cause they must be changeable for the zoom mode +//#define TRIANGLE_HEIGHT 28 //30 --> old value, 28 is the right +//#define TRIANGLE_WIDTH 56 //54 --> old value, 56 is the right +//#define TRIANGLE_INCREASE 5 //depends on TRIANGLE_HEIGHT --> TRIANGLE_HEIGHT/TRIANGLE_INCREASE must be greater than 5 + +#define TRIANGLE_TEXTURE_STEPPE_MEADOW1 0x00 +#define TRIANGLE_TEXTURE_STEPPE_MEADOW1_HARBOUR 0x40 +#define TRIANGLE_TEXTURE_MINING1 0x01 +#define TRIANGLE_TEXTURE_SNOW 0x02 +#define TRIANGLE_TEXTURE_SWAMP 0x03 +#define TRIANGLE_TEXTURE_STEPPE 0x04 +#define TRIANGLE_TEXTURE_WATER 0x05 +#define TRIANGLE_TEXTURE_WATER_ 0x06 +#define TRIANGLE_TEXTURE_STEPPE_ 0x07 +#define TRIANGLE_TEXTURE_MEADOW1 0x08 +#define TRIANGLE_TEXTURE_MEADOW1_HARBOUR 0x48 +#define TRIANGLE_TEXTURE_MEADOW2 0x09 +#define TRIANGLE_TEXTURE_MEADOW2_HARBOUR 0x49 +#define TRIANGLE_TEXTURE_MEADOW3 0x0A +#define TRIANGLE_TEXTURE_MEADOW3_HARBOUR 0x4A +#define TRIANGLE_TEXTURE_MINING2 0x0B +#define TRIANGLE_TEXTURE_MINING3 0x0C +#define TRIANGLE_TEXTURE_MINING4 0x0D +#define TRIANGLE_TEXTURE_STEPPE_MEADOW2 0x0E +#define TRIANGLE_TEXTURE_STEPPE_MEADOW2_HARBOUR 0x4E +#define TRIANGLE_TEXTURE_FLOWER 0x0F +#define TRIANGLE_TEXTURE_FLOWER_HARBOUR 0x4F +#define TRIANGLE_TEXTURE_LAVA 0x10 +#define TRIANGLE_TEXTURE_COLOR 0x11 +#define TRIANGLE_TEXTURE_MINING_MEADOW 0x12 +#define TRIANGLE_TEXTURE_MINING_MEADOW_HARBOUR 0x52 +#define TRIANGLE_TEXTURE_WATER__ 0x13 +#define TRIANGLE_TEXTURE_STEPPE__ 0x80 +#define TRIANGLE_TEXTURE_STEPPE___ 0x84 +#define TRIANGLE_TEXTURE_MEADOW_MIXED 0xBF // this will not be written to map-files, it is only a indicator for mixed meadow in editor mode +#define TRIANGLE_TEXTURE_MEADOW_MIXED_HARBOUR \ + 0xFF // this will not be written to map-files, it is only a indicator for mixed meadow in editor mode + +#endif diff --git a/globals.cpp b/globals.cpp index 894ec20..7a89bac 100644 --- a/globals.cpp +++ b/globals.cpp @@ -1,20 +1,20 @@ -#include "globals.h" - -// array for all pictures -std::vector global::bmpArray(MAXBOBBMP); -// array for all shadows -std::vector global::shadowArray(MAXBOBSHADOW); -// array for all palettes -std::vector global::palArray(MAXBOBPAL); -// the game object -CGame* global::s2; - -std::string global::gameDataFilePath("."); -std::string global::userMapsPath("./WORLDS"); - -unsigned char TRIANGLE_HEIGHT = 28; -unsigned char TRIANGLE_WIDTH = 56; -unsigned char TRIANGLE_INCREASE = 5; - -// three-dimensional array for the GOUx.DAT-Files (3 files * 256 * 256 values) -Uint8 gouData[3][256][256]; +#include "globals.h" + +// array for all pictures +std::vector global::bmpArray(MAXBOBBMP); +// array for all shadows +std::vector global::shadowArray(MAXBOBSHADOW); +// array for all palettes +std::vector global::palArray(MAXBOBPAL); +// the game object +CGame* global::s2; + +std::string global::gameDataFilePath("."); +std::string global::userMapsPath("./WORLDS"); + +unsigned char TRIANGLE_HEIGHT = 28; +unsigned char TRIANGLE_WIDTH = 56; +unsigned char TRIANGLE_INCREASE = 5; + +// three-dimensional array for the GOUx.DAT-Files (3 files * 256 * 256 values) +Uint8 gouData[3][256][256]; diff --git a/globals.h b/globals.h index 0e0fca7..90b9a13 100644 --- a/globals.h +++ b/globals.h @@ -1,30 +1,30 @@ -#ifndef _GLOBALS_H -#define _GLOBALS_H - -#include "includes.h" -#include - -class CGame; - -namespace global { -// array for all pictures -extern std::vector bmpArray; -// array for all shadows -extern std::vector shadowArray; -// array for all palettes -extern std::vector palArray; -// the game objec -extern CGame* s2; -// Path to game data (must not be empty!) -extern std::string gameDataFilePath; -// Path where maps will be stored (must not be empty!) -extern std::string userMapsPath; -} // namespace global - -extern unsigned char TRIANGLE_HEIGHT; -extern unsigned char TRIANGLE_WIDTH; -extern unsigned char TRIANGLE_INCREASE; - -extern Uint8 gouData[3][256][256]; - -#endif +#ifndef _GLOBALS_H +#define _GLOBALS_H + +#include "includes.h" +#include + +class CGame; + +namespace global { +// array for all pictures +extern std::vector bmpArray; +// array for all shadows +extern std::vector shadowArray; +// array for all palettes +extern std::vector palArray; +// the game objec +extern CGame* s2; +// Path to game data (must not be empty!) +extern std::string gameDataFilePath; +// Path where maps will be stored (must not be empty!) +extern std::string userMapsPath; +} // namespace global + +extern unsigned char TRIANGLE_HEIGHT; +extern unsigned char TRIANGLE_WIDTH; +extern unsigned char TRIANGLE_INCREASE; + +extern Uint8 gouData[3][256][256]; + +#endif diff --git a/includes.h b/includes.h index 05071a4..a308e50 100644 --- a/includes.h +++ b/includes.h @@ -1,13 +1,13 @@ -#ifndef _INCLUDES_H -#define _INCLUDES_H - -#include - -#include -#include - -#include "SGE/sge.h" - -#include "defines.h" - -#endif +#ifndef _INCLUDES_H +#define _INCLUDES_H + +#include + +#include +#include + +#include "SGE/sge.h" + +#include "defines.h" + +#endif