1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D 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.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(__INCLUDE_Lightningh_INCLUDE__)
22 #define __INCLUDE_Lightningh_INCLUDE__
23 
24 #include <actions/Action.h>
25 #include <weapons/WeaponLightning.h>
26 #include <list>
27 
28 #ifndef S3D_SERVER
29 #include <GLEXT/GLTextureReference.h>
30 #endif
31 
32 class Target;
33 class Lightning : public Action
34 {
35 public:
36 	Lightning(WeaponLightning *weapon,
37 		WeaponFireContext &weaponContext,
38 		FixedVector &position, FixedVector &velocity);
39 	virtual ~Lightning();
40 
41 	virtual void draw();
42 	virtual void init();
43 	virtual void simulate(fixed frameTime, bool &remove);
44 	virtual std::string getActionDetails();
getActionType()45 	virtual std::string getActionType() { return "Lightning"; }
46 
47 protected:
48 	struct Segment
49 	{
50 		FixedVector start;
51 		FixedVector end;
52 		FixedVector direction;
53 		bool endsegment;
54 		fixed size;
55 	};
56 	bool firstTime_;
57 	fixed totalTime_;
58 	std::list<Segment> segments_;
59 
60 #ifndef S3D_SERVER
61 	GLTextureReference texture_;
62 #endif
63 	WeaponLightning *weapon_;
64 	FixedVector position_;
65 	FixedVector velocity_;
66 	WeaponFireContext weaponContext_;
67 
68 	void damageTargets(FixedVector &position,
69 		std::map<unsigned int, fixed> &hurtMap);
70 	void dispaceDirection(FixedVector &direction,
71 		FixedVector &originalDirection, fixed angle);
72 	void generateLightning(int id, int depth, fixed size,
73 		FixedVector &originalPosition, FixedVector &originalDirection,
74 		FixedVector &position, FixedVector &direction,
75 		std::map<unsigned int, fixed> &hurtMap);
76 };
77 
78 #endif // __INCLUDE_Lightningh_INCLUDE__
79