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()
59 if (self.bot_strategytime < time)
61 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
62 navigation_goalrating_start();
64 FOREACH_ENTITY_CLASS("trigger_race_checkpoint", true,
66 if(it.cnt == self.race_checkpoint)
67 navigation_routerating(it, 1000000, 5000);
68 else if(self.race_checkpoint == -1)
69 navigation_routerating(it, 1000000, 5000);
72 navigation_goalrating_end();
78 ScoreRules_basics(0, 0, 0, false);
81 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
85 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
86 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
87 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
89 ScoreRules_basics_end();
92 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
94 if(autocvar_sv_eventlog)
95 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
98 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
100 e.killindicator = spawn();
101 e.killindicator.owner = e;
102 e.killindicator.think = KillIndicator_Think;
103 e.killindicator.nextthink = time + (e.lip) * 0.05;
104 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
105 e.killindicator.health = 1; // this is used to indicate that it should be silent
109 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
111 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
112 float f = floor(self.race_movetime_frac);
113 self.race_movetime_frac -= f;
114 self.race_movetime_count += f;
115 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
120 if (self.race_penalty)
121 if (time > self.race_penalty)
122 self.race_penalty = 0;
123 if(self.race_penalty)
125 self.velocity = '0 0 0';
126 self.movetype = MOVETYPE_NONE;
127 self.disableclientprediction = 2;
132 // force kbd movement for fairness
136 // if record times matter
137 // ensure nothing EVIL is being done (i.e. div0_evade)
138 // this hinders joystick users though
139 // but it still gives SOME analog control
140 wishvel.x = fabs(self.movement.x);
141 wishvel.y = fabs(self.movement.y);
142 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
145 wishspeed = vlen(wishvel);
146 if(wishvel.x >= 2 * wishvel.y)
149 if(self.movement.x > 0)
150 self.movement_x = wishspeed;
152 self.movement_x = -wishspeed;
155 else if(wishvel.y >= 2 * wishvel.x)
159 if(self.movement.y > 0)
160 self.movement_y = wishspeed;
162 self.movement_y = -wishspeed;
167 if(self.movement.x > 0)
168 self.movement_x = M_SQRT1_2 * wishspeed;
170 self.movement_x = -M_SQRT1_2 * wishspeed;
171 if(self.movement.y > 0)
172 self.movement_y = M_SQRT1_2 * wishspeed;
174 self.movement_y = -M_SQRT1_2 * wishspeed;
181 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
185 Score_NicePrint(world);
188 PlayerScore_Sort(race_place, 0, 1, 0);
190 FOREACH_CLIENT(true, LAMBDA(
193 s = PlayerScore_Add(it, SP_RACE_FASTEST, 0);
197 cts_EventLog(ftos(it.race_place), it);
200 if(g_race_qualifying == 2)
202 g_race_qualifying = 0;
203 independent_players = 0;
204 cvar_set("fraglimit", ftos(race_fraglimit));
205 cvar_set("leadlimit", ftos(race_leadlimit));
206 cvar_set("timelimit", ftos(race_timelimit));
213 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
215 race_PreparePlayer();
216 self.race_checkpoint = -1;
218 if(IS_REAL_CLIENT(self))
220 string rr = CTS_RECORD;
223 race_send_recordtime(MSG_ONE);
224 race_send_speedaward(MSG_ONE);
226 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
227 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
228 race_send_speedaward_alltimebest(MSG_ONE);
231 for (i = 1; i <= RANKINGS_CNT; ++i)
233 race_SendRankings(i, 0, 0, MSG_ONE);
240 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
242 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
243 self.frags = FRAGS_LMS_LOSER;
245 self.frags = FRAGS_SPECTATOR;
247 race_PreparePlayer();
248 self.race_checkpoint = -1;
253 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
255 if(spawn_spot.target == "")
256 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
257 race_PreparePlayer();
259 // if we need to respawn, do it right
260 self.race_respawn_checkpoint = self.race_checkpoint;
261 self.race_respawn_spotref = spawn_spot;
268 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
273 if(self.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
274 race_PreparePlayer();
276 race_RetractPlayer();
278 race_AbandonRaceCheck(self);
283 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
285 self.respawn_flags |= RESPAWN_FORCE;
286 race_AbandonRaceCheck(self);
290 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
292 self.havocbot_role = havocbot_role_cts;
296 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
298 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
300 if (!self.stored_netname)
301 self.stored_netname = strzone(uid2name(self.crypto_idfp));
302 if(self.stored_netname != self.netname)
304 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
305 strunzone(self.stored_netname);
306 self.stored_netname = strzone(self.netname);
310 if (!IS_OBSERVER(self))
312 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
314 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
315 speedaward_holder = self.netname;
316 speedaward_uid = self.crypto_idfp;
317 speedaward_lastupdate = time;
319 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
321 string rr = CTS_RECORD;
322 race_send_speedaward(MSG_ALL);
323 speedaward_lastsent = speedaward_speed;
324 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
326 speedaward_alltimebest = speedaward_speed;
327 speedaward_alltimebest_holder = speedaward_holder;
328 speedaward_alltimebest_uid = speedaward_uid;
329 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
330 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
331 race_send_speedaward_alltimebest(MSG_ALL);
339 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
341 // no weapon dropping in CTS
345 MUTATOR_HOOKFUNCTION(cts, FilterItem)
347 if(self.classname == "droppedweapon")
353 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
355 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
356 if(!autocvar_g_cts_selfdamage)
362 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
364 return true; // in CTS, you don't lose score by observing
367 MUTATOR_HOOKFUNCTION(cts, GetRecords)
369 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
371 if(MapInfo_Get_ByID(i))
373 float r = race_readTime(MapInfo_Map_bspname, 1);
378 string h = race_readName(MapInfo_Map_bspname, 1);
379 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
386 MUTATOR_HOOKFUNCTION(cts, ClientKill)
390 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
392 remove(self.killindicator);
393 self.killindicator = world;
395 ClientKill_Now(); // allow instant kill in this case
401 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
403 if(autocvar_g_cts_finish_kill_delay)
404 CTS_ClientKill(race_player);
409 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
411 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
415 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
417 ret_float = (want_weaponinfo == WEP_SHOTGUN);
418 want_mutatorblocked = true;
422 void cts_Initialize()