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 26 namespace irr 27 { 28 namespace scene 29 { 30 class IAnimatedMeshSceneNode; class IAnimatedMesh; class ISceneNode; 31 } 32 } 33 34 class CTFFlag; 35 36 class CaptureTheFlag : public FreeForAll 37 { 38 private: 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 74 public: 75 // ------------------------------------------------------------------------ 76 CaptureTheFlag(); 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 // ------------------------------------------------------------------------ hasTeam() const88 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 // ------------------------------------------------------------------------ getKartCTFResult(unsigned int kart_id) const98 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 // ------------------------------------------------------------------------ getRedScore() const113 int getRedScore() const { return m_red_scores; } 114 // ------------------------------------------------------------------------ getBlueScore() const115 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 // ------------------------------------------------------------------------ resetKartForSwatterHit(int kart_id,int at_world_ticks)134 void resetKartForSwatterHit(int kart_id, int at_world_ticks) 135 { m_swatter_reset_kart_ticks[kart_id] = at_world_ticks; } 136 // ------------------------------------------------------------------------ getGameStartedProgress() const137 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 167