From 132071e39b92d69fcf5ebaec1531e4c53ddb154e Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Sat, 27 Jun 2020 14:00:13 -0700 Subject: [PATCH] Placement Dialog now places objects in proper isometric space. --- SCU01EA.INI | 40 +++++++++++---------------- code/redalert/cell.cpp | 58 +++++++++++++++++++++++++++++++++++++-- code/redalert/cell.h | 13 ++++++++- code/redalert/display.cpp | 32 ++++++++------------- code/redalert/display.h | 3 -- code/redalert/object.cpp | 2 +- 6 files changed, 96 insertions(+), 52 deletions(-) diff --git a/SCU01EA.INI b/SCU01EA.INI index 0172fd7..b78850f 100644 --- a/SCU01EA.INI +++ b/SCU01EA.INI @@ -103,7 +103,7 @@ Allies=Special [Basic] Name=In the thick of it -Intro= +Intro=AAGUN Brief= Win= Lose= @@ -145,27 +145,19 @@ Height=30 1=BwAAIIH//v8f/4AHAAAggf/+/x//gAcAACCB//7/H/+ABwAAIIH//v8f/4AHAAAggQD+/x 2=8AgAcAACCBAP7/HwCA -[TERRAIN] -7363=T01 -6853=T01 -6474=T01 -6862=T01 -7502=T01 -7884=T01 -7249=T01 -7105=T01 - [UNITS] -0=USSR,4TNK,256,7495,0,Guard,None -1=USSR,4TNK,256,7882,0,Guard,None -2=USSR,4TNK,256,7500,0,Guard,None -3=Spain,TRUK,256,7241,0,Guard,None +0=USSR,4TNK,256,8637,0,Guard,None +1=USSR,4TNK,256,7999,0,Guard,None [STRUCTURES] -0=Spain,IRON,256,7369,0,None,0,0 -1=Spain,WEAP,256,6856,0,None,0,0 -2=Spain,PDOX,256,7115,0,None,0,0 -3=Spain,IRON,256,7109,0,None,0,0 +0=USSR,FACT,256,7863,0,None,0,0 +1=USSR,PROC,256,6843,0,None,0,0 +2=USSR,APWR,256,8133,0,None,0,0 +3=USSR,STEK,256,6723,0,None,0,0 +4=USSR,APWR,256,7113,0,None,0,0 +5=USSR,BARR,256,7883,0,None,0,0 +6=USSR,BIO,256,7095,0,None,0,0 +7=USSR,KENN,256,9035,0,None,0,0 [Base] Player=USSR @@ -175,11 +167,11 @@ Count=0 1=BwAAIIH//v8f/4AHAAAggf/+/x//gA== [Briefing] -1=A pitiful excuse for resistance has blockaded itself in this village. -2=Stalin has decided to make an example of them. Kill them all and destroy -3=their homes. You will have Yak aircraft to use in teaching these rebels a -4=lesson. +1=Rescue Einstein from the Headquarters inside this Soviet complex. Once +2=found, evacuate him via the helicopter at the signal flare. Einstein and +3=Tanya must be kept alive at all costs. Beware the Soviet's Tesla Coils. +4=Direct Tanya to destroy the westmost power plants to take them off-line. [Digest] -1=Fnccg6L7HTpz6/hYgFxr9Irh0dU= +1=PiAoEnI3N561zfpmapveIIQHqFE= diff --git a/code/redalert/cell.cpp b/code/redalert/cell.cpp index 9afb537..10acd8c 100644 --- a/code/redalert/cell.cpp +++ b/code/redalert/cell.cpp @@ -999,6 +999,47 @@ bool CellClass::Get_Template_Info(char *template_name, int &icon, void *&image_d return false; } +void CellClass::ConvertCoordsToIsometric(int& x, int& y) { + int tileWidth = CELL_PIXEL_W; + int tileHeight = CELL_PIXEL_H; + int sx = (x / CELL_PIXEL_W) * (tileWidth / 2) - (y / CELL_PIXEL_W) * (tileWidth / 2); + int sy = (x / CELL_PIXEL_W) * (tileHeight / 2) + (y / CELL_PIXEL_W) * (tileHeight / 2); + + x = sx + (CELL_PIXEL_W / 2); + y = sy + (CELL_PIXEL_W / 2); + + x = x + (ScreenWidth / 2); +} + +bool CellClass::ScreenCoordsToIsoTile(int x, int y, int &tileX, int &tileY) { + x = x - (ScreenWidth / 2); + + float tempPt_x = (2 * y + x) / 2; + float tempPt_y = (2 * y - x) / 2; + + tileX = floor(tempPt_x / (CELL_PIXEL_W * 0.5f)); + tileY = floor(tempPt_y / (CELL_PIXEL_H * 0.5f)); + + if (tileX < 0 || tileY < 0 || tileX > 128 || tileY > 128) + return false; + + return true; +} + +bool CellClass::ScreenCoordsToIsoCoords(COORDINATE screenCoord, COORDINATE& isoCoord) { + int x, y; + Map.Coord_To_Pixel(screenCoord, x, y); + int tileX, tileY; + if (!CellClass::ScreenCoordsToIsoTile(x, y, tileX, tileY)) { + return false; + } + int worldTileX = tileX * CELL_PIXEL_W; + int worldTileY = tileY * CELL_PIXEL_H; + isoCoord = Map.Pixel_To_Coord(worldTileX, worldTileY); + return true; +} + + /*********************************************************************************************** * CellClass::Draw_It -- Draws the cell imagery at the location specified. * * * @@ -1022,7 +1063,7 @@ bool CellClass::Get_Template_Info(char *template_name, int &icon, void *&image_d * 04/25/1995 JLB : Smudges drawn BELOW overlays. * * 07/22/1996 JLB : Objects added to draw process. * *=============================================================================================*/ -void CellClass::Draw_It(int x, int y, bool objects) const +void CellClass::Draw_It(int x, int y, bool objects) { assert((unsigned)Cell_Number() <= MAP_CELL_TOTAL); @@ -1093,7 +1134,12 @@ void CellClass::Draw_It(int x, int y, bool objects) const */ if (ttype->Get_Image_Data()) { // jmarshall - hd image should always be valid even if loading legacy assets - LogicPage->Draw_Stamp(ttype->Get_HDImage_Data(), icon, x, y, NULL, WINDOW_TACTICAL); + int xx = x; + int yy = y; + ConvertCoordsToIsometric(xx, yy); + lastRenderX = xx; + lastRenderY = yy; + LogicPage->Draw_Stamp(ttype->Get_HDImage_Data(), icon, xx, yy, NULL, WINDOW_TACTICAL); // jmarshall end if (remap) { LogicPage->Remap(x+Map.TacPixelX, y+Map.TacPixelY, ICON_PIXEL_W, ICON_PIXEL_H, remap); @@ -1217,7 +1263,12 @@ void CellClass::Draw_It(int x, int y, bool objects) const (Cell_Y(cell) - Cell_Y(Map.ZoneCell + Map.ZoneOffset)) * tptr->Width; // jmarshall - hd image should always be valid even if loading legacy assets - LogicPage->Draw_Stamp(tptr->Get_HDImage_Data(), icon, x, y, NULL, WINDOW_TACTICAL); + int xx = x; + int yy = y; + ConvertCoordsToIsometric(xx, yy); + lastRenderX = xx; + lastRenderY = yy; + LogicPage->Draw_Stamp(tptr->Get_HDImage_Data(), icon, xx, yy, NULL, WINDOW_TACTICAL); // jmarshall end } break; @@ -1338,6 +1389,7 @@ void CellClass::Draw_It(int x, int y, bool objects) const renderedFrameObjects.push_back(object); int xx,yy; if (object->IsToDisplay && (!object->Is_Techno() || ((TechnoClass *)object)->Visual_Character() == VISUAL_NORMAL) && Map.Coord_To_Pixel(object->Render_Coord(), xx, yy)) { + ConvertCoordsToIsometric(xx, yy); if (_Calc_Partial_Window(x, y, xx, yy)) { object->Draw_It(xx, yy, WINDOW_PARTIAL); if (Debug_Map) { diff --git a/code/redalert/cell.h b/code/redalert/cell.h index 7754c04..984c2e9 100644 --- a/code/redalert/cell.h +++ b/code/redalert/cell.h @@ -276,10 +276,14 @@ class CellClass void Code_Pointers(void); void Decode_Pointers(void); + static void ConvertCoordsToIsometric(int& x, int& y); + static bool ScreenCoordsToIsoTile(int x, int y, int& tileX, int& tileY); + static bool ScreenCoordsToIsoCoords(COORDINATE screenCoord, COORDINATE& isoCoord); + /* ** Display and rendering controls. */ - void Draw_It(int x, int y, bool objects=false) const; + void Draw_It(int x, int y, bool objects=false); void Redraw_Objects(bool forced=false); void Shimmer(void); @@ -319,9 +323,16 @@ class CellClass */ void Override_Land_Type(LandType type); + + int GetLastRenderX(void) { return lastRenderX; } + int GetLastRenderY(void) { return lastRenderY; } + private: CellClass (CellClass const &) ; + int lastRenderX; + int lastRenderY; + LandType Land; // The land type of this cell. LandType OverrideLand; // The overriden land type of this cell. diff --git a/code/redalert/display.cpp b/code/redalert/display.cpp index fdce09f..e0b0d67 100644 --- a/code/redalert/display.cpp +++ b/code/redalert/display.cpp @@ -1145,11 +1145,19 @@ void DisplayClass::Remove(ObjectClass const * object, LayerType layer) *=============================================================================================*/ CELL DisplayClass::Click_Cell_Calc(int x, int y) const { + int tileX, tileY; + if (!CellClass::ScreenCoordsToIsoTile(x, y, tileX, tileY)) { + return -1; + } + + x = tileX * CELL_PIXEL_W; + y = tileY * CELL_PIXEL_H; + x -= TacPixelX; x = Pixel_To_Lepton(x); y -= TacPixelY; y = Pixel_To_Lepton(y); - + // Possibly ignore the view constraints if we aren't using the internal renderer. ST - 8/5/2019 11:56AM if (IgnoreViewConstraints || (unsigned)x < TacLeptonWidth && (unsigned)y < TacLeptonHeight) { COORDINATE tcoord = XY_Coord(Pixel_To_Lepton(Lepton_To_Pixel(Coord_X(TacticalCoord))), Pixel_To_Lepton(Lepton_To_Pixel(Coord_Y(TacticalCoord)))); @@ -2304,28 +2312,16 @@ ObjectClass * DisplayClass::Cell_Object(CELL cell, int x, int y) const ** cell coordinates. */ if (Debug_Map && PendingObjectPtr) { - PendingObjectPtr->Coord = PendingObjectPtr->Class_Of().Coord_Fixup(Cell_Coord(ZoneCell + ZoneOffset)); + COORDINATE coord = Cell_Coord(ZoneCell + ZoneOffset); + PendingObjectPtr->Coord = PendingObjectPtr->Class_Of().Coord_Fixup(coord); PendingObjectPtr->Render(true); + } #endif BEnd(BENCH_TACTICAL); } } -// jmarshall - isometric -void DisplayClass::ConvertCoordsToIsometric(int& x, int& y) { - int tileWidth = CELL_PIXEL_W; - int tileHeight = CELL_PIXEL_H; - int sx = (x / CELL_PIXEL_W) * (tileWidth / 2) - (y / CELL_PIXEL_W) * (tileWidth / 2); - int sy = (x / CELL_PIXEL_W) * (tileHeight / 2) + (y / CELL_PIXEL_W) * (tileHeight / 2); - - x = sx + (CELL_PIXEL_W / 2); - y = sy + (CELL_PIXEL_W / 2); - - x = x + (ScreenWidth / 2); -} -// jmarshall end - /*********************************************************************************************** * DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. * * * @@ -2362,8 +2358,6 @@ void DisplayClass::Redraw_Icons(void) int ypixel; if (Coord_To_Pixel(coord, xpixel, ypixel)) { - ConvertCoordsToIsometric(xpixel, ypixel); - CellClass * cellptr = &(*this)[coord]; /* @@ -2409,8 +2403,6 @@ void DisplayClass::Redraw_OIcons(void) if (Coord_To_Pixel(coord, xpixel, ypixel)) { CellClass * cellptr = &(*this)[coord]; - // ConvertCoordsToIsometric(xpixel, ypixel); - /* ** If there is a portion of the underlying icon that could be visible, ** then draw it. Also draw the cell if the shroud is off. diff --git a/code/redalert/display.h b/code/redalert/display.h index 5d0861e..7fbca54 100644 --- a/code/redalert/display.h +++ b/code/redalert/display.h @@ -222,9 +222,6 @@ class DisplayClass: public MapClass */ int TacPixelX; int TacPixelY; -// jmarshall - static void ConvertCoordsToIsometric(int& x, int& y); -// jmarshall end /* ** This is the coordinate that the tactical map should be in at next available opportunity. diff --git a/code/redalert/object.cpp b/code/redalert/object.cpp index 52df6b6..05c3589 100644 --- a/code/redalert/object.cpp +++ b/code/redalert/object.cpp @@ -1318,7 +1318,7 @@ bool ObjectClass::Render(bool forced) const const_cast(this)->IsToDisplay = false; // added const_cast ST - 5/9/2019 if (Map.Coord_To_Pixel(coord, x, y)) { - + CellClass::ConvertCoordsToIsometric(x, y); /* ** Draw the object itself */