1 #include "../../race.qh"
8 REGISTER_MUTATOR(cts, false)
10 g_race_qualifying = true;
11 independent_players = 1;
12 SetLimits(0, 0, 0, -1);
16 if (time > 1) // game loads at time 1
17 error("This is a game type and it cannot be added at runtime.");
21 MUTATOR_ONROLLBACK_OR_REMOVE
23 // we actually cannot roll back cts_Initialize here
24 // BUT: we don't need to! If this gets called, adding always
30 LOG_INFO("This is a game type and it cannot be removed at runtime.");
38 const float ST_CTS_LAPS = 1;
39 const float SP_CTS_LAPS = 4;
40 const float SP_CTS_TIME = 5;
41 const float SP_CTS_FASTEST = 6;
46 #include "../../race.qh"
48 float autocvar_g_cts_finish_kill_delay;
49 bool autocvar_g_cts_selfdamage;
52 .float race_checkpoint;
53 void havocbot_role_cts()
55 if(self.deadflag != DEAD_NO)
59 if (self.bot_strategytime < time)
61 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
62 navigation_goalrating_start();
64 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
66 if(e.cnt == self.race_checkpoint)
68 navigation_routerating(e, 1000000, 5000);
70 else if(self.race_checkpoint == -1)
72 navigation_routerating(e, 1000000, 5000);
76 navigation_goalrating_end();
82 ScoreRules_basics(0, 0, 0, false);
85 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
89 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
90 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
91 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
93 ScoreRules_basics_end();
96 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
98 if(autocvar_sv_eventlog)
99 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
102 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
104 e.killindicator = spawn();
105 e.killindicator.owner = e;
106 e.killindicator.think = KillIndicator_Think;
107 e.killindicator.nextthink = time + (e.lip) * 0.05;
108 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
109 e.killindicator.health = 1; // this is used to indicate that it should be silent
113 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
115 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
116 float f = floor(self.race_movetime_frac);
117 self.race_movetime_frac -= f;
118 self.race_movetime_count += f;
119 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
124 if (self.race_penalty)
125 if (time > self.race_penalty)
126 self.race_penalty = 0;
127 if(self.race_penalty)
129 self.velocity = '0 0 0';
130 self.movetype = MOVETYPE_NONE;
131 self.disableclientprediction = 2;
136 // force kbd movement for fairness
140 // if record times matter
141 // ensure nothing EVIL is being done (i.e. div0_evade)
142 // this hinders joystick users though
143 // but it still gives SOME analog control
144 wishvel.x = fabs(self.movement.x);
145 wishvel.y = fabs(self.movement.y);
146 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
149 wishspeed = vlen(wishvel);
150 if(wishvel.x >= 2 * wishvel.y)
153 if(self.movement.x > 0)
154 self.movement_x = wishspeed;
156 self.movement_x = -wishspeed;
159 else if(wishvel.y >= 2 * wishvel.x)
163 if(self.movement.y > 0)
164 self.movement_y = wishspeed;
166 self.movement_y = -wishspeed;
171 if(self.movement.x > 0)
172 self.movement_x = M_SQRT1_2 * wishspeed;
174 self.movement_x = -M_SQRT1_2 * wishspeed;
175 if(self.movement.y > 0)
176 self.movement_y = M_SQRT1_2 * wishspeed;
178 self.movement_y = -M_SQRT1_2 * wishspeed;
185 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
189 Score_NicePrint(world);
192 PlayerScore_Sort(race_place, 0, 1, 0);
199 s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
203 cts_EventLog(ftos(e.race_place), e);
206 if(g_race_qualifying == 2)
208 g_race_qualifying = 0;
209 independent_players = 0;
210 cvar_set("fraglimit", ftos(race_fraglimit));
211 cvar_set("leadlimit", ftos(race_leadlimit));
212 cvar_set("timelimit", ftos(race_timelimit));
219 MUTATOR_HOOKFUNCTION(cts, PlayerPreThink)
221 if(IS_SPEC(self) || IS_OBSERVER(self))
222 if(g_race_qualifying)
223 if(msg_entity.enemy.race_laptime)
224 race_SendNextCheckpoint(msg_entity.enemy, 1);
229 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
231 race_PreparePlayer();
232 self.race_checkpoint = -1;
234 if(IS_REAL_CLIENT(self))
236 string rr = CTS_RECORD;
239 race_send_recordtime(MSG_ONE);
240 race_send_speedaward(MSG_ONE);
242 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
243 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
244 race_send_speedaward_alltimebest(MSG_ONE);
247 for (i = 1; i <= RANKINGS_CNT; ++i)
249 race_SendRankings(i, 0, 0, MSG_ONE);
256 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
258 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
259 self.frags = FRAGS_LMS_LOSER;
261 self.frags = FRAGS_SPECTATOR;
263 race_PreparePlayer();
264 self.race_checkpoint = -1;
269 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
271 if(spawn_spot.target == "")
272 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
273 race_PreparePlayer();
275 // if we need to respawn, do it right
276 self.race_respawn_checkpoint = self.race_checkpoint;
277 self.race_respawn_spotref = spawn_spot;
284 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
289 if(self.killcount == -666 /* initial spawn */ || g_race_qualifying) // spawn
290 race_PreparePlayer();
292 race_RetractPlayer();
294 race_AbandonRaceCheck(self);
299 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
301 self.respawn_flags |= RESPAWN_FORCE;
302 race_AbandonRaceCheck(self);
306 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
308 self.havocbot_role = havocbot_role_cts;
312 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
314 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
316 if (!self.stored_netname)
317 self.stored_netname = strzone(uid2name(self.crypto_idfp));
318 if(self.stored_netname != self.netname)
320 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
321 strunzone(self.stored_netname);
322 self.stored_netname = strzone(self.netname);
326 if (!IS_OBSERVER(self))
328 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
330 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
331 speedaward_holder = self.netname;
332 speedaward_uid = self.crypto_idfp;
333 speedaward_lastupdate = time;
335 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
337 string rr = CTS_RECORD;
338 race_send_speedaward(MSG_ALL);
339 speedaward_lastsent = speedaward_speed;
340 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
342 speedaward_alltimebest = speedaward_speed;
343 speedaward_alltimebest_holder = speedaward_holder;
344 speedaward_alltimebest_uid = speedaward_uid;
345 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
346 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
347 race_send_speedaward_alltimebest(MSG_ALL);
355 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
357 // no weapon dropping in CTS
361 MUTATOR_HOOKFUNCTION(cts, FilterItem)
363 if(self.classname == "droppedweapon")
369 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
371 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
372 if(!autocvar_g_cts_selfdamage)
378 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
380 return true; // in CTS, you don't lose score by observing
383 MUTATOR_HOOKFUNCTION(cts, SetModname)
385 g_cloaked = 1; // always enable cloak in CTS
390 MUTATOR_HOOKFUNCTION(cts, GetRecords)
392 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
394 if(MapInfo_Get_ByID(i))
396 float r = race_readTime(MapInfo_Map_bspname, 1);
401 string h = race_readName(MapInfo_Map_bspname, 1);
402 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
409 MUTATOR_HOOKFUNCTION(cts, ClientKill)
413 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
415 remove(self.killindicator);
416 self.killindicator = world;
418 ClientKill_Now(); // allow instant kill in this case
424 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
426 if(autocvar_g_cts_finish_kill_delay)
427 CTS_ClientKill(self);
432 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
434 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
438 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
440 ret_float = (want_weaponinfo.weapon == WEP_SHOTGUN.m_id);
441 want_mutatorblocked = true;
445 void cts_Initialize()