Switched TacticalCoordinate to new DisplayTacticalCoord struct that manages XY to Coord and vice versa conversion. Temp disabled scroll inertia.

This commit is contained in:
Justin Marshall
2020-07-19 10:39:36 -07:00
parent 8a2bf274c9
commit 0ceb87a4d4
7 changed files with 74 additions and 23 deletions
+2
View File
@@ -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
+21 -13
View File
@@ -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.
+4 -7
View File
@@ -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.
+5 -2
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+26
View File
@@ -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);
}
+15
View File
@@ -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;
};