SuperTuxKart
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
SoccerWorld Class Reference

An implementation of WorldWithRank, to provide the soccer game mode Notice: In soccer world, true goal means blue, false means red. More...

#include <soccer_world.hpp>

Inheritance diagram for SoccerWorld:
Inheritance graph
[legend]

Classes

class  BallGoalData
 
class  KartDistanceMap
 
struct  ScorerData
 

Public Member Functions

 SoccerWorld ()
 Constructor. More...
 
virtual ~SoccerWorld ()
 The destructor frees all data structures.
 
virtual void init () OVERRIDE
 Initializes the soccer world. More...
 
virtual void onGo () OVERRIDE
 Called when 'go' is being displayed for the first time. More...
 
virtual bool isRaceOver () OVERRIDE
 The soccer game is over if time up or either team wins.
 
virtual void countdownReachedZero () OVERRIDE
 Called when the match time ends.
 
virtual void terminateRace () OVERRIDE
 Called at the end of a race. More...
 
virtual void reset (bool restart=false) OVERRIDE
 Called when a soccer game is restarted.
 
virtual unsigned int getRescuePositionIndex (AbstractKart *kart) OVERRIDE
 Determines the rescue position for a kart. More...
 
virtual btTransform getRescueTransform (unsigned int rescue_pos) const OVERRIDE
 Returns the bullet transformation for the specified rescue index. More...
 
virtual bool useFastMusicNearEnd () const OVERRIDE
 Returns if this mode should use fast music (if available). More...
 
virtual void getKartsDisplayInfo (std::vector< RaceGUIBase::KartIconDisplayInfo > *info) OVERRIDE
 Called by the code that draws the list of karts on the race GUI to know what needs to be drawn in the current mode. More...
 
virtual bool raceHasLaps () OVERRIDE
 Called when it is needed to know whether this kind of race involves counting laps. More...
 
virtual void enterRaceOverState () OVERRIDE
 Called when the race is finished, but it still leaves some time for an end of race animation, and potentially let some more AI karts finish the race.
 
virtual const std::string & getIdent () const OVERRIDE
 Returns the internal identifier for this race.
 
virtual void update (int ticks) OVERRIDE
 Update the world and the track. More...
 
bool shouldDrawTimer () const OVERRIDE
 The code that draws the timer should call this first to know whether the game mode wants a timer drawn. More...
 
void onCheckGoalTriggered (bool first_goal)
 
void setBallHitter (unsigned int kart_id)
 Sets the last kart that hit the ball, to be able to identify the scorer later.
 
bool getKartSoccerResult (unsigned int kart_id) const
 Get the soccer result of kart in soccer world (including AIs)
 
int getScore (KartTeam team) const
 
const std::vector< ScorerData > & getScorers (KartTeam team) const
 
int getBallNode () const
 
const Vec3getBallPosition () const
 
bool ballNotMoving () const
 
float getBallHeading () const
 
float getBallDiameter () const
 
bool ballApproachingGoal (KartTeam team) const
 
Vec3 getBallAimPosition (KartTeam team, bool reverse=false) const
 
bool isCorrectGoal (unsigned int kart_id, bool first_goal) const
 
int getBallChaser (KartTeam team) const
 
int getAttacker (KartTeam team) const
 Get the AI who will attack the other team ball chaser. More...
 
void handlePlayerGoalFromServer (const NetworkString &ns)
 
void handleResetBallFromServer (const NetworkString &ns)
 
virtual bool hasTeam () const OVERRIDE
 
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 in percent. More...
 
virtual void saveCompleteState (BareNetworkString *bns, STKPeer *peer) OVERRIDE
 
virtual void restoreCompleteState (const BareNetworkString &b) OVERRIDE
 
virtual bool isGoalPhase () const OVERRIDE
 
- Public Member Functions inherited from WorldWithRank
bool displayRank () const
 
void beginSetKartPositions ()
 This function must be called before starting to set all kart positions again. More...
 
bool setKartPosition (unsigned int kart_id, unsigned int position)
 Sets the position of a kart. More...
 
