Rename some arguments of CTileset methods.

Change some methods of CTileset as private.
Move hardcoded getDefaultTileIndex into CTileset.
This commit is contained in:
joris 2013-04-23 22:49:57 +02:00
parent 69246a0896
commit 8610491675
6 changed files with 88 additions and 85 deletions

View file

@ -958,7 +958,7 @@ static void DrawEditorInfo()
// Tile info
const CTileset &tileset = *Map.Tileset;
const int index = tileset.findTileIndexByTile(mf.Tile);
const int index = tileset.findTileIndexByTile(mf.TilesetTile);
Assert(index != -1);
const int baseTerrainIdx = tileset.tiles[index].tileinfo.BaseTerrain;
const char *baseTerrainStr = tileset.getTerrainName(baseTerrainIdx).c_str();
@ -1862,8 +1862,7 @@ void CEditor::Init()
Map.Fields = new CMapField[Map.Info.MapWidth * Map.Info.MapHeight];
// Hard coded
const int defaultTile = 0x50;
const int defaultTile = Map.Tileset->getDefaultTileIndex();
for (int i = 0; i < Map.Info.MapWidth * Map.Info.MapHeight; ++i) {
Map.Fields[i].setTileIndex(*Map.Tileset, defaultTile, 0);

View file

@ -66,8 +66,7 @@ public:
CTileInfo(unsigned char base, unsigned char mix) : BaseTerrain(base), MixTerrain(mix)
{}
bool operator ==(const CTileInfo &rhs) const
{
bool operator ==(const CTileInfo &rhs) const {
return BaseTerrain == rhs.BaseTerrain && MixTerrain == rhs.MixTerrain;
}
bool operator !=(const CTileInfo &rhs) const { return !(*this == rhs); }
@ -99,10 +98,12 @@ public:
unsigned int getTileCount() const { return tiles.size(); }
bool isAWallTile(unsigned tileIndex) const;
bool isARaceWallTile(unsigned tileIndex, bool human) const;
bool isAWoodTile(unsigned tileIndex) const;
bool isARockTile(unsigned tileIndex) const;
unsigned int getDefaultTileIndex() const;
bool isAWallTile(unsigned tile) const;
bool isARaceWallTile(unsigned tile, bool human) const;
bool isAWoodTile(unsigned tile) const;
bool isARockTile(unsigned tile) const;
const PixelSize &getPixelTileSize() const { return pixelTileSize; }
@ -111,22 +112,20 @@ public:
unsigned getBottomOneTreeTile() const { return botOneTreeTile; }
unsigned getTopOneTreeTile() const { return topOneTreeTile; }
unsigned getHumanWallTile(int index) const;
unsigned getOrcWallTile(int index) const;
unsigned getHumanWallTile_broken(int index) const;
unsigned getOrcWallTile_broken(int index) const;
unsigned getHumanWallTile_destroyed(int index) const;
unsigned getOrcWallTile_destroyed(int index) const;
unsigned getHumanWallTile(int dirFlag) const;
unsigned getOrcWallTile(int dirFlag) const;
unsigned getHumanWallTile_broken(int dirFlag) const;
unsigned getOrcWallTile_broken(int dirFlag) const;
unsigned getHumanWallTile_destroyed(int dirFlag) const;
unsigned getOrcWallTile_destroyed(int dirFlag) const;
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;
int findTileIndexByTile(unsigned int tile) const;
unsigned int getTileNumber(int basic, bool random, bool filler) const;
void fillSolidTiles(std::vector<unsigned int> *tiles) const;
void fillSolidTiles(std::vector<unsigned int> *solidTiles) const;
unsigned getQuadFromTile(unsigned int tile) const;
int getTileIndexBySurrounding(unsigned short type,
@ -140,6 +139,8 @@ public:
private:
unsigned int getOrAddSolidTileIndexByName(const std::string &name);
int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain = 0) const;
int getTileIndex(unsigned char baseTerrain, unsigned char mixTerrain, unsigned int quad) const;
void buildWallReplacementTable();
void parseSlots(lua_State *l, int t);
void parseSpecial(lua_State *l);

View file

@ -415,7 +415,7 @@ void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
CMapField &mf = *this->Field(index);
if (!((type == MapFieldForest && Tileset->isAWoodTile(mf.playerInfo.SeenTile))
|| (type == MapFieldRocks && Tileset->isARockTile(mf.playerInfo.SeenTile)))) {
|| (type == MapFieldRocks && Tileset->isARockTile(mf.playerInfo.SeenTile)))) {
if (seen) {
return;
}

View file

@ -60,23 +60,23 @@
For the connecting new walls -- all's fine.
*/
static unsigned int getWallTile(const CTileset &tileset, bool humanWall, int index, int value)
static unsigned int getWallTile(const CTileset &tileset, bool humanWall, int dirFlag, int value)
{
if (humanWall) {
if (value == 0) {
return tileset.getHumanWallTile_destroyed(index);
return tileset.getHumanWallTile_destroyed(dirFlag);
} else if (UnitTypeHumanWall && value <= UnitTypeHumanWall->DefaultStat.Variables[HP_INDEX].Max / 2) {
return tileset.getHumanWallTile_broken(index);
return tileset.getHumanWallTile_broken(dirFlag);
} else {
return tileset.getHumanWallTile(index);
return tileset.getHumanWallTile(dirFlag);
}
} else { // orcWall
if (value == 0) {
return tileset.getOrcWallTile_destroyed(index);
return tileset.getOrcWallTile_destroyed(dirFlag);
} else if (UnitTypeOrcWall && value <= UnitTypeOrcWall->DefaultStat.Variables[HP_INDEX].Max / 2) {
return tileset.getOrcWallTile_broken(index);
return tileset.getOrcWallTile_broken(dirFlag);
} else {
return tileset.getOrcWallTile(index);
return tileset.getOrcWallTile(dirFlag);
}
}
}
@ -88,23 +88,23 @@ static unsigned int getWallTile(const CTileset &tileset, bool humanWall, int ind
static int GetDirectionFromSurrounding(const Vec2i &pos, bool human, bool seen)
{
const Vec2i offsets[4] = {Vec2i(0, -1), Vec2i(1, 0), Vec2i(0, 1), Vec2i(-1, 0)};
int dir = 0;
int dirFlag = 0;
for (int i = 0; i != 4; ++i) {
const Vec2i newpos = pos + offsets[i];
if (!Map.Info.IsPointOnMap(newpos)) {
dir |= 1 << i;
dirFlag |= 1 << i;
} else {
const CMapField &mf = *Map.Field(newpos);
const unsigned int tileIndex = seen ? mf.playerInfo.SeenTile : mf.Tile;
const unsigned int tile = seen ? mf.playerInfo.SeenTile : mf.Tile;
if (Map.Tileset->isARaceWallTile(tileIndex, human)) {
dir |= 1 << i;
if (Map.Tileset->isARaceWallTile(tile, human)) {
dirFlag |= 1 << i;
}
}
}
return dir;
return dirFlag;
}
/**
@ -120,16 +120,16 @@ void MapFixSeenWallTile(const Vec2i &pos)
}
CMapField &mf = *Map.Field(pos);
const CTileset &tileset = *Map.Tileset;
const unsigned tileIndex = mf.playerInfo.SeenTile;
if (!tileset.isAWallTile(tileIndex)) {
const unsigned tile = mf.playerInfo.SeenTile;
if (!tileset.isAWallTile(tile)) {
return;
}
const bool human = tileset.isARaceWallTile(tileIndex, true);
const int dir = GetDirectionFromSurrounding(pos, human, true);
const int tile = getWallTile(tileset, human, dir, mf.Value);
const bool human = tileset.isARaceWallTile(tile, true);
const int dirFlag = GetDirectionFromSurrounding(pos, human, true);
const int wallTile = getWallTile(tileset, human, dirFlag, mf.Value);
if (mf.playerInfo.SeenTile != tile) { // Already there!
mf.playerInfo.SeenTile = tile;
if (mf.playerInfo.SeenTile != wallTile) { // Already there!
mf.playerInfo.SeenTile = wallTile;
// FIXME: can this only happen if seen?
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
UI.Minimap.UpdateSeenXY(pos);
@ -164,16 +164,16 @@ void MapFixWallTile(const Vec2i &pos)
}
CMapField &mf = *Map.Field(pos);
const CTileset &tileset = *Map.Tileset;
const unsigned tileIndex = mf.Tile;
if (!tileset.isAWallTile(tileIndex)) {
const int tile = mf.Tile;
if (!tileset.isAWallTile(tile)) {
return;
}
const bool human = tileset.isARaceWallTile(tileIndex, true);
const int dir = GetDirectionFromSurrounding(pos, human, false);
const int tile = getWallTile(tileset, human, dir, mf.Value);
const bool human = tileset.isARaceWallTile(tile, true);
const int dirFlag = GetDirectionFromSurrounding(pos, human, false);
const int wallTile = getWallTile(tileset, human, dirFlag, mf.Value);
if (mf.Tile != tile) {
mf.Tile = tile;
if (mf.Tile != wallTile) {
mf.Tile = wallTile;
UI.Minimap.UpdateXY(pos);
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
@ -259,9 +259,8 @@ void CMap::SetWall(const Vec2i &pos, bool humanwall)
*/
void CMap::HitWall(const Vec2i &pos, unsigned damage)
{
unsigned v;
const unsigned v = this->Field(pos)->Value;
v = this->Field(pos)->Value;
if (v <= damage) {
RemoveWall(pos);
} else {

View file

@ -650,26 +650,26 @@ void CTileset::buildWallReplacementTable()
// Set destroyed walls to TileTypeUnknown
for (int i = 0; i < 16; ++i) {
int n = 0;
unsigned int tile = humanWallTable[i];
while (tiles[tile].tile) { // Skip good tiles
++tile;
unsigned int tileIndex = humanWallTable[i];
while (tiles[tileIndex].tile) { // Skip good tiles
++tileIndex;
++n;
}
while (!tiles[tile].tile) { // Skip separator
++tile;
while (!tiles[tileIndex].tile) { // Skip separator
++tileIndex;
++n;
}
while (tiles[tile].tile) { // Skip good tiles
++tile;
while (tiles[tileIndex].tile) { // Skip good tiles
++tileIndex;
++n;
}
while (!tiles[tile].tile) { // Skip separator
++tile;
while (!tiles[tileIndex].tile) { // Skip separator
++tileIndex;
++n;
}
while (n < 16 && tiles[tile].tile) {
TileTypeTable[tiles[tile].tile] = TileTypeUnknown;
++tile;
while (n < 16 && tiles[tileIndex].tile) {
TileTypeTable[tiles[tileIndex].tile] = TileTypeUnknown;
++tileIndex;
++n;
}
}

View file

@ -227,45 +227,49 @@ void CTileset::clear()
memset(orcWallTable, 0, sizeof(orcWallTable));
}
bool CTileset::isAWallTile(unsigned tileIndex) const
unsigned int CTileset::getDefaultTileIndex() const
{
// TODO: remove hardcoded value.
return 0x50;
}
bool CTileset::isAWallTile(unsigned tile) const
{
if (TileTypeTable.empty() == false) {
return (TileTypeTable[tileIndex] == TileTypeHumanWall
|| TileTypeTable[tileIndex] == TileTypeOrcWall);
return (TileTypeTable[tile] == TileTypeHumanWall
|| TileTypeTable[tile] == TileTypeOrcWall);
}
return false;
}
bool CTileset::isARaceWallTile(unsigned tileIndex, bool human) const
bool CTileset::isARaceWallTile(unsigned tile, bool human) const
{
if (TileTypeTable.empty() == false) {
if (human) {
return TileTypeTable[tileIndex] == TileTypeHumanWall;
return TileTypeTable[tile] == TileTypeHumanWall;
} else {
return TileTypeTable[tileIndex] == TileTypeOrcWall;
return TileTypeTable[tile] == TileTypeOrcWall;
}
}
return false;
}
bool CTileset::isAWoodTile(unsigned tileIndex) const
bool CTileset::isAWoodTile(unsigned tile) const
{
if (TileTypeTable.empty() == false) {
return TileTypeTable[tileIndex] == TileTypeWood;
return TileTypeTable[tile] == TileTypeWood;
}
return false;
}
bool CTileset::isARockTile(unsigned tileIndex) const
bool CTileset::isARockTile(unsigned tile) const
{
if (TileTypeTable.empty() == false) {
return TileTypeTable[tileIndex] == TileTypeRock;
return TileTypeTable[tile] == TileTypeRock;
}
return false;
}
unsigned int CTileset::getOrAddSolidTileIndexByName(const std::string &name)
{
for (size_t i = 0; i != solidTerrainTypes.size(); ++i) {
@ -523,7 +527,7 @@ int CTileset::getTileIndexBySurrounding(unsigned short type,
bool CTileset::isEquivalentTile(unsigned int tile1, unsigned int tile2) const
{
// Assert(type == MapFieldForest || type == MapFieldRocks);
//Assert(type == MapFieldForest || type == MapFieldRocks);
return mixedLookupTable[tile1] == mixedLookupTable[tile2];
}
@ -644,15 +648,15 @@ void CTileset::fillSolidTiles(std::vector<unsigned int> *solidTiles) const
}
unsigned CTileset::getHumanWallTile(int index) const
unsigned CTileset::getHumanWallTile(int dirFlag) const
{
unsigned tile = humanWallTable[index];
unsigned tile = humanWallTable[dirFlag];
tile = tiles[tile].tile;
return tile;
}
unsigned CTileset::getOrcWallTile(int index) const
unsigned CTileset::getOrcWallTile(int dirFlag) const
{
unsigned tile = orcWallTable[index];
unsigned tile = orcWallTable[dirFlag];
tile = tiles[tile].tile;
return tile;
}
@ -668,31 +672,31 @@ static unsigned int NextSection(const CTileset &tileset, unsigned int tile)
return tile;
}
unsigned CTileset::getHumanWallTile_broken(int index) const
unsigned CTileset::getHumanWallTile_broken(int dirFlag) const
{
unsigned tile = humanWallTable[index];
unsigned tile = humanWallTable[dirFlag];
tile = NextSection(*this, tile);
tile = tiles[tile].tile;
return tile;
}
unsigned CTileset::getOrcWallTile_broken(int index) const
unsigned CTileset::getOrcWallTile_broken(int dirFlag) const
{
unsigned tile = orcWallTable[index];
unsigned tile = orcWallTable[dirFlag];
tile = NextSection(*this, tile);
tile = tiles[tile].tile;
return tile;
}
unsigned CTileset::getHumanWallTile_destroyed(int index) const
unsigned CTileset::getHumanWallTile_destroyed(int dirFlag) const
{
unsigned tile = humanWallTable[index];
unsigned tile = humanWallTable[dirFlag];
tile = NextSection(*this, tile);
tile = NextSection(*this, tile);
tile = tiles[tile].tile;
return tile;
}
unsigned CTileset::getOrcWallTile_destroyed(int index) const
unsigned CTileset::getOrcWallTile_destroyed(int dirFlag) const
{
unsigned tile = orcWallTable[index];
unsigned tile = orcWallTable[dirFlag];
tile = NextSection(*this, tile);
tile = NextSection(*this, tile);
tile = tiles[tile].tile;