2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Thanks to Simon for his early research on the racing system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BitStream.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "Component.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Information for each player in the race
|
|
|
|
*/
|
|
|
|
struct RacingPlayerInfo {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID of the player
|
|
|
|
*/
|
|
|
|
LWOOBJID playerID;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the car the player is driving
|
|
|
|
*/
|
|
|
|
LWOOBJID vehicleID;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
2023-05-09 15:58:57 +00:00
|
|
|
* The rank of a player
|
2021-12-05 17:54:36 +00:00
|
|
|
*/
|
2023-05-09 15:58:57 +00:00
|
|
|
uint32_t rank;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Whether the player has finished loading or not
|
|
|
|
*/
|
|
|
|
bool playerLoaded;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Scripted activity component score
|
|
|
|
*/
|
|
|
|
float data[10]{};
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Point that the player will respawn at if they smash their car
|
|
|
|
*/
|
|
|
|
NiPoint3 respawnPosition;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Rotation that the player will respawn at if they smash their car
|
|
|
|
*/
|
|
|
|
NiQuaternion respawnRotation;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The index in the respawn point the player is now at
|
|
|
|
*/
|
|
|
|
uint32_t respawnIndex;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The number of laps the player has completed
|
|
|
|
*/
|
|
|
|
uint32_t lap;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the player has finished the race
|
|
|
|
*/
|
|
|
|
uint32_t finished;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Unused
|
|
|
|
*/
|
|
|
|
uint16_t reachedPoints;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The fastest lap time of the player
|
|
|
|
*/
|
|
|
|
time_t bestLapTime = 0;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The current lap time of the player
|
|
|
|
*/
|
|
|
|
time_t lapTime = 0;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The number of times this player smashed their car
|
|
|
|
*/
|
|
|
|
uint32_t smashedTimes = 0;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the player should be smashed if the game is reloaded
|
|
|
|
*/
|
|
|
|
bool noSmashOnReload = false;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Whether or not this player has collected their rewards from completing the race
|
|
|
|
*/
|
|
|
|
bool collectedRewards = false;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Unused
|
|
|
|
*/
|
|
|
|
time_t raceTime = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that's attached to a manager entity in each race zone that loads player vehicles, keep scores, etc.
|
|
|
|
*/
|
|
|
|
class RacingControlComponent : public Component {
|
|
|
|
public:
|
2023-03-04 07:16:37 +00:00
|
|
|
static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
RacingControlComponent(Entity* parentEntity);
|
|
|
|
~RacingControlComponent();
|
|
|
|
|
|
|
|
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
|
|
|
void Update(float deltaTime);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Invoked when a player loads into the zone.
|
|
|
|
*/
|
|
|
|
void OnPlayerLoaded(Entity* player);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Initalize the player's vehicle.
|
|
|
|
*
|
|
|
|
* @param player The player who's vehicle to initialize.
|
|
|
|
* @param initialLoad Is this the first time the player is loading in this race?
|
|
|
|
*/
|
2022-12-22 13:16:18 +00:00
|
|
|
void LoadPlayerVehicle(Entity* player, uint32_t positionNumber, bool initialLoad = false);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Invoked when the client says it has loaded in.
|
|
|
|
*/
|
|
|
|
void OnRacingClientReady(Entity* player);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Invoked when the client says it should be smashed.
|
|
|
|
*/
|
|
|
|
void OnRequestDie(Entity* player);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Invoked when the player has finished respawning.
|
|
|
|
*/
|
|
|
|
void OnRacingPlayerInfoResetFinished(Entity* player);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Invoked when the player responds to the GUI.
|
|
|
|
*/
|
2023-05-09 05:40:00 +00:00
|
|
|
void HandleMessageBoxResponse(Entity* player, int32_t button, const std::string& id);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
2022-02-05 11:28:17 +00:00
|
|
|
* Get the racing data from a player's LWOOBJID.
|
2021-12-05 17:54:36 +00:00
|
|
|
*/
|
|
|
|
RacingPlayerInfo* GetPlayerData(LWOOBJID playerID);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Formats a time to a string, currently unused
|
|
|
|
* @param time the time to format
|
|
|
|
* @return the time formatted as string
|
|
|
|
*/
|
|
|
|
static std::string FormatTimeString(time_t time);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The players that are currently racing
|
|
|
|
*/
|
|
|
|
std::vector<RacingPlayerInfo> m_RacingPlayers;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The paths that are followed for the camera scenes
|
|
|
|
*/
|
|
|
|
std::u16string m_PathName;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the activity for participating in this race
|
|
|
|
*/
|
|
|
|
uint32_t m_ActivityID;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The world the players return to when they finish the race
|
|
|
|
*/
|
|
|
|
uint32_t m_MainWorld;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The number of laps that are remaining for the winning player
|
|
|
|
*/
|
|
|
|
uint16_t m_RemainingLaps;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the player that's currently winning the race
|
|
|
|
*/
|
|
|
|
LWOOBJID m_LeadingPlayer;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The overall best lap from all the players
|
|
|
|
*/
|
|
|
|
float m_RaceBestLap;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The overall best time from all the players
|
|
|
|
*/
|
|
|
|
float m_RaceBestTime;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the race has started
|
|
|
|
*/
|
|
|
|
bool m_Started;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The time left until the race will start
|
|
|
|
*/
|
|
|
|
float m_StartTimer;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The time left for loading the players
|
|
|
|
*/
|
|
|
|
float m_LoadTimer;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Whether or not all players have loaded
|
|
|
|
*/
|
|
|
|
bool m_Loaded;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The number of loaded players
|
|
|
|
*/
|
|
|
|
uint32_t m_LoadedPlayers;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* All the players that are in the lobby, loaded or not
|
|
|
|
*/
|
|
|
|
std::vector<LWOOBJID> m_LobbyPlayers;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
2022-02-05 11:28:17 +00:00
|
|
|
* The number of players that have finished the race
|
2021-12-05 17:54:36 +00:00
|
|
|
*/
|
|
|
|
uint32_t m_Finished;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The time the race was started
|
|
|
|
*/
|
|
|
|
time_t m_StartTime;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Timer for tracking how long a player was alone in this race
|
|
|
|
*/
|
|
|
|
float m_EmptyTimer;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
bool m_SoloRacing;
|
2023-05-09 15:58:57 +00:00
|
|
|
|
|
|
|
bool m_DirtyEndOfRaceInfo;
|
|
|
|
bool m_DirtyRaceInfo;
|
|
|
|
bool m_DirtyPathName;
|
|
|
|
bool m_DirtyRank;
|
|
|
|
bool m_DirtyLoadPlayer;
|
|
|
|
bool m_DirtyLobby;
|
2023-05-09 05:40:00 +00:00
|
|
|
/**
|
|
|
|
* Value for message box response to know if we are exiting the race via the activity dialogue
|
|
|
|
*/
|
|
|
|
const int32_t m_ActivityExitConfirm = 1;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|