1/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
2#ifndef GAME_SERVER_ENTITIES_DRAGGER_H
3#define GAME_SERVER_ENTITIES_DRAGGER_H
4
5#include <game/server/entity.h>
6
7#include <optional>
8
9class CDraggerBeam;
10
11/**
12 * Draggers generate dragger beams which pull players towards their center similar to a tractor beam
13 *
14 * A dragger will only generate one dragger beam per team for the closest player for whom the following criteria are met:
15 * - The player is within the dragger range (sv_dragger_range).
16 * - The player is not a super player
17 * - The dragger is activated
18 * - The dragger beam to be generated is not blocked by laser stoppers (or solid blocks if IgnoreWalls is set to false)
19 * With the exception of solo players, for whom a dragger beam is always generated, regardless of the rest of the team,
20 * if the above criteria are met. Solo players have no influence on the generation of the dragger beam for the rest
21 * of the team.
22 * A created dragger beam remains for the selected player until one of the criteria is no longer fulfilled. Only then
23 * can a new dragger beam be created for that team, which may drag another team partner.
24 */
25class CDragger : public CEntity
26{
27 // m_Core is the direction vector by which a dragger is shifted at each movement tick (every 150ms)
28 vec2 m_Core;
29 float m_Strength;
30 bool m_IgnoreWalls;
31 int m_EvalTick;
32
33 int m_aTargetIdInTeam[MAX_CLIENTS];
34 CDraggerBeam *m_apDraggerBeam[MAX_CLIENTS];
35
36 void LookForPlayersToDrag();
37 // Returns the client id of the dragger beam that is snapped with the dragger's id
38 // for the given snapping client, if there is one
39 std::optional<int> DraggerBeamUsingDraggerId(int SnappingClientId);
40
41public:
42 CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool IgnoreWalls, int Layer = 0, int Number = 0);
43
44 void RemoveDraggerBeam(int ClientId);
45 bool WillDraggerBeamUseDraggerId(int TargetClientId, int SnappingClientId);
46
47 void Reset() override;
48 void Tick() override;
49 void Snap(int SnappingClient) override;
50 void SwapClients(int Client1, int Client2) override;
51};
52
53#endif // GAME_SERVER_ENTITIES_DRAGGER_H
54