SuperTuxKart
Loading...
Searching...
No Matches
capture_the_flag.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2018 SuperTuxKart-Team
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18#ifndef CAPTURE_THE_FLAG_HPP
19#define CAPTURE_THE_FLAG_HPP
20
21#include "modes/free_for_all.hpp"
22
23#include <vector>
24#include <string>
25
26namespace irr
27{
28 namespace scene
29 {
30 class IAnimatedMeshSceneNode; class IAnimatedMesh; class ISceneNode;
31 }
32}
33
34class CTFFlag;
35
37{
38private:
39 scene::IAnimatedMeshSceneNode* m_red_flag_node;
40
41 scene::IAnimatedMeshSceneNode* m_blue_flag_node;
42
43 scene::IAnimatedMesh* m_red_flag_mesh;
44
45 scene::IAnimatedMesh* m_blue_flag_mesh;
46
47 scene::ISceneNode* m_red_flag_indicator;
48
49 scene::ISceneNode* m_blue_flag_indicator;
50
51 SFXBase* m_scored_sound;
52
53 int m_red_scores, m_blue_scores;
54
55 /* Save the last captured flag ticks */
56 int m_last_captured_flag_ticks;
57
58 /* Used in updateGraphics to add race gui message for flag */
59 int m_red_flag_status, m_blue_flag_status;
60
61 std::map<int, int> m_swatter_reset_kart_ticks;
62
63 std::shared_ptr<CTFFlag> m_red_flag, m_blue_flag;
64
65 // ------------------------------------------------------------------------
66 bool getDroppedFlagTrans(const btTransform& kt, btTransform* out) const;
67 // ------------------------------------------------------------------------
68 void resetRedFlagToOrigin();
69 // ------------------------------------------------------------------------
70 void resetBlueFlagToOrigin();
71 // ------------------------------------------------------------------------
72 virtual video::SColor getColor(unsigned int kart_id) const OVERRIDE;
73
74public:
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
78 virtual ~CaptureTheFlag();
79 // ------------------------------------------------------------------------
80 virtual void init() OVERRIDE;
81 // ------------------------------------------------------------------------
82 virtual void reset(bool restart=false) OVERRIDE;
83 // ------------------------------------------------------------------------
84 virtual void update(int ticks) OVERRIDE;
85 // ------------------------------------------------------------------------
86 virtual void updateGraphics(float dt) OVERRIDE;
87 // ------------------------------------------------------------------------
88 virtual bool hasTeam() const OVERRIDE { return true; }
89 // ------------------------------------------------------------------------
90 virtual bool isRaceOver() OVERRIDE;
91 // ------------------------------------------------------------------------
92 virtual bool kartHit(int kart_id, int hitter = -1) OVERRIDE;
93 // ------------------------------------------------------------------------
94 virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
95 // ------------------------------------------------------------------------
96 virtual const std::string& getIdent() const OVERRIDE;
97 // ------------------------------------------------------------------------
98 bool getKartCTFResult(unsigned int kart_id) const
99 {
100 if (m_red_scores == m_blue_scores)
101 return true;
102
103 bool red_win = m_red_scores > m_blue_scores;
104 KartTeam team = getKartTeam(kart_id);
105
106 if ((red_win && team == KART_TEAM_RED) ||
107 (!red_win && team == KART_TEAM_BLUE))
108 return true;
109 else
110 return false;
111 }
112 // ------------------------------------------------------------------------
113 int getRedScore() const { return m_red_scores; }
114 // ------------------------------------------------------------------------
115 int getBlueScore() const { return m_blue_scores; }
116 // ------------------------------------------------------------------------
117 int getRedHolder() const;
118 // ------------------------------------------------------------------------
119 int getBlueHolder() const;
120 // ------------------------------------------------------------------------
121 bool isRedFlagInBase() const;
122 // ------------------------------------------------------------------------
123 bool isBlueFlagInBase() const;
124 // ------------------------------------------------------------------------
125 const Vec3& getRedFlag() const;
126 // ------------------------------------------------------------------------
127 const Vec3& getBlueFlag() const;
128 // ------------------------------------------------------------------------
129 void ctfScored(int kart_id, bool red_team_scored, int new_kart_score,
130 int new_red_score, int new_blue_score);
131 // ------------------------------------------------------------------------
132 void loseFlagForKart(int kart_id);
133 // ------------------------------------------------------------------------
134 void resetKartForSwatterHit(int kart_id, int at_world_ticks)
135 { m_swatter_reset_kart_ticks[kart_id] = at_world_ticks; }
136 // ------------------------------------------------------------------------
137 virtual std::pair<uint32_t, uint32_t> getGameStartedProgress() const
138 OVERRIDE
139 {
140 std::pair<uint32_t, uint32_t> progress(
141 std::numeric_limits<uint32_t>::max(),
142 std::numeric_limits<uint32_t>::max());
143 if (RaceManager::get()->hasTimeTarget())
144 {
145 progress.first = (uint32_t)m_time;
146 }
147 if (m_red_scores > m_blue_scores)
148 {
149 progress.second = (uint32_t)((float)m_red_scores /
150 (float)RaceManager::get()->getHitCaptureLimit() * 100.0f);
151 }
152 else
153 {
154 progress.second = (uint32_t)((float)m_blue_scores /
155 (float)RaceManager::get()->getHitCaptureLimit() * 100.0f);
156 }
157 return progress;
158 }
159 // ------------------------------------------------------------------------
160 virtual void saveCompleteState(BareNetworkString* bns,
161 STKPeer* peer) OVERRIDE;
162 // ------------------------------------------------------------------------
163 virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE;
164}; // CaptureTheFlag
165
166#endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Definition: ctf_flag.hpp:44
Definition: capture_the_flag.hpp:37
CaptureTheFlag()
Constructor.
Definition: capture_the_flag.cpp:50
virtual std::pair< uint32_t, uint32_t > getGameStartedProgress() const OVERRIDE
Used by server to get the current started game progress in either or both remaining time or progress ...
Definition: capture_the_flag.hpp:137
virtual bool isRaceOver() OVERRIDE
The battle is over if only one kart is left, or no player kart.
Definition: capture_the_flag.cpp:473
virtual const std::string & getIdent() const OVERRIDE
Returns the internal identifier for this race.
Definition: capture_the_flag.cpp:556
virtual bool kartHit(int kart_id, int hitter=-1) OVERRIDE
Called when a kart is hit.
Definition: capture_the_flag.cpp:534
virtual void reset(bool restart=false) OVERRIDE
Called when a battle is restarted.
Definition: capture_the_flag.cpp:139
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE
Determines the rescue position for a kart.
Definition: capture_the_flag.cpp:548
virtual void update(int ticks) OVERRIDE
Updates the physics, all karts, the track, and projectile manager.
Definition: capture_the_flag.cpp:226
virtual void init() OVERRIDE
call just after instanciating.
Definition: capture_the_flag.cpp:93
virtual void updateGraphics(float dt) OVERRIDE
This updates all only graphical elements.
Definition: capture_the_flag.cpp:164
Definition: free_for_all.hpp:29
The base class for sound effects.
Definition: sfx_base.hpp:43
Represents a peer. This class is used to interface the ENetPeer structure.
Definition: stk_peer.hpp:76
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
double m_time
Elasped/remaining time in seconds.
Definition: world_status.hpp:94
KartTeam getKartTeam(unsigned int kart_id) const
Get the team of kart in world (including AIs)
Definition: world.cpp:1663