1 /***************************************************************************
2               projectile.h  -  Class representing a projectile
3                              -------------------
4     begin                : Sat May 3 2003
5     copyright            : (C) 2003 by Gabor Torok
6     email                : cctorok@yahoo.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef PROJECTILE_H
19 #define PROJECTILE_H
20 #pragma once
21 
22 #include <map>
23 #include <vector>
24 #include "render/renderedprojectile.h"
25 
26 class Creature;
27 class Item;
28 class Spell;
29 class Session;
30 class ProjectileRenderer;
31 
32 /**
33   *@author Gabor Torok
34   */
35 
36 /// Contains looks and attributes of an individual projectile.
37 class Projectile : public RenderedProjectile {
38 private:
39 	Creature *creature, *target;
40 	float tx, ty;
41 	int tw, td;
42 	Item *item;
43 	Spell *spell;
44 	std::vector<float> sx, sy;
45 	float ex, ey;
46 	float angle;
47 	float parabolic;
48 	int q;
49 	int cx, cy;
50 	int steps;
51 	ProjectileRenderer *renderer;
52 	float maxDist;
53 	float startX, startY, distToTarget;
54 	bool stopOnImpact;
55 	bool seeker;
56 	Uint32 timeToLive;
57 	bool reachedTarget;
58 	int casterLevel;
59 
60 	static Uint32 lastProjectileTick;
61 
62 public:
63 	Projectile( Creature *creature, Creature *target, Item *item, ProjectileRenderer *renderer, float parabolic = 0.0f, bool stopOnImpact = true, bool seeker = false );
64 	Projectile( Creature *creature, Creature *target, Spell *spell, ProjectileRenderer *renderer, float parabolic = 0.0f, bool stopOnImpact = true, bool seeker = false );
65 	Projectile( Creature *creature, int x, int y, int w, int d, Spell *spell, ProjectileRenderer *renderer, float parabolic = 0.0f, bool stopOnImpact = true );
66 	virtual ~Projectile();
67 
doesStopOnImpact()68 	inline bool doesStopOnImpact() {
69 		return stopOnImpact;
70 	}
71 
72 	// return true when out of moves
73 	bool move();
74 
setCasterLevel(int n)75 	inline void setCasterLevel( int n ) {
76 		casterLevel = n;
77 	}
getCasterLevel()78 	inline int getCasterLevel() {
79 		return casterLevel;
80 	}
81 
getStepCount()82 	inline int getStepCount() {
83 		return sx.size();
84 	}
getX(int index)85 	inline float getX( int index ) {
86 		return( index < 0 ? sx[0] : sx[ index ] );
87 	}
getY(int index)88 	inline float getY( int index ) {
89 		return( index < 0 ? sy[0] : sy[ index ] );
90 	}
getZ(int index)91 	inline float getZ( int index ) {
92 		return 0;
93 	}
getCurrentX()94 	inline float getCurrentX() {
95 		return sx.back();
96 	}
getCurrentY()97 	inline float getCurrentY() {
98 		return sy.back();
99 	}
getCurrentZ()100 	inline float getCurrentZ() {
101 		return 0;
102 	}
getAngle()103 	inline float getAngle() {
104 		return angle;
105 	}
getRenderer()106 	inline ProjectileRenderer *getRenderer() {
107 		return renderer;
108 	}
getCreature()109 	inline RenderedCreature *getCreature() {
110 		return ( RenderedCreature* )creature;
111 	}
getItem()112 	inline Item *getItem() {
113 		return item;
114 	}
getSpell()115 	inline Spell *getSpell() {
116 		return spell;
117 	}
118 
119 	static Projectile *addProjectile( Creature *creature, Creature *target,
120 	                                  Item *item, ProjectileRenderer *renderer,
121 	                                  int maxProjectiles, bool stopOnImpact = true );
122 	static Projectile *addProjectile( Creature *creature, Creature *target,
123 	                                  Spell *spell, ProjectileRenderer *renderer,
124 	                                  int maxProjectiles, bool stopOnImpact = true );
125 	static Projectile *addProjectile( Creature *creature, int x, int y, int w, int d,
126 	                                  Spell *spell, ProjectileRenderer *renderer,
127 	                                  int maxProjectiles, bool stopOnImpact = true );
128 	static void moveProjectiles( Session *session );
129 	bool atTargetLocation();
130 	void debug();
131 
132 protected:
133 	void commonInit();
134 	void calculateAngle( float sx, float sy );
135 };
136 
137 #endif
138