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);
112 player.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
113 float f = floor(player.race_movetime_frac);
114 player.race_movetime_frac -= f;
115 player.race_movetime_count += f;
116 player.race_movetime = player.race_movetime_frac + player.race_movetime_count;
119 if(IS_PLAYER(player))
121 if (player.race_penalty)
122 if (time > player.race_penalty)
123 player.race_penalty = 0;
124 if(player.race_penalty)
126 player.velocity = '0 0 0';
127 player.movetype = MOVETYPE_NONE;
128 player.disableclientprediction = 2;
133 // force kbd movement for fairness
137 // if record times matter
138 // ensure nothing EVIL is being done (i.e. div0_evade)
139 // this hinders joystick users though
140 // but it still gives SOME analog control
141 wishvel.x = fabs(player.movement.x);
142 wishvel.y = fabs(player.movement.y);
143 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
146 wishspeed = vlen(wishvel);
147 if(wishvel.x >= 2 * wishvel.y)
150 if(player.movement.x > 0)
151 player.movement_x = wishspeed;
153 player.movement_x = -wishspeed;
154 player.movement_y = 0;
156 else if(wishvel.y >= 2 * wishvel.x)
159 player.movement_x = 0;
160 if(player.movement.y > 0)
161 player.movement_y = wishspeed;
163 player.movement_y = -wishspeed;
168 if(player.movement.x > 0)
169 player.movement_x = M_SQRT1_2 * wishspeed;
171 player.movement_x = -M_SQRT1_2 * wishspeed;
172 if(player.movement.y > 0)
173 player.movement_y = M_SQRT1_2 * wishspeed;
175 player.movement_y = -M_SQRT1_2 * wishspeed;
180 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
184 Score_NicePrint(NULL);
187 PlayerScore_Sort(race_place, 0, 1, 0);
189 FOREACH_CLIENT(true, LAMBDA(
192 s = PlayerScore_Add(it, SP_RACE_FASTEST, 0);
196 cts_EventLog(ftos(it.race_place), it);
199 if(g_race_qualifying == 2)
201 g_race_qualifying = 0;
202 independent_players = 0;
203 cvar_set("fraglimit", ftos(race_fraglimit));
204 cvar_set("leadlimit", ftos(race_leadlimit));
205 cvar_set("timelimit", ftos(race_timelimit));
210 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
212 entity player = M_ARGV(0, entity);
214 race_PreparePlayer(player);
215 player.race_checkpoint = -1;
217 if(IS_REAL_CLIENT(player))
219 string rr = CTS_RECORD;
222 race_send_recordtime(MSG_ONE);
223 race_send_speedaward(MSG_ONE);
225 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
226 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
227 race_send_speedaward_alltimebest(MSG_ONE);
230 for (i = 1; i <= RANKINGS_CNT; ++i)
232 race_SendRankings(i, 0, 0, MSG_ONE);
237 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
239 entity player = M_ARGV(0, entity);
241 if(PlayerScore_Add(player, SP_RACE_FASTEST, 0))
242 player.frags = FRAGS_LMS_LOSER;
244 player.frags = FRAGS_SPECTATOR;
246 race_PreparePlayer(player);
247 player.race_checkpoint = -1;
250 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
252 entity player = M_ARGV(0, entity);
253 entity spawn_spot = M_ARGV(1, entity);
255 if(spawn_spot.target == "")
256 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
257 race_PreparePlayer(player);
259 // if we need to respawn, do it right
260 player.race_respawn_checkpoint = player.race_checkpoint;
261 player.race_respawn_spotref = spawn_spot;
263 player.race_place = 0;
266 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
268 entity player = M_ARGV(0, entity);
270 if(IS_PLAYER(player))
273 if(player.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
274 race_PreparePlayer(player);
276 race_RetractPlayer(player);
278 race_AbandonRaceCheck(player);
282 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
284 entity frag_target = M_ARGV(2, entity);
286 frag_target.respawn_flags |= RESPAWN_FORCE;
287 race_AbandonRaceCheck(frag_target);
290 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
292 entity bot = M_ARGV(0, entity);
294 bot.havocbot_role = havocbot_role_cts;
298 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
300 entity player = M_ARGV(0, entity);
302 if(player.cvar_cl_allow_uidtracking == 1 && player.cvar_cl_allow_uid2name == 1)
304 if (!player.stored_netname)
305 player.stored_netname = strzone(uid2name(player.crypto_idfp));
306 if(player.stored_netname != player.netname)
308 db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname);
309 strunzone(player.stored_netname);
310 player.stored_netname = strzone(player.netname);
314 if (!IS_OBSERVER(player))
316 if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed))
318 speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1');
319 speedaward_holder = player.netname;
320 speedaward_uid = player.crypto_idfp;
321 speedaward_lastupdate = time;
323 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
325 string rr = CTS_RECORD;
326 race_send_speedaward(MSG_ALL);
327 speedaward_lastsent = speedaward_speed;
328 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
330 speedaward_alltimebest = speedaward_speed;
331 speedaward_alltimebest_holder = speedaward_holder;
332 speedaward_alltimebest_uid = speedaward_uid;
333 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
334 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
335 race_send_speedaward_alltimebest(MSG_ALL);
341 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
343 // no weapon dropping in CTS
347 MUTATOR_HOOKFUNCTION(cts, FilterItem)
349 entity item = M_ARGV(0, entity);
351 if(item.classname == "droppedweapon")
355 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
357 entity frag_attacker = M_ARGV(1, entity);
358 entity frag_target = M_ARGV(2, entity);
359 float frag_deathtype = M_ARGV(3, float);
360 float frag_damage = M_ARGV(4, float);
362 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
363 if(!autocvar_g_cts_selfdamage)
366 M_ARGV(4, float) = frag_damage;
370 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
372 return true; // in CTS, you don't lose score by observing
375 MUTATOR_HOOKFUNCTION(cts, GetRecords)
377 int record_page = M_ARGV(0, int);
378 string ret_string = M_ARGV(1, string);
380 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
382 if(MapInfo_Get_ByID(i))
384 float r = race_readTime(MapInfo_Map_bspname, 1);
389 string h = race_readName(MapInfo_Map_bspname, 1);
390 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
394 M_ARGV(1, string) = ret_string;
397 void ClientKill_Now(entity this);
398 MUTATOR_HOOKFUNCTION(cts, ClientKill)
400 entity player = M_ARGV(0, entity);
402 M_ARGV(1, float) = 0; // kill delay
404 if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
406 remove(player.killindicator);
407 player.killindicator = NULL;
409 ClientKill_Now(player); // allow instant kill in this case
414 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
416 entity player = M_ARGV(0, entity);
418 if(autocvar_g_cts_finish_kill_delay)
419 CTS_ClientKill(player);
422 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
424 entity player = M_ARGV(0, entity);
426 stuffcmd(player, "cl_cmd settemp cl_movecliptokeyboard 2\n");
429 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
431 M_ARGV(1, float) = (M_ARGV(0, entity) == WEP_SHOTGUN); // want weapon = weapon info
432 M_ARGV(3, bool) = true; // want mutator blocked
436 void cts_Initialize()