21 int free[8], count = 0;
22 for (
int i = 0; i < 8; i++)
25 if (count == 0)
return rand() % 8;
27 int chosen = free[rand() % count];
36 return (
static_cast<uint64_t
>(
static_cast<uint32_t
>(x)) << 32) |
static_cast<uint32_t
>(y);
42 return (
static_cast<uint64_t
>(x) << 24) | (
static_cast<uint64_t
>(y) << 4) |
43 static_cast<uint64_t
>(resourceType);
49 std::array<int, 7> result;
52 for (
int i = 0; i < 7; i++) {
55 bool hasCount = resources[i] > 0;
57 if (hasCount && !hasSlot) {
62 }
else if (!hasCount && hasSlot) {
66 }
else if (hasCount && hasSlot) {
79 if (eggs.find(
id) == eggs.end()) {
82 auto [ex, ey] = tileIt->second;
94 for (
const auto& [
id, egg] : eggs) {
107 return it !=
_eggSlots.end() ? it->second : -1;
static constexpr std::pair< float, float > SLOT_OFFSETS[8]
std::unordered_set< int > _knownEggs
static std::pair< float, float > slotOffset(int slotIndex)
Returns the XZ offset pair {dx, dz} for a slot index (0-7).
std::unordered_map< uint64_t, int > _resourceSlots
float resourceRotation(int tileX, int tileY, int resourceType) const
Returns the stable random Y rotation for a resource slot, or 0 if absent.
static uint64_t tileKey(int x, int y)
void syncEggs(const std::unordered_map< int, Egg > &eggs)
Syncs egg slot assignments against the current egg map. Assigns slots to new eggs,...
std::unordered_map< int, std::pair< int, int > > _eggTile
std::array< int, 7 > updateResourceSlots(int tileX, int tileY, const Resources &resources)
Updates slot assignments for all resource types on a tile. Assigns a slot when count goes 0→nonzero,...
void clear()
Resets all state. Call on reconnect.
std::unordered_map< int, int > _eggSlots
static uint64_t resourceKey(int x, int y, int resourceType)
std::unordered_map< uint64_t, float > _resourceRotations
int eggSlot(int eggId) const
Returns the slot index for an egg id, or -1 if unknown.
std::unordered_map< uint64_t, TileOccupancy > _tileOccupancy
void release(int slotIndex)
std::array< bool, 8 > occupied