#ifndef WORLD_H
#define WORLD_H

#include <stdint.h>
#include "entity.h"
#include "grid.h"
#include "shared/squeue.h"
#include "shared/random.h"
#include "game_world_player.h"

typedef struct {
    uint32_t seed;
    Random_Generator random_generator;

    Game_World_Player *players;
    uint16_t max_players;
    
    SQueue entity_id_queue;
    Entity *entities;
    uint16_t max_entities;

    Grid grid;

} Game_World;

Game_World *game_world_create(uint32_t seed, uint16_t max_players, uint16_t level_width, uint16_t level_height);
void game_world_destroy(Game_World *world);

bool game_world_create_entity(Game_World *world, Entity_Type type, uint16_t x, uint16_t y, Entity_ID *out_entity_id);
void game_world_destroy_entity(Game_World *world, Entity_ID entity_id, bool destroy_children);

void game_world_tick(Game_World *world);

bool game_world_add_player(Game_World *world, Game_World_Player **out_gw_player);
bool game_world_remove_player(Game_World *world, Game_World_Player *player);

Entity *game_world_try_get_entity_by_id(Game_World *world, Entity_ID id);

bool game_world_find_position_to_spawn(Game_World *world, uint16_t *out_x, uint16_t *out_y);
Entity_Movement_Direction game_world_choose_initial_move_direction_based_on_coords(Game_World *world, uint16_t x, uint16_t y);

#endif