1 #include "gamemode_cts.qh"
3 #include <server/race.qh>
4 #include <server/items.qh>
6 float autocvar_g_cts_finish_kill_delay;
7 bool autocvar_g_cts_selfdamage;
10 .float race_checkpoint;
11 void havocbot_role_cts(entity this)
16 if (this.bot_strategytime < time)
18 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
19 navigation_goalrating_start(this);
21 bool raw_touch_check = true;
22 int cp = this.race_checkpoint;
24 LABEL(search_racecheckpoints)
25 IL_EACH(g_racecheckpoints, true,
27 if(it.cnt == cp || cp == -1)
29 // redirect bot to next goal if it touched the waypoint of an untouchable checkpoint
30 // e.g. checkpoint in front of Stormkeep's warpzone
31 // the same workaround is applied in Race game mode
32 if (raw_touch_check && vdist(this.origin - it.nearestwaypoint.origin, <, 30))
34 cp = race_NextCheckpoint(cp);
35 raw_touch_check = false;
36 goto search_racecheckpoints;
38 navigation_routerating(this, it, 1000000, 5000);
42 navigation_goalrating_end(this);
48 GameRules_score_enabled(false);
49 GameRules_scoring(0, 0, 0, {
50 if (g_race_qualifying) {
51 field(SP_RACE_FASTEST, "fastest", SFL_SORT_PRIO_PRIMARY | SFL_LOWER_IS_BETTER | SFL_TIME);
53 field(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
54 field(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
55 field(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
60 void cts_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
62 if(autocvar_sv_eventlog)
63 GameLogEcho(strcat(":cts:", mode, ":", ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : "")));
66 void KillIndicator_Think(entity this);
67 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
69 e.killindicator = spawn();
70 e.killindicator.owner = e;
71 setthink(e.killindicator, KillIndicator_Think);
72 e.killindicator.nextthink = time + (e.lip) * 0.05;
73 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
74 e.killindicator.health = 1; // this is used to indicate that it should be silent
78 MUTATOR_HOOKFUNCTION(cts, PlayerPhysics)
80 entity player = M_ARGV(0, entity);
81 float dt = M_ARGV(1, float);
83 player.race_movetime_frac += dt;
84 float f = floor(player.race_movetime_frac);
85 player.race_movetime_frac -= f;
86 player.race_movetime_count += f;
87 player.race_movetime = player.race_movetime_frac + player.race_movetime_count;
92 if (player.race_penalty)
93 if (time > player.race_penalty)
94 player.race_penalty = 0;
95 if(player.race_penalty)
97 player.velocity = '0 0 0';
98 set_movetype(player, MOVETYPE_NONE);
99 player.disableclientprediction = 2;
104 // force kbd movement for fairness
108 // if record times matter
109 // ensure nothing EVIL is being done (i.e. div0_evade)
110 // this hinders joystick users though
111 // but it still gives SOME analog control
112 wishvel.x = fabs(CS(player).movement.x);
113 wishvel.y = fabs(CS(player).movement.y);
114 if(wishvel.x != 0 && wishvel.y != 0 && wishvel.x != wishvel.y)
117 wishspeed = vlen(wishvel);
118 if(wishvel.x >= 2 * wishvel.y)
121 if(CS(player).movement.x > 0)
122 CS(player).movement_x = wishspeed;
124 CS(player).movement_x = -wishspeed;
125 CS(player).movement_y = 0;
127 else if(wishvel.y >= 2 * wishvel.x)
130 CS(player).movement_x = 0;
131 if(CS(player).movement.y > 0)
132 CS(player).movement_y = wishspeed;
134 CS(player).movement_y = -wishspeed;
139 if(CS(player).movement.x > 0)
140 CS(player).movement_x = M_SQRT1_2 * wishspeed;
142 CS(player).movement_x = -M_SQRT1_2 * wishspeed;
143 if(CS(player).movement.y > 0)
144 CS(player).movement_y = M_SQRT1_2 * wishspeed;
146 CS(player).movement_y = -M_SQRT1_2 * wishspeed;
151 MUTATOR_HOOKFUNCTION(cts, reset_map_global)
155 Score_NicePrint(NULL);
158 PlayerScore_Sort(race_place, 0, 1, 0);
160 FOREACH_CLIENT(true, {
163 s = GameRules_scoring_add(it, RACE_FASTEST, 0);
167 cts_EventLog(ftos(it.race_place), it);
170 if(g_race_qualifying == 2)
172 g_race_qualifying = 0;
173 independent_players = 0;
174 cvar_set("fraglimit", ftos(race_fraglimit));
175 cvar_set("leadlimit", ftos(race_leadlimit));
176 cvar_set("timelimit", ftos(race_timelimit));
181 MUTATOR_HOOKFUNCTION(cts, ClientConnect)
183 entity player = M_ARGV(0, entity);
185 race_PreparePlayer(player);
186 player.race_checkpoint = -1;
188 if(IS_REAL_CLIENT(player))
190 string rr = CTS_RECORD;
193 race_send_recordtime(MSG_ONE);
194 race_send_speedaward(MSG_ONE);
196 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
197 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
198 race_send_speedaward_alltimebest(MSG_ONE);
201 for (i = 1; i <= RANKINGS_CNT; ++i)
203 race_SendRankings(i, 0, 0, MSG_ONE);
208 MUTATOR_HOOKFUNCTION(cts, AbortSpeedrun)
210 entity player = M_ARGV(0, entity);
212 if(autocvar_g_allow_checkpoints)
213 race_PreparePlayer(player); // nice try
216 MUTATOR_HOOKFUNCTION(cts, MakePlayerObserver)
218 entity player = M_ARGV(0, entity);
220 if(GameRules_scoring_add(player, RACE_FASTEST, 0))
221 player.frags = FRAGS_LMS_LOSER;
223 player.frags = FRAGS_SPECTATOR;
225 race_PreparePlayer(player);
226 player.race_checkpoint = -1;
229 MUTATOR_HOOKFUNCTION(cts, PlayerSpawn)
231 entity player = M_ARGV(0, entity);
232 entity spawn_spot = M_ARGV(1, entity);
234 if(spawn_spot.target == "")
235 // Emergency: this wasn't a real spawnpoint. Can this ever happen?
236 race_PreparePlayer(player);
238 // if we need to respawn, do it right
239 player.race_respawn_checkpoint = player.race_checkpoint;
240 player.race_respawn_spotref = spawn_spot;
242 player.race_place = 0;
245 MUTATOR_HOOKFUNCTION(cts, PutClientInServer)
247 entity player = M_ARGV(0, entity);
249 if(IS_PLAYER(player))
252 if(CS(player).killcount == FRAGS_SPECTATOR /* initial spawn */ || g_race_qualifying) // spawn
253 race_PreparePlayer(player);
255 race_RetractPlayer(player);
257 race_AbandonRaceCheck(player);
261 MUTATOR_HOOKFUNCTION(cts, PlayerDies)
263 entity frag_target = M_ARGV(2, entity);
265 frag_target.respawn_flags |= RESPAWN_FORCE;
266 race_AbandonRaceCheck(frag_target);
269 MUTATOR_HOOKFUNCTION(cts, HavocBot_ChooseRole)
271 entity bot = M_ARGV(0, entity);
273 bot.havocbot_role = havocbot_role_cts;
277 MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
279 entity player = M_ARGV(0, entity);
281 if(CS(player).cvar_cl_allow_uidtracking == 1 && CS(player).cvar_cl_allow_uid2name == 1)
283 if (!player.stored_netname)
284 player.stored_netname = strzone(uid2name(player.crypto_idfp));
285 if(player.stored_netname != player.netname)
287 db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname);
288 strunzone(player.stored_netname);
289 player.stored_netname = strzone(player.netname);
293 if (!IS_OBSERVER(player))
295 if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed))
297 speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1');
298 speedaward_holder = player.netname;
299 speedaward_uid = player.crypto_idfp;
300 speedaward_lastupdate = time;
302 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
304 string rr = CTS_RECORD;
305 race_send_speedaward(MSG_ALL);
306 speedaward_lastsent = speedaward_speed;
307 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
309 speedaward_alltimebest = speedaward_speed;
310 speedaward_alltimebest_holder = speedaward_holder;
311 speedaward_alltimebest_uid = speedaward_uid;
312 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
313 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
314 race_send_speedaward_alltimebest(MSG_ALL);
320 MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon)
322 // no weapon dropping in CTS
326 MUTATOR_HOOKFUNCTION(cts, FilterItem)
328 entity item = M_ARGV(0, entity);
330 if (Item_IsLoot(item))
336 MUTATOR_HOOKFUNCTION(cts, Damage_Calculate)
338 entity frag_attacker = M_ARGV(1, entity);
339 entity frag_target = M_ARGV(2, entity);
340 float frag_deathtype = M_ARGV(3, float);
341 float frag_damage = M_ARGV(4, float);
343 if(frag_target == frag_attacker || frag_deathtype == DEATH_FALL.m_id)
344 if(!autocvar_g_cts_selfdamage)
347 M_ARGV(4, float) = frag_damage;
351 MUTATOR_HOOKFUNCTION(cts, ForbidPlayerScore_Clear)
353 return true; // in CTS, you don't lose score by observing
356 MUTATOR_HOOKFUNCTION(cts, GetRecords)
358 int record_page = M_ARGV(0, int);
359 string ret_string = M_ARGV(1, string);
361 for(int i = record_page * 200; i < MapInfo_count && i < record_page * 200 + 200; ++i)
363 if(MapInfo_Get_ByID(i))
365 float r = race_readTime(MapInfo_Map_bspname, 1);
370 string h = race_readName(MapInfo_Map_bspname, 1);
371 ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
375 M_ARGV(1, string) = ret_string;
378 void ClientKill_Now(entity this);
379 MUTATOR_HOOKFUNCTION(cts, ClientKill)
381 entity player = M_ARGV(0, entity);
383 M_ARGV(1, float) = 0; // kill delay
385 if(player.killindicator && player.killindicator.health == 1) // player.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
387 delete(player.killindicator);
388 player.killindicator = NULL;
390 ClientKill_Now(player); // allow instant kill in this case
395 MUTATOR_HOOKFUNCTION(cts, Race_FinalCheckpoint)
397 entity player = M_ARGV(0, entity);
399 if(autocvar_g_cts_finish_kill_delay)
400 CTS_ClientKill(player);
403 MUTATOR_HOOKFUNCTION(cts, HideTeamNagger)
405 return true; // doesn't work so well (but isn't cts a teamless mode?)
408 MUTATOR_HOOKFUNCTION(cts, FixClientCvars)
410 entity player = M_ARGV(0, entity);
412 stuffcmd(player, "cl_cmd settemp cl_movecliptokeyboard 2\n");
415 MUTATOR_HOOKFUNCTION(cts, WantWeapon)
417 M_ARGV(1, float) = (M_ARGV(0, entity) == WEP_SHOTGUN); // want weapon = weapon info
418 M_ARGV(3, bool) = true; // want mutator blocked
422 MUTATOR_HOOKFUNCTION(cts, ForbidDropCurrentWeapon)
427 void cts_Initialize()