void endSetKartPositions ()
 Called once the last position was set. More...
 
AbstractKartgetKartAtPosition (unsigned int p) const
 Returns the kart with a given position. More...
 
virtual int getScoreForPosition (int p)
 Returns the number of points for a kart at a specified position. More...
 
TrackSectorgetTrackSector (unsigned int kart_index) const
 Returns the track_sector object for the specified kart. More...
 
bool isOnRoad (unsigned int kart_index) const
 Returns true if the kart is on a valid graph quad. More...
 
int getSectorForKart (const AbstractKart *kart) const
 Gets the sector a kart is on. More...
 
- Public Member Functions inherited from World
 World ()
 The main world class is used to handle the track and the karts. More...
 
virtual unsigned int getNumberOfRescuePositions () const
 Returns the number of rescue positions on a given track and game mode. More...
 
virtual void moveKartAfterRescue (AbstractKart *kart)
 Places a kart that is rescued. More...
 
virtual int getFinishedLapsOfKart (unsigned int kart_index) const
 Returns the number of laps for a given kart. More...
 
virtual void updateGraphics (float dt)
 This updates all only graphical elements. More...
 
virtual void pause (Phase phase) OVERRIDE
 Pauses the music (and then pauses WorldStatus).
 
virtual void unpause () OVERRIDE
 Switches back from a pause state to the previous state.
 
virtual void getDefaultCollectibles (int *collectible_type, int *amount)
 Called to determine the default collectibles to give each player at the start for this kind of race. More...
 
virtual void collectedItem (const AbstractKart *kart, const ItemState *item)
 Receives notification if an item is collected. More...
 
virtual void endRaceEarly ()
 
virtual bool hasRaceEndedEarly () const
 
virtual bool haveBonusBoxes ()
 Called to determine whether this race mode uses bonus boxes. More...
 
virtual void kartAdded (AbstractKart *kart, scene::ISceneNode *node)
 If you want to do something to karts or their graphics at the start of the race, override this. More...
 
virtual void newLap (unsigned int kart_index)
 Called whenever a kart starts a new lap. More...
 
virtual bool kartHit (int kart_id, int hitter=-1)
 Called when a kart was hit by a projectile. More...
 
virtual void onMouseClick (int x, int y)
 
HighscoresgetHighscores () const
 
void schedulePause (Phase phase)
 
void scheduleUnpause ()
 
void scheduleExitRace ()
 
void scheduleTutorial ()
 
void updateWorld (int ticks)
 This is the main interface to update the world. More...
 
void handleExplosion (const Vec3 &xyz, AbstractKart *kart_hit, PhysicalObject *object)
 
AbstractKartgetPlayerKart (unsigned int player) const
 Returns the n-th player kart. More...
 
AbstractKartgetLocalPlayerKart (unsigned int n) const
 Returns the nth local player kart, i.e. More...
 
virtual const btTransform & getStartTransform (int index)
 Returns the start coordinates for a kart with a given index. More...
 
void moveKartTo (AbstractKart *kart, const btTransform &t)
 Places the kart at a given position and rotation. More...
 
RaceGUIBasegetRaceGUI () const
 Returns a pointer to the race gui. More...
 
unsigned int getNumKarts () const
 Returns the number of karts in the race. More...
 
AbstractKartgetKart (int kartId) const
 Returns the kart with a given world id. More...
 
const KartList & getKarts () const
 Returns all karts. More...
 
unsigned int getCurrentNumKarts () const
 Returns the number of currently active (i.e.non-elikminated) karts. More...
 
