bwmodel
A modeling environment for Minecraft Bedwars
Loading...
Searching...
No Matches
map.h
1// Copyright (C) 2024 Ethan Uppal. All rights reserved.
2
3#pragma once
4
5#include <cstdint>
6#include <cstdbool>
7#include <string>
8#include <memory>
9#include <cassert>
10#include <stdexcept>
11#include "core/grid.h"
12#include "game/player.h"
13
14namespace bwmodel {
17 using blocks_t = int32_t;
18
20 constexpr blocks_t REGION_W = 8;
21
23 constexpr blocks_t REGION_H = 8;
24
25 using RegionSetBacking = uint16_t;
26
28 enum class RegionSet : RegionSetBacking {
29 BASE = 1 << 0,
30 EMPTY = 1 << 1,
31 DIAMOND = 1 << 2,
32 MIDDLE = 1 << 3,
33
34 RED = 1 << (8 + *PlayerColor::RED),
35 BLUE = 1 << (8 + *PlayerColor::BLUE),
36 GREEN = 1 << (8 + *PlayerColor::GREEN),
37 AQUA = 1 << (8 + *PlayerColor::AQUA),
38 YELLOW = 1 << (8 + *PlayerColor::YELLOW),
39 WHITE = 1 << (8 + *PlayerColor::WHITE),
40 BLACK = 1 << (8 + *PlayerColor::BLACK),
41 PINK = 1 << (8 + *PlayerColor::PINK),
42
43 INVALID = 0
44 };
45
46 inline RegionSet operator|(RegionSet lhs, RegionSet rhs) {
47 return static_cast<RegionSet>(static_cast<RegionSetBacking>(lhs)
48 | static_cast<RegionSetBacking>(rhs));
49 }
50
51 inline void operator|=(RegionSet& lhs, RegionSet rhs) {
52 lhs = lhs | rhs;
53 }
54
56 class MapLoadError : public std::runtime_error {
57 public:
58 using std::runtime_error::runtime_error;
59 };
60
62 class Map final : public GridInterface<RegionSet, blocks_t> {
64 std::shared_ptr<Grid<RegionSet>> grid;
65
71 Map(std::shared_ptr<Grid<RegionSet>> grid);
72
73 protected:
74 const Grid<RegionSet>& backing() const override;
75
76 public:
83 bool update_region(blocks_t x, blocks_t y, RegionSet regions);
84
90 RegionSet regions_at(blocks_t x, blocks_t y) const;
91
97 static std::unique_ptr<Map> load_from(const std::string& path);
98 };
99
100 namespace RegionSetHelper {
102 RegionSet from(PlayerColor color);
103
105 RegionSet from(char value);
106 }
107}
Definition grid.h:17
Definition map.h:62
RegionSet regions_at(blocks_t x, blocks_t y) const
Definition map.cpp:27
bool update_region(blocks_t x, blocks_t y, RegionSet regions)
Definition map.cpp:17
static std::unique_ptr< Map > load_from(const std::string &path)
Definition map.cpp:36
const Grid< RegionSet > & backing() const override
Definition map.cpp:13
Definition map.h:56