1 #include "gamemode_cts.qh"
7 float autocvar_g_cts_finish_kill_delay;
8 bool autocvar_g_cts_selfdamage;
11 .float race_checkpoint;
12 void havocbot_role_cts()
14 if(self.deadflag != DEAD_NO)
18 if (self.bot_strategytime < time)
20 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
21 navigation_goalrating_start();
23 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
25 if(e.cnt == self.race_checkpoint)
27 navigation_routerating(e, 1000000, 5000);
29 else if(self.race_checkpoint == -1)
31 navigation_routerating(e, 1000000, 5000);
35 navigation_goalrating_end();
41 ScoreRules_basics(0, 0, 0, false);
44 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
48 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
49 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
50 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
52 ScoreRules_basics_end();
55 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
57 if(autocvar_sv_eventlog)
58 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
61 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
63 e.killindicator = spawn();
64 e.killindicator.owner = e;
65 e.killindicator.think = KillIndicator_Think;
66 e.killindicator.nextthink = time + (e.lip) * 0.05;
67 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
68 e.killindicator.health = 1; // this is used to indicate that it should be silent
72 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
74 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
75 float f = floor(self.race_movetime_frac);
76 self.race_movetime_frac -= f;
77 self.race_movetime_count += f;
78 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
83 if (self.race_penalty)
84 if (time > self.race_penalty)
85 self.race_penalty = 0;
88 self.velocity = '0 0 0';
89 self.movetype = MOVETYPE_NONE;
90 self.disableclientprediction = 2;
95 // force kbd movement for fairness
99 // if record times matter
100 // ensure nothing EVIL is being done (i.e. div0_evade)
101 // this hinders joystick users though
102 // but it still gives SOME analog control
103 wishvel.x = fabs(self.movement.x);
104 wishvel.y = fabs(self.movement.y);
105 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
108 wishspeed = vlen(wishvel);
109 if(wishvel.x >= 2 * wishvel.y)
112 if(self.movement.x > 0)
113 self.movement_x = wishspeed;
115 self.movement_x = -wishspeed;
118 else if(wishvel.y >= 2 * wishvel.x)
122 if(self.movement.y > 0)
123 self.movement_y = wishspeed;
125 self.movement_y = -wishspeed;
130 if(self.movement.x > 0)
131 self.movement_x = M_SQRT1_2 * wishspeed;
133 self.movement_x = -M_SQRT1_2 * wishspeed;
134 if(self.movement.y > 0)
135 self.movement_y = M_SQRT1_2 * wishspeed;
137 self.movement_y = -M_SQRT1_2 * wishspeed;
144 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
148 Score_NicePrint(world);
151 PlayerScore_Sort(race_place, 0, 1, 0);
158 s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
162 cts_EventLog(ftos(e.race_place), e);
165 if(g_race_qualifying == 2)
167 g_race_qualifying = 0;
168 independent_players = 0;
169 cvar_set("fraglimit", ftos(race_fraglimit));
170 cvar_set("leadlimit", ftos(race_leadlimit));
171 cvar_set("timelimit", ftos(race_timelimit));
178 MUTATOR_HOOKFUNCTION(cts, PlayerPreThink)
180 if(IS_SPEC(self) || IS_OBSERVER(self))
181 if(g_race_qualifying)
182 if(msg_entity.enemy.race_laptime)
183 race_SendNextCheckpoint(msg_entity.enemy, 1);
188 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
190 race_PreparePlayer();
191 self.race_checkpoint = -1;
193 if(IS_REAL_CLIENT(self))
195 string rr = CTS_RECORD;
198 race_send_recordtime(MSG_ONE);
199 race_send_speedaward(MSG_ONE);
201 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
202 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
203 race_send_speedaward_alltimebest(MSG_ONE);
206 for (i = 1; i <= RANKINGS_CNT; ++i)
208 race_SendRankings(i, 0, 0, MSG_ONE);
215 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
217 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
218 self.frags = FRAGS_LMS_LOSER;
220 self.frags = FRAGS_SPECTATOR;
222 race_PreparePlayer();
223 self.race_checkpoint = -1;
228 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
230 if(spawn_spot.target == "")
231 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
232 race_PreparePlayer();
234 // if we need to respawn, do it right
235 self.race_respawn_checkpoint = self.race_checkpoint;
236 self.race_respawn_spotref = spawn_spot;
243 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
248 if(self.killcount == -666 /* initial spawn */ || g_race_qualifying) // spawn
249 race_PreparePlayer();
251 race_RetractPlayer();
253 race_AbandonRaceCheck(self);
258 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
260 self.respawn_flags |= RESPAWN_FORCE;
261 race_AbandonRaceCheck(self);
265 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
267 self.havocbot_role = havocbot_role_cts;
271 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
273 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
275 if (!self.stored_netname)
276 self.stored_netname = strzone(uid2name(self.crypto_idfp));
277 if(self.stored_netname != self.netname)
279 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
280 strunzone(self.stored_netname);
281 self.stored_netname = strzone(self.netname);
285 if (!IS_OBSERVER(self))
287 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
289 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
290 speedaward_holder = self.netname;
291 speedaward_uid = self.crypto_idfp;
292 speedaward_lastupdate = time;
294 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
296 string rr = CTS_RECORD;
297 race_send_speedaward(MSG_ALL);
298 speedaward_lastsent = speedaward_speed;
299 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
301 speedaward_alltimebest = speedaward_speed;
302 speedaward_alltimebest_holder = speedaward_holder;
303 speedaward_alltimebest_uid = speedaward_uid;
304 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
305 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
306 race_send_speedaward_alltimebest(MSG_ALL);
314 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
316 // no weapon dropping in CTS
320 MUTATOR_HOOKFUNCTION(cts, FilterItem)
322 if(self.classname == "droppedweapon")
328 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
330 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
331 if(!autocvar_g_cts_selfdamage)
337 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
339 return true; // in CTS, you don't lose score by observing
342 MUTATOR_HOOKFUNCTION(cts, SetModname)
344 g_cloaked = 1; // always enable cloak in CTS
349 MUTATOR_HOOKFUNCTION(cts, GetRecords)
351 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
353 if(MapInfo_Get_ByID(i))
355 float r = race_readTime(MapInfo_Map_bspname, 1);
360 string h = race_readName(MapInfo_Map_bspname, 1);
361 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
368 MUTATOR_HOOKFUNCTION(cts, ClientKill)
372 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
374 remove(self.killindicator);
375 self.killindicator = world;
377 ClientKill_Now(); // allow instant kill in this case
383 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
385 if(autocvar_g_cts_finish_kill_delay)
386 CTS_ClientKill(self);
391 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
393 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
397 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
399 ret_float = (want_weaponinfo.weapon == WEP_SHOTGUN.m_id);
400 want_mutatorblocked = true;
404 void cts_Initialize()
409 REGISTER_MUTATOR(cts, g_cts)
411 g_race_qualifying = 1;
412 independent_players = 1;
413 SetLimits(0, 0, 0, -1);
417 if(time > 1) // game loads at time 1
418 error("This is a game type and it cannot be added at runtime.");
422 MUTATOR_ONROLLBACK_OR_REMOVE
424 // we actually cannot roll back cts_Initialize here
425 // BUT: we don't need to! If this gets called, adding always
431 LOG_INFO("This is a game type and it cannot be removed at runtime.");