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 SCRIPTEDENTITY_H
22 #define SCRIPTEDENTITY_H
23 
24 #include "CollideEntity.h"
25 #include "Segmented.h"
26 #include "Hair.h"
27 struct lua_State;
28 
29 class ScriptedEntity : public CollideEntity, public Segmented
30 {
31 public:
32 	ScriptedEntity(const std::string &scriptName, Vector position, EntityType et = ET_ENEMY);
33 	void init();
34 	void postInit();
35 	void destroy();
36 	void stopTimer();
37 	void resetTimer(float t);
38 	void setEntityLayer(int layer);
39 	void setupEntity(const std::string &tex, int layer=0);
40 	void setupBasicEntity(const std::string& texture, int health, int manaBall, int exp, int money, float collideRadius, int state, int w, int h, int expType, bool hitEntity, int updateCull, int layer);
41 	void initSegments(int numSegments, int minDist, int maxDist, std::string bodyTex, std::string tailTex, int w, int h, float taper, bool reverseSegments);
42 	void registerNewPart(RenderObject *r, const std::string &name);
43 	typedef std::map<std::string, RenderObject*> PartMap;
44 	PartMap partMap;
45 	bool surfaceMoveDir;
46 	void activate();
47 	void warpSegments();
48 	void lightFlare();
49 	void entityDied(Entity *e);
50 	void message(const std::string &msg, int v);
51 	int messageVariadic(lua_State *L, int nparams);
52 
53 	static bool runningActivation;
54 
55 	void sporesDropped(const Vector &pos, int type);
56 
57 	bool damage(const DamageData &d);
58 	bool canShotHit(const DamageData &d);
59 
60 	void song(SongType songType);
61 
62 	void startPull();
63 	void stopPull();
64 
65 	void songNote(int note);
66 	void songNoteDone(int note, float len);
67 	void onAnimationKeyPassed(int key);
68 
69 	void initStrands(int num, int segs, int dist, int spacing, Vector color);
70 	typedef std::vector<Strand*> Strands;
71 	Strands strands;
72 	int strandSpacing;
73 	void becomeSolid();
74 
75 	std::string deathParticleEffect;
76 
77 	ParticleEffect pullEmitter;
78 	float manaBallAmount;
79 
80 	void initEmitter(int emit, const std::string &file);
81 	void startEmitter(int emit);
82 	void stopEmitter(int emit);
83 	ParticleEffect *getEmitter(int emit);
84 	int getNumEmitters() const;
85 
86 	void shiftWorlds(WorldType lastWorld, WorldType worldType);
87 	void setAutoSkeletalUpdate(bool v);
88 
89 	void shotHitEntity(Entity *hit, Shot *shot, Bone *b);
90 protected:
91 	void onDieNormal();
92 	void onDieEaten();
93 	void luaDebugMsg(const std::string &func, const std::string &msg);
94 	float crushDelay;
95 	int beforePullMaxSpeed;
96 	bool songNoteFunction;
97 	bool songNoteDoneFunction;
98 	std::vector<ParticleEffect*> emitters;
99 	bool becomeSolidDelay;
100 	void onAlwaysUpdate(float dt);
101 	void updateStrands(float dt);
102 	bool animKeyFunc;
103 	//void onPathEnd();
104 
105 	void onExitTimer();
106 	float myTimer;
107 	void onHitWall();
108 	bool reverseSegments;
109 	Script *script;
110 	void onUpdate(float dt);
111 	void onEnterState(int action);
112 	void onExitState(int action);
113 	virtual void deathNotify(RenderObject *r);
114 	bool canShotHitFunc;
115 };
116 
117 #endif
118