unsigned int getCurrentNumPlayers () const
 Returns the number of currently active (i.e. More...
 
void resetElimination ()
 
virtual void addReservedKart (int kart_id)
 
bool useHighScores () const
 
virtual void onFirePressed (Controller *who)
 Override if you want to know when a kart presses fire.
 
virtual bool useChecklineRequirements () const
 Whether to compute checkline requirements for each world on the quadgraph. More...
 
virtual void escapePressed ()
 
virtual void loadCustomModels ()
 
void eliminateKart (int kart_number, bool notify_of_elimination=true)
 Remove (eliminate) a kart from the race.
 
void setUnfairTeam (bool val)
 
KartTeam getKartTeam (unsigned int kart_id) const
 Get the team of kart in world (including AIs)
 
int getTeamNum (KartTeam team) const
 
void setNetworkWorld (bool is_networked)
 Set the network mode (true if networked)
 
bool isNetworkWorld () const
 
void initTeamArrows (AbstractKart *k)
 Set the team arrow on karts if necessary.
 
- Public Member Functions inherited from WorldStatus
virtual ~WorldStatus ()
 Destructor of WorldStatus.
 
virtual void updateTime (int ticks)
 Updates the world time and clock (which might be running backwards), and all status information, called once per frame at the end of the main loop. More...
 
void startReadySetGo ()
 
virtual void pause (Phase phase)
 Pauses the game and switches to the specified phase. More...
 
void setTime (const float time)
 Sets the time for the clock. More...
 
void setTicks (int ticks)
 Sets a new time for the world time, measured in ticks. More...
 
void setTicksForRewind (int ticks)
 Sets a new time for the world time (used by rewind), measured in ticks. More...
 
bool isStartPhase () const
 
bool isRacePhase () const
 
bool isActiveRacePhase () const
 
bool isFinishPhase () const
 While the race menu is being displayed, m_phase is limbo, and m_previous_phase is finish. More...
 
const Phase getPhase () const
 Returns the current race phase. More...
 
void setPhase (Phase phase)
 Sets the current race phase. More...
 
void setClockMode (const ClockType mode, const float initial_time=0.0f)
 Call to specify what kind of clock you want. More...
 
int getClockMode () const
 Returns the current clock mode. More...
 
float getTime () const
 Returns the current race time. More...
 
int getTimeTicks () const
 Returns the current race time in time ticks (i.e. More...
 
int getTicksSinceStart () const
 Get the ticks since start regardless of which way the clock counts.
 
int getAuxiliaryTicks () const
 
bool isLiveJoinWorld () const
 
void setLiveJoinWorld (bool val)
 
int getMusicDescriptionTicks () const
 
void endLiveJoinWorld (int ticks_now)
 Base on the network timer set current world count up ticks to tick_now.
 

Private Member Functions

void updateBallPosition (int ticks)
 Function to update the location the ball on the polygon map. More...
 
void updateAIData ()
 Function to update data for AI usage. More...
 
int getTeamNum (KartTeam team) const
 Get number of teammates in a team, used by starting position assign. More...
 
void resetKartsToSelfGoals ()
 

Private Attributes

std::vector< KartDistanceMapm_red_kdm
 
std::vector< KartDistanceMapm_blue_kdm
 
BallGoalData m_bgd
 
TrackObjectm_ball
 Keep a pointer to the track object of soccer ball.
 
btRigidBody * m_ball_body
 
int m_goal_target
 Number of goals needed to win.
 
bool m_count_down_reached_zero
 
SFXBasem_goal_sound
 
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 2 seconds. More...
 
int m_ball_hitter
 
std::vector< ScorerDatam_red_scorers
 Goals data of each team scored.
 
std::vector< ScorerDatam_blue_scorers
 
TrackSectorm_ball_track_sector
 Data generated from navmesh.
 
float m_ball_heading
 
std::vector< btTransform > m_goal_transforms
 
int m_frame_count
 Profiling usage.
 
std::vector< int > m_goal_frame
 
int m_reset_ball_ticks
 
int m_ticks_back_to_own_goal
 

Additional Inherited Members

- Public Types inherited from World
typedef std::vector< std::shared_ptr< AbstractKart > > KartList
 
- Public Types inherited from WorldStatus
enum  ClockType { CLOCK_NONE, CLOCK_CHRONO, CLOCK_COUNTDOWN }
 Different clock types for a race. More...
 
enum  Phase {
  TRACK_INTRO_PHASE, SETUP_PHASE, WAIT_FOR_SERVER_PHASE, SERVER_READY_PHASE,
  READY_PHASE, SET_PHASE, GO_PHASE, MUSIC_PHASE,
  RACE_PHASE, DELAY_FINISH_PHASE, RESULT_DISPLAY_PHASE, FINISH_PHASE,
  IN_GAME_MENU_PHASE, UNDEFINED_PHASE
}
 
- Static Public Member Functions inherited from World
static WorldgetWorld ()
 Returns a pointer to the (singleton) world object. More...
 
static void deleteWorld ()
 Delete the )singleton) world object, if it exists, and sets the singleton pointer to NULL. More...
 
