_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

missile.cpp File Reference
#include <math.h>
#include "stratagus.h"
#include "missile.h"
#include "action/action_spellcast.h"
#include "actions.h"
#include "animation.h"
#include "font.h"
#include "iolib.h"
#include "luacallback.h"
#include "map.h"
#include "player.h"
#include "sound.h"
#include "spells.h"
#include "trigger.h"
#include "ui.h"
#include "unit.h"
#include "unit_find.h"
#include "unitsound.h"
#include "unittype.h"
#include "video.h"

missile.cpp - The missiles.

typedef std::map< std::string, MissileType * > MissileTypeMap
 all local missiles on map More...
 
static std::vector< Missile * > GlobalMissiles
 
static std::vector< Missile * > LocalMissiles
 all global missiles on map More...
 
static MissileTypeMap MissileTypes
 
std::vector< BurningBuildingFrame * > BurningBuildingFrames
 
NumberDescDamage
 Burning building frames. More...
 
void LoadMissileSprites ()
 load all missile sprites More...
 
MissileTypeMissileTypeByIdent (const std::string &ident)
 Get missile-type by ident. More...
 
MissileTypeNewMissileTypeSlot (const std::string &ident)
 allocate an empty missile-type slot More...
 
MissileMakeMissile (const MissileType &mtype, const PixelPos &startPos, const PixelPos &destPos)
 create a missile More...
 
MissileMakeLocalMissile (const MissileType &mtype, const PixelPos &startPos, const PixelPos &destPos)
 create a local missile More...
 
static int CalculateDamageStats (const CUnitStats &attacker_stats, const CUnitStats &goal_stats, int bloodlust)
 
int CalculateDamage (const CUnit &attacker, const CUnit &goal, const NumberDesc *formula)
 Calculates damage done to goal by attacker using formula. More...
 
void FireMissile (CUnit &unit, CUnit *goal, const Vec2i &goalPos)
 fire a missile More...
 
static void GetMissileMapArea (const Missile &missile, Vec2i &boxMin, Vec2i &boxMax)
 
static int MissileVisibleInViewport (const CViewport &vp, const Missile &missile)
 
static bool MissileDrawLevelCompare (const Missile *const l, const Missile *const r)
 
void FindAndSortMissiles (const CViewport &vp, std::vector< Missile * > &table)
 
bool MissileInitMove (Missile &missile, bool pointToPoint)
 
void MissileHandlePierce (Missile &missile, const Vec2i &pos)
 
bool MissileHandleBlocking (Missile &missile, const PixelPos &position)
 
bool PointToPointMissile (Missile &missile)
 
static void MissileHitsGoal (const Missile &missile, CUnit &goal, int splash)
 
static void MissileHitsWall (const Missile &missile, const Vec2i &tilePos, int splash)
 
static bool IsPiercedUnit (const Missile &missile, const CUnit &unit)
 
static void MissilesActionLoop (std::vector< Missile * > &missiles)
 
void MissileActions ()
 handle all missiles More...
 
int ViewPointDistanceToMissile (const Missile &missile)
 distance from view point to missile More...
 
MissileTypeMissileBurningBuilding (int percent)
 Get the burning building missile based on hp percent. More...
 
static void SavePixelPos (CFile &file, const PixelPos &pos)
 
void SaveMissiles (CFile &file)
 Save missiles. More...
 
void InitMissileTypes ()
 Initialize missile-types. More...
 
void CleanMissileTypes ()
 Clean missile-types. More...
 
void InitMissiles ()
 Initialize missiles. More...
 
void CleanMissiles ()
 Clean missiles. More...
 
void FreeBurningBuildingFrames ()
 

Typedef Documentation

◆ MissileTypeMap

typedef std::map<std::string, MissileType *> MissileTypeMap

all local missiles on map

lookup table for missile names

Function Documentation

◆ CalculateDamage()

int CalculateDamage ( const CUnit attacker,
const CUnit goal,
const NumberDesc formula 
)

Calculates damage done to goal by attacker using formula.

Calculate damage.

Parameters
attackerAttacker.
goalGoal unit.
formulaFormula used to calculate damage.
Returns
damage produces on goal.

◆ CalculateDamageStats()

static int CalculateDamageStats ( const CUnitStats attacker_stats,
const CUnitStats goal_stats,
int  bloodlust 
)
static

Calculate damage.

Todo:

NOTE: different targets (big are hit by some missiles better)

NOTE: lower damage for hidden targets.

NOTE: lower damage for targets on higher ground.

Parameters
attacker_statsAttacker attributes.
goal_statsGoal attributes.
bloodlustIf attacker has bloodlust
xpExperience of attacker.
Returns
damage inflicted to goal.

◆ CleanMissiles()

void CleanMissiles ( )

Clean missiles.

Clean up missiles.

◆ CleanMissileTypes()

void CleanMissileTypes ( )

Clean missile-types.

Clean up missile-types.

◆ FindAndSortMissiles()

void FindAndSortMissiles ( const CViewport vp,
std::vector< Missile * > &  table 
)

Sort visible missiles on map for display.

Parameters
vpViewport pointer.
tableOUT : array of missile to display sorted by DrawLevel.

◆ FireMissile()

void FireMissile ( CUnit unit,
CUnit goal,
const Vec2i goalPos 
)

fire a missile

Fire missile.

Parameters
unitUnit that fires the missile.

◆ FreeBurningBuildingFrames()

