1 #ifndef GAMEMODE_KEEPAWAY_H
2 #define GAMEMODE_KEEPAWAY_H
7 const float SP_KEEPAWAY_PICKUPS = 4;
8 const float SP_KEEPAWAY_CARRIERKILLS = 5;
9 const float SP_KEEPAWAY_BCTIME = 6;
11 void() havocbot_role_ka_carrier;
12 void() havocbot_role_ka_collector;
14 void ka_DropEvent(entity plyr);
19 int autocvar_g_keepaway_ballcarrier_effects;
20 float autocvar_g_keepaway_ballcarrier_damage;
21 float autocvar_g_keepaway_ballcarrier_force;
22 float autocvar_g_keepaway_ballcarrier_highspeed;
23 float autocvar_g_keepaway_ballcarrier_selfdamage;
24 float autocvar_g_keepaway_ballcarrier_selfforce;
25 float autocvar_g_keepaway_noncarrier_damage;
26 float autocvar_g_keepaway_noncarrier_force;
27 float autocvar_g_keepaway_noncarrier_selfdamage;
28 float autocvar_g_keepaway_noncarrier_selfforce;
29 bool autocvar_g_keepaway_noncarrier_warn;
30 int autocvar_g_keepaway_score_bckill;
31 int autocvar_g_keepaway_score_killac;
32 int autocvar_g_keepaway_score_timepoints;
33 float autocvar_g_keepaway_score_timeinterval;
34 float autocvar_g_keepawayball_damageforcescale;
35 int autocvar_g_keepawayball_effects;
36 float autocvar_g_keepawayball_respawntime;
37 int autocvar_g_keepawayball_trail_color;
39 float ka_ballcarrier_waypointsprite_visible_for_player(entity e) // runs on waypoints which are attached to ballcarriers, updates once per frame
43 return false; // we don't want spectators of the ballcarrier to see the attached waypoint on the top of their screen
45 // TODO: Make the ballcarrier lack a waypointsprite whenever they have the invisibility powerup
50 void ka_EventLog(string mode, entity actor) // use an alias for easy changing and quick editing later
52 if(autocvar_sv_eventlog)
53 GameLogEcho(strcat(":ka:", mode, ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
57 void ka_RespawnBall() // runs whenever the ball needs to be relocated
59 if(gameover) { return; }
60 vector oldballorigin = self.origin;
62 if(!MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
64 entity spot = SelectSpawnPoint(true);
65 setorigin(self, spot.origin);
66 self.angles = spot.angles;
69 makevectors(self.angles);
70 self.movetype = MOVETYPE_BOUNCE;
71 self.velocity = '0 0 200';
72 self.angles = '0 0 0';
73 self.effects = autocvar_g_keepawayball_effects;
74 self.touch = ka_TouchEvent;
75 self.think = ka_RespawnBall;
76 self.nextthink = time + autocvar_g_keepawayball_respawntime;
78 Send_Effect(EFFECT_ELECTRO_COMBO, oldballorigin, '0 0 0', 1);
79 Send_Effect(EFFECT_ELECTRO_COMBO, self.origin, '0 0 0', 1);
81 WaypointSprite_Spawn(WP_KaBall, 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER);
82 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
84 sound(self, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
89 if(self.owner.ballcarried)
90 { // add points for holding the ball after a certain amount of time
91 if(autocvar_g_keepaway_score_timepoints)
92 PlayerScore_Add(self.owner, SP_SCORE, autocvar_g_keepaway_score_timepoints);
94 PlayerScore_Add(self.owner, SP_KEEPAWAY_BCTIME, (autocvar_g_keepaway_score_timeinterval / 1)); // interval is divided by 1 so that time always shows "seconds"
95 self.nextthink = time + autocvar_g_keepaway_score_timeinterval;
99 void ka_TouchEvent() // runs any time that the ball comes in contact with something
101 if(gameover) { return; }
102 if(!self) { return; }
103 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
104 { // The ball fell off the map, respawn it since players can't get to it
108 if(other.deadflag != DEAD_NO) { return; }
109 if(other.frozen) { return; }
110 if (!IS_PLAYER(other))
111 { // The ball just touched an object, most likely the world
112 Send_Effect(EFFECT_BALL_SPARKS, self.origin, '0 0 0', 1);
113 sound(self, CH_TRIGGER, SND_KA_TOUCH, VOL_BASE, ATTEN_NORM);
116 else if(self.wait > time) { return; }
118 // attach the ball to the player
120 other.ballcarried = self;
121 setattachment(self, other, "");
122 setorigin(self, '0 0 0');
124 // make the ball invisible/unable to do anything/set up time scoring
125 self.velocity = '0 0 0';
126 self.movetype = MOVETYPE_NONE;
127 self.effects |= EF_NODRAW;
128 self.touch = func_null;
129 self.think = ka_TimeScoring;
130 self.nextthink = time + autocvar_g_keepaway_score_timeinterval;
131 self.takedamage = DAMAGE_NO;
133 // apply effects to player
134 other.glow_color = autocvar_g_keepawayball_trail_color;
135 other.glow_trail = true;
136 other.effects |= autocvar_g_keepaway_ballcarrier_effects;
138 // messages and sounds
139 ka_EventLog("pickup", other);
140 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_KEEPAWAY_PICKUP, other.netname);
141 Send_Notification(NOTIF_ALL_EXCEPT, other, MSG_CENTER, CENTER_KEEPAWAY_PICKUP, other.netname);
142 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_KEEPAWAY_PICKUP_SELF);
143 sound(self.owner, CH_TRIGGER, SND_KA_PICKEDUP, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
146 PlayerScore_Add(other, SP_KEEPAWAY_PICKUPS, 1);
149 WaypointSprite_AttachCarrier(WP_KaBallCarrier, other, RADARICON_FLAGCARRIER);
150 other.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = ka_ballcarrier_waypointsprite_visible_for_player;
151 WaypointSprite_UpdateRule(other.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
152 WaypointSprite_Ping(other.waypointsprite_attachedforcarrier);
153 WaypointSprite_Kill(self.waypointsprite_attachedforcarrier);
156 void ka_DropEvent(entity plyr) // runs any time that a player is supposed to lose the ball
159 ball = plyr.ballcarried;
161 if(!ball) { return; }
164 setattachment(ball, world, "");
165 ball.movetype = MOVETYPE_BOUNCE;
166 ball.wait = time + 1;
167 ball.touch = ka_TouchEvent;
168 ball.think = ka_RespawnBall;
169 ball.nextthink = time + autocvar_g_keepawayball_respawntime;
170 ball.takedamage = DAMAGE_YES;
171 ball.effects &= ~EF_NODRAW;
172 setorigin(ball, plyr.origin + '0 0 10');
173 ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
174 ball.owner.ballcarried = world; // I hope nothing checks to see if the world has the ball in the rest of my code :P
177 // reset the player effects
178 plyr.glow_trail = false;
179 plyr.effects &= ~autocvar_g_keepaway_ballcarrier_effects;
181 // messages and sounds
182 ka_EventLog("dropped", plyr);
183 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_KEEPAWAY_DROPPED, plyr.netname);
184 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEEPAWAY_DROPPED, plyr.netname);
185 sound(other, CH_TRIGGER, SND_KA_DROPPED, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
188 // PlayerScore_Add(plyr, SP_KEEPAWAY_DROPS, 1); Not anymore, this is 100% the same as pickups and is useless.
191 WaypointSprite_Spawn(WP_KaBall, 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER);
192 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
193 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
194 WaypointSprite_Kill(plyr.waypointsprite_attachedforcarrier);
197 void ka_Reset() // used to clear the ballcarrier whenever the match switches from warmup to normal
199 if((self.owner) && (IS_PLAYER(self.owner)))
200 ka_DropEvent(self.owner);
202 if(time < game_starttime)
204 self.think = ka_RespawnBall;
205 self.touch = func_null;
206 self.nextthink = game_starttime;
217 void havocbot_goalrating_ball(float ratingscale, vector org)
221 ball_owner = ka_ball.owner;
223 if (ball_owner == self)
226 // If ball is carried by player then hunt them down.
229 t = (self.health + self.armorvalue) / (ball_owner.health + ball_owner.armorvalue);
230 navigation_routerating(ball_owner, t * ratingscale, 2000);
232 else // Ball has been dropped so collect.
233 navigation_routerating(ka_ball, ratingscale, 2000);
236 void havocbot_role_ka_carrier()
238 if (self.deadflag != DEAD_NO)
241 if (time > self.bot_strategytime)
243 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
245 navigation_goalrating_start();
246 havocbot_goalrating_items(10000, self.origin, 10000);
247 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
248 //havocbot_goalrating_waypoints(1, self.origin, 1000);
249 navigation_goalrating_end();
252 if (!self.ballcarried)
254 self.havocbot_role = havocbot_role_ka_collector;
255 self.bot_strategytime = 0;
259 void havocbot_role_ka_collector()
261 if (self.deadflag != DEAD_NO)
264 if (time > self.bot_strategytime)
266 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
268 navigation_goalrating_start();
269 havocbot_goalrating_items(10000, self.origin, 10000);
270 havocbot_goalrating_enemyplayers(1000, self.origin, 10000);
271 havocbot_goalrating_ball(20000, self.origin);
272 navigation_goalrating_end();
275 if (self.ballcarried)
277 self.havocbot_role = havocbot_role_ka_carrier;
278 self.bot_strategytime = 0;
287 MUTATOR_HOOKFUNCTION(ka, PlayerDies)
289 if((frag_attacker != frag_target) && (IS_PLAYER(frag_attacker)))
291 if(frag_target.ballcarried) { // add to amount of times killing carrier
292 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_CARRIERKILLS, 1);
293 if(autocvar_g_keepaway_score_bckill) // add bckills to the score
294 PlayerScore_Add(frag_attacker, SP_SCORE, autocvar_g_keepaway_score_bckill);
296 else if(!frag_attacker.ballcarried)
297 if(autocvar_g_keepaway_noncarrier_warn)
298 Send_Notification(NOTIF_ONE_ONLY, frag_attacker, MSG_CENTER, CENTER_KEEPAWAY_WARN);
300 if(frag_attacker.ballcarried) // add to amount of kills while ballcarrier
301 PlayerScore_Add(frag_attacker, SP_SCORE, autocvar_g_keepaway_score_killac);
304 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has died, drop it
308 MUTATOR_HOOKFUNCTION(ka, GiveFragsForKill)
310 frag_score = 0; // no frags counted in keepaway
311 return 1; // you deceptive little bugger ;3 This needs to be true in order for this function to even count.
314 MUTATOR_HOOKFUNCTION(ka, PlayerPreThink)
316 // clear the item used for the ball in keepaway
317 self.items &= ~IT_KEY1;
319 // if the player has the ball, make sure they have the item for it (Used for HUD primarily)
321 self.items |= IT_KEY1;
326 MUTATOR_HOOKFUNCTION(ka, PlayerUseKey)
328 if(MUTATOR_RETURNVALUE == 0)
337 MUTATOR_HOOKFUNCTION(ka, PlayerDamage_Calculate) // for changing damage and force values that are applied to players in g_damage.qc
339 if(frag_attacker.ballcarried) // if the attacker is a ballcarrier
341 if(frag_target == frag_attacker) // damage done to yourself
343 frag_damage *= autocvar_g_keepaway_ballcarrier_selfdamage;
344 frag_force *= autocvar_g_keepaway_ballcarrier_selfforce;
346 else // damage done to noncarriers
348 frag_damage *= autocvar_g_keepaway_ballcarrier_damage;
349 frag_force *= autocvar_g_keepaway_ballcarrier_force;
352 else if (!frag_target.ballcarried) // if the target is a noncarrier
354 if(frag_target == frag_attacker) // damage done to yourself
356 frag_damage *= autocvar_g_keepaway_noncarrier_selfdamage;
357 frag_force *= autocvar_g_keepaway_noncarrier_selfforce;
359 else // damage done to other noncarriers
361 frag_damage *= autocvar_g_keepaway_noncarrier_damage;
362 frag_force *= autocvar_g_keepaway_noncarrier_force;
368 MUTATOR_HOOKFUNCTION(ka, ClientDisconnect)
370 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has left the match, drop it
374 MUTATOR_HOOKFUNCTION(ka, MakePlayerObserver)
376 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has left the match, drop it
380 MUTATOR_HOOKFUNCTION(ka, PlayerPowerups)
382 // In the future this hook is supposed to allow me to do some extra stuff with waypointsprites and invisibility powerup
383 // So bare with me until I can fix a certain bug with ka_ballcarrier_waypointsprite_visible_for_player()
385 self.effects &= ~autocvar_g_keepaway_ballcarrier_effects;
388 self.effects |= autocvar_g_keepaway_ballcarrier_effects;
393 .float stat_sv_airspeedlimit_nonqw;
394 .float stat_sv_maxspeed;
396 MUTATOR_HOOKFUNCTION(ka, PlayerPhysics)
400 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_keepaway_ballcarrier_highspeed;
401 self.stat_sv_maxspeed *= autocvar_g_keepaway_ballcarrier_highspeed;
406 MUTATOR_HOOKFUNCTION(ka, BotShouldAttack)
408 // if neither player has ball then don't attack unless the ball is on the ground
409 if(!checkentity.ballcarried && !self.ballcarried && ka_ball.owner)
414 MUTATOR_HOOKFUNCTION(ka, HavocBot_ChooseRole)
416 if (self.ballcarried)
417 self.havocbot_role = havocbot_role_ka_carrier;
419 self.havocbot_role = havocbot_role_ka_collector;
423 MUTATOR_HOOKFUNCTION(ka, DropSpecialItems)
425 if(frag_target.ballcarried)
426 ka_DropEvent(frag_target);
436 void ka_SpawnBall() // loads various values for the ball, runs only once at start of match
440 e.model = "models/orbs/orbblue.md3";
441 precache_model(e.model);
442 _setmodel(e, e.model);
443 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
444 e.classname = "keepawayball";
445 e.damageforcescale = autocvar_g_keepawayball_damageforcescale;
446 e.takedamage = DAMAGE_YES;
447 e.solid = SOLID_TRIGGER;
448 e.movetype = MOVETYPE_BOUNCE;
449 e.glow_color = autocvar_g_keepawayball_trail_color;
453 e.touch = ka_TouchEvent;
457 InitializeEntity(e, ka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So.
462 ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY, 0, true); // SFL_SORT_PRIO_PRIMARY
463 ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_PICKUPS, "pickups", 0);
464 ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0);
465 ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY);
466 ScoreRules_basics_end();
469 void ka_Initialize() // run at the start of a match, initiates game mode
476 REGISTER_MUTATOR(ka, IS_GAMETYPE(KEEPAWAY))
480 if(time > 1) // game loads at time 1
481 error("This is a game type and it cannot be added at runtime.");
485 MUTATOR_ONROLLBACK_OR_REMOVE
487 // we actually cannot roll back ka_Initialize here
488 // BUT: we don't need to! If this gets called, adding always
494 LOG_INFO("This is a game type and it cannot be removed at runtime.");