1 void freezetag_Initialize()
3 precache_model("models/ice/ice.md3");
4 warmup = time + autocvar_g_start_delay + autocvar_g_freezetag_warmup;
5 ScoreRules_freezetag();
8 void freezetag_CheckWinner()
10 if(time <= game_starttime) // game didn't even start yet! nobody can win in that case.
13 if(next_round || (time > warmup - autocvar_g_freezetag_warmup && time < warmup))
14 return; // already waiting for next round to start
16 if((redalive >= 1 && bluealive >= 1)
17 || (redalive >= 1 && yellowalive >= 1)
18 || (redalive >= 1 && pinkalive >= 1)
19 || (bluealive >= 1 && yellowalive >= 1)
20 || (bluealive >= 1 && pinkalive >= 1)
21 || (yellowalive >= 1 && pinkalive >= 1))
22 return; // we still have active players on two or more teams, nobody won yet
29 if(e.frozen != 1 && e.health >= 1) // here's one player from the winning team... good
32 break; // break, we found the winner
36 if(winner != world) // just in case a winner wasn't found
38 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner.team, CENTER_FREEZETAG_ROUND_WIN_));
39 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner.team, INFO_FREEZETAG_ROUND_WIN_));
40 TeamScore_AddToTeam(winner.team, ST_SCORE, +1);
43 next_round = time + 5;
46 // this is needed to allow the player to turn his view around (fixangle can't
47 // be used to freeze his view, as that also changes the angles), while not
48 // turning that ice object with the player
49 void freezetag_Ice_Think()
51 setorigin(self, self.owner.origin - '0 0 16');
52 self.nextthink = time;
55 void freezetag_Freeze(entity attacker)
60 Freeze(self, 0, 1, TRUE);
64 // you froze your own dumb self
65 // counted as "suicide" already
66 PlayerScore_Add(self, SP_SCORE, -1);
68 else if(attacker.classname == "player")
70 // got frozen by an enemy
71 // counted as "kill" and "death" already
72 PlayerScore_Add(self, SP_SCORE, -1);
73 PlayerScore_Add(attacker, SP_SCORE, +1);
77 // nothing - got frozen by the game type rules themselves
86 void() havocbot_role_ft_freeing;
87 void() havocbot_role_ft_offense;
89 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
96 if ((head != self) && (head.team == self.team))
100 distance = vlen(head.origin - org);
101 if (distance > sradius)
103 navigation_routerating(head, ratingscale, 2000);
107 // If teamate is not frozen still seek them out as fight better
109 navigation_routerating(head, ratingscale/3, 2000);
115 void havocbot_role_ft_offense()
120 if(self.deadflag != DEAD_NO)
123 if (!self.havocbot_role_timeout)
124 self.havocbot_role_timeout = time + random() * 10 + 20;
126 // Count how many players on team are unfrozen.
128 FOR_EACH_PLAYER(head)
130 if ((head.team == self.team) && (head.frozen != 1))
134 // If only one left on team or if role has timed out then start trying to free players.
135 if (((unfrozen == 0) && (self.frozen != 1)) || (time > self.havocbot_role_timeout))
137 dprint("changing role to freeing\n");
138 self.havocbot_role = havocbot_role_ft_freeing;
139 self.havocbot_role_timeout = 0;
143 if (time > self.bot_strategytime)
145 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
147 navigation_goalrating_start();
148 havocbot_goalrating_items(10000, self.origin, 10000);
149 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
150 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
151 //havocbot_goalrating_waypoints(1, self.origin, 1000);
152 navigation_goalrating_end();
156 void havocbot_role_ft_freeing()
158 if(self.deadflag != DEAD_NO)
161 if (!self.havocbot_role_timeout)
162 self.havocbot_role_timeout = time + random() * 10 + 20;
164 if (time > self.havocbot_role_timeout)
166 dprint("changing role to offense\n");
167 self.havocbot_role = havocbot_role_ft_offense;
168 self.havocbot_role_timeout = 0;
172 if (time > self.bot_strategytime)
174 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
176 navigation_goalrating_start();
177 havocbot_goalrating_items(8000, self.origin, 10000);
178 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
179 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
180 //havocbot_goalrating_waypoints(1, self.origin, 1000);
181 navigation_goalrating_end();
190 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
192 if(self.frozen != 1 && self.health >= 1)
194 if(self.team == NUM_TEAM_1)
196 else if(self.team == NUM_TEAM_2)
198 else if(self.team == NUM_TEAM_3)
200 else if(self.team == NUM_TEAM_4)
205 if(total_players > 2) // only check for winners if we had more than two players (one of them left, don't let the other player win just because of that)
206 freezetag_CheckWinner();
213 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
217 if(self.team == NUM_TEAM_1)
219 else if(self.team == NUM_TEAM_2)
221 else if(self.team == NUM_TEAM_3)
223 else if(self.team == NUM_TEAM_4)
227 freezetag_Freeze(frag_attacker);
230 if(frag_attacker == frag_target || frag_attacker == world)
232 if(frag_target.classname == STR_PLAYER)
233 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
234 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
238 if(frag_target.classname == STR_PLAYER)
239 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
240 if(frag_attacker.classname == STR_PLAYER)
241 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
242 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
245 frag_target.health = 1; // "respawn" the player :P
247 freezetag_CheckWinner();
252 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
254 Unfreeze(self); // start by making sure that all ice blocks are removed
256 if(total_players == 1 && time > game_starttime) // only one player active on server, start a new match immediately
257 if(!next_round && warmup && (time < warmup - autocvar_g_freezetag_warmup || time > warmup)) // not awaiting next round
262 if(warmup && time > warmup) // spawn too late, freeze player
264 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
265 freezetag_Freeze(world);
271 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
273 frag_score = 0; // no frags counted in Freeze Tag
277 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
280 vector revive_extra_size;
282 revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
287 FOR_EACH_PLAYER(other) if(self != other)
289 if(other.frozen != 1)
291 if(other.team == self.team)
293 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
303 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
305 self.revive_progress = bound(0, self.revive_progress + frametime * autocvar_g_freezetag_revive_speed, 1);
306 self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
308 if(self.revive_progress >= 1)
312 // EVERY team mate nearby gets a point (even if multiple!)
313 FOR_EACH_PLAYER(other) if(self != other)
317 if(other.team == self.team)
319 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
321 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
322 PlayerScore_Add(other, SP_SCORE, +1);
328 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
329 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
330 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVE, self.netname, o.netname);
333 // now find EVERY teammate within reviving radius, set their revive_progress values correct
334 FOR_EACH_PLAYER(other) if(self != other)
338 if(other.team == self.team)
340 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
341 other.revive_progress = self.revive_progress;
346 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
348 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
349 self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
351 else if(!n && !self.frozen)
353 self.revive_progress = 0; // thawing nobody
359 MUTATOR_HOOKFUNCTION(freezetag_PlayerDamage_Calculate)
363 if(frag_target.frozen == 1 && frag_deathtype != DEATH_HURTTRIGGER)
366 frag_force = frag_force * autocvar_g_freezetag_frozen_force;
372 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
374 if not(self.deadflag)
377 self.havocbot_role = havocbot_role_ft_freeing;
379 self.havocbot_role = havocbot_role_ft_offense;
385 MUTATOR_DEFINITION(gamemode_freezetag)
387 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
388 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
389 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
390 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
391 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
392 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
393 MUTATOR_HOOK(PlayerDamage_Calculate, freezetag_PlayerDamage_Calculate, CBC_ORDER_ANY);
394 MUTATOR_HOOK(HavocBot_ChooseRule, freezetag_BotRoles, CBC_ORDER_ANY);
398 if(time > 1) // game loads at time 1
399 error("This is a game type and it cannot be added at runtime.");
400 freezetag_Initialize();
403 MUTATOR_ONROLLBACK_OR_REMOVE
405 // we actually cannot roll back freezetag_Initialize here
406 // BUT: we don't need to! If this gets called, adding always
412 print("This is a game type and it cannot be removed at runtime.");