nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
animator.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_ANIMATOR_H_
2#define NANOMMO_CLIENT_ANIMATOR_H_
3
4#include <raylib.h>
5
6#include <cstdint>
7#include <map>
8#include <numbers>
9#include <optional>
10#include <string>
11#include <utility>
12#include <vector>
13
14#include "content/content.h"
15#include "content/figures.h"
16#include "protocol/nanommo.pb.h"
17
18namespace nanommo {
19
20struct Figure {
21 uint32_t id = 0;
22 std::string name;
23 /// A player's guild, by its name, or empty.
24 std::string guild;
25 /// A player's faction, or the one an NPC is the herald of, by its id in the
26 /// factions file, or 0 for none, and its colour.
27 uint32_t faction = 0;
28 Color faction_color = BLANK;
29 bool you = false;
30 bool monster = false;
31 bool npc = false;
32 /// A monster's or an NPC's kind, by its id in the content folder.
33 uint32_t kind = 0;
34 /// A monster's tint, or the colour of what an NPC wears that's dyed.
35 Color color = WHITE;
36 /// An NPC's skin and hair, from its kind, and a player's, with their build,
37 /// as they chose them. Without any, their id picks them.
38 std::optional<Features> features;
39 /// Whether the player can talk to it, by clicking it.
40 bool talks = false;
41 /// The skills an NPC teaches, by their ids, when it's a trainer.
42 std::vector<uint32_t> teaches;
43 /// The quests an NPC gives, by their ids in the quests file.
44 std::vector<uint32_t> quests;
45 /// Over an NPC with a quest for you: '!' for one to take, or '?' for one
46 /// you've done, to turn in.
47 char mark = 0;
48 int level = 1;
49 int health = 0;
50 int max_health = 0;
51 /// A boss's phase, from one, or 0 for any other monster.
52 uint32_t phase = 0;
53 /// A monster's height, in metres, from its kind's look.
54 float height = 0.0f;
55 /// What a player holds, by its id in the items file.
56 uint32_t weapon = 0;
57 /// What else a player wears, by its ids in the items file.
58 std::vector<uint32_t> wearing;
59 /// While a player uses a skill, the monster they picked, by its id, or in
60 /// a duel, the player.
61 uint32_t target = 0;
62 uint32_t target_player = 0;
63 Vector3 position{0.0f, 0.0f, 0.0f};
64 float yaw = 0.0f;
65 /// How high a blow's thrown it, in metres off the ground.
66 float lift = 0.0f;
67 /// How far it's tipped over, in radians, and which way it tips, as a yaw:
68 /// a monster rocking back from a blow.
69 float lean = 0.0f;
70 float lean_yaw = 0.0f;
71 /// How lit up it is from a blow just landed, from 0 to 1.
72 float flash = 0.0f;
73 protocol::Motion from = protocol::MOTION_IDLE;
74 /// While a motion is a skill's, which skill, by its id in the skills file.
75 uint32_t from_skill = 0;
76 float from_time = 0.0f;
77 protocol::Motion to = protocol::MOTION_IDLE;
78 uint32_t to_skill = 0;
79 /// While a player uses a skill, how many they've started: a new count is a
80 /// new cast, even of the skill before.
81 uint32_t casts = 0;
82 float to_time = 0.0f;
83 float blend = 1.0f;
84};
85
86/// Which figure is which, as players, monsters and NPCs each count their ids
87/// from one.
88uint64_t Who(const Figure& figure);
89
90/// What a player looks like, from the looks they chose: the skin, the hair
91/// colour and the hair at those places in the figures' lists, each wrapped
92/// round to what there is, so that any looks draw as someone, and the build,
93/// which the rig's builds wrap round the same way as they're drawn.
94Features FeaturesOf(const figures::Figures& figures,
95 const protocol::Looks& looks);
96
97class Animator {
98 public:
99 /// Monsters and NPCs come by kind, so the animator looks up their names, in
100 /// the player's language, and their looks in the content.
101 explicit Animator(Content content = Content())
102 : content_(std::move(content)) {}
103
104 static constexpr float kBlendTime = 0.25f;
105
106 /// For a monster's lift: the share of the gap still left after a second is
107 /// e to the minus this.
108 static constexpr float kFollowRate = 15.0f;
109
110 static constexpr float kTurnRate = 4.0f * std::numbers::pi_v<float>;
111
112 std::vector<Figure> Update(const protocol::World& world, float seconds);
113
114 private:
115 Content content_;
116 // Players, monsters and NPCs each have ids of their own, so they're kept
117 // apart.
118 std::map<uint32_t, Figure> players_;
119 std::map<uint32_t, Figure> monsters_;
120 std::map<uint32_t, Figure> npcs_;
121};
122
123} // namespace nanommo
124
125#endif // NANOMMO_CLIENT_ANIMATOR_H_
static constexpr float kBlendTime
Definition animator.h:104
static constexpr float kFollowRate
Definition animator.h:108
Animator(Content content=Content())
Definition animator.h:101
std::vector< Figure > Update(const protocol::World &world, float seconds)
Definition animator.cc:150
static constexpr float kTurnRate
Definition animator.h:110
Definition chat.cc:9
uint64_t Who(const Figure &figure)
Definition animator.cc:124
Features FeaturesOf(const figures::Figures &figures, uint32_t id)
Definition figures.cc:74
uint32_t target_player
Definition animator.h:62
protocol::Motion from
Definition animator.h:73
uint32_t kind
A monster's or an NPC's kind, by its id in the content folder.
Definition animator.h:33
float lift
How high a blow's thrown it, in metres off the ground.
Definition animator.h:66
Color color
A monster's tint, or the colour of what an NPC wears that's dyed.
Definition animator.h:35
std::string name
Definition animator.h:22
Color faction_color
Definition animator.h:28
float flash
How lit up it is from a blow just landed, from 0 to 1.
Definition animator.h:72
uint32_t from_skill
While a motion is a skill's, which skill, by its id in the skills file.
Definition animator.h:75
std::vector< uint32_t > quests
The quests an NPC gives, by their ids in the quests file.
Definition animator.h:44
uint32_t target
Definition animator.h:61
std::vector< uint32_t > teaches
The skills an NPC teaches, by their ids, when it's a trainer.
Definition animator.h:42
float from_time
Definition animator.h:76
Vector3 position
Definition animator.h:63
std::string guild
A player's guild, by its name, or empty.
Definition animator.h:24
bool talks
Whether the player can talk to it, by clicking it.
Definition animator.h:40
float height
A monster's height, in metres, from its kind's look.
Definition animator.h:54
uint32_t casts
Definition animator.h:81
uint32_t phase
A boss's phase, from one, or 0 for any other monster.
Definition animator.h:52
uint32_t weapon
What a player holds, by its id in the items file.
Definition animator.h:56
protocol::Motion to
Definition animator.h:77
std::vector< uint32_t > wearing
What else a player wears, by its ids in the items file.
Definition animator.h:58
std::optional< Features > features
Definition animator.h:38
uint32_t to_skill
Definition animator.h:78
uint32_t faction
Definition animator.h:27