1 #include "gamemode_keepaway.qh"
5 int autocvar_g_keepaway_ballcarrier_effects;
6 float autocvar_g_keepaway_ballcarrier_damage;
7 float autocvar_g_keepaway_ballcarrier_force;
8 float autocvar_g_keepaway_ballcarrier_highspeed;
9 float autocvar_g_keepaway_ballcarrier_selfdamage;
10 float autocvar_g_keepaway_ballcarrier_selfforce;
11 float autocvar_g_keepaway_noncarrier_damage;
12 float autocvar_g_keepaway_noncarrier_force;
13 float autocvar_g_keepaway_noncarrier_selfdamage;
14 float autocvar_g_keepaway_noncarrier_selfforce;
15 bool autocvar_g_keepaway_noncarrier_warn;
16 int autocvar_g_keepaway_score_bckill;
17 int autocvar_g_keepaway_score_killac;
18 int autocvar_g_keepaway_score_timepoints;
19 float autocvar_g_keepaway_score_timeinterval;
20 float autocvar_g_keepawayball_damageforcescale;
21 int autocvar_g_keepawayball_effects;
22 float autocvar_g_keepawayball_respawntime;
23 int autocvar_g_keepawayball_trail_color;
25 float ka_ballcarrier_waypointsprite_visible_for_player(entity e) // runs on waypoints which are attached to ballcarriers, updates once per frame
29 return false; // we don't want spectators of the ballcarrier to see the attached waypoint on the top of their screen
31 // TODO: Make the ballcarrier lack a waypointsprite whenever they have the invisibility powerup
36 void ka_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
38 if(autocvar_sv_eventlog)
39 GameLogEcho(strcat(":ka:", mode, ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
43 void ka_RespawnBall() // runs whenever the ball needs to be relocated
45 if(gameover) { return; }
46 vector oldballorigin = self.origin;
48 if(!MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
50 entity spot = SelectSpawnPoint(true);
51 setorigin(self, spot.origin);
52 self.angles = spot.angles;
55 makevectors(self.angles);
56 self.movetype = MOVETYPE_BOUNCE;
57 self.velocity = '0 0 200';
58 self.angles = '0 0 0';
59 self.effects = autocvar_g_keepawayball_effects;
60 self.touch = ka_TouchEvent;
61 self.think = ka_RespawnBall;
62 self.nextthink = time + autocvar_g_keepawayball_respawntime;
64 Send_Effect(EFFECT_ELECTRO_COMBO, oldballorigin, '0 0 0', 1);
65 Send_Effect(EFFECT_ELECTRO_COMBO, self.origin, '0 0 0', 1);
67 WaypointSprite_Spawn(WP_KaBall, 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER);
68 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
70 sound(self, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
75 if(self.owner.ballcarried)
76 { // add points for holding the ball after a certain amount of time
77 if(autocvar_g_keepaway_score_timepoints)
78 PlayerScore_Add(self.owner, SP_SCORE, autocvar_g_keepaway_score_timepoints);
80 PlayerScore_Add(self.owner, SP_KEEPAWAY_BCTIME, (autocvar_g_keepaway_score_timeinterval / 1)); // interval is divided by 1 so that time always shows "seconds"
81 self.nextthink = time + autocvar_g_keepaway_score_timeinterval;
85 void ka_TouchEvent() // runs any time that the ball comes in contact with something
87 if(gameover) { return; }
89 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
90 { // The ball fell off the map, respawn it since players can't get to it
94 if(other.deadflag != DEAD_NO) { return; }
95 if(other.frozen) { return; }
96 if (!IS_PLAYER(other))
97 { // The ball just touched an object, most likely the world
98 Send_Effect(EFFECT_BALL_SPARKS, self.origin, '0 0 0', 1);
99 sound(self, CH_TRIGGER, SND_KA_TOUCH, VOL_BASE, ATTEN_NORM);
102 else if(self.wait > time) { return; }
104 // attach the ball to the player
106 other.ballcarried = self;
107 setattachment(self, other, "");
108 setorigin(self, '0 0 0');
110 // make the ball invisible/unable to do anything/set up time scoring
111 self.velocity = '0 0 0';
112 self.movetype = MOVETYPE_NONE;
113 self.effects |= EF_NODRAW;
114 self.touch = func_null;
115 self.think = ka_TimeScoring;
116 self.nextthink = time + autocvar_g_keepaway_score_timeinterval;
117 self.takedamage = DAMAGE_NO;
119 // apply effects to player
120 other.glow_color = autocvar_g_keepawayball_trail_color;
121 other.glow_trail = true;
122 other.effects |= autocvar_g_keepaway_ballcarrier_effects;
124 // messages and sounds
125 ka_EventLog("pickup", other);
126 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_KEEPAWAY_PICKUP, other.netname);
127 Send_Notification(NOTIF_ALL_EXCEPT, other, MSG_CENTER, CENTER_KEEPAWAY_PICKUP, other.netname);
128 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_KEEPAWAY_PICKUP_SELF);
129 sound(self.owner, CH_TRIGGER, SND_KA_PICKEDUP, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
132 PlayerScore_Add(other, SP_KEEPAWAY_PICKUPS, 1);
135 WaypointSprite_AttachCarrier(WP_KaBallCarrier, other, RADARICON_FLAGCARRIER);
136 other.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = ka_ballcarrier_waypointsprite_visible_for_player;
137 WaypointSprite_UpdateRule(other.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
138 WaypointSprite_Ping(other.waypointsprite_attachedforcarrier);
139 WaypointSprite_Kill(self.waypointsprite_attachedforcarrier);
142 void ka_DropEvent(entity plyr) // runs any time that a player is supposed to lose the ball
145 ball = plyr.ballcarried;
147 if(!ball) { return; }
150 setattachment(ball, world, "");
151 ball.movetype = MOVETYPE_BOUNCE;
152 ball.wait = time + 1;
153 ball.touch = ka_TouchEvent;
154 ball.think = ka_RespawnBall;
155 ball.nextthink = time + autocvar_g_keepawayball_respawntime;
156 ball.takedamage = DAMAGE_YES;
157 ball.effects &= ~EF_NODRAW;
158 setorigin(ball, plyr.origin + '0 0 10');
159 ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
160 ball.owner.ballcarried = world; // I hope nothing checks to see if the world has the ball in the rest of my code :P
163 // reset the player effects
164 plyr.glow_trail = false;
165 plyr.effects &= ~autocvar_g_keepaway_ballcarrier_effects;
167 // messages and sounds
168 ka_EventLog("dropped", plyr);
169 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_KEEPAWAY_DROPPED, plyr.netname);
170 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEEPAWAY_DROPPED, plyr.netname);
171 sound(other, CH_TRIGGER, SND_KA_DROPPED, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
174 // PlayerScore_Add(plyr, SP_KEEPAWAY_DROPS, 1); Not anymore, this is 100% the same as pickups and is useless.
177 WaypointSprite_Spawn(WP_KaBall, 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER);
178 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
179 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
180 WaypointSprite_Kill(plyr.waypointsprite_attachedforcarrier);
183 void ka_Reset() // used to clear the ballcarrier whenever the match switches from warmup to normal
185 if((self.owner) && (IS_PLAYER(self.owner)))
186 ka_DropEvent(self.owner);
188 if(time < game_starttime)
190 self.think = ka_RespawnBall;
191 self.touch = func_null;
192 self.nextthink = game_starttime;
203 void havocbot_goalrating_ball(float ratingscale, vector org)
207 ball_owner = ka_ball.owner;
209 if (ball_owner == self)
212 // If ball is carried by player then hunt them down.
215 t = (self.health + self.armorvalue) / (ball_owner.health + ball_owner.armorvalue);
216 navigation_routerating(ball_owner, t * ratingscale, 2000);
218 else // Ball has been dropped so collect.
219 navigation_routerating(ka_ball, ratingscale, 2000);
222 void havocbot_role_ka_carrier()
224 if (self.deadflag != DEAD_NO)
227 if (time > self.bot_strategytime)
229 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
231 navigation_goalrating_start();
232 havocbot_goalrating_items(10000, self.origin, 10000);
233 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
234 //havocbot_goalrating_waypoints(1, self.origin, 1000);
235 navigation_goalrating_end();
238 if (!self.ballcarried)
240 self.havocbot_role = havocbot_role_ka_collector;
241 self.bot_strategytime = 0;
245 void havocbot_role_ka_collector()
247 if (self.deadflag != DEAD_NO)
250 if (time > self.bot_strategytime)
252 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
254 navigation_goalrating_start();
255 havocbot_goalrating_items(10000, self.origin, 10000);
256 havocbot_goalrating_enemyplayers(1000, self.origin, 10000);
257 havocbot_goalrating_ball(20000, self.origin);
258 navigation_goalrating_end();
261 if (self.ballcarried)
263 self.havocbot_role = havocbot_role_ka_carrier;
264 self.bot_strategytime = 0;
273 MUTATOR_HOOKFUNCTION(ka, PlayerDies)
275 if((frag_attacker != frag_target) && (IS_PLAYER(frag_attacker)))
277 if(frag_target.ballcarried) { // add to amount of times killing carrier
278 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_CARRIERKILLS, 1);
279 if(autocvar_g_keepaway_score_bckill) // add bckills to the score
280 PlayerScore_Add(frag_attacker, SP_SCORE, autocvar_g_keepaway_score_bckill);
282 else if(!frag_attacker.ballcarried)
283 if(autocvar_g_keepaway_noncarrier_warn)
284 Send_Notification(NOTIF_ONE_ONLY, frag_attacker, MSG_CENTER, CENTER_KEEPAWAY_WARN);
286 if(frag_attacker.ballcarried) // add to amount of kills while ballcarrier
287 PlayerScore_Add(frag_attacker, SP_SCORE, autocvar_g_keepaway_score_killac);
290 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has died, drop it
294 MUTATOR_HOOKFUNCTION(ka, GiveFragsForKill)
296 frag_score = 0; // no frags counted in keepaway
297 return 1; // you deceptive little bugger ;3 This needs to be true in order for this function to even count.
300 MUTATOR_HOOKFUNCTION(ka, PlayerPreThink)
302 // clear the item used for the ball in keepaway
303 self.items &= ~IT_KEY1;
305 // if the player has the ball, make sure they have the item for it (Used for HUD primarily)
307 self.items |= IT_KEY1;
312 MUTATOR_HOOKFUNCTION(ka, PlayerUseKey)
314 if(MUTATOR_RETURNVALUE == 0)
323 MUTATOR_HOOKFUNCTION(ka, PlayerDamage_Calculate) // for changing damage and force values that are applied to players in g_damage.qc
325 if(frag_attacker.ballcarried) // if the attacker is a ballcarrier
327 if(frag_target == frag_attacker) // damage done to yourself
329 frag_damage *= autocvar_g_keepaway_ballcarrier_selfdamage;
330 frag_force *= autocvar_g_keepaway_ballcarrier_selfforce;
332 else // damage done to noncarriers
334 frag_damage *= autocvar_g_keepaway_ballcarrier_damage;
335 frag_force *= autocvar_g_keepaway_ballcarrier_force;
338 else if (!frag_target.ballcarried) // if the target is a noncarrier
340 if(frag_target == frag_attacker) // damage done to yourself
342 frag_damage *= autocvar_g_keepaway_noncarrier_selfdamage;
343 frag_force *= autocvar_g_keepaway_noncarrier_selfforce;
345 else // damage done to other noncarriers
347 frag_damage *= autocvar_g_keepaway_noncarrier_damage;
348 frag_force *= autocvar_g_keepaway_noncarrier_force;
354 MUTATOR_HOOKFUNCTION(ka, ClientDisconnect)
356 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has left the match, drop it
360 MUTATOR_HOOKFUNCTION(ka, MakePlayerObserver)
362 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has left the match, drop it
366 MUTATOR_HOOKFUNCTION(ka, PlayerPowerups)
368 // In the future this hook is supposed to allow me to do some extra stuff with waypointsprites and invisibility powerup
369 // So bare with me until I can fix a certain bug with ka_ballcarrier_waypointsprite_visible_for_player()
371 self.effects &= ~autocvar_g_keepaway_ballcarrier_effects;
374 self.effects |= autocvar_g_keepaway_ballcarrier_effects;
379 .float stat_sv_airspeedlimit_nonqw;
380 .float stat_sv_maxspeed;
382 MUTATOR_HOOKFUNCTION(ka, PlayerPhysics)
386 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_keepaway_ballcarrier_highspeed;
387 self.stat_sv_maxspeed *= autocvar_g_keepaway_ballcarrier_highspeed;
392 MUTATOR_HOOKFUNCTION(ka, BotShouldAttack)
394 // if neither player has ball then don't attack unless the ball is on the ground
395 if(!checkentity.ballcarried && !self.ballcarried && ka_ball.owner)
400 MUTATOR_HOOKFUNCTION(ka, HavocBot_ChooseRole)
402 if (self.ballcarried)
403 self.havocbot_role = havocbot_role_ka_carrier;
405 self.havocbot_role = havocbot_role_ka_collector;
414 void ka_SpawnBall() // loads various values for the ball, runs only once at start of match
416 if(!g_keepaway) { return; }
420 e.model = "models/orbs/orbblue.md3";
421 precache_model(e.model);
422 _setmodel(e, e.model);
423 setsize(e, '-16 -16 -20', '16 16 20'); // 20 20 20 was too big, player is only 16 16 24... gotta cheat with the Z (20) axis so that the particle isn't cut off
424 e.classname = "keepawayball";
425 e.damageforcescale = autocvar_g_keepawayball_damageforcescale;
426 e.takedamage = DAMAGE_YES;
427 e.solid = SOLID_TRIGGER;
428 e.movetype = MOVETYPE_BOUNCE;
429 e.glow_color = autocvar_g_keepawayball_trail_color;
433 e.touch = ka_TouchEvent;
437 InitializeEntity(e, ka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So.
442 ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY, 0, true); // SFL_SORT_PRIO_PRIMARY
443 ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_PICKUPS, "pickups", 0);
444 ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0);
445 ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY);
446 ScoreRules_basics_end();
449 void ka_Initialize() // run at the start of a match, initiates game mode
459 REGISTER_MUTATOR(ka, g_keepaway)
463 if(time > 1) // game loads at time 1
464 error("This is a game type and it cannot be added at runtime.");
468 MUTATOR_ONROLLBACK_OR_REMOVE
470 // we actually cannot roll back ka_Initialize here
471 // BUT: we don't need to! If this gets called, adding always
477 LOG_INFO("This is a game type and it cannot be removed at runtime.");