_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Classes
unit_find.h File Reference
#include "map.h"
#include "pathfinder.h"
#include "unit.h"
#include "unittype.h"

Go to the source code of this file.

Classes

class  CUnitFilter
 
class  NoFilter
 
class  HasSameTypeAs
 
class  HasSamePlayerAs
 
class  HasNotSamePlayerAs
 
class  IsAlliedWith
 
class  IsEnemyWith
 
class  HasSamePlayerAndTypeAs
 
class  IsNotTheSameUnitAs
 
class  IsBuildingType
 
class  IsAggresiveUnit
 
class  OutOfMinRange
 
class  NotPredicate< Pred >
 
class  AndPredicate< Pred1, Pred2 >
 
class  CUnitTypeFinder
 
class  UnitFinder
 

Functions

unit.h - The unit headerfile.
template<typename Pred >
NotPredicate< Pred > MakeNotPredicate (Pred pred)
 
template<typename Pred1 , typename Pred2 >
AndPredicate< Pred1, Pred2 > MakeAndPredicate (Pred1 pred1, Pred2 pred2)
 
void Select (const Vec2i &ltPos, const Vec2i &rbPos, std::vector< CUnit * > &units)
 
void SelectFixed (const Vec2i &ltPos, const Vec2i &rbPos, std::vector< CUnit * > &units)
 
void SelectAroundUnit (const CUnit &unit, int range, std::vector< CUnit * > &around)
 
template<int selectMax = 0, typename Pred >
void SelectFixed (const Vec2i &ltPos, const Vec2i &rbPos, std::vector< CUnit * > &units, Pred pred)
 
template<int selectMax = 0, typename Pred >
void Select (const Vec2i &ltPos, const Vec2i &rbPos, std::vector< CUnit * > &units, Pred pred)
 
template<int selectMax = 0, typename Pred >
void SelectAroundUnit (const CUnit &unit, int range, std::vector< CUnit * > &around, Pred pred)
 
template<typename Pred >
CUnitFindUnit_IfFixed (const Vec2i &ltPos, const Vec2i &rbPos, Pred pred)
 
template<typename Pred >
CUnitFindUnit_If (const Vec2i &ltPos, const Vec2i &rbPos, Pred pred)
 
CUnitUnitFindResource (const CUnit &unit, const CUnit &startUnit, int range, int resource, bool check_usage=false, const CUnit *deposit=NULL)
 Find resource. More...
 
CUnitFindDeposit (const CUnit &unit, int range, int resource)
 Find nearest deposit. More...
 
CUnitFindIdleWorker (const CPlayer &player, const CUnit *last)
 Find the next idle worker. More...
 
bool FindTerrainType (int movemask, int resmask, int range, const CPlayer &player, const Vec2i &startPos, Vec2i *pos)
 Find the neareast piece of terrain with specific flags. More...
 
void FindUnitsByType (const CUnitType &type, std::vector< CUnit * > &units, bool everybody=false)
 
void FindPlayerUnitsByType (const CPlayer &player, const CUnitType &type, std::vector< CUnit * > &units, bool ai_active=false)
 Find all units of this type of the player. More...
 
CUnitUnitOnMapTile (const Vec2i &pos, unsigned int type)
 Return any unit on that map tile. More...
 
CUnitTargetOnMap (const CUnit &unit, const Vec2i &pos1, const Vec2i &pos2)
 Return possible attack target on that map area. More...
 
CUnitResourceOnMap (const Vec2i &pos, int resource, bool mine_on_top=true)
 Return resource, if on map tile. More...
 
CUnitResourceDepositOnMap (const Vec2i &pos, int resource)
 Return resource deposit, if on map tile. More...
 
bool CheckObstaclesBetweenTiles (const Vec2i &unitPos, const Vec2i &goalPos, unsigned short flags, int *distance=NULL)
 Check map for obstacles in a line between 2 tiles. More...
 
CUnitAttackUnitsInDistance (const CUnit &unit, int range, CUnitFilter pred)
 Find best enemy in numeric range to attack. More...
 
