mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Aesthetic changes in BattleHex (#303)
This commit is contained in:
committed by
ArseniyShestakov
parent
8a494b7820
commit
039e3842fc
@@ -76,7 +76,7 @@ std::pair<si16, si16> BattleHex::getXY() const
|
||||
return std::make_pair(getX(), getY());
|
||||
}
|
||||
|
||||
BattleHex& BattleHex::moveInDir(EDir dir, bool hasToBeValid)
|
||||
BattleHex& BattleHex::moveInDirection(EDir dir, bool hasToBeValid)
|
||||
{
|
||||
si16 x(getX()), y(getY());
|
||||
switch(dir)
|
||||
@@ -102,58 +102,41 @@ BattleHex& BattleHex::moveInDir(EDir dir, bool hasToBeValid)
|
||||
default:
|
||||
throw std::runtime_error("Disaster: wrong direction in BattleHex::operator+=!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
BattleHex &BattleHex::operator+=(BattleHex::EDir dir)
|
||||
{
|
||||
return moveInDir(dir);
|
||||
return moveInDirection(dir);
|
||||
}
|
||||
|
||||
BattleHex BattleHex::movedInDir(BattleHex::EDir dir, bool hasToBeValid) const
|
||||
BattleHex BattleHex::cloneInDirection(BattleHex::EDir dir, bool hasToBeValid) const
|
||||
{
|
||||
BattleHex result(*this);
|
||||
result.moveInDir(dir, hasToBeValid);
|
||||
BattleHex result(hex);
|
||||
result.moveInDirection(dir, hasToBeValid);
|
||||
return result;
|
||||
}
|
||||
|
||||
BattleHex BattleHex::operator+(BattleHex::EDir dir) const
|
||||
{
|
||||
return movedInDir(dir);
|
||||
return cloneInDirection(dir);
|
||||
}
|
||||
|
||||
std::vector<BattleHex> BattleHex::neighbouringTiles() const
|
||||
{
|
||||
std::vector<BattleHex> ret;
|
||||
const int WN = GameConstants::BFIELD_WIDTH;
|
||||
// H3 order : TR, R, BR, BL, L, TL (T = top, B = bottom ...)
|
||||
|
||||
checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret); // 1
|
||||
checkAndPush(hex + 1, ret); // 2
|
||||
checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), ret); // 3
|
||||
checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), ret); // 4
|
||||
checkAndPush(hex - 1, ret); // 5
|
||||
checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret); // 6
|
||||
|
||||
for(EDir dir = EDir(0); dir <= EDir(5); dir = EDir(dir+1))
|
||||
checkAndPush(cloneInDirection(dir, false), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
signed char BattleHex::mutualPosition(BattleHex hex1, BattleHex hex2)
|
||||
{
|
||||
if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left
|
||||
return 0;
|
||||
if(hex2 == hex1 - ( (hex1/17)%2 ? 17 : 16 )) //top right
|
||||
return 1;
|
||||
if(hex2 == hex1 + 1 && hex1%17 != 16) //right
|
||||
return 2;
|
||||
if(hex2 == hex1 + ( (hex1/17)%2 ? 17 : 18 )) //bottom right
|
||||
return 3;
|
||||
if(hex2 == hex1 + ( (hex1/17)%2 ? 16 : 17 )) //bottom left
|
||||
return 4;
|
||||
if(hex2 == hex1 - 1 && hex1%17 != 0) //left
|
||||
return 5;
|
||||
return -1;
|
||||
for(EDir dir = EDir(0); dir <= EDir(5); dir = EDir(dir+1))
|
||||
if(hex2 == hex1.cloneInDirection(dir,false))
|
||||
return dir;
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
char BattleHex::getDistance(BattleHex hex1, BattleHex hex2)
|
||||
|
||||
@@ -15,7 +15,7 @@ struct DLL_LINKAGE BattleHex //TODO: decide if this should be changed to class f
|
||||
{
|
||||
si16 hex;
|
||||
static const si16 INVALID = -1;
|
||||
enum EDir { RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT, TOP_LEFT, TOP_RIGHT };
|
||||
enum EDir { TOP_LEFT, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT};
|
||||
|
||||
BattleHex();
|
||||
BattleHex(si16 _hex);
|
||||
@@ -31,16 +31,12 @@ struct DLL_LINKAGE BattleHex //TODO: decide if this should be changed to class f
|
||||
si16 getX() const;
|
||||
si16 getY() const;
|
||||
std::pair<si16, si16> getXY() const;
|
||||
//moving to direction
|
||||
BattleHex& moveInDir(EDir dir, bool hasToBeValid = true);
|
||||
BattleHex& operator+=(EDir dir); //sugar for above
|
||||
//generates new BattleHex moved by given dir
|
||||
BattleHex movedInDir(EDir dir, bool hasToBeValid = true) const;
|
||||
BattleHex& moveInDirection(EDir dir, bool hasToBeValid = true);
|
||||
BattleHex& operator+=(EDir dir);
|
||||
BattleHex cloneInDirection(EDir dir, bool hasToBeValid = true) const;
|
||||
BattleHex operator+(EDir dir) const;
|
||||
std::vector<BattleHex> neighbouringTiles() const;
|
||||
//returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
|
||||
static signed char mutualPosition(BattleHex hex1, BattleHex hex2);
|
||||
//returns distance between given hexes
|
||||
static char getDistance(BattleHex hex1, BattleHex hex2);
|
||||
static void checkAndPush(BattleHex tile, std::vector<BattleHex> & ret);
|
||||
static BattleHex getClosestTile(bool attackerOwned, BattleHex initialPos, std::set<BattleHex> & possibilities); //TODO: vector or set? copying one to another is bad
|
||||
|
||||
@@ -566,9 +566,9 @@ std::vector<BattleHex> WallMechanics::rangeInHexes(BattleHex centralHex, ui8 sch
|
||||
};
|
||||
|
||||
ret.push_back(centralHex);
|
||||
addIfValid(centralHex.moveInDir(firstStep, false));
|
||||
addIfValid(centralHex.moveInDirection(firstStep, false));
|
||||
if(schoolLvl >= 2) //advanced versions of fire wall / force field cotnains of 3 hexes
|
||||
addIfValid(centralHex.moveInDir(secondStep, false)); //moveInDir function modifies subject hex
|
||||
addIfValid(centralHex.moveInDirection(secondStep, false)); //moveInDir function modifies subject hex
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user