#include "CustomThread.h"
#include "Scripting.h"
#include "../ScriptHook/Log.h"
#include <windows.h>
#include <string>
#include <vector>

//private

#include "Vars.h"
#include "Common.h"
#include "ini_module.h"
#include "drug_wars.h"
#include "drug_wars_coords.h"
#include "drug_wars_deal.h"
#include "drug_wars_vehicles.h"
#include "drug_wars_peds.h"

using namespace Scripting;

CustomThread::CustomThread()
{
    SetName("dws_drug_wars_misions"); //log
}


void CustomThread::RunScript()
{
    while (IsThreadAlive())
    {
        //loop;
        // Inicjalizacja menu przy pierwszym uruchomieniu
        static bool initialized = false;
        

        if (!(initialized) && !(IS_SCREEN_FADING())) {
            //LoadSettings();       // Wczytanie konfiguracji z INI
            NUM_DRUG_WARS = ini_read_int("drug_wars_passed", "val");
            noob_progress_state = ini_read_int("noob_progress_state", "val");
            SET_INT_STAT((eIntStatistic)363, 3); // DISABLE ISLANDS ROAD BLOCK BY COPS
            
            
            prepare_decision();
            prepare_coords_for_blip();
            open_log();
            CURRENT_TASK = 1;
            if (noob_progress_state == 0) {
                CURRENT_TASK = 0;
            }

            
            dump_log("[LOG] Rozpoczęto nową sesję gry.Inicjalizacja...\n");
            dump_log("[Wczytano INI] NUM_DRUG_WARS: " + std::to_string(NUM_DRUG_WARS));
            dump_log("[Wczytano INI] noob_progress_state: " + std::to_string(noob_progress_state));
            initialized = true;
        }
        pPlayer = GetPlayerPed();
        drug_wars_controler();
        model_loading_machine();

        if (isHelpActive > 0)
        {

            if (GetTickCount() - helpStartTime > max_time) {
                isHelpActive = show_NONE; // WyĹ‚Ä…cz wyĹ›wietlanie po upĹ‚ywie czasu
            }
            else {
                draw_mision_progres(isHelpActive); // Rysuj box tylko, gdy czas jeszcze nie minÄ…Ĺ‚
            }
        }
        Wait(0);
    }
}