#include "component_action_on_delete_give_ammo.h"

/* DEPENDENCIES: ActionDeleteOnTouch, Ammo */
/* On deletion, give ammo to the ID belonging to ActionDeleteOnTouch. */

/* Initializes delete on touch component. */
void
component_action_on_delete_give_ammo_init(ComponentActionOnDeleteGiveAmmo* self, u32 value)
{
	self->value = value;
}

/* Ticks delete on touch component. */
void
component_action_on_delete_give_ammo_delete(ComponentActionOnDeleteGiveAmmo* self, ECS* ecs)
{
	ComponentActionDeleteOnTouch* actionDeleteOnTouch;
	ComponentAmmo* touchAmmo;

	actionDeleteOnTouch = ecs_component_get
	(
		ecs, 
		ECS_COMPONENT_ACTION_DELETE_ON_TOUCH, 
		self->component.id
	);

	touchAmmo = ecs_component_get(ecs, ECS_COMPONENT_AMMO, actionDeleteOnTouch->id);

	touchAmmo->value += self->value;
	touchAmmo->value = MAX(touchAmmo->value, touchAmmo->max);
}
