Remove unused growingTree.

make more CTileset member private
This commit is contained in:
joris 2013-04-20 09:33:37 +02:00
parent 5003649f64
commit e8451ddea9
6 changed files with 113 additions and 134 deletions

View file

@ -938,13 +938,13 @@ static void DrawEditorInfo()
char buf[256];
snprintf(buf, sizeof(buf), "Editor (%d %d)", pos.x, pos.y);
CLabel(GetGameFont()).Draw(UI.StatusLine.TextX + 2, UI.StatusLine.TextY, buf);
const CMapField *mf = Map.Field(pos);
const CMapField &mf = *Map.Field(pos);
//
// Flags info
//
unsigned flags = mf->Flags;
unsigned flags = mf.Flags;
sprintf(buf, "%02X|%04X|%c%c%c%c%c%c%c%c%c%c%c%c%c",
mf->Value, flags,
mf.Value, flags,
flags & MapFieldUnpassable ? 'u' : '-',
flags & MapFieldNoBuilding ? 'n' : '-',
flags & MapFieldHuman ? 'h' : '-',
@ -961,12 +961,13 @@ static void DrawEditorInfo()
CLabel(GetGameFont()).Draw(UI.StatusLine.TextX + 118, UI.StatusLine.TextY, buf);
// Tile info
const int index = Map.Tileset->findTileIndexByTile(mf->Tile);
const CTileset &tileset = *Map.Tileset;
const int index = tileset.findTileIndexByTile(mf.Tile);
Assert(index != -1);
const int baseTerrainIdx = Map.Tileset->Tiles[index].BaseTerrain;
const char *baseTerrainStr = Map.Tileset->SolidTerrainTypes[baseTerrainIdx].TerrainName.c_str();
const int mixTerrainIdx = Map.Tileset->Tiles[index].MixTerrain;
const char *mixTerrainStr = mixTerrainIdx ? Map.Tileset->SolidTerrainTypes[mixTerrainIdx].TerrainName.c_str() : "";
const int baseTerrainIdx = tileset.Tiles[index].BaseTerrain;
const char *baseTerrainStr = tileset.getTerrainName(baseTerrainIdx).c_str();
const int mixTerrainIdx = tileset.Tiles[index].MixTerrain;
const char *mixTerrainStr = mixTerrainIdx ? tileset.getTerrainName(mixTerrainIdx).c_str() : "";
snprintf(buf, sizeof(buf), "%s %s", baseTerrainStr, mixTerrainStr);
CLabel(GetGameFont()).Draw(UI.StatusLine.TextX + 250, UI.StatusLine.TextY, buf);
#endif
@ -1563,7 +1564,7 @@ static bool EditorCallbackMouse_EditTileArea(const PixelPos &screenPos)
const int tile = Editor.ShownTileTypes[i];
const int tileindex = Map.Tileset->findTileIndexByTile(tile);
const int base = Map.Tileset->Tiles[tileindex].BaseTerrain;
UI.StatusLine.Set(Map.Tileset->SolidTerrainTypes[base].TerrainName);
UI.StatusLine.Set(Map.Tileset->getTerrainName(base));
Editor.CursorTileIndex = i;
return true;
}

View file

