1 #include <server/race.qh>
8 REGISTER_MUTATOR(cts, false)
12 if (time > 1) // game loads at time 1
13 error("This is a game type and it cannot be added at runtime.");
15 g_race_qualifying = true;
16 independent_players = 1;
17 SetLimits(0, 0, -1, -1);
22 MUTATOR_ONROLLBACK_OR_REMOVE
24 // we actually cannot roll back cts_Initialize here
25 // BUT: we don't need to! If this gets called, adding always
31 LOG_INFO("This is a game type and it cannot be removed at runtime.");
39 const float ST_CTS_LAPS = 1;
40 const float SP_CTS_LAPS = 4;
41 const float SP_CTS_TIME = 5;
42 const float SP_CTS_FASTEST = 6;
47 #include <server/race.qh>
49 float autocvar_g_cts_finish_kill_delay;
50 bool autocvar_g_cts_selfdamage;
53 .float race_checkpoint;
54 void havocbot_role_cts()
60 if (self.bot_strategytime < time)
62 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
63 navigation_goalrating_start();
65 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
67 if(e.cnt == self.race_checkpoint)
69 navigation_routerating(e, 1000000, 5000);
71 else if(self.race_checkpoint == -1)
73 navigation_routerating(e, 1000000, 5000);
77 navigation_goalrating_end();
83 ScoreRules_basics(0, 0, 0, false);
86 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
90 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
91 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
92 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
94 ScoreRules_basics_end();
97 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
99 if(autocvar_sv_eventlog)
100 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
103 void CTS_ClientKill(entity e) // silent version of ClientKill, used when player finishes a CTS run. Useful to prevent cheating by running back to the start line and starting out with more speed
105 e.killindicator = spawn();
106 e.killindicator.owner = e;
107 e.killindicator.think = KillIndicator_Think;
108 e.killindicator.nextthink = time + (e.lip) * 0.05;
109 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
110 e.killindicator.health = 1; // this is used to indicate that it should be silent
114 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
116 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
117 float f = floor(self.race_movetime_frac);
118 self.race_movetime_frac -= f;
119 self.race_movetime_count += f;
120 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
125 if (self.race_penalty)
126 if (time > self.race_penalty)
127 self.race_penalty = 0;
128 if(self.race_penalty)
130 self.velocity = '0 0 0';
131 self.movetype = MOVETYPE_NONE;
132 self.disableclientprediction = 2;
137 // force kbd movement for fairness
141 // if record times matter
142 // ensure nothing EVIL is being done (i.e. div0_evade)
143 // this hinders joystick users though
144 // but it still gives SOME analog control
145 wishvel.x = fabs(self.movement.x);
146 wishvel.y = fabs(self.movement.y);
147 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
150 wishspeed = vlen(wishvel);
151 if(wishvel.x >= 2 * wishvel.y)
154 if(self.movement.x > 0)
155 self.movement_x = wishspeed;
157 self.movement_x = -wishspeed;
160 else if(wishvel.y >= 2 * wishvel.x)
164 if(self.movement.y > 0)
165 self.movement_y = wishspeed;
167 self.movement_y = -wishspeed;
172 if(self.movement.x > 0)
173 self.movement_x = M_SQRT1_2 * wishspeed;
175 self.movement_x = -M_SQRT1_2 * wishspeed;
176 if(self.movement.y > 0)
177 self.movement_y = M_SQRT1_2 * wishspeed;
179 self.movement_y = -M_SQRT1_2 * wishspeed;
186 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
190 Score_NicePrint(world);
193 PlayerScore_Sort(race_place, 0, 1, 0);
195 FOREACH_CLIENT(true, LAMBDA(
198 s = PlayerScore_Add(it, SP_RACE_FASTEST, 0);
202 cts_EventLog(ftos(it.race_place), it);
205 if(g_race_qualifying == 2)
207 g_race_qualifying = 0;
208 independent_players = 0;
209 cvar_set("fraglimit", ftos(race_fraglimit));
210 cvar_set("leadlimit", ftos(race_leadlimit));
211 cvar_set("timelimit", ftos(race_timelimit));
218 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
220 race_PreparePlayer();
221 self.race_checkpoint = -1;
223 if(IS_REAL_CLIENT(self))
225 string rr = CTS_RECORD;
228 race_send_recordtime(MSG_ONE);
229 race_send_speedaward(MSG_ONE);
231 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
232 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
233 race_send_speedaward_alltimebest(MSG_ONE);
236 for (i = 1; i <= RANKINGS_CNT; ++i)
238 race_SendRankings(i, 0, 0, MSG_ONE);
245 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
247 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
248 self.frags = FRAGS_LMS_LOSER;
250 self.frags = FRAGS_SPECTATOR;
252 race_PreparePlayer();
253 self.race_checkpoint = -1;
258 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
260 if(spawn_spot.target == "")
261 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
262 race_PreparePlayer();
264 // if we need to respawn, do it right
265 self.race_respawn_checkpoint = self.race_checkpoint;
266 self.race_respawn_spotref = spawn_spot;
273 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
278 if(self.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
279 race_PreparePlayer();
281 race_RetractPlayer();
283 race_AbandonRaceCheck(self);
288 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
290 self.respawn_flags |= RESPAWN_FORCE;
291 race_AbandonRaceCheck(self);
295 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
297 self.havocbot_role = havocbot_role_cts;
301 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
303 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
305 if (!self.stored_netname)
306 self.stored_netname = strzone(uid2name(self.crypto_idfp));
307 if(self.stored_netname != self.netname)
309 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
310 strunzone(self.stored_netname);
311 self.stored_netname = strzone(self.netname);
315 if (!IS_OBSERVER(self))
317 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
319 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
320 speedaward_holder = self.netname;
321 speedaward_uid = self.crypto_idfp;
322 speedaward_lastupdate = time;
324 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
326 string rr = CTS_RECORD;
327 race_send_speedaward(MSG_ALL);
328 speedaward_lastsent = speedaward_speed;
329 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
331 speedaward_alltimebest = speedaward_speed;
332 speedaward_alltimebest_holder = speedaward_holder;
333 speedaward_alltimebest_uid = speedaward_uid;
334 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
335 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
336 race_send_speedaward_alltimebest(MSG_ALL);
344 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
346 // no weapon dropping in CTS
350 MUTATOR_HOOKFUNCTION(cts, FilterItem)
352 if(self.classname == "droppedweapon")
358 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
360 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
361 if(!autocvar_g_cts_selfdamage)
367 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
369 return true; // in CTS, you don't lose score by observing
372 MUTATOR_HOOKFUNCTION(cts, GetRecords)
374 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
376 if(MapInfo_Get_ByID(i))
378 float r = race_readTime(MapInfo_Map_bspname, 1);
383 string h = race_readName(MapInfo_Map_bspname, 1);
384 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
391 MUTATOR_HOOKFUNCTION(cts, ClientKill)
395 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
397 remove(self.killindicator);
398 self.killindicator = world;
400 ClientKill_Now(); // allow instant kill in this case
406 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
408 if(autocvar_g_cts_finish_kill_delay)
409 CTS_ClientKill(race_player);
414 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
416 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
420 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
422 ret_float = (want_weaponinfo == WEP_SHOTGUN);
423 want_mutatorblocked = true;
427 void cts_Initialize()