#include "entity_elemental.h"

/* Initializes a elemental entity. */
void
entity_elemental_init(ECS* ecs, u32 id, vec3 position, u32 spawnID, u32 playerID)
{
	ComponentGameObject* gameObject;
	ComponentActionOnCombatHide* actionOnCombatHide;
	ComponentAnimationSquash* animationSquash;
	ComponentCircleCollision* circleCollision;
	ComponentGoodies* goodies;
	ComponentShop* shop;
	ComponentAnimationStretch* animationStretch;

	gameObject = ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, id);
	actionOnCombatHide = ecs_component_add(ecs, ECS_COMPONENT_ACTION_ON_COMBAT_HIDE, id);
	animationSquash = ecs_component_add(ecs, ECS_COMPONENT_ANIMATION_SQUASH, id);
	animationStretch = ecs_component_add(ecs, ECS_COMPONENT_ANIMATION_STRETCH, id);
	circleCollision = ecs_component_add(ecs, ECS_COMPONENT_CIRCLE_COLLISION, id);
	goodies = ecs_component_add(ecs, ECS_COMPONENT_GOODIES, id);
	shop = ecs_component_add(ecs, ECS_COMPONENT_SHOP, id);

	ecs_component_add(ecs, ECS_COMPONENT_FATNESS, id);

	component_game_object_atlas_init
	(
		gameObject,
		ecs,
		ecs->game->resources.textures[TEXTURE_ELEMENTAL],
		(s32*)ELEMENTAL_FRAME_SIZE,
		(s32*)ELEMENTAL_ATLAS_SIZE,
		(f32*)ELEMENTAL_SIZE,
		(f32*)ELEMENTAL_PHYSICS_SIZE,
		position,
		ELEMENTAL_FRICTION,
		ELEMENTAL_VELOCITY_MAX,
		ELEMENTAL_GAME_OBJECT_IS_BOUNCE,
		ELEMENTAL_GAME_OBJECT_IS_AFFECTED_BY_GRAVITY,
		ELEMENTAL_GAME_OBJECT_IS_SOLID
	);

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

	component_game_entity_type_init 
	( 
		gameEntityType, 
		GAME_ENTITY_ELEMENTAL
	);

	component_action_on_combat_hide_init(actionOnCombatHide, ecs, spawnID, ELEMENTAL_ACTION_ON_COMBAT_HIDE_TIMER);

	component_animation_squash_init
	(
		animationSquash,
		ELEMENTAL_ANIMATION_SQUASH_BASE,
		ELEMENTAL_ANIMATION_SQUASH_MULTIPLIER,
		ELEMENTAL_ANIMATION_SQUASH_SPEED
	);

	component_animation_stretch_init
	(
		animationStretch,
		ELEMENTAL_ANIMATION_STRETCH_BASE,
		ELEMENTAL_ANIMATION_STRETCH_MULTIPLIER,
		ELEMENTAL_ANIMATION_STRETCH_SPEED
	);

	component_circle_collision_init
	(
		circleCollision,
		ecs,
		ELEMENTAL_CIRCLE_RADIUS
	);

	goodies->max = ELEMENTAL_GOODIES_MAX;

	entity_elemental_goodie_display_init(ecs, ecs_entity_add(ecs), id);

	component_shop_init
	(
		shop,
		ecs,
		playerID,
		id
	);
}
