1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3 
4 This file is part of Aquaria.
5 
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 #ifndef SHOT_H
22 #define SHOT_H
23 
24 #include "CollideEntity.h"
25 #include "Segmented.h"
26 #include "../BBGE/Particles.h"
27 #include "../BBGE/ScriptObject.h"
28 
29 struct ShotData
30 {
31 	ShotData();
32 	std::string texture, name;
33 	std::string hitSfx, bounceSfx, fireSfx;
34 	std::string hitPrt, trailPrt, firePrt, bouncePrt;
35 	std::string spawnEntity;
36 	BounceType bounceType;
37 	int blendType;
38 	bool segments;
39 	float damage;
40 	float maxSpeed, homing, homingMax;
41 	double homingIncr;
42 	DamageType damageType;
43 	Vector scale;
44 
45 	bool ignoreShield;
46 	bool dieOnKill;
47 
48 	float effectTime;
49 
50 	float collideRadius;
51 	float lifeTime;
52 
53 	int numSegs, segDist;
54 	int dieOnHit;
55 	int rotateToVel;
56 	int wallHitRadius;
57 	Vector segScale;
58 	std::string segTexture;
59 	float segTaper;
60 
61 	float waveSpeed, waveMag;
62 
63 	float spinSpeed;
64 	bool invisible, checkDamageTarget, hitWalls, hitEnts, alwaysDoHitEffects;
65 	float rotIncr;
66 
67 	float avatarKickBack, avatarKickBackTime;
68 
69 	Vector gravity;
70 
71 	void bankLoad(const std::string &file, const std::string &path);
72 
73 };
74 
75 class Shot : public Quad, public Segmented
76 {
77 public:
78 	//Shot(DamageType damageType, Entity *firer, Vector pos, Entity *target, std::string tex="", float homingness=1000, int maxSpeed=400, int segments=10, float segMin=0.1, float segMax=5, float damage = 1, float lifeTime = 0);
79 	Shot();
80 	//void destroy();
81 	void reflectFromEntity(Entity *e);
82 	void setParticleEffect(const std::string &particleEffect);
83 	typedef std::vector<Shot*> Shots;
84 	static Shots shots, deleteShots;
85 	static unsigned int shotsIter; // for script
getFirstShot()86 	static Shot *getFirstShot() { shotsIter = 0; return getNextShot(); }
getNextShot()87 	static Shot *getNextShot() { return shotsIter < shots.size() ? shots[shotsIter++] : NULL; }
88 	static std::string shotBankPath;
89 	static void targetDied(Entity *t);
90 	static void killAllShots();
91 	static void clearShotGarbage();
92 	Entity *target, *firer;
93 	int targetPt;
94 	float maxSpeed;
95 
96 	void fire(bool playSfx = true);
97 	void hitEntity(Entity *e, Bone *b);
98 
99 	void noSegs();
100 
101 	void rotateToVec(Vector addVec, float time, int offsetAngle);
102 	void doHitEffects();
103 
104 	typedef std::map<std::string, ShotData> ShotBank;
105 	static ShotBank shotBank;
106 
107 
108 	static void loadShotBank(const std::string &bank1, const std::string &bank2);
109 	static void clearShotBank();
110 	static ShotData* getShotData(const std::string &ident);
111 	static void loadBankShot(const std::string &ident, Shot *shot);
112 	void applyShotData(ShotData *shotData);
113 
114 	void setAimVector(const Vector &aim);
115 	void setTarget(Entity *target);
116 	void setTargetPoint(int pt);
117 	float getDamage() const;
118 	int getCollideRadius() const;
119 	DamageType getDamageType() const;
120 	ShotData *shotData;
121 	void updatePosition();
122 	bool isHitEnts() const;
123 	bool isObstructed(float dt) const;
isActive()124 	inline bool isActive() const { return !dead; }
getName()125 	inline const char *getName() const { return shotData ? shotData->name.c_str() : ""; }
126 
127 	float extraDamage;
128 	float homingness;
129 	float lifeTime;
130 	DamageType damageType;
131 	bool checkDamageTarget;
132 
133 protected:
134 
135 	float waveTimer;
136 
137 	void suicide();
138 
139 	ParticleEffect *emitter;
140 
141 	void onHitWall();
142 	void onEndOfLife();
143 
144 	bool dead;
145 	bool fired;
146 	bool enqueuedForDelete;
147 	void onUpdate(float dt);
148 
149 private:
150 	unsigned int shotIdx;
151 };
152 
153 class Beam : public Quad
154 {
155 public:
156 	Beam(Vector pos, float angle);
157 	typedef std::list<Beam*> Beams;
158 	static Beams beams;
159 	//static void targetDied(Entity *t);
160 	static void killAllBeams();
161 
162 	float angle;
163 	void trace();
164 	Vector endPos;
165 	void render();
166 	DamageData damageData;
167 
168 	void setDamage(float dmg);
169 	void setFirer(Entity *e);
170 	void setBeamWidth(float w);
171 protected:
172 	float beamWidth;
173 	void onRender();
174 	void onEndOfLife();
175 	void onUpdate(float dt);
176 };
177 
178 class GasCloud : public Entity
179 {
180 public:
181 	GasCloud(Entity *source, const Vector &position, const std::string &particles, const Vector &color, int radius, float life, float damage=0, bool isMoney=false, float poisonTime=0);
182 protected:
183 	ParticleEffect *emitter;
184 	std::string gfx, particles;
185 	int radius;
186 	float damage;
187 	float pTimer;
188 	void onUpdate(float dt);
189 	float poisonTime;
190 	Entity *sourceEntity;
191 };
192 
193 class Spore : public CollideEntity
194 {
195 public:
196 	Spore(const Vector &position);
197 	typedef std::list<Spore*> Spores;
198 	static Spores spores;
199 	static void killAllSpores();
200 	static bool isPositionClear(const Vector &position);
201 	void destroy();
202 protected:
203 	void onEnterState(int state);
204 	void onUpdate(float dt);
205 	void onEndOfLife();
206 };
207 
208 #endif
209