#include "entity_player.h"

/* Initializes a player entity. */
void
entity_player_init(ECS* ecs, u32 id, vec3 position)
{
	ComponentActionShoot* actionShoot;
	ComponentAmmo* ammo;
	ComponentCharacter* character;
	ComponentControlPlayer* controlPlayer;
	ComponentGameEntityType* gameEntityType;
	ComponentHealth* health;
	ComponentRedirects* redirects;

	actionShoot = ecs_component_add(ecs, ECS_COMPONENT_ACTION_SHOOT, id);
	ammo = ecs_component_add(ecs, ECS_COMPONENT_AMMO, id);
	character = ecs_component_add(ecs, ECS_COMPONENT_CHARACTER, id);
	controlPlayer = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_PLAYER, id);
	redirects = ecs_component_add(ecs, ECS_COMPONENT_REDIRECTS, id);
	gameEntityType = ecs_component_add(ecs, ECS_COMPONENT_GAME_ENTITY_TYPE, id);

	ecs_component_add(ecs, ECS_COMPONENT_UPGRADES, id);
	ecs_component_add(ecs, ECS_COMPONENT_GOODIES, id);

	component_character_init
	(
		character,
		ecs,
		ecs->game->resources.textures[TEXTURE_PLAYER],
		(s32*)PLAYER_FRAME_SIZE,
		(s32*)PLAYER_ATLAS_SIZE,
		(f32*)PLAYER_SIZE,
		(f32*)PLAYER_PHYSICS_SIZE,
		position,
		(f32*)COLOR_OPAQUE,
		PLAYER_FRICTION,
		PLAYER_VELOCITY_MAX,
		PLAYER_ALLEGIANCE,
		PLAYER_HEALTH_MAX
	);

	component_action_shoot_init
	(
		actionShoot,
		(ProjectileInit)entity_snake_init,
		PLAYER_ACTION_SHOOT_SPEED,
		PLAYER_ACTION_SHOOT_OFFSET,
		PLAYER_ACTION_SHOOT_HEIGHT
	);

	component_control_player_init
	(
		controlPlayer,
		ecs,
		PLAYER_CONTROL_MOVE_SPEED,
		PLAYER_CONTROL_REDIRECT_ANGLE_THRESHOLD,
		PLAYER_CONTROL_SHOOT_COOLDOWN
	);

	component_ammo_init(ammo, PLAYER_AMMO_START);
	component_redirects_init(redirects, PLAYER_REDIRECTS_START);
	component_game_entity_type_init(gameEntityType, PLAYER_GAME_ENTITY_TYPE);
}
