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, -1, -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 != world) ? (strcat(":", ftos(actor.playerid))) : "")));
96 void KillIndicator_Think();
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 e.killindicator.think = 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 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
111 float f = floor(self.race_movetime_frac);
112 self.race_movetime_frac -= f;
113 self.race_movetime_count += f;
114 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
119 if (self.race_penalty)
120 if (time > self.race_penalty)
121 self.race_penalty = 0;
122 if(self.race_penalty)
124 self.velocity = '0 0 0';
125 self.movetype = MOVETYPE_NONE;
126 self.disableclientprediction = 2;
131 // force kbd movement for fairness
135 // if record times matter
136 // ensure nothing EVIL is being done (i.e. div0_evade)
137 // this hinders joystick users though
138 // but it still gives SOME analog control
139 wishvel.x = fabs(self.movement.x);
140 wishvel.y = fabs(self.movement.y);
141 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
144 wishspeed = vlen(wishvel);
145 if(wishvel.x >= 2 * wishvel.y)
148 if(self.movement.x > 0)
149 self.movement_x = wishspeed;
151 self.movement_x = -wishspeed;
154 else if(wishvel.y >= 2 * wishvel.x)
158 if(self.movement.y > 0)
159 self.movement_y = wishspeed;
161 self.movement_y = -wishspeed;
166 if(self.movement.x > 0)
167 self.movement_x = M_SQRT1_2 * wishspeed;
169 self.movement_x = -M_SQRT1_2 * wishspeed;
170 if(self.movement.y > 0)
171 self.movement_y = M_SQRT1_2 * wishspeed;
173 self.movement_y = -M_SQRT1_2 * wishspeed;
180 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
184 Score_NicePrint(world);
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));
212 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
214 race_PreparePlayer();
215 self.race_checkpoint = -1;
217 if(IS_REAL_CLIENT(self))
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);
239 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
241 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
242 self.frags = FRAGS_LMS_LOSER;
244 self.frags = FRAGS_SPECTATOR;
246 race_PreparePlayer();
247 self.race_checkpoint = -1;
252 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
254 if(spawn_spot.target == "")
255 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
256 race_PreparePlayer();
258 // if we need to respawn, do it right
259 self.race_respawn_checkpoint = self.race_checkpoint;
260 self.race_respawn_spotref = spawn_spot;
267 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
272 if(self.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
273 race_PreparePlayer();
275 race_RetractPlayer();
277 race_AbandonRaceCheck(self);
282 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
284 frag_target.respawn_flags |= RESPAWN_FORCE;
285 race_AbandonRaceCheck(frag_target);
289 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
291 self.havocbot_role = havocbot_role_cts;
295 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
297 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
299 if (!self.stored_netname)
300 self.stored_netname = strzone(uid2name(self.crypto_idfp));
301 if(self.stored_netname != self.netname)
303 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
304 strunzone(self.stored_netname);
305 self.stored_netname = strzone(self.netname);
309 if (!IS_OBSERVER(self))
311 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
313 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
314 speedaward_holder = self.netname;
315 speedaward_uid = self.crypto_idfp;
316 speedaward_lastupdate = time;
318 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
320 string rr = CTS_RECORD;
321 race_send_speedaward(MSG_ALL);
322 speedaward_lastsent = speedaward_speed;
323 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
325 speedaward_alltimebest = speedaward_speed;
326 speedaward_alltimebest_holder = speedaward_holder;
327 speedaward_alltimebest_uid = speedaward_uid;
328 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
329 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
330 race_send_speedaward_alltimebest(MSG_ALL);
338 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
340 // no weapon dropping in CTS
344 MUTATOR_HOOKFUNCTION(cts, FilterItem)
346 if(self.classname == "droppedweapon")
352 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
354 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
355 if(!autocvar_g_cts_selfdamage)
361 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
363 return true; // in CTS, you don't lose score by observing
366 MUTATOR_HOOKFUNCTION(cts, GetRecords)
368 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
370 if(MapInfo_Get_ByID(i))
372 float r = race_readTime(MapInfo_Map_bspname, 1);
377 string h = race_readName(MapInfo_Map_bspname, 1);
378 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
385 void ClientKill_Now();
386 MUTATOR_HOOKFUNCTION(cts, ClientKill)
391 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
393 remove(self.killindicator);
394 self.killindicator = world;
396 ClientKill_Now(); // allow instant kill in this case
402 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
404 if(autocvar_g_cts_finish_kill_delay)
405 CTS_ClientKill(race_player);
410 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
412 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
416 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
418 ret_float = (want_weaponinfo == WEP_SHOTGUN);
419 want_mutatorblocked = true;
423 void cts_Initialize()