#include "component_action_delete_on_dead.h"

/* DEPENDENCIES: Health */
/* This entity associated with this component will be deleted if it is dead. */

static void _dead_sound(ComponentActionDeleteOnDead* self, ECS* ecs);

static void
_dead_sound(ComponentActionDeleteOnDead* self, ECS* ecs)
{
	ComponentGameEntityType* gameEntityType;

	gameEntityType = ecs_component_get(ecs, ECS_COMPONENT_GAME_ENTITY_TYPE, self->component.id);

	switch (gameEntityType->type)
	{
		case GAME_ENTITY_CUPPER:
			sound_play(&ecs->game->resources.sounds[SOUND_CUPPER_KILL], SOUND_NO_PRIORITY);
			break;
		case GAME_ENTITY_CHIPPER:
			sound_play(&ecs->game->resources.sounds[SOUND_CHIPPER_KILL], SOUND_NO_PRIORITY);
			break;
		case GAME_ENTITY_CHIP:
			sound_play(&ecs->game->resources.sounds[SOUND_CHIP_KILL], SOUND_NO_PRIORITY);
			break;
		case GAME_ENTITY_CRUMBLER:
			sound_play(&ecs->game->resources.sounds[SOUND_CRUMBLER_KILL], SOUND_NO_PRIORITY);
			break;
		case GAME_ENTITY_CUSTARPEDO:
			sound_play(&ecs->game->resources.sounds[SOUND_CUSTARPEDO_KILL], SOUND_NO_PRIORITY);
			break;
		case GAME_ENTITY_EXCORSANT:
			sound_play(&ecs->game->resources.sounds[SOUND_EXCORSANT_KILL], SOUND_NO_PRIORITY);
			break;
		default:
			break;
	}
}

/* Ticks delete on dead component. */
void
component_action_delete_on_dead_tick(ComponentActionDeleteOnDead* self, ECS* ecs)
{
	ComponentHealth* health;

	health = ecs_component_get(ecs, ECS_COMPONENT_HEALTH, self->component.id);

	if (health->isDead)
	{
		_dead_sound(self, ecs);

		ecs_entity_delete(ecs, self->component.id);
	}
}