CUnitAttackUnitsInDistance (const CUnit &unit, int range)
 
CUnitAttackUnitsInRange (const CUnit &unit, CUnitFilter pred)
 Find best enemy in attack range to attack. More...
 
CUnitAttackUnitsInRange (const CUnit &unit)
 
CUnitAttackUnitsInReactRange (const CUnit &unit, CUnitFilter pred)
 Find best enemy in reaction range to attack. More...
 
CUnitAttackUnitsInReactRange (const CUnit &unit)
 

Function Documentation

◆ AttackUnitsInDistance() [1/2]

CUnit* AttackUnitsInDistance ( const CUnit unit,
int  range 
)

◆ AttackUnitsInDistance() [2/2]

CUnit* AttackUnitsInDistance ( const CUnit unit,
int  range,
CUnitFilter  pred 
)

Find best enemy in numeric range to attack.

Attack units in distance.

If the unit can attack must be handled by caller. Choose the best target, that can be attacked.

Parameters
unitFind in distance for this unit.
rangeDistance range to look.
onlyBuildingsSearch only buildings (useful when attacking with AI force)
Returns
Unit to be attacked.

◆ AttackUnitsInRange() [1/2]

CUnit* AttackUnitsInRange ( const CUnit unit)

◆ AttackUnitsInRange() [2/2]

CUnit* AttackUnitsInRange ( const CUnit unit,
CUnitFilter  pred 
)

Find best enemy in attack range to attack.

Attack units in attack range.

Parameters
unitFind unit in attack range for this unit.
Returns
Pointer to unit which should be attacked.

◆ AttackUnitsInReactRange() [1/2]

CUnit* AttackUnitsInReactRange ( const CUnit unit)

◆ AttackUnitsInReactRange() [2/2]

CUnit* AttackUnitsInReactRange ( const CUnit unit,
CUnitFilter  pred 
)

Find best enemy in reaction range to attack.

Attack units in reaction range.

Parameters
unitFind unit in reaction range for this unit.
Returns
Pointer to unit which should be attacked.

◆ CheckObstaclesBetweenTiles()

bool CheckObstaclesBetweenTiles ( const Vec2i unitPos,
const Vec2i goalPos,
unsigned short  flags,
int *  distance 
)

Check map for obstacles in a line between 2 tiles.

Check map for obstacles in a line between 2 tiles

This function uses Bresenham's line algorithm

Parameters
unitFirst tile
goalSecond tile
flagsTerrain type to check
Returns
false, if an obstacle was found, true otherwise

◆ FindDeposit()

CUnit* FindDeposit ( const CUnit unit,
int  range,
int  resource 
)

Find nearest deposit.

Find deposit. This will find a deposit for a resource

Parameters
unitThe unit that wants to find a resource.
rangeMaximum distance to the deposit.
resourceResource to find deposit from.
Note
This will return a reachable allied depot.
Returns
NULL or deposit unit

◆ FindIdleWorker()

CUnit* FindIdleWorker ( const CPlayer player,
const CUnit last 
)

Find the next idle worker.

Find the next idle worker

Parameters
playerPlayer's units to search through
lastPrevious idle worker selected
Returns
NULL or next idle worker

◆ FindPlayerUnitsByType()

void FindPlayerUnitsByType ( const CPlayer player,
const CUnitType type,
std::vector< CUnit * > &  table,
bool  ai_active 
)

Find all units of this type of the player.

Find all units of type.

Parameters
playerwe're looking for the units of this player
typetype of unit requested
tabletable in which we have to store the units

◆ FindTerrainType()

bool FindTerrainType ( int  movemask,
int  resmask,
int  range,
const CPlayer player,
const Vec2i startPos,
Vec2i terrainPos 
)

Find the neareast piece of terrain with specific flags.

Find the closest piece of terrain with the given flags.

Parameters
movemaskThe movement mask to reach that location.
resmaskResult tile mask.
rangeMaximum distance for the search.
playerOnly search fields explored by player
startPosMap start position for the search.
terrainPosOUT: Map position of tile.
Note
Movement mask can be 0xFFFFFFFF to have no effect Range is not circular, but square. Player is ignored if nil(search the entire map)
Returns
True if wood was found.