static void setWorld (World *world)
 Sets the pointer to the world object. More...
 
- Protected Member Functions inherited from WorldWithRank
unsigned int getClosestStartPoint (AbstractKart *kart)
 
void updateSectorForKarts ()
 Localize each kart on the graph using its center xyz.
 
- Protected Member Functions inherited from World
void updateHighscores (int *best_highscore_rank)
 Called at the end of a race. More...
 
void resetAllKarts ()
 Waits till each kart is resting on the ground. More...
 
ControllerloadAIController (AbstractKart *kart)
 Creates an AI controller for the kart. More...
 
virtual std::shared_ptr< AbstractKartcreateKart (const std::string &kart_ident, int index, int local_player_id, int global_player_id, RaceManager::KartType type, HandicapLevel handicap)
 Creates a kart, having a certain position, starting location, and local and global player id (if applicable). More...
 
virtual void createRaceGUI ()
 
void updateTrack (int ticks)
 Only updates the track. More...
 
virtual float estimateFinishTimeForKart (AbstractKart *kart)
 Used for AI karts that are still racing when all player kart finished. More...
 
void updateAchievementDataEndRace ()
 
void updateAchievementModeCounters (bool start)
 
- Protected Attributes inherited from WorldWithRank
std::vector< int > m_position_index
 This contains a mapping from race position to kart index. More...
 
bool m_display_rank
 Whether to display the rank in the race GUI.
 
