Skip to content

Commit

Permalink
Drifting: restrict to automobiles and bikes
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLVP committed Jul 3, 2020
1 parent 8c15b64 commit efcc29f
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 89 deletions.
12 changes: 12 additions & 0 deletions pawn/Driver/Drift/DriftHelpers.pwn
Expand Up @@ -16,6 +16,15 @@ new Float: g_playerDriftStartHealth[MAX_PLAYERS];
new g_playerDriftStartTime[MAX_PLAYERS] = { 0, ... };
new g_playerDriftUpdateTime[MAX_PLAYERS] = { 0, ... };

// Determines whether the given |vehicleId| is able to drift. This generally is restricted to bikes
// and automobiles, because >250k scores are easily obtainable through helicopters.
IsValidDriftVehicle(vehicleId) {
new const modelId = GetVehicleModel(vehicleId);

return VehicleModel->isAutomobile(modelId) ||
VehicleModel->isBike(modelId);
}

// Calculates the vehicle's principal axes based on it's rotation quaternion, which allows us to
// determine the vehicle's orientation during a drift. Drifts on a flat plane are great, but they
// become a lot more interesting when exercised on e.g. a hill.
Expand Down Expand Up @@ -147,6 +156,9 @@ ProcessDriftUpdateForPlayer(playerId) {
if (!vehicleId)
return; // the |playerId| is not currently in a vehicle

if (!IsValidDriftVehicle(vehicleId))
return; // the |vehicleId| is not valid for drifting

if ((++g_playerDriftUpdateCounter[playerId] % DRIFT_UPDATE_INTERVAL) != 0)
return; // this tick will be ignored to decrease server load

Expand Down
25 changes: 24 additions & 1 deletion pawn/Entities/Vehicles/VehicleModel.pwn
Expand Up @@ -53,7 +53,10 @@ enum _: VehicleModelFlags {
DisableNitroInjectionVehicleFlag = 0x1000,

// Marks this vehicle as being unable to be created (i.e. because it's useless).
DisableCreationVehicleFlag = 0x2000
DisableCreationVehicleFlag = 0x2000,

// Indicates that this vehicle is an automobile.
AutomobileVehicleFlag = 0x4000,
};

/**
Expand Down Expand Up @@ -230,6 +233,26 @@ class VehicleModel <modelId (NumberOfVehicleModels)> {
return this->hasFlag(modelId, AirplaneVehicleFlag);
}

/**
* Returns whether this model Id represents an automobile.
*
* @param modelId Id of the vehicle model to check against.
* @return boolean Is this model representing an automobile?
*/
public static inline bool: isAutomobile(modelId) {
return this->hasFlag(modelId, AutomobileVehicleFlag);
}

/**
* Returns whether this model Id represents a bike.
*
* @param modelId Id of the vehicle model to check against.
* @return boolean Is this model representing a bike?
*/
public static inline bool: isBike(modelId) {
return this->hasFlag(modelId, BikeVehicleFlag);
}

/**
* Returns whether this vehicle model Id represents a trailer. Trailers cannot be driven by
* players, and must be positioned in a different way.
Expand Down

0 comments on commit efcc29f

Please sign in to comment.