____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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 <math.h>
#include "stratagus.h"
#include <vector>
#include <string>
#include <map>
#include "video.h"
#include "font.h"
#include "map.h"
#include "unitsound.h"
#include "unittype.h"
#include "unit_cache.h"
#include "player.h"
#include "unit.h"
#include "missile.h"
#include "sound.h"
#include "ui.h"
#include "iolib.h"
#include "particle.h"
#include "trigger.h"
#include "luacallback.h"
Go to the source code of this file.
Defines | |
| #define | BoundX(x) std::min(std::max(0, x), Map.Info.MapWidth - 1) |
| #define | BoundY(y) std::min(std::max(0, y), Map.Info.MapHeight - 1) |
Functions | |
| void | LoadMissileSprites (void) |
| < load all missile sprites | |
| MissileType * | MissileTypeByIdent (const std::string &ident) |
| create a missile | |
| MissileType * | NewMissileTypeSlot (const std::string &ident) |
| Get missile-type by ident. | |
| Missile * | MakeMissile (MissileType *mtype, int sx, int sy, int dx, int dy) |
| create a local missile | |
| Missile * | MakeLocalMissile (MissileType *mtype, int sx, int sy, int dx, int dy) |
| fire a missile | |
| static void | FreeMissile (std::vector< Missile * > &missiles, size_t i) |
| static int | CalculateDamage (const CUnit *attacker, const CUnit *goal) |
| void | FireMissile (CUnit *unit) |
| static void | GetMissileMapArea (const Missile *missile, int *sx, int *sy, int *ex, int *ey) |
| static int | MissileVisibleInViewport (const CViewport *vp, const Missile *missile) |
| static int | MissileDrawLevelCompare (const void *v1, const void *v2) |
| int | FindAndSortMissiles (const CViewport *vp, Missile **table, int tablesize) |
| handle all missiles | |
| static void | MissileNewHeadingFromXY (Missile *missile, int dx, int dy) |
| static int | MissileInitMove (Missile *missile) |
| static int | PointToPointMissile (Missile *missile) |
| static int | ParabolicMissile (Missile *missile) |
| static void | MissileHitsGoal (const Missile *missile, CUnit *goal, int splash) |
| void | MissileHit (Missile *missile) |
| static int | NextMissileFrame (Missile *missile, char sign, char longAnimation) |
| static void | NextMissileFrameCycle (Missile *missile) |
| static void | MissilesActionLoop (std::vector< Missile * > &missiles) |
| void | MissileActions (void) |
| distance from view point to missile | |
| int | ViewPointDistanceToMissile (const Missile *missile) |
| Get the burning building missile based on hp percent. | |
| MissileType * | MissileBurningBuilding (int percent) |
| Save missiles. | |
| void | SaveMissiles (CFile *file) |
| Initialize missile-types. | |
| void | InitMissileTypes (void) |
| Clean missile-types. | |
| void | CleanMissileTypes (void) |
| Initialize missiles. | |
| void | InitMissiles (void) |
| Clean missiles. | |
| void | CleanMissiles (void) |
Variables | |
| static std::vector< MissileType * > | MissileTypes |
| Missile types. | |
| static std::vector< Missile * > | GlobalMissiles |
| all global missiles on map | |
| static std::vector< Missile * > | LocalMissiles |
| all local missiles on map | |
| static std::map< std::string, MissileType * > | MissileTypeMap |
| std::vector < BurningBuildingFrame * > | BurningBuildingFrames |
| Burning building frames. | |
Definition in file missile.cpp.
| #define BoundX | ( | x | ) | std::min(std::max(0, x), Map.Info.MapWidth - 1) |
Referenced by GetMissileMapArea().
Referenced by GetMissileMapArea().
Calculate damage.
| attacker | Attacker. | |
| goal | Goal unit. |
Definition at line 297 of file missile.cpp.
References ARMOR_INDEX, Assert, BASICDAMAGE_INDEX, PIERCINGDAMAGE_INDEX, CUnit::Stats, SyncRand(), CVariable::Value, and CUnitStats::Variables.
Referenced by FireMissile(), and MissileHitsGoal().
| void CleanMissiles | ( | void | ) |
Clean up missiles.
Definition at line 1179 of file missile.cpp.
References GlobalMissiles, and LocalMissiles.
Referenced by CleanGame(), and CleanModules().
| void CleanMissileTypes | ( | void | ) |
Initialize missiles.
Clean up missile-types.
Definition at line 1160 of file missile.cpp.
References MissileTypeMap, and MissileTypes.
Referenced by CleanModules().
handle all missiles
Sort visible missiles on map for display.
| vp | Viewport pointer. | |
| table | OUT : array of missile to display sorted by DrawLevel. | |
| tablesize | Size of table array |
Definition at line 563 of file missile.cpp.
References GlobalMissiles, LocalMissiles, MissileDrawLevelCompare(), and MissileVisibleInViewport().
Referenced by CViewport::Draw().
| void FireMissile | ( | CUnit * | unit | ) |
Fire missile.
| unit | Unit that fires the missile. |
Definition at line 319 of file missile.cpp.
References _C_, Assert, CalculateDamage(), MissileType::Class, CUnit::Container, DebugPrint, CUnit::Destroyed, HitUnit(), MakeMissile(), MapDistanceBetweenUnits(), CUnitType::MinAttackRange, MissileConfig::Missile, CUnitType::Missile, MissileClassNone, NearestOfUnit(), CUnit::Orders, CUnit::RefsIncrease(), CUnit::Removed, Missile::SourceUnit, Missile::TargetUnit, TileSizeX, TileSizeY, CUnit::Type, UnitActionDie, CUnit::X, CUnit::Y, and y.
Referenced by AnimateActionAttack(), and UnitShowAnimationScaled().
| static void FreeMissile | ( | std::vector< Missile * > & | missiles, | |
| size_t | i | |||
| ) | [static] |
Free a missile.
| missiles | Missile pointer. | |
| i | Index in missiles of missile to free |
Definition at line 261 of file missile.cpp.
References CUnit::RefsDecrease(), Missile::SourceUnit, and Missile::TargetUnit.
Referenced by MissilesActionLoop().
| static void GetMissileMapArea | ( | const Missile * | missile, | |
| int * | sx, | |||
| int * | sy, | |||
| int * | ex, | |||
| int * | ey | |||
| ) | [static] |
Get area of tiles covered by missile
| missile | Missile to be checked and set. | |
| sx | OUT: Pointer to X of top left corner in map tiles. | |
| sy | OUT: Pointer to Y of top left corner in map tiles. | |
| ex | OUT: Pointer to X of bottom right corner in map tiles. | |
| ey | OUT: Pointer to Y of bottom right corner in map tiles. |
Definition at line 422 of file missile.cpp.
References BoundX, BoundY, MissileType::Height, TileSizeX, TileSizeY, Missile::Type, MissileType::Width, Missile::X, and Missile::Y.
Referenced by MissileVisibleInViewport().
| void InitMissiles | ( | void | ) |
Clean missiles.
Initialize missiles.
Definition at line 1172 of file missile.cpp.
Referenced by InitModules().
| void InitMissileTypes | ( | void | ) |
Clean missile-types.
Initialize missile-types.
Definition at line 1128 of file missile.cpp.
References MissileTypes.
Referenced by CreateGame(), and InitModules().
| void LoadMissileSprites | ( | void | ) |
< load all missile sprites
Load the graphics for all missiles types
Definition at line 104 of file missile.cpp.
References MissileTypes.
Referenced by CreateGame(), and LoadModules().
| Missile* MakeLocalMissile | ( | MissileType * | mtype, | |
| int | sx, | |||
| int | sy, | |||
| int | dx, | |||
| int | dy | |||
| ) |
fire a missile
Create a new local missile at (x,y).
| mtype | Type pointer of missile. | |
| sx | Missile x start point in pixel. | |
| sy | Missile y start point in pixel. | |
| dx | Missile x destination point in pixel. | |
| dy | Missile y destination point in pixel. |
Definition at line 245 of file missile.cpp.
References Missile::Init(), Missile::Local, and LocalMissiles.
Referenced by CclMissile(), HitUnit(), UIHandleButtonDown(), and UISelectStateButtonDown().
| Missile* MakeMissile | ( | MissileType * | mtype, | |
| int | sx, | |||
| int | sy, | |||
| int | dx, | |||
| int | dy | |||
| ) |
create a local missile
Create a new global missile at (x,y).
| mtype | Type pointer of missile. | |
| sx | Missile x start point in pixel. | |
| sy | Missile y start point in pixel. | |
| dx | Missile x destination point in pixel. | |
| dy | Missile y destination point in pixel. |
Definition at line 225 of file missile.cpp.
References GlobalMissiles, and Missile::Init().
Referenced by SpawnMissile::Cast(), AreaBombardment::Cast(), CclMissile(), FireMissile(), HitUnit(), LetUnitDie(), MissileHit(), ParabolicMissile(), and PointToPointMissile().
| void MissileActions | ( | void | ) |
distance from view point to missile
Handle all missile actions.
Definition at line 1013 of file missile.cpp.
References GlobalMissiles, LocalMissiles, and MissilesActionLoop().
Referenced by GameMainLoop().
| MissileType* MissileBurningBuilding | ( | int | percent | ) |
Save missiles.
Get the burning building missile based on hp percent.
| percent | HP percent |
Definition at line 1041 of file missile.cpp.
References BurningBuildingFrames.
Referenced by MissileFire::Action(), and HitUnit().
| static int MissileDrawLevelCompare | ( | const void * | v1, | |
| const void * | v2 | |||
| ) | [static] |
Compare Draw level. Used by qsort.
| v1 | adress of a missile pointer. | |
| v2 | adress of a missile pointer. |
Definition at line 540 of file missile.cpp.
References MissileType::DrawLevel, Missile::Slot, and Missile::Type.
Referenced by FindAndSortMissiles().
| void MissileHit | ( | Missile * | missile | ) |
Work for missile hit.
| missile | Missile reaching end-point. |
Definition at line 782 of file missile.cpp.
References Assert, CanTarget(), DebugPrint, CUnit::Destroyed, MissileType::Height, MissileType::ImpactMissile, MissileType::ImpactParticle, MissileType::ImpactSound, CMap::Info, MakeMissile(), Map, MapDistanceToUnit(), CMapInfo::MapHeight, CMapInfo::MapWidth, MissileHitsGoal(), NoUnitP, PlayMissileSound(), LuaCallback::pushInteger(), LuaCallback::pushPreamble(), MissileType::Range, CUnit::RefsDecrease(), LuaCallback::run(), CUnitCache::Select(), SoundConfig::Sound, Missile::SourceUnit, MissileType::SplashFactor, Missile::TargetUnit, TileSizeX, TileSizeY, CUnit::Type, Missile::Type, UnitCache, UnitMax, MissileType::Width, Missile::X, Missile::Y, and y.
Referenced by MissileParabolic::Action(), MissileHit::Action(), MissileCycleOnce::Action(), MissilePointToPointBounce::Action(), MissileStay::Action(), MissilePointToPointCycleOnce::Action(), MissilePointToPointWithHit::Action(), and MissilePointToPoint::Action().
Missile hits the goal.
| missile | Missile hitting the goal. | |
| goal | Goal of the missile. | |
| splash | Splash damage divisor. |
Definition at line 760 of file missile.cpp.
References Assert, CalculateDamage(), MissileType::CanHitOwner, Missile::Damage, HitUnit(), CUnit::Orders, Missile::SourceUnit, Missile::Type, and UnitActionDie.
Referenced by MissileHit().
| static int MissileInitMove | ( | Missile * | missile | ) | [static] |
Init the move.
| missile | missile to initialise for movement. |
Definition at line 640 of file missile.cpp.
References Assert, Missile::CurrentStep, Missile::DX, Missile::DY, MapDistance(), MissileNewHeadingFromXY(), Missile::SourceX, Missile::SourceY, MissileType::Speed, Missile::State, Missile::TotalStep, Missile::Type, Missile::X, and Missile::Y.
Referenced by ParabolicMissile(), and PointToPointMissile().
| static void MissileNewHeadingFromXY | ( | Missile * | missile, | |
| int | dx, | |||
| int | dy | |||
| ) | [static] |
Change missile heading from x,y.
| missile | Missile pointer. | |
| dx | Delta in x. | |
| dy | Delta in y. |
Definition at line 603 of file missile.cpp.
References Assert, DirectionToHeading(), LookingS, MissileType::NumDirections, Missile::SpriteFrame, and Missile::Type.
Referenced by MissileInitMove(), and ParabolicMissile().
| static void MissilesActionLoop | ( | std::vector< Missile * > & | missiles | ) | [static] |
Handle all missile actions of global/local missiles.
| missiles | Table of missiles. |
Definition at line 972 of file missile.cpp.
References Assert, Missile::Delay, FreeMissile(), Missile::TTL, and Missile::Wait.
Referenced by MissileActions().
| MissileType* MissileTypeByIdent | ( | const std::string & | ident | ) |
create a missile
Get Missile type by identifier.
| ident | Identifier. |
Definition at line 117 of file missile.cpp.
References MissileTypeMap.
Referenced by CclDefineBurningBuilding(), CclDefineMissileType(), CclMissile(), CclSpellAction(), HitUnit(), MissileType::Init(), LoadUnitTypes(), UIHandleButtonDown(), and UISelectStateButtonDown().
Check missile visibility in a given viewport.
| vp | Viewport to be checked. | |
| missile | Missile pointer to check if visible. |
Definition at line 445 of file missile.cpp.
References CViewport::AnyMapAreaVisibleInViewport(), GetMissileMapArea(), CMap::IsFieldVisible(), Map, ReplayRevealMap, ThisPlayer, and y.
Referenced by FindAndSortMissiles().
| MissileType* NewMissileTypeSlot | ( | const std::string & | ident | ) |
Get missile-type by ident.
Allocate an empty missile-type slot.
| ident | Identifier to identify the slot. |
Definition at line 129 of file missile.cpp.
References MissileType::MissileType(), MissileTypeMap, and MissileTypes.
Referenced by CclDefineMissileType().
| static int NextMissileFrame | ( | Missile * | missile, | |
| char | sign, | |||
| char | longAnimation | |||
| ) | [static] |
Pass to the next frame for animation.
| missile | missile to animate. | |
| sign | 1 for next frame, -1 for previous frame. | |
| longAnimation | 1 if Frame is conditionned by covered distance, 0 else. |
Definition at line 878 of file missile.cpp.
References Missile::DX, Missile::DY, MapDistance(), MissileType::NumDirections, Missile::SourceX, Missile::SourceY, Missile::SpriteFrame, MissileType::SpriteFrames, Missile::Type, Missile::X, and Missile::Y.
Referenced by MissileFire::Action(), MissileCycleOnce::Action(), MissilePointToPointBounce::Action(), MissileStay::Action(), MissilePointToPointWithHit::Action(), and MissilePointToPoint::Action().
| static void NextMissileFrameCycle | ( | Missile * | missile | ) | [static] |
Pass the next frame of the animation. This animation goes from start to finish ONCE on the way
| missile | Missile pointer. |
Definition at line 934 of file missile.cpp.
References Missile::DX, MissileType::NumDirections, Missile::SourceX, Missile::SpriteFrame, MissileType::SpriteFrames, Missile::Type, and Missile::X.
Referenced by MissileParabolic::Action(), and MissilePointToPointCycleOnce::Action().
| static int ParabolicMissile | ( | Missile * | missile | ) | [static] |
Calculate parabolic trajectories.
| missile | Missile pointer. |
Definition at line 710 of file missile.cpp.
References Assert, Missile::CurrentStep, Missile::DX, Missile::DY, MissileType::Height, MakeMissile(), MissileInitMove(), MissileNewHeadingFromXY(), MissileType::SmokeMissile, Missile::SourceX, Missile::SourceY, Missile::TotalStep, Missile::Type, MissileType::Width, Missile::X, Missile::Y, and y.
Referenced by MissileParabolic::Action().
| static int PointToPointMissile | ( | Missile * | missile | ) | [static] |
Handle point to point missile.
| missile | Missile pointer. |
Definition at line 676 of file missile.cpp.
References Assert, Missile::CurrentStep, Missile::DX, Missile::DY, MissileType::Height, MakeMissile(), MissileInitMove(), MissileType::SmokeMissile, Missile::SourceX, Missile::SourceY, Missile::TotalStep, Missile::Type, MissileType::Width, Missile::X, Missile::Y, and y.
Referenced by MissileHit::Action(), MissilePointToPointBounce::Action(), MissilePointToPointCycleOnce::Action(), MissilePointToPointWithHit::Action(), and MissilePointToPoint::Action().
| void SaveMissiles | ( | CFile * | file | ) |
Initialize missile-types.
Save the state missiles to file.
| file | Output file. |
Definition at line 1092 of file missile.cpp.
References GlobalMissiles, LocalMissiles, and CFile::printf().
Referenced by SaveGame().
| int ViewPointDistanceToMissile | ( | const Missile * | missile | ) |
Get the burning building missile based on hp percent.
Calculate distance from view-point to missle.
| missile | Missile pointer for distance. |
Definition at line 1026 of file missile.cpp.
References MissileType::Height, TileSizeX, TileSizeY, Missile::Type, ViewPointDistance(), MissileType::Width, Missile::X, Missile::Y, and y.
Referenced by PlayMissileSound().
| std::vector<BurningBuildingFrame *> BurningBuildingFrames |
Burning building frames.
Definition at line 77 of file missile.cpp.
Referenced by CclDefineBurningBuilding(), and MissileBurningBuilding().
std::vector<Missile*> GlobalMissiles [static] |
all global missiles on map
Definition at line 71 of file missile.cpp.
Referenced by CleanMissiles(), FindAndSortMissiles(), MakeMissile(), MissileActions(), and SaveMissiles().
std::vector<Missile*> LocalMissiles [static] |
all local missiles on map
lookup table for missile names
Definition at line 72 of file missile.cpp.
Referenced by CleanMissiles(), FindAndSortMissiles(), MakeLocalMissile(), MissileActions(), and SaveMissiles().
std::map<std::string, MissileType *> MissileTypeMap [static] |
Definition at line 75 of file missile.cpp.
Referenced by CleanMissileTypes(), MissileTypeByIdent(), and NewMissileTypeSlot().
std::vector<MissileType *> MissileTypes [static] |
Missile types.
Definition at line 69 of file missile.cpp.
Referenced by CleanMissileTypes(), InitMissileTypes(), LoadMissileSprites(), and NewMissileTypeSlot().
1.5.6