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

Classes
unit_find.cpp File Reference
#include <limits.h>
#include "stratagus.h"
#include "unit_find.h"
#include "actions.h"
#include "map.h"
#include "missile.h"
#include "pathfinder.h"
#include "player.h"
#include "spells.h"
#include "tileset.h"
#include "unit.h"
#include "unit_manager.h"
#include "unittype.h"

Classes

class  TerrainFinder
 
class  BestDepotFinder< NEARLOCATION >
 
class  CResourceFinder
 
class  ResourceUnitFinder
 
class  IsADepositForResource
 
class  BestTargetFinder
 
class  BestRangeTargetFinder
 
class  BestRangeTargetFinder::FillBadGood
 
struct  CompareUnitDistance
 

Functions

unit_find.cpp - The find/select for units.
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)
 
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. More...
 
CUnitFindDepositNearLoc (CPlayer &p, const Vec2i &pos, int range, int resource)
 
CUnitUnitFindResource (const CUnit &unit, const CUnit &startUnit, int range, int resource, bool check_usage, const CUnit *deposit)
 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...
 
void FindUnitsByType (const CUnitType &type, std::vector< CUnit * > &units, bool everybody)
 
void FindPlayerUnitsByType (const CPlayer &player, const CUnitType &type, std::vector< CUnit * > &table, bool ai_active)
 Find all units of this type of the player. More...
 
CUnitUnitOnMapTile (const unsigned int index, unsigned int type)
 
CUnitUnitOnMapTile (const Vec2i &pos, unsigned int type)
 Return any unit on that map tile. More...
 
CUnitTargetOnMap (const CUnit &source, 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)
 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)
 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

◆ FindDepositNearLoc()

CUnit* FindDepositNearLoc ( CPlayer p,
const Vec2i pos,
int  range,
int  resource 
)

◆ 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.

◆ 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

◆ 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()

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

◆ SelectAroundUnit()

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

◆ SelectFixed()

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

◆ 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() [1/2]

CUnit* UnitOnMapTile ( const unsigned int  index,
unsigned int  type 
)

Unit on map tile.

Parameters
indexflat index position on map, tile-based.
typeUnitTypeType, (unsigned)-1 for any type.
Returns
Returns first found unit on tile.

◆ UnitOnMapTile() [2/2]

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.