1 #include "../../race.qh"
8 REGISTER_MUTATOR(cts, false)
12 if (time > 1) // game loads at time 1
13 error("This is a game type and it cannot be added at runtime.");
15 g_race_qualifying = true;
16 independent_players = 1;
17 SetLimits(0, 0, -1, -1);
22 MUTATOR_ONROLLBACK_OR_REMOVE
24 // we actually cannot roll back cts_Initialize here
25 // BUT: we don't need to! If this gets called, adding always
31 LOG_INFO("This is a game type and it cannot be removed at runtime.");
39 const float ST_CTS_LAPS = 1;
40 const float SP_CTS_LAPS = 4;
41 const float SP_CTS_TIME = 5;
42 const float SP_CTS_FASTEST = 6;
47 #include "../../race.qh"
49 float autocvar_g_cts_finish_kill_delay;
50 bool autocvar_g_cts_selfdamage;
53 .float race_checkpoint;
54 void havocbot_role_cts()
56 if(self.deadflag != DEAD_NO)
60 if (self.bot_strategytime < time)
62 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
63 navigation_goalrating_start();
65 for(e = world; (e = find(e, classname, "trigger_race_checkpoint")) != world; )
67 if(e.cnt == self.race_checkpoint)
69 navigation_routerating(e, 1000000, 5000);
71 else if(self.race_checkpoint == -1)
73 navigation_routerating(e, 1000000, 5000);
77 navigation_goalrating_end();
83 ScoreRules_basics(0, 0, 0, false);
86 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
90 ScoreInfo_SetLabel_PlayerScore(SP_CTS_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
91 ScoreInfo_SetLabel_PlayerScore(SP_CTS_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
92 ScoreInfo_SetLabel_PlayerScore(SP_CTS_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
94 ScoreRules_basics_end();
97 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
99 if(autocvar_sv_eventlog)
100 GameLogEcho(strcat(":cts:", mode, ":", ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
103 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
105 e.killindicator = spawn();
106 e.killindicator.owner = e;
107 e.killindicator.think = KillIndicator_Think;
108 e.killindicator.nextthink = time + (e.lip) * 0.05;
109 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
110 e.killindicator.health = 1; // this is used to indicate that it should be silent
114 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
116 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
117 float f = floor(self.race_movetime_frac);
118 self.race_movetime_frac -= f;
119 self.race_movetime_count += f;
120 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
125 if (self.race_penalty)
126 if (time > self.race_penalty)
127 self.race_penalty = 0;
128 if(self.race_penalty)
130 self.velocity = '0 0 0';
131 self.movetype = MOVETYPE_NONE;
132 self.disableclientprediction = 2;
137 // force kbd movement for fairness
141 // if record times matter
142 // ensure nothing EVIL is being done (i.e. div0_evade)
143 // this hinders joystick users though
144 // but it still gives SOME analog control
145 wishvel.x = fabs(self.movement.x);
146 wishvel.y = fabs(self.movement.y);
147 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
150 wishspeed = vlen(wishvel);
151 if(wishvel.x >= 2 * wishvel.y)
154 if(self.movement.x > 0)
155 self.movement_x = wishspeed;
157 self.movement_x = -wishspeed;
160 else if(wishvel.y >= 2 * wishvel.x)
164 if(self.movement.y > 0)
165 self.movement_y = wishspeed;
167 self.movement_y = -wishspeed;
172 if(self.movement.x > 0)
173 self.movement_x = M_SQRT1_2 * wishspeed;
175 self.movement_x = -M_SQRT1_2 * wishspeed;
176 if(self.movement.y > 0)
177 self.movement_y = M_SQRT1_2 * wishspeed;
179 self.movement_y = -M_SQRT1_2 * wishspeed;
186 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
190 Score_NicePrint(world);
193 PlayerScore_Sort(race_place, 0, 1, 0);
200 s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
204 cts_EventLog(ftos(e.race_place), e);
207 if(g_race_qualifying == 2)
209 g_race_qualifying = 0;
210 independent_players = 0;
211 cvar_set("fraglimit", ftos(race_fraglimit));
212 cvar_set("leadlimit", ftos(race_leadlimit));
213 cvar_set("timelimit", ftos(race_timelimit));
220 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
222 race_PreparePlayer();
223 self.race_checkpoint = -1;
225 if(IS_REAL_CLIENT(self))
227 string rr = CTS_RECORD;
230 race_send_recordtime(MSG_ONE);
231 race_send_speedaward(MSG_ONE);
233 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
234 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
235 race_send_speedaward_alltimebest(MSG_ONE);
238 for (i = 1; i <= RANKINGS_CNT; ++i)
240 race_SendRankings(i, 0, 0, MSG_ONE);
247 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
249 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
250 self.frags = FRAGS_LMS_LOSER;
252 self.frags = FRAGS_SPECTATOR;
254 race_PreparePlayer();
255 self.race_checkpoint = -1;
260 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
262 if(spawn_spot.target == "")
263 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
264 race_PreparePlayer();
266 // if we need to respawn, do it right
267 self.race_respawn_checkpoint = self.race_checkpoint;
268 self.race_respawn_spotref = spawn_spot;
275 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
280 if(self.killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
281 race_PreparePlayer();
283 race_RetractPlayer();
285 race_AbandonRaceCheck(self);
290 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
292 self.respawn_flags |= RESPAWN_FORCE;
293 race_AbandonRaceCheck(self);
297 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
299 self.havocbot_role = havocbot_role_cts;
303 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
305 if(self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
307 if (!self.stored_netname)
308 self.stored_netname = strzone(uid2name(self.crypto_idfp));
309 if(self.stored_netname != self.netname)
311 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
312 strunzone(self.stored_netname);
313 self.stored_netname = strzone(self.netname);
317 if (!IS_OBSERVER(self))
319 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
321 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
322 speedaward_holder = self.netname;
323 speedaward_uid = self.crypto_idfp;
324 speedaward_lastupdate = time;
326 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
328 string rr = CTS_RECORD;
329 race_send_speedaward(MSG_ALL);
330 speedaward_lastsent = speedaward_speed;
331 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
333 speedaward_alltimebest = speedaward_speed;
334 speedaward_alltimebest_holder = speedaward_holder;
335 speedaward_alltimebest_uid = speedaward_uid;
336 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
337 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
338 race_send_speedaward_alltimebest(MSG_ALL);
346 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
348 // no weapon dropping in CTS
352 MUTATOR_HOOKFUNCTION(cts, FilterItem)
354 if(self.classname == "droppedweapon")
360 MUTATOR_HOOKFUNCTION(cts, PlayerDamage_Calculate)
362 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
363 if(!autocvar_g_cts_selfdamage)
369 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
371 return true; // in CTS, you don't lose score by observing
374 MUTATOR_HOOKFUNCTION(cts, GetRecords)
376 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
378 if(MapInfo_Get_ByID(i))
380 float r = race_readTime(MapInfo_Map_bspname, 1);
385 string h = race_readName(MapInfo_Map_bspname, 1);
386 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
393 MUTATOR_HOOKFUNCTION(cts, ClientKill)
397 if(self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
399 remove(self.killindicator);
400 self.killindicator = world;
402 ClientKill_Now(); // allow instant kill in this case
408 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
410 if(autocvar_g_cts_finish_kill_delay)
411 CTS_ClientKill(race_player);
416 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
418 stuffcmd(fix_client, "cl_cmd settemp cl_movecliptokeyboard 2\n");
422 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
424 ret_float = (want_weaponinfo.weapon == WEP_SHOTGUN.m_id);
425 want_mutatorblocked = true;
429 void cts_Initialize()