Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerate the map tiles in row order #3641

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ void kf_HalveHeights()
{
MAPTILE *psTile;

for (int i = 0; i < mapWidth; ++i)
for (int j = 0; j < mapHeight; ++j)
{
for (int j = 0; j < mapHeight; ++j)
for (int i = 0; i < mapWidth; ++i)
{
psTile = mapTile(i, j);
psTile->height /= 2;
Expand Down
4 changes: 2 additions & 2 deletions src/lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void initLighting(UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2)
return;
}

for (unsigned i = x1; i < x2; i++)
for (unsigned j = y1; j < y2; j++)
{
for (unsigned j = y1; j < y2; j++)
for (unsigned i = x1; i < x2; i++)
{
MAPTILE *psTile = mapTile(i, j);

Expand Down
55 changes: 29 additions & 26 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,9 @@ static bool hasDecals(int i, int j)
// Sets the ground type to be a decal or not
static bool mapSetGroundTypes()
{
int i, j;

for (i = 0; i < mapWidth; i++)
for (int j = 0; j < mapHeight; j++)
{
for (j = 0; j < mapHeight; j++)
for (int i = 0; i < mapWidth; i++)
{
MAPTILE *psTile = mapTile(i, j);

Expand Down Expand Up @@ -758,16 +756,19 @@ static bool isWaterVertex(int x, int y)
static void generateRiverbed()
{
MersenneTwister mt(12345); // 12345 = random seed.
int maxIdx = 1, idx[MAP_MAXWIDTH][MAP_MAXHEIGHT];
int i, j, l = 0;
int maxIdx = 1;
ASSERT_OR_RETURN(, mapWidth > 0 && mapHeight > 0, "Invalid map width or height (%d x %d)", mapWidth, mapHeight);
std::vector<int> idx(static_cast<size_t>(mapWidth) * static_cast<size_t>(mapHeight), 0);
int x, y, l = 0;

for (i = 0; i < mapWidth; i++)
for (y = 0; y < mapHeight; y++)
{
for (j = 0; j < mapHeight; j++)
for (x = 0; x < mapWidth; x++)
{
// initially set the seabed index to 0 for ground and 100 for water
idx[i][j] = 100 * isWaterVertex(i, j);
if (idx[i][j] > 0)
int val = 100 * isWaterVertex(x, y);
idx[x + (y * mapWidth)] = val;
if (val > 0)
{
l++;
}
Expand All @@ -782,17 +783,18 @@ static void generateRiverbed()
do
{
maxIdx = 1;
for (i = 1; i < mapWidth - 2; i++)
for (y = 1; y < mapHeight - 2; y++)
{
for (j = 1; j < mapHeight - 2; j++)
for (x = 1; x < mapWidth - 2; x++)
{

if (idx[i][j] > 0)
int rowOffset = (y * mapWidth);
auto& idxVal = idx[x + rowOffset];
if (idxVal > 0)
{
idx[i][j] = (idx[i - 1][j] + idx[i][j - 1] + idx[i][j + 1] + idx[i + 1][j]) / 4;
if (idx[i][j] > maxIdx)
idxVal = (idx[(x - 1) + rowOffset] + idx[x + ((y - 1) * mapWidth)] + idx[x + ((y + 1) * mapWidth)] + idx[(x + 1) + rowOffset]) / 4;
if (idxVal > maxIdx)
{
maxIdx = idx[i][j];
maxIdx = idxVal;
}
}
}
Expand All @@ -802,22 +804,23 @@ static void generateRiverbed()
}
while (maxIdx > 90 && l < 20);

for (i = 0; i < mapWidth; i++)
for (y = 0; y < mapHeight; y++)
{
for (j = 0; j < mapHeight; j++)
for (x = 0; x < mapWidth; x++)
{
if (idx[i][j] > maxIdx)
auto& idxVal = idx[x + (y * mapWidth)];
if (idxVal > maxIdx)
{
idx[i][j] = maxIdx;
idxVal = maxIdx;
}
if (idx[i][j] < 1)
if (idxVal < 1)
{
idx[i][j] = 1;
idxVal = 1;
}
if (isWaterVertex(i, j))
if (isWaterVertex(x, y))
{
l = (WATER_MAX_DEPTH + 1 - WATER_MIN_DEPTH) * (maxIdx - idx[i][j] - mt.u32() % (maxIdx / 6 + 1));
mapTile(i, j)->height -= WATER_MIN_DEPTH - (l / maxIdx);
l = (WATER_MAX_DEPTH + 1 - WATER_MIN_DEPTH) * (maxIdx - idxVal - mt.u32() % (maxIdx / 6 + 1));
mapTile(x, y)->height -= WATER_MIN_DEPTH - (l / maxIdx);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/qtscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,9 +1760,9 @@ std::vector<scripting_engine::LabelInfo> scripting_engine::debug_GetLabelInfo()

void clearMarks()
{
for (int x = 0; x < mapWidth; x++) // clear old marks
for (int y = 0; y < mapHeight; y++)
{
for (int y = 0; y < mapHeight; y++)
for (int x = 0; x < mapWidth; x++) // clear old marks
{
MAPTILE *psTile = mapTile(x, y);
psTile->tileInfoBits &= ~BITS_MARKED;
Expand Down
4 changes: 2 additions & 2 deletions src/visibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ void revealAll(UBYTE player)
}

//reveal all tiles
for (i = 0; i < mapWidth; i++)
for (j = 0; j < mapHeight; j++)
{
for (j = 0; j < mapHeight; j++)
for (i = 0; i < mapWidth; i++)
{
psTile = mapTile(i, j);
psTile->tileExploredBits |= alliancebits[player];
Expand Down
Loading