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

src/unit/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 "unit.h"
#include "unit_manager.h"
#include "unittype.h"

Classes

class  NoFilter
class  TerrainFinder
class  BestDepotFinder< NEARLOCATION >
class  CResourceFinder
class  ResourceUnitFinder
struct  ResourceUnitFinder::ResourceUnitFinder_Cost
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)
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.
CUnitFindDeposit (const CUnit &unit, int range, int resource)
 Find nearest deposit.
CUnitFindIdleWorker (const CPlayer &player, const CUnit *last)
 Find the next idle worker.
void FindUnitsByType (const CUnitType &type, std::vector< CUnit * > &units)
void FindPlayerUnitsByType (const CPlayer &player, const CUnitType &type, std::vector< CUnit * > &table)
 Find all units of this type of the player.
CUnitUnitOnMapTile (const unsigned int index, unsigned int type)
CUnitUnitOnMapTile (const Vec2i &pos, unsigned int type)
CUnitTargetOnMap (const CUnit &source, const Vec2i &pos1, const Vec2i &pos2)
CUnitResourceOnMap (const Vec2i &pos, int resource, bool mine_on_top)
CUnitResourceDepositOnMap (const Vec2i &pos, int resource)
CUnitAttackUnitsInDistance (const CUnit &unit, int range, bool onlyBuildings)
 Find best enemy in numeric range to attack.
CUnitAttackUnitsInRange (const CUnit &unit)
 Find best enemy in attack range to attack.
CUnitAttackUnitsInReactRange (const CUnit &unit)
 Find best enemy in reaction range to attack.

Function Documentation

CUnit* AttackUnitsInDistance ( const CUnit unit,
int  range,
bool  onlyBuildings 
)

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:
unit Find in distance for this unit.
range Distance range to look.
onlyBuildings Search only buildings (useful when attacking with AI force)
Returns:
Unit to be attacked.

CUnit* AttackUnitsInRange ( const CUnit unit  ) 

Find best enemy in attack range to attack.

Attack units in attack range.

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

CUnit* AttackUnitsInReactRange ( const CUnit unit  ) 

Find best enemy in reaction range to attack.

Attack units in reaction range.

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

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

Find nearest deposit.

Find deposit. This will find a deposit for a resource

Parameters:
unit The unit that wants to find a resource.
x Closest to x
y Closest to y
range Maximum distance to the deposit.
resource Resource to find deposit from.
Note:
This will return a reachable allied depot.
Returns:
NULL or deposit unit

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

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

Find the next idle worker.

Find the next idle worker

Parameters:
player Player's units to search through
last Previous idle worker selected
Returns:
NULL or next idle worker

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

Find all units of this type of the player.

Find all units of type.

Parameters:
player we're looking for the units of this player
type type of unit requested
table table in which we have to store the units

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

Find the closest piece of terrain with the given flags.

Parameters:
movemask The movement mask to reach that location.
resmask Result tile mask.
range Maximum distance for the search.
player Only search fields explored by player
startPos Map start position for the search.
terrainPos OUT: 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.

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

Find all units of type.

Parameters:
type type of unit requested
units array in which we have to store the units

CUnit* ResourceDepositOnMap ( const Vec2i pos,
int  resource 
)

Resource deposit on map tile

Parameters:
pos position on map, tile-based.
resource resource type.
Returns:
Returns the deposit if found, or NULL.

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

Resource on map tile

Parameters:
pos position on map, tile-based.
resource resource type.
mine_on_top return mine or mining area.
Returns:
Returns the deposit if found, or NULL.

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

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

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

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

Choose target on map area.

Parameters:
source Unit which want to attack.
pos1 position on map, tile-based.
pos2 position on map, tile-based.
Returns:
Returns ideal target on map tile.

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

Find resource.

Find Resource.

Parameters:
unit The unit that wants to find a resource.
startUnit Find closest unit from this location
range Maximum distance to the resource.
resource The 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

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

Unit on map tile.

Parameters:
pos position on map, tile-based.
type UnitTypeType, (unsigned)-1 for any type.
Returns:
Returns first found unit on tile.

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

Unit on map tile.

Parameters:
index flat index position on map, tile-based.
type UnitTypeType, (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.