Nimbin[12]?SDL & Graphics / mapcreator / src/building/building_data.hpp

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz
src/building/building_data.hpp 2.6 KB · 122 lines raw
#pragma once

#include "objects/object.hpp"

enum class ItemType : uint32_t ;

enum class BuildingType {
    NONE,
    CRAFTING_STONE_1,
    CRAFTING_STONE_2,
    CRAFTING_STONE_3,
    CRAFTING_WOOD_1,
    CRAFTING_WOOD_2,
    CRAFTING_WOOD_3,
    CRAFTING_IRON_1,
    CRAFTING_IRON_2,
    CRAFTING_IRON_3,
    RESEARCH_STONE_1,
    RESEARCH_STONE_2,
    RESEARCH_STONE_3,
    RESEARCH_WOOD_1,
    RESEARCH_WOOD_2,
    RESEARCH_WOOD_3,
    RESEARCH_IRON_1,
    RESEARCH_IRON_2,
    RESEARCH_IRON_3,
    LAST,
};

enum class BuildObjectType {
    NONE,
    WORKBENCH,
    // WALL, DOOR, etc.
};


struct BuildingCost {
    ResourceType type;
    int amount;
};


struct BuildingData_s {
    BuildingType type;
    std::string title;
    float building_duration;
    int   level_max;
    int   required_level;
    BuildingType research_by;

    std::initializer_list<BuildingCost> cost;

    TileType  tileset_type;
    size_t    tileset_id;
    size_t    tileset_object_id;
};

struct ActiveBuild {
    BuildingType    type = BuildingType::NONE;
    BuildingData_s* data = nullptr;
    TilesetObject   object;
    SDL_FPoint world_position = {0, 0};
    SDL_Point tile_position;
    bool is_colliding = true;

    // Later add other types
    // WallTypes wall_type
    // DoorTypes door_type
};


namespace BuildingData {
    extern std::vector<BuildingData_s>
        building_data;
    extern SDL_Texture*
        workbench_texture;
    extern ActiveBuild
        active_build;

    bool Init(SDL_Renderer*);

    inline bool is_CraftingTable(BuildingType t) {
        return t >= BuildingType::CRAFTING_STONE_1 &&
            t <= BuildingType::CRAFTING_IRON_3;
    }

    inline bool is_ResearchTable(BuildingType t) {
        return t >= BuildingType::RESEARCH_STONE_1 &&
            t <= BuildingType::RESEARCH_IRON_3;
    }

    BuildingData_s*
    get_BuildingDataByType(BuildingType);

    std::vector<BuildingData_s*>
    get_CraftingTable();

    std::vector<BuildingData_s*>
    get_ResearchTable();


    void
    draw_WorkbenchMenu(SDL_Renderer* r, SDL_Rect win_size, std::vector<bool>& enabled_buildings); // it sucks to pass buildings

    BuildingType
    menu_DetectWorkbenchClick(const Input& input, SDL_Rect win_size, std::vector<bool>& enabled_buildings);

    int
    get_WorkbenchLevel(BuildingType);

    void
    update_ActiveBuildData(float pos_x, float pos_y);
    bool
    is_BuildingCollidingWithObject();
    bool
    snap_BuildPosition(float in_x, float in_y);
    void
    draw_SelectedWorkbenchAt(SDL_Renderer* r);

    bool
    menu_Hovering(const Input& input, SDL_Rect win_size, std::vector<bool>& enabled_buildings);
}