#include "component_action_damage.h"

/* DEPENDENCIES: Physics, Health */

/* Sets action_damage component info. */
void
component_action_damage_init(ComponentActionDamage* self, AllegianceType type, u32 value)
{
	self->value = value;
}

/* Ticks action_damage component. */
void
component_action_damage_tick(ComponentActionDamage* self, ECS* ecs)
{	
	ComponentPhysics* physics;
	ComponentHealth* health;
	ComponentAllegiance* allegiance;

	physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->component.id);

	for (s32 i = 0; i < (s32)physics->collisions.count; i++)
	{	
		u32 id;

		id = *(u32*)vector_get(&physics->collisions, i);

		health = ecs_component_get(ecs, ECS_COMPONENT_HEALTH, id);
		allegiance = ecs_component_get(ecs, ECS_COMPONENT_ALLEGIANCE, id);

		if (!health || !allegiance)
			continue;

		if (allegiance->type != self->type)
			health->value -= self->value;
	}
}
