nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
copies.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_COPIES_H_
2#define NANOMMO_SERVER_COPIES_H_
3
4#include <chrono>
5#include <cstdint>
6#include <map>
7#include <memory>
8#include <set>
9#include <vector>
10
11#include "content/content.h"
12#include "server/interest.h"
13#include "server/world.h"
14#include "terrain/paths.h"
15#include "terrain/terrain.h"
16
17namespace nanommo {
18
19/// A land, running: a World of it, with its NPCs in their cells.
20struct Copy {
21 /// By its place in kLands.
22 int land = 0;
25 /// Whose copy of a dungeon it is, by their id. Nobody owns an open land's
26 /// copy, which everyone in the world shares.
27 uint32_t owner = 0;
28 /// How long it's had nobody in it.
29 std::chrono::nanoseconds empty{0};
30};
31
32/// The world's lands, as copies. Each open land has one from the start, and a
33/// dungeon has one for each player who goes in, from when they do.
34class Copies {
35 public:
36 /// After its last player leaves, a dungeon's copy stops, and waits this long
37 /// for them before it goes, so that someone who steps out finds it as they
38 /// left it.
39 static constexpr std::chrono::minutes kEmptyLife{5};
40
41 /// The world's seed makes each land's terrain, and the content fills them.
42 Copies(uint32_t seed, Content content);
43
44 /// Into their land's copy: the open land's, or for a dungeon, their own.
45 void Join(uint32_t id, Player player);
46
47 void Leave(uint32_t id);
48
49 /// The copy the player's in, or nullptr.
50 Copy* Of(uint32_t id);
51
52 /// Steps the copies with players in them, and the open lands' always, takes
53 /// players through the gates, and drops the dungeons' copies that have been
54 /// empty for kEmptyLife.
55 void Step(std::chrono::nanoseconds time);
56
57 /// By their ids.
58 const std::map<uint32_t, Copy>& all() const { return copies_; }
59
60 /// What all of them are made of, which doesn't change as the game runs.
61 const Content& content() const { return *content_; }
62
63 /// The lines each copy has for its players since the last time.
64 std::vector<Notice> TakeNotices();
65
66 /// What's happened in all of them since the last time, each with the copy
67 /// it happened in.
68 std::vector<Event> TakeEvents();
69
70 /// The players whose trade, in any of them, has opened, changed or ended
71 /// since the last time.
72 std::set<uint32_t> TakeTradeNews();
73
74 /// The players whose duel, in any of them, has been asked for, counted
75 /// down, started or ended since the last time.
76 std::set<uint32_t> TakeDuelNews();
77
78 /// The wars between the world's guilds, for each of them, and each made
79 /// after.
80 void SetWars(const std::vector<War>& wars);
81
82 /// The players killed by an enemy at war, in any of them, since the last
83 /// time.
84 std::vector<WarKill> TakeWarKills();
85
86 /// In all the copies.
87 int players() const;
88
89 private:
90 /// The copy of the land for the player, which for a dungeon it makes if
91 /// they haven't one.
92 uint32_t For(int land, uint32_t id);
93 void Travel();
94
95 /// One copy, which each copy of each land shares.
96 std::shared_ptr<const Content> content_;
97 /// Each land's, made once, which each of its copies copies.
98 std::vector<Terrain> terrains_;
99 /// Each land's, which its copies share.
100 std::vector<std::shared_ptr<Paths>> paths_;
101 std::map<uint32_t, Copy> copies_;
102 uint32_t next_ = 1;
103 /// The copy each player's in, by their ids.
104 std::map<uint32_t, uint32_t> where_;
105 std::vector<War> wars_;
106};
107
108} // namespace nanommo
109
110#endif // NANOMMO_SERVER_COPIES_H_
void SetWars(const std::vector< War > &wars)
Definition copies.cc:88
int players() const
In all the copies.
Definition copies.cc:103
const std::map< uint32_t, Copy > & all() const
By their ids.
Definition copies.h:58
Copies(uint32_t seed, Content content)
The world's seed makes each land's terrain, and the content fills them.
Definition copies.cc:20
Copy * Of(uint32_t id)
The copy the player's in, or nullptr.
Definition copies.cc:48
std::set< uint32_t > TakeTradeNews()
Definition copies.cc:72
std::vector< Event > TakeEvents()
Definition copies.cc:61
static constexpr std::chrono::minutes kEmptyLife
Definition copies.h:39
void Join(uint32_t id, Player player)
Into their land's copy: the open land's, or for a dungeon, their own.
Definition copies.cc:33
std::set< uint32_t > TakeDuelNews()
Definition copies.cc:80
const Content & content() const
What all of them are made of, which doesn't change as the game runs.
Definition copies.h:61
std::vector< Notice > TakeNotices()
The lines each copy has for its players since the last time.
Definition copies.cc:53
std::vector< WarKill > TakeWarKills()
Definition copies.cc:95
void Leave(uint32_t id)
Definition copies.cc:39
void Step(std::chrono::nanoseconds time)
Definition copies.cc:111
Definition chat.cc:9
std::optional< protocol::Input > Travel(Trip &trip, float x, float z)
Definition wander.cc:60
std::map< Cell, std::vector< uint32_t > > Cells
The ids of what's in each cell.
Definition interest.h:33
A land, running: a World of it, with its NPCs in their cells.
Definition copies.h:20
Cells npc_cells
Definition copies.h:24
World world
Definition copies.h:23
std::chrono::nanoseconds empty
How long it's had nobody in it.
Definition copies.h:29
int land
By its place in kLands.
Definition copies.h:22
uint32_t owner
Definition copies.h:27