/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include <stdlib.h>
#include "lib/my_memory.h"
#include "game/memory.h"
#include "game/core.h"

static void free_thrower(thrower_t **thrower, int thrower_counter)
{
	int i;

	if (thrower == NULL)
		return;
	i = -1;
	while (++i < thrower_counter){
		if (thrower[i]->object)
			free(thrower[i]->object);
		free(thrower[i]);
	}
	free(thrower);
}

static void free_message(message_t **message, int nb_message)
{
	int i;

	if (message == NULL)
		return;
	i = -1;
	while (++i < nb_message)
		if (message[i])
			free(message[i]);
	free(message);
}

void free_scene(scene_t *scene)
{
	if (scene == NULL)
		return;
	if (scene->thrower)
		free_thrower(scene->thrower, scene->level->thrower_counter);
	if (scene->level){
		if (scene->level->map)
			free(scene->level->map);
		free(scene->level);
	}
	if (scene->message)
		free_message(scene->message, scene->nb_message);
	if (scene->player)
		free(scene->player);
	if (scene->camera)
		free(scene->camera);
	if (scene->wall)
		free(scene->wall);
}
