____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include "stratagus.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 "unit_cache.h"
#include "interface.h"
#include "map.h"
#include "pathfinder.h"
Go to the source code of this file.
Defines | |
| #define | PRIORITY_FACTOR 0x00010000 |
| #define | HEALTH_FACTOR 0x00000001 |
| #define | DISTANCE_FACTOR 0x00100000 |
| #define | INRANGE_FACTOR 0x00010000 |
| #define | INRANGE_BONUS 0x01000000 |
| #define | CANATTACK_BONUS 0x00100000 |
Functions | |
| int | FindUnitsByType (const CUnitType *type, CUnit **table, int tablesize) |
| < Find all units of this type | |
| int | FindPlayerUnitsByType (const CPlayer *player, const CUnitType *type, CUnit **table, int tablesize) |
| Return any unit on that map tile. | |
| CUnit * | UnitOnMapTile (int tx, int ty, unsigned type) |
| Return possible attack target on that map area. | |
| CUnit * | TargetOnMap (const CUnit *source, int x1, int y1, int x2, int y2) |
| Return resource, if on map tile. | |
| CUnit * | ResourceOnMap (int tx, int ty, int resource) |
| Find best enemy in numeric range to attack. | |
| static CUnit * | FindRangeAttack (const CUnit *u, int range) |
| static int | CompareUnitDistance (const void *v1, const void *v2) |
| CUnit * | AttackUnitsInDistance (const CUnit *unit, int range) |
| Find best enemy in attack range to attack. | |
| CUnit * | AttackUnitsInRange (const CUnit *unit) |
| Find best enemy in reaction range to attack. | |
| CUnit * | AttackUnitsInReactRange (const CUnit *unit) |
Variables | |
| static const CUnit * | referenceunit |
Definition in file unit_find.cpp.
| #define CANATTACK_BONUS 0x00100000 |
Definition at line 66 of file unit_find.cpp.
Referenced by AttackUnitsInDistance(), and FindRangeAttack().
| #define DISTANCE_FACTOR 0x00100000 |
| #define HEALTH_FACTOR 0x00000001 |
Definition at line 62 of file unit_find.cpp.
Referenced by AttackUnitsInDistance(), and FindRangeAttack().
| #define INRANGE_BONUS 0x01000000 |
| #define INRANGE_FACTOR 0x00010000 |
| #define PRIORITY_FACTOR 0x00010000 |
Definition at line 61 of file unit_find.cpp.
Referenced by AttackUnitsInDistance(), and FindRangeAttack().
Find best enemy in attack 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.
| unit | Find in distance for this unit. | |
| range | Distance range to look. |
Definition at line 559 of file unit_find.cpp.
References ATTACKRANGE_INDEX, CANATTACK_BONUS, CanTarget(), CompareUnitDistance(), DISTANCE_FACTOR, FindRangeAttack(), HEALTH_FACTOR, HP_INDEX, INRANGE_BONUS, INRANGE_FACTOR, CPlayer::IsEnemy(), CUnit::IsVisibleAsGoal(), MapDistanceBetweenUnits(), CVariable::Max, CUnitType::MinAttackRange, MissileConfig::Missile, CUnitType::Missile, NoUnitP, CUnit::Player, CUnitType::Priority, PRIORITY_FACTOR, MissileType::Range, CUnitCache::Select(), CUnit::Stats, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitCache, UnitMax, UnitReachable(), CVariable::Value, CUnit::Variable, CUnitStats::Variables, CUnit::X, CUnit::Y, and y.
Referenced by AiAttackWithForce(), AiForceAttacks(), AttackUnitsInRange(), and AttackUnitsInReactRange().
Find best enemy in reaction range to attack.
Attack units in attack range.
| unit | Find unit in attack range for this unit. |
Definition at line 677 of file unit_find.cpp.
References Assert, ATTACKRANGE_INDEX, AttackUnitsInDistance(), CUnitType::CanAttack, CVariable::Max, CUnit::Stats, CUnit::Type, and CUnitStats::Variables.
Referenced by AutoAttack().
Attack units in reaction range.
| unit | Find unit in reaction range for this unit. |
Definition at line 690 of file unit_find.cpp.
References Assert, AttackUnitsInDistance(), CUnitType::CanAttack, CUnit::Player, PlayerPerson, CUnitType::ReactRangeComputer, CUnitType::ReactRangePerson, CPlayer::Type, and CUnit::Type.
Referenced by AiForceManager(), AttackTarget(), AutoAttack(), CheckForTargetInRange(), HandleActionFollow(), HandleActionPatrol(), and HitUnit().
| static int CompareUnitDistance | ( | const void * | v1, | |
| const void * | v2 | |||
| ) | [static] |
Returns a value less then 0, 0 or bigger then 0, when the first unit is repectively nearer, at the same distance or further away then the 2nd from the referenceunit.
Definition at line 531 of file unit_find.cpp.
References MapDistanceBetweenUnits(), and CUnit::Slot.
Referenced by AttackUnitsInDistance().
| int FindPlayerUnitsByType | ( | const CPlayer * | player, | |
| const CUnitType * | type, | |||
| CUnit ** | table, | |||
| int | tablesize | |||
| ) |
Return any unit on that map tile.
Find all units of type.
| 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 | |
| tablesize | size of table array |
Definition at line 108 of file unit_find.cpp.
References CUnit::IsUnusable(), CUnitType::Slot, CPlayer::TotalNumUnits, CUnit::Type, CPlayer::Units, and CPlayer::UnitTypesCount.
Referenced by AiBuildBuilding(), AiRepairBuilding(), and AiTrainUnit().
Attack units in distance, with large missile
Choose the best target, that can be attacked. It takes into account allied unit which could be hit by the missile
| u | Find in distance for this unit. | |
| range | Distance range to look. |
Limited to attack range smaller than 16.
Will be moved to unit_ai.c soon.
Definition at line 254 of file unit_find.cpp.
References Assert, ATTACKRANGE_INDEX, BASICDAMAGE_INDEX, CANATTACK_BONUS, CanTarget(), CUnit::Container, HEALTH_FACTOR, HP_INDEX, CPlayer::IsEnemy(), CUnit::IsVisibleAsGoal(), MapDistanceBetweenUnits(), CVariable::Max, MissileConfig::Missile, CUnitType::Missile, NoUnitP, PIERCINGDAMAGE_INDEX, CUnit::Player, CUnitType::Priority, PRIORITY_FACTOR, MissileType::Range, CUnit::Removed, CUnitCache::Select(), CUnit::Stats, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitCache, UnitMax, UnitReachable(), CVariable::Value, CUnit::Variable, CUnitStats::Variables, CUnit::X, CUnit::Y, and y.
Referenced by AttackUnitsInDistance().
< Find all units of this type
Find all units of type.
| type | type of unit requested | |
| table | table in which we have to store the units | |
| tablesize | size of table array |
Definition at line 85 of file unit_find.cpp.
References CUnit::IsUnusable(), NumUnits, CUnit::Type, and Units.
Referenced by CclIfNearUnit(), and CclIfRescuedNearUnit().
| CUnit* ResourceOnMap | ( | int | tx, | |
| int | ty, | |||
| int | resource | |||
| ) |
Find best enemy in numeric range to attack.
Resource on map tile
| tx | X position on map, tile-based. | |
| ty | Y position on map, tile-based. | |
| resource | Resource number or -1 for any. |
Definition at line 211 of file unit_find.cpp.
References NoUnitP, CUnitCache::Select(), UnitCache, UnitHoldsResources(), and UnitMax.
Referenced by UnitFindResource().
Return resource, if on map tile.
Choose target on map area.
| 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. |
Definition at line 168 of file unit_find.cpp.
References CanTarget(), CUnit::IsVisibleAsGoal(), NoUnitP, CUnit::Player, CUnitType::Priority, CUnitCache::Select(), CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitCache, UnitMax, CUnit::X, and CUnit::Y.
Referenced by CclOrderUnit().
| CUnit* UnitOnMapTile | ( | int | tx, | |
| int | ty, | |||
| unsigned | type | |||
| ) |
Return possible attack target on that map area.
Unit on map tile.
| tx | X position on map, tile-based. | |
| ty | Y position on map, tile-based. | |
| type | UnitTypeType, (unsigned)-1 for any type. |
Definition at line 136 of file unit_find.cpp.
References NoUnitP, CUnitCache::Select(), UnitCache, and UnitMax.
Referenced by ClosestFreeCoast(), CostMoveTo(), EditorRedoAction(), EditorUndoAction(), UIHandleButtonDown(), and UIHandleMouseMove().
const CUnit* referenceunit [static] |
Reference unit used by CompareUnitDistance.
Definition at line 524 of file unit_find.cpp.
1.5.6