@ -155,7 +155,7 @@ static int TileFromQuad(unsigned fixed, unsigned quad)
std::vector<char> marks;
int dummytileIndex;
marks.resize(Map.Tileset->SolidTerrainTypes.size(), 0);
marks.resize(Map.Tileset->getSolidTerrainCount(), 0);
marks[type1] = type1;
marks[type2] = type2;
@ -181,7 +181,7 @@ static int TileFromQuad(unsigned fixed, unsigned quad)
}
// Find the best tile path.
std::vector<char> marks;
marks.resize(Map.Tileset->SolidTerrainTypes.size(), 0);
marks.resize(Map.Tileset->getSolidTerrainCount(), 0);
marks[type1] = type1;
if (FindTilePath(type1, type2, 0, marks, &tileIndex) == INT_MAX) {
DebugPrint("Huch, no mix found!!!!!!!!!!!\n");

View file

@ -85,6 +85,8 @@ public:
void Clear();
bool IsSeenTile(unsigned short type, unsigned short seen) const;
unsigned getRemovedRockTile() const { return RemovedRock; }
unsigned getRemovedTreeTile() const { return RemovedTree; }
unsigned getBottomOneTreeTile() const { return BotOneTree; }
unsigned getTopOneTreeTile() const { return TopOneTree; }
@ -96,7 +98,9 @@ public:
unsigned getOrcWallTile_destroyed(int index) const;
public:
unsigned int getOrAddSolidTileIndexByName(const std::string &name);
unsigned int getSolidTerrainCount() const;
const std::string &getTerrainName(int solidTerrainIndex) const;
int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain = 0) const;
int getTileIndex(unsigned char baseTerrain, unsigned char mixTerrain, unsigned int quad) const;
@ -104,15 +108,17 @@ public:
unsigned int getTileNumber(int basic, bool random, bool filler) const;
void fillSolidTiles(std::vector<unsigned int> *tiles) const;
unsigned getQuadFromTile(unsigned int tile) const;
int getTileIndexBySurrounding(unsigned short type,
unsigned int up, unsigned int right,
unsigned int bottom, unsigned int left) const;
public:
void parse(lua_State *l);
void buildTable(lua_State *l);
private:
unsigned int getOrAddSolidTileIndexByName(const std::string &name);
void buildWallReplacementTable();
void parseSlots(lua_State *l, int t);
void parseSpecial(lua_State *l);
@ -131,25 +137,21 @@ public:
// TODO: currently hardcoded
std::vector<unsigned char> TileTypeTable; /// For fast lookup of tile type
private:
std::vector<SolidTerrainInfo> SolidTerrainTypes; /// Information about solid terrains.
public:
std::vector<int> MixedLookupTable; /// Lookup for what part of tile used
private:
unsigned TopOneTree; /// Tile for one tree top
unsigned MidOneTree; /// Tile for one tree middle
unsigned BotOneTree; /// Tile for one tree bottom
public:
int RemovedTree; /// Tile placed where trees are gone
unsigned GrowingTree[2]; /// Growing tree tiles
int WoodTable[20]; /// Table for tree removable
private:
unsigned TopOneRock; /// Tile for one rock top
unsigned MidOneRock; /// Tile for one rock middle
unsigned BotOneRock; /// Tile for one rock bottom
public:
int RemovedRock; /// Tile placed where rocks are gone
int RockTable[20]; /// Removed rock placement table
private:
unsigned HumanWallTable[16]; /// Human wall placement table
unsigned OrcWallTable[16]; /// Orc wall placement table
};

View file

