SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
Entity.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include "CharacterData.h"
10 #include "CommonNetStructures.h"
11 #include "Costume.h"
12 #include "FixedPointValue.h"
13 #include "Movement.h"
14 #include "Powers.h"
15 #include "Team.h"
16 #include "StateInterpolator.h"
17 #include "StateStorage.h"
23 #include "Common/GameData/Store.h"
24 
25 #include <glm/gtc/constants.hpp>
26 #include <QQueue>
27 #include <array>
28 #include <memory>
29 
30 struct MapClientSession;
31 class Team;
32 class Trade;
33 class Character;
34 struct PlayerData;
35 using Parse_AllKeyProfiles = std::vector<struct Keybind_Profiles>;
36 
37 enum class FadeDirection
38 {
39  In,
40  Out
41 };
42 
43 
44 
45 // returned by getEntityFromDB()
47 {
48  QString name;
51  float hitpoints;
52  float endurance;
53  uint32_t sg_id;
54  uint32_t m_db_id;
55 };
56 
57 enum class EntType : uint8_t
58 {
59  Invalid = 0,
60  NPC = 1,
61  PLAYER = 2,
62  HERO = 3,
63  CRITTER = 4,
64  CAR = 5,
65  DELIVERYTARGET = 6,
66  MOBILEGEOMETRY = 7,
67  MISSION_ITEM = 8,
68  MAPXFERDOOR = 9,
69  DOOR = 10,
70  COUNT = 11
71 };
72 
73 enum class AppearanceType : uint8_t
74 {
75  None = 0,
76  WholeCostume = 1,
77  NpcCostume = 2,
78  VillainIndex = 3,
79  SequencerName = 4
80 };
81 
82 struct SuperGroup
83 {
84  int m_SG_id = {0};
85  QString m_SG_name = "Supergroup"; // 64 chars max
86  QString m_SG_motto;
87  QString m_SG_motd;
88  QString m_SG_emblem; // 128 chars max -> hash table key from the CostumeString_HTable
89  uint32_t m_SG_color1 = 0; // supergroup color 1
90  uint32_t m_SG_color2 = 0; // supergroup color 2
91  int m_SG_rank = 1;
92 };
93 
95 {
96  bool m_has_faction = false; // send Faction info
97  int m_rank = 0; // iRank
98  QString m_faction_name; // group_name
99 };
100 
101 struct NPCData
102 {
103  bool m_is_owned = false;
104  const struct Parse_NPC *src_data;
105  int npc_idx=0;
106  int costume_variant=0;
107 };
108 
110 {
111  bool type_is_location = false;
112  uint32_t ent_idx = 0;
113  glm::vec3 pos;
114 };
115 
116 struct NetFx
117 {
118  uint8_t command;
119  uint32_t net_id;
120  uint32_t handle;
121  bool pitch_to_target = false;
122  uint8_t bone_id;
123  float client_timer = 0;
124  int client_trigger_fx = 0;
125  float duration = 0;
126  float radius = 0;
127  int power = 0; // char.toInt()
128  int debris = 0;
131 };
132 
133 
134 class Entity
135 {
136  // only EntityStore can create instances of this class
137  friend class EntityStore;
138  friend std::array<Entity,10240>;
139  using CharacterPtr = std::unique_ptr<Character>;
140  using PlayerPtr = std::unique_ptr<PlayerData>;
141  using EntityPtr = std::unique_ptr<EntityData>;
142  using NPCPtr = std::unique_ptr<NPCData>;
143  using TradePtr = std::shared_ptr<Trade>;
144 private:
145  Entity();
146  ~Entity();
147 public:
150  // Some entities might not have a character data ( doors, cars )
151  // Making it an unique_ptr<Character> makes it clear that Entity 'owns'
152  // and takes care of this data, at the same time it can be missing
153  CharacterPtr m_char;
154  // And not all entities are players
155  PlayerPtr m_player;
156  EntityPtr m_entity;
157  NPCPtr m_npc;
158 
159  SuperGroup m_supergroup; // client has this in entity class, but maybe move to Character class?
160  bool m_has_supergroup = true;
161  bool m_has_team = false;
162  Team * m_team = nullptr; // we might want t move this to Character class, but maybe Baddies use teams?
163  TradePtr m_trade;
166 
167  uint32_t m_idx = {0};
168  uint32_t m_db_id = {0};
170  glm::quat m_direction;
171  int32_t m_target_idx = -1;
172  int32_t m_assist_target_idx = -1;
173 
174  std::vector<Buffs> m_buffs;
175  QQueue<QueuedPowers> m_queued_powers;
176  std::vector<QueuedPowers> m_recharging_powers;
178  bool m_update_buffs = false;
179 
180 
181  // Animations: Sequencers, NetFx, and TriggeredMoves
182  std::vector<NetFx> m_net_fx;
183  std::vector<TriggeredMove> m_triggered_moves;
184  SeqBitSet m_seq_state; // Should be part of SeqState
186  int m_seq_move_idx = 0;
187  int m_randSeed = 0; // Sequencer uses this as a seed for random bone scale
188  bool m_has_state_mode = false;
189  bool m_seq_update = false;
190  uint8_t m_seq_move_change_time = 0;
191  uint8_t m_move_type = 0;
192 
193  int m_time_till_logout = 0; // time in miliseconds untill given entity should be marked as logged out.
195  bool m_is_logging_out = false;
196  bool m_odd_send = false;
197  bool m_no_draw_on_client = false;
198  bool m_force_camera_dir = false; // used to force the client camera direction in sendClientData()
199  bool m_is_hero = false;
200  bool m_is_villian = false;
201  bool m_contact = false;
202  uint8_t m_update_id = 1;
203  bool m_update_part_1 = true; // EntityResponse sendServerControlState
204  bool m_force_pos_and_cam = true; // EntityResponse sendServerControlState
205  bool m_full_update = true; // EntityReponse sendServerPhysicsPositions
206  bool m_has_control_id = true; // EntityReponse sendServerPhysicsPositions
207  bool m_has_interp = false; // EntityUpdateCodec storePosUpdate
208  bool m_move_instantly = false; // EntityUpdateCodec storePosUpdate
209  bool m_in_training = false;
210  bool m_has_input_on_timeframe= false;
211  bool m_is_using_mapmenu = false;
212  bool m_map_swap_collided = false;
213 
214  int u1 = 0; // used for live-debugging
215 
216  std::array<PosUpdate, 64> m_pos_updates;
217  std::array<BinTreeEntry, 7> m_interp_bintree;
218  size_t m_update_idx = 0;
219  bool m_pchar_things = false;
220  bool m_update_anims = false;
221  bool m_hasname = false;
222  bool m_classname_override = false;
223  bool m_hasRagdoll = false;
224  bool m_has_owner = false;
225  bool m_create_player = false;
226  bool m_rare_update = false;
227  int m_input_pkt_id = {0};
228  uint32_t m_input_ack = {0};
229  uint32_t ownerEntityId = 0;
230  uint32_t creatorEntityId = 0;
231  MapClientSession * m_client = nullptr;
232  FadeDirection m_fading_direction = FadeDirection::In;
233  uint32_t m_db_store_flags = 0;
235  float translucency = 1.0f;
236  bool player_type = false;
237  bool m_destroyed = false;
238  bool m_is_fading = true;
239  bool m_is_store = false;
241 
242  std::function<void(int)> m_active_dialog = NULL;
243 
244  void dump();
245 
246 static void sendAllyID(BitStream &bs);
247 static void sendPvP(BitStream &bs);
248 
249  const QString & name() const;
250  void fillFromCharacter(const GameDataStore &data);
251  void beginLogout(uint16_t time_till_logout=10); // Default logout time is 10 s
252  void setActiveDialogCallback(std::function<void(int)> callback);
253 };
std::array< PosUpdate, 64 > m_pos_updates
Definition: Entity.h:216
uint32_t handle
Definition: Entity.h:120
uint32_t net_id
Definition: Entity.h:119
NPCPtr m_npc
Definition: Entity.h:157
Definition: MapClientSession.h:32
Definition: Trade.h:95
QString m_faction_name
Definition: Entity.h:98
QString m_SG_emblem
Definition: Entity.h:88
QString m_SG_motd
Definition: Entity.h:87
PowerStance m_stance
Definition: Entity.h:177
Definition: Entity.h:109
Definition: Character.h:47
std::vector< NetFx > m_net_fx
Definition: Entity.h:182
Definition: Entity.h:82
Definition: Team.h:13
Definition: StateStorage.h:119
Definition: GameDataStore.h:27
std::vector< QueuedPowers > m_recharging_powers
Definition: Entity.h:176
Definition: Contact.h:46
SuperGroup m_supergroup
Definition: Entity.h:159
Definition: Entity.h:101
Definition: BitStream.h:34
Definition: entitydata_definitions.h:14
Definition: playerdata_definitions.h:23
Destination m_cur_destination
Definition: Entity.h:234
uint32_t m_db_id
Definition: Entity.h:54
NetFxTarget target
Definition: Entity.h:129
Definition: Entity.h:116
Definition: Entity.h:94
float endurance
Definition: Entity.h:52
Definition: Entity.h:46
MotionState m_motion_state
Definition: Entity.h:149
EntityPtr m_entity
Definition: Entity.h:156
PlayerPtr m_player
Definition: Entity.h:155
FactionData m_faction_data
Definition: Entity.h:165
float hitpoints
Definition: Entity.h:51
CharacterPtr m_char
Definition: Entity.h:153
CharacterData char_data
Definition: Entity.h:50
AppearanceType
Definition: Entity.h:73
EntityData m_entity_data
Definition: Entity.h:164
std::array< BinTreeEntry, 7 > m_interp_bintree
Definition: Entity.h:217
Definition: npc_definitions.h:57
QString m_SG_motto
Definition: Entity.h:86
Definition: Entity.h:134
uint8_t bone_id
Definition: Entity.h:122
TradePtr m_trade
Definition: Entity.h:163
vStoreItems m_store_items
Definition: Entity.h:240
uint32_t sg_id
Definition: Entity.h:53
StateStorage m_states
Definition: Entity.h:148
Definition: seq_definitions.h:409
std::vector< StoreItem > vStoreItems
Definition: Store.h:45
SeqBitSet m_seq_state
Definition: Entity.h:184
FadeDirection
Definition: Entity.h:37
Definition: Movement.h:90
std::vector< Buffs > m_buffs
Definition: Entity.h:174
EntType
Definition: Entity.h:57
uint8_t command
Definition: Entity.h:118
NetFxTarget origin
Definition: Entity.h:130
glm::quat m_direction
Definition: Entity.h:170
EntityData entity_data
Definition: Entity.h:49
Definition: Powers.h:44
QQueue< QueuedPowers > m_queued_powers
Definition: Entity.h:175
std::vector< TriggeredMove > m_triggered_moves
Definition: Entity.h:183
Definition: EntityStorage.h:24
QString name
Definition: Entity.h:48
ClientStates
Definition: ClientStates.h:10
glm::vec3 pos
Definition: Entity.h:113
std::vector< struct Keybind_Profiles > Parse_AllKeyProfiles
Definition: Entity.h:35
Definition: CharacterData.h:18
const struct Parse_NPC * src_data
Definition: Entity.h:104