2014-11-13 12:17:06 -05:00
|
|
|
#pragma once
|
|
|
|
#include <BWAPI/Position.h>
|
|
|
|
|
|
|
|
namespace BWAPI
|
|
|
|
{
|
|
|
|
class UnitInterface;
|
|
|
|
typedef UnitInterface *Unit;
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>PositionOrUnit is a class that is either a Position <b>or</b> a Unit.</summary>
|
|
|
|
/// The purpose of this class is to reduce interface overhead by combining two commonly passed
|
|
|
|
/// values into one, and to allow more function overloads with less effort.
|
2014-11-13 12:17:06 -05:00
|
|
|
class PositionOrUnit
|
|
|
|
{
|
|
|
|
public:
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>Unit constructor. Assigns this class to contain a unit.</summary>
|
|
|
|
///
|
|
|
|
/// <param name="unit">
|
|
|
|
/// The unit to assign to this class.
|
|
|
|
/// </param>
|
2014-11-13 12:17:06 -05:00
|
|
|
PositionOrUnit(Unit unit = nullptr);
|
2016-02-28 08:49:15 -05:00
|
|
|
|
|
|
|
/// <summary>Position constructor. Assigns this class to contain a position.</summary>
|
|
|
|
///
|
|
|
|
/// <param name="pos">
|
|
|
|
/// The position to assign to this class.
|
|
|
|
/// </param>
|
2014-11-13 12:17:06 -05:00
|
|
|
PositionOrUnit(Position pos);
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>Unit assignment operator. Assigns a unit to this class.</summary>
|
2014-11-13 12:17:06 -05:00
|
|
|
PositionOrUnit &operator =(Unit pUnit);
|
2016-02-28 08:49:15 -05:00
|
|
|
|
|
|
|
/// <summary>Position assignment operator. Assigns a position to this class.</summary>
|
2014-11-13 12:17:06 -05:00
|
|
|
PositionOrUnit &operator =(Position pos);
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>Indicates if a Unit is currently held in this class.</summary>
|
|
|
|
///
|
|
|
|
/// @returns true if the value contained within this class is considered a unit, and false if
|
|
|
|
/// it is a position.
|
2014-11-13 12:17:06 -05:00
|
|
|
bool isUnit() const;
|
2016-02-28 08:49:15 -05:00
|
|
|
|
|
|
|
/// <summary>Retrieves the Unit attached to this class, if there is one.</summary>
|
|
|
|
///
|
|
|
|
/// @returns The Unit that was assigned to this class.
|
|
|
|
/// @retval nullptr If this class does not contain a unit, or if nullptr was assigned to
|
|
|
|
/// this class as a Unit.
|
2014-11-13 12:17:06 -05:00
|
|
|
Unit getUnit() const;
|
|
|
|
|
2016-02-28 08:49:15 -05:00
|
|
|
/// <summary>Indicates if a Position is currently held in this class.</summary>
|
|
|
|
///
|
|
|
|
/// @returns true if the value contained within this class is considered a position, and false
|
|
|
|
/// if it is a unit.
|
2014-11-13 12:17:06 -05:00
|
|
|
bool isPosition() const;
|
2016-02-28 08:49:15 -05:00
|
|
|
|
|
|
|
/// <summary>Retrieves the position if it was assigned to this class, otherwise it will
|
|
|
|
/// retrieve the position of the unit contained within this class if there is one.</summary>
|
|
|
|
///
|
|
|
|
/// @returns Position that was stored if there is one. If not, then the position of the unit
|
|
|
|
/// will be used instead.
|
|
|
|
/// @retval Positions::None if a nullptr Unit was assigned to this class.
|
2014-11-13 12:17:06 -05:00
|
|
|
Position getPosition() const;
|
2016-02-28 08:49:15 -05:00
|
|
|
|
2014-11-13 12:17:06 -05:00
|
|
|
private:
|
2016-02-28 08:49:15 -05:00
|
|
|
/// @cond HIDDEN
|
2014-11-13 12:17:06 -05:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
} position;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
Unit pUnit;
|
|
|
|
int y;
|
|
|
|
} unit;
|
|
|
|
};
|
2016-02-28 08:49:15 -05:00
|
|
|
/// @endcond
|
2014-11-13 12:17:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|