#include "game_session.h"

#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

Game_Session *g_current_session = NULL;

void game_session_create(bool is_singleplayer, bool is_host, Game_Session_Settings settings) {
    assert(g_current_session == NULL);

    Game_Session *session = (Game_Session *)calloc(1, sizeof(Game_Session));
    session->is_singleplayer = is_singleplayer;
    session->is_host = is_host;
    session->settings = settings;

    session->simulation_world = simulation_create_world(
        session->settings.seed,
        session->settings.max_players,
        session->settings.level_width,
        session->settings.level_height
    );

    g_current_session = session;

    printf("New Game_Session created.\n");
}

void game_session_destroy() {
    if(g_current_session == NULL) {
        return;
    }

    simulation_destroy_world(&g_current_session->simulation_world);

    free(g_current_session);
    g_current_session = NULL;
}

void game_session_init_default_settings(bool is_singleplayer, Game_Session_Settings *out_settings) {
    out_settings->seed         = 1337; // TODO: SS - Randomize.
    out_settings->level_width  = 48;
    out_settings->level_height = 48;
    out_settings->max_players  = is_singleplayer ? 1 : 8;
}