@ -61,17 +61,14 @@ char CurrentMapPath[1024]; /// Path of the current map
/**
** Marks seen tile -- used mainly for the Fog Of War
**
** @param x Map X tile-position.
** @param y Map Y tile-position.
** @param mf MapField-position.
*/
void CMap::MarkSeenTile(CMapField &mf)
{
const int tile = mf.Tile;
const int seentile = mf.playerInfo.SeenTile;
const unsigned int tile = mf.Tile;
const unsigned int seentile = mf.playerInfo.SeenTile;
//
// Nothing changed? Seeing already the correct tile.
//
if (tile == seentile) {
return;
}
@ -95,18 +92,18 @@ void CMap::MarkSeenTile(CMapField &mf)
#endif
// Handle wood changes. FIXME: check if for growing wood correct?
if (seentile != this->Tileset->RemovedTree && tile == this->Tileset->RemovedTree) {
if (seentile != this->Tileset->getRemovedTreeTile() && tile == this->Tileset->getRemovedTreeTile()) {
FixNeighbors(MapFieldForest, 1, pos);
} else if (seentile == this->Tileset->RemovedTree && tile != this->Tileset->RemovedTree) {
} else if (seentile == this->Tileset->getRemovedTreeTile() && tile != this->Tileset->getRemovedTreeTile()) {
FixTile(MapFieldForest, 1, pos);
} else if (mf.ForestOnMap()) {
FixTile(MapFieldForest, 1, pos);
FixNeighbors(MapFieldForest, 1, pos);
// Handle rock changes.
} else if (seentile != Tileset->RemovedRock && tile == Tileset->RemovedRock) {
} else if (seentile != Tileset->getRemovedRockTile() && tile == Tileset->getRemovedRockTile()) {
FixNeighbors(MapFieldRocks, 1, pos);
} else if (seentile == Tileset->RemovedRock && tile != Tileset->RemovedRock) {
} else if (seentile == Tileset->getRemovedRockTile() && tile != Tileset->getRemovedRockTile()) {
FixTile(MapFieldRocks, 1, pos);
} else if (mf.RockOnMap()) {
FixTile(MapFieldRocks, 1, pos);
@ -428,12 +425,14 @@ void CMap::Clean()
/**
** Correct the seen wood field, depending on the surrounding.
**
** @param type type fo tile to update
** @param type type of tile to update
** @param seen 1 if updating seen value, 0 for real
** @param pos Map tile-position.
*/
void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
{
Assert(type == MapFieldForest || type == MapFieldRocks);
// Outside of map or no wood.
if (!Info.IsPointOnMap(pos)) {
return;
@ -448,29 +447,16 @@ void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
}
// Select Table to lookup
int *lookuptable;
int removedtile;
int flags;
switch (type) {
case MapFieldForest:
lookuptable = this->Tileset->WoodTable;
removedtile = this->Tileset->RemovedTree;
flags = (MapFieldForest | MapFieldUnpassable);
break;
case MapFieldRocks:
lookuptable = this->Tileset->RockTable;
removedtile = this->Tileset->RemovedRock;
flags = (MapFieldRocks | MapFieldUnpassable);
break;
default:
lookuptable = NULL;
removedtile = 0;
flags = 0;
if (type == MapFieldForest) {
removedtile = this->Tileset->getRemovedTreeTile();
flags = (MapFieldForest | MapFieldUnpassable);
} else { // (type == MapFieldRocks)
removedtile = this->Tileset->getRemovedRockTile();
flags = (MapFieldRocks | MapFieldUnpassable);
}
//
// Find out what each tile has with respect to wood, or grass.
//
int tile = 0;
int ttup;
int ttdown;
int ttleft;
@ -479,79 +465,32 @@ void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
if (pos.y - 1 < 0) {
ttup = 15; //Assign trees in all directions
} else {
CMapField &new_mf = *(&mf - this->Info.MapWidth);
if (seen) {
ttup = this->Tileset->MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttup = this->Tileset->MixedLookupTable[new_mf.Tile];
}
const CMapField &new_mf = *(&mf - this->Info.MapWidth);
ttup = seen ? new_mf.playerInfo.SeenTile : new_mf.Tile;
ttup = this->Tileset->MixedLookupTable[ttup];
}
if (pos.x + 1 >= this->Info.MapWidth) {
ttright = 15; //Assign trees in all directions
} else {
CMapField &new_mf = *(&mf + 1);
if (seen) {
ttright = this->Tileset->MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttright = this->Tileset->MixedLookupTable[new_mf.Tile];
}
const CMapField &new_mf = *(&mf + 1);
ttright = seen ? new_mf.playerInfo.SeenTile : new_mf.Tile;
ttright = this->Tileset->MixedLookupTable[ttright];
}
if (pos.y + 1 >= this->Info.MapHeight) {
ttdown = 15; //Assign trees in all directions
} else {
CMapField &new_mf = *(&mf + this->Info.MapWidth);
if (seen) {
ttdown = this->Tileset->MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttdown = this->Tileset->MixedLookupTable[new_mf.Tile];
}
const CMapField &new_mf = *(&mf + this->Info.MapWidth);
ttdown = seen ? new_mf.playerInfo.SeenTile : new_mf.Tile;
ttdown = this->Tileset->MixedLookupTable[ttdown];
}
if (pos.x - 1 < 0) {
ttleft = 15; //Assign trees in all directions
} else {
CMapField &new_mf = *(&mf - 1);
if (seen) {
ttleft = this->Tileset->MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttleft = this->Tileset->MixedLookupTable[new_mf.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;
//Test if we have top tree, or bottom tree, they are special
if ((ttdown & 0x10) != 0) {
tile |= (ttleft & 0x06) != 0 ? 1 : 0;
tile |= (ttright & 0x09) != 0 ? 2 : 0;
}
if ((ttup & 0x20) != 0) {
tile |= (ttleft & 0x06) != 0 ? 8 : 0;
tile |= (ttright & 0x09) != 0 ? 4 : 0;
}
tile = lookuptable[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 = lookuptable[tile];
const CMapField &new_mf = *(&mf - 1);
ttleft = seen ? new_mf.playerInfo.SeenTile : new_mf.Tile;
ttleft = this->Tileset->MixedLookupTable[ttleft];
}
int tile = this->Tileset->getTileIndexBySurrounding(type, ttup, ttright, ttdown, ttleft);
//Update seen tile.
if (tile == -1) { // No valid wood remove it.
@ -618,15 +557,15 @@ void CMap::ClearTile(unsigned short type, const Vec2i &pos)
// Select Table to lookup
switch (type) {
case MapFieldForest:
removedtile = this->Tileset->RemovedTree;
removedtile = this->Tileset->getRemovedTreeTile();
flags = (MapFieldForest | MapFieldUnpassable);
break;
case MapFieldRocks:
removedtile = this->Tileset->RemovedRock;
removedtile = this->Tileset->getRemovedRockTile();
flags = (MapFieldRocks | MapFieldUnpassable);
break;
default:
removedtile = flags = 0;
return;
}
mf.Tile = removedtile;
mf.Flags &= ~flags;
@ -652,7 +591,7 @@ void CMap::RegenerateForestTile(const Vec2i &pos)
Assert(Map.Info.IsPointOnMap(pos));
CMapField &mf = *this->Field(pos);
if (mf.Tile != this->Tileset->RemovedTree) {
if (mf.Tile != this->Tileset->getRemovedTreeTile()) {
return;
}
@ -671,7 +610,7 @@ void CMap::RegenerateForestTile(const Vec2i &pos)
return;
}
CMapField &topMf = *(&mf - this->Info.MapWidth);
if (topMf.Tile == this->Tileset->RemovedTree
if (topMf.Tile == this->Tileset->getRemovedTreeTile()
&& topMf.Value >= ForestRegeneration
&& !(topMf.Flags & occupedFlag)) {
DebugPrint("Real place wood\n");

View file

@ -177,19 +177,8 @@ void CTileset::parseSpecial(lua_State *l)
lua_pop(l, 1);
} else if (!strcmp(value, "growing-tree")) {
++j;
lua_rawgeti(l, -1, j + 1);
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument");
}
if (lua_rawlen(l, -1) != 2) {
LuaError(l, "growing-tree: Wrong table length");
}
for (int i = 0; i < 2; ++i) {
lua_rawgeti(l, -1, i + 1);
GrowingTree[i] = LuaToNumber(l, -1);
lua_pop(l, 1);
}
lua_pop(l, 1);
// keep for retro compatibility.
// TODO : remove when game data are updated.
} else if (!strcmp(value, "top-one-rock")) {
++j;
lua_rawgeti(l, -1, j + 1);

View file

@ -125,11 +125,6 @@
** The tile number of the tile placed where trees are removed.
** Is created on the map by lumber chopping.
**
** CTileset::GrowingTree[2]
**
** Contains the tile numbers of a growing tree from small to big.
** @note Not yet used.
**
** CTilset::WoodTable[20]
**
** Table for wood removable. This table contains the tile which
@ -248,7 +243,6 @@ void CTileset::Clear()
MidOneTree = 0;
BotOneTree = 0;
RemovedTree = 0;
memset(GrowingTree, 0, sizeof(GrowingTree));
memset(WoodTable, 0, sizeof(WoodTable));
MixedLookupTable.clear();
TopOneRock = 0;
@ -289,6 +283,16 @@ unsigned int CTileset::getOrAddSolidTileIndexByName(const std::string &name)
return SolidTerrainTypes.size() - 1;
}
const std::string &CTileset::getTerrainName(int solidTerrainIndex) const
{
return SolidTerrainTypes[solidTerrainIndex].TerrainName;
}
unsigned int CTileset::getSolidTerrainCount() const
{
return SolidTerrainTypes.size();
}
int CTileset::findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain) const
{
const TileInfo tileInfo = {baseTerrain, mixTerrain};
@ -330,6 +334,50 @@ int CTileset::getTileIndex(unsigned char baseTerrain, unsigned char mixTerrain,
return base | (table[direction] << 4);
}
int CTileset::getTileIndexBySurrounding(unsigned short type,
unsigned int ttup, unsigned int ttright,
unsigned int ttdown, unsigned int ttleft) const
{
// Check each of the corners to ensure it has both connecting
// ?**?
// *mm*
// *mm*
// ?**?
//
// * type asterixs must match for wood to be present
int tile = 0;
tile += ((ttup & 0x01) && (ttleft & 0x04)) * 8;
tile += ((ttup & 0x02) && (ttright & 0x08)) * 4;
tile += ((ttright & 0x01) && (ttdown & 0x04)) * 2;
tile += ((ttleft & 0x02) && (ttdown & 0x08)) * 1;
//Test if we have top tree, or bottom tree, they are special
if ((ttdown & 0x10) != 0) {
tile |= (ttleft & 0x06) != 0 ? 1 : 0;
tile |= (ttright & 0x09) != 0 ? 2 : 0;
}
if ((ttup & 0x20) != 0) {
tile |= (ttleft & 0x06) != 0 ? 8 : 0;
tile |= (ttright & 0x09) != 0 ? 4 : 0;
}
Assert(type == MapFieldForest || type == MapFieldRocks);
const int (&lookuptable)[20] = (type == MapFieldForest) ? WoodTable : RockTable;
tile = lookuptable[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 = lookuptable[tile];
}
return tile;
}
int CTileset::findTileIndexByTile(unsigned int tile) const
{
for (int i = 0; i != NumTiles; ++i) {