summaryrefslogtreecommitdiff
path: root/src/engine/RandomItemTable.h
blob: 384014b82d96c208aa6e75bdd9ce8606e5b1b38b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include <libultraship/libultraship.h>
#include <utility>

/**
 * Uses weighted random picking
 * 
 * This allows stock game to work identically
 * while allowing mods to add items which equalizes
 * the stock items without requiring addition chance editing
 */

class RandomItemTable {
public:
    RandomItemTable();
    bool Add(const std::string& resourceName, uint32_t rank, uint32_t weight, float distance);
    uint8_t Roll(uint32_t rank) const;
    void Blacklist(const std::string& resourceName);
    bool IsBlacklisted(uint32_t id) const;
    void ClearBlacklist();
protected:
    bool mDistanceEnabled;
    struct ItemEntry {
        uint32_t Id;
        uint32_t Weight;
        float Distance;
    };

    // Rank         index        item_id,   chance
    std::vector<std::vector<ItemEntry>> mTable;
    std::unordered_set<uint32_t> mBlacklist;
};