/*
   base/weapon.h
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#ifndef __INCLUDED_BASE_WEAPON_H__
#define __INCLUDED_BASE_WEAPON_H__

#include "core/info.h"

namespace game
{
class Weapon : public core::Info {

public:
	enum SubType {Ammo = 0, Cannon = 1, Turret = 2, Mine = 3 };
	
	Weapon();
	~Weapon();
	
	/* --- inspectors ------------------------------------------ */
	
	inline SubType subtype() const {
		return weapon_subtype;
	}
		
	/**
	 * @brief player level required to buy this weapon
	 * */
	inline int level() const {
		return weapon_level;
	}
		
	/**
	 * @brief the amount of damage this weapon inflicts
	 * */
	inline const float damage() const
	{
		return weapon_damage;
	}
	
	/**
	 * @brief lifespan of projectiles generated by this weapon, in milliseconds
	 * */
	inline const unsigned long projectile_lifespan() const
	{
		return weapon_projectile_lifespan;
	}
	
	/**
	 * @brief speed of projectiles generated by this weapon, in game units per second
	 * */
	inline const float projectile_speed() const
	{
		return weapon_projectile_speed;
	}
	
	/**
	 * @brief projectile range, in game units
	 * */
	inline const float projectile_range() const
	{
		return (weapon_projectile_speed * ((float) weapon_projectile_lifespan) / 1000.0f);
	}
	
	/**
	 * @brief interval between consequtive projectils fired by this weapon, in milliseconds
	 * */
	inline const unsigned long projectile_interval() const
	{
		return weapon_projectile_interval;
	}
	
	/**
	 * @brief name of the model used for projectiles generated by this weapon
	 * */
	inline const std::string & projectile_modelname() const
	{
		return weapon_projectile_modelname;
	}
	
	/**
	 * @brief name of the sound used when a projectile is fired by this weapon
	 * */
	inline const std::string & projectile_soundname() const
	{
		return weapon_projectile_soundname;
	}
	
	inline const model::Slot::Type slot_type() const
	{
		switch (weapon_subtype) {
			case Cannon:
				return model::Slot::Cannon;
				break;
			case Turret:
				return model::Slot::Turret;
				break;
			default:
				return model::Slot::None;
		}
	}
		

	/* --- mutators -------------------------------------------- */

	void set_level(const int level);
	
	void set_subtype(const SubType subtype);
	
	/**
	 * @brief set the projectile lifespan, in milliseconds
	 * */
	inline void set_projectile_lifespan(const unsigned long projectile_lifespan)
	{
		weapon_projectile_lifespan = projectile_lifespan;
	}
	
	/**
	 * @brief set the interval between two consecutive shots by this weapon
	 * */
	inline void set_projectile_interval(const unsigned long projectile_interval)
	{
		weapon_projectile_interval = projectile_interval;
	}

	/**
	 * @brief set_projectile speed, in game units per second
	 * */
	inline void set_projectile_speed(const float projectile_speed)
	{
		weapon_projectile_speed = projectile_speed;
	}
	
	/**
	 * @brief set the amount of damage this weapon inflicts
	 * */
	inline void set_damage(const float damage)
	{
		weapon_damage = damage;
	}
	
	/**
	 * @brief set projectile model name
	 * */
	inline void set_projectile_modelname(const std::string & projectile_modelname)
	{
		weapon_projectile_modelname.assign(projectile_modelname);
	}
	
	/**
	 * @brief set the projectile sound name
	 * */
	inline void set_projectile_soundname(const std::string soundname)
	{
		weapon_projectile_soundname.assign(soundname);
	}

	/**
	 * @brief generate specifications info.
	 * */
	void generate_info();
	
	/* --- static registry functions ---------------------------------- */
	
	static Weapon *find(const std::string & label);
	
	static bool init();
	
	static void done();
	
	static void list();
	
	static inline const core::InfoType *infotype() {
		return weapon_infotype;
	}

private:
	static core::InfoType *weapon_infotype;
	
	SubType		weapon_subtype;
	
	int		weapon_level;
	
	unsigned long	weapon_projectile_interval;
	
	unsigned long	weapon_projectile_lifespan;
	
	float		weapon_projectile_speed;
	
	float		weapon_damage;
	
	std::string	weapon_projectile_modelname;
	
	std::string	weapon_projectile_soundname;
};

} // namespace game

#endif // __INCLUDED_BASE_WEAPON_H__