1 /*
2  * client/Hazard.hpp
3  *
4  * This file is part of Leges Motus, a networked, 2D shooter set in zero gravity.
5  *
6  * Copyright 2009-2010 Andrew Ayer, Nathan Partlan, Jeffrey Pfau
7  *
8  * Leges Motus is free and open source software.  You may redistribute it and/or
9  * modify it under the terms of version 2, or (at your option) version 3, of the
10  * GNU General Public License (GPL), as published by the Free Software Foundation.
11  *
12  * Leges Motus is distributed in the hope that it will be useful, but WITHOUT ANY
13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14  * PARTICULAR PURPOSE.  See the full text of the GNU General Public License for
15  * further detail.
16  *
17  * For a full copy of the GNU General Public License, please see the COPYING file
18  * in the root of the source code tree.  You may also retrieve a copy from
19  * <http://www.gnu.org/licenses/gpl-2.0.txt>, or request a copy by writing to the
20  * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307  USA
22  *
23  */
24 
25 #ifndef LM_CLIENT_HAZARD_HPP
26 #define LM_CLIENT_HAZARD_HPP
27 
28 #include "BaseMapObject.hpp"
29 #include "MapObjectParams.hpp"
30 #include "common/Shape.hpp"
31 #include <memory>
32 #include <string>
33 #include <stdint.h>
34 
35 namespace LM {
36 	class Hazard : public BaseMapObject {
37 	private:
38 		std::string		m_graphic_name;
39 		MapObjectParams		m_params;
40 		Graphic*		m_graphic;
41 		std::auto_ptr<Shape>	m_bounding_shape;
42 		bool			m_is_slippery;
43 
44 		char			m_team;			// What team this affects (0 for all players)
45 		int			m_damage;		// Damage when player interacts with object
46 		uint64_t		m_damage_rate;		// How often damage is applied (when interacting)
47 		bool			m_is_collidable;	// Can player collide with this hazard?  If false, then it's a hazard *area*
48 		int			m_collision_damage;	// Damage when player collides with obstacle
49 		uint64_t		m_freeze_time;		// How long you're frozen for (only when colliding)
50 		double			m_repel_velocity;	// The magnitude of velocity at which killed player should be pushed away
51 		double			m_bounce_factor;	// How much your velocity changes when you bounce off
52 
53 		uint64_t		m_last_damage_time;	// 0 if not engaged
54 		double			m_angle_of_incidence;	// Angle of incidence of the surface we landed on (used for repelling players)
55 
56 		bool			repel_player(Player&);	// Returns true if player was repelled, false otherwise
57 
58 	public:
59 		explicit Hazard (Point pos);
60 
get_graphic() const61 		virtual Graphic*	get_graphic () const { return m_graphic; }
get_bounding_shape() const62 		virtual const Shape*	get_bounding_shape () const { return m_bounding_shape.get(); }
63 
is_jumpable() const64 		virtual bool	is_jumpable () const { return m_is_collidable; }
is_shootable() const65 		virtual bool	is_shootable () const { return m_is_collidable; }
is_collidable() const66 		virtual bool	is_collidable () const { return m_is_collidable; }
is_interactive() const67 		virtual bool	is_interactive () const { return true; }
is_engaged() const68 		virtual bool	is_engaged () const { return m_last_damage_time != 0; }
shot(GameController & gc,Player & shooter,Point point_hit,double direction)69 		virtual bool	shot (GameController& gc, Player& shooter, Point point_hit, double direction) { return m_is_collidable; }
70 		virtual void	collide (GameController& gc, Player& player, Point old_position, double angle_of_incidence);
71 		virtual void	interact (GameController& gc, Player& player);
72 		virtual void	disengage (GameController& gc, Player& player);
73 		virtual void	init (MapReader& reader, ClientMap& map);
74 	};
75 }
76 
77 #endif
78