diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 8396e1e..cdc544f 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -306,6 +306,8 @@ set(src_redalert ./redalert/idata.cpp ./redalert/infantry.cpp ./redalert/infantry.h + ./redalert/tacticalcoord.cpp + ./redalert/tacticalcoord.h ./redalert/ini.cpp ./redalert/ini.h ./redalert/inibin.cpp diff --git a/code/redalert/display.cpp b/code/redalert/display.cpp index 2c94608..12e7da5 100644 --- a/code/redalert/display.cpp +++ b/code/redalert/display.cpp @@ -583,17 +583,17 @@ void DisplayClass::Set_View_Dimensions(int x, int y, int width, int height) // Set our min/max viewport rectangle. TacViewportRect.Clear(); + int mapWidth = MapCellWidth * CELL_PIXEL_W; + int mapHeight = MapCellHeight * CELL_PIXEL_H; TacViewportRect.AddPoint(0, 0); // Top Corner - TacViewportRect.AddPoint(TacLeptonWidth, TacLeptonHeight); - TacViewportRect.AddPoint(-TacLeptonWidth, TacLeptonHeight); - TacViewportRect.AddPoint(0, TacLeptonHeight); + TacViewportRect.AddPoint(mapWidth, mapHeight / 2); + TacViewportRect.AddPoint(-mapWidth, mapHeight / 2); + TacViewportRect.AddPoint(0, mapHeight); { - int iso_x_offset = (ScreenWidth / 2); - int iso_y_offset = (ScreenWidth / 4); - TacViewportRect.X -= Pixel_To_Lepton(iso_x_offset); - TacViewportRect.Y -= Pixel_To_Lepton(iso_y_offset); - TacViewportRect.X2 -= Pixel_To_Lepton(iso_x_offset); - TacViewportRect.Y2 -= Pixel_To_Lepton(iso_y_offset); + TacViewportRect.X += (MapCellX * CELL_PIXEL_W); + TacViewportRect.Y += (MapCellY * CELL_PIXEL_H); + TacViewportRect.X2 += (MapCellX * CELL_PIXEL_W); + TacViewportRect.Y2 += (MapCellY * CELL_PIXEL_H); } /* @@ -1240,13 +1240,21 @@ bool DisplayClass::Scroll_Map(DirType facing, int & distance, bool really) int neighborCellX = weights[crude].x * (distance * 0.4f); int neighbotCellY = weights[crude].y * (distance * 0.4f); - int tacx, tacy; - Map.Coord_To_Pixel(TacticalCoord, tacx, tacy); - COORDINATE coord = Map.Pixel_To_Coord(neighborCellX + tacx, neighbotCellY + tacx); - if (!TacViewportRect.ContainsPoint(Coord_X(coord), Coord_Y(coord))) { + DisplayTacticalCoord newCoord = TacticalCoord; + newCoord.x += Pixel_To_Lepton(neighborCellX); + newCoord.y += Pixel_To_Lepton(neighbotCellY); + + int sx = Lepton_To_Pixel(newCoord.x); + int sy = Lepton_To_Pixel(newCoord.y); + CellClass::ConvertCoordsToIsometric(sx, sy); + sy += (ScreenWidth / 4); + sy += ScreenHeight / 2; + if (!TacViewportRect.ContainsPoint(sx, sy)) { return false; } + COORDINATE coord = newCoord; + /* ** Clip the new coordinate to the edges of the game world. diff --git a/code/redalert/display.h b/code/redalert/display.h index 01d17c7..11c3650 100644 --- a/code/redalert/display.h +++ b/code/redalert/display.h @@ -37,6 +37,7 @@ #include "map.h" #include "layer.h" +#include "tacticalcoord.h" struct Image_t; @@ -60,17 +61,13 @@ struct Image_t; extern COORDINATE Coord_Add(COORDINATE coord1, COORDINATE coord2); + class DisplayClass: public MapClass { public: friend class DLLExportClass; // ST - 5/13/2019 - /* - ** The tactical map display position is indicated by the cell of the - ** upper left hand corner. These should not be altered directly. Use - ** the Set_Tactical_Position function instead. - */ - COORDINATE TacticalCoord; + DisplayTacticalCoord TacticalCoord; /* ** The dimensions (in cells) of the visible window onto the game map. This tactical @@ -228,7 +225,7 @@ class DisplayClass: public MapClass /* ** This is the coordinate that the tactical map should be in at next available opportunity. */ - COORDINATE DesiredTacticalCoord; + DisplayTacticalCoord DesiredTacticalCoord; /* ** If something in the tactical map is to be redrawn, this flag is set to true. diff --git a/code/redalert/mapeddlg.cpp b/code/redalert/mapeddlg.cpp index 050a12c..62b0511 100644 --- a/code/redalert/mapeddlg.cpp +++ b/code/redalert/mapeddlg.cpp @@ -175,11 +175,12 @@ int MapEditClass::New_Scenario(void) ** Set the Home & Reinforcement Cells to the center of the map */ Scen.Waypoint[WAYPT_REINF] = XY_Cell(MapCellX + MapCellWidth / 2, MapCellY + MapCellHeight / 2); - Scen.Waypoint[WAYPT_HOME] = XY_Cell(MapCellX + MapCellWidth / 2, MapCellY + MapCellHeight / 2); + Scen.Waypoint[WAYPT_HOME] = XY_Cell(MapCellX, MapCellY); + TacticalCoord = Cell_Coord(Scen.Waypoint[WAYPT_HOME]); (*this)[TacticalCoord].IsWaypoint = 1; Flag_Cell(Coord_Cell(TacticalCoord)); - Set_Tactical_Position(Cell_Coord(Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR) - (5 * RESFACTOR))); + Set_Tactical_Position(Cell_Coord(Scen.Waypoint[WAYPT_HOME])); ScenarioInit--; return(0); @@ -1177,6 +1178,8 @@ int MapEditClass::Size_Map(int x, int y, int w, int h) Scen.Waypoint[WAYPT_HOME] = XY_Cell(Cell_X(Scen.Waypoint[WAYPT_HOME]), MapCellY + MapCellHeight - 1); } + Set_View_Dimensions(0, 0); + return(0); } diff --git a/code/redalert/scroll.cpp b/code/redalert/scroll.cpp index 00f346e..039c21d 100644 --- a/code/redalert/scroll.cpp +++ b/code/redalert/scroll.cpp @@ -118,7 +118,7 @@ void ScrollClass::AI(KeyNumType &input, int x, int y) /* ** Verify that the mouse is over a scroll region. */ - if (Inertia || at_screen_edge) { + if (at_screen_edge) { if (at_screen_edge) { player_scrolled = true; diff --git a/code/redalert/tacticalcoord.cpp b/code/redalert/tacticalcoord.cpp new file mode 100644 index 0000000..7bae6c6 --- /dev/null +++ b/code/redalert/tacticalcoord.cpp @@ -0,0 +1,26 @@ +// tacticalcoord.cpp +// + +#include "function.h" + +DisplayTacticalCoord::DisplayTacticalCoord() { + x = 0; + y = 0; +} + +DisplayTacticalCoord::DisplayTacticalCoord(COORDINATE coord) +{ + SetFromCoordinate(coord); +} + +COORDINATE DisplayTacticalCoord::GetCoordinate() const +{ + return XY_Coord(x, y); +} + +void DisplayTacticalCoord::SetFromCoordinate(COORDINATE coord) +{ + //Map.Coord_To_Pixel(coord, x, y); + x = Coord_X(coord); + y = Coord_Y(coord); +} \ No newline at end of file diff --git a/code/redalert/tacticalcoord.h b/code/redalert/tacticalcoord.h new file mode 100644 index 0000000..ead50ca --- /dev/null +++ b/code/redalert/tacticalcoord.h @@ -0,0 +1,15 @@ +// tacticalcoord.h +// + +struct DisplayTacticalCoord { + DisplayTacticalCoord(); + DisplayTacticalCoord(COORDINATE coord); + + operator DisplayTacticalCoord::COORDINATE() const { return GetCoordinate(); } + COORDINATE GetCoordinate() const; + + void SetFromCoordinate(COORDINATE coord); + + int x; + int y; +}; \ No newline at end of file