◆ FindUnit_If()

template<typename Pred >
CUnit* FindUnit_If ( const Vec2i ltPos,
const Vec2i rbPos,
Pred  pred 
)

◆ FindUnit_IfFixed()

template<typename Pred >
CUnit* FindUnit_IfFixed ( const Vec2i ltPos,
const Vec2i rbPos,
Pred  pred 
)

◆ FindUnitsByType()

void FindUnitsByType ( const CUnitType type,
std::vector< CUnit * > &  units,
bool  everybody 
)

Find all units of type.

Parameters
typetype of unit requested
unitsarray in which we have to store the units
everybodyif true, include all units

◆ MakeAndPredicate()

template<typename Pred1 , typename Pred2 >
AndPredicate<Pred1, Pred2> MakeAndPredicate ( Pred1  pred1,
Pred2  pred2 
)

◆ MakeNotPredicate()

template<typename Pred >
NotPredicate<Pred> MakeNotPredicate ( Pred  pred)

◆ ResourceDepositOnMap()

CUnit* ResourceDepositOnMap ( const Vec2i pos,
int  resource 
)

Return resource deposit, if on map tile.

Resource deposit on map tile

Parameters
posposition on map, tile-based.
resourceresource type.
Returns
Returns the deposit if found, or NULL.

◆ ResourceOnMap()

CUnit* ResourceOnMap ( const Vec2i pos,
int  resource,
bool  mine_on_top 
)

Return resource, if on map tile.

Resource on map tile

Parameters
posposition on map, tile-based.
resourceresource type.
mine_on_topreturn mine or mining area.
Returns
Returns the deposit if found, or NULL.

◆ Select() [1/2]

void Select ( const Vec2i ltPos,
const Vec2i rbPos,
std::vector< CUnit * > &  units 
)

◆ Select() [2/2]

template<int selectMax = 0, typename Pred >
void Select ( const Vec2i ltPos,
const Vec2i rbPos,
std::vector< CUnit * > &  units,
Pred  pred 
)

◆ SelectAroundUnit() [1/2]

void SelectAroundUnit ( const CUnit unit,
int  range,
std::vector< CUnit * > &  around 
)

◆ SelectAroundUnit() [2/2]

template<int selectMax = 0, typename Pred >
void SelectAroundUnit ( const CUnit unit,
int  range,
std::vector< CUnit * > &  around,
Pred  pred 
)

◆ SelectFixed() [1/2]

void SelectFixed ( const Vec2i ltPos,
const Vec2i rbPos,
std::vector< CUnit * > &  units 
)

◆ SelectFixed() [2/2]

template<int selectMax = 0, typename Pred >
void SelectFixed ( const Vec2i ltPos,
const Vec2i rbPos,
std::vector< CUnit * > &  units,
Pred  pred 
)

◆ TargetOnMap()

CUnit* TargetOnMap ( const CUnit source,
const Vec2i pos1,
const Vec2i pos2 
)

Return possible attack target on that map area.

Choose target on map area.

Parameters
sourceUnit which want to attack.
pos1position on map, tile-based.
pos2position on map, tile-based.
Returns
Returns ideal target on map tile.

◆ UnitFindResource()

CUnit* UnitFindResource ( const CUnit unit,
const CUnit startUnit,
int  range,
int  resource,
bool  check_usage,
const CUnit deposit 
)

Find resource.

Find Resource.

Parameters
unitThe unit that wants to find a resource.
startUnitFind closest unit from this location
rangeMaximum distance to the resource.
resourceThe resource id.
Note
This will return an usable resource building that doesn't belong to the player or one of his allies.
Returns
NULL or resource unit

◆ UnitOnMapTile()

CUnit* UnitOnMapTile ( const Vec2i pos,
unsigned int  type 
)

Return any unit on that map tile.

Unit on map tile.

Parameters
posposition on map, tile-based.
typeUnitTypeType, (unsigned)-1 for any type.
Returns
Returns first found unit on tile.
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.