_________ __ __
/ _____// |_____________ _/ |______ ____ __ __ ______
\_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
/ \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \
/_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
\/ \/ \//_____/ \/
______________________ ______________________
T H E W A R B E G I N S
Stratagus - A free fantasy real time strategy game engine
Go to the documentation of this file.
31 #ifndef __UNIT_FIND_H__
32 #define __UNIT_FIND_H__
110 player(unit.Player), type(unit.Type)
113 player(&_player), type(&_type)
118 return (unit->
Player == player && unit->
Type == type);
132 const CUnit *forbidden;
158 template <
typename Pred>
168 template <
typename Pred>
171 template <
typename Pred1,
typename Pred2>
175 AndPredicate(Pred1 _pred1, Pred2 _pred2) : pred1(_pred1), pred2(_pred2) {}
182 template <
typename Pred1,
typename Pred2>
208 player(player), units(units), maxDist(maxDist), movemask(movemask), unitP(unitP) {}
214 const std::vector<CUnit *> &units;
220 void Select(
const Vec2i <Pos,
const Vec2i &rbPos, std::vector<CUnit *> &units);
224 template <
int selectMax = 0,
typename Pred>
230 units.reserve(selectMax << 1);
231 int max = selectMax || INT_MAX;
233 for (
Vec2i posIt = ltPos; posIt.
y != rbPos.
y + 1; ++posIt.y) {
234 for (posIt.x = ltPos.
x; posIt.x != rbPos.
x + 1; ++posIt.x) {
238 for (
size_t i = 0; i != cache.
size(); ++i) {
239 CUnit &unit = *cache[i];
241 if ((selectMax == 1 || unit.
CacheLock == 0) && pred(&unit)) {
242 if (selectMax == 1) {
243 units.push_back(&unit);
247 units.push_back(&unit);
256 for (
size_t i = 0; i != units.size(); ++i) {
257 units[i]->CacheLock = 0;
261 template <
int selectMax = 0,
typename Pred>
262 void Select(
const Vec2i <Pos,
const Vec2i &rbPos, std::vector<CUnit *> &units, Pred pred)
264 Vec2i minPos = ltPos;
265 Vec2i maxPos = rbPos;
268 SelectFixed<selectMax>(minPos, maxPos, units, pred);
271 template <
int selectMax = 0,
typename Pred>
274 const Vec2i offset(range, range);
277 Select<selectMax>(unit.
tilePos - offset,
278 unit.
tilePos + typeSize + offset, around,
282 template <
typename Pred>
288 for (
Vec2i posIt = ltPos; posIt.
y != rbPos.
y + 1; ++posIt.y) {
289 for (posIt.x = ltPos.
x; posIt.x != rbPos.
x + 1; ++posIt.x) {
294 if (it != cache.
end()) {
302 template <
typename Pred>
305 Vec2i minPos = ltPos;
306 Vec2i maxPos = rbPos;
314 int resource,
bool check_usage =
false,
const CUnit *deposit = NULL);
355 #endif // !__UNIT_FIND_H__
Diplomacy states for CommandDiplomacy.
Definition: player.h:83
bool operator()(const CUnit *unit) const
Definition: unit_find.h:101
const_iterator end() const
Definition: unit_cache.h:65
void FindUnitsByType(const CUnitType &type, std::vector< CUnit * > &units, bool everybody=false)
Definition: unit_find.cpp:516
OutOfMinRange(const int range, const Vec2i pos)
Definition: unit_find.h:150
Definition: unit_find.h:204
bool operator()(const CUnit *unit) const
Definition: unit_find.h:116
CUnit * AttackUnitsInDistance(const CUnit &unit, int range, CUnitFilter pred)
Find best enemy in numeric range to attack.
Definition: unit_find.cpp:1147
bool operator()(const CUnit *unit) const
Definition: unit_find.h:138
NotPredicate< Pred > MakeNotPredicate(Pred pred)
Definition: unit_find.h:169
Definition: unit_cache.h:50
void SelectFixed(const Vec2i <Pos, const Vec2i &rbPos, std::vector< CUnit * > &units)
Definition: unit_find.cpp:62
std::vector< BoolFlags > BoolFlag
Definition: unittype.h:646
unsigned CacheLock
Unit is on board a transporter.
Definition: unit.h:380
@ VANISHES_INDEX
Can attack from transporter.
Definition: unittype.h:155
Definition: unit_find.h:126
bool operator()(const CUnit *unit) const
Definition: unit_find.h:144
Definition: unit_find.h:55
IsEnemyWith(const CPlayer &_player)
Definition: unit_find.h:100
Definition: unit_find.h:141
CUnitTypeFinder(const UnitTypeType t)
Definition: unit_find.h:190
T y
Definition: vec2i.h:43
IsNotTheSameUnitAs(const CUnit &unit)
Definition: unit_find.h:129
Definition: unit_find.h:147
Definition: unit_find.h:97
bool CheckObstaclesBetweenTiles(const Vec2i &unitPos, const Vec2i &goalPos, unsigned short flags, int *distance=NULL)
Check map for obstacles in a line between 2 tiles.
Definition: unit_find.cpp:1103
VisitResult
Definition: pathfinder.h:127
HasSameTypeAs(const CUnitType &_type)
Definition: unit_find.h:64
CUnit * FindUnit_IfFixed(const Vec2i <Pos, const Vec2i &rbPos, Pred pred)
Definition: unit_find.h:283
Definition: unittype.h:508
CUnit * UnitOnMapTile(const Vec2i &pos, unsigned int type)
Return any unit on that map tile.
Definition: unit_find.cpp:588
CUnit * UnitFindResource(const CUnit &unit, const CUnit &startUnit, int range, int resource, bool check_usage=false, const CUnit *deposit=NULL)
Find resource.
Definition: unit_find.cpp:423
AndPredicate(Pred1 _pred1, Pred2 _pred2)
Definition: unit_find.h:175
bool IsAllied(const CPlayer &player) const
Definition: unit.cpp:3401
Definition: unit_find.h:49
bool operator()(const CUnit *const unit) const
Definition: unit_find.h:191
NotPredicate(Pred _pred)
Definition: unit_find.h:162
Definition: unit_find.h:70
Vec2i tilePos
Resource still.
Definition: unit.h:341
UnitFinder(const CPlayer &player, const std::vector< CUnit * > &units, int maxDist, int movemask, CUnit **unitP)
Definition: unit_find.h:207
UnitTypeType
Definition: unittype.h:362
CMapField * Field(unsigned int index) const
Definition: map.h:171
HasSamePlayerAndTypeAs(const CUnit &unit)
Definition: unit_find.h:109
bool IsEnemy(const CPlayer &player) const
Definition: unit.cpp:3381
CUnit * FindIdleWorker(const CPlayer &player, const CUnit *last)
Find the next idle worker.
Definition: unit_find.cpp:481
bool operator()(const CUnit *unit) const
Definition: unit_find.h:74
bool operator()(const CUnit *) const
Definition: unit_find.h:58
CUnit * FindDeposit(const CUnit &unit, int range, int resource)
Find nearest deposit.
Definition: unit_find.cpp:456
bool operator()(const CUnit *unit) const
Definition: unit_find.h:130
Definition: unit_find.h:135
void Select(const Vec2i <Pos, const Vec2i &rbPos, std::vector< CUnit * > &units)
Definition: unit_find.cpp:57
Definition: unit_find.h:88
std::vector< CUnit * >::const_iterator const_iterator
Definition: unit_cache.h:54
CUnitCache UnitCache
HP for walls/Wood Regeneration, value of stored resource for forest or harvestable terrain.
Definition: tile.h:253
Definition: unit_find.h:61
Definition: pathfinder.h:134
bool IsAgressive() const
Definition: unit.h:187
unsigned Building
Death explosion animated.
Definition: unittype.h:631
CPlayer * Player
Pointer to unit-type (peon,...)
Definition: unit.h:346
CUnit * TargetOnMap(const CUnit &unit, const Vec2i &pos1, const Vec2i &pos2)
Return possible attack target on that map area.
Definition: unit_find.cpp:602
size_t size() const
Definition: unit_cache.h:59
Definition: unit_find.h:106
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.
Definition: unit_find.cpp:534
int TileHeight
Tile size on map width.
Definition: unittype.h:585
void SelectAroundUnit(const CUnit &unit, int range, std::vector< CUnit * > &around)
Definition: unit_find.cpp:67
IsAlliedWith(const CPlayer &_player)
Definition: unit_find.h:91
int MapDistanceTo(const CUnit &dst) const
Definition: unit.h:286
Definition: unit_find.h:79
HasSamePlayerAs(const CPlayer &_player)
Definition: unit_find.h:73
Definition: unit_find.h:159
bool operator()(const CUnit *unit) const
Definition: unit_find.h:92
VisitResult Visit(TerrainTraversal &terrainTraversal, const Vec2i &pos, const Vec2i &from)
Definition: unit_find.cpp:86
AndPredicate< Pred1, Pred2 > MakeAndPredicate(Pred1 pred1, Pred2 pred2)
Definition: unit_find.h:183
const CUnitType * Type
Map position as flat index offset (x + y * w)
Definition: unit.h:345
HasNotSamePlayerAs(const CPlayer &_player)
Definition: unit_find.h:82
bool operator()(const CUnit *unit) const
Definition: unit_find.h:151
Definition: unit_find.h:187
#define Assert(cond)
Definition: stratagus.h:142
CMapInfo Info
Definition: map.h:276
bool IsPointOnMap(int x, int y) const
Definition: map.h:125
bool operator()(const CUnit *unit) const
Definition: unit_find.h:83
Definition: unit_find.h:172
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.
Definition: unit_find.cpp:162
T x
Definition: vec2i.h:42
HasSamePlayerAndTypeAs(const CPlayer &_player, const CUnitType &_type)
Definition: unit_find.h:112
CUnit * ResourceDepositOnMap(const Vec2i &pos, int resource)
Return resource deposit, if on map tile.
Definition: unit_find.cpp:664
UnitTypeType UnitType
originally only visual effect, we do more with this!
Definition: unittype.h:609
CUnit * ResourceOnMap(const Vec2i &pos, int resource, bool mine_on_top=true)
Return resource, if on map tile.
Definition: unit_find.cpp:639
CUnit * FindUnit_If(const Vec2i <Pos, const Vec2i &rbPos, Pred pred)
Definition: unit_find.h:303
bool operator()(const CUnit *unit) const
Definition: unit_find.h:163
void FixSelectionArea(Vec2i &minpos, Vec2i &maxpos)
Definition: map.h:244
CUnit * AttackUnitsInReactRange(const CUnit &unit, CUnitFilter pred)
Find best enemy in reaction range to attack.
Definition: unit_find.cpp:1217
bool operator()(const CUnit *unit) const
Definition: unit_find.h:52
int TileWidth
How much it costs to repair.
Definition: unittype.h:584
Describes a field of the map.
Definition: tile.h:186
bool operator()(const CUnit *unit) const
Definition: unit_find.h:65
CMap Map
Definition: map.cpp:55
The big unit structure.
Definition: unit.h:135
bool operator()(const CUnit *unit) const
Definition: unit_find.h:176
CUnit * AttackUnitsInRange(const CUnit &unit, CUnitFilter pred)
Find best enemy in attack range to attack.
Definition: unit_find.cpp:1199
const_iterator begin() const
Definition: unit_cache.h:63
(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.