nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
lands.cc
Go to the documentation of this file.
1#include "terrain/lands.h"
2
3#include <algorithm>
4#include <cmath>
5#include <cstddef>
6#include <string_view>
7
8namespace nanommo {
9
10int LandNamed(std::string_view name) {
11 for (std::size_t i = 0; i < kLands.size(); ++i) {
12 if (kLands[i].name == name) {
13 return static_cast<int>(i);
14 }
15 }
16 return 0;
17}
18
19bool IsLand(std::string_view name) {
20 for (const Land& land : kLands) {
21 if (land.name == name) {
22 return true;
23 }
24 }
25 return false;
26}
27
28bool InGate(const Gate& gate, float x, float z) {
29 return std::hypot(x - gate.place.x, z - gate.place.z) < kGateRadius;
30}
31
32const Gate& Twin(const Gate& gate) {
33 // GatesLeadBack makes sure there's one.
34 return *std::ranges::find_if(kGates, [&gate](const Gate& other) {
35 return other.land == gate.to && other.to == gate.land;
36 });
37}
38
39const Gate& WayOut(int dungeon) {
40 return *std::ranges::find(kGates, dungeon, &Gate::land);
41}
42
43Place Arrival(const Gate& gate, float yaw) {
44 const Place& twin = Twin(gate).place;
45 return {.x = twin.x + kArrival * std::sin(yaw),
46 .z = twin.z + kArrival * std::cos(yaw)};
47}
48
49} // namespace nanommo
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 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
In metres from the middle of a land.
Definition lands.h:13
float z
Definition lands.h:15
float x
Definition lands.h:14