void FreeBurningBuildingFrames ( )

◆ GetMissileMapArea()

static void GetMissileMapArea ( const Missile missile,
Vec2i boxMin,
Vec2i boxMax 
)
static

Get area of tiles covered by missile

Parameters
missileMissile to be checked and set.
boxMinOUT: Pointer to top left corner in map tiles.
boxMaxOUT: Pointer to bottom right corner in map tiles.
Returns
sx,sy,ex,ey defining area in Map

◆ InitMissiles()

void InitMissiles ( )

Initialize missiles.

Initialize missiles.

◆ InitMissileTypes()

void InitMissileTypes ( )

Initialize missile-types.

Initialize missile-types.

◆ IsPiercedUnit()

static bool IsPiercedUnit ( const Missile missile,
const CUnit unit 
)
static

Check if missile has already pierced that unit

Parameters
missileCurrent missile.
unitTarget unit.
Returns
true if goal is pierced, false else.

◆ LoadMissileSprites()

void LoadMissileSprites ( )

load all missile sprites

Load the graphics for all missiles types

◆ MakeLocalMissile()

Missile* MakeLocalMissile ( const MissileType mtype,
const PixelPos startPos,
const PixelPos destPos 
)

create a local missile

Create a new local missile at (x,y).

Parameters
mtypeType pointer of missile.
startPosMissile start point in pixel.
destPosMissile destination point in pixel.
Returns
created missile.

◆ MakeMissile()

Missile* MakeMissile ( const MissileType mtype,
const PixelPos startPos,
const PixelPos destPos 
)

create a missile

Create a new global missile at (x,y).

Parameters
mtypeType pointer of missile.
startPosMissile start point in pixel.
destPosMissile destination point in pixel.
Returns
created missile.

◆ MissileActions()

void MissileActions ( )

handle all missiles

Handle all missile actions.

◆ MissileBurningBuilding()

MissileType* MissileBurningBuilding ( int  percent)

Get the burning building missile based on hp percent.

Get the burning building missile based on hp percent.

Parameters
percentHP percent
Returns
the missile used for burning.

◆ MissileDrawLevelCompare()

static bool MissileDrawLevelCompare ( const Missile *const  l,
const Missile *const  r 
)
static

◆ MissileHandleBlocking()

bool MissileHandleBlocking ( Missile missile,
const PixelPos position 
)

◆ MissileHandlePierce()

void MissileHandlePierce ( Missile missile,
const Vec2i pos 
)

◆ MissileHitsGoal()

static void MissileHitsGoal ( const Missile missile,
CUnit goal,
int  splash 
)
static

Missile hits the goal.

Parameters
missileMissile hitting the goal.
goalGoal of the missile.
splashSplash damage divisor.

◆ MissileHitsWall()

static void MissileHitsWall ( const Missile missile,
const Vec2i tilePos,
int  splash 
)
static

Missile hits wall.

Parameters
missileMissile hitting the goal.
tilePosWall map tile position.
splashSplash damage divisor.
Todo:
FIXME: Support for more races.

◆ MissileInitMove()

bool MissileInitMove ( Missile missile,
bool  pointToPoint 
)

Init the move.

Parameters
missilemissile to initialise for movement.
Returns
true if goal is reached, false else.

◆ MissilesActionLoop()

static void MissilesActionLoop ( std::vector< Missile * > &  missiles)
static

Handle all missile actions of global/local missiles.

Parameters
missilesTable of missiles.

◆ MissileTypeByIdent()

MissileType* MissileTypeByIdent ( const std::string &  ident)

Get missile-type by ident.

Get Missile type by identifier.

Parameters
identIdentifier.
Returns
Missile type pointer.

◆ MissileVisibleInViewport()

static int MissileVisibleInViewport ( const CViewport vp,
const Missile missile 
)
static

Check missile visibility in a given viewport.

Parameters
vpViewport to be checked.
missileMissile pointer to check if visible.
Returns
Returns true if visible, false otherwise.

◆ NewMissileTypeSlot()

MissileType* NewMissileTypeSlot ( const std::string &  ident)

allocate an empty missile-type slot

Allocate an empty missile-type slot.

Parameters
identIdentifier to identify the slot.
Returns
New allocated (zeroed) missile-type pointer.

◆ PointToPointMissile()

bool PointToPointMissile ( Missile missile)

Handle point to point missile.

Parameters
missileMissile pointer.
Returns
true if goal is reached, false else.

◆ SaveMissiles()

void SaveMissiles ( CFile file)

Save missiles.

Save the state missiles to file.

Parameters
fileOutput file.

◆ SavePixelPos()

static void SavePixelPos ( CFile file,
const PixelPos pos 
)
static

Save a specific pos.

◆ ViewPointDistanceToMissile()

int ViewPointDistanceToMissile ( const Missile missile)

distance from view point to missile

Calculate distance from view-point to missile.

Parameters
missileMissile pointer for distance.
Returns
the computed value.

Variable Documentation

◆ BurningBuildingFrames

std::vector<BurningBuildingFrame *> BurningBuildingFrames

◆ Damage

NumberDesc* Damage

Burning building frames.

Burning building frames.

◆ GlobalMissiles

std::vector<Missile *> GlobalMissiles
static

◆ LocalMissiles

std::vector<Missile *> LocalMissiles
static

all global missiles on map

◆ MissileTypes

MissileTypeMap MissileTypes
static
(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.