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)
65 WaypointSprite_Spawn("freezetag_frozen", 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attached, TRUE, RADARICON_WAYPOINT, '0.25 0.90 1');
69 // you froze your own dumb self
70 // counted as "suicide" already
71 PlayerScore_Add(self, SP_SCORE, -1);
73 else if(attacker.classname == "player")
75 // got frozen by an enemy
76 // counted as "kill" and "death" already
77 PlayerScore_Add(self, SP_SCORE, -1);
78 PlayerScore_Add(attacker, SP_SCORE, +1);
82 // nothing - got frozen by the game type rules themselves
86 void freezetag_Unfreeze(entity attacker)
91 if(self.waypointsprite_attached)
92 WaypointSprite_Kill(self.waypointsprite_attached);
100 void() havocbot_role_ft_freeing;
101 void() havocbot_role_ft_offense;
103 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
108 FOR_EACH_PLAYER(head)
110 if ((head != self) && (head.team == self.team))
112 if (head.frozen == 1)
114 distance = vlen(head.origin - org);
115 if (distance > sradius)
117 navigation_routerating(head, ratingscale, 2000);
121 // If teamate is not frozen still seek them out as fight better
123 navigation_routerating(head, ratingscale/3, 2000);
129 void havocbot_role_ft_offense()
134 if(self.deadflag != DEAD_NO)
137 if (!self.havocbot_role_timeout)
138 self.havocbot_role_timeout = time + random() * 10 + 20;
140 // Count how many players on team are unfrozen.
142 FOR_EACH_PLAYER(head)
144 if ((head.team == self.team) && (head.frozen != 1))
148 // If only one left on team or if role has timed out then start trying to free players.
149 if (((unfrozen == 0) && (self.frozen != 1)) || (time > self.havocbot_role_timeout))
151 dprint("changing role to freeing\n");
152 self.havocbot_role = havocbot_role_ft_freeing;
153 self.havocbot_role_timeout = 0;
157 if (time > self.bot_strategytime)
159 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
161 navigation_goalrating_start();
162 havocbot_goalrating_items(10000, self.origin, 10000);
163 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
164 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
165 //havocbot_goalrating_waypoints(1, self.origin, 1000);
166 navigation_goalrating_end();
170 void havocbot_role_ft_freeing()
172 if(self.deadflag != DEAD_NO)
175 if (!self.havocbot_role_timeout)
176 self.havocbot_role_timeout = time + random() * 10 + 20;
178 if (time > self.havocbot_role_timeout)
180 dprint("changing role to offense\n");
181 self.havocbot_role = havocbot_role_ft_offense;
182 self.havocbot_role_timeout = 0;
186 if (time > self.bot_strategytime)
188 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
190 navigation_goalrating_start();
191 havocbot_goalrating_items(8000, self.origin, 10000);
192 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
193 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
194 //havocbot_goalrating_waypoints(1, self.origin, 1000);
195 navigation_goalrating_end();
204 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
206 if(self.frozen != 1 && self.health >= 1)
208 if(self.team == NUM_TEAM_1)
210 else if(self.team == NUM_TEAM_2)
212 else if(self.team == NUM_TEAM_3)
214 else if(self.team == NUM_TEAM_4)
219 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)
220 freezetag_CheckWinner();
222 freezetag_Unfreeze(world);
227 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
231 if(self.team == NUM_TEAM_1)
233 else if(self.team == NUM_TEAM_2)
235 else if(self.team == NUM_TEAM_3)
237 else if(self.team == NUM_TEAM_4)
241 freezetag_Freeze(frag_attacker);
244 if(frag_attacker == frag_target || frag_attacker == world)
246 if(frag_target.classname == STR_PLAYER)
247 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
248 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
252 if(frag_target.classname == STR_PLAYER)
253 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
254 if(frag_attacker.classname == STR_PLAYER)
255 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
256 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
259 frag_target.health = 1; // "respawn" the player :P
261 freezetag_CheckWinner();
266 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
268 freezetag_Unfreeze(world); // start by making sure that all ice blocks are removed
270 if(total_players == 1 && time > game_starttime) // only one player active on server, start a new match immediately
271 if(!next_round && warmup && (time < warmup - autocvar_g_freezetag_warmup || time > warmup)) // not awaiting next round
276 if(warmup && time > warmup) // spawn too late, freeze player
278 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
279 freezetag_Freeze(world);
285 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
287 frag_score = 0; // no frags counted in Freeze Tag
291 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
294 vector revive_extra_size;
296 revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
301 FOR_EACH_PLAYER(other) if(self != other)
303 if(other.frozen != 1)
305 if(other.team == self.team)
307 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
317 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
319 self.revive_progress = bound(0, self.revive_progress + frametime * autocvar_g_freezetag_revive_speed, 1);
320 self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
322 if(self.revive_progress >= 1)
324 freezetag_Unfreeze(self);
326 // EVERY team mate nearby gets a point (even if multiple!)
327 FOR_EACH_PLAYER(other) if(self != other)
331 if(other.team == self.team)
333 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
335 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
336 PlayerScore_Add(other, SP_SCORE, +1);
342 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
343 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
344 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVE, self.netname, o.netname);
347 // now find EVERY teammate within reviving radius, set their revive_progress values correct
348 FOR_EACH_PLAYER(other) if(self != other)
352 if(other.team == self.team)
354 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
355 other.revive_progress = self.revive_progress;
360 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
362 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
363 self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
365 else if(!n && !self.frozen)
367 self.revive_progress = 0; // thawing nobody
373 MUTATOR_HOOKFUNCTION(freezetag_PlayerDamage_Calculate)
377 if(frag_target.frozen == 1 && frag_deathtype != DEATH_HURTTRIGGER)
380 frag_force = frag_force * autocvar_g_freezetag_frozen_force;
386 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
388 if not(self.deadflag)
391 self.havocbot_role = havocbot_role_ft_freeing;
393 self.havocbot_role = havocbot_role_ft_offense;
399 MUTATOR_DEFINITION(gamemode_freezetag)
401 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
402 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
403 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
404 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
405 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
406 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
407 MUTATOR_HOOK(PlayerDamage_Calculate, freezetag_PlayerDamage_Calculate, CBC_ORDER_ANY);
408 MUTATOR_HOOK(HavocBot_ChooseRule, freezetag_BotRoles, CBC_ORDER_ANY);
412 if(time > 1) // game loads at time 1
413 error("This is a game type and it cannot be added at runtime.");
414 freezetag_Initialize();
417 MUTATOR_ONROLLBACK_OR_REMOVE
419 // we actually cannot roll back freezetag_Initialize here
420 // BUT: we don't need to! If this gets called, adding always
426 print("This is a game type and it cannot be removed at runtime.");