std::vector< int > m_score_for_position
 The points given to a kart on a given position (index is 0 based, so using race-position - 1. More...
 
std::vector< TrackSector * > m_kart_track_sector
 Stores the current graph node and track coordinates for each kart. More...
 
- Protected Attributes inherited from World
int m_red_ai
 
int m_blue_ai
 
std::map< int, KartTeam > m_kart_team_map
 
std::map< int, unsigned int > m_kart_position_map
 
KartList m_karts
 The list of all karts. More...
 
RandomGenerator m_random
 
AbstractKartm_fastest_kart
 
int m_eliminated_karts
 Number of eliminated karts. More...
 
int m_eliminated_players
 Number of eliminated players. More...
 
int m_num_players
 OVerall number of players. More...
 
bool m_faster_music_active
 
bool m_stop_music_when_dialog_open
 
bool m_unfair_team
 
bool m_use_highscores
 Whether highscores should be used for this kind of race. More...
 
RaceGUIBasem_race_gui
 Pointer to the race GUI. More...
 
RaceGUIBasem_saved_race_gui
 The actual race gui needs to be saved when the race result gui is displayed since it is still needed in case of a restart, and it can't simply be created again (since it assumes that it can render to texture without having any scene nodes, but in case of a restart there are scene nodes). More...
 
bool m_schedule_pause
 Pausing/unpausing are not done immediately, but at next udpdate. More...
 
bool m_schedule_unpause
 Pausing/unpausing are not done immediately, but at next udpdate. More...
 
bool m_schedule_exit_race
 
bool m_schedule_tutorial
 
Phase m_scheduled_pause_phase
 
bool m_self_destruct
 Set when the world needs to be deleted but you can't do it immediately because you are e.g. More...
 
bool m_is_network_world
 Set when the world is online and counts network players. More...
 
bool m_ended_early
 
- Protected Attributes inherited from WorldStatus
double m_time
 Elasped/remaining time in seconds. More...
 
int m_time_ticks
 Time in number of ticks (in terms of physics time steps). More...
 
bool m_play_racestart_sounds
 If the start race should be played, disabled in cutscenes. More...
 
bool m_play_track_intro_sound
 
bool m_play_ready_set_go_sounds
 
std::atomic< Phase > m_phase
 

Detailed Description

An implementation of WorldWithRank, to provide the soccer game mode Notice: In soccer world, true goal means blue, false means red.

Constructor & Destructor Documentation

◆ SoccerWorld()

SoccerWorld::SoccerWorld ( )

Constructor.

Sets up the clock mode etc.

Member Function Documentation

◆ getAttacker()

int SoccerWorld::getAttacker ( KartTeam  team) const

Get the AI who will attack the other team ball chaser.

◆ getGameStartedProgress()

virtual std::pair<uint32_t, uint32_t> SoccerWorld::getGameStartedProgress ( ) const
inlinevirtual

Used by server to get the current started game progress in either or both remaining time or progress in percent.

uint32_t max for either or both if not available.

Reimplemented from World.

◆ getKartsDisplayInfo()

virtual void SoccerWorld::getKartsDisplayInfo ( std::vector< RaceGUIBase::KartIconDisplayInfo > *  info)
inlinevirtual

Called by the code that draws the list of karts on the race GUI to know what needs to be drawn in the current mode.

Implements World.

◆ getRescuePositionIndex()

unsigned int SoccerWorld::getRescuePositionIndex ( AbstractKart kart)
virtual

Determines the rescue position for a kart.

The rescue position is the start position which is has the biggest accumulated distance to all other karts, and which has no other kart very close. The latter avoids dropping a kart on top of another kart. This is the method used

Parameters
kartThe kart that is going to be rescued.
Returns
The index of the start position to which the rescued kart should be moved to.

Reimplemented from WorldWithRank.

◆ getRescueTransform()

btTransform SoccerWorld::getRescueTransform ( unsigned int  rescue_pos) const
virtual

Returns the bullet transformation for the specified rescue index.

Returns the start transform with the give index.

Parameters
rescue_posIndex of the start position to be returned.
Returns
The transform of the corresponding start position.

Reimplemented from World.

◆ getTeamNum()

int SoccerWorld::getTeamNum ( KartTeam  team) const
private

Get number of teammates in a team, used by starting position assign.

◆ init()

void SoccerWorld::init ( )
virtual

Initializes the soccer world.

It sets up the data structure to keep track of points etc. for each kart.

Reimplemented from WorldWithRank.

◆ onGo()

void SoccerWorld::onGo ( )
virtual

Called when 'go' is being displayed for the first time.

Here the brakes of the karts are released.

Reimplemented from World.

◆ raceHasLaps()

virtual bool SoccerWorld::raceHasLaps ( )
inlinevirtual

Called when it is needed to know whether this kind of race involves counting laps.

Implements World.

◆ shouldDrawTimer()

bool SoccerWorld::shouldDrawTimer ( ) const
inlinevirtual

The code that draws the timer should call this first to know whether the game mode wants a timer drawn.

Reimplemented from World.

◆ terminateRace()

void SoccerWorld::terminateRace ( )
virtual

Called at the end of a race.

Updates highscores, pauses the game, and informs the unlock manager about the finished race. This function must be called after all other stats were updated from the different game modes.

Reimplemented from World.

◆ update()

void SoccerWorld::update ( int  ticks)
virtual

Update the world and the track.

Parameters
ticksPhysics time steps - should be 1.

Reimplemented from World.

◆ updateAIData()

void SoccerWorld::updateAIData ( )
private

Function to update data for AI usage.

◆ updateBallPosition()

void SoccerWorld::updateBallPosition ( int  ticks)
private

Function to update the location the ball on the polygon map.

Localize the ball on the navigation mesh.

◆ useFastMusicNearEnd()

virtual bool SoccerWorld::useFastMusicNearEnd ( ) const
inlinevirtual

Returns if this mode should use fast music (if available).

Reimplemented from World.

Member Data Documentation

◆ m_ball_invalid_timer

int SoccerWorld::m_ball_invalid_timer
private

Counts ticks when the ball is off track, so a reset can be triggered if the ball is off for more than 2 seconds.


The documentation for this class was generated from the following files: