____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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 <string.h>
#include <limits.h>
#include <math.h>
#include "stratagus.h"
#include "unit.h"
#include "unit_manager.h"
#include "unit_cache.h"
#include "video.h"
#include "unitsound.h"
#include "unittype.h"
#include "animation.h"
#include "player.h"
#include "map.h"
#include "actions.h"
#include "sound_server.h"
#include "missile.h"
#include "interface.h"
#include "sound.h"
#include "ai.h"
#include "pathfinder.h"
#include "network.h"
#include "ui.h"
#include "script.h"
#include "editor.h"
#include "spells.h"
#include "luacallback.h"
Go to the source code of this file.
Functions | |
| static void | RemoveUnitFromContainer (CUnit *unit) |
| CUnit * | MakeUnit (CUnitType *type, CPlayer *player) |
| Create a new unit and place on map. | |
| static void | MapMarkUnitSightRec (const CUnit *unit, int x, int y, int width, int height, MapMarkerFunc *f) |
| static CUnit * | GetFirstContainer (CUnit *unit) |
| void | MapMarkUnitSight (CUnit *unit) |
| Mark on vision table the Sight of the unit. | |
| void | MapUnmarkUnitSight (CUnit *unit) |
| Unmark on vision table the Sight of the unit. | |
| void | UpdateUnitSightRange (CUnit *unit) |
| Create a new unit. | |
| void | MarkUnitFieldFlags (const CUnit *unit) |
| < Mark the field with the FieldFlags. | |
| void | UnmarkUnitFieldFlags (const CUnit *unit) |
| Update unit->CurrentSightRange. | |
| static void | UnitInXY (CUnit *unit, int x, int y) |
| CUnit * | MakeUnitAndPlace (int x, int y, CUnitType *type, CPlayer *player) |
| Handle the loss of a unit (food,...). | |
| void | UnitLost (CUnit *unit) |
| Remove the Orders of a Unit. | |
| void | UnitClearOrders (CUnit *unit) |
| void | UpdateForNewUnit (const CUnit *unit, int upgrade) |
| void | NearestOfUnit (const CUnit *unit, int tx, int ty, int *dx, int *dy) |
| Call when an Unit goes under fog. | |
| static void | UnitFillSeenValues (CUnit *unit) |
| void | UnitGoesUnderFog (CUnit *unit, const CPlayer *player) |
| Call when an Unit goes out of fog. | |
| void | UnitGoesOutOfFog (CUnit *unit, const CPlayer *player) |
| Marks a unit as seen. | |
| void | UnitsOnTileMarkSeen (const CPlayer *player, int x, int y) |
| Unmarks a unit as seen. | |
| void | UnitsOnTileUnmarkSeen (const CPlayer *player, int x, int y) |
| Does a recount for VisCount. | |
| void | UnitCountSeen (CUnit *unit) |
| Check for rescue each second. | |
| void | RescueUnits (void) |
| Convert direction (dx,dy) to heading (0-255). | |
| bool | UnitHoldsResources (const CUnit *unit) |
| Find resource. | |
| static int | myatan (int val) |
| int | DirectionToHeading (int delta_x, int delta_y) |
| Update frame from heading. | |
| void | UnitUpdateHeading (CUnit *unit) |
| Heading and frame from delta direction x,y. | |
| void | UnitHeadingFromDeltaXY (CUnit *unit, int dx, int dy) |
| void | DropOutOnSide (CUnit *unit, int heading, int addx, int addy) |
| void | DropOutNearest (CUnit *unit, int gx, int gy, int addx, int addy) |
| Drop out all units in the unit. | |
| void | DropOutAll (const CUnit *source) |
| Return the rule used to build this building. | |
| CUnit * | UnitFindResource (const CUnit *unit, int x, int y, int range, int resource) |
| Find the next idle worker. | |
| CUnit * | FindIdleWorker (const CPlayer *player) |
| CUnit * | UnitOnScreen (int x, int y) |
| Check if a unit should be removed from UnitsConsumingResources. | |
| void | UnitRemoveConsumingResources (CUnit *unit) |
| Let a unit die. | |
| void | LetUnitDie (CUnit *unit) |
| Destory all units inside another unit. | |
| void | DestroyAllInside (CUnit *source) |
| Hit unit with damage, if destroyed give attacker the points. | |
| void | HitUnit (CUnit *attacker, CUnit *target, int damage) |
| Returns the map distance between two points. | |
| int | MapDistance (int x1, int y1, int x2, int y2) |
| Returns the map distance between two points with unit-type. | |
| int | MapDistanceToType (int x1, int y1, const CUnitType *type, int x2, int y2) |
| Returns the map distance to unit. | |
| int | MapDistanceToUnit (int x, int y, const CUnit *dest) |
| Returns the map diestance between to unittype as locations. | |
| int | MapDistanceBetweenUnits (const CUnit *src, const CUnit *dst) |
| Calculate the distance from current view point to coordinate. | |
| int | MapDistanceBetweenTypes (const CUnitType *src, int x1, int y1, const CUnitType *dst, int x2, int y2) |
| Returns the map distance between two units. | |
| int | ViewPointDistance (int x, int y) |
| Calculate the distance from current view point to unit. | |
| int | ViewPointDistanceToUnit (const CUnit *dest) |
| Can this unit-type attack the other (destination). | |
| int | CanTarget (const CUnitType *source, const CUnitType *dest) |
| Can transporter transport the other unit. | |
| int | CanTransport (const CUnit *transporter, const CUnit *unit) |
| Check if unit can move. | |
| void | InitUnits (void) |
| Clean unit module. | |
| void | CleanUnits (void) |
Variables | |
| CUnit * | Units [MAX_UNIT_SLOTS] |
| Array of used slots. | |
| int | NumUnits |
| Number of slots used. | |
| bool | EnableBuildingCapture |
| Config: capture buildings enabled. | |
| static unsigned long | HelpMeLastCycle |
| Last cycle HelpMe sound played. | |
| static int | HelpMeLastX |
| Last X coordinate HelpMe sound played. | |
| static int | HelpMeLastY |
| Last Y coordinate HelpMe sound played. | |
Definition in file unit.cpp.
Can transporter transport the other unit.
Can the source unit attack the destination unit.
| source | Unit type pointer of the attacker. | |
| dest | Unit type pointer of the target. |
Definition at line 2425 of file unit.cpp.
References CUnitType::CanTarget, CanTargetAir, CanTargetLand, CanTargetSea, CUnitType::ShoreBuilding, CUnitType::UnitType, UnitTypeFly, UnitTypeLand, and UnitTypeNaval.
Referenced by AiEnemyUnitsInDistance(), AttackUnitsInDistance(), DoRightButton(), EnemyOnMapTile(), FindRangeAttack(), HitUnit(), MissileHit(), SendAttack(), and TargetOnMap().
Check if unit can move.
Can the transporter transport the other unit.
| transporter | Unit which is the transporter. | |
| unit | Unit which wants to go in the transporter. |
Definition at line 2450 of file unit.cpp.
References CUnit::BoardCount, CUnitType::CanTransport, CUnit::IsTeamed(), CUnitType::MaxOnBoard, CUnit::Orders, CUnitType::Organic, CUnit::Type, UnitActionBuilt, CUnitType::UnitType, and UnitTypeLand.
Referenced by DoRightButton(), SendMove(), and WaitForTransporter().
| void CleanUnits | ( | void | ) |
Clean up unit module.
Definition at line 2611 of file unit.cpp.
References HelpMeLastCycle, CUnitManager::Init(), NumUnits, and UnitManager.
Referenced by CleanGame(), and CleanModules().
| void DestroyAllInside | ( | CUnit * | source | ) |
Hit unit with damage, if destroyed give attacker the points.
Destroy all units inside unit.
| source | container. |
Definition at line 2027 of file unit.cpp.
References DestroyAllInside(), CUnit::InsideCount, CUnit::NextContained, CUnit::Release(), UnitClearOrders(), CUnit::UnitInside, and UnitLost().
Referenced by DestroyAllInside(), and LetUnitDie().
| int DirectionToHeading | ( | int | delta_x, | |
| int | delta_y | |||
| ) |
Update frame from heading.
Convert direction to heading.
| delta_x | Delta X. | |
| delta_y | Delta Y. |
Definition at line 1424 of file unit.cpp.
References myatan().
Referenced by MissileNewHeadingFromXY(), StartBuilding(), and UnitHeadingFromDeltaXY().
| void DropOutAll | ( | const CUnit * | source | ) |
Return the rule used to build this building.
Drop out all units inside unit.
| source | All units inside source are dropped out. |
Definition at line 1663 of file unit.cpp.
References Assert, DropOutOnSide(), CUnit::InsideCount, LookingW, CUnit::NextContained, CUnit::Orders, CUnit::SubAction, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitActionStill, and CUnit::UnitInside.
| void DropOutNearest | ( | CUnit * | unit, | |
| int | gx, | |||
| int | gy, | |||
| int | addx, | |||
| int | addy | |||
| ) |
Drop out all units in the unit.
Place a unit on the map nearest to x, y.
| unit | Unit to drop out. | |
| gx | Goal X map tile position. | |
| gy | Goal Y map tile position. | |
| addx | Tile width of unit it's dropping out of. | |
| addy | Tile height of unit it's dropping out of. |
Definition at line 1578 of file unit.cpp.
References Assert, CUnit::Container, MapDistance(), CUnit::Place(), CUnit::Removed, UnitCanBeAt(), CUnit::X, CUnit::Y, and y.
| void DropOutOnSide | ( | CUnit * | unit, | |
| int | heading, | |||
| int | addx, | |||
| int | addy | |||
| ) |
Place a unit on the map to the side of a unit.
| unit | Unit to drop out. | |
| heading | Direction in which the unit should appear. | |
| addx | Tile width of unit it's dropping out of. | |
| addy | Tile height of unit it's dropping out of. |
Definition at line 1502 of file unit.cpp.
References CUnit::Container, LookingNW, LookingSE, LookingSW, CUnit::Place(), UnitCanBeAt(), CUnit::X, CUnit::Y, and y.
Referenced by Summon::Cast(), CclCreateUnit(), CclMoveUnit(), DropOutAll(), HandleActionBuilt(), and HandleActionTrain().
Find the next idle worker
| player | Player's units to search through |
Definition at line 1816 of file unit.cpp.
References CUnitType::Harvester, IsOnlySelected, NoUnitP, CUnit::Orders, CUnit::Removed, CPlayer::TotalNumUnits, CUnit::Type, UnitActionStill, and CPlayer::Units.
Referenced by UiFindIdleWorker().
Return the unit not transported, by viewing the container recursively.
| unit | unit from where look the first conatiner. |
Definition at line 361 of file unit.cpp.
References CUnit::Container.
Referenced by MapMarkUnitSight(), and MapUnmarkUnitSight().
Returns the map distance between two points.
Unit is hit by missile or other damage.
| attacker | Unit that attacks. | |
| target | Unit that is hit. | |
| damage | How many damage to take. |
Definition at line 2056 of file unit.cpp.
References _, COrder::Action, CPlayer::AiEnabled, AiHelpMe(), Assert, CUnit::Attacked, AttackUnitsInReactRange(), CUnitType::Building, CUnit::Burning, CUnitType::CanAttack, CanMove(), CanTarget(), CUnit::ChangeOwner(), CommandAttack(), CommandMove(), CommandStopUnit(), CUnitType::Coward, CYCLES_PER_SECOND, Missile::Damage, DamageMissile, DebugPrint, CVariable::Enable, EnableBuildingCapture, FlushCommands, GameCycle, GodMode, HelpMeLastCycle, HelpMeLastX, HelpMeLastY, HP_INDEX, CUnitType::Indestructible, CMap::Info, CUnit::IsEnemy(), isqrt(), CUnit::IsVisibleOnMap(), KILL_INDEX, LetUnitDie(), MakeLocalMissile(), MakeMissile(), Map, CMapInfo::MapHeight, CMapInfo::MapWidth, CVariable::Max, MissileBurningBuilding(), MissileTypeByIdent(), CUnitType::Name, CPlayer::Notify(), NotifyRed, NoUnitP, CUnit::Orders, CUnitType::Organic, CUnit::Player, PlayUnitSound(), CUnitType::Points, CUnit::RefsIncrease(), CUnit::Removed, CUnitType::RepairRange, ReplayRevealMap, CUnit::SavedOrder, CPlayer::Score, Missile::SourceUnit, SyncRand(), ThisPlayer, CUnitType::TileHeight, TileSizeX, TileSizeY, CUnitType::TileWidth, CPlayer::TotalKills, CPlayer::TotalRazings, CUnit::Type, UnitActionDie, UnitActionStill, CVariable::Value, CUnitType::Vanishes, CUnit::Variable, VoiceHelpMe, CUnit::X, y, and CUnit::Y.
Referenced by Capture::Cast(), AdjustVitals::Cast(), AreaAdjustVitals::Cast(), Demolish::Cast(), FireMissile(), HandleRegenerations(), and MissileHitsGoal().
| void InitUnits | ( | void | ) |
Clean unit module.
Initialize unit module.
Definition at line 2600 of file unit.cpp.
References CUnitManager::Init(), NumUnits, SaveGameLoading, and UnitManager.
Referenced by InitModules().
| void LetUnitDie | ( | CUnit * | unit | ) |
Destory all units inside another unit.
Let a unit die.
| unit | Unit to be destroyed. |
Definition at line 1927 of file unit.cpp.
References CUnit::Anim, CUnitType::Animations, CUnit::_order_data_::Built, CUnitType::CanHarvestFrom, CUnitType::CorpseType, CUnit::CurrentSightRange, CUnit::Data, CAnimations::Death, CUnitType::DeathExplosion, DebugPrint, DestroyAllInside(), CUnitType::ExplodeWhenKilled, CUnitType::Explosion, CGraphic::Height, CUnitType::Height, CPlayer::Index, CUnitCache::Insert(), CUnit::IX, CUnit::IY, MakeMissile(), MapMarkUnitSight(), CVariable::Max, MaxCosts, MissileConfig::Missile, CUnit::Moving, CUnit::Orders, CUnit::Player, PlayUnitSound(), CUnit::ProductionEfficiency, CUnitType::ProductionRate, CPlayer::ProductionRate, LuaCallback::pushInteger(), LuaCallback::pushPreamble(), CUnit::Release(), CUnit::Remove(), CUnit::Removed, CUnit::ResourcesHeld, LuaCallback::run(), SIGHTRANGE_INDEX, CUnitType::Sprite, CUnit::State, CUnitType::Stats, CUnitType::StorageCapacity, CPlayer::StorageCapacity, CPlayer::StoredResources, CUnit::SubAction, CUnitType::TileHeight, TileSizeX, TileSizeY, CUnitType::TileWidth, CUnit::TTL, CUnit::Type, CUnit::_unit_anim_::Unbreakable, UnitActionBuilt, UnitActionDie, UnitCache, UnitClearOrders(), CUnit::UnitInside, UnitLost(), UnitRemoveConsumingResources(), CUnitStats::Variables, VoiceDying, CGraphic::Width, CUnitType::Width, CUnit::_order_data_::_order_built_::Worker, CUnit::X, and CUnit::Y.
Referenced by CclKillUnit(), CclKillUnitAt(), CommandDismiss(), GatherResource(), HandleActionBuilt(), HandleBuffs(), and HitUnit().
Create a new unit and place on map.
Create a new unit.
| type | Pointer to unit-type. | |
| player | Pointer to owning player. |
Definition at line 302 of file unit.cpp.
References _C_, CUnitManager::AllocUnit(), CUnit::AssignToPlayer(), DebugPrint, CUnit::Init(), NoUnitP, NumUnits, UnitManager, and UnitMax.
Referenced by Summon::Cast(), CclCreateUnit(), HandleActionTrain(), MakeUnitAndPlace(), and StartBuilding().
Handle the loss of a unit (food,...).
Create new unit and place on map.
| x | X map tile position. | |
| y | Y map tile position. | |
| type | Pointer to unit-type. | |
| player | Pointer to owning player. |
Definition at line 636 of file unit.cpp.
References MakeUnit(), NoUnitP, and CUnit::Place().
Referenced by Polymorph::Cast(), SpawnPortal::Cast(), EditorActionPlaceUnit(), and UnitLost().
| int MapDistance | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2 | |||
| ) |
Returns the map distance between two points with unit-type.
Returns the map distance between two points.
| x1 | X map tile position. | |
| y1 | Y map tile position. | |
| x2 | X map tile position. | |
| y2 | Y map tile position. |
Definition at line 2272 of file unit.cpp.
References isqrt().
Referenced by DropOutNearest(), MissileInitMove(), NextMissileFrame(), and ViewPointDistance().
| int MapDistanceBetweenTypes | ( | const CUnitType * | src, | |
| int | x1, | |||
| int | y1, | |||
| const CUnitType * | dst, | |||
| int | x2, | |||
| int | y2 | |||
| ) |
Returns the map distance between two units.
Returns the map distance between two points with unit type.
| src | src unittype | |
| x1 | X map tile position of src (upperleft). | |
| y1 | Y map tile position of src. | |
| dst | Unit type to take into account. | |
| x2 | X map tile position of dst. | |
| y2 | Y map tile position of dst. |
Definition at line 2354 of file unit.cpp.
References isqrt(), CUnitType::TileHeight, and CUnitType::TileWidth.
Referenced by CBuildRestrictionDistance::Check(), and MapDistanceBetweenUnits().
Calculate the distance from current view point to coordinate.
Returns the map distance between two units.
| src | Distance from this unit. | |
| dst | Distance to this unit. |
Definition at line 2336 of file unit.cpp.
References MapDistanceBetweenTypes(), CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by AttackTarget(), AttackUnitsInDistance(), CompareUnitDistance(), FindRangeAttack(), FireMissile(), HandleActionAttack(), MoveToLocation(), MoveToTarget(), RepairUnit(), SpellMoveToTarget(), StartGathering(), and WaitForTransporter().
| int MapDistanceToType | ( | int | x1, | |
| int | y1, | |||
| const CUnitType * | type, | |||
| int | x2, | |||
| int | y2 | |||
| ) |
Returns the map distance to unit.
Returns the map distance between two points with unit type.
| x1 | X map tile position. | |
| y1 | Y map tile position. | |
| type | Unit type to take into account. | |
| x2 | X map tile position. | |
| y2 | Y map tile position. |
Definition at line 2288 of file unit.cpp.
References isqrt(), CUnitType::TileHeight, and CUnitType::TileWidth.
Referenced by MapDistanceToUnit().
| int MapDistanceToUnit | ( | int | x, | |
| int | y, | |||
| const CUnit * | dest | |||
| ) |
Returns the map diestance between to unittype as locations.
Returns the map distance to unit.
| x | X map tile position. | |
| y | Y map tile position. | |
| dest | Distance to this unit. |
Definition at line 2323 of file unit.cpp.
References MapDistanceToType(), CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by Demolish::Cast(), MissileHit(), MoveToTarget(), SpellMoveToTarget(), and ViewPointDistanceToUnit().
| void MapMarkUnitSight | ( | CUnit * | unit | ) |
Mark on vision table the Sight of the unit.
Mark on vision table the Sight of the unit (and units inside for transporter)
| unit | unit to unmark its vision. |
Definition at line 375 of file unit.cpp.
References GetFirstContainer(), CUnit::IsUnusable(), MapMarkRadar(), MapMarkRadarJammer(), MapMarkTileSight, MapMarkUnitSightRec(), CUnit::Player, RADAR_INDEX, RADARJAMMER_INDEX, CUnit::Stats, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CVariable::Value, CUnitStats::Variables, CUnit::X, and CUnit::Y.
Referenced by CclUnit(), CUnit::ChangeOwner(), CommandSharedVision(), HandleActionBuilt(), HandleActionDie(), LetUnitDie(), CUnit::MoveToXY(), CUnit::Place(), CUnit::Remove(), and StartBuilding().
| static void MapMarkUnitSightRec | ( | const CUnit * | unit, | |
| int | x, | |||
| int | y, | |||
| int | width, | |||
| int | height, | |||
| MapMarkerFunc * | f | |||
| ) | [static] |
(Un)Mark on vision table the Sight of the unit (and units inside for transporter (recursively))
| unit | Unit to (un)mark. | |
| x | X coord of first container of unit. | |
| y | Y coord of first container of unit. | |
| width | Width of the first container of unit. | |
| height | Height of the first container of unit. | |
| f | Function to (un)mark for normal vision. |
Definition at line 340 of file unit.cpp.
References CUnit::Container, CUnit::CurrentSightRange, CUnit::InsideCount, MapSight(), CUnit::NextContained, CUnit::Player, and CUnit::UnitInside.
Referenced by MapMarkUnitSight(), and MapUnmarkUnitSight().
| void MapUnmarkUnitSight | ( | CUnit * | unit | ) |
Unmark on vision table the Sight of the unit.
Unmark on vision table the Sight of the unit (and units inside for transporter)
| unit | unit to unmark its vision. |
Definition at line 402 of file unit.cpp.
References GetFirstContainer(), CUnit::IsUnusable(), MapMarkUnitSightRec(), MapUnmarkRadar(), MapUnmarkRadarJammer(), MapUnmarkTileSight, CUnit::Player, RADAR_INDEX, RADARJAMMER_INDEX, CUnit::Stats, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CVariable::Value, CUnitStats::Variables, CUnit::X, and CUnit::Y.
Referenced by CUnit::ChangeOwner(), CommandSharedVision(), HandleActionDie(), CUnit::MoveToXY(), CUnit::Place(), CUnit::Release(), and CUnit::Remove().
| void MarkUnitFieldFlags | ( | const CUnit * | unit | ) |
< Mark the field with the FieldFlags.
Mark the field with the FieldFlags.
| unit | unit to mark. |
Definition at line 467 of file unit.cpp.
References CMap::Field(), CUnitType::FieldFlags, CMapField::Flags, Map, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by CanBuildUnitType(), DoActionMove(), CUnit::MoveToXY(), and CUnit::Place().
| static int myatan | ( | int | val | ) | [static] |
Fast arc tangent function.
| val | atan argument |
Definition at line 1398 of file unit.cpp.
Referenced by DirectionToHeading().
| void NearestOfUnit | ( | const CUnit * | unit, | |
| int | tx, | |||
| int | ty, | |||
| int * | dx, | |||
| int * | dy | |||
| ) |
Call when an Unit goes under fog.
Find nearest point of unit.
| unit | Pointer to unit. | |
| tx | X tile map postion. | |
| ty | Y tile map postion. | |
| dx | Out: nearest point X tile map postion to (tx,ty). | |
| dy | Out: nearest point Y tile map postion to (tx,ty). |
Definition at line 828 of file unit.cpp.
References CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, CUnit::X, CUnit::Y, and y.
Referenced by FireMissile().
| static void RemoveUnitFromContainer | ( | CUnit * | unit | ) | [static] |
Remove unit from a container. It only updates linked list stuff.
| unit | Pointer to unit. |
Definition at line 528 of file unit.cpp.
References Assert, CUnit::Container, CUnit::InsideCount, CUnit::NextContained, NoUnitP, CUnit::PrevContained, and CUnit::UnitInside.
Referenced by CUnit::Place(), and CUnit::Release().
| void RescueUnits | ( | void | ) |
Convert direction (dx,dy) to heading (0-255).
Rescue units.
Look through all rescueable players, if they could be rescued.
Definition at line 1310 of file unit.cpp.
References CUnit::Blink, CUnit::ChangeOwner(), GameSounds, CUnit::IsAllied(), MaxSampleVolume, NoRescueCheck, NumPlayers, CUnit::Player, PlayerRescueActive, PlayerRescuePassive, Players, PlayGameSound(), CUnit::Removed, GameSound::Rescue, CUnit::RescuedFrom, CUnitCache::Select(), SoundConfig::Sound, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitCache, UnitMax, CUnitType::UnitType, UnitTypeLand, CUnit::X, and CUnit::Y.
Referenced by GameMainLoop().
| void UnitClearOrders | ( | CUnit * | unit | ) |
Removes all orders from a unit.
| unit | The unit that will have all its orders cleared |
Definition at line 770 of file unit.cpp.
References COrder::Goal, CUnit::NewOrder, NoUnitP, CUnit::OrderCount, CUnit::Orders, CUnit::RefsDecrease(), CUnit::SavedOrder, CUnit::State, CUnit::SubAction, and UnitActionStill.
Referenced by Capture::Cast(), Polymorph::Cast(), DestroyAllInside(), EditorActionPlaceUnit(), EditorActionRemoveUnit(), LetUnitDie(), and StartBuilding().
| void UnitCountSeen | ( | CUnit * | unit | ) |
Check for rescue each second.
Recalculates a units visiblity count. This happens really often, Like every time a unit moves. It's really fast though, since we have per-tile counts.
| unit | pointer to the unit to check if seen |
Definition at line 1013 of file unit.cpp.
References CMap::Field(), CUnit::IsVisible(), Map, CMap::NoFogOfWar, PlayerMax, PlayerNobody, Players, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitGoesOutOfFog(), UnitGoesUnderFog(), CUnit::VisCount, CMapField::Visible, CUnit::X, CUnit::Y, and y.
Referenced by CUnit::MoveToXY(), CUnit::Place(), CMap::Reveal(), and UpdateFogOfWarChange().
| static void UnitFillSeenValues | ( | CUnit * | unit | ) | [static] |
Copy the unit look in Seen variables. This should be called when buildings go under fog of war for ThisPlayer.
| unit | The unit to work on |
Definition at line 855 of file unit.cpp.
References CUnit::_order_data_::Built, CUnit::_unit_seen_::CFrame, CUnit::Constructed, CUnit::_unit_seen_::Constructed, CUnit::Data, CUnit::_order_data_::_order_built_::Frame, CUnit::Frame, CUnit::_unit_seen_::Frame, CUnit::IX, CUnit::_unit_seen_::IX, CUnit::IY, CUnit::_unit_seen_::IY, CUnit::Orders, CUnit::Seen, CUnit::_unit_seen_::State, CUnit::Type, CUnit::_unit_seen_::Type, UnitActionBuilt, UnitActionDie, CUnit::X, CUnit::_unit_seen_::X, CUnit::Y, and CUnit::_unit_seen_::Y.
Referenced by UnitGoesUnderFog().
Find the next idle worker.
Find Resource.
| unit | The unit that wants to find a resource. | |
| x | Closest to x | |
| y | Closest to y | |
| range | Maximum distance to the resource. | |
| resource | The resource id. |
Definition at line 1696 of file unit.cpp.
References CUnitType::CanHarvestFrom, CanMoveToMask(), CreateMatrix(), CMap::Info, CMap::IsFieldExplored(), Map, MapFieldAirUnit, MapFieldLandUnit, MapFieldSeaUnit, CMapInfo::MapHeight, CMapInfo::MapWidth, CUnitType::MovementMask, NoUnitP, CUnit::Player, PlayerNeutral, ResourceOnMap(), CPlayer::Type, CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by AiAssignHarvester(), FindNewResource(), and StartGathering().
Marks a unit as seen.
This function should get called when a unit goes out of fog of war.
| unit | The unit that goes out of fog. | |
| player | The player the unit goes out of fog for. |
Definition at line 923 of file unit.cpp.
References CUnit::_unit_seen_::ByPlayer, CUnit::_unit_seen_::Destroyed, CPlayer::Index, PlayerPerson, CUnit::RefsDecrease(), CUnit::Seen, CPlayer::Type, CUnit::Type, and CUnitType::VisibleUnderFog.
Referenced by CMap::Reveal(), UnitCountSeen(), and UnitsOnTileMarkSeen().
Call when an Unit goes out of fog.
This function should get called when a unit goes under fog of war.
| unit | The unit that goes under fog. | |
| player | The player the unit goes out of fog for. |
Definition at line 882 of file unit.cpp.
References CUnit::_unit_seen_::Destroyed, CUnit::Destroyed, CPlayer::Index, PlayerPerson, CUnit::RefsIncrease(), CUnit::Seen, ThisPlayer, CPlayer::Type, CUnit::Type, UnitFillSeenValues(), and CUnitType::VisibleUnderFog.
Referenced by CMap::Reveal(), UnitCountSeen(), and UnitsOnTileUnmarkSeen().
| void UnitHeadingFromDeltaXY | ( | CUnit * | unit, | |
| int | dx, | |||
| int | dy | |||
| ) |
Change unit heading/frame from delta direction x, y.
| unit | Unit for new direction looking. | |
| dx | X map tile delta direction. | |
| dy | Y map tile delta direction. |
Definition at line 1484 of file unit.cpp.
References CUnit::Direction, DirectionToHeading(), and UnitUpdateHeading().
Referenced by AttackTarget(), AutoAttack(), DoActionMove(), HandleActionAttack(), MoveToLocation(), MoveToTarget(), SpellMoveToTarget(), and StartGathering().
| bool UnitHoldsResources | ( | const CUnit * | unit | ) |
Find resource.
Check if a unit holds any resources
| unit | Unit to check |
Definition at line 1377 of file unit.cpp.
References MaxCosts, and CUnit::ResourcesHeld.
Referenced by GatherResource(), ResourceOnMap(), and UnitLost().
| static void UnitInXY | ( | CUnit * | unit, | |
| int | x, | |||
| int | y | |||
| ) | [static] |
Affect Tile coord of a unit (with units inside) to tile (x, y).
| unit | unit to move. | |
| x | X map tile position. | |
| y | Y map tile position. |
Definition at line 560 of file unit.cpp.
References CUnit::InsideCount, CUnit::NextContained, CUnit::UnitInside, CUnit::X, and CUnit::Y.
Referenced by CUnit::MoveToXY(), CUnit::Place(), and CUnit::Remove().
| void UnitLost | ( | CUnit * | unit | ) |
Remove the Orders of a Unit.
Update information for lost units.
| unit | Pointer to unit. |
Definition at line 703 of file unit.cpp.
References _C_, CPlayer::AiEnabled, AiUnitKilled(), Assert, CUnitType::Building, CUnitType::CanHarvestFrom, DebugPrint, CUnit::GroupId, CUnitType::Ident, MakeUnitAndPlace(), NoUnitP, CPlayer::NumBuildings, OnTopDetails(), CUnit::Orders, CBuildRestrictionOnTop::Parent, CUnit::Player, PlayerNumNeutral, Players, CUnit::PlayerSlot, RemoveUnitFromGroups(), CBuildRestrictionOnTop::ReplaceOnDie, CUnit::ResourcesHeld, CUnitType::Slot, CPlayer::TotalNumUnits, CUnit::Type, UnitActionBuilt, UnitHoldsResources(), UnitMax, UnitNumber, CPlayer::Units, CPlayer::UnitTypesCount, CUnitType::Vanishes, CUnit::X, and CUnit::Y.
Referenced by Capture::Cast(), Polymorph::Cast(), CUnit::ChangeOwner(), DestroyAllInside(), EditorActionPlaceUnit(), EditorActionRemoveUnit(), LetUnitDie(), and StartBuilding().
| CUnit* UnitOnScreen | ( | int | x, | |
| int | y | |||
| ) |
Check if a unit should be removed from UnitsConsumingResources.
Select unit on screen. (x, y are in pixels relative to map 0,0).
| x | X pixel position. | |
| y | Y pixel position. |
Definition at line 1865 of file unit.cpp.
References CUnitType::BoxHeight, CUnitType::BoxWidth, CUnitType::DrawLevel, CUnit::IsVisibleAsGoal(), CUnit::IX, CUnit::IY, NumUnits, ReplayRevealMap, ThisPlayer, CUnitType::TileHeight, TileSizeX, TileSizeY, CUnitType::TileWidth, CUnit::Type, CUnit::X, and CUnit::Y.
Referenced by EditorCallbackMouse(), UIHandleButtonUp(), and UIHandleMouseMove().
| void UnitRemoveConsumingResources | ( | CUnit * | unit | ) |
Let a unit die.
Check if a unit should be removed from UnitsConsumingResources
Definition at line 1908 of file unit.cpp.
References CUnitType::BuilderOutside, CUnit::_order_data_::_order_harvest_::CurrentProduction, CUnit::Data, CUnit::_order_data_::Harvest, MaxCosts, CUnit::Orders, CUnit::Player, CPlayer::ProductionRate, CPlayer::RemoveFromUnitsConsumingResources(), CUnit::SubAction, CUnit::Type, UnitActionBuild, UnitActionRepair, UnitActionResource, and UnitActionTrain.
Referenced by HandleUnitAction(), and LetUnitDie().
| void UnitsOnTileMarkSeen | ( | const CPlayer * | player, | |
| int | x, | |||
| int | y | |||
| ) |
Unmarks a unit as seen.
Mark all units on a tile as now visible.
| player | The player this is for. | |
| x | x location to check | |
| y | y location to check |
Definition at line 944 of file unit.cpp.
References CPlayer::Index, CPlayer::IsBothSharedVision(), CUnit::IsVisible(), PlayerMax, Players, CUnitCache::Select(), UnitCache, UnitGoesOutOfFog(), UnitMax, and CUnit::VisCount.
Referenced by MapMarkTileSight().
| void UnitsOnTileUnmarkSeen | ( | const CPlayer * | player, | |
| int | x, | |||
| int | y | |||
| ) |
Does a recount for VisCount.
This function unmarks units on x, y as seen. It uses a reference count.
| player | The player to mark for. | |
| x | x location to check if building is on, and mark as seen | |
| y | y location to check if building is on, and mark as seen |
Definition at line 975 of file unit.cpp.
References Assert, CPlayer::Index, CPlayer::IsBothSharedVision(), CUnit::IsVisible(), PlayerMax, Players, CUnitCache::Select(), CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitCache, UnitGoesUnderFog(), UnitMax, CUnit::VisCount, CUnit::X, and CUnit::Y.
Referenced by MapUnmarkTileSight().
| void UnitUpdateHeading | ( | CUnit * | unit | ) |
Heading and frame from delta direction x,y.
Update sprite frame for new heading.
Definition at line 1448 of file unit.cpp.
References CUnitType::Building, CUnit::Direction, CUnit::Frame, LookingS, CUnitType::NumDirections, and CUnit::Type.
Referenced by DoActionMove(), HandleActionBuilt(), HandleActionDie(), HandleActionFollow(), CUnit::Init(), StartBuilding(), UnitHeadingFromDeltaXY(), UnitRotate(), and UnitShowAnimationScaled().
| void UnmarkUnitFieldFlags | ( | const CUnit * | unit | ) |
Update unit->CurrentSightRange.
Mark the field with the FieldFlags.
| unit | unit to mark. |
Definition at line 483 of file unit.cpp.
References CMap::Field(), CUnitType::FieldFlags, CMapField::Flags, Map, CUnit::Orders, CUnitCache::Select(), CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitActionDie, UnitCache, UnitMax, CUnit::X, and CUnit::Y.
Referenced by CanBuildUnitType(), DoActionMove(), CUnit::MoveToXY(), and CUnit::Remove().
| void UpdateForNewUnit | ( | const CUnit * | unit, | |
| int | upgrade | |||
| ) |
Update for new unit. Food and income ...
| unit | New unit pointer. | |
| upgrade | True unit was upgraded. |
Definition at line 805 of file unit.cpp.
References MaxCosts, CUnit::Player, CUnit::ProductionEfficiency, CUnitType::ProductionRate, CPlayer::ProductionRate, CUnitType::StorageCapacity, CPlayer::StorageCapacity, and CUnit::Type.
Referenced by CclCreateUnit(), CclUnit(), CUnit::ChangeOwner(), HandleActionBuilt(), and HandleActionTrain().
| void UpdateUnitSightRange | ( | CUnit * | unit | ) |
Create a new unit.
Update the Unit Current sight range to good value and transported units inside.
| unit | unit to update SightRange |
Definition at line 435 of file unit.cpp.
References Assert, CUnit::Constructed, CUnit::Container, CUnit::CurrentSightRange, CUnit::InsideCount, CVariable::Max, CUnit::NextContained, SaveGameLoading, SIGHTRANGE_INDEX, CUnit::Stats, CUnit::UnitInside, UpdateUnitSightRange(), and CUnitStats::Variables.
Referenced by CUnit::ChangeOwner(), CUnit::Place(), CUnit::Remove(), and UpdateUnitSightRange().
| int ViewPointDistance | ( | int | x, | |
| int | y | |||
| ) |
Calculate the distance from current view point to unit.
Compute the distance from the view point to a given point.
| x | X map tile position. | |
| y | Y map tile position. |
Definition at line 2391 of file unit.cpp.
References MapDistance(), CViewport::MapHeight, CViewport::MapWidth, CViewport::MapX, CViewport::MapY, CUserInterface::SelectedViewport, and UI.
Referenced by ViewPointDistanceToMissile().
| int ViewPointDistanceToUnit | ( | const CUnit * | dest | ) |
Can this unit-type attack the other (destination).
Compute the distance from the view point to a given unit.
| dest | Distance to this unit. |
Definition at line 2410 of file unit.cpp.
References MapDistanceToUnit(), CViewport::MapHeight, CViewport::MapWidth, CViewport::MapX, CViewport::MapY, CUserInterface::SelectedViewport, and UI.
Referenced by PlayUnitSound().
Config: capture buildings enabled.
Config: building capture enabled.
Definition at line 73 of file unit.cpp.
Referenced by CclSetBuildingCapture(), and HitUnit().
unsigned long HelpMeLastCycle [static] |
Last cycle HelpMe sound played.
Definition at line 75 of file unit.cpp.
Referenced by CleanUnits(), and HitUnit().
int HelpMeLastX [static] |
int HelpMeLastY [static] |
| int NumUnits |
Number of slots used.
Number of units used.
Definition at line 71 of file unit.cpp.
Referenced by AddGroupFromUnitToSelection(), AiMoveUnitInTheWay(), CclGetUnits(), CclKillUnit(), CPlayer::CheckLimits(), CleanUnits(), CommandSharedVision(), CreateGame(), FindUnitsByType(), HandleActionTrain(), CUnit::Init(), InitUnits(), LoadGame(), MakeUnit(), CUnit::Release(), RemoveUnitFromGroups(), CMap::Reveal(), SaveGroups(), SaveUnits(), UiAddGroupToSelection(), UnitActions(), UnitOnScreen(), CMinimap::Update(), UpdateFogOfWarChange(), and WriteMapSetup().
Array of used slots.
Units used.
Definition at line 70 of file unit.cpp.
Referenced by AddGroupFromUnitToSelection(), AiMoveUnitInTheWay(), CclGetUnits(), CclKillUnit(), CommandSharedVision(), CreateGame(), FindUnitsByType(), InitGroups(), LoadGame(), NetworkProcessSelection(), CMap::Reveal(), SaveGroups(), SaveUnits(), UnitActions(), CMinimap::Update(), UpdateFogOfWarChange(), and WriteMapSetup().
1.5.6