2 .float race_checkpoint;
3 void havocbot_role_race()
5 if(self.deadflag != DEAD_NO)
9 if (self.bot_strategytime < time)
11 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
12 navigation_goalrating_start();
14 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
16 if(e.cnt == self.race_checkpoint)
18 navigation_routerating(e, 1000000, 5000);
20 else if(self.race_checkpoint == -1)
22 navigation_routerating(e, 1000000, 5000);
26 navigation_goalrating_end();
30 void race_ScoreRules()
32 ScoreRules_basics(race_teams, 0, 0, FALSE);
35 ScoreInfo_SetLabel_TeamScore( ST_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
36 ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
37 ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
38 ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
40 else if(g_race_qualifying)
42 ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
46 ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
47 ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
48 ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
50 ScoreRules_basics_end();
53 MUTATOR_HOOKFUNCTION(race_PlayerPhysics)
55 // force kbd movement for fairness
59 // if record times matter
60 // ensure nothing EVIL is being done (i.e. div0_evade)
61 // this hinders joystick users though
62 // but it still gives SOME analog control
63 wishvel_x = fabs(self.movement_x);
64 wishvel_y = fabs(self.movement_y);
65 if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
68 wishspeed = vlen(wishvel);
69 if(wishvel_x >= 2 * wishvel_y)
72 if(self.movement_x > 0)
73 self.movement_x = wishspeed;
75 self.movement_x = -wishspeed;
78 else if(wishvel_y >= 2 * wishvel_x)
82 if(self.movement_y > 0)
83 self.movement_y = wishspeed;
85 self.movement_y = -wishspeed;
90 if(self.movement_x > 0)
91 self.movement_x = M_SQRT1_2 * wishspeed;
93 self.movement_x = -M_SQRT1_2 * wishspeed;
94 if(self.movement_y > 0)
95 self.movement_y = M_SQRT1_2 * wishspeed;
97 self.movement_y = -M_SQRT1_2 * wishspeed;
104 MUTATOR_HOOKFUNCTION(race_ResetMap)
108 Score_NicePrint(world);
111 PlayerScore_Sort(race_place, 0, 1, 0);
118 s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
122 print(e.netname, " = ", ftos(e.race_place), "\n");
125 if(g_race_qualifying == 2)
127 g_race_qualifying = 0;
128 independent_players = 0;
129 cvar_set("fraglimit", ftos(race_fraglimit));
130 cvar_set("leadlimit", ftos(race_leadlimit));
131 cvar_set("timelimit", ftos(race_timelimit));
138 MUTATOR_HOOKFUNCTION(race_PlayerPreThink)
140 if(IS_SPEC(self) || IS_OBSERVER(self))
141 if(g_race_qualifying)
142 if(msg_entity.enemy.race_laptime)
143 race_SendNextCheckpoint(msg_entity.enemy, 1);
148 MUTATOR_HOOKFUNCTION(race_ClientConnect)
150 race_PreparePlayer();
151 self.race_checkpoint = -1;
153 string rr = RACE_RECORD;
155 if(IS_REAL_CLIENT(self))
158 race_send_recordtime(MSG_ONE);
159 race_send_speedaward(MSG_ONE);
161 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
162 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
163 race_send_speedaward_alltimebest(MSG_ONE);
166 for (i = 1; i <= RANKINGS_CNT; ++i)
168 race_SendRankings(i, 0, 0, MSG_ONE);
175 MUTATOR_HOOKFUNCTION(race_MakePlayerObserver)
177 if(g_race_qualifying)
178 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
179 self.frags = FRAGS_LMS_LOSER;
181 self.frags = FRAGS_SPECTATOR;
183 race_PreparePlayer();
184 self.race_checkpoint = -1;
189 MUTATOR_HOOKFUNCTION(race_PlayerSpawn)
191 if(spawn_spot.target == "")
192 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
193 race_PreparePlayer();
195 // if we need to respawn, do it right
196 self.race_respawn_checkpoint = self.race_checkpoint;
197 self.race_respawn_spotref = spawn_spot;
204 MUTATOR_HOOKFUNCTION(race_PutClientInServer)
209 if(self.killcount == -666 /* initial spawn */ || g_race_qualifying) // spawn
210 race_PreparePlayer();
212 race_RetractPlayer();
214 race_AbandonRaceCheck(self);
219 MUTATOR_HOOKFUNCTION(race_PlayerDies)
221 self.respawn_flags |= RESPAWN_FORCE;
222 race_AbandonRaceCheck(self);
226 MUTATOR_HOOKFUNCTION(race_BotRoles)
228 self.havocbot_role = havocbot_role_race;
232 MUTATOR_HOOKFUNCTION(race_PlayerPostThink)
234 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
236 if (!self.stored_netname)
237 self.stored_netname = strzone(uid2name(self.crypto_idfp));
238 if(self.stored_netname != self.netname)
240 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
241 strunzone(self.stored_netname);
242 self.stored_netname = strzone(self.netname);
249 MUTATOR_HOOKFUNCTION(race_ForbidClearPlayerScore)
251 if(g_race_qualifying)
252 return TRUE; // in qualifying, you don't lose score by observing
257 MUTATOR_HOOKFUNCTION(race_GetTeamCount)
259 ret_float = race_teams;
263 void race_Initialize()
266 if(g_race_qualifying == 2)
270 MUTATOR_DEFINITION(gamemode_race)
272 MUTATOR_HOOK(PlayerPhysics, race_PlayerPhysics, CBC_ORDER_ANY);
273 MUTATOR_HOOK(reset_map_global, race_ResetMap, CBC_ORDER_ANY);
274 MUTATOR_HOOK(PlayerPreThink, race_PlayerPreThink, CBC_ORDER_ANY);
275 MUTATOR_HOOK(ClientConnect, race_ClientConnect, CBC_ORDER_ANY);
276 MUTATOR_HOOK(MakePlayerObserver, race_MakePlayerObserver, CBC_ORDER_ANY);
277 MUTATOR_HOOK(PlayerSpawn, race_PlayerSpawn, CBC_ORDER_ANY);
278 MUTATOR_HOOK(PutClientInServer, race_PutClientInServer, CBC_ORDER_ANY);
279 MUTATOR_HOOK(PlayerDies, race_PlayerDies, CBC_ORDER_ANY);
280 MUTATOR_HOOK(HavocBot_ChooseRule, race_BotRoles, CBC_ORDER_ANY);
281 MUTATOR_HOOK(GetPressedKeys, race_PlayerPostThink, CBC_ORDER_ANY);
282 MUTATOR_HOOK(ForbidPlayerScore_Clear, race_ForbidClearPlayerScore, CBC_ORDER_ANY);
283 MUTATOR_HOOK(GetTeamCount, race_GetTeamCount, CBC_ORDER_ANY);
287 if(time > 1) // game loads at time 1
288 error("This is a game type and it cannot be added at runtime.");
292 MUTATOR_ONROLLBACK_OR_REMOVE
294 // we actually cannot roll back race_Initialize here
295 // BUT: we don't need to! If this gets called, adding always
301 print("This is a game type and it cannot be removed at runtime.");