split out some big functions from MapData .

This commit is contained in:
Zero Fanker 2024-06-18 00:14:48 -04:00
parent 98079e43d0
commit 6e0eb71f29
8 changed files with 689 additions and 601 deletions

View file

@ -24,13 +24,21 @@
//
//////////////////////////////////////////////////////////////////////
#include "structs.h"
#if !defined(AFX_MAP_H__9278CAC0_D4E7_11D3_B63B_444553540001__INCLUDED_)
#define AFX_MAP_H__9278CAC0_D4E7_11D3_B63B_444553540001__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <array>
#include <vector>
#include "structs.h"
#include "variables.h"
#include "macros.h"
#include "ovrlinline.h"
#include "Tube.h"
#include "IniFile.h" // Hinzugefügt von der Klassenansicht
extern TILEDATA** tiledata;
extern DWORD* tiledata_count;
@ -54,15 +62,6 @@ extern int rampset;
#if !defined(AFX_MAP_H__9278CAC0_D4E7_11D3_B63B_444553540001__INCLUDED_)
#define AFX_MAP_H__9278CAC0_D4E7_11D3_B63B_444553540001__INCLUDED_
#include "IniFile.h" // Hinzugefügt von der Klassenansicht
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <array>
#define MAPDATA_UPDATE_FROM_INI 0
#define MAPDATA_UPDATE_TO_INI 1
#define MAPDATA_UPDATE_TO_INI_ALL 2
@ -181,160 +180,13 @@ public:
void SetReserved(DWORD dwPos, BYTE val);
DWORD GetTileID(DWORD dwTileSet, int iTile);
int GetNecessarySlope(DWORD dwPos);
void CreateSlopesAt(DWORD dwPos)
{
//OutputDebugString("CreateSlopes()\n");
FIELDDATA m = *GetFielddataAt(dwPos);
if (m.wGround == 0xFFFF) m.wGround = 0;
TILEDATA& d = (*tiledata)[m.wGround];
int ns = -1;
int i, e, p = 0;
int h[3][3];
for (i = 0; i < 3; i++) {
for (e = 0; e < 3; e++) {
int pos = dwPos + (i - 1) + (e - 1) * m_IsoSize;
if (pos < 0 || pos >= m_IsoSize * m_IsoSize) {
h[i][e] = 0;
} else {
FIELDDATA m2 = *GetFielddataAt(pos);
h[i][e] = m.bHeight - m2.bHeight;
}
}
}
// check if the current tile must be heightened anyway
if (!theApp.m_Options.bDisableSlopeCorrection && d.bMorphable) {
if ((h[0][1] < 0 && h[2][1] < 0) || (h[1][0] < 0 && h[1][2] < 0)
|| (h[1][0] < 0 && h[0][2] < 0 && h[0][1] >= 0)
|| (h[1][0] < 0 && h[2][2] < 0 && h[2][1] >= 0)
|| (h[0][1] < 0 && h[2][0] < 0 && h[1][0] >= 0)
|| (h[0][1] < 0 && h[2][2] < 0 && h[1][2] >= 0)
|| (h[1][2] < 0 && h[0][0] < 0 && h[0][1] >= 0)
|| (h[1][2] < 0 && h[2][0] < 0 && h[2][1] >= 0)
|| (h[2][1] < 0 && h[0][0] < 0 && h[1][0] >= 0)
|| (h[2][1] < 0 && h[0][2] < 0 && h[1][2] >= 0)
|| (h[1][0] < 0 && h[0][1] < 0 && h[0][0] >= 0)
|| (h[0][1] < 0 && h[1][2] < 0 && h[0][2] >= 0)
|| (h[1][2] < 0 && h[2][1] < 0 && h[2][2] >= 0)
|| (h[2][1] < 0 && h[1][0] < 0 && h[2][0] >= 0)
) {
SetHeightAt(dwPos, m.bHeight + 1);
for (i = -1; i < 2; i++)
for (e = -1; e < 2; e++)
CreateSlopesAt(dwPos + i + e * m_IsoSize);
return;
}
}
BOOL checkOtherSlopes = FALSE;
if (h[0][0] == -1 && h[2][2] == -1 && h[2][0] >= 0 && h[0][2] >= 0 && h[1][0] >= 0 && h[1][2] >= 0 && h[0][1] >= 0 && h[2][1] >= 0) ns = SLOPE_UP_LEFTTOP_AND_RIGHTBOTTOM;
if (h[0][2] == -1 && h[2][0] == -1 && h[0][0] >= 0 && h[2][2] >= 0 && h[0][1] >= 0 && h[1][0] >= 0 && h[1][2] >= 0 && h[2][1] >= 0) ns = SLOPE_UP_LEFTBOTTOM_AND_RIGHTTOP;
if (ns == -1)
if (h[1][0] == -1 && h[0][1] != -1 && h[1][2] != -1 && h[2][1] != -1) {
ns = SLOPE_UP_LEFT;
} else if (h[0][1] == -1 && h[1][0] != -1 && h[2][1] != -1 && h[1][2] != -1) {
ns = SLOPE_UP_TOP;
} else if (h[1][2] == -1 && h[0][1] != -1 && h[1][0] != -1 && h[2][1] != -1) {
ns = SLOPE_UP_RIGHT;
} else if (h[2][1] == -1 && h[0][1] != -1 && h[1][0] != -1 && h[1][2] != -1) {
ns = SLOPE_UP_BOTTOM;
}
if (ns == -1) {
if (h[0][0] == -2) ns = SLOPE_DOWN_BOTTOM;
if (h[2][0] == -2) ns = SLOPE_DOWN_RIGHT;
if (h[0][2] == -2) ns = SLOPE_DOWN_LEFT;
if (h[2][2] == -2) ns = SLOPE_DOWN_TOP;
}
if (ns == -1 && h[0][0] == -1) {
if (h[1][0] == -1 && h[0][1] == -1) ns = SLOPE_DOWN_RIGHTBOTTOM;
else if (h[1][0] == 0 && h[0][1] == 0) ns = SLOPE_UP_LEFTTOP;
//else if(h[2][2]==1) ns=SLOPE_DOWN_BOTTOM;
}
if (ns == -1 && h[2][0] == -1) {
if (h[1][0] == -1 && h[2][1] == -1) ns = SLOPE_DOWN_RIGHTTOP;
else if (h[1][0] == 0 && h[2][1] == 0) ns = SLOPE_UP_LEFTBOTTOM;
//else if(h[0][2]==1) ns=SLOPE_DOWN_RIGHT;
}
if (ns == -1 && h[0][2] == -1) {
if (h[1][2] == -1 && h[0][1] == -1) ns = SLOPE_DOWN_LEFTBOTTOM;
else if (h[1][2] == 0 && h[0][1] == 0) ns = SLOPE_UP_RIGHTTOP;
//else if(h[2][0]==1) ns=SLOPE_DOWN_LEFT;
}
if (ns == -1 && h[2][2] == -1) {
if (h[1][2] == -1 && h[2][1] == -1) ns = SLOPE_DOWN_LEFTTOP;
else if (h[1][2] == 0 && h[2][1] == 0) ns = SLOPE_UP_RIGHTBOTTOM;
//else if(h[0][0]==1) ns=SLOPE_DOWN_TOP;
}
if (ns == -1 && h[1][0] == -1 && h[2][1] == -1) ns = SLOPE_DOWN_RIGHTTOP;
if (ns == -1 && h[1][2] == -1 && h[2][1] == -1) ns = SLOPE_DOWN_LEFTTOP;
if (ns == -1 && h[1][0] == -1 && h[0][1] == -1) ns = SLOPE_DOWN_RIGHTBOTTOM;
if (ns == -1 && h[1][2] == -1 && h[0][1] == -1) ns = SLOPE_DOWN_LEFTBOTTOM;
int rampbase = rampset_start;//atoi((*tiles).sections["General"].values["RampBase"]);
int rampsmooth = tiles->GetInteger("General", "RampSmooth");
if (ns == -1 && (d.wTileSet == rampset || d.wTileSet == rampsmooth) && d.bMorphable) {
SetTileAt(dwPos, 0, 0);
}
if (tiledata == &un_tiledata) {
int r = ramp2set;
int m = pave2set;
if (ns == -1 && (d.wTileSet == r || d.wTileSet == m) && d.bMorphable) {
SetTileAt(dwPos, pave2set_start/*GetTileID(m,0)*/, 0);
}
}
if (d.bMorphable && ns != -1) {
if (tiledata == &un_tiledata) // NEW URBAN FIX FOR URBAN PAVEMENT
{
//[NewUrbanInfo]
//Morphable2=114
//Ramps2=117
int r = ramp2set;
int m = pave2set;
if (d.wTileSet == r || d.wTileSet == m)
rampbase = ramp2set_start;
}
SetTileAt(dwPos, rampbase + ns - 1, 0);
}
}
void CreateSlopesAt(DWORD dwPos);
void CreateMap(DWORD dwWidth, DWORD dwHeight, LPCTSTR lpTerrainType, DWORD dwGroundHeight);
BOOL SetTileAt(DWORD dwPos, DWORD dwID, DWORD dwTile)
{
if (dwPos > fielddata_size) return FALSE;
if (dwPos > fielddata_size) {
return FALSE;
}
int replacement = 0; // MW fix: ignore for bridges
if ((*tiledata)[dwID].bReplacementCount && tiles->GetInteger("General", "BridgeSet") != (*tiledata)[dwID].wTileSet) {
@ -356,7 +208,9 @@ public:
break;
}
}
if (fielddata[dwPos].bRedrawTerrain) break;
if (fielddata[dwPos].bRedrawTerrain) {
break;
}
}
Mini_UpdatePos(dwPos % m_IsoSize, dwPos / m_IsoSize, IsMultiplayer());
@ -737,187 +591,8 @@ protected:
}
__forceinline void Mini_UpdatePos(const int i, const int e, bool isMultiplayer)
{
const int pwidth = m_mini_biinfo.bmiHeader.biWidth;
const int pheight = m_mini_biinfo.bmiHeader.biHeight;
if (m_mini_colors.empty() || !tiledata)
return;
const DWORD dwIsoSize = m_IsoSize;
const int pitch = m_mini_pitch;
int x = 0;
int y = 0;
GetMiniMapPos(i, e, x, y);
y = pheight - y - 1;
int xiso = i;
int yiso = e;
if (xiso >= m_IsoSize)
xiso = m_IsoSize - 1;
if (yiso >= m_IsoSize)
yiso = m_IsoSize - 1;
if (xiso < 0)
xiso = 0;
if (yiso < 0)
yiso = 0;
DWORD dwPos = xiso + yiso * dwIsoSize;
int dwDrawPos = (x * 3 + y * pitch);
int size = pitch * pheight;
if (dwDrawPos >= size || x >= pwidth || y >= pheight || x < 0 || y < 0) return;
if (dwPos >= m_IsoSize * m_IsoSize) return;
if (dwDrawPos + 3 >= m_mini_colors.size()) return;
RGBTRIPLE& col = (RGBTRIPLE&)m_mini_colors[dwDrawPos];
RGBTRIPLE& col_r = (RGBTRIPLE&)m_mini_colors[(dwDrawPos + sizeof(RGBTRIPLE)) < size ? dwDrawPos + sizeof(RGBTRIPLE) : dwDrawPos];
FIELDDATA td;
td = *GetFielddataAt(dwPos);
STDOBJECTDATA sod;
sod.house = "";
int ic;
for (ic = 0; ic < SUBPOS_COUNT; ic++) {
if (td.infantry[ic] >= 0) {
GetStdInfantryData(td.infantry[ic], &sod);
}
}
if (td.structure >= 0) {
GetStdStructureData(td.structure, &sod);
}
if (td.aircraft >= 0) {
GetStdAircraftData(td.aircraft, &sod);
}
if (td.unit >= 0) {
GetStdUnitData(td.unit, &sod);
}
int ground = (td.wGround >= (*tiledata_count)) ? 0 : td.wGround;
int subt = td.bSubTile;
int ttype = 0;
if (subt < (*tiledata)[ground].wTileCount) ttype = (*tiledata)[ground].tiles[subt].bTerrainType;
// mw added check:
if (subt >= (*tiledata)[ground].wTileCount) return;
RGBTRIPLE& l = (*tiledata)[ground].tiles[subt].rgbLeft;
RGBTRIPLE& r = (*tiledata)[ground].tiles[subt].rgbRight;
int pos = GetHeightAt(dwPos);
col.rgbtBlue = l.rgbtBlue;
col.rgbtGreen = l.rgbtGreen;
col.rgbtRed = l.rgbtRed;
col_r.rgbtBlue = r.rgbtBlue;
col_r.rgbtGreen = r.rgbtGreen;
col_r.rgbtRed = r.rgbtRed;
if (isGreenTiberium(td.overlay)) {
#ifndef RA2_MODE
col.rgbtBlue = 0;
col.rgbtGreen = 200;
col.rgbtRed = 0;
col_r = col;
#else
col.rgbtBlue = 0;
col.rgbtGreen = 250;
col.rgbtRed = 250;
col_r = col;
#endif
} else if (td.overlay == OVRL_VEINS) {
col.rgbtBlue = 120;
col.rgbtGreen = 180;
col.rgbtRed = 190;
col_r = col;
} else if (td.overlay == OVRL_VEINHOLE || td.overlay == OVRL_VEINHOLEBORDER) {
col.rgbtBlue = 120;
col.rgbtGreen = 160;
col.rgbtRed = 165;
col_r = col;
} else if (td.overlay != 0xFF) {
col.rgbtBlue = 20;
col.rgbtGreen = 20;
col.rgbtRed = 20;
col_r = col;
}
if (sod.house.GetLength() > 0) {
/*
if(strstr(sod.house, houses[1].name))
{
col.rgbtRed=255;
col.rgbtGreen=0;
col.rgbtBlue=0;
}
else if(strstr(sod.house,houses[0].name))
{
col.rgbtRed=180;
col.rgbtGreen=180;
col.rgbtBlue=0;
}
else
{
col.rgbtRed=200;
col.rgbtGreen=200;
col.rgbtBlue=200;
}*/
COLORREF c = ((CFinalSunDlg*)theApp.m_pMainWnd)->m_view.m_isoview->GetColor(sod.house);
col.rgbtRed = GetRValue(c);
col.rgbtBlue = GetBValue(c);
col.rgbtGreen = GetGValue(c);
col_r = col;
}
// MW: ADD: make red start pos dots
if (isMultiplayer) {
CString id;
DWORD p;
int wp = td.waypoint;
BOOL startpos = FALSE;
int i, e;
for (i = -1; i < 2; i++) {
for (e = -1; e < 2; e++) {
if (dwPos + i + e * m_IsoSize < fielddata_size) {
int w = GetWaypointAt(dwPos + i + e * m_IsoSize);
if (w >= 0) {
GetWaypointData(w, &id, &p);
if (atoi(id) < 8) {
startpos = TRUE;
break;
}
}
}
}
if (startpos) break;
}
if (startpos) {
col.rgbtBlue = 0;
col.rgbtGreen = 0;
col.rgbtRed = 255;
col_r = col;
}
}
}
void Mini_UpdatePos(const int i, const int e, bool isMultiplayer);
// helper function. Is val==iSet1 or val=iSet2?
__forceinline BOOL st(int val, int iSet)
{
@ -957,182 +632,7 @@ public:
void Redo();
void SmoothAllAt(DWORD dwPos);
__forceinline void SmoothAt(DWORD dwPos, int iSmoothSet, int iLatSet, int iTargetSet, BOOL bIgnoreShore = TRUE)
{
int i;
int its, iss, ils;
int iLatGround = tilesets_start[iLatSet];
int iSmoothGround = tilesets_start[iSmoothSet];
its = (*tiledata)[tilesets_start[iTargetSet]].tiles[0].bTerrainType;
iss = (*tiledata)[iSmoothGround].tiles[0].bTerrainType;
ils = (*tiledata)[iLatGround].tiles[0].bTerrainType;
FIELDDATA m = *GetFielddataAt(dwPos);
if (m.wGround == 0xFFFF) m.wGround = 0;
// do we have that certain LAT tile here?
if ((*tiledata)[m.wGround].wTileSet != iSmoothSet && (*tiledata)[m.wGround].wTileSet != iLatSet) return;
//if(m.wGround==iLatGround) m.wGround=iSmoothGround;
if (its == iss && (*tiledata)[m.wGround].wTileSet == iSmoothSet) m.wGround = iLatGround;
if (its == iss) ils += 1;
BOOL bOnlyLat = TRUE;
//BOOL bNoLat=TRUE;
int ns = -1;
int e, p = 0;
int ts[3][3]; // terrain info
int set = (*tiledata)[m.wGround].wTileSet;
for (i = 0; i < 3; i++) {
for (e = 0; e < 3; e++) {
int pos = dwPos + (i - 1) + (e - 1) * m_IsoSize;
if (pos < 0 || pos >= fielddata_size) {
ts[i][e] = 0;
} else {
FIELDDATA m2 = *GetFielddataAt(pos);
if (m2.wGround == 0xFFFF) m2.wGround = 0;
int cur_set = (*tiledata)[m2.wGround].wTileSet;
//if(cur_set==iSmoothSet) bNoLat=FALSE;
//
if (its == iss && cur_set == iSmoothSet) {
m2.wGround = iLatGround; cur_set = iLatSet;
}
if (cur_set == iSmoothSet || cur_set == iTargetSet) bOnlyLat = FALSE;
/*if(cur_set != iSmoothSet && cur_set!= iLatSet && cur_set!=iTargetSet)
{
ts[i][e]=(*tiledata)[m2.wGround].tiles[m2.bSubTile].bTerrainType;
if((*tiledata)[m2.wGround].wTileSet!=shoreset)
{
ts[i][e]=0;//ts[i][e]+1; // make sure you don´t smooth at it except it´s shore
}
//if(bIgnoreShore && (*tiledata)[m2.wGround].wTileSet==shoreset)
// ts[i][e]=0;//ts[i][e]+1;
}
else*/ if (its == iss && cur_set != set) {
if (cur_set == shoreset && !bIgnoreShore)
ts[i][e] = its;
else if (cur_set != iSmoothSet && cur_set != iTargetSet && cur_set != iLatSet)
ts[i][e] = 0;
else
ts[i][e] = its;
} else if (its == iss && cur_set == set)
ts[i][e] = ils;
else {
ts[i][e] = (*tiledata)[m2.wGround].tiles[m2.bSubTile].bTerrainType;
if (cur_set != shoreset && cur_set != iLatSet && cur_set != iSmoothSet) {
ts[i][e] = 0;//ts[i][e]+1; // make sure you don´t smooth at it except it´s shore
}
}
}
}
}
//if(bOnlyLat) return;
int needed = -1;
// 1/1 is smoothed tile
if (ts[1][1] == ils) {
// single lat
if (ts[0][1] != ils && ts[1][0] != ils
&& ts[1][2] != ils && ts[2][1] != ils)
needed = 16;
else if (ts[0][1] == ils && ts[1][0] == ils
&& ts[1][2] == ils && ts[2][1] == ils)
needed = 0;
else if (ts[0][1] == ils && ts[2][1] == ils &&
ts[1][0] != ils && ts[1][2] != ils)
needed = 11;
else if (ts[1][0] == ils && ts[1][2] == ils &&
ts[0][1] != ils && ts[2][1] != ils)
needed = 6;
else if (ts[1][0] != ils && ts[0][1] == ils &&
ts[2][1] == ils)
needed = 9;
else if (ts[2][1] != ils && ts[1][0] == ils &&
ts[1][2] == ils)
needed = 5;
else if (ts[1][2] != ils && ts[0][1] == ils &&
ts[2][1] == ils)
needed = 3;
else if (ts[0][1] != ils && ts[1][0] == ils &&
ts[1][2] == ils)
needed = 2;
else if (ts[0][1] == ils && ts[1][0] != ils &&
ts[1][2] != ils && ts[2][1] != ils)
needed = 15;
else if (ts[1][2] == ils && ts[1][0] != ils &&
ts[0][1] != ils && ts[2][1] != ils)
needed = 14;
else if (ts[2][1] == ils && ts[1][0] != ils &&
ts[0][1] != ils && ts[1][2] != ils)
needed = 12;
else if (ts[1][0] == ils && ts[0][1] != ils &&
ts[1][2] != ils && ts[2][1] != ils)
needed = 8;
else if (ts[1][0] != ils && ts[2][1] != ils)
needed = 13;
else if (ts[1][0] != ils && ts[0][1] != ils)
needed = 10;
else if (ts[2][1] != ils && ts[1][2] != ils)
needed = 7;
else if (ts[0][1] != ils && ts[1][2] != ils)
needed = 4;
} else if (ts[1][1] == its) {
// replace target set instead of smooth set
//if(st(ts[0][0], && ts[0][1]
}
needed -= 1;
if (needed >= 0) {
/*for(i=0;i<*tiledata_count;i++)
{
if((*tiledata)[i].wTileSet==iLatSet)
{
break;
}
}*/
i = tilesets_start[iLatSet];
// i is first lat tile
int e;
for (e = 0; e < needed; e++) {
i += (*tiledata)[i].wTileCount;
}
SetTileAt(dwPos, i, 0);
} else if (needed == -1) {
/*for(i=0;i<*tiledata_count;i++)
{
if((*tiledata)[i].wTileSet==iSmoothSet)
{
break;
}
}*/
i = tilesets_start[iSmoothSet];
// i is first lat tile
SetTileAt(dwPos, i, 0);
}
}
void SmoothAt(DWORD dwPos, int iSmoothSet, int iLatSet, int iTargetSet, BOOL bIgnoreShore = TRUE);
BOOL GetLocalSize(RECT* rect) const;
void Undo();