$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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <sstream>
#include <iomanip>
#include "stratagus.h"
#include "unit.h"
#include "unit_manager.h"
#include "video.h"
#include "unitsound.h"
#include "unittype.h"
#include "animation.h"
#include "player.h"
#include "tileset.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"
#include "construct.h"
#include "iolib.h"
Classes | |
struct | _UnmarkUnitFieldFlags |
struct | _TileSeen< MARK > |
class | BestDepotFinder< NEARLOCATION > |
unit.cpp - The units. | |
CUnit * | Units [MAX_UNIT_SLOTS] |
int | NumUnits |
Array of used slots. | |
bool | EnableTrainingQueue |
Number of slots used. | |
bool | EnableBuildingCapture |
Config: training queues enabled. | |
bool | RevealAttacker |
Config: capture buildings enabled. | |
static unsigned long | HelpMeLastCycle |
Config: reveal attacker enabled. | |
static int | HelpMeLastX |
Last cycle HelpMe sound played. | |
static int | HelpMeLastY |
Last X coordinate HelpMe sound played. | |
static void | RemoveUnitFromContainer (CUnit &unit) |
Last Y coordinate HelpMe sound played. | |
int | ExtraDeathIndex (const char *death) |
CUnit * | MakeUnit (CUnitType &type, CPlayer *player) |
Create a new unit. | |
static void | MapMarkUnitSightRec (const CUnit &unit, const Vec2i &pos, int width, int height, MapMarkerFunc *f, MapMarkerFunc *f2) |
static CUnit * | GetFirstContainer (const 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) |
Update unit->CurrentSightRange. | |
void | MarkUnitFieldFlags (const CUnit &unit) |
Number of Units a team member has selected. | |
void | UnmarkUnitFieldFlags (const CUnit &unit) |
Unmark the field with the FieldFlags. | |
static void | UnitInXY (CUnit &unit, const Vec2i &pos) |
CUnit * | MakeUnitAndPlace (const Vec2i &pos, CUnitType &type, CPlayer *player) |
void | UnitLost (CUnit &unit) |
Handle the loss of a unit (food,...). | |
void | UnitClearOrders (CUnit &unit) |
Remove the Orders of a Unit. | |
void | UpdateForNewUnit (const CUnit &unit, int upgrade) |
void | NearestOfUnit (const CUnit &unit, const Vec2i &pos, Vec2i *dpos) |
static void | UnitFillSeenValues (CUnit &unit) |
void | UnitGoesUnderFog (CUnit &unit, const CPlayer &player) |
Call when an Unit goes under fog. | |
void | UnitGoesOutOfFog (CUnit &unit, const CPlayer &player) |
Call when an Unit goes out of fog. | |
void | UnitsOnTileMarkSeen (const CPlayer &player, const unsigned int index, int cloak) |
void | UnitsOnTileMarkSeen (const CPlayer &player, int x, int y, int cloak) |
Marks a unit as seen. | |
void | UnitsOnTileUnmarkSeen (const CPlayer &player, const unsigned int index, int cloak) |
void | UnitsOnTileUnmarkSeen (const CPlayer &player, int x, int y, int cloak) |
Unmarks a unit as seen. | |
void | UnitCountSeen (CUnit &unit) |
Does a recount for VisCount. | |
static void | ChangePlayerOwner (CPlayer &oldplayer, CPlayer &newplayer) |
void | RescueUnits () |
Check for rescue each second. | |
static int | myatan (int val) |
int | DirectionToHeading (const Vec2i &delta) |
Convert direction (dx,dy) to heading (0-255). | |
void | UnitUpdateHeading (CUnit &unit) |
Update frame from heading. | |
void | UnitHeadingFromDeltaXY (CUnit &unit, const Vec2i &delta) |
void | DropOutOnSide (CUnit &unit, int heading, const CUnit *container) |
void | DropOutNearest (CUnit &unit, const Vec2i &goalPos, const CUnit *container) |
void | DropOutAll (const CUnit &source) |
Drop out all units in the unit. | |
int | FindWoodInSight (const CUnit &unit, Vec2i *pos) |
int | FindTerrainType (int movemask, int resmask, int rvresult, int range, const CPlayer *player, const Vec2i &startPos, Vec2i *terrainPos) |
CUnit * | FindDepositNearLoc (CPlayer &p, const Vec2i &pos, int range, int resource) |
CUnit * | UnitFindResource (const CUnit &unit, int x, int y, int range, int resource, bool check_usage, const CUnit *destu) |
Find resource. | |
CUnit * | UnitFindMiningArea (const CUnit &unit, int x, int y, int range, int resource) |
CUnit * | FindDeposit (const CUnit &unit, int range, int resource) |
Find nearest deposit. | |
CUnit * | FindIdleWorker (const CPlayer &player, const CUnit *last) |
Find the next idle worker. | |
CUnit * | UnitOnScreen (CUnit *ounit, int x, int y) |
void | LetUnitDie (CUnit &unit) |
Let a unit die. | |
void | DestroyAllInside (CUnit &source) |
Destory all units inside another unit. | |
void | HitUnit (CUnit *attacker, CUnit &target, int damage) |
Hit unit with damage, if destroyed give attacker the points. | |
int | MapDistanceToType (const Vec2i &pos1, const CUnitType &type, const Vec2i &pos2) |
int | MapDistanceBetweenTypes (const CUnitType &src, const Vec2i &pos1, const CUnitType &dst, const Vec2i &pos2) |
int | ViewPointDistance (const Vec2i &pos) |
int | ViewPointDistanceToUnit (const CUnit &dest) |
Calculate the distance from current view point to unit. | |
int | CanTarget (const CUnitType *source, const CUnitType *dest) |
Can this unit-type attack the other (destination). | |
int | CanTransport (const CUnit &transporter, const CUnit &unit) |
Can transporter transport the other unit. | |
int | GetAnimationDamagedState (CUnit &unit, int anim) |
Get the suitable animation frame when unit is damaged. | |
void | InitUnits () |
Initialize unit module. | |
void | CleanUnits () |
Clean unit module. |
Can this unit-type attack the other (destination).
Can the source unit attack the destination unit.
source | Unit type pointer of the attacker. | |
dest | Unit type pointer of the target. |
Can transporter transport the other unit.
Can the transporter transport the other unit.
transporter | Unit which is the transporter. | |
unit | Unit which wants to go in the transporter. |
Change the owner of all units of a player.
oldplayer | Old owning player. | |
newplayer | New owning player. |
void CleanUnits | ( | ) |
Clean unit module.
Clean up unit module.
void DestroyAllInside | ( | CUnit & | source | ) |
Destory all units inside another unit.
Destroy all units inside unit.
source | container. |
int DirectionToHeading | ( | const Vec2i & | delta | ) |
Convert direction (dx,dy) to heading (0-255).
Convert direction to heading.
delta | Delta. |
void DropOutAll | ( | const CUnit & | source | ) |
Drop out all units in the unit.
Drop out all units inside unit.
source | All units inside source are dropped out. |
Place a unit on the map nearest to goalPos.
unit | Unit to drop out. | |
goalPos | Goal map tile position. | |
addx | Tile width of unit it's dropping out of. | |
addy | Tile height of unit it's dropping out of. |
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. | |
container | Unit "containing" unit to drop (may be different of unit.Container). |
int ExtraDeathIndex | ( | const char * | death | ) |
Find the index of a extra death type
Find nearest deposit.
Find deposit. This will find a deposit for a resource
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. |
Find the next idle worker.
Find the next idle worker
player | Player's units to search through | |
last | Previous idle worker selected |
int FindTerrainType | ( | int | movemask, | |
int | resmask, | |||
int | rvresult, | |||
int | range, | |||
const CPlayer * | player, | |||
const Vec2i & | startPos, | |||
Vec2i * | terrainPos | |||
) |
Find the closest piece of terrain with the given flags.
movemask | The movement mask to reach that location. | |
resmask | Result tile mask. | |
rvresult | Return a tile that doesn't match. | |
range | Maximum distance for the search. | |
player | Only search fields explored by player | |
startPos | Map start position for the search. | |
pos | OUT: Map position of tile. |
Find the closest piece of wood for an unit.
unit | The unit. | |
pos | OUT: Map position of tile. |
int GetAnimationDamagedState | ( | CUnit & | unit, | |
int | anim | |||
) |
Get the suitable animation frame when unit is damaged.
Get the suitable animation frame when unit is damaged.
Return the unit not transported, by viewing the container recursively.
unit | unit from where look the first conatiner. |
Hit unit with damage, if destroyed give attacker the points.
Unit is hit by missile or other damage.
attacker | Unit that attacks. | |
target | Unit that is hit. | |
damage | How many damage to take. |
void InitUnits | ( | ) |
Initialize unit module.
Initialize unit module.
void LetUnitDie | ( | CUnit & | unit | ) |
Let a unit die.
Let an unit die.
unit | Unit to be destroyed. |
Create a new unit.
Create a new unit.
type | Pointer to unit-type. | |
player | Pointer to owning player. |
Create new unit and place on map.
pos | map tile position. | |
type | Pointer to unit-type. | |
player | Pointer to owning player. |
int MapDistanceBetweenTypes | ( | const CUnitType & | src, | |
const Vec2i & | pos1, | |||
const CUnitType & | dst, | |||
const Vec2i & | pos2 | |||
) |
Returns the map distance between two points with unit type.
src | src unittype | |
pos1 | map tile position of src (upperleft). | |
dst | Unit type to take into account. | |
pos2 | map tile position of dst. |
Returns the map distance between two points with unit type.
pos1 | map tile position. | |
type | Unit type to take into account. | |
pos2 | map tile position. |
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. |
static void MapMarkUnitSightRec | ( | const CUnit & | unit, | |
const Vec2i & | pos, | |||
int | width, | |||
int | height, | |||
MapMarkerFunc * | f, | |||
MapMarkerFunc * | f2 | |||
) | [static] |
(Un)Mark on vision table the Sight of the unit (and units inside for transporter (recursively))
unit | Unit to (un)mark. | |
pos | 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. | |
f2 | Function to (un)mark for cloaking vision. |
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. |
void MarkUnitFieldFlags | ( | const CUnit & | unit | ) |
Number of Units a team member has selected.
Mark the field with the FieldFlags.
unit | unit to mark. |
static int myatan | ( | int | val | ) | [static] |
Fast arc tangent function.
val | atan argument |
Find nearest point of unit.
unit | Pointer to unit. | |
pos | tile map postion. | |
dpos | Out: nearest point tile map postion to (tx,ty). |
static void RemoveUnitFromContainer | ( | CUnit & | unit | ) | [static] |
Last Y coordinate HelpMe sound played.
Remove unit from a container. It only updates linked list stuff.
unit | Pointer to unit. |
void RescueUnits | ( | ) |
Check for rescue each second.
Rescue units.
Look through all rescueable players, if they could be rescued.
void UnitClearOrders | ( | CUnit & | unit | ) |
Remove the Orders of a Unit.
Removes all orders from a unit.
unit | The unit that will have all its orders cleared |
void UnitCountSeen | ( | CUnit & | unit | ) |
Does a recount for VisCount.
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 |
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 |
Find Mining Area for 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. |
CUnit* UnitFindResource | ( | const CUnit & | unit, | |
int | x, | |||
int | y, | |||
int | range, | |||
int | resource, | |||
bool | check_usage, | |||
const CUnit * | destu | |||
) |
Find resource.
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. |
Call when an Unit goes out of fog.
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. |
Call when an Unit goes under 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. |
Change unit heading/frame from delta direction x, y.
unit | Unit for new direction looking. | |
delta | map tile delta direction. |
Affect Tile coord of a unit (with units inside) to tile (x, y).
unit | unit to move. | |
pos | map tile position. |
void UnitLost | ( | CUnit & | unit | ) |
Handle the loss of a unit (food,...).
Update information for lost units.
unit | Pointer to unit. |
Unit on map screen.
Select units on screen. (x, y are in pixels relative to map 0,0). Not GAMEPLAY safe, uses ReplayRevealMap
More units on same position. Cycle through units. ounit is the old one. First take highest unit.
ounit | Old selected unit. | |
x | X pixel position. | |
y | Y pixel position. |
void UnitsOnTileMarkSeen | ( | const CPlayer & | player, | |
int | x, | |||
int | y, | |||
int | cloak | |||
) |
Marks a unit as seen.
void UnitsOnTileMarkSeen | ( | const CPlayer & | player, | |
const unsigned int | index, | |||
int | cloak | |||
) |
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 | |
cloak | If we mark cloaked units too. |
void UnitsOnTileUnmarkSeen | ( | const CPlayer & | player, | |
int | x, | |||
int | y, | |||
int | cloak | |||
) |
Unmarks a unit as seen.
void UnitsOnTileUnmarkSeen | ( | const CPlayer & | player, | |
const unsigned int | index, | |||
int | cloak | |||
) |
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 | |
cloak | If this is for cloaked units. |
void UnitUpdateHeading | ( | CUnit & | unit | ) |
Update frame from heading.
Update sprite frame for new heading.
void UnmarkUnitFieldFlags | ( | const CUnit & | unit | ) |
Unmark the field with the FieldFlags.
Mark the field with the FieldFlags.
unit | unit to mark. |
void UpdateForNewUnit | ( | const CUnit & | unit, | |
int | upgrade | |||
) |
Update for new unit. Food and income ...
unit | New unit pointer. | |
upgrade | True unit was upgraded. |
void UpdateUnitSightRange | ( | CUnit & | unit | ) |
Update unit->CurrentSightRange.
Update the Unit Current sight range to good value and transported units inside.
unit | unit to update SightRange |
int ViewPointDistance | ( | const Vec2i & | pos | ) |
Compute the distance from the view point to a given point.
pos | map tile position. |
int ViewPointDistanceToUnit | ( | const CUnit & | dest | ) |
Calculate the distance from current view point to unit.
Compute the distance from the view point to a given unit.
dest | Distance to this unit. |
Config: training queues enabled.
bool EnableTrainingQueue |
Number of slots used.
Show orders for some time.
unsigned long HelpMeLastCycle [static] |
Config: reveal attacker enabled.
int HelpMeLastX [static] |
Last cycle HelpMe sound played.
int HelpMeLastY [static] |
Last X coordinate HelpMe sound played.
int NumUnits |
Array of used slots.
Units used.
bool RevealAttacker |
Config: capture buildings enabled.
Config: building capture enabled.