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

static void draw_debug_map(level_t *level)
{
	int i;

	i = -1;
	my_printf("level width: %d - level height: %d\n", level->width,
	level->height);
	while (++i < level->height){
		write(1, &level->map[i * level->width], level->width);
		write(1, "$\n", 2);
	}
}

static int check_entity(scene_t *scene)
{
	int counter_princess = 0;
	int counter_player = 0;
	int i = -1;

	while (++i < scene->level->width * scene->level->height){
		counter_player += (scene->level->map[i] == ID_PLAYER) ? 1 : 0;
		if (scene->level->map[i] == ID_PRINCESS)
			counter_princess++;
	}
	if (counter_player != 1)
		write(2, "Player error.\n", 14);
	if (counter_princess <= 0)
		write(2, "Princess error.\n", 16);
	return ((counter_player != 1 || counter_princess <= 0) ? 1 : 0);
}

int check_map(scene_t *scene)
{
	int i = -1;

	#ifdef DEBUG_LOAD_FILE
	draw_debug_map(scene->level);
	#endif
	if (scene->level->width <= 0 || scene->level->height <= 0){
		write(2, "Map size not correct.\n", 22);
		return (1);
	}
	return (check_entity(scene));
}
