2008-07-14 01:21:37 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2006 SuperTuxKart-Team
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#ifndef HEADER_RACEMANAGER_H
|
|
|
|
#define HEADER_RACEMANAGER_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
2008-09-07 09:25:58 -04:00
|
|
|
|
2008-07-29 01:38:30 -04:00
|
|
|
#include "grand_prix_data.hpp"
|
2008-09-07 09:38:46 -04:00
|
|
|
#include "network/remote_kart_info.hpp"
|
2008-07-14 01:21:37 -04:00
|
|
|
|
2008-09-21 12:07:56 -04:00
|
|
|
class World;
|
|
|
|
class Track;
|
2008-12-09 17:21:01 -05:00
|
|
|
class Kart;
|
2008-09-21 12:07:56 -04:00
|
|
|
|
2008-07-14 01:21:37 -04:00
|
|
|
/** The race manager has two functions:
|
2008-09-16 19:46:29 -04:00
|
|
|
* 1) it stores information about the race the user selected (e.g. number
|
|
|
|
* of karts, track, race mode etc.). Most of the values are just stored
|
|
|
|
* from the menus, and just read back, except for GP mode (the race
|
|
|
|
* manager stores the GP information, but World queries only track
|
|
|
|
* and number of laps, so in case of GP this information is taken from
|
|
|
|
* the GrandPrix object), and local player information (number of local
|
|
|
|
* players, and selected karts). The local player information is read
|
|
|
|
* from the NetworkManager, gathered on the server (from all clients and
|
|
|
|
* the server, see NetworkManager::setupPlayerKartInfo), and then the
|
|
|
|
* combined information distributed to all RaceManagers in all clients
|
|
|
|
* and server. Even in no networking mode, the data flow is the same:
|
|
|
|
* information about local players is stored here, then processed by
|
|
|
|
* NetworkManager::setupPlayerKartInfo and the 'global' information about
|
|
|
|
* player karts is set in the RaceManager, to be used by World later on.
|
|
|
|
* 2) when a race is started, it creates the world, and keeps track of
|
|
|
|
* score during the race. When a race is finished, it deletes the world,
|
|
|
|
* and (depending on race mode) starts the next race by creating a new
|
|
|
|
* world.
|
|
|
|
* Information in the RaceManager is considered to be 'more static', sometimes
|
|
|
|
* the world has similar functions showing the current state. E.g.: the
|
|
|
|
* race manager keeps track of the number of karts with which the race was
|
|
|
|
* started, while world keeps track of the number of karts currently in the
|
|
|
|
* race (consider a race mode like follow the leader where karts can get
|
|
|
|
* eliminated, but still the RaceManager has to accumulate points for those
|
|
|
|
* karts).
|
|
|
|
* The race manager handles all race types as a kind of grand prix. E.g.:
|
|
|
|
* a quick race is basically a GP with only one track (so the race manager
|
|
|
|
* keeps track of scores even though no scores are used in a quick race).
|
|
|
|
*/
|
2008-07-14 01:21:37 -04:00
|
|
|
class RaceManager
|
|
|
|
{
|
|
|
|
public:
|
2008-09-21 20:55:27 -04:00
|
|
|
/** The major types or races supported in STK
|
|
|
|
*/
|
|
|
|
enum MajorRaceModeType
|
|
|
|
{
|
|
|
|
MAJOR_MODE_GRAND_PRIX,
|
|
|
|
MAJOR_MODE_SINGLE
|
|
|
|
};
|
2008-10-10 20:32:44 -04:00
|
|
|
|
|
|
|
// quick method to tell the difference between battle modes and race modes
|
|
|
|
// think of it like a bitmask, but done in decimal to avoid endianness issues
|
|
|
|
#define LINEAR_RACE(ID, COUNT_LAPSES) (1000+ID+100*COUNT_LAPSES)
|
|
|
|
#define BATTLE_ARENA(ID) (2000+ID)
|
2008-09-21 20:55:27 -04:00
|
|
|
/** Minor variants to the major types of race.
|
2008-10-10 20:32:44 -04:00
|
|
|
* Make sure to use the 'LINEAR_RACE/BATTLE_ARENA' macros
|
|
|
|
*/
|
2008-09-21 20:55:27 -04:00
|
|
|
enum MinorRaceModeType
|
|
|
|
{
|
2008-10-10 20:32:44 -04:00
|
|
|
MINOR_MODE_QUICK_RACE = LINEAR_RACE(0, true),
|
|
|
|
MINOR_MODE_TIME_TRIAL = LINEAR_RACE(1, true),
|
|
|
|
MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
|
|
|
|
|
2008-10-14 16:20:54 -04:00
|
|
|
MINOR_MODE_3_STRIKES = BATTLE_ARENA(0)
|
2008-09-21 20:55:27 -04:00
|
|
|
};
|
2008-10-10 20:32:44 -04:00
|
|
|
#undef LINEAR_RACE
|
|
|
|
#undef BATTLE_ARENA
|
|
|
|
|
2008-11-24 18:19:47 -05:00
|
|
|
/** Difficulty. */
|
|
|
|
enum Difficulty { RD_EASY, RD_MEDIUM, RD_HARD };
|
2008-09-16 19:46:29 -04:00
|
|
|
|
|
|
|
/** Different kart types: A local player, a player connected via network,
|
|
|
|
* an AI kart, the leader kart (currently not used), a ghost kart
|
|
|
|
* (currently not used). */
|
2008-09-07 09:25:58 -04:00
|
|
|
enum KartType { KT_PLAYER, KT_NETWORK_PLAYER, KT_AI, KT_LEADER, KT_GHOST };
|
2008-07-14 01:21:37 -04:00
|
|
|
private:
|
|
|
|
struct KartStatus
|
|
|
|
{
|
|
|
|
std::string m_ident; // The .tkkf filename without the .tkkf
|
2008-09-07 09:33:12 -04:00
|
|
|
std::string m_player_name; // for networked karts
|
2008-07-14 01:21:37 -04:00
|
|
|
int m_score; // score for this kart
|
2008-12-25 13:16:49 -05:00
|
|
|
int m_last_score; // needed for restart race, and for race results GUI.
|
2008-07-14 01:21:37 -04:00
|
|
|
double m_overall_time; // sum of times of all races
|
|
|
|
double m_last_time; // needed for restart
|
|
|
|
int m_prev_finish_pos; // previous finished position
|
2008-09-07 09:25:58 -04:00
|
|
|
KartType m_kart_type; // Kart type: AI, player, network player etc.
|
2008-09-07 09:51:44 -04:00
|
|
|
int m_local_player_id; // player controling the kart, for AI: -1
|
|
|
|
int m_global_player_id; // global ID of player
|
2008-12-25 12:59:41 -05:00
|
|
|
int m_gp_final_rank; // In GPs, at the end, will hold the overall rank of this kart.
|
|
|
|
|
2008-07-14 01:21:37 -04:00
|
|
|
KartStatus(const std::string& ident, const int& prev_finish_pos,
|
2008-09-07 09:51:44 -04:00
|
|
|
int local_player_id, int global_player_id, KartType kt) :
|
2008-07-14 01:21:37 -04:00
|
|
|
m_ident(ident), m_score(0), m_last_score(0),
|
|
|
|
m_overall_time(0.0f), m_last_time(0.0f),
|
2008-09-07 09:25:58 -04:00
|
|
|
m_prev_finish_pos(prev_finish_pos), m_kart_type(kt),
|
2008-09-07 09:51:44 -04:00
|
|
|
m_local_player_id(local_player_id),
|
|
|
|
m_global_player_id(global_player_id)
|
2008-07-14 01:21:37 -04:00
|
|
|
{}
|
|
|
|
|
|
|
|
}; // KartStatus
|
|
|
|
|
|
|
|
std::vector<KartStatus> m_kart_status;
|
|
|
|
Difficulty m_difficulty;
|
2008-09-21 20:55:27 -04:00
|
|
|
MajorRaceModeType m_major_mode;
|
|
|
|
MinorRaceModeType m_minor_mode;
|
2008-07-14 01:21:37 -04:00
|
|
|
typedef std::vector<std::string> PlayerKarts;
|
2008-09-13 03:09:36 -04:00
|
|
|
/** Stores remote kart information about all player karts. */
|
2008-09-07 09:51:44 -04:00
|
|
|
std::vector<RemoteKartInfo> m_player_karts;
|
|
|
|
std::vector<RemoteKartInfo> m_local_kart_info;
|
2008-07-14 01:21:37 -04:00
|
|
|
std::vector<std::string> m_tracks;
|
2008-09-07 09:33:12 -04:00
|
|
|
std::vector<int> m_host_ids;
|
2008-07-14 01:21:37 -04:00
|
|
|
std::vector<int> m_num_laps;
|
|
|
|
std::vector<int> m_score_for_position;
|
2008-09-07 10:24:40 -04:00
|
|
|
std::vector<std::string> m_random_kart_list;
|
2008-07-14 01:21:37 -04:00
|
|
|
int m_track_number;
|
2008-07-29 01:38:30 -04:00
|
|
|
GrandPrixData m_grand_prix;
|
2008-07-14 01:21:37 -04:00
|
|
|
int m_num_karts;
|
|
|
|
unsigned int m_num_finished_karts;
|
|
|
|
unsigned int m_num_finished_players;
|
|
|
|
int m_coin_target;
|
2008-09-07 09:51:44 -04:00
|
|
|
|
2008-07-14 01:21:37 -04:00
|
|
|
void startNextRace(); // start a next race
|
|
|
|
|
|
|
|
friend bool operator< (const KartStatus& left, const KartStatus& right)
|
|
|
|
{
|
|
|
|
return (left.m_score < right.m_score);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2008-12-09 17:21:01 -05:00
|
|
|
bool m_active_race; //True if there is a race
|
2008-07-14 01:21:37 -04:00
|
|
|
|
2008-09-21 12:07:56 -04:00
|
|
|
static World* getWorld();
|
|
|
|
static void setWorld(World* world);
|
|
|
|
static Track* getTrack();
|
|
|
|
static Kart* getPlayerKart(const unsigned int n);
|
|
|
|
static Kart* getKart(const unsigned int n);
|
|
|
|
|
2008-07-14 01:21:37 -04:00
|
|
|
public:
|
2008-09-07 09:51:44 -04:00
|
|
|
RaceManager();
|
|
|
|
~RaceManager();
|
2008-07-14 01:21:37 -04:00
|
|
|
void reset();
|
2008-09-07 09:51:44 -04:00
|
|
|
void setLocalKartInfo(unsigned int player_id, const std::string& kart);
|
|
|
|
const RemoteKartInfo&
|
|
|
|
getLocalKartInfo(unsigned int n) const {return m_local_kart_info[n];}
|
|
|
|
void setNumLocalPlayers(unsigned int n);
|
|
|
|
unsigned int getNumLocalPlayers() const {return m_local_kart_info.size(); };
|
|
|
|
|
|
|
|
void setNumPlayers(int num);
|
|
|
|
void setPlayerKart(unsigned int player_id, const RemoteKartInfo& ki);
|
2008-07-14 01:21:37 -04:00
|
|
|
void RaceFinished(const Kart* kart, float time);
|
|
|
|
void setTrack(const std::string& track);
|
2008-07-29 01:38:30 -04:00
|
|
|
void setGrandPrix(const GrandPrixData &gp){ m_grand_prix = gp; }
|
2008-07-14 01:21:37 -04:00
|
|
|
void setDifficulty(Difficulty diff);
|
|
|
|
void setNumLaps(int num) { m_num_laps.clear();
|
|
|
|
m_num_laps.push_back(num); }
|
2008-09-21 20:55:27 -04:00
|
|
|
void setMajorMode(MajorRaceModeType mode)
|
|
|
|
{ m_major_mode = mode; }
|
|
|
|
void setMinorMode(MinorRaceModeType mode)
|
|
|
|
{ m_minor_mode = mode; }
|
2008-07-14 01:21:37 -04:00
|
|
|
void setNumKarts(int num) { m_num_karts = num; }
|
|
|
|
void setCoinTarget(int num) { m_coin_target = num; }
|
2008-09-21 20:55:27 -04:00
|
|
|
MajorRaceModeType
|
|
|
|
getMajorMode() const { return m_major_mode; }
|
|
|
|
MinorRaceModeType
|
|
|
|
getMinorMode() const { return m_minor_mode; }
|
2008-07-14 01:21:37 -04:00
|
|
|
unsigned int getNumKarts() const { return m_num_karts; }
|
2008-09-07 09:51:44 -04:00
|
|
|
unsigned int getNumPlayers() const { return m_player_karts.size(); }
|
2008-07-14 01:21:37 -04:00
|
|
|
int getNumLaps() const { return m_num_laps[m_track_number];}
|
|
|
|
Difficulty getDifficulty() const { return m_difficulty; }
|
2008-09-21 20:55:27 -04:00
|
|
|
const std::string& getTrackName() const { return m_tracks[m_track_number]; }
|
|
|
|
const GrandPrixData *getGrandPrix() const { return &m_grand_prix; }
|
2008-07-14 01:21:37 -04:00
|
|
|
unsigned int getFinishedKarts() const { return m_num_finished_karts; }
|
|
|
|
unsigned int getFinishedPlayers() const { return m_num_finished_players; }
|
2008-12-25 12:59:41 -05:00
|
|
|
const std::string& getItemStyle() const { return m_grand_prix.getItemStyle(); }
|
|
|
|
|
|
|
|
int getKartFinalGPRank(const int kart_id)
|
|
|
|
const { return m_kart_status[kart_id].m_gp_final_rank; }
|
|
|
|
|
2008-07-14 01:21:37 -04:00
|
|
|
const std::string&
|
|
|
|
getKartName(int kart) const { return m_kart_status[kart].m_ident;}
|
2008-09-07 09:51:44 -04:00
|
|
|
int getKartScore(int krt) const { return m_kart_status[krt].m_score; }
|
2008-07-21 00:51:27 -04:00
|
|
|
int getKartPrevScore(int krt)const { return m_kart_status[krt].m_last_score;}
|
2008-09-21 20:55:27 -04:00
|
|
|
int getKartLocalPlayerId(int k)
|
|
|
|
const { return m_kart_status[k].m_local_player_id; }
|
|
|
|
int getKartGlobalPlayerId(int k)
|
|
|
|
const { return m_kart_status[k].m_global_player_id; }
|
2008-07-14 01:21:37 -04:00
|
|
|
double getOverallTime(int kart) const { return m_kart_status[kart].m_overall_time;}
|
2008-09-07 09:51:44 -04:00
|
|
|
KartType getKartType(int kart) const { return m_kart_status[kart].m_kart_type;}
|
|
|
|
int getCoinTarget() const { return m_coin_target; }
|
|
|
|
int getPositionScore(int p) const { return m_score_for_position[p-1]; }
|
2008-07-14 01:21:37 -04:00
|
|
|
int allPlayerFinished() const {return
|
2008-09-07 09:51:44 -04:00
|
|
|
m_num_finished_players==m_player_karts.size();}
|
2008-09-07 10:24:40 -04:00
|
|
|
int raceIsActive() const { return m_active_race; }
|
|
|
|
const std::vector<std::string>&
|
|
|
|
getRandomKartList() const { return m_random_kart_list; }
|
|
|
|
void setRandomKartList(const std::vector<std::string>& rkl)
|
|
|
|
{ m_random_kart_list = rkl; }
|
|
|
|
void computeRandomKartList();
|
2008-07-14 01:21:37 -04:00
|
|
|
|
|
|
|
void setMirror() {/*FIXME*/}
|
|
|
|
void setReverse(){/*FIXME*/}
|
|
|
|
void startNew(); // start new race/GP/...
|
|
|
|
void next(); // start the next race or go back to the start screen
|
2008-07-14 23:33:17 -04:00
|
|
|
void rerunRace(); // Rerun the same race again
|
2009-03-26 19:31:00 -04:00
|
|
|
void exitRace(); // exit a race (and don't start the next one)
|
2008-10-10 20:32:44 -04:00
|
|
|
|
|
|
|
/** get information about given mode (returns true if 'mode' is of linear races type)
|
|
|
|
info is stored in its ID for conveniance, see the macros above for exact meaning
|
|
|
|
*/
|
|
|
|
static bool isLinearRaceMode(const MinorRaceModeType type)
|
|
|
|
{
|
|
|
|
const int id = (int)type;
|
|
|
|
if(id > 999 && id < 2000) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
/** get information about given mode (returns true if 'mode' is of battle type)
|
|
|
|
info is stored in its ID for conveniance, see the macros above for exact meaning
|
|
|
|
*/
|
|
|
|
static bool isBattleMode(const MinorRaceModeType type)
|
|
|
|
{
|
|
|
|
const int id = (int)type;
|
|
|
|
if(id >= 2000) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
/** get information about given mode (returns true if 'mode' requires lap counting)
|
|
|
|
info is stored in its ID for conveniance, see the macros above for exact meaning
|
|
|
|
*/
|
|
|
|
static bool modeHasLaps(const MinorRaceModeType type)
|
|
|
|
{
|
|
|
|
if(isBattleMode(type)) return false;
|
|
|
|
const int id = (int)type;
|
|
|
|
const int answer = (id-1000)/100;
|
2008-10-15 20:20:49 -04:00
|
|
|
return answer!=0;
|
2008-10-10 20:32:44 -04:00
|
|
|
}
|
2008-07-14 01:21:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
extern RaceManager *race_manager;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* EOF */
|