nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
monsters.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_MONSTERS_H_
2#define NANOMMO_SERVER_MONSTERS_H_
3
4#include <chrono>
5#include <cstdint>
6#include <map>
7#include <random>
8#include <utility>
9#include <vector>
10
11#include "content/monsters.h"
12#include "server/world.h"
13#include "terrain/terrain.h"
14
15namespace nanommo {
16
17constexpr std::chrono::milliseconds kShortestRest{2000};
18constexpr std::chrono::milliseconds kLongestRest{6000};
19
20Monster MonsterOf(const monsters::Kind& kind, float x, float z);
21
22/// Spawns the land's monsters from the table's spawns and camps. The index is
23/// the land's place in kLands.
24void SpawnMonsters(World& land, int index, const MonsterTable& table);
25
26/// In metres between the middles of two camps, at least.
27constexpr float kCampSpacing = 30.0f;
28
29/// Places for camps of monsters, which the terrain's seed picks: between the
30/// beach and the rock, well away from the middle, where the players start,
31/// and spread out over the land, kCampSpacing apart at least. As many as
32/// count, or as many as it finds room for in its tries.
33std::vector<std::pair<float, float>> Camps(const Terrain& terrain, int count);
34
35std::chrono::nanoseconds RandomRest(std::mt19937& random);
36
37void Wander(Monster& monster, const Terrain& terrain,
38 std::chrono::nanoseconds time, std::mt19937& random);
39
40/// The player the monster goes for: the one who's hurt it most, seen or not,
41/// or else the nearest it can see, either way within its leash of its home.
42uint32_t Spot(const Monster& monster,
43 const std::map<uint32_t, Player>& players);
44
45/// Goes for the player Spot finds, and once nobody who's hurt the monster is
46/// left within its leash, forgets them. A boss goes home then, at full health
47/// and in its first phase, and nothing hurts it on its way.
48void Hunt(Monster& monster, const std::map<uint32_t, Player>& players,
49 const Terrain& terrain, std::chrono::nanoseconds time,
50 std::mt19937& random);
51
52void Revive(Monster& monster, std::chrono::nanoseconds time,
53 std::mt19937& random);
54
55} // namespace nanommo
56
57#endif // NANOMMO_SERVER_MONSTERS_H_
Definition chat.cc:9
constexpr std::chrono::milliseconds kLongestRest
Definition monsters.h:18
std::chrono::nanoseconds RandomRest(std::mt19937 &random)
Definition monsters.cc:156
constexpr float kCampSpacing
In metres between the middles of two camps, at least.
Definition monsters.h:27
void Wander(Monster &monster, const Terrain &terrain, std::chrono::nanoseconds time, std::mt19937 &random)
Definition monsters.cc:162
void SpawnMonsters(World &land, int index, const MonsterTable &table)
Definition monsters.cc:108
void Hunt(Monster &monster, const std::map< uint32_t, Player > &players, const Terrain &terrain, std::chrono::nanoseconds time, std::mt19937 &random)
Definition monsters.cc:228
constexpr std::chrono::milliseconds kShortestRest
Definition monsters.h:17
Monster MonsterOf(const monsters::Kind &kind, float x, float z)
Definition monsters.cc:86
std::vector< std::pair< float, float > > Camps(const Terrain &terrain, int count)
Definition monsters.cc:131
void Revive(Monster &monster, std::chrono::nanoseconds time, std::mt19937 &random)
Definition monsters.cc:293
uint32_t Spot(const Monster &monster, const std::map< uint32_t, Player > &players)
Definition monsters.cc:194