#include "entity_player.h"

/* Initializes a player entity. */
void
entity_player_init(ECS* ecs, u32 id, vec3 position)
{
	ComponentActionShoot* actionShoot;
	ComponentAmmo* ammo;
	ComponentControlLock* controlLock;
	ComponentControlMove* controlMove;
	ComponentControlRecall* controlRecall;
	ComponentControlRedirect* controlRedirect;
	ComponentControlShoot* controlShoot;
	ComponentGameObject* gameObject;
	ComponentHealth* health;
	ComponentRedirect* redirect;

	ammo = ecs_component_add(ecs, ECS_COMPONENT_AMMO, id);
	controlMove = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_MOVE, id);
	controlShoot = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_SHOOT, id);
	gameObject = ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, id);
	health = ecs_component_add(ecs, ECS_COMPONENT_HEALTH, id);
	actionShoot = ecs_component_add(ecs, ECS_COMPONENT_ACTION_SHOOT, id);
	redirect = ecs_component_add(ecs, ECS_COMPONENT_REDIRECT, id);
	controlRedirect = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_REDIRECT, id);
	controlLock = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_LOCK, id);
	controlRecall = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_RECALL, id);

	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_AIM, id);
	
	component_game_object_init
	(
		gameObject,
		ecs,
		ecs->game->resources.textures[TEXTURE_PLAYER],
		(f32*)PLAYER_SIZE,
		(f32*)PLAYER_PHYSICS_SIZE,
		position,
		(f32*)PLAYER_OFFSET,
		(f32*)COLOR_OPAQUE,
		PLAYER_FRICTION,
		PLAYER_VELOCITY_MAX
	);

	component_control_move_init(controlMove, PLAYER_SPEED);

	component_action_shoot_init
	(
		actionShoot,
		(ProjectileInit)entity_snake_init,
		PLAYER_ACTION_SHOOT_SPEED,
		PLAYER_ACTION_SHOOT_OFFSET
	);

	component_control_shoot_init(controlShoot, PLAYER_CONTROL_SHOOT_COOLDOWN);
	component_control_redirect_init(controlRedirect, PLAYER_CONTROL_REDIRECT_COOLDOWN);
	component_control_lock_init(controlLock, PLAYER_CONTROL_LOCK_COOLDOWN);
	component_control_recall_init(controlRecall, PLAYER_CONTROL_RECALL_COOLDOWN);

	component_health_init(health, PLAYER_HEALTH_MAX);
	component_ammo_init(ammo, PLAYER_AMMO_MAX);
	component_redirect_init(redirect, PLAYER_REDIRECT_MAX);
}
