Debian Codegraph @

engine/include/missile.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name missile.h - The missile headerfile. */
11 //
12 // (c) Copyright 1998-2008 by Lutz Sammer
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27
28 #ifndef __MISSILE_H__
29 #define __MISSILE_H__
30
31 //@{
32
33 /*----------------------------------------------------------------------------
34 -- Documentation
35 ----------------------------------------------------------------------------*/
36
37 /**
38 ** @class MissileType missile.h
39 **
40 ** \#include "missile.h"
41 **
42 ** This structure defines the base type information of all missiles. It
43 ** contains all information that all missiles of the same type shares.
44 ** The fields are filled from the configuration files.
45 **
46 **
47 ** The missile-type structure members:
48 **
49 ** MissileType::Ident
50 **
51 ** Unique identifier of the missile-type, used to reference it in
52 ** config files and during startup.
53 ** @note Don't use this member in game, use instead the pointer
54 ** to this structure. See MissileTypeByIdent().
55 **
56 ** MissileType::DrawLevel
57 **
58 ** The Level/Order to draw the missile in, usually 0-255
59 **
60 ** MissileType::Width MissileType::Height
61 **
62 ** Size (width and height) of a frame in the image. All sprite
63 ** frames of the missile-type must have the same size.
64 **
65 ** MissileType::SpriteFrames
66 **
67 ** The number of animation steps, multiplied with
68 ** (MissileType::NumDirections / 2 - 1). Thus, if
69 ** MissileType::Flip == true, then MissileType::SpriteFrames is the
70 ** total number of sprite frames in the graphic image.
71 ** @note If the image is smaller than the number of directions,
72 ** width/height and/or framecount suggest the engine crashes.
73 **
74 ** MissileType::NumDirections
75 **
76 ** Number of directions missile can face.
77 **
78 ** MissileType::Transparency
79 **
80 ** Set a missile transparency. Current supported value is 50 only.
81 **
82 ** MissileType::FiredSound
83 **
84 ** Sound of the missile, if fired. @note currently not used.
85 **
86 ** MissileType::ImpactSound
87 **
88 ** Impact sound for this missile.
89 **
90 ** MissileType::CanHitOwner
91 **
92 ** Can hit the unit that have fired the missile.
93 ** @note Currently no missile can hurt its owner.
94 **
95 ** MissileType::FriendlyFire
96 **
97 ** Can't hit the units of the same player, that has the
98 ** missile fired.
99 **
100 ** MissileType::Class
101 **
102 ** Class of the missile-type, defines the basic effects of the
103 ** missile. Look at the different class identifiers for more
104 ** informations (::_missile_class_, ::MissileClassNone, ...).
105 **
106 ** MissileType::NumBounces
107 **
108 ** This is the number of bounces, and it is only valid with
109 ** MissileClassBounce. The missile will hit this many times in
110 ** a row.
111 **
112 ** MissileType::StartDelay
113 **
114 ** Delay in game cycles after the missile generation, until the
115 ** missile animation and effects starts. Delay denotes the number
116 ** of display cycles to skip before drawing the first sprite frame
117 ** and only happens once at start.
118 **
119 ** MissileType::Sleep
120 **
121 ** This are the number of game cycles to wait for the next
122 ** animation or the sleeping between the animation steps.
123 ** All animations steps use the same delay. 0 is the
124 ** fastest and 255 the slowest animation.
125 ** @note Perhaps we should later allow animation scripts for
126 ** more complex animations.
127 **
128 ** MissileType::Speed
129 **
130 ** The speed how fast the missile moves. 0 the missile didn't
131 ** move, 1 is the slowest speed and 32 s the fastest supported
132 ** speed. This is how many pixels the missiles moves with each
133 ** animation step. The real use of this member depends on the
134 ** MissileType::Class
135 ** @note This is currently only used by the point-to-point
136 ** missiles (::MissileClassPointToPoint, ...). Perhaps we should
137 ** later allow animation scripts for more complex animations.
138 **
139 ** MissileType::Range
140 **
141 ** Determines the range in which a projectile will deal its damage.
142 ** A range of 0 will mean that the damage will be limited to the
143 ** targetted unit only. So if you shot a missile at a unit, it
144 ** would only damage that unit. A value of 1 only affects the
145 ** field where the missile hits. A value of 2 would mean that
146 ** the damage for that particular missile would be dealt for a range
147 ** of 1 around the impact spot. All fields that aren't the center
148 ** get only 1/SpashFactor of the damage. Fields 2 away get
149 ** 1/(SplashFactor*2), and following...
150 **
151 ** MissileType::SplashFactor
152 **
153 ** Determines The Splash damage divisor, see Range
154 **
155 ** MissileType::ImpactName
156 **
157 ** The name of the next (other) missile to generate, when this
158 ** missile reached its end point or its life time is over. So it
159 ** can be used to generate a chain of missiles.
160 ** @note Used and should only be used during configuration and
161 ** startup.
162 **
163 ** MissileType::ImpactMissile
164 **
165 ** Pointer to the impact missile-type. Used during run time.
166 **
167 ** MissileType::SmokeName
168 **
169 ** The name of the next (other) missile to generate a trailing smoke. So it
170 ** can be used to generate a chain of missiles.
171 ** @note Used and should only be used during configuration and
172 ** startup.
173 **
174 ** MissileType::SmokeMissile
175 **
176 ** Pointer to the smoke missile-type. Used during run time.
177 **
178 ** MissileType::Sprite
179 **
180 ** Missile sprite image loaded from MissileType::File
181 **
182 ** MissileType::G
183 **
184 ** File containing the image (sprite) graphics of the missile.
185 ** The file can contain multiple sprite frames. The sprite frames
186 ** for the different directions are placed in the row.
187 ** The different animations steps are placed in the column. But
188 ** the correct order depends on MissileType::Class. Missiles like fire
189 ** have no directions, missiles like arrows have a direction.
190 */
191
192 /**
193 ** @class Missile missile.h
194 **
195 ** \#include "missile.h"
196 **
197 ** This structure contains all information about a missile in game.
198 ** A missile could have different effects, based on its missile-type.
199 ** Missiles could be saved and stored with CCL. See (missile).
200 ** Currently only a tile, a unit or a missile could be placed on the map.
201 **
202 **
203 ** The missile structure members:
204 **
205 ** Missile::X Missile::Y
206 **
207 ** Missile current map position in pixels. To convert a map tile
208 ** position to pixel position use: (mapx * ::TileSizeX + ::TileSizeX / 2)
209 ** and (mapy * ::TileSizeY + ::TileSizeY / 2)
210 ** @note ::TileSizeX % 2 == 0 && ::TileSizeY % 2 == 0
211 **
212 ** Missile::SourceX Missile::SourceY
213 **
214 ** Missile original map position in pixels. To convert a map tile
215 ** position to pixel position use: (mapx*::TileSizeX+::TileSizeX/2)
216 ** and (mapy*::TileSizeY+::TileSizeY/2)
217 ** @note ::TileSizeX%2==0 && ::TileSizeY%2==0 and ::TileSizeX,
218 ** ::TileSizeY are currently fixed 32 pixels.
219 **
220 ** Missile::DX Missile::DY
221 **
222 ** Missile destination on the map in pixels. If
223 ** Missile::X==Missile::DX and Missile::Y==Missile::DY the missile
224 ** stays at its position. But the movement also depends on
225 ** MissileType::Class.
226 **
227 ** Missile::Type
228 **
229 ** ::MissileType pointer of the missile, contains the shared
230 ** informations of all missiles of the same type.
231 **
232 ** Missile::SpriteFrame
233 **
234 ** Current sprite frame of the missile. The range is from
235 ** -MissileType::SpriteFrames to MissileType::SpriteFrames-1.
236 ** When MissileType::Flip is true (as usual), negative values
237 ** of Missile::SpriteFrame mean mirror the sprite in X direction;
238 ** the real frame number is then -Missile::SpriteFrame - 1.
239 ** When MissileType::Flip is false, Missile::SpriteFrame still
240 ** uses the same numbers as if MissileType::Flip were true,
241 ** and the engine maps these numbers to the real frame numbers
242 ** when it draws each missile.
243 **
244 ** Animation scripts aren't currently supported for missiles,
245 ** everything is handled by MissileType::Class
246 ** @note If wanted, we can add animation scripts support to the
247 ** engine.
248 **
249 ** Missile::State
250 **
251 ** Current state of the missile. Used for a simple state machine.
252 **
253 ** Missile::AnimWait
254 **
255 ** Animation wait. Used internally by missile actions, to run the
256 ** animation in parallel with the rest.
257 **
258 ** Missile::Wait
259 **
260 ** Wait this number of game cycles until the next state or
261 ** animation of this missile is handled. This counts down from
262 ** MissileType::Sleep to 0.
263 **
264 ** Missile::Delay
265 **
266 ** Number of game cycles the missile isn't shown on the map.
267 ** This counts down from MissileType::StartDelay to 0, before this
268 ** happens the missile isn't shown and has no effects.
269 ** @note This can also be used by MissileType::Class
270 ** for temporary removement of the missile.
271 **
272 ** Missile::SourceUnit
273 **
274 ** The owner of the missile. Normally the one who fired the
275 ** missile. Used to check units, to prevent hitting the owner
276 ** when field MissileType::CanHitOwner==true. Also used for kill
277 ** and experience points.
278 **
279 ** Missile::TargetUnit
280 **
281 ** The target of the missile. Normally the unit which should be
282 ** hit by the missile.
283 **
284 ** Missile::Damage
285 **
286 ** Damage done by missile. See also MissileType::Range, which
287 ** denoted the 100% damage in center.
288 **
289 ** Missile::TTL
290 **
291 ** Time to live in game cycles of the missile, if it reaches zero
292 ** the missile is automatic removed from the map. If -1 the
293 ** missile lives for ever and the lifetime is handled by
294 ** Missile::Type:MissileType::Class
295 **
296 ** Missile::Hidden
297 **
298 ** When you set this to 1 the unit becomes hidden for a while.
299 **
300 ** Missile::CurrentStep
301 **
302 ** Movement step. Used for the different trajectories.
303 **
304 ** Missile::TotalStep
305 **
306 ** Maximum number of step. When CurrentStep >= TotalStep, the movement is finished.
307 **
308 ** Missile::Local
309 **
310 ** This is a local missile, which can be different on all
311 ** computer in play. Used for the user interface (fe the green
312 ** cross).
313 **
314 ** Missile::MissileSlot
315 **
316 ** Pointer to the slot of this missile. Used for faster freeing.
317 */
318
319 /*----------------------------------------------------------------------------
320 -- Includes
321 ----------------------------------------------------------------------------*/
322
323 #include <vector>
324 #include "unitsound.h"
325
326 /*----------------------------------------------------------------------------
327 -- Declarations
328 ----------------------------------------------------------------------------*/
329
330 class CGraphic;
331 class CUnit;
332 class CViewport;
333 class CFile;
334 class LuaCallback;
335
336 /*----------------------------------------------------------------------------
337 -- Missile-type
338 ----------------------------------------------------------------------------*/
339
340 #define MAX_MISSILES 2048 /// maximum number of missiles
341
342 /**
343 ** Missile-type-class typedef
344 */
345 typedef int MissileClass;
346
347 /**
348 ** Missile-class this defines how a missile-type reacts.
349 **
350 */
351 enum _missile_class_ {
352 /// Missile does nothing
353 MissileClassNone,
354 /// Missile flies from x,y to x1,y1
355 MissileClassPointToPoint,
356 /// Missile flies from x,y to x1,y1 than shows hit animation.
357 MissileClassPointToPointWithHit,
358 /// Missile flies from x,y to x1,y1 and animates ONCE from start to finish and back
359 MissileClassPointToPointCycleOnce,
360 /// Missile flies from x,y to x1,y1 than bounces three times.
361 MissileClassPointToPointBounce,
362 /// Missile appears at x,y, does it's anim and vanishes.
363 MissileClassStay,
364 /// Missile appears at x,y, then cycle through the frames once.
365 MissileClassCycleOnce,
366 /// Missile doesn't move, than checks the source unit for HP.
367 MissileClassFire,
368 /// Missile shows the hit points.
369 MissileClassHit,
370 /// Missile flies from x,y to x1,y1 using a parabolic path
371 MissileClassParabolic,
372 };
373
374 /// Base structure of missile-types
375 class MissileType {
376 public:
377 MissileType(const std::string &ident);
378 ~MissileType();
379
380 /// load the graphics for a missile type
381 void LoadMissileSprite();
382 void Init(void);
383 void DrawMissileType(int frame, int x, int y) const;
384
385
386 std::string Ident; /// missile name
387 int Transparency; /// missile transparency
388 int Width; /// missile width in pixels
389 int Height; /// missile height in pixels
390 int DrawLevel; /// Level to draw missile at
391 int SpriteFrames; /// number of sprite frames in graphic
392 int NumDirections; /// number of directions missile can face
393
394 /// @todo FiredSound defined but not used!
395 SoundConfig FiredSound; /// fired sound
396 SoundConfig ImpactSound; /// impact sound for this missile-type
397
398 bool Flip; /// flip image when facing left
399 bool CanHitOwner; /// missile can hit the owner
400 bool FriendlyFire; /// missile can't hit own units
401
402 MissileClass Class; /// missile class
403 int NumBounces; /// number of bounces
404 int StartDelay; /// missile start delay
405 int Sleep; /// missile sleep
406 int Speed; /// missile speed
407
408 int Range; /// missile damage range
409 int SplashFactor; /// missile splash divisor
410 std::string ImpactName; /// impact missile-type name
411 MissileType *ImpactMissile;/// missile produces an impact
412 std::string SmokeName; /// impact missile-type name
413 MissileType *SmokeMissile; /// Trailling missile
414 LuaCallback *ImpactParticle; /// impact particle
415
416 // --- FILLED UP ---
417 CGraphic *G; /// missile graphic
418 };
419
420 /*----------------------------------------------------------------------------
421 -- Missile
422 ----------------------------------------------------------------------------*/
423
424 /// Missile on the map
425 class Missile {
426 protected:
427 Missile();
428
429 public:
430 virtual ~Missile() {};
431
432 static Missile *Init(MissileType *mtype, int sx, int sy, int dx, int dy);
433
434 virtual void Action() = 0;
435
436 void DrawMissile() const;
437 void SaveMissile(CFile *file) const;
438
439 int SourceX; /// Missile Source X
440 int SourceY; /// Missile Source Y
441 int X; /// missile pixel position
442 int Y; /// missile pixel position
443 int DX; /// missile pixel destination
444 int DY; /// missile pixel destination
445 MissileType *Type; /// missile-type pointer
446 int SpriteFrame; /// sprite frame counter
447 int State; /// state
448 int AnimWait; /// Animation wait.
449 int Wait; /// delay between frames
450 int Delay; /// delay to showup
451
452 CUnit *SourceUnit; /// unit that fires (could be killed)
453 CUnit *TargetUnit; /// target unit, used for spells
454
455 int Damage; /// direct damage that missile applies
456
457 int TTL; /// time to live (ticks) used for spells
458 int Hidden; /// If this is 1 then the missile is invisible
459
460 // Internal use:
461 int CurrentStep; /// Current step (0 <= x < TotalStep).
462 int TotalStep; /// Total step.
463
464 unsigned Local:1; /// missile is a local missile
465 unsigned int Slot; /// unique number for draw level.
466
467
468 static unsigned int Count; /// slot number generator.
469 };
470
471 class MissileNone : public Missile {
472 public:
473 virtual void Action();
474 };
475 class MissilePointToPoint : public Missile {
476 public:
477 virtual void Action();
478 };
479 class MissilePointToPointWithHit : public Missile {
480 public:
481 virtual void Action();
482 };
483 class MissilePointToPointCycleOnce : public Missile {
484 public:
485 virtual void Action();
486 };
487 class MissilePointToPointBounce : public Missile {
488 public:
489 virtual void Action();
490 };
491 class MissileStay : public Missile {
492 public:
493 virtual void Action();
494 };
495 class MissileCycleOnce : public Missile {
496 public:
497 virtual void Action();
498 };
499 class MissileFire : public Missile {
500 public:
501 virtual void Action();
502 };
503 class MissileHit : public Missile {
504 public:
505 virtual void Action();
506 };
507 class MissileParabolic : public Missile {
508 public:
509 virtual void Action();
510 };
511
512 class BurningBuildingFrame {
513 public:
514 BurningBuildingFrame() : Percent(0), Missile(NULL) {};
515
516 int Percent; /// HP percent
517 MissileType *Missile; /// Missile to draw
518 } ;
519
520 /*----------------------------------------------------------------------------
521 -- Variables
522 ----------------------------------------------------------------------------*/
523
524 extern std::vector<BurningBuildingFrame *> BurningBuildingFrames; /// Burning building frames
525
526 /*----------------------------------------------------------------------------
527 -- Functions
528 ----------------------------------------------------------------------------*/
529
530 // In script_missile.cpp
531
532 /// register ccl features
533 extern void MissileCclRegister(void);
534
535 // In missile.cpp
536
537 /// load all missile sprites
538 extern void LoadMissileSprites();
539 /// allocate an empty missile-type slot
540 extern MissileType *NewMissileTypeSlot(const std::string& ident);
541 /// Get missile-type by ident
542 extern MissileType *MissileTypeByIdent(const std::string& ident);
543 /// create a missile
544 extern Missile *MakeMissile(MissileType *mtype, int sx, int sy, int dx,
545 int dy);
546 /// create a local missile
547 extern Missile *MakeLocalMissile(MissileType *mtype, int sx, int sy, int dx,
548 int dy);
549 /// fire a missile
550 extern void FireMissile(CUnit *unit);
551
552 extern int FindAndSortMissiles(const CViewport *vp, Missile **table, int tablesize);
553
554 /// handle all missiles
555 extern void MissileActions(void);
556 /// distance from view point to missile
557 extern int ViewPointDistanceToMissile(const Missile *missile);
558
559 /// Get the burning building missile based on hp percent
560 extern MissileType *MissileBurningBuilding(int percent);
561
562 /// Save missiles
563 extern void SaveMissiles(CFile *file);
564
565 /// Initialize missile-types
566 extern void InitMissileTypes(void);
567 /// Clean missile-types
568 extern void CleanMissileTypes(void);
569 /// Initialize missiles
570 extern void InitMissiles(void);
571 /// Clean missiles
572 extern void CleanMissiles(void);
573
574 extern void FreeBurningBuildingFrames();
575
576
577 //@}
578
579 #endif // !__MISSILE_H__