Fixed Bugs: #636552 and #647169, Forest and Rock Bugs

This commit is contained in:
mr-russ 2002-12-21 06:20:07 +00:00
parent 6b28b9bc2c
commit 47d7225623
5 changed files with 299 additions and 130 deletions

View file

@ -173,11 +173,15 @@
** Contains the tile numbers of a growing tree from small to big.
** @note Not yet used.
**
** Tilset::WoodTable[16]
** Tilset::WoodTable[20]
**
** Table for wood removable. This table contains the tile which
** is placed after a tree removement, depending on the surrounding.
**
** Tileset::MixedLookupTable[MaxTilesInTileset]
** Table for finding what part of the tile contains wood/rock,
** and which part is grass or bare ground.
**
** Tileset::ExtraRocks[6]
**
** This are six extra tile numbers, which are needed if rocks are
@ -282,8 +286,9 @@ typedef struct _tileset_ {
unsigned BotOneTree; /// Tile for one tree bottom
int RemovedTree; /// Tile placed where trees are gone
unsigned GrowingTree[2]; /// Growing tree tiles
int WoodTable[16]; /// Table for tree removable
int WoodTable[20]; /// Table for tree removable
int MixedLookupTable[MaxTilesInTileset];
/// Lookup for what part of tile used
unsigned ExtraRocks[6]; /// Extra rock tiles for removing
unsigned TopOneRock; /// Tile for one rock top
unsigned MidOneRock; /// Tile for one rock middle

View file

@ -543,10 +543,6 @@ global void PreprocessMap(void)
// it is required for fixing the wood that all tiles are marked as seen!
for (ix = 0; ix < TheMap.Width; ix++) {
for (iy = 0; iy < TheMap.Height; iy++) {
MapFixWoodTile(ix, iy);
MapFixSeenWoodTile(ix, iy);
MapFixRockTile(ix, iy);
MapFixSeenRockTile(ix, iy);
MapFixWallTile(ix, iy);
MapFixSeenWallTile(ix, iy);
}

View file

@ -76,50 +76,58 @@ global int MapIsSeenTileRock(int x, int y)
global void MapFixSeenRockTile(int x, int y)
{
int tile;
int ttup;
int ttdown;
int ttleft;
int ttright;
MapField *mf;
// Outside of map or no rock.
// Outside of map or no wood.
if (x < 0 || y < 0 || x >= TheMap.Width || y >= TheMap.Height) {
return;
}
if (!MapIsSeenTileRock(x,y)) {
return;
}
//
// Calculate the correct tile. Depends on the surrounding.
// Find out what each tile has with respect to wood, or grass.
//
tile = 0;
if ((y - 1) < 0 || MapIsSeenTileRock(x,y-1)) {
tile |= 1 << 0;
}
if ((x + 1) >= TheMap.Width || MapIsSeenTileRock(x+1,y)) {
tile |= 1 << 1;
}
if ((y + 1) >= TheMap.Height || MapIsSeenTileRock(x,y+1)) {
tile |= 1 << 2;
}
if ((x - 1) < 0 || MapIsSeenTileRock(x-1,y)) {
tile |= 1 << 3;
}
if( tile==15 ) { // Filter more corners.
if ((y - 1) > 0 && (x + 1) < TheMap.Width
&& !MapIsSeenTileRock(x+1,y-1)) {
tile += 1;
} else if ((y + 1) < TheMap.Height && (x + 1) < TheMap.Width
&& !MapIsSeenTileRock(x+1,y+1)) {
tile += 2;
} else if ((y + 1) < TheMap.Height && (x - 1) > 0
&& !MapIsSeenTileRock(x-1,y+1)) {
tile += 3;
} else if ((y - 1) > 0 && (x - 1) > 0
&& !MapIsSeenTileRock(x-1,y-1)) {
tile += 4;
} else {
return;
}
}
ttup = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y - 1) * TheMap.Width].SeenTile];
ttright = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + 1 + y * TheMap.Width].SeenTile];
ttdown = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y + 1) * TheMap.Width].SeenTile];
ttleft = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x -1 + y * TheMap.Width].SeenTile];
//
// Check each of the corners to ensure it has both connecting
// ?**?
// *mm*
// *mm*
// ?**?
// *
// * type asterixs must match for wood to be present
tile += ((ttup & 0x01) && (ttleft & 0x04)) * 8;
tile += ((ttup & 0x02) && (ttright & 0x08)) * 4;
tile += ((ttright & 0x01) && (ttdown & 0x04)) * 2;
tile += ((ttleft & 0x02) && (ttdown & 0x08)) * 1;
tile = TheMap.Tileset->RockTable[tile];
//If tile is -1, then we should check if we are to draw just one tree
//Check for tile about, or below or both...
if (tile == -1) {
tile = 16;
tile += ((ttup & 0x01) || (ttup & 0x02)) * 1;
tile += ((ttdown & 0x04) || (ttdown & 0x08)) * 2;
tile = TheMap.Tileset->RockTable[tile];
}
mf = TheMap.Fields + x + y * TheMap.Width;
if (tile == -1) { // No valid rock remove it.
@ -166,37 +174,58 @@ global void MapFixSeenRockNeighbors(int x, int y)
global void MapFixRockTile(int x, int y)
{
int tile;
int ttup;
int ttdown;
int ttleft;
int ttright;
MapField *mf;
// Outside of map or no rock.
// Outside of map or no wood.
if (x < 0 || y < 0 || x >= TheMap.Width || y >= TheMap.Height) {
return;
}
mf = TheMap.Fields + x + y * TheMap.Width;
if (!(mf->Flags & MapFieldRocks)) {
if (!(mf->Flags & MapFieldForest)) {
return;
}
//
// Calculate the correct tile. Depends on the surrounding.
// Find out what each tile has with respect to wood, or grass.
//
tile = 0;
if ((y - 1) < 0 || (TheMap.Fields[x + (y - 1) * TheMap.Width].
Flags & MapFieldRocks)) {
tile |= 1 << 0;
}
if ((x + 1) >= TheMap.Width || (TheMap.Fields[x + 1 + y * TheMap.Width].
Flags & MapFieldRocks)) {
tile |= 1 << 1;
}
if ((y + 1) >= TheMap.Height || (TheMap.Fields[x + (y + 1) * TheMap.Width].
Flags & MapFieldRocks)) {
tile |= 1 << 2;
}
if ((x - 1) < 0 || (TheMap.Fields[x - 1 + y * TheMap.Width].
Flags & MapFieldRocks)) {
tile |= 1 << 3;
}
ttup = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y - 1) * TheMap.Width].Tile];
ttright = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + 1 + y * TheMap.Width].Tile];
ttdown = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y + 1) * TheMap.Width].Tile];
ttleft = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x -1 + y * TheMap.Width].Tile];
//
// Check each of the corners to ensure it has both connecting
// ?**?
// *mm*
// *mm*
// ?**?
// *
// * type asterixs must match for wood to be present
tile += ((ttup & 0x01) && (ttleft & 0x04)) * 8;
tile += ((ttup & 0x02) && (ttright & 0x08)) * 4;
tile += ((ttright & 0x01) && (ttdown & 0x04)) * 2;
tile += ((ttleft & 0x02) && (ttdown & 0x08)) * 1;
tile = TheMap.Tileset->RockTable[tile];
//If tile is -1, then we should check if we are to draw just one tree
//Check for tile about, or below or both...
if (tile == -1) {
tile = 16;
tile += ((ttup & 0x01) || (ttup & 0x02)) * 1;
tile += ((ttdown & 0x04) || (ttdown & 0x08)) * 2;
tile = TheMap.Tileset->RockTable[tile];
}
if (tile == -1) { // No valid rock remove it.
MapRemoveRock(x, y);
@ -260,5 +289,3 @@ global void MapRemoveRock(unsigned x, unsigned y)
MustRedraw |= RedrawMinimap;
}
}
//@}

View file

@ -77,37 +77,60 @@ global int MapIsSeenTileWood(int x, int y)
global void MapFixSeenWoodTile(int x, int y)
{
int tile;
int ttup;
int ttdown;
int ttleft;
int ttright;
MapField *mf;
// Outside of map or no wood.
if (x < 0 || y < 0 || x >= TheMap.Width || y >= TheMap.Height) {
return;
}
if (!MapIsSeenTileWood(x,y)) {
return;
}
//
// Calculate the correct tile. Depends on the surrounding.
// Find out what each tile has with respect to wood, or grass.
//
tile = 0;
if ((y - 1) < 0 || MapIsSeenTileWood(x,y-1)) {
tile |= 1 << 0;
}
if ((x + 1) >= TheMap.Width || MapIsSeenTileWood(x+1,y)) {
tile |= 1 << 1;
}
if ((y + 1) >= TheMap.Height || MapIsSeenTileWood(x,y+1)) {
tile |= 1 << 2;
}
if ((x - 1) < 0 || MapIsSeenTileWood(x-1,y)) {
tile |= 1 << 3;
}
if( tile==15 ) {
return;
}
tile = TheMap.Tileset->WoodTable[tile];
ttup = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y - 1) * TheMap.Width].SeenTile];
ttright = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + 1 + y * TheMap.Width].SeenTile];
ttdown = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y + 1) * TheMap.Width].SeenTile];
ttleft = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x -1 + y * TheMap.Width].SeenTile];
//
// Check each of the corners to ensure it has both connecting
// ?**?
// *mm*
// *mm*
// ?**?
// *
// * type asterixs must match for wood to be present
tile += ((ttup & 0x01) && (ttleft & 0x04)) * 8;
tile += ((ttup & 0x02) && (ttright & 0x08)) * 4;
tile += ((ttright & 0x01) && (ttdown & 0x04)) * 2;
tile += ((ttleft & 0x02) && (ttdown & 0x08)) * 1;
tile = TheMap.Tileset->WoodTable[tile];
//If tile is -1, then we should check if we are to draw just one tree
//Check for tile about, or below or both...
if (tile == -1) {
tile = 16;
tile += ((ttup & 0x01) || (ttup & 0x02)) * 1;
tile += ((ttdown & 0x04) || (ttdown & 0x08)) * 2;
tile = TheMap.Tileset->WoodTable[tile];
}
//Update seen tile.
mf = TheMap.Fields + x + y * TheMap.Width;
if (tile == -1) { // No valid wood remove it.
mf->SeenTile = TheMap.Tileset->RemovedTree;
@ -153,7 +176,12 @@ global void MapFixSeenWoodNeighbors(int x, int y)
global void MapFixWoodTile(int x, int y)
{
int tile;
int ttup;
int ttdown;
int ttleft;
int ttright;
MapField *mf;
// Outside of map or no wood.
if (x < 0 || y < 0 || x >= TheMap.Width || y >= TheMap.Height) {
@ -164,26 +192,42 @@ global void MapFixWoodTile(int x, int y)
return;
}
//
// Calculate the correct tile. Depends on the surrounding.
// Find out what each tile has with respect to wood, or grass.
//
tile = 0;
if ((y - 1) < 0 || (TheMap.Fields[x + (y - 1) * TheMap.Width].
Flags & MapFieldForest)) {
tile |= 1 << 0;
}
if ((x + 1) >= TheMap.Width || (TheMap.Fields[x + 1 + y * TheMap.Width].
Flags & MapFieldForest)) {
tile |= 1 << 1;
}
if ((y + 1) >= TheMap.Height || (TheMap.Fields[x + (y + 1) * TheMap.Width].
Flags & MapFieldForest)) {
tile |= 1 << 2;
}
if ((x - 1) < 0 || (TheMap.Fields[x - 1 + y * TheMap.Width].
Flags & MapFieldForest)) {
tile |= 1 << 3;
}
ttup = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y - 1) * TheMap.Width].Tile];
ttright = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + 1 + y * TheMap.Width].Tile];
ttdown = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x + (y + 1) * TheMap.Width].Tile];
ttleft = TheMap.Tileset->MixedLookupTable[
TheMap.Fields[x -1 + y * TheMap.Width].Tile];
//
// Check each of the corners to ensure it has both connecting
// ?**?
// *mm*
// *mm*
// ?**?
// *
// * type asterixs must match for wood to be present
tile += ((ttup & 0x01) && (ttleft & 0x04)) * 8;
tile += ((ttup & 0x02) && (ttright & 0x08)) * 4;
tile += ((ttright & 0x01) && (ttdown & 0x04)) * 2;
tile += ((ttleft & 0x02) && (ttdown & 0x08)) * 1;
tile = TheMap.Tileset->WoodTable[tile];
//If tile is -1, then we should check if we are to draw just one tree
//Check for tile about, or below or both...
if (tile == -1) {
tile = 16;
tile += ((ttup & 0x01) || (ttup & 0x02)) * 1;
tile += ((ttdown & 0x04) || (ttdown & 0x08)) * 2;
tile = TheMap.Tileset->WoodTable[tile];
}
if (tile == -1) { // No valid wood remove it.
MapRemoveWood(x, y);

View file

@ -197,6 +197,9 @@ global void LoadTileset(void)
if ((tile = table[i])) {
unsigned flags;
//Initialize all Lookup Items to zero
TheMap.Tileset->MixedLookupTable[table[i]] = 0;
flags = TheMap.Tileset->FlagsTable[i];
if (flags & MapFieldWaterAllowed) {
TheMap.Tileset->TileTypeTable[tile] = TileTypeWater;
@ -262,27 +265,76 @@ global void LoadTileset(void)
TheMap.Tileset->MixedNameTable[i] == 0) {
if (TheMap.Tileset->FlagsTable[i] & MapFieldForest) {
solid = i;
}
}
}
i += 16;
}
}
TheMap.Tileset->WoodTable[ 0] = -1;
TheMap.Tileset->WoodTable[ 1] = TheMap.Tileset->BotOneTree;
TheMap.Tileset->WoodTable[ 2] = -1;
TheMap.Tileset->WoodTable[ 3] = table[mixed + 0x10];
TheMap.Tileset->WoodTable[ 4] = TheMap.Tileset->TopOneTree;
TheMap.Tileset->WoodTable[ 5] = TheMap.Tileset->MidOneTree;
TheMap.Tileset->WoodTable[ 6] = table[mixed + 0x70];
TheMap.Tileset->WoodTable[ 7] = table[mixed + 0x90];
TheMap.Tileset->WoodTable[ 8] = -1;
TheMap.Tileset->WoodTable[ 9] = table[mixed + 0x00];
TheMap.Tileset->WoodTable[10] = -1;
TheMap.Tileset->WoodTable[11] = table[mixed + 0x20];
TheMap.Tileset->WoodTable[12] = table[mixed + 0x30];
TheMap.Tileset->WoodTable[13] = table[mixed + 0x40];
TheMap.Tileset->WoodTable[14] = table[mixed + 0xB0];
TheMap.Tileset->WoodTable[ 1] = table[mixed + 0x30];
TheMap.Tileset->WoodTable[ 2] = table[mixed + 0x70];
TheMap.Tileset->WoodTable[ 3] = table[mixed + 0xB0];
TheMap.Tileset->WoodTable[ 4] = table[mixed + 0x10];
TheMap.Tileset->WoodTable[ 5] = table[mixed + 0x50];
TheMap.Tileset->WoodTable[ 6] = table[mixed + 0x90];
TheMap.Tileset->WoodTable[ 7] = table[mixed + 0xD0];
TheMap.Tileset->WoodTable[ 8] = table[mixed + 0x00];
TheMap.Tileset->WoodTable[ 9] = table[mixed + 0x40];
TheMap.Tileset->WoodTable[10] = table[mixed + 0x80];
TheMap.Tileset->WoodTable[11] = table[mixed + 0xC0];
TheMap.Tileset->WoodTable[12] = table[mixed + 0x20];
TheMap.Tileset->WoodTable[13] = table[mixed + 0x60];
TheMap.Tileset->WoodTable[14] = table[mixed + 0xA0];
TheMap.Tileset->WoodTable[15] = table[solid];
TheMap.Tileset->WoodTable[16] = -1;
TheMap.Tileset->WoodTable[17] = TheMap.Tileset->BotOneTree;
TheMap.Tileset->WoodTable[18] = TheMap.Tileset->TopOneTree;
TheMap.Tileset->WoodTable[19] = TheMap.Tileset->MidOneTree;
//Mark which corners of each tile has tree in it.
//All corners for solid tiles.
//1 Bottom Left
//2 Bottom Right
//4 Top Right
//8 Top Left
for (i = solid; i < solid + 16; i++ ) {
TheMap.Tileset->MixedLookupTable[table[i]] = 15;
}
for (i = mixed; i < mixed + 256; i++) {
int check=(int)((i-mixed)/16);
switch (check) {
case 0: TheMap.Tileset->MixedLookupTable[table[i]] = 8;
break;
case 1: TheMap.Tileset->MixedLookupTable[table[i]] = 4;
break;
case 2: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 4;
break;
case 3: TheMap.Tileset->MixedLookupTable[table[i]] = 1;
break;
case 4: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 1;
break;
case 5: TheMap.Tileset->MixedLookupTable[table[i]] = 4 + 1;
break;
case 6: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 4 + 1;
break;
case 7: TheMap.Tileset->MixedLookupTable[table[i]] = 2;
break;
case 8: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 2;
break;
case 9: TheMap.Tileset->MixedLookupTable[table[i]] = 4 + 2;
break;
case 10: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 4 + 2;
break;
case 11: TheMap.Tileset->MixedLookupTable[table[i]] = 2 + 1;
break;
case 12: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 2 + 1;
break;
case 13: TheMap.Tileset->MixedLookupTable[table[i]] = 4 + 2 + 1;
break;
default: TheMap.Tileset->MixedLookupTable[table[i]] = 0;
break;
}
}
//
// Build rock removement table.
@ -304,27 +356,72 @@ global void LoadTileset(void)
i += 16;
}
}
TheMap.Tileset->RockTable[ 0] = -1;
TheMap.Tileset->RockTable[ 1] = TheMap.Tileset->BotOneRock;
TheMap.Tileset->RockTable[ 2] = -1;
TheMap.Tileset->RockTable[ 3] = table[mixed + 0x10];
TheMap.Tileset->RockTable[ 4] = TheMap.Tileset->TopOneRock;
TheMap.Tileset->RockTable[ 5] = TheMap.Tileset->MidOneRock;
TheMap.Tileset->RockTable[ 6] = table[mixed + 0x70];
TheMap.Tileset->RockTable[ 7] = table[mixed + 0x90];
TheMap.Tileset->RockTable[ 8] = -1;
TheMap.Tileset->RockTable[ 9] = table[mixed + 0x00];
TheMap.Tileset->RockTable[10] = -1;
TheMap.Tileset->RockTable[11] = table[mixed + 0x20];
TheMap.Tileset->RockTable[12] = table[mixed + 0x30];
TheMap.Tileset->RockTable[13] = table[mixed + 0x40];
TheMap.Tileset->RockTable[14] = table[mixed + 0xB0];
TheMap.Tileset->RockTable[15] = table[solid];
TheMap.Tileset->RockTable[16] = table[mixed + 0xC0];
TheMap.Tileset->RockTable[17] = table[mixed + 0x60];
TheMap.Tileset->RockTable[18] = table[mixed + 0xA0];
TheMap.Tileset->RockTable[19] = table[mixed + 0xD0];
//Mark which corners of each tile has rock in it.
//All corners for solid tiles.
//1 Bottom Left
//2 Bottom Right
//4 Top Right
//8 Top Left
for (i = solid; i < solid + 16; i++ ) {
TheMap.Tileset->MixedLookupTable[table[i]] = 15;
}
for (i = mixed; i < mixed + 256; i++) {
int check=(int)((i-mixed)/16);
switch (check) {
case 0: TheMap.Tileset->MixedLookupTable[table[i]] = 8;
break;
case 1: TheMap.Tileset->MixedLookupTable[table[i]] = 4;
break;
case 2: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 4;
break;
case 3: TheMap.Tileset->MixedLookupTable[table[i]] = 1;
break;
case 4: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 1;
break;
case 5: TheMap.Tileset->MixedLookupTable[table[i]] = 4 + 1;
break;
case 6: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 4 + 1;
break;
case 7: TheMap.Tileset->MixedLookupTable[table[i]] = 2;
break;
case 8: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 2;
break;
case 9: TheMap.Tileset->MixedLookupTable[table[i]] = 4 + 2;
break;
case 10: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 4 + 2;
break;
case 11: TheMap.Tileset->MixedLookupTable[table[i]] = 2 + 1;
break;
case 12: TheMap.Tileset->MixedLookupTable[table[i]] = 8 + 2 + 1;
break;
case 13: TheMap.Tileset->MixedLookupTable[table[i]] = 4 + 2 + 1;
break;
default: TheMap.Tileset->MixedLookupTable[table[i]] = 0;
break;
}
}
TheMap.Tileset->RockTable[ 0] = -1;
TheMap.Tileset->RockTable[ 1] = table[mixed + 0x30];
TheMap.Tileset->RockTable[ 2] = table[mixed + 0x70];
TheMap.Tileset->RockTable[ 3] = table[mixed + 0xB0];
TheMap.Tileset->RockTable[ 4] = table[mixed + 0x10];
TheMap.Tileset->RockTable[ 5] = table[mixed + 0x50];
TheMap.Tileset->RockTable[ 6] = table[mixed + 0x90];
TheMap.Tileset->RockTable[ 7] = table[mixed + 0xD0];
TheMap.Tileset->RockTable[ 8] = table[mixed + 0x00];
TheMap.Tileset->RockTable[ 9] = table[mixed + 0x40];
TheMap.Tileset->RockTable[10] = table[mixed + 0x80];
TheMap.Tileset->RockTable[11] = table[mixed + 0xC0];
TheMap.Tileset->RockTable[12] = table[mixed + 0x20];
TheMap.Tileset->RockTable[13] = table[mixed + 0x60];
TheMap.Tileset->RockTable[14] = table[mixed + 0xA0];
TheMap.Tileset->RockTable[15] = table[solid];
TheMap.Tileset->RockTable[16] = -1;
TheMap.Tileset->RockTable[17] = TheMap.Tileset->BotOneRock;
TheMap.Tileset->RockTable[18] = TheMap.Tileset->TopOneRock;
TheMap.Tileset->RockTable[19] = TheMap.Tileset->MidOneRock;
//
// FIXME: Build wall replacement tables
//