2020-03-31 20:47:18 +02:00
|
|
|
#include "position.h"
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-03-31 20:47:18 +02:00
|
|
|
#include "../realms/realm.h"
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-03-27 17:08:52 +01:00
|
|
|
#include <algorithm>
|
2020-04-09 20:29:32 +02:00
|
|
|
#include <array>
|
2020-03-27 16:21:32 +01:00
|
|
|
#include <cstdlib>
|
2020-03-27 17:08:52 +01:00
|
|
|
#include <limits>
|
2020-03-27 16:21:32 +01:00
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Core
|
|
|
|
|
{
|
2020-03-29 13:31:53 +02:00
|
|
|
namespace
|
|
|
|
|
{
|
2020-04-09 20:29:32 +02:00
|
|
|
const std::array<Vec2d, 8> move_delta = {{{0, -1}, // 0 is N
|
|
|
|
|
{+1, -1}, // 1 is NE
|
|
|
|
|
{+1, 0}, // ...
|
|
|
|
|
{+1, +1},
|
|
|
|
|
{0, +1},
|
|
|
|
|
{-1, +1},
|
|
|
|
|
{-1, 0},
|
|
|
|
|
{-1, -1}}};
|
|
|
|
|
const std::array<UFACING, 8> away_cvt = {FACING_S, FACING_SW, FACING_W, FACING_NW,
|
|
|
|
|
FACING_N, FACING_NE, FACING_E, FACING_SE};
|
|
|
|
|
|
2020-03-31 20:47:18 +02:00
|
|
|
s8 clip_s8( int v )
|
|
|
|
|
{
|
|
|
|
|
return static_cast<s8>(
|
|
|
|
|
std::min( static_cast<int>( std::numeric_limits<s8>::max() ),
|
|
|
|
|
std::max( static_cast<int>( std::numeric_limits<s8>::min() ), v ) ) );
|
|
|
|
|
}
|
2020-03-29 13:31:53 +02:00
|
|
|
u16 clip_u16( int v )
|
|
|
|
|
{
|
|
|
|
|
return static_cast<u16>(
|
|
|
|
|
std::max( 0, std::min( static_cast<int>( std::numeric_limits<u16>::max() ), v ) ) );
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos2d::operator==( const Pos2d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _x == other._x && _y == other._y;
|
2020-03-27 16:21:32 +01:00
|
|
|
}
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos2d::operator!=( const Pos2d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
|
|
|
|
return !( *this == other );
|
|
|
|
|
}
|
2020-03-29 21:00:44 +02:00
|
|
|
bool Pos2d::operator<( const Pos2d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _x < other._x && _y < other._y;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos2d::operator>( const Pos2d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _x > other._x && _y > other._y;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos2d::operator<=( const Pos2d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _x <= other._x && _y <= other._y;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos2d::operator>=( const Pos2d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _x >= other._x && _y >= other._y;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-03-29 11:37:00 +02:00
|
|
|
Pos2d& Pos2d::operator-=( const Vec2d& other )
|
|
|
|
|
{
|
2020-03-29 15:34:31 +02:00
|
|
|
int x = static_cast<int>( _x ) - other.x();
|
|
|
|
|
int y = static_cast<int>( _y ) - other.y();
|
2020-03-29 13:31:53 +02:00
|
|
|
_x = clip_u16( x );
|
|
|
|
|
_y = clip_u16( y );
|
2020-03-29 11:37:00 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
Pos2d& Pos2d::operator+=( const Vec2d& other )
|
|
|
|
|
{
|
2020-03-29 15:34:31 +02:00
|
|
|
int x = static_cast<int>( _x ) + other.x();
|
|
|
|
|
int y = static_cast<int>( _y ) + other.y();
|
2020-03-29 13:31:53 +02:00
|
|
|
_x = clip_u16( x );
|
|
|
|
|
_y = clip_u16( y );
|
2020-03-29 11:37:00 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
2020-03-29 13:31:53 +02:00
|
|
|
Vec2d operator-( const Pos2d& lhs, const Pos2d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
2020-03-29 15:34:31 +02:00
|
|
|
int x = static_cast<int>( lhs.x() ) - rhs.x();
|
|
|
|
|
int y = static_cast<int>( lhs.y() ) - rhs.y();
|
2020-05-31 15:22:01 +02:00
|
|
|
return Vec2d( Vec2d::clip( x ), Vec2d::clip( y ) );
|
2020-03-27 21:20:41 +01:00
|
|
|
}
|
2020-03-29 11:37:00 +02:00
|
|
|
Pos2d operator-( Pos2d lhs, const Vec2d& rhs )
|
|
|
|
|
{
|
|
|
|
|
lhs -= rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
|
|
|
|
Pos2d operator+( Pos2d lhs, const Vec2d& rhs )
|
|
|
|
|
{
|
|
|
|
|
lhs += rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-27 19:54:13 +01:00
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
u16 Pos2d::pol_distance( const Pos2d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-03-27 17:08:52 +01:00
|
|
|
int xd = std::abs( static_cast<int>( _x ) - other._x );
|
|
|
|
|
int yd = std::abs( static_cast<int>( _y ) - other._y );
|
|
|
|
|
return static_cast<u16>( std::max( xd, yd ) );
|
2020-03-27 16:21:32 +01:00
|
|
|
}
|
2020-04-12 22:24:54 +02:00
|
|
|
bool Pos2d::inRange( const Pos2d& other, u16 range ) const
|
|
|
|
|
{
|
|
|
|
|
return pol_distance( other ) <= range;
|
|
|
|
|
}
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-04-04 17:22:24 +02:00
|
|
|
void Pos2d::crop( const Realms::Realm* realm )
|
2020-03-29 18:29:24 +02:00
|
|
|
{
|
|
|
|
|
if ( realm == nullptr )
|
|
|
|
|
return;
|
2020-03-29 21:00:44 +02:00
|
|
|
if ( _x >= realm->width() )
|
|
|
|
|
_x = realm->width() - 1;
|
|
|
|
|
if ( _y >= realm->height() )
|
|
|
|
|
_y = realm->height() - 1;
|
2020-03-29 18:29:24 +02:00
|
|
|
}
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-04-12 00:17:30 +02:00
|
|
|
bool Pos2d::can_move_to( const Vec2d& displacement, const Realms::Realm* realm ) const
|
|
|
|
|
{
|
|
|
|
|
Vec2d vec_fromorigin = this->from_origin() + displacement;
|
|
|
|
|
|
|
|
|
|
if ( vec_fromorigin.x() < 0 && vec_fromorigin.y() < 0 )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if ( realm == nullptr ||
|
|
|
|
|
( vec_fromorigin.x() < realm->width() && vec_fromorigin.y() < realm->height() ) )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-12 22:24:54 +02:00
|
|
|
UFACING Pos2d::direction_toward( const Pos2d& dst ) const
|
|
|
|
|
{
|
|
|
|
|
if ( x() < dst.x() ) // East to target
|
|
|
|
|
{
|
|
|
|
|
if ( y() < dst.y() )
|
|
|
|
|
return FACING_SE;
|
|
|
|
|
else if ( y() == dst.y() )
|
|
|
|
|
return FACING_E;
|
|
|
|
|
else /* y() > dst.y() */
|
|
|
|
|
return FACING_NE;
|
|
|
|
|
}
|
|
|
|
|
else if ( x() == dst.x() )
|
|
|
|
|
{
|
|
|
|
|
if ( y() < dst.y() )
|
|
|
|
|
return FACING_S;
|
|
|
|
|
else if ( y() > dst.y() )
|
|
|
|
|
return FACING_N;
|
|
|
|
|
}
|
|
|
|
|
else /* x() > dst.x() */ // West to target
|
|
|
|
|
{
|
|
|
|
|
if ( y() < dst.y() )
|
|
|
|
|
return FACING_SW;
|
|
|
|
|
else if ( y() == dst.y() )
|
|
|
|
|
return FACING_W;
|
|
|
|
|
else /* y() > dst.y() */
|
|
|
|
|
return FACING_NW;
|
|
|
|
|
}
|
|
|
|
|
return FACING_N;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UFACING Pos2d::direction_away( const Pos2d& dst ) const
|
|
|
|
|
{
|
|
|
|
|
UFACING toward = direction_toward( dst );
|
|
|
|
|
return away_cvt[static_cast<int>( toward )];
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 10:18:06 +02:00
|
|
|
void Pos2d::update_min( const Pos2d& v )
|
|
|
|
|
{
|
|
|
|
|
if ( v._x < _x )
|
|
|
|
|
_x = v._x;
|
|
|
|
|
if ( v._y < _y )
|
|
|
|
|
_y = v._y;
|
|
|
|
|
}
|
|
|
|
|
void Pos2d::update_max( const Pos2d& v )
|
|
|
|
|
{
|
|
|
|
|
if ( v._x > _x )
|
|
|
|
|
_x = v._x;
|
|
|
|
|
if ( v._y > _y )
|
|
|
|
|
_y = v._y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos3d::operator==( const Pos3d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _xy == other._xy && _z == other._z;
|
2020-03-27 16:21:32 +01:00
|
|
|
}
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos3d::operator!=( const Pos3d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
|
|
|
|
return !( *this == other );
|
|
|
|
|
}
|
2020-03-29 21:00:44 +02:00
|
|
|
bool Pos3d::operator<( const Pos3d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _xy < other._xy && _z < other._z;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos3d::operator>( const Pos3d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _xy > other._xy && _z > other._z;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos3d::operator<=( const Pos3d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _xy <= other._xy && _z <= other._z;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos3d::operator>=( const Pos3d& other ) const
|
|
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _xy >= other._xy && _z >= other._z;
|
2020-03-29 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
bool Pos3d::operator==( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy == other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos3d::operator!=( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy != other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos3d::operator<( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy < other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos3d::operator>( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy > other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos3d::operator<=( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy <= other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos3d::operator>=( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy >= other;
|
|
|
|
|
}
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-03-29 11:37:00 +02:00
|
|
|
Pos3d& Pos3d::operator-=( const Vec2d& other )
|
|
|
|
|
{
|
|
|
|
|
_xy -= other;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
Pos3d& Pos3d::operator+=( const Vec2d& other )
|
|
|
|
|
{
|
|
|
|
|
_xy += other;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2020-03-31 20:47:18 +02:00
|
|
|
Pos3d& Pos3d::operator-=( const Vec3d& other )
|
|
|
|
|
{
|
|
|
|
|
_xy -= other.xy();
|
|
|
|
|
int z = static_cast<int>( _z ) - other.z();
|
|
|
|
|
_z = clip_s8( z );
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
Pos3d& Pos3d::operator+=( const Vec3d& other )
|
|
|
|
|
{
|
|
|
|
|
_xy += other.xy();
|
|
|
|
|
int z = static_cast<int>( _z ) + other.z();
|
|
|
|
|
_z = clip_s8( z );
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2020-03-27 19:54:13 +01:00
|
|
|
|
2020-03-29 13:31:53 +02:00
|
|
|
Pos3d operator-( Pos3d lhs, const Vec2d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
|
|
|
|
lhs -= rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-29 13:31:53 +02:00
|
|
|
Pos3d operator+( Pos3d lhs, const Vec2d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
|
|
|
|
lhs += rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-31 20:47:18 +02:00
|
|
|
Pos3d operator-( Pos3d lhs, const Vec3d& rhs )
|
|
|
|
|
{
|
|
|
|
|
lhs -= rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
|
|
|
|
Pos3d operator+( Pos3d lhs, const Vec3d& rhs )
|
|
|
|
|
{
|
|
|
|
|
lhs += rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-29 13:31:53 +02:00
|
|
|
Vec2d operator-( const Pos3d& lhs, const Pos2d& rhs )
|
2020-03-29 11:37:00 +02:00
|
|
|
{
|
2020-03-29 18:29:24 +02:00
|
|
|
return lhs.xy() - rhs;
|
2020-03-29 11:37:00 +02:00
|
|
|
}
|
2020-04-04 17:22:24 +02:00
|
|
|
Vec2d operator-( const Pos2d& lhs, const Pos3d& rhs )
|
|
|
|
|
{
|
|
|
|
|
return lhs - rhs.xy();
|
|
|
|
|
}
|
2020-03-31 20:47:18 +02:00
|
|
|
Vec3d operator-( const Pos3d& lhs, const Pos3d& rhs )
|
2020-03-29 11:37:00 +02:00
|
|
|
{
|
2020-03-31 20:47:18 +02:00
|
|
|
Vec2d xy = lhs.xy() - rhs.xy();
|
|
|
|
|
int z = static_cast<int>( lhs.z() ) - rhs.z();
|
2020-05-31 15:22:01 +02:00
|
|
|
return Vec3d( xy, Vec2d::clip( z ) );
|
2020-03-29 11:37:00 +02:00
|
|
|
}
|
2020-03-27 21:20:41 +01:00
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
u16 Pos3d::pol_distance( const Pos3d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
|
|
|
|
return _xy.pol_distance( other._xy );
|
|
|
|
|
}
|
2020-04-12 11:34:08 +02:00
|
|
|
bool Pos3d::inRange( const Pos3d& other, u16 range ) const
|
|
|
|
|
{
|
2020-04-12 22:24:54 +02:00
|
|
|
return _xy.inRange( other._xy, range );
|
|
|
|
|
}
|
|
|
|
|
bool Pos3d::inRange( const Pos2d& other, u16 range ) const
|
|
|
|
|
{
|
|
|
|
|
return _xy.inRange( other, range );
|
2020-04-12 11:34:08 +02:00
|
|
|
}
|
2020-04-04 17:22:24 +02:00
|
|
|
void Pos3d::crop( const Realms::Realm* realm )
|
2020-03-27 19:54:13 +01:00
|
|
|
{
|
2020-03-29 18:29:24 +02:00
|
|
|
_xy.crop( realm );
|
2020-03-27 19:54:13 +01:00
|
|
|
}
|
2020-03-29 18:29:24 +02:00
|
|
|
|
2020-06-07 10:18:06 +02:00
|
|
|
void Pos3d::update_min( const Pos3d& v )
|
|
|
|
|
{
|
|
|
|
|
_xy.update_min( v.xy() );
|
|
|
|
|
if ( v._z < _z )
|
|
|
|
|
_z = v._z;
|
|
|
|
|
}
|
|
|
|
|
void Pos3d::update_max( const Pos3d& v )
|
|
|
|
|
{
|
|
|
|
|
_xy.update_max( v.xy() );
|
|
|
|
|
if ( v._z > _z )
|
|
|
|
|
_z = v._z;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 18:29:24 +02:00
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
u16 Pos4d::cropX( u16 x ) const
|
2020-03-27 22:53:24 +01:00
|
|
|
{
|
2020-03-29 15:34:31 +02:00
|
|
|
if ( _realm != nullptr && x >= _realm->width() )
|
2020-03-27 22:53:24 +01:00
|
|
|
return _realm->width() - 1;
|
|
|
|
|
return x;
|
|
|
|
|
}
|
2020-03-28 14:05:32 +01:00
|
|
|
u16 Pos4d::cropY( u16 y ) const
|
2020-03-27 22:53:24 +01:00
|
|
|
{
|
2020-03-29 15:34:31 +02:00
|
|
|
if ( _realm != nullptr && y >= _realm->height() )
|
2020-03-27 22:53:24 +01:00
|
|
|
return _realm->height() - 1;
|
|
|
|
|
return y;
|
|
|
|
|
}
|
2020-03-27 19:54:13 +01:00
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos4d::operator==( const Pos4d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-04-11 14:09:25 +02:00
|
|
|
return _xyz == other._xyz && _realm == other._realm;
|
2020-03-27 16:21:32 +01:00
|
|
|
}
|
2020-03-29 21:00:44 +02:00
|
|
|
bool Pos4d::operator!=( const Pos4d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return !( *this == other );
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator<( const Pos4d& other ) const
|
|
|
|
|
{
|
|
|
|
|
if ( _realm != other._realm )
|
|
|
|
|
return false;
|
|
|
|
|
return _xyz < other._xyz;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator>( const Pos4d& other ) const
|
|
|
|
|
{
|
|
|
|
|
if ( _realm != other._realm )
|
|
|
|
|
return false;
|
|
|
|
|
return _xyz > other._xyz;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator<=( const Pos4d& other ) const
|
|
|
|
|
{
|
|
|
|
|
if ( _realm != other._realm )
|
|
|
|
|
return false;
|
|
|
|
|
return _xyz <= other._xyz;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator>=( const Pos4d& other ) const
|
|
|
|
|
{
|
|
|
|
|
if ( _realm != other._realm )
|
|
|
|
|
return false;
|
|
|
|
|
return _xyz >= other._xyz;
|
|
|
|
|
}
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos4d::operator==( const Pos3d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
|
|
|
|
return _xyz == other;
|
|
|
|
|
}
|
2020-03-29 21:00:44 +02:00
|
|
|
bool Pos4d::operator!=( const Pos3d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
|
|
|
|
return !( *this == other );
|
|
|
|
|
}
|
2020-03-29 21:00:44 +02:00
|
|
|
bool Pos4d::operator<( const Pos3d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz < other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator>( const Pos3d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz > other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator<=( const Pos3d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz <= other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator>=( const Pos3d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz >= other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator==( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz.xy() == other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator!=( const Pos2d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
|
|
|
|
return !( *this == other );
|
|
|
|
|
}
|
2020-03-29 21:00:44 +02:00
|
|
|
bool Pos4d::operator<( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz.xy() < other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator>( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz.xy() > other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator<=( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz.xy() <= other;
|
|
|
|
|
}
|
|
|
|
|
bool Pos4d::operator>=( const Pos2d& other ) const
|
|
|
|
|
{
|
|
|
|
|
return _xyz.xy() >= other;
|
|
|
|
|
}
|
2020-03-27 16:21:32 +01:00
|
|
|
|
2020-03-29 11:37:00 +02:00
|
|
|
Pos4d& Pos4d::operator-=( const Vec2d& other )
|
|
|
|
|
{
|
|
|
|
|
_xyz -= other;
|
2020-03-29 18:29:24 +02:00
|
|
|
_xyz.crop( _realm );
|
2020-03-29 11:37:00 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
Pos4d& Pos4d::operator+=( const Vec2d& other )
|
|
|
|
|
{
|
|
|
|
|
_xyz += other;
|
2020-03-29 18:29:24 +02:00
|
|
|
_xyz.crop( _realm );
|
2020-03-29 11:37:00 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
2020-03-31 20:47:18 +02:00
|
|
|
Pos4d& Pos4d::operator-=( const Vec3d& other )
|
|
|
|
|
{
|
|
|
|
|
_xyz -= other;
|
|
|
|
|
_xyz.crop( _realm );
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
Pos4d& Pos4d::operator+=( const Vec3d& other )
|
|
|
|
|
{
|
|
|
|
|
_xyz += other;
|
|
|
|
|
_xyz.crop( _realm );
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2020-03-27 20:56:28 +01:00
|
|
|
|
2020-03-29 13:31:53 +02:00
|
|
|
Pos4d operator-( Pos4d lhs, const Vec2d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
|
|
|
|
lhs -= rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-29 13:31:53 +02:00
|
|
|
Pos4d operator+( Pos4d lhs, const Vec2d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
|
|
|
|
lhs += rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-31 20:47:18 +02:00
|
|
|
Pos4d operator-( Pos4d lhs, const Vec3d& rhs )
|
|
|
|
|
{
|
|
|
|
|
lhs -= rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
|
|
|
|
Pos4d operator+( Pos4d lhs, const Vec3d& rhs )
|
|
|
|
|
{
|
|
|
|
|
lhs += rhs;
|
|
|
|
|
return lhs;
|
|
|
|
|
}
|
2020-03-29 13:31:53 +02:00
|
|
|
Vec2d operator-( const Pos4d& lhs, const Pos2d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
2020-03-29 18:29:24 +02:00
|
|
|
return lhs.xyz() - rhs;
|
2020-03-27 21:20:41 +01:00
|
|
|
}
|
2020-04-04 17:22:24 +02:00
|
|
|
Vec2d operator-( const Pos2d& lhs, const Pos4d& rhs )
|
|
|
|
|
{
|
|
|
|
|
return lhs - rhs.xyz();
|
|
|
|
|
}
|
2020-03-31 20:47:18 +02:00
|
|
|
Vec3d operator-( const Pos4d& lhs, const Pos3d& rhs )
|
2020-03-27 21:20:41 +01:00
|
|
|
{
|
2020-03-29 18:29:24 +02:00
|
|
|
return lhs.xyz() - rhs;
|
2020-03-27 21:20:41 +01:00
|
|
|
}
|
2020-04-04 17:22:24 +02:00
|
|
|
Vec3d operator-( const Pos3d& lhs, const Pos4d& rhs )
|
|
|
|
|
{
|
|
|
|
|
return lhs - rhs.xyz();
|
|
|
|
|
}
|
2020-04-10 18:40:17 +02:00
|
|
|
/*Vec3d operator-( const Pos4d& lhs, const Pos4d& rhs )
|
2020-03-29 11:37:00 +02:00
|
|
|
{
|
2020-03-29 18:29:24 +02:00
|
|
|
return lhs.xyz() - rhs.xyz();
|
2020-04-10 18:40:17 +02:00
|
|
|
}*/
|
2020-03-27 21:20:41 +01:00
|
|
|
|
2020-04-09 20:29:32 +02:00
|
|
|
Pos4d Pos4d::move( UFACING dir ) const
|
2020-03-27 17:08:52 +01:00
|
|
|
{
|
2020-04-09 20:29:32 +02:00
|
|
|
return *this + move_delta[dir];
|
2020-03-27 17:08:52 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-28 14:05:32 +01:00
|
|
|
u16 Pos4d::pol_distance( const Pos4d& other ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-03-27 17:08:52 +01:00
|
|
|
if ( _realm != other._realm )
|
|
|
|
|
return std::numeric_limits<u16>::max();
|
2020-03-27 16:21:32 +01:00
|
|
|
return _xyz.pol_distance( other._xyz );
|
|
|
|
|
}
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos4d::inRange( const Pos4d& other, u16 range ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-04-12 22:24:54 +02:00
|
|
|
return _realm == other._realm && _xyz.inRange( other._xyz, range );
|
2020-03-27 16:21:32 +01:00
|
|
|
}
|
2020-03-28 14:05:32 +01:00
|
|
|
bool Pos4d::inRange( const Pos3d& other, u16 range ) const
|
2020-03-27 16:21:32 +01:00
|
|
|
{
|
2020-04-12 22:24:54 +02:00
|
|
|
return _xyz.inRange( other, range );
|
2020-03-27 16:21:32 +01:00
|
|
|
}
|
2020-04-12 22:24:54 +02:00
|
|
|
bool Pos4d::inRange( const Pos2d& other, u16 range ) const
|
2020-04-09 20:29:32 +02:00
|
|
|
{
|
2020-04-12 22:24:54 +02:00
|
|
|
return _xyz.inRange( other, range );
|
2020-04-09 20:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-27 16:21:32 +01:00
|
|
|
} // namespace Core
|
|
|
|
|
} // namespace Pol
|