1 
2 /* Battle Tanks Game
3  * Copyright (C) 2006-2009 Battle Tanks team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 
20 /*
21  * Additional rights can be granted beyond the GNU General Public License
22  * on the terms provided in the Exception. If you modify this file,
23  * you may extend this exception to your version of the file,
24  * but you are not obligated to do so. If you do not wish to provide this
25  * exception without modification, you must delete this exception statement
26  * from your version and license this file solely under the GPL without exception.
27 */
28 
29 #include "object.h"
30 #include "registrar.h"
31 
32 class SinglePose : public Object {
33 public:
SinglePose(const std::string & pose)34 	SinglePose(const std::string &pose) :
35 		Object("single-pose"), _pose(pose) {
36 			impassability = 0;
37 			hp = -1;
38 		}
39 
40 	virtual Object * clone() const;
41 	virtual void tick(const float dt);
42 	virtual void on_spawn();
43 	virtual void render(sdlx::Surface &surface, const int x, const int y);
44 
serialize(mrt::Serializator & s) const45 	virtual void serialize(mrt::Serializator &s) const {
46 		Object::serialize(s);
47 		s.add(_pose);
48 	}
49 
deserialize(const mrt::Serializator & s)50 	virtual void deserialize(const mrt::Serializator &s) {
51 		Object::deserialize(s);
52 		s.get(_pose);
53 	}
54 
55 private:
56 	std::string _pose;
57 };
58 
render(sdlx::Surface & surface,const int x,const int y)59 void SinglePose::render(sdlx::Surface &surface, const int x, const int y) {
60 	if (_variants.has("no-directions"))
61 		set_direction(0);
62 	Object::render(surface, x, y);
63 }
64 
65 
tick(const float dt)66 void SinglePose::tick(const float dt) {
67 	Object::tick(dt);
68 	if (get_state().empty()) {
69 		//LOG_DEBUG(("over"));
70 		emit("death", this);
71 	}
72 }
73 
on_spawn()74 void SinglePose::on_spawn() {
75 	//LOG_DEBUG(("single-pose: play('%s', %s)", _pose.c_str(), _repeat?"true":"false"));
76 	play(_pose, !_variants.has("once"));
77 	if (_variants.has("play-start")) {
78 		play_now("start");
79 	}
80 }
81 
82 
clone() const83 Object* SinglePose::clone() const  {
84 	return new SinglePose(*this);
85 }
86 
87 REGISTER_OBJECT("single-pose", SinglePose, ("main"));
88 REGISTER_OBJECT("broken-object", SinglePose, ("broken"));
89 REGISTER_OBJECT("outline", SinglePose, ("main"));
90 REGISTER_OBJECT("eternal-flame", SinglePose, ("burn"));
91 REGISTER_OBJECT("helmet", SinglePose, ("hold"));
92