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;
45 #include <server/race.qh>
47 float autocvar_g_cts_finish_kill_delay;
48 bool autocvar_g_cts_selfdamage;
51 .float race_checkpoint;
52 void havocbot_role_cts(entity this)
57 if (this.bot_strategytime < time)
59 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
60 navigation_goalrating_start(this);
62 FOREACH_ENTITY_CLASS("trigger_race_checkpoint", true,
64 if(it.cnt == this.race_checkpoint)
65 navigation_routerating(this, it, 1000000, 5000);
66 else if(this.race_checkpoint == -1)
67 navigation_routerating(this, it, 1000000, 5000);
70 navigation_goalrating_end(this);
76 ScoreRules_basics(0, 0, 0, false);
79 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
83 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
84 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
85 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
87 ScoreRules_basics_end();
90 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
92 if(autocvar_sv_eventlog)
93 GameLogEcho(strcat(":cts:", mode, ":", ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : "")));
96 void KillIndicator_Think(entity this);
97 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
99 e.killindicator = spawn();
100 e.killindicator.owner = e;
101 setthink(e.killindicator, KillIndicator_Think);
102 e.killindicator.nextthink = time + (e.lip) * 0.05;
103 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
104 e.killindicator.health = 1; // this is used to indicate that it should be silent
108 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
110 entity player = M_ARGV(0, entity);
111 float dt = M_ARGV(1, float);
113 player.race_movetime_frac += dt;
114 float f = floor(player.race_movetime_frac);
115 player.race_movetime_frac -= f;
116 player.race_movetime_count += f;
117 player.race_movetime = player.race_movetime_frac + player.race_movetime_count;
120 if(IS_PLAYER(player))
122 if (player.race_penalty)
123 if (time > player.race_penalty)
124 player.race_penalty = 0;
125 if(player.race_penalty)
127 player.velocity = '0 0 0';
128 set_movetype(player, MOVETYPE_NONE);
129 player.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(player.movement.x);
143 wishvel.y = fabs(player.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(player.movement.x > 0)
152 player.movement_x = wishspeed;
154 player.movement_x = -wishspeed;
155 player.movement_y = 0;
157 else if(wishvel.y >= 2 * wishvel.x)
160 player.movement_x = 0;
161 if(player.movement.y > 0)
162 player.movement_y = wishspeed;
164 player.movement_y = -wishspeed;
169 if(player.movement.x > 0)
170 player.movement_x = M_SQRT1_2 * wishspeed;
172 player.movement_x = -M_SQRT1_2 * wishspeed;
173 if(player.movement.y > 0)
174 player.movement_y = M_SQRT1_2 * wishspeed;
176 player.movement_y = -M_SQRT1_2 * wishspeed;
181 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
185 Score_NicePrint(NULL);
188 PlayerScore_Sort(race_place, 0, 1, 0);
190 FOREACH_CLIENT(true, LAMBDA(
193 s = PlayerScore_Add(it, SP_RACE_FASTEST, 0);
197 cts_EventLog(ftos(it.race_place), it);
200 if(g_race_qualifying == 2)
202 g_race_qualifying = 0;
203 independent_players = 0;
204 cvar_set("fraglimit", ftos(race_fraglimit));
205 cvar_set("leadlimit", ftos(race_leadlimit));
206 cvar_set("timelimit", ftos(race_timelimit));
211 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
213 entity player = M_ARGV(0, entity);
215 race_PreparePlayer(player);
216 player.race_checkpoint = -1;
218 if(IS_REAL_CLIENT(player))
220 string rr = CTS_RECORD;
223 race_send_recordtime(MSG_ONE);
224 race_send_speedaward(MSG_ONE);
226 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
227 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
228 race_send_speedaward_alltimebest(MSG_ONE);
231 for (i = 1; i <= RANKINGS_CNT; ++i)
233 race_SendRankings(i, 0, 0, MSG_ONE);
238 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
240 entity player = M_ARGV(0, entity);
242 if(PlayerScore_Add(player, SP_RACE_FASTEST, 0))
243 player.frags = FRAGS_LMS_LOSER;
245 player.frags = FRAGS_SPECTATOR;
247 race_PreparePlayer(player);
248 player.race_checkpoint = -1;
251 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
253 entity player = M_ARGV(0, entity);
254 entity spawn_spot = M_ARGV(1, entity);
256 if(spawn_spot.target == "")
257 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
258 race_PreparePlayer(player);
260 // if we need to respawn, do it right
261 player.race_respawn_checkpoint = player.race_checkpoint;
262 player.race_respawn_spotref = spawn_spot;
264 player.race_place = 0;
267 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
269 entity player = M_ARGV(0, entity);
271 if(IS_PLAYER(player))
274 if(player.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
275 race_PreparePlayer(player);
277 race_RetractPlayer(player);
279 race_AbandonRaceCheck(player);
283 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
285 entity frag_target = M_ARGV(2, entity);
287 frag_target.respawn_flags |= RESPAWN_FORCE;
288 race_AbandonRaceCheck(frag_target);
291 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
293 entity bot = M_ARGV(0, entity);
295 bot.havocbot_role = havocbot_role_cts;
299 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
301 entity player = M_ARGV(0, entity);
303 if(player.cvar_cl_allow_uidtracking == 1 && player.cvar_cl_allow_uid2name == 1)
305 if (!player.stored_netname)
306 player.stored_netname = strzone(uid2name(player.crypto_idfp));
307 if(player.stored_netname != player.netname)
309 db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname);
310 strunzone(player.stored_netname);
311 player.stored_netname = strzone(player.netname);
315 if (!IS_OBSERVER(player))
317 if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed))
319 speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1');
320 speedaward_holder = player.netname;
321 speedaward_uid = player.crypto_idfp;
322 speedaward_lastupdate = time;
324 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
326 string rr = CTS_RECORD;
327 race_send_speedaward(MSG_ALL);
328 speedaward_lastsent = speedaward_speed;
329 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
331 speedaward_alltimebest = speedaward_speed;
332 speedaward_alltimebest_holder = speedaward_holder;
333 speedaward_alltimebest_uid = speedaward_uid;
334 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
335 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
336 race_send_speedaward_alltimebest(MSG_ALL);
342 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
344 // no weapon dropping in CTS
348 MUTATOR_HOOKFUNCTION(cts, FilterItem)
350 entity item = M_ARGV(0, entity);
352 if(item.classname == "droppedweapon")
356 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
358 entity frag_attacker = M_ARGV(1, entity);
359 entity frag_target = M_ARGV(2, entity);
360 float frag_deathtype = M_ARGV(3, float);
361 float frag_damage = M_ARGV(4, float);
363 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
364 if(!autocvar_g_cts_selfdamage)
367 M_ARGV(4, float) = frag_damage;
371 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
373 return true; // in CTS, you don't lose score by observing
376 MUTATOR_HOOKFUNCTION(cts, GetRecords)
378 int record_page = M_ARGV(0, int);
379 string ret_string = M_ARGV(1, string);
381 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
383 if(MapInfo_Get_ByID(i))
385 float r = race_readTime(MapInfo_Map_bspname, 1);
390 string h = race_readName(MapInfo_Map_bspname, 1);
391 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
395 M_ARGV(1, string) = ret_string;
398 void ClientKill_Now(entity this);
399 MUTATOR_HOOKFUNCTION(cts, ClientKill)
401 entity player = M_ARGV(0, entity);
403 M_ARGV(1, float) = 0; // kill delay
405 if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
407 delete(player.killindicator);
408 player.killindicator = NULL;
410 ClientKill_Now(player); // allow instant kill in this case
415 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
417 entity player = M_ARGV(0, entity);
419 if(autocvar_g_cts_finish_kill_delay)
420 CTS_ClientKill(player);
423 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
425 entity player = M_ARGV(0, entity);
427 stuffcmd(player, "cl_cmd settemp cl_movecliptokeyboard 2\n");
430 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
432 M_ARGV(1, float) = (M_ARGV(0, entity) == WEP_SHOTGUN); // want weapon = weapon info
433 M_ARGV(3, bool) = true; // want mutator blocked
437 void cts_Initialize()