//
// Created by sebastian on 07.02.26.
//

#ifndef MAPGENERATOR_H
#define MAPGENERATOR_H
#include <cmath>
#include <random>

#include "HexTile.h"
#include "Map.h"

class MapGenerator {
public:
    static void generateHexMap(Map& map, int width, int height, float hexRadius) {
        // Zufallsgenerator initialisieren (einmal)
        std::random_device rd;  // Zufälliger Seed
        std::mt19937 gen(rd()); // Mersenne Twister Generator

        // Verteilung definieren: hier z.B. 0 bis 9
        std::uniform_real_distribution<float> dis(0.0f, 1.0f);
        map.tiles.clear();

        float xOffset = hexRadius * std::sqrt(3.0f);
        float zOffset = hexRadius * 1.5f;

        for (int r = 0; r < height; ++r) {
            for (int q = 0; q < width; ++q) {
                HexTile tile;
                tile.q = q;
                tile.r = r;

                // Pointy-top Hexes
                float x = xOffset * (q + 0.5f * (r % 2));
                float z = zOffset * r;
                tile.worldPos = glm::vec3(x, 0.0f, z);
                tile.radius = hexRadius;

                float randomValue = dis(gen);
                if (randomValue < 0.5f) {
                    tile.resourceType = RessourceType::WOOD;
                }

                map.tiles.push_back(tile);
            }
        }
    }
};



#endif //MAPGENERATOR_H
