5 const float ST_CTS_LAPS = 1;
6 const float SP_CTS_LAPS = 4;
7 const float SP_CTS_TIME = 5;
8 const float SP_CTS_FASTEST = 6;
13 #include "../../race.qh"
15 float autocvar_g_cts_finish_kill_delay;
16 bool autocvar_g_cts_selfdamage;
19 .float race_checkpoint;
20 void havocbot_role_cts()
22 if(self.deadflag != DEAD_NO)
26 if (self.bot_strategytime < time)
28 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
29 navigation_goalrating_start();
31 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
33 if(e.cnt == self.race_checkpoint)
35 navigation_routerating(e, 1000000, 5000);
37 else if(self.race_checkpoint == -1)
39 navigation_routerating(e, 1000000, 5000);
43 navigation_goalrating_end();
49 ScoreRules_basics(0, 0, 0, false);
52 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
56 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
57 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
58 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
60 ScoreRules_basics_end();
63 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
65 if(autocvar_sv_eventlog)
66 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
69 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
71 e.killindicator = spawn();
72 e.killindicator.owner = e;
73 e.killindicator.think = KillIndicator_Think;
74 e.killindicator.nextthink = time + (e.lip) * 0.05;
75 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
76 e.killindicator.health = 1; // this is used to indicate that it should be silent
80 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
82 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
83 float f = floor(self.race_movetime_frac);
84 self.race_movetime_frac -= f;
85 self.race_movetime_count += f;
86 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
91 if (self.race_penalty)
92 if (time > self.race_penalty)
93 self.race_penalty = 0;
96 self.velocity = '0 0 0';
97 self.movetype = MOVETYPE_NONE;
98 self.disableclientprediction = 2;
103 // force kbd movement for fairness
107 // if record times matter
108 // ensure nothing EVIL is being done (i.e. div0_evade)
109 // this hinders joystick users though
110 // but it still gives SOME analog control
111 wishvel.x = fabs(self.movement.x);
112 wishvel.y = fabs(self.movement.y);
113 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
116 wishspeed = vlen(wishvel);
117 if(wishvel.x >= 2 * wishvel.y)
120 if(self.movement.x > 0)
121 self.movement_x = wishspeed;
123 self.movement_x = -wishspeed;
126 else if(wishvel.y >= 2 * wishvel.x)
130 if(self.movement.y > 0)
131 self.movement_y = wishspeed;
133 self.movement_y = -wishspeed;
138 if(self.movement.x > 0)
139 self.movement_x = M_SQRT1_2 * wishspeed;
141 self.movement_x = -M_SQRT1_2 * wishspeed;
142 if(self.movement.y > 0)
143 self.movement_y = M_SQRT1_2 * wishspeed;
145 self.movement_y = -M_SQRT1_2 * wishspeed;
152 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
156 Score_NicePrint(world);
159 PlayerScore_Sort(race_place, 0, 1, 0);
166 s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
170 cts_EventLog(ftos(e.race_place), e);
173 if(g_race_qualifying == 2)
175 g_race_qualifying = 0;
176 independent_players = 0;
177 cvar_set("fraglimit", ftos(race_fraglimit));
178 cvar_set("leadlimit", ftos(race_leadlimit));
179 cvar_set("timelimit", ftos(race_timelimit));
186 MUTATOR_HOOKFUNCTION(cts, PlayerPreThink)
188 if(IS_SPEC(self) || IS_OBSERVER(self))
189 if(g_race_qualifying)
190 if(msg_entity.enemy.race_laptime)
191 race_SendNextCheckpoint(msg_entity.enemy, 1);
196 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
198 race_PreparePlayer();
199 self.race_checkpoint = -1;
201 if(IS_REAL_CLIENT(self))
203 string rr = CTS_RECORD;
206 race_send_recordtime(MSG_ONE);
207 race_send_speedaward(MSG_ONE);
209 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
210 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
211 race_send_speedaward_alltimebest(MSG_ONE);
214 for (i = 1; i <= RANKINGS_CNT; ++i)
216 race_SendRankings(i, 0, 0, MSG_ONE);
223 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
225 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
226 self.frags = FRAGS_LMS_LOSER;
228 self.frags = FRAGS_SPECTATOR;
230 race_PreparePlayer();
231 self.race_checkpoint = -1;
236 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
238 if(spawn_spot.target == "")
239 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
240 race_PreparePlayer();
242 // if we need to respawn, do it right
243 self.race_respawn_checkpoint = self.race_checkpoint;
244 self.race_respawn_spotref = spawn_spot;
251 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
256 if(self.killcount == -666 /* initial spawn */ || g_race_qualifying) // spawn
257 race_PreparePlayer();
259 race_RetractPlayer();
261 race_AbandonRaceCheck(self);
266 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
268 self.respawn_flags |= RESPAWN_FORCE;
269 race_AbandonRaceCheck(self);
273 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
275 self.havocbot_role = havocbot_role_cts;
279 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
281 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
283 if (!self.stored_netname)
284 self.stored_netname = strzone(uid2name(self.crypto_idfp));
285 if(self.stored_netname != self.netname)
287 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
288 strunzone(self.stored_netname);
289 self.stored_netname = strzone(self.netname);
293 if (!IS_OBSERVER(self))
295 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
297 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
298 speedaward_holder = self.netname;
299 speedaward_uid = self.crypto_idfp;
300 speedaward_lastupdate = time;
302 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
304 string rr = CTS_RECORD;
305 race_send_speedaward(MSG_ALL);
306 speedaward_lastsent = speedaward_speed;
307 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
309 speedaward_alltimebest = speedaward_speed;
310 speedaward_alltimebest_holder = speedaward_holder;
311 speedaward_alltimebest_uid = speedaward_uid;
312 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
313 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
314 race_send_speedaward_alltimebest(MSG_ALL);
322 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
324 // no weapon dropping in CTS
328 MUTATOR_HOOKFUNCTION(cts, FilterItem)
330 if(self.classname == "droppedweapon")
336 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
338 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
339 if(!autocvar_g_cts_selfdamage)
345 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
347 return true; // in CTS, you don't lose score by observing
350 MUTATOR_HOOKFUNCTION(cts, SetModname)
352 g_cloaked = 1; // always enable cloak in CTS
357 MUTATOR_HOOKFUNCTION(cts, GetRecords)
359 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
361 if(MapInfo_Get_ByID(i))
363 float r = race_readTime(MapInfo_Map_bspname, 1);
368 string h = race_readName(MapInfo_Map_bspname, 1);
369 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
376 MUTATOR_HOOKFUNCTION(cts, ClientKill)
380 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
382 remove(self.killindicator);
383 self.killindicator = world;
385 ClientKill_Now(); // allow instant kill in this case
391 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
393 if(autocvar_g_cts_finish_kill_delay)
394 CTS_ClientKill(self);
399 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
401 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
405 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
407 ret_float = (want_weaponinfo.weapon == WEP_SHOTGUN.m_id);
408 want_mutatorblocked = true;
412 void cts_Initialize()
417 REGISTER_MUTATOR(cts, g_cts)
419 g_race_qualifying = 1;
420 independent_players = 1;
421 SetLimits(0, 0, 0, -1);
425 if(time > 1) // game loads at time 1
426 error("This is a game type and it cannot be added at runtime.");
430 MUTATOR_ONROLLBACK_OR_REMOVE
432 // we actually cannot roll back cts_Initialize here
433 // BUT: we don't need to! If this gets called, adding always
439 LOG_INFO("This is a game type and it cannot be removed at runtime.");