nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
lands.h
Go to the documentation of this file.
1#ifndef NANOMMO_TERRAIN_LANDS_H_
2#define NANOMMO_TERRAIN_LANDS_H_
3
4#include <array>
5#include <cstdint>
6#include <string_view>
7
8#include "terrain/terrain.h"
9
10namespace nanommo {
11
12/// In metres from the middle of a land.
13struct Place {
14 float x = 0.0f;
15 float z = 0.0f;
16};
17
18struct Land {
19 const char* name;
20 /// Added to the world's seed, so that each land has an island of its own.
21 uint32_t seed = 0;
22 /// How deep into its sea players can wade, in metres.
24 /// Whether each player who goes in gets a copy of the land of their own,
25 /// rather than the one copy that everyone in the world shares.
26 bool dungeon = false;
27};
28
29/// Each world has these lands. The server tells a client which one it's in by
30/// its place in the list, so the server and the client list them in one order.
31constexpr std::array<Land, 3> kLands = {{
32 {.name = "Meadows", .seed = 0, .wading = Terrain::kWading},
33 {.name = "Ashlands", .seed = 1000, .wading = 0.0f},
34 {.name = "Crypt", .seed = 2000, .wading = 0.0f, .dungeon = true},
35}};
36
37/// A ring of stones in a land, which takes players to another.
38struct Gate {
39 /// Where it stands, and the land it takes you to, by their places in kLands.
40 int land = 0;
42 int to = 0;
43};
44
45constexpr std::array<Gate, 4> kGates = {{
46 // Between the Meadows and the Ashlands.
47 {.land = 0, .place = {0.0f, -10.0f}, .to = 1},
48 {.land = 1, .place = {0.0f, -10.0f}, .to = 0},
49 // Between the Meadows and the Crypt.
50 {.land = 0, .place = {12.0f, 0.0f}, .to = 2},
51 {.land = 2, .place = {0.0f, -10.0f}, .to = 0},
52}};
53
54/// Each gate has a twin in the land it takes you to, which leads back, and
55/// each dungeon has a gate, which is the way out.
56constexpr bool GatesLeadBack() {
57 for (const Gate& gate : kGates) {
58 bool twin = false;
59 for (const Gate& other : kGates) {
60 twin = twin || (other.land == gate.to && other.to == gate.land);
61 }
62 if (!twin) {
63 return false;
64 }
65 }
66 for (int land = 0; land < static_cast<int>(kLands.size()); ++land) {
67 bool gate = false;
68 for (const Gate& other : kGates) {
69 gate = gate || other.land == land;
70 }
71 if (kLands[land].dungeon && !gate) {
72 return false;
73 }
74 }
75 return true;
76}
77static_assert(GatesLeadBack(),
78 "each gate needs a twin, and each dungeon a way out");
79
80/// In metres from the middle of a gate.
81constexpr float kGateRadius = 1.0f;
82
83/// Past the edge of a gate, so that players don't arrive inside it.
84constexpr float kArrival = 3.0f;
85
86/// Its place in the list, or the first land's for a name that isn't there.
87int LandNamed(std::string_view name);
88
89bool IsLand(std::string_view name);
90
91bool InGate(const Gate& gate, float x, float z);
92
93/// The gate in the land this one takes you to, which leads back.
94const Gate& Twin(const Gate& gate);
95
96/// The dungeon's way out: its first gate.
97const Gate& WayOut(int dungeon);
98
99/// Where a player who goes through the gate comes out: past the middle of its
100/// twin, the way they were facing, so that they walk on out of it.
101Place Arrival(const Gate& gate, float yaw);
102
103} // namespace nanommo
104
105#endif // NANOMMO_TERRAIN_LANDS_H_
static constexpr float kWading
Players wade into the sea up to their knees.
Definition terrain.h:53
Definition chat.cc:9
constexpr std::array< Gate, 4 > kGates
Definition lands.h:45
const Gate & WayOut(int dungeon)
The dungeon's way out: its first gate.
Definition lands.cc:39
const Gate & Twin(const Gate &gate)
The gate in the land this one takes you to, which leads back.
Definition lands.cc:32
int LandNamed(std::string_view name)
Its place in the list, or the first land's for a name that isn't there.
Definition lands.cc:10
constexpr float kArrival
Past the edge of a gate, so that players don't arrive inside it.
Definition lands.h:84
Place Arrival(const Gate &gate, float yaw)
Definition lands.cc:43
bool InGate(const Gate &gate, float x, float z)
Definition lands.cc:28
constexpr std::array< Land, 3 > kLands
Definition lands.h:31
constexpr bool GatesLeadBack()
Definition lands.h:56
constexpr float kGateRadius
In metres from the middle of a gate.
Definition lands.h:81
bool IsLand(std::string_view name)
Definition lands.cc:19
A ring of stones in a land, which takes players to another.
Definition lands.h:38
Place place
Definition lands.h:41
int land
Where it stands, and the land it takes you to, by their places in kLands.
Definition lands.h:40
const char * name
Definition lands.h:19
bool dungeon
Definition lands.h:26
uint32_t seed
Added to the world's seed, so that each land has an island of its own.
Definition lands.h:21
float wading
How deep into its sea players can wade, in metres.
Definition lands.h:23
In metres from the middle of a land.
Definition lands.h:13
float z
Definition lands.h:15
float x
Definition lands.h:14