23 terrains_.emplace_back(seed + land.seed, land.wading);
24 paths_.push_back(std::make_shared<Paths>(terrains_.back()));
26 for (
int land = 0; land < std::ssize(
kLands); ++land) {
27 if (!
kLands[land].dungeon) {
34 const uint32_t copy = For(player.
land,
id);
35 copies_.at(copy).world.Join(
id, std::move(player));
40 const auto where = where_.find(
id);
41 if (where == where_.end()) {
44 copies_.at(where->second).world.Leave(
id);
49 const auto where = where_.find(
id);
50 return where != where_.end() ? &copies_.at(where->second) :
nullptr;
54 std::vector<Notice> notices;
55 for (
auto& [
id, copy] : copies_) {
56 std::ranges::move(copy.world.TakeNotices(), std::back_inserter(notices));
62 std::vector<Event> events;
63 for (
auto& [
id, copy] : copies_) {
64 for (
Event& event : copy.world.TakeEvents()) {
66 events.push_back(std::move(event));
73 std::set<uint32_t> news;
74 for (
auto& [
id, copy] : copies_) {
75 news.merge(copy.world.TakeTradeNews());
81 std::set<uint32_t> news;
82 for (
auto& [
id, copy] : copies_) {
83 news.merge(copy.world.TakeDuelNews());
90 for (
auto& [
id, copy] : copies_) {
91 copy.world.SetWars(wars_);
96 std::vector<WarKill> kills;
97 for (
auto& [
id, copy] : copies_) {
98 std::ranges::move(copy.world.TakeWarKills(), std::back_inserter(kills));
105 for (
const auto& [
id, copy] : copies_) {
106 count +=
static_cast<int>(copy.world.players().size());
112 for (
auto it = copies_.begin(); it != copies_.end();) {
113 Copy& copy = it->second;
115 copy.
empty = std::chrono::nanoseconds::zero();
125 std::cout <<
"dropped player " << copy.
owner <<
"'s copy of the "
127 it = copies_.erase(it);
132uint32_t Copies::For(
int land, uint32_t
id) {
133 const uint32_t owner =
kLands[land].dungeon ? id : 0;
134 for (
const auto& [copy_id, copy] : copies_) {
135 if (copy.land == land && copy.owner == owner) {
139 const uint32_t made = next_++;
141 .emplace(made, Copy{.land = land,
142 .world = World(std::random_device()(),
143 terrains_[land], content_,
147 copy.world.SetWars(wars_);
149 SpawnNpcs(copy.world, land, content_->npcs);
150 copy.npc_cells =
CellsOf(copy.world.npcs());
152 std::cout <<
"made player " << owner <<
" a copy of the "
153 <<
kLands[land].name << std::endl;
158void Copies::Travel() {
161 for (
auto& [from, copy] : copies_) {
164 std::vector<std::pair<uint32_t, const Gate*>> travellers;
165 for (
const auto& [
id, player] : copy.world.players()) {
166 for (
const Gate& gate :
kGates) {
167 if (gate.land == copy.land &&
InGate(gate, player.x, player.z)) {
168 travellers.emplace_back(
id, &gate);
173 for (
const auto& [
id, gate] : travellers) {
174 Player player = copy.world.players().at(
id);
175 copy.world.Leave(
id);
177 player.x = arrival.x;
178 player.z = arrival.z;
179 player.land = gate->to;
180 std::cout << player.name <<
" went to the " <<
kLands[gate->to].name
182 const uint32_t to = For(gate->to,
id);
183 copies_.at(to).world.Join(
id, std::move(player));
void SetWars(const std::vector< War > &wars)
int players() const
In all the copies.
Copies(uint32_t seed, Content content)
The world's seed makes each land's terrain, and the content fills them.
Copy * Of(uint32_t id)
The copy the player's in, or nullptr.
std::set< uint32_t > TakeTradeNews()
std::vector< Event > TakeEvents()
static constexpr std::chrono::minutes kEmptyLife
void Join(uint32_t id, Player player)
Into their land's copy: the open land's, or for a dungeon, their own.
std::set< uint32_t > TakeDuelNews()
const Content & content() const
What all of them are made of, which doesn't change as the game runs.
std::vector< Notice > TakeNotices()
The lines each copy has for its players since the last time.
std::vector< WarKill > TakeWarKills()
void Step(std::chrono::nanoseconds time)
const std::map< uint32_t, Player > & players() const
void Step(std::chrono::nanoseconds time)
Vector3 Place(const Point &point, const Terrain &terrain)
constexpr std::array< Gate, 4 > kGates
void SpawnMonsters(World &land, int index, const MonsterTable &table)
Place Arrival(const Gate &gate, float yaw)
bool InGate(const Gate &gate, float x, float z)
constexpr std::array< Land, 3 > kLands
Cells CellsOf(const std::map< uint32_t, Unit > &units)
void SpawnNpcs(World &land, int index, const NpcTable &table)
A land, running: a World of it, with its NPCs in their cells.
std::chrono::nanoseconds empty
How long it's had nobody in it.
int land
By its place in kLands.
int land
Which of the world's lands, by its place in kLands.