#include "component_control_player.h"

/* DEPENDENCIES: ControlAim, ControlShoot, ControlMove, ControlRedirect, ControlLock, ControlRecall, ControlHeart */

/* Ticks control_player component. */
void
component_control_player_init
(
	ComponentControlPlayer* self, 
	ECS* ecs,
	f32 speed,
	f32 angleThreshold,
	f32 shootCooldown,
	u32 spawnID
)
{
	ComponentControlMove* controlMove;
	ComponentControlRedirect* controlRedirect;
	ComponentControlShoot* controlShoot;
	ComponentControlHeart* controlHeart;

	controlMove = ecs_component_get(ecs, ECS_COMPONENT_CONTROL_MOVE, self->component.id);
	controlRedirect = ecs_component_get(ecs, ECS_COMPONENT_CONTROL_REDIRECT, self->component.id);
	controlShoot = ecs_component_get(ecs, ECS_COMPONENT_CONTROL_SHOOT, self->component.id);
	controlHeart = ecs_component_get(ecs, ECS_COMPONENT_CONTROL_HEART, self->component.id);

	component_control_move_init(controlMove, speed);
	component_control_redirect_init(controlRedirect, angleThreshold);
	component_control_shoot_init(controlShoot, shootCooldown);
	component_control_heart_init(controlHeart, spawnID);
}

/* Ticks control_player component. */
void
component_control_player_add(ComponentControlPlayer* self, ECS* ecs)
{
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_MOVE, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_AIM, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_SHOOT, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_REDIRECT, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_LOCK, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_RECALL, self->component.id);
	ecs_component_add(ecs, ECS_COMPONENT_CONTROL_HEART, self->component.id);
}

/* Ticks control_player component. */
void
component_control_player_delete(ComponentControlPlayer* self, ECS* ecs)
{
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_MOVE, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_AIM, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_SHOOT, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_REDIRECT, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_LOCK, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_RECALL, self->component.id);
	ecs_component_delete(ecs, ECS_COMPONENT_CONTROL_HEART, self->component.id);
}
