SuperTuxKart
Loading...
Searching...
No Matches
soccer_world.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2004-2015 SuperTuxKart-Team
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef SOCCER_WORLD_HPP
20#define SOCCER_WORLD_HPP
21
22#include "modes/world_with_rank.hpp"
23#include "states_screens/race_gui_base.hpp"
24#include "karts/abstract_kart.hpp"
25
26#include <string>
27
28class AbstractKart;
29class BallGoalData;
30class Controller;
31class NetworkString;
32class TrackObject;
33class TrackSector;
34
40{
41public:
43 {
45 unsigned int m_id;
49 float m_time;
51 std::string m_kart;
53 core::stringw m_player;
55 std::string m_country_code;
58 }; // ScorerData
59
60private:
62 {
63 public:
65 unsigned int m_kart_id;
68
69 bool operator < (const KartDistanceMap& r) const
70 {
71 return m_distance < r.m_distance;
72 }
73 KartDistanceMap(unsigned int kart_id = 0, float distance = 0.0f)
74 {
75 m_kart_id = kart_id;
76 m_distance = distance;
77 }
78 }; // KartDistanceMap
79
80 std::vector<KartDistanceMap> m_red_kdm;
81 std::vector<KartDistanceMap> m_blue_kdm;
82 std::unique_ptr<BallGoalData> m_bgd;
83
86 btRigidBody* m_ball_body;
87
90 bool m_count_down_reached_zero;
91
92 SFXBase *m_goal_sound;
93
97 int m_ball_hitter;
98
100 std::vector<ScorerData> m_red_scorers;
101 std::vector<ScorerData> m_blue_scorers;
102
105
106 float m_ball_heading;
107
108 std::vector<int> m_team_icon_draw_id;
109
110 std::vector<btTransform> m_goal_transforms;
112 void updateBallPosition(int ticks);
114 void updateAIData();
116 int getTeamNum(KartTeam team) const;
117
120 std::vector<int> m_goal_frame;
121
122 int m_reset_ball_ticks;
123 int m_ticks_back_to_own_goal;
124
125 void resetKartsToSelfGoals();
126
127public:
128
129 SoccerWorld();
130 virtual ~SoccerWorld();
131
132 virtual void init() OVERRIDE;
133 virtual void onGo() OVERRIDE;
134
135 // clock events
136 virtual bool isRaceOver() OVERRIDE;
137 virtual void countdownReachedZero() OVERRIDE;
138 virtual void terminateRace() OVERRIDE;
139
140 // overriding World methods
141 virtual void reset(bool restart=false) OVERRIDE;
142
143 virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
144 virtual btTransform getRescueTransform(unsigned int rescue_pos) const
145 OVERRIDE;
146 virtual bool useFastMusicNearEnd() const OVERRIDE { return false; }
147 virtual void getKartsDisplayInfo(
148 std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
149
150 virtual bool raceHasLaps() OVERRIDE { return false; }
151
152 virtual void enterRaceOverState() OVERRIDE;
153
154 virtual const std::string& getIdent() const OVERRIDE;
155
156 virtual void update(int ticks) OVERRIDE;
157
158 bool shouldDrawTimer() const OVERRIDE { return !isStartPhase(); }
159 // ------------------------------------------------------------------------
160 void onCheckGoalTriggered(bool first_goal);
161 // ------------------------------------------------------------------------
162 void setBallHitter(unsigned int kart_id);
163 // ------------------------------------------------------------------------
165 bool getKartSoccerResult(unsigned int kart_id) const;
166 // ------------------------------------------------------------------------
167 int getScore(KartTeam team) const
168 {
169 return (int)(team == KART_TEAM_BLUE ? m_blue_scorers.size()
170 : m_red_scorers.size());
171 }
172 // ------------------------------------------------------------------------
173 const std::vector<ScorerData>& getScorers(KartTeam team) const
174 { return (team == KART_TEAM_BLUE ? m_blue_scorers : m_red_scorers); }
175 // ------------------------------------------------------------------------
176 int getBallNode() const;
177 // ------------------------------------------------------------------------
178 const Vec3& getBallPosition() const
179 { return (Vec3&)m_ball_body->getCenterOfMassTransform().getOrigin(); }
180 // ------------------------------------------------------------------------
181 bool ballNotMoving() const
182 {
183 return (m_ball_body->getLinearVelocity().x() == 0.0f ||
184 m_ball_body->getLinearVelocity().z() == 0.0f);
185 }
186 // ------------------------------------------------------------------------
187 float getBallHeading() const
188 { return m_ball_heading; }
189 // ------------------------------------------------------------------------
190 float getBallDiameter() const;
191 // ------------------------------------------------------------------------
192 bool ballApproachingGoal(KartTeam team) const;
193 // ------------------------------------------------------------------------
194 Vec3 getBallAimPosition(KartTeam team, bool reverse = false) const;
195 // ------------------------------------------------------------------------
196 bool isCorrectGoal(unsigned int kart_id, bool first_goal) const;
197 // ------------------------------------------------------------------------
198 int getBallChaser(KartTeam team) const
199 {
200 // Only AI call this function, so each team should have at least a kart
201 assert(m_blue_kdm.size() > 0 && m_red_kdm.size() > 0);
202 return (team == KART_TEAM_BLUE ? m_blue_kdm[0].m_kart_id :
203 m_red_kdm[0].m_kart_id);
204 }
205 // ------------------------------------------------------------------------
207 int getAttacker(KartTeam team) const;
208 // ------------------------------------------------------------------------
209 void handlePlayerGoalFromServer(const NetworkString& ns);
210 // ------------------------------------------------------------------------
211 void handleResetBallFromServer(const NetworkString& ns);
212 // ------------------------------------------------------------------------
213 virtual bool hasTeam() const OVERRIDE { return true; }
214 // ------------------------------------------------------------------------
215 virtual std::pair<uint32_t, uint32_t> getGameStartedProgress() const
216 OVERRIDE
217 {
218 std::pair<uint32_t, uint32_t> progress(
219 std::numeric_limits<uint32_t>::max(),
220 std::numeric_limits<uint32_t>::max());
221 if (RaceManager::get()->hasTimeTarget())
222 {
223 progress.first = (uint32_t)m_time;
224 }
225 else if (m_red_scorers.size() > m_blue_scorers.size())
226 {
227 progress.second = (uint32_t)((float)m_red_scorers.size() /
228 (float)RaceManager::get()->getMaxGoal() * 100.0f);
229 }
230 else
231 {
232 progress.second = (uint32_t)((float)m_blue_scorers.size() /
233 (float)RaceManager::get()->getMaxGoal() * 100.0f);
234 }
235 return progress;
236 }
237 // ------------------------------------------------------------------------
238 virtual void saveCompleteState(BareNetworkString* bns,
239 STKPeer* peer) OVERRIDE;
240 // ------------------------------------------------------------------------
241 virtual void restoreCompleteState(const BareNetworkString& b) OVERRIDE;
242 // ------------------------------------------------------------------------
243 virtual bool isGoalPhase() const OVERRIDE
244 {
245 int diff = m_ticks_back_to_own_goal - getTicksSinceStart();
246 return diff > 0 && diff < stk_config->time2Ticks(3.0f);
247 }
248 // ------------------------------------------------------------------------
249 AbstractKart* getKartAtDrawingPosition(unsigned int p) const OVERRIDE
250 { return getKart(m_team_icon_draw_id[p - 1]); }
251 // ------------------------------------------------------------------------
252 TrackObject* getBall() const { return m_ball; }
253}; // SoccerWorld
254
255
256#endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Definition: soccer_world.cpp:55
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
This is the base class for kart controller - that can be a player or a a robot.
Definition: controller.hpp:46
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
The base class for sound effects.
Definition: sfx_base.hpp:43
int time2Ticks(float t)
Converts a time value into ticks (of physics time steps).
Definition: stk_config.hpp:316
Represents a peer. This class is used to interface the ENetPeer structure.
Definition: stk_peer.hpp:76
Definition: soccer_world.hpp:62
float m_distance
Distance to ball from kart.
Definition: soccer_world.hpp:67
unsigned int m_kart_id
World ID of kart.
Definition: soccer_world.hpp:65
An implementation of WorldWithRank, to provide the soccer game mode Notice: In soccer world,...
Definition: soccer_world.hpp:40
void updateAIData()
Function to update data for AI usage.
Definition: soccer_world.cpp:877
virtual void reset(bool restart=false) OVERRIDE
Called when a soccer game is restarted.
Definition: soccer_world.cpp:322
bool shouldDrawTimer() const OVERRIDE
The code that draws the timer should call this first to know whether the game mode wants a timer draw...
Definition: soccer_world.hpp:158
TrackSector * m_ball_track_sector
Data generated from navmesh.
Definition: soccer_world.hpp:104
bool getKartSoccerResult(unsigned int kart_id) const
Get the soccer result of kart in soccer world (including AIs)
Definition: soccer_world.cpp:774
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: soccer_world.hpp:215
int m_frame_count
Profiling usage.
Definition: soccer_world.hpp:119
virtual const std::string & getIdent() const OVERRIDE
Returns the internal identifier for this race.
Definition: soccer_world.cpp:411
AbstractKart * getKartAtDrawingPosition(unsigned int p) const OVERRIDE
Returns the kart at which position (start from 1) to draw race icon.
Definition: soccer_world.hpp:249
int getAttacker(KartTeam team) const
Get the AI who will attack the other team ball chaser.
Definition: soccer_world.cpp:912
virtual void getKartsDisplayInfo(std::vector< RaceGUIBase::KartIconDisplayInfo > *info) OVERRIDE
Returns the data to display in the race gui.
Definition: soccer_world.cpp:1149
virtual bool raceHasLaps() OVERRIDE
Called when it is needed to know whether this kind of race involves counting laps.
Definition: soccer_world.hpp:150
SoccerWorld()
Constructor.
Definition: soccer_world.cpp:238
virtual void update(int ticks) OVERRIDE
Update the world and the track.
Definition: soccer_world.cpp:420
int getTeamNum(KartTeam team) const
Get number of teammates in a team, used by starting position assign.
int m_goal_target
Number of goals needed to win.
Definition: soccer_world.hpp:89
virtual void terminateRace() OVERRIDE
Called at the end of a race.
Definition: soccer_world.cpp:396
virtual void onGo() OVERRIDE
Called when 'go' is being displayed for the first time.
Definition: soccer_world.cpp:388
virtual bool isRaceOver() OVERRIDE
The soccer game is over if time up or either team wins.
Definition: soccer_world.cpp:744
virtual ~SoccerWorld()
The destructor frees all data structures.
Definition: soccer_world.cpp:261
virtual void enterRaceOverState() OVERRIDE
Called when the race is finished, but it still leaves some time for an end of race animation,...
Definition: soccer_world.cpp:970
virtual void init() OVERRIDE
Initializes the soccer world.
Definition: soccer_world.cpp:273
std::vector< ScorerData > m_red_scorers
Goals data of each team scored.
Definition: soccer_world.hpp:100
virtual btTransform getRescueTransform(unsigned int rescue_pos) const OVERRIDE
Returns the bullet transformation for the specified rescue index.
Definition: soccer_world.cpp:955
TrackObject * m_ball
Keep a pointer to the track object of soccer ball.
Definition: soccer_world.hpp:85
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE
Determines the rescue position for a kart.
Definition: soccer_world.cpp:941
virtual void countdownReachedZero() OVERRIDE
Called when the match time ends.
Definition: soccer_world.cpp:765
int m_ball_invalid_timer
Counts ticks when the ball is off track, so a reset can be triggered if the ball is off for more than...
Definition: soccer_world.hpp:96
void setBallHitter(unsigned int kart_id)
Sets the last kart that hit the ball, to be able to identify the scorer later.
Definition: soccer_world.cpp:736
void updateBallPosition(int ticks)
Function to update the location the ball on the polygon map.
Definition: soccer_world.cpp:792
virtual bool useFastMusicNearEnd() const OVERRIDE
Returns if this mode should use fast music (if available).
Definition: soccer_world.hpp:146
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:56
This object keeps track of which sector an object is on.
Definition: track_sector.hpp:39
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
int getTicksSinceStart() const
Get the ticks since start regardless of which way the clock counts.
Definition: world_status.hpp:226
A WorldWithRank is a world where the karts are ranked.
Definition: world_with_rank.hpp:39
AbstractKart * getKart(int kartId) const
Returns the kart with a given world id.
Definition: world.hpp:342
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:42
Definition: soccer_world.hpp:43
unsigned int m_id
World ID of kart which scores.
Definition: soccer_world.hpp:45
core::stringw m_player
Player name which scores.
Definition: soccer_world.hpp:53
std::string m_kart
Kart ident which scores.
Definition: soccer_world.hpp:51
std::string m_country_code
Country code of player.
Definition: soccer_world.hpp:55
HandicapLevel m_handicap_level
Handicap of player.
Definition: soccer_world.hpp:57
float m_time
Time goal.
Definition: soccer_world.hpp:49
bool m_correct_goal
Whether this goal is socred correctly (identify for own goal).
Definition: soccer_world.hpp:47