1 #include "gamemode_cts.qh"
2 #include <server/race.qh>
9 REGISTER_MUTATOR(cts, false)
13 if (time > 1) // game loads at time 1
14 error("This is a game type and it cannot be added at runtime.");
16 g_race_qualifying = true;
17 independent_players = 1;
18 SetLimits(0, 0, autocvar_timelimit_override, -1);
23 MUTATOR_ONROLLBACK_OR_REMOVE
25 // we actually cannot roll back cts_Initialize here
26 // BUT: we don't need to! If this gets called, adding always
32 LOG_INFO("This is a game type and it cannot be removed at runtime.");
40 const float ST_CTS_LAPS = 1;
41 const float SP_CTS_LAPS = 4;
42 const float SP_CTS_TIME = 5;
43 const float SP_CTS_FASTEST = 6;
48 #include <server/race.qh>
50 float autocvar_g_cts_finish_kill_delay;
51 bool autocvar_g_cts_selfdamage;
54 .float race_checkpoint;
55 void havocbot_role_cts(entity this)
60 if (this.bot_strategytime < time)
62 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
63 navigation_goalrating_start(this);
65 FOREACH_ENTITY_CLASS("trigger_race_checkpoint", true,
67 if(it.cnt == this.race_checkpoint)
68 navigation_routerating(this, it, 1000000, 5000);
69 else if(this.race_checkpoint == -1)
70 navigation_routerating(this, it, 1000000, 5000);
73 navigation_goalrating_end(this);
79 ScoreRules_basics(0, 0, 0, false);
82 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
86 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
87 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
88 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
90 ScoreRules_basics_end();
93 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
95 if(autocvar_sv_eventlog)
96 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
99 void KillIndicator_Think(entity this);
100 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
102 e.killindicator = spawn();
103 e.killindicator.owner = e;
104 setthink(e.killindicator, KillIndicator_Think);
105 e.killindicator.nextthink = time + (e.lip) * 0.05;
106 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
107 e.killindicator.health = 1; // this is used to indicate that it should be silent
111 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
113 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
114 float f = floor(self.race_movetime_frac);
115 self.race_movetime_frac -= f;
116 self.race_movetime_count += f;
117 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
122 if (self.race_penalty)
123 if (time > self.race_penalty)
124 self.race_penalty = 0;
125 if(self.race_penalty)
127 self.velocity = '0 0 0';
128 self.movetype = MOVETYPE_NONE;
129 self.disableclientprediction = 2;
134 // force kbd movement for fairness
138 // if record times matter
139 // ensure nothing EVIL is being done (i.e. div0_evade)
140 // this hinders joystick users though
141 // but it still gives SOME analog control
142 wishvel.x = fabs(self.movement.x);
143 wishvel.y = fabs(self.movement.y);
144 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
147 wishspeed = vlen(wishvel);
148 if(wishvel.x >= 2 * wishvel.y)
151 if(self.movement.x > 0)
152 self.movement_x = wishspeed;
154 self.movement_x = -wishspeed;
157 else if(wishvel.y >= 2 * wishvel.x)
161 if(self.movement.y > 0)
162 self.movement_y = wishspeed;
164 self.movement_y = -wishspeed;
169 if(self.movement.x > 0)
170 self.movement_x = M_SQRT1_2 * wishspeed;
172 self.movement_x = -M_SQRT1_2 * wishspeed;
173 if(self.movement.y > 0)
174 self.movement_y = M_SQRT1_2 * wishspeed;
176 self.movement_y = -M_SQRT1_2 * wishspeed;
183 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
187 Score_NicePrint(world);
190 PlayerScore_Sort(race_place, 0, 1, 0);
192 FOREACH_CLIENT(true, LAMBDA(
195 s = PlayerScore_Add(it, SP_RACE_FASTEST, 0);
199 cts_EventLog(ftos(it.race_place), it);
202 if(g_race_qualifying == 2)
204 g_race_qualifying = 0;
205 independent_players = 0;
206 cvar_set("fraglimit", ftos(race_fraglimit));
207 cvar_set("leadlimit", ftos(race_leadlimit));
208 cvar_set("timelimit", ftos(race_timelimit));
215 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
217 race_PreparePlayer(this);
218 self.race_checkpoint = -1;
220 if(IS_REAL_CLIENT(self))
222 string rr = CTS_RECORD;
225 race_send_recordtime(MSG_ONE);
226 race_send_speedaward(MSG_ONE);
228 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
229 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
230 race_send_speedaward_alltimebest(MSG_ONE);
233 for (i = 1; i <= RANKINGS_CNT; ++i)
235 race_SendRankings(i, 0, 0, MSG_ONE);
242 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
244 entity player = M_ARGV(0, entity);
246 if(PlayerScore_Add(player, SP_RACE_FASTEST, 0))
247 player.frags = FRAGS_LMS_LOSER;
249 player.frags = FRAGS_SPECTATOR;
251 race_PreparePlayer(player);
252 player.race_checkpoint = -1;
257 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
259 entity player = M_ARGV(0, entity);
260 entity spawn_spot = M_ARGV(1, entity);
262 if(spawn_spot.target == "")
263 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
264 race_PreparePlayer(player);
266 // if we need to respawn, do it right
267 player.race_respawn_checkpoint = player.race_checkpoint;
268 player.race_respawn_spotref = spawn_spot;
270 player.race_place = 0;
275 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
277 entity player = M_ARGV(0, entity);
279 if(IS_PLAYER(player))
282 if(player.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
283 race_PreparePlayer(player);
285 race_RetractPlayer(player);
287 race_AbandonRaceCheck(player);
292 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
294 entity frag_target = M_ARGV(2, entity);
296 frag_target.respawn_flags |= RESPAWN_FORCE;
297 race_AbandonRaceCheck(frag_target);
301 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
303 self.havocbot_role = havocbot_role_cts;
307 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
309 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
311 if (!self.stored_netname)
312 self.stored_netname = strzone(uid2name(self.crypto_idfp));
313 if(self.stored_netname != self.netname)
315 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
316 strunzone(self.stored_netname);
317 self.stored_netname = strzone(self.netname);
321 if (!IS_OBSERVER(self))
323 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
325 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
326 speedaward_holder = self.netname;
327 speedaward_uid = self.crypto_idfp;
328 speedaward_lastupdate = time;
330 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
332 string rr = CTS_RECORD;
333 race_send_speedaward(MSG_ALL);
334 speedaward_lastsent = speedaward_speed;
335 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
337 speedaward_alltimebest = speedaward_speed;
338 speedaward_alltimebest_holder = speedaward_holder;
339 speedaward_alltimebest_uid = speedaward_uid;
340 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
341 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
342 race_send_speedaward_alltimebest(MSG_ALL);
350 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
352 // no weapon dropping in CTS
356 MUTATOR_HOOKFUNCTION(cts, FilterItem)
358 entity item = M_ARGV(0, entity);
360 if(item.classname == "droppedweapon")
366 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
368 entity frag_attacker = M_ARGV(1, entity);
369 entity frag_target = M_ARGV(2, entity);
370 float frag_deathtype = M_ARGV(3, float);
371 float frag_damage = M_ARGV(4, float);
373 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
374 if(!autocvar_g_cts_selfdamage)
377 M_ARGV(4, float) = frag_damage;
383 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
385 return true; // in CTS, you don't lose score by observing
388 MUTATOR_HOOKFUNCTION(cts, GetRecords)
390 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
392 if(MapInfo_Get_ByID(i))
394 float r = race_readTime(MapInfo_Map_bspname, 1);
399 string h = race_readName(MapInfo_Map_bspname, 1);
400 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
407 void ClientKill_Now();
408 MUTATOR_HOOKFUNCTION(cts, ClientKill)
410 entity player = M_ARGV(0, entity);
412 M_ARGV(1, float) = 0; // kill delay
414 if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
416 remove(player.killindicator);
417 player.killindicator = world;
419 WITHSELF(player, 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(race_player);
432 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
434 entity player = M_ARGV(0, entity);
436 stuffcmd(player, "cl_cmd settemp cl_movecliptokeyboard 2\n");
439 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
441 M_ARGV(1, float) = (M_ARGV(0, entity) == WEP_SHOTGUN); // want weapon = weapon info
442 M_ARGV(3, bool) = true; // want mutator blocked
446 void cts_Initialize()