10
10
11
11
new g_playerDriftUpdateCounter[MAX_PLAYERS];
12
12
13
+ new g_playerDriftPoints[MAX_PLAYERS];
14
+ new Float: g_playerDriftPosition[MAX_PLAYERS][3 ];
15
+ new g_playerDriftStartTime[MAX_PLAYERS] = { 0 , ... };
16
+ new g_playerDriftUpdateTime[MAX_PLAYERS] = { 0 , ... };
17
+
13
18
// Calculates the vehicle's principal axes based on it's rotation quaternion, which allows us to
14
19
// determine the vehicle's orientation during a drift. Drifts on a flat plane are great, but they
15
20
// become a lot more interesting when exercised on e.g. a hill.
@@ -84,6 +89,25 @@ GetVehicleDriftValues(vehicleId, &bool: backwards, &Float: driftAngle, &Float: d
84
89
return 1 ;
85
90
}
86
91
92
+ // Calculates the expiration time of a drift, in milliseconds. The |timeDifference| details the
93
+ // number of milliseconds since their last drift, and the |driftDuration| details the time in
94
+ // milliseconds since the player started their drift.
95
+ CalculateDriftExpiration (timeDifference, driftDuration) {
96
+ return 0 ;
97
+ }
98
+
99
+ // Calculates the amount of drifting points to award as a bonus, given the vehicle's |pitch|, |roll|
100
+ // and |yaw| values, each of which make for harder circumstances to maintain a drift.
101
+ CalculateDriftBonus (timeDifference, Float: pitch, Float: roll, Float: yaw) {
102
+ return 0 ;
103
+ }
104
+
105
+ // Calculates the amount of drifting points to award for a drift at the given |driftSpeed| and the
106
+ // |driftAngle|, which took place in the given |timeDifference| in milliseconds.
107
+ CalculateDriftPoints (timeDifference, Float: driftSpeed, Float: driftAngle, Float: driftDistance) {
108
+ return 0 ;
109
+ }
110
+
87
111
// Processes drift updates for the given |playerId|. Only works when they're in a vehicle, and only
88
112
// processed a certain ratio of player updates as this method is called a lot.
89
113
ProcessDriftUpdateForPlayer (playerId) {
@@ -110,6 +134,50 @@ ProcessDriftUpdateForPlayer(playerId) {
110
134
driftAngle >= g_driftingMinAngle && driftAngle <= g_driftingMaxAngle &&
111
135
! backwards;
112
136
113
- printf (" [%d ] P:[%.f 4] R:[%.4f ] Y:[%.f 4] A:[%.4f ] S:[%.f 4] B:[%d ] D:[%d ]" ,
114
- playerId, pitch, roll, yaw, driftAngle, driftSpeed, backwards ? 1 : 0 , isDrifting ? 1 : 0 );
137
+ // If the player wasn't drifting, and isn't currently drifting, just bail out.
138
+ if (g_playerDriftStartTime[playerId] == 0 && ! isDrifting)
139
+ return ;
140
+
141
+ new const currentTime = GetTickCount ();
142
+
143
+ // (1) The player is currently drifting, and was drifting during the previous tick as well.
144
+ if (g_playerDriftStartTime[playerId] > 0 && isDrifting) {
145
+ new const difference = currentTime - g_playerDriftUpdateTime[playerId];
146
+ new const Float: distance = GetVehicleDistanceFromPoint (
147
+ vehicleId, g_playerDriftPosition[playerId][0 ], g_playerDriftPosition[playerId][1 ],
148
+ g_playerDriftPosition[playerId][2 ]);
149
+
150
+ g_playerDriftUpdateTime[playerId] = currentTime;
151
+ g_playerDriftPoints[playerId] +=
152
+ CalculateDriftBonus (difference, pitch, roll, yaw) +
153
+ CalculateDriftPoints (difference, driftSpeed, driftAngle, distance);
154
+
155
+ printf (" [%d ] Drift: %d " , playerId, g_playerDriftPoints[playerId]);
156
+
157
+ } else if (g_playerDriftStartTime[playerId] == 0 && isDrifting) {
158
+ // (2) The player is currently drifting, but wasn't yet drifting during their previous tick.
159
+ g_playerDriftPoints[playerId] = 0 ;
160
+ g_playerDriftStartTime[playerId] = currentTime;
161
+ g_playerDriftUpdateTime[playerId] = currentTime;
162
+
163
+ printf (" [%d ] Drift started" , playerId);
164
+
165
+ } else {
166
+ // (3) The player is currently in a drift, but missed the thresholds for this tick.
167
+ new const difference = currentTime - g_playerDriftUpdateTime[playerId];
168
+ new const duration = currentTime - g_playerDriftStartTime[playerId];
169
+
170
+ // If the |difference| is larger than the expiration we'd award for this moment in the drift
171
+ // then we'll mark the drift as having finished.
172
+ if (difference > CalculateDriftExpiration (difference, duration)) {
173
+ g_playerDriftStartTime[playerId] = 0 ;
174
+
175
+ printf (" [%d ] Drift finished" , playerId);
176
+ }
177
+ }
178
+
179
+ // Store the position so that we can calculate the moved drift distance during the next tick.
180
+ GetVehiclePos (
181
+ vehicleId, g_playerDriftPosition[playerId][0 ], g_playerDriftPosition[playerId][1 ],
182
+ g_playerDriftPosition[playerId][2 ]);
115
183
}
0 commit comments