#ifndef _WORLD_H
#define _WORLD_H

//#include	<stdio.h>

#include	"p_user.h"
#include	"hooks.h"
#include	"common.h"

//	for files that don't include windows.h
#ifndef	TRUE
#define	TRUE	1
#endif
#ifndef	FALSE
#define	FALSE	0
#endif

extern	char			*global_spawntarget;
extern	Vector			forward, right, up;
extern	vec3_t			zero_vector;
extern	userTrace_t		trace;
extern	trace_t			tr;
extern	serverState_t	*gstate;
extern	common_export_t	*com;

float	debris_vel	(userEntity_t *self, float distxy, float distz, float up_vel);


// this structure is appended to door entities with userHook
typedef struct
{
	int		state;
	int		count;
	int		max_count;
	int		already_linked;
	int		continuous_mode;
	
	float	wait;
	float	max_health;
	float	speed;
	float	distance;
	float	move_finished;
	float	damage;
	float	ignore_time;

	// for func_trains that rotate
	float	x_speed;
	float	y_speed;
	float	z_speed;
	float	x_distance;
	float	y_distance;
	float	z_distance;
	float	end_x_rotation_time;
	float	end_y_rotation_time;
	float	end_z_rotation_time;
	float	end_x_angle;
	float	end_y_angle;	
	float	end_z_angle;
	float	end_move_time;

	// for secrets only
	float	t_width;
	float	t_length;

	Vector	pos1;
	Vector	pos2;
	Vector	final_dest;
	Vector	size;
	Vector	old_origin;
	Vector	mangle;
	
	void	(*done_think)(userEntity_t *self);
	//void	(*die_think)(userEntity_t *self);
	//void	(*use_think)(userEntity_t *self);

	userEntity_t	*linked_door;
	userEntity_t	*trigger_field;
	userEntity_t 	*movetarget;
	userEntity_t	*activator;
	userEntity_t	*portal;

/*
	char	*sound_top;
	char	*sound_bottom;
	char	*sound_up;
	char	*sound_down;
*/
	int		sound_top;
	int		sound_bottom;
	int		sound_up;
	int		sound_down;
} doorHook_t;

// func_floater hook

typedef struct 
{
	int				water_level;

	char			*frameName;

	userEntity_t	*last_touch;

	float			speed;

} floatHook_t;

// func_debris hook

typedef struct 
{
	char	*modelName;
	char	*fly_sound;
	char	*hit_sound;

	int		has_rotated;

	float	damage;
	float	last_water;
	float	change_time;
	
	float	rotation_scale;
	float	mass_scale;

	Vector	last_pos;
	Vector	hit_water_pos;
	Vector	dest;
	Vector	avel;
} debrisHook_t;

// trigger hook

typedef struct 
{
	float			wait;
	float			max_health;
	float			next_trigger_time;
	float			damage;
	float			speed;

	int				count;

	char			*sound;
	char			*console_msg;

	char			*model_1;
	char			*model_2;
	char			*model_3;

	userEntity_t	*activator;

	Vector			mangle;
	Vector			v_angle;

	void	(*done_think)(userEntity_t *self);
} trigHook_t;

// rock hook (func_wall_explode random debris)

typedef struct
{
	float	remove_time;
	float	last_touch_time;
	float	last_water;
	float	change_time;

	float	rotation_scale;
	float	mass_scale;

	Vector	last_pos;
	Vector	hit_water_pos;
} rockHook_t;

// fog trigger hook

typedef struct
{
	float	cur_fog_value;
} fogHook_t;

// particlefield hook

typedef struct
{
	Vector	dest;
	Vector	dest1;
	Vector	dest2;
	Vector	impact_vel;

	char	*touch_sound;
	char	*trigger_sound;
	char	*amb_sound;

	float	damage;
	float	attack_finished;
	float	hold_time;

	int		count;
	int		color;
	int		last_color;

	userEntity_t	*other;
	think_t			think_use;
} particleHook_t;


#endif