#include "entity_snake.h"

/* Initializes a snake entity. */
void
entity_snake_init(ECS* ecs, u32 id, vec3 position, u32 sender)
{
	ComponentGameObject* gameObject;
	ComponentActionReturn* actionReturn;
	ComponentActionRedirect* actionRedirect;
	ComponentActionLock* actionLock;
	ComponentActionOnDeleteGiveAmmo* actionOnDeleteGiveAmmo;
	ComponentActionDamage* actionDamage;
	ComponentAllegiance* allegiance;

	gameObject = ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, id);
	actionReturn = ecs_component_add(ecs, ECS_COMPONENT_ACTION_RETURN, id);
	actionRedirect = ecs_component_add(ecs, ECS_COMPONENT_ACTION_REDIRECT, id);
	actionOnDeleteGiveAmmo = ecs_component_add(ecs, ECS_COMPONENT_ACTION_ON_DELETE_GIVE_AMMO, id);
	actionDamage = ecs_component_add(ecs, ECS_COMPONENT_ACTION_DAMAGE, id);
	actionLock = ecs_component_add(ecs, ECS_COMPONENT_ACTION_LOCK, id);
	allegiance = ecs_component_add(ecs, ECS_COMPONENT_ALLEGIANCE, id);

	ecs_component_add(ecs, ECS_COMPONENT_ACTION_GRIP, id);

	component_game_object_init
	(
		gameObject,
		ecs,
		ecs->game->resources.textures[TEXTURE_SNAKE],
		(f32*)SNAKE_SIZE,
		(f32*)SNAKE_PHYSICS_SIZE,
		position,
		SNAKE_FRICTION,
		SNAKE_VELOCITY_MAX,
		SNAKE_GAME_OBJECT_IS_BOUNCE,
		SNAKE_GAME_OBJECT_IS_AFFECTED_BY_GRAVITY,
		SNAKE_GAME_OBJECT_IS_SOLID
	);

	component_action_return_init
	(
		actionReturn,
		ecs,
		SNAKE_ACTION_RETURN_SPEED,
		SNAKE_ACTION_RETURN_MULTIPLIER,
		SNAKE_ACTION_RETURN_VELOCITY_MAX,
		SNAKE_ACTION_RETURN_LIFETIME,
		sender
	);

	component_action_redirect_init(actionRedirect, SNAKE_ACTION_REDIRECT_MULTIPLIER, sender);
	component_action_lock_init(actionLock, SNAKE_ACTION_LOCK_COOLDOWN, SNAKE_ACTION_LOCK_SELECT_RADIUS, sender);
	component_action_on_delete_give_ammo_init(actionOnDeleteGiveAmmo, SNAKE_ACTION_ON_DELETE_GIVE_AMMO_VALUE);
	component_action_damage_init
	(
		actionDamage, 
		SNAKE_ACTION_DAMAGE_ATTACK_TYPE, 
		SNAKE_ACTION_DAMAGE_TIMER, 
		SNAKE_ACTION_DAMAGE_VALUE
	);
	component_allegiance_init(allegiance, SNAKE_ALLEGIANCE);

	ComponentGameEntityType* gameEntityType; 
	gameEntityType = ecs_component_add(ecs, ECS_COMPONENT_GAME_ENTITY_TYPE, id); 

	component_game_entity_type_init 
	( 
		gameEntityType, 
		GAME_ENTITY_SNAKE
	);
}
