1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2006 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * Declares Projectile, class for supporting functionality of spell/item projectiles
24 * @author The GemRB Project
34 #include "PathFinder.h"
35 #include "CharAnimations.h" //contains MAX_ORIENT
38 //this is the height of the projectile when Spark Flag Fly = 1
40 //this is supposed to move the projectile to the background
45 #define P_TRAVEL 0 //projectile moves to target
46 #define P_TRIGGER 1 //projectile hovers over target, waits for trigger
47 #define P_EXPLODING1 2 //projectile explosion spreads
48 #define P_EXPLODING2 3 //projectile explosion repeats
49 #define P_EXPLODED 4 //projectile spread over area
50 #define P_EXPIRED 99 //projectile scheduled for removal (existing parts are still drawn)
52 //projectile spark flags
55 #define PSF_LOOPING 4 //looping sound
56 #define PSF_IGNORE_CENTER 16
58 //projectile travel flags
59 #define PTF_COLOUR 1 //fake colours
60 #define PTF_SMOKE 2 //has smoke
61 #define PTF_TINT 8 //tint projectile
62 #define PTF_SHADOW 32 //has shadow bam
63 #define PTF_LIGHT 64 //has light shadow
64 #define PTF_BLEND 128 //blend colours
66 //projectile extended travel flags (gemrb specific)
67 #define PEF_BOUNCE 1 //bounce from walls (lightning bolt)
68 #define PEF_CONTINUE 2 //continue as a travel projectile after trigger (lightning bolt)
69 #define PEF_FREEZE 4 //stay around (ice dagger)
70 #define PEF_NO_TRAVEL 8 //all instant projectiles (draw upon holy might, finger of death)
71 #define PEF_TRAIL 16 //trail bams facing value uses the same field as the travel projectile (otherwise it defaults to 9) (shout in iwd)
72 #define PEF_CURVE 32 //curved path (magic missile)
73 #define PEF_RANDOM 64 //random starting frame for animation (?)
74 #define PEF_PILLAR 128 //draw all cycles simultaneously on top of each other (call lightning, flamestrike)
75 #define PEF_HALFTRANS 256 //half-transparency (holy might)
76 #define PEF_TINT 512 //use palette gradient as tint
77 #define PEF_ITERATION 1024 //create another projectile of type-1 (magic missiles)
78 #define PEF_TILED 2048 //tiled AOE (bg1 cone of cold/fire)
79 #define PEF_FALLING 4096 //projectile falls down vertically (cow)
80 #define PEF_INCOMING 8192 //projectile falls in on trajectory (comet)
81 #define PEF_LINE 16384 //solid line between source and target (agannazar's scorcher)
82 #define PEF_WALL 32768 //solid line in front of source, crossing target (wall of fire)
83 #define PEF_BACKGROUND 0x10000 //draw under target,overrides flying (dimension door)
84 #define PEF_POP 0x20000 //draw travel bam, then shadow, then travel bam backwards
85 #define PEF_UNPOP 0x40000 //draw shadow, then travel bam (this is an internal flag)
86 #define PEF_FADE 0x80000 //gradually fade on spot if used with PEF_FREEZE (ice dagger)
87 #define PEF_TEXT 0x100000//display text during setup
88 #define PEF_WANDERING 0x200000//random movement (no real path)
89 #define PEF_CYCLE 0x400000//random cycle
90 #define PEF_RGB 0x800000//rgb pulse on hit
92 //projectile area flags
93 #define PAF_VISIBLE 1 //the travel projectile is visible until explosion
94 #define PAF_INANIMATE 2 //target inanimates
95 #define PAF_TRIGGER 4 //explosion needs to be triggered
96 #define PAF_SYNC 8 //one explosion at a time
97 #define PAF_SECONDARY 16 //secondary projectiles at explosion
98 #define PAF_FRAGMENT 32 //fragments (charanimation) at explosion
99 #define PAF_ENEMY 64 //target party or not party
100 #define PAF_PARTY 128 //target party
101 #define PAF_TARGET (64|128)
103 #define PAF_CONE 2048
104 #define PAF_DELAY 0x4000
105 #define PAF_AFFECT_ONE 0x8000
108 //area projectile flags (in areapro.2da)
109 //this functionality was hardcoded in the original engine, so the bit flags are
110 //completely arbitrary (i assign them as need arises)
111 //child projectiles need to be tinted (example: stinking cloud, counter example: fireball)
113 //child projectiles fill the whole area (example: stinking cloud, counter example: fireball)
115 //child projectiles start in their destination (example: icestorm, counter example: fireball)
116 #define APF_SCATTER 4
117 //the explosion vvc has gradient (example: icestorm, counter example: fireball)
119 //there is an additional added scatter after the initial spreading ring
120 #define APF_SPREAD 16
121 //the spread projectile needs gradient colouring,not tint (example:web, counter example: stinking cloud)
122 #define APF_PALETTE 32
123 //use both animations in the spread
125 //more child projectiles
127 //apply spell on caster if failed to find target
128 #define APF_SPELLFAIL 256
130 struct ProjectileExtension
133 ieWord TriggerRadius
;
134 ieWord ExplosionRadius
;
135 ieResRef SoundRes
; //used for areapro.2da explosion sound
139 ieByte ExplosionCount
;
143 ieResRef VVCRes
; //used for areapro.2da second resref (center animation)
145 //these are GemRB specific (from areapro.2da)
146 ieDword APFlags
; //areapro.2da flags
147 ieResRef Spread
; //areapro.2da first resref
148 ieResRef Secondary
; //areapro.2da third resref
149 ieResRef AreaSound
; //areapro.2da second sound resource
152 class GEM_EXPORT Projectile
157 void InitExtension();
184 ieResRef TrailBAM
[3];
185 ieWord TrailSpeed
[3];
186 //these are public but not in the .pro file
187 ProjectileExtension
* Extension
;
193 ieDword timeStartStep
;
194 //attributes from moveable object
195 unsigned char Orientation
, NewOrientation
;
196 PathNode
* path
; //whole path
197 PathNode
* step
; //actual step
198 //similar to normal actors
203 ieDword Caster
; //the globalID of the caster actor
204 ieDword Target
; //the globalID of target actor
209 //these come from the extension area
211 int extension_explosioncount
;
214 //special (not using char animations)
215 Animation
* travel
[MAX_ORIENT
];
216 Animation
* shadow
[MAX_ORIENT
];
217 Sprite2D
* light
;//this is just a round/halftrans sprite, has no animation
218 EffectQueue
* effects
;
219 Projectile
**children
;
223 void SetCaster(ieDword t
);
225 void SetTarget(ieDword t
);
226 void SetTarget(Point
&p
);
227 bool PointInRadius(Point
&p
);
230 //inliners to protect data consistency
231 inline PathNode
* GetNextStep() {
233 DoStep((unsigned int) ~0);
238 inline Point
GetDestination() const { return Destination
; }
239 inline const char * GetName() const { return name
; }
240 inline ieWord
GetType() const { return type
; }
241 //This assumes that the effect queue cannot be bigger than 65535
242 //which is a sane expectation
243 inline EffectQueue
*GetEffects() {
247 inline unsigned char GetOrientation() const {
250 //no idea if projectiles got height, using y
251 inline int GetHeight() const {
252 //if projectile is drawn behind target
253 if (ExtFlags
&PEF_BACKGROUND
) {
254 return Pos
.y
-BACK_DEPTH
;
257 //if projectile is flying
258 if (SFlags
&PSF_FLYING
) {
259 return Pos
.y
+FLY_HEIGHT
;
264 void SetIdentifiers(const char *name
, ieWord type
);
266 void SetEffectsCopy(EffectQueue
*eq
);
268 //don't forget to set effects to NULL when the projectile discharges
269 //unexploded projectiles are responsible to destruct their payload
271 inline void SetEffects(EffectQueue
*fx
) {
275 inline unsigned char GetNextFace() {
277 if (Orientation
!= NewOrientation
) {
278 if ( ( (NewOrientation
-Orientation
) & (MAX_ORIENT
-1) ) <= MAX_ORIENT
/2) {
283 Orientation
= Orientation
&(MAX_ORIENT
-1);
289 inline void SetOrientation(int value
, bool slow
) {
290 //MAX_ORIENT == 16, so we can do this
291 NewOrientation
= (unsigned char) (value
&(MAX_ORIENT
-1));
293 Orientation
= NewOrientation
;
298 //sets how long a created travel projectile will hover over a spot
299 //before vanishing (without the need of area extension)
300 void SetDelay(int delay
);
301 void MoveTo(Map
*map
, Point
&Des
);
303 //handle phases, return 0 when expired
306 void Draw(Region
&screen
);
307 void SetGradient(int gradient
, bool tint
);
308 void StaticTint(Color
&newtint
);
310 //creates a child projectile with current_projectile_id - 1
311 void CreateIteration();
312 void CreateAnimations(Animation
**anims
, const ieResRef bam
, int Seq
);
313 //pillar type animations
314 void CreateCompositeAnimation(Animation
**anims
, AnimationFactory
*af
, int Seq
);
315 //oriented animations (also simple ones)
316 void CreateOrientedAnimations(Animation
**anims
, AnimationFactory
*af
, int Seq
);
317 void GetPaletteCopy(Animation
*anim
[], Palette
*&pal
);
323 void AddTrail(ieResRef BAM
, const ieByte
*pal
);
324 void DoStep(unsigned int walk_speed
);
325 void LineTarget(); //line projectiles (walls, scorchers)
326 void SecondaryTarget(); //area projectiles (circles, cones)
327 void CheckTrigger(unsigned int radius
);
329 void DrawLine(Region
&screen
, int face
, ieDword flag
);
330 void DrawTravel(Region
&screen
);
331 bool DrawChildren(Region
&screen
);
332 void DrawExplosion(Region
&screen
);
333 void DrawExploded(Region
&screen
);
334 int GetTravelPos(int face
);
335 int GetShadowPos(int face
);
336 void SetPos(int face
, int frame1
, int frame2
);
337 //logic to resolve target when single projectile hit destination
338 int CalculateTargetFlag();
340 void NextTarget(Point
&p
);
341 void SetupPalette(Animation
*anim
[], Palette
*&pal
, const ieByte
*gradients
);
344 #endif // PROJECTILE_H