1 #include "gamemode_cts.qh"
2 #include <server/race.qh>
4 #include <server/race.qh>
6 float autocvar_g_cts_finish_kill_delay;
7 bool autocvar_g_cts_selfdamage;
10 .float race_checkpoint;
11 void havocbot_role_cts(entity this)
16 if (navigation_goalrating_timeout(this))
18 navigation_goalrating_start(this);
20 IL_EACH(g_racecheckpoints, true,
22 if(it.cnt == this.race_checkpoint)
23 navigation_routerating(this, it, 1000000, 5000);
24 else if(this.race_checkpoint == -1)
25 navigation_routerating(this, it, 1000000, 5000);
28 navigation_goalrating_end(this);
30 navigation_goalrating_timeout_set(this);
36 GameRules_score_enabled(false);
37 GameRules_scoring(0, 0, 0, {
38 if (g_race_qualifying) {
39 field(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
41 field(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
42 field(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
43 field(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
48 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
50 if(autocvar_sv_eventlog)
51 GameLogEcho(strcat(":cts:", mode, ":", ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : "")));
54 void KillIndicator_Think(entity this);
55 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
57 e.killindicator = spawn();
58 e.killindicator.owner = e;
59 setthink(e.killindicator, KillIndicator_Think);
60 e.killindicator.nextthink = time + (e.lip) * 0.05;
61 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
62 e.killindicator.health = 1; // this is used to indicate that it should be silent
66 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
68 entity player = M_ARGV(0, entity);
69 float dt = M_ARGV(1, float);
71 player.race_movetime_frac += dt;
72 float f = floor(player.race_movetime_frac);
73 player.race_movetime_frac -= f;
74 player.race_movetime_count += f;
75 player.race_movetime = player.race_movetime_frac + player.race_movetime_count;
80 if (player.race_penalty)
81 if (time > player.race_penalty)
82 player.race_penalty = 0;
83 if(player.race_penalty)
85 player.velocity = '0 0 0';
86 set_movetype(player, MOVETYPE_NONE);
87 player.disableclientprediction = 2;
92 // force kbd movement for fairness
96 // if record times matter
97 // ensure nothing EVIL is being done (i.e. div0_evade)
98 // this hinders joystick users though
99 // but it still gives SOME analog control
100 wishvel.x = fabs(CS(player).movement.x);
101 wishvel.y = fabs(CS(player).movement.y);
102 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
105 wishspeed = vlen(wishvel);
106 if(wishvel.x >= 2 * wishvel.y)
109 if(CS(player).movement.x > 0)
110 CS(player).movement_x = wishspeed;
112 CS(player).movement_x = -wishspeed;
113 CS(player).movement_y = 0;
115 else if(wishvel.y >= 2 * wishvel.x)
118 CS(player).movement_x = 0;
119 if(CS(player).movement.y > 0)
120 CS(player).movement_y = wishspeed;
122 CS(player).movement_y = -wishspeed;
127 if(CS(player).movement.x > 0)
128 CS(player).movement_x = M_SQRT1_2 * wishspeed;
130 CS(player).movement_x = -M_SQRT1_2 * wishspeed;
131 if(CS(player).movement.y > 0)
132 CS(player).movement_y = M_SQRT1_2 * wishspeed;
134 CS(player).movement_y = -M_SQRT1_2 * wishspeed;
139 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
143 Score_NicePrint(NULL);
146 PlayerScore_Sort(race_place, 0, 1, 0);
148 FOREACH_CLIENT(true, {
151 s = GameRules_scoring_add(it, RACE_FASTEST, 0);
155 cts_EventLog(ftos(it.race_place), it);
158 if(g_race_qualifying == 2)
160 g_race_qualifying = 0;
161 independent_players = 0;
162 cvar_set("fraglimit", ftos(race_fraglimit));
163 cvar_set("leadlimit", ftos(race_leadlimit));
164 cvar_set("timelimit", ftos(race_timelimit));
169 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
171 entity player = M_ARGV(0, entity);
173 race_PreparePlayer(player);
174 player.race_checkpoint = -1;
176 if(IS_REAL_CLIENT(player))
178 string rr = CTS_RECORD;
181 race_send_recordtime(MSG_ONE);
182 race_send_speedaward(MSG_ONE);
184 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
185 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
186 race_send_speedaward_alltimebest(MSG_ONE);
189 for (i = 1; i <= RANKINGS_CNT; ++i)
191 race_SendRankings(i, 0, 0, MSG_ONE);
196 MUTATOR_HOOKFUNCTION(cts, AbortSpeedrun)
198 entity player = M_ARGV(0, entity);
200 if(autocvar_g_allow_checkpoints)
201 race_PreparePlayer(player); // nice try
204 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
206 entity player = M_ARGV(0, entity);
208 if(GameRules_scoring_add(player, RACE_FASTEST, 0))
209 player.frags = FRAGS_LMS_LOSER;
211 player.frags = FRAGS_SPECTATOR;
213 race_PreparePlayer(player);
214 player.race_checkpoint = -1;
217 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
219 entity player = M_ARGV(0, entity);
220 entity spawn_spot = M_ARGV(1, entity);
222 if(spawn_spot.target == "")
223 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
224 race_PreparePlayer(player);
226 // if we need to respawn, do it right
227 player.race_respawn_checkpoint = player.race_checkpoint;
228 player.race_respawn_spotref = spawn_spot;
230 player.race_place = 0;
233 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
235 entity player = M_ARGV(0, entity);
237 if(IS_PLAYER(player))
240 if(CS(player).killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
241 race_PreparePlayer(player);
243 race_RetractPlayer(player);
245 race_AbandonRaceCheck(player);
249 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
251 entity frag_target = M_ARGV(2, entity);
253 frag_target.respawn_flags |= RESPAWN_FORCE;
254 race_AbandonRaceCheck(frag_target);
257 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
259 entity bot = M_ARGV(0, entity);
261 bot.havocbot_role = havocbot_role_cts;
265 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
267 entity player = M_ARGV(0, entity);
269 if(CS(player).cvar_cl_allow_uidtracking == 1 && CS(player).cvar_cl_allow_uid2name == 1)
271 if (!player.stored_netname)
272 player.stored_netname = strzone(uid2name(player.crypto_idfp));
273 if(player.stored_netname != player.netname)
275 db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname);
276 strunzone(player.stored_netname);
277 player.stored_netname = strzone(player.netname);
281 if (!IS_OBSERVER(player))
283 if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed))
285 speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1');
286 speedaward_holder = player.netname;
287 speedaward_uid = player.crypto_idfp;
288 speedaward_lastupdate = time;
290 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
292 string rr = CTS_RECORD;
293 race_send_speedaward(MSG_ALL);
294 speedaward_lastsent = speedaward_speed;
295 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
297 speedaward_alltimebest = speedaward_speed;
298 speedaward_alltimebest_holder = speedaward_holder;
299 speedaward_alltimebest_uid = speedaward_uid;
300 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
301 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
302 race_send_speedaward_alltimebest(MSG_ALL);
308 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
310 // no weapon dropping in CTS
314 MUTATOR_HOOKFUNCTION(cts, FilterItem)
316 entity item = M_ARGV(0, entity);
318 if(item.classname == "droppedweapon")
322 MUTATOR_HOOKFUNCTION(cts, Damage_Calculate)
324 entity frag_attacker = M_ARGV(1, entity);
325 entity frag_target = M_ARGV(2, entity);
326 float frag_deathtype = M_ARGV(3, float);
327 float frag_damage = M_ARGV(4, float);
329 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
330 if(!autocvar_g_cts_selfdamage)
333 M_ARGV(4, float) = frag_damage;
337 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
339 return true; // in CTS, you don't lose score by observing
342 MUTATOR_HOOKFUNCTION(cts, GetRecords)
344 int record_page = M_ARGV(0, int);
345 string ret_string = M_ARGV(1, string);
347 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
349 if(MapInfo_Get_ByID(i))
351 float r = race_readTime(MapInfo_Map_bspname, 1);
356 string h = race_readName(MapInfo_Map_bspname, 1);
357 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
361 M_ARGV(1, string) = ret_string;
364 void ClientKill_Now(entity this);
365 MUTATOR_HOOKFUNCTION(cts, ClientKill)
367 entity player = M_ARGV(0, entity);
369 M_ARGV(1, float) = 0; // kill delay
371 if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
373 delete(player.killindicator);
374 player.killindicator = NULL;
376 ClientKill_Now(player); // allow instant kill in this case
381 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
383 entity player = M_ARGV(0, entity);
385 if(autocvar_g_cts_finish_kill_delay)
386 CTS_ClientKill(player);
389 MUTATOR_HOOKFUNCTION(cts, HideTeamNagger)
391 return true; // doesn't work so well (but isn't cts a teamless mode?)
394 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
396 entity player = M_ARGV(0, entity);
398 stuffcmd(player, "cl_cmd settemp cl_movecliptokeyboard 2\n");
401 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
403 M_ARGV(1, float) = (M_ARGV(0, entity) == WEP_SHOTGUN); // want weapon = weapon info
404 M_ARGV(3, bool) = true; // want mutator blocked
408 MUTATOR_HOOKFUNCTION(cts, ForbidDropCurrentWeapon)
413 void cts_Initialize()