$treeview $search $mathjax
Stratagus  2.2.6
$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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include "stratagus.h"
#include "map.h"
#include "video.h"
#include "sound.h"
#include "unitsound.h"
#include "unittype.h"
#include "actions.h"
#include "player.h"
#include "missile.h"
#include "unit.h"
#include "interface.h"
#include "tileset.h"
#include "pathfinder.h"

Classes

struct  BestTargetFinder
struct  BestRangeTargetFinder
struct  BestRangeTargetFinder::FillBadGood
struct  CompareUnitDistance

unit_find.cpp - The find/select for units.

#define PRIORITY_FACTOR   0x00010000
#define HEALTH_FACTOR   0x00000001
#define DISTANCE_FACTOR   0x00100000
#define INRANGE_FACTOR   0x00010000
#define INRANGE_BONUS   0x01000000
#define CANATTACK_BONUS   0x00100000
int FindUnitsByType (const CUnitType &type, CUnit **table)
 Find all units of this type.
int FindPlayerUnitsByType (const CPlayer &player, const CUnitType &type, 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, int x1, int y1, int x2, int y2)
 Return possible attack target on that map area.
CUnitResourceOnMap (const Vec2i &pos, int resource, bool mine_on_top)
CUnitResourceDepositOnMap (const Vec2i &pos, int resource)
CUnitAutoAttackUnitsInDistance (const CUnit &unit, int range, CUnitCache &autotargets)
CUnitAttackUnitsInDistance (const CUnit &unit, int range)
 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.

Define Documentation

#define CANATTACK_BONUS   0x00100000

#define DISTANCE_FACTOR   0x00100000

#define HEALTH_FACTOR   0x00000001

#define INRANGE_BONUS   0x01000000

#define INRANGE_FACTOR   0x00010000

#define PRIORITY_FACTOR   0x00010000


Function Documentation

CUnit* AttackUnitsInDistance ( const CUnit unit,
int  range 
)

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.
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* AutoAttackUnitsInDistance ( const CUnit unit,
int  range,
CUnitCache autotargets 
)

AutoAttack 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.
autotargets Know enemy targets to chose in range.
Returns:
Unit to be attacked.

int FindPlayerUnitsByType ( const CPlayer player,
const CUnitType type,
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
Returns:
Returns the number of units found.

int FindUnitsByType ( const CUnitType type,
CUnit **  table 
)

Find all units of this type.

Find all units of type.

Parameters:
type type of unit requested
table table in which we have to store the units
Returns:
Returns the number of units found.

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

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

CUnit* TargetOnMap ( const CUnit source,
int  x1,
int  y1,
int  x2,
int  y2 
)

Return possible attack target on that map area.

Choose target on map area.

Parameters:
source Unit which want to attack.
x1 X position on map, tile-based.
y1 Y position on map, tile-based.
x2 X position on map, tile-based.
y2 Y position on map, tile-based.
Returns:
Returns ideal target on map tile.

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-2011 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.