18#ifndef HEADER_CTF_FLAG_HPP
19#define HEADER_CTF_FLAG_HPP
21#include "network/rewinder.hpp"
23#include "utils/vec3.hpp"
25#include "LinearMath/btTransform.h"
28enum FlagColor :
unsigned int
34namespace GE {
class GERenderInfo; }
40 class IAnimatedMeshSceneNode;
46 static const int IN_BASE = -1;
47 static const int OFF_BASE = -2;
53 btTransform m_flag_trans;
56 const btTransform m_flag_base_trans;
60 uint16_t m_ticks_since_off_base;
62 FlagColor m_flag_color;
65 int m_off_base_compressed[4];
68 std::shared_ptr<GE::GERenderInfo> m_flag_render_info;
70 uint16_t m_deactivated_ticks;
73 CTFFlag(FlagColor fc,
const btTransform& base_trans)
75 std::string{RN_RED_FLAG} : std::string{RN_BLUE_FLAG}),
76 m_flag_base_trans(base_trans)
80 m_flag_status = IN_BASE;
81 m_flag_trans.setOrigin(
Vec3(0.0f));
82 m_flag_trans.setRotation(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
84 m_ticks_since_off_base = 0;
85 memset(m_off_base_compressed, 0, 16);
102 int getHolder()
const
104 if (m_flag_status >= 0)
105 return m_flag_status;
109 int getStatus()
const {
return m_flag_status; }
111 const Vec3& getOrigin()
const {
return (
Vec3&)m_flag_trans.getOrigin(); }
113 const Vec3& getBaseOrigin()
const
114 {
return (
Vec3&)m_flag_base_trans.getOrigin(); }
116 const btTransform& getBaseTrans()
const {
return m_flag_base_trans; }
118 void resetToBase(
unsigned deactivated_ticks = 0)
121 if (deactivated_ticks > 2047)
122 deactivated_ticks = 2047;
123 m_deactivated_ticks = deactivated_ticks;
124 m_flag_status = IN_BASE;
125 m_ticks_since_off_base = 0;
129 void setCapturedByKart(
int kart_id)
131 m_flag_status = (int8_t)kart_id;
132 m_ticks_since_off_base = 0;
136 void dropFlagAt(
const btTransform& t);
138 bool isInBase()
const {
return m_flag_status == IN_BASE; }
140 bool isActivated()
const {
return m_deactivated_ticks == 0; }
142 bool canBeCaptured()
const
143 {
return !(m_flag_status >= 0) && isActivated(); }
145 void update(
int ticks);
147 void updateFlagTrans(
const btTransform& off_base_trans = btTransform());
149 void updateFlagGraphics(irr::scene::IAnimatedMeshSceneNode* flag_node);
151 void initFlagRenderInfo(irr::scene::IAnimatedMeshSceneNode* flag_node);
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Definition: ctf_flag.hpp:44
virtual void rewindToEvent(BareNetworkString *buffer)
Called when an event needs to be replayed.
Definition: ctf_flag.hpp:96
virtual void undoEvent(BareNetworkString *buffer)
Called when an event needs to be undone.
Definition: ctf_flag.hpp:94
virtual BareNetworkString * saveState(std::vector< std::string > *ru)
Provides a copy of the state of the object in one memory buffer.
Definition: ctf_flag.cpp:35
virtual void computeError()
Called when a rewind is finished, and is used to compute the error caused by the rewind (which is the...
Definition: ctf_flag.hpp:90
virtual void restoreState(BareNetworkString *buffer, int count)
Called when a state needs to be replayed.
Definition: ctf_flag.cpp:56
virtual void undoState(BareNetworkString *buffer)
Undo the effects of the given state, but do not rewind to that state (which is done by rewindTo).
Definition: ctf_flag.hpp:100
virtual void saveTransform()
Called before a rewind.
Definition: ctf_flag.hpp:88
Definition: rewinder.hpp:44
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
Declares the general types that are used by the network.