summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/gokz/racing.inc
blob: d6819ea9f4aa41313a07d90945c1a711722ac32b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* 	
	gokz-racing Plugin Include
	
	Website: https://bitbucket.org/kztimerglobalteam/gokz
*/

#if defined _gokz_racing_included_
#endinput
#endif
#define _gokz_racing_included_



// =====[ ENUMS ]=====

enum RaceInfo:
{
	RaceInfo_ID, 
	RaceInfo_Status, 
	RaceInfo_HostUserID, 
	RaceInfo_FinishedRacerCount, 
	RaceInfo_Type, 
	RaceInfo_Course, 
	RaceInfo_Mode, 
	RaceInfo_CheckpointRule, 
	RaceInfo_CooldownRule,
	RACEINFO_COUNT
};

enum
{
	RaceType_Normal, 
	RaceType_Duel, 
	RACETYPE_COUNT
};

enum
{
	RaceStatus_Pending, 
	RaceStatus_Countdown, 
	RaceStatus_Started, 
	RaceStatus_Aborting, 
	RACESTATUS_COUNT
};

enum
{
	RacerStatus_Available, 
	RacerStatus_Pending, 
	RacerStatus_Accepted, 
	RacerStatus_Racing, 
	RacerStatus_Finished, 
	RacerStatus_Surrendered, 
	RACERSTATUS_COUNT
};

enum
{
	CheckpointRule_None,
	CheckpointRule_Limit,
	CheckpointRule_Cooldown,
	CheckpointRule_Unlimited,
	CHECKPOINTRULE_COUNT
};



// =====[ CONSTANTS ]=====

#define RC_COUNTDOWN_TIME 10.0
#define RC_REQUEST_TIMEOUT_TIME 15.0



// =====[ FORWARDS ]=====

/**
 * Called when a player has finished their race.
 *
 * @param client		Client index.
 * @param raceID		ID of the race.
 * @param place			Final placement in the race.
 */
forward void GOKZ_RC_OnFinish(int client, int raceID, int place);

/**
 * Called when a player has surrendered their race.
 *
 * @param client		Client index.
 * @param raceID		ID of the race.
 */
forward void GOKZ_RC_OnSurrender(int client, int raceID);

/**
 * Called when a player receives a race request.
 *
 * @param client		Client index.
 * @param raceID		ID of the race.
 */
forward void GOKZ_RC_OnRequestReceived(int client, int raceID)

/**
 * Called when a player accepts a race request.
 *
 * @param client		Client index.
 * @param raceID		ID of the race.
 */
forward void GOKZ_RC_OnRequestAccepted(int client, int raceID)

/**
 * Called when a player declines a race request.
 *
 * @param client		Client index.
 * @param raceID		ID of the race.
 * @param timeout		Whether the client was too late to respond.
 */
forward void GOKZ_RC_OnRequestDeclined(int client, int raceID, bool timeout)

/**
 * Called when a race has been registered.
 * The initial status of a race is RaceStatus_Pending.
 *
 * @param raceID		ID of the race.
 */
forward void GOKZ_RC_OnRaceRegistered(int raceID);

/**
 * Called when a race's info property has changed.
 *
 * @param raceID		ID of the race.
 * @param prop			Info property that was changed.
 * @param oldValue		Previous value.
 * @param newValue		New value.
 */
forward void GOKZ_RC_OnRaceInfoChanged(int raceID, RaceInfo prop, int oldValue, int newValue);



// =====[ NATIVES ]=====

/**
 * Gets the value of a race info property.
 *
 * @param raceID    	Race index.
 * @param prop			Info property to get.
 * @return				Value of the info property.
 */
native int GOKZ_RC_GetRaceInfo(int raceID, RaceInfo prop);

/**
 * Gets a player's racer status.
 * Refer to the RacerStatus enumeration.
 *
 * @param client    	Client index.
 * @return				Racer status of the client.
 */
native int GOKZ_RC_GetStatus(int client);

/**
 * Gets the ID of the race a player is in.
 *
 * @param client    	Client index.
 * @return				ID of the race the player is in, or -1 if not in a race.
 */
native int GOKZ_RC_GetRaceID(int client);



// =====[ DEPENDENCY ]=====

public SharedPlugin __pl_gokz_racing = 
{
	name = "gokz-racing", 
	file = "gokz-racing.smx", 
	#if defined REQUIRE_PLUGIN
	required = 1, 
	#else
	required = 0, 
	#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_gokz_racing_SetNTVOptional()
{
	MarkNativeAsOptional("GOKZ_RC_GetRaceInfo");
	MarkNativeAsOptional("GOKZ_RC_GetStatus");
	MarkNativeAsOptional("GOKZ_RC_GetRaceID");
}
#endif