2 MUTATOR_HOOKFUNCTION(nexball_BallDrop)
4 if(self.ballcarried && g_nexball)
5 DropBall(self.ballcarried, self.origin, self.velocity);
11 MUTATOR_HOOKFUNCTION(nexball_BuildMutatorsString)
13 ret_string = strcat(ret_string, ":NB");
17 MUTATOR_HOOKFUNCTION(nexball_BuildMutatorsPrettyString)
19 ret_string = strcat(ret_string, ", NexBall");
22 MUTATOR_DEFINITION(gamemode_nexball)
24 //MUTATOR_HOOK(MakePlayerObserver, kh_Key_DropAll, CBC_ORDER_ANY);
25 MUTATOR_HOOK(PlayerDies, nexball_BallDrop, CBC_ORDER_ANY);
26 MUTATOR_HOOK(MakePlayerObserver, nexball_BallDrop, CBC_ORDER_ANY);
27 MUTATOR_HOOK(ClientDisconnect, nexball_BallDrop, CBC_ORDER_ANY);
28 MUTATOR_HOOK(BuildMutatorsPrettyString, nexball_BuildMutatorsPrettyString, CBC_ORDER_ANY);
29 MUTATOR_HOOK(BuildMutatorsString, nexball_BuildMutatorsString, CBC_ORDER_ANY);
36 g_nexball_meter_period = autocvar_g_nexball_meter_period;
37 if (g_nexball_meter_period <= 0)
38 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
39 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
40 addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
44 CVTOV(g_nexball_football_boost_forward); //100
45 CVTOV(g_nexball_football_boost_up); //200
46 CVTOV(g_nexball_delay_idle); //10
47 CVTOV(g_nexball_football_physics); //0
49 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
51 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
57 float OtherTeam(float t) //works only if there are two teams on the map!
60 e = find(world, classname, "nexball_team");
62 e = find(e, classname, "nexball_team");
68 void LogNB(string mode, entity actor)
71 if(!autocvar_sv_eventlog)
73 s = strcat(":nexball:", mode);
75 s = strcat(s, ":", ftos(actor.playerid));
79 void ball_restart (void)
82 DropBall(self, self.owner.origin, '0 0 0');
86 void nexball_setstatus (void)
89 self.items &~= IT_KEY1;
92 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
94 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
96 self = self.ballcarried;
97 DropBall(self, self.owner.origin, '0 0 0');
101 self.items |= IT_KEY1;
105 void relocate_nexball (void)
107 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
108 if (trace_startsolid)
112 if(!move_out_of_solid(self))
113 objerror("could not get out of solid at all!");
114 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
115 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
116 print(" ", ftos(self.origin_y - o_y));
117 print(" ", ftos(self.origin_z - o_z), "'\n");
122 void basketball_touch();
123 void football_touch();
125 void DropOwner (void)
129 DropBall(self, ownr.origin, ownr.velocity);
130 makevectors(ownr.v_angle_y * '0 1 0');
131 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
132 ownr.flags &~= FL_ONGROUND;
135 void GiveBall (entity plyr, entity ball)
139 if ((ownr = ball.owner))
141 ownr.effects &~= autocvar_g_nexball_basketball_effects_default;
142 ownr.ballcarried = world;
146 ownr.weaponentity.state = WS_READY;
148 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
152 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
155 setattachment(ball, plyr, "");
156 setorigin(ball, BALL_ATTACHORG);
158 if (ball.team != plyr.team)
159 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
161 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
162 ball.team = plyr.team;
163 plyr.ballcarried = ball;
164 ball.dropperid = plyr.playerid;
166 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
167 ball.effects &~= autocvar_g_nexball_basketball_effects_default;
169 ball.velocity = '0 0 0';
170 ball.movetype = MOVETYPE_NONE;
171 ball.touch = SUB_Null;
172 ball.effects |= EF_NOSHADOW;
173 ball.scale = 1; // scale down.
175 WaypointSprite_AttachCarrier("nb-ball", plyr, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
176 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
178 if (autocvar_g_nexball_basketball_delay_hold)
180 ball.think = DropOwner;
181 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
185 void DropBall (entity ball, vector org, vector vel)
187 ball.effects |= autocvar_g_nexball_basketball_effects_default;
188 ball.effects &~= EF_NOSHADOW;
189 ball.owner.effects &~= autocvar_g_nexball_basketball_effects_default;
191 setattachment(ball, world, "");
192 setorigin (ball, org);
193 ball.movetype = MOVETYPE_BOUNCE;
194 ball.flags &~= FL_ONGROUND;
195 ball.scale = ball_scale;
197 ball.ctf_droptime = time;
198 ball.touch = basketball_touch;
199 ball.think = ResetBall;
200 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
202 if (ball.owner.metertime)
204 ball.owner.metertime = 0;
205 ball.owner.weaponentity.state = WS_READY;
208 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
209 WaypointSprite_Spawn("nb-ball", 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, FALSE, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR); // no health bar please
210 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
212 ball.owner.ballcarried = world;
218 if (gameover) return;
219 self.flags &~= FL_ONGROUND;
220 self.movetype = MOVETYPE_BOUNCE;
221 if (self.classname == "nexball_basketball")
222 self.touch = basketball_touch;
223 else if (self.classname == "nexball_football")
224 self.touch = football_touch;
226 self.think = ResetBall;
227 self.nextthink = time + autocvar_g_nexball_delay_idle + 3;
231 sound (self, CH_TRIGGER, self.noise1, VOL_BASE, ATTN_NORM);
232 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
233 LogNB("init", world);
236 void ResetBall (void)
238 if (self.cnt < 2) { // step 1
239 if (time == self.teamtime)
240 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
241 self.touch = SUB_Null;
242 self.movetype = MOVETYPE_NOCLIP;
243 self.velocity = '0 0 0'; // just in case?
245 LogNB("resetidle", world);
247 self.nextthink = time;
248 } else if (self.cnt < 4) { // step 2 and 3
249 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
250 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
251 self.nextthink = time + 0.5;
254 // dprint("Step 4: time: ", ftos(time), "\n");
255 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
256 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
257 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
258 self.velocity = '0 0 0';
259 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
260 self.movetype = MOVETYPE_NONE;
261 self.think = InitBall;
262 self.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
266 void football_touch (void)
268 if (other.solid == SOLID_BSP) {
269 if (time > self.lastground + 0.1)
271 sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
272 self.lastground = time;
274 if (vlen(self.velocity) && !self.cnt)
275 self.nextthink = time + autocvar_g_nexball_delay_idle;
278 if (other.classname != "player")
280 if (other.health < 1)
283 self.nextthink = time + autocvar_g_nexball_delay_idle;
286 self.team = other.team;
288 if (autocvar_g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
289 if (vlen(other.velocity))
290 self.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
291 } else if (autocvar_g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
292 makevectors(other.v_angle);
293 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
294 } else if (autocvar_g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
295 makevectors(other.v_angle_y * '0 1 0');
296 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
297 } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
298 makevectors(other.v_angle);
299 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
301 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
304 void basketball_touch (void)
306 if (other.ballcarried)
311 if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_nexball_delay_collect)) {
312 if (other.health <= 0)
314 LogNB("caught", other);
315 GiveBall(other, self);
316 } else if (other.solid == SOLID_BSP) {
317 sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
318 if (vlen(self.velocity) && !self.cnt)
319 self.nextthink = min(time + autocvar_g_nexball_delay_idle, self.teamtime);
323 void GoalTouch (void)
326 float isclient, pscore, otherteam;
329 if (gameover) return;
330 if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
331 ball = other.ballcarried;
334 if (ball.classname != "nexball_basketball")
335 if (ball.classname != "nexball_football")
337 if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
343 otherteam = OtherTeam(ball.team);
345 if((isclient = ball.pusher.flags & FL_CLIENT))
346 pname = ball.pusher.netname;
348 pname = "Someone (?)";
350 if (ball.team == self.team) //owngoal (regular goals)
352 LogNB("owngoal", ball.pusher);
353 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
355 } else if (self.team == GOAL_FAULT) {
356 LogNB("fault", ball.pusher);
358 bprint(ColoredTeamName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
360 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
362 } else if (self.team == GOAL_OUT) {
363 LogNB("out", ball.pusher);
364 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
365 bprint(pname, "^7 went out of bounds.\n");
367 bprint("The ball was returned.\n");
370 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
371 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
375 sound (ball, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NONE);
377 if(ball.team && pscore)
379 if (nb_teams == 2 && pscore < 0)
380 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
382 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
387 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
389 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
392 if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
393 DropBall(ball, ball.owner.origin, ball.owner.velocity);
395 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
398 ball.think = ResetBall;
399 if (ball.classname == "nexball_basketball")
400 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
401 ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
404 //=======================//
406 //=======================//
407 void spawnfunc_nexball_team (void)
409 if(!g_nexball) { remove(self); return; }
410 self.team = self.cnt + 1;
413 void nb_spawnteam (string teamname, float teamcolor)
415 dprint("^2spawned team ", teamname, "\n");
418 e.classname = "nexball_team";
419 e.netname = teamname;
425 void nb_spawnteams (void)
427 float t_r, t_b, t_y, t_p;
429 for(e = world; (e = find(e, classname, "nexball_goal")); )
433 case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1) ; t_r = 1; } break;
434 case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1) ; t_b = 1; } break;
435 case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
436 case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1) ; t_p = 1; } break;
441 void nb_delayedinit (void)
443 if (find(world, classname, "nexball_team") == world)
445 ScoreRules_nexball(nb_teams);
449 //=======================//
451 //=======================//
453 void SpawnBall (void)
455 if(!g_nexball) { remove(self); return; }
457 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
460 self.model = "models/nexball/ball.md3";
464 precache_model (self.model);
465 setmodel (self, self.model);
466 setsize (self, BALL_MINS, BALL_MAXS);
467 ball_scale = self.scale;
470 self.spawnorigin = self.origin;
472 self.effects = self.effects | EF_LOWPRECISION;
474 if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
476 self.glow_color = autocvar_g_nexball_trail_color;
477 self.glow_trail = TRUE;
480 self.movetype = MOVETYPE_FLY;
482 if (!autocvar_g_nexball_sound_bounce)
484 else if (!self.noise)
485 self.noise = "sound/nexball/bounce.wav";
486 //bounce sound placeholder (FIXME)
488 self.noise1 = "sound/nexball/drop.wav";
489 //ball drop sound placeholder (FIXME)
491 self.noise2 = "sound/nexball/steal.wav";
492 //stealing sound placeholder (FIXME)
493 if (self.noise) precache_sound (self.noise);
494 precache_sound (self.noise1);
495 precache_sound (self.noise2);
497 WaypointSprite_AttachCarrier("nb-ball", self, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR); // the ball's team is not set yet, no rule update needed
499 self.reset = ball_restart;
500 self.think = InitBall;
501 self.nextthink = game_starttime + autocvar_g_nexball_delay_start;
504 void spawnfunc_nexball_basketball (void)
506 self.classname = "nexball_basketball";
507 if not(balls & BALL_BASKET)
510 CVTOV(g_nexball_basketball_effects_default);
511 CVTOV(g_nexball_basketball_delay_hold);
512 CVTOV(g_nexball_basketball_delay_hold_forteam);
513 CVTOV(g_nexball_basketball_teamsteal);
515 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
518 self.effects = autocvar_g_nexball_basketball_effects_default;
519 self.solid = SOLID_TRIGGER;
520 balls |= BALL_BASKET;
521 self.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
522 self.bouncestop = autocvar_g_nexball_basketball_bouncestop;
526 void spawnfunc_nexball_football (void)
528 self.classname = "nexball_football";
529 self.solid = SOLID_TRIGGER;
531 self.bouncefactor = autocvar_g_nexball_football_bouncefactor;
532 self.bouncestop = autocvar_g_nexball_football_bouncestop;
536 void SpawnGoal (void)
538 if(!g_nexball) { remove(self); return; }
540 self.classname = "nexball_goal";
542 self.noise = "ctf/respawn.wav";
543 precache_sound(self.noise);
544 self.touch = GoalTouch;
547 void spawnfunc_nexball_redgoal (void)
549 self.team = COLOR_TEAM1;
552 void spawnfunc_nexball_bluegoal (void)
554 self.team = COLOR_TEAM2;
557 void spawnfunc_nexball_yellowgoal (void)
559 self.team = COLOR_TEAM3;
562 void spawnfunc_nexball_pinkgoal (void)
564 self.team = COLOR_TEAM4;
568 void spawnfunc_nexball_fault (void)
570 self.team = GOAL_FAULT;
572 self.noise = "misc/typehit.wav";
576 void spawnfunc_nexball_out (void)
578 self.team = GOAL_OUT;
580 self.noise = "misc/typehit.wav";
585 //Spawnfuncs preserved for compatibility
588 void spawnfunc_ball (void) { spawnfunc_nexball_football(); }
589 void spawnfunc_ball_football (void) { spawnfunc_nexball_football(); }
590 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
591 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
592 void spawnfunc_ball_redgoal (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
593 void spawnfunc_ball_bluegoal (void) { spawnfunc_nexball_redgoal(); } // but he didn't mean to cause trouble :p
594 void spawnfunc_ball_fault (void) { spawnfunc_nexball_fault(); }
595 void spawnfunc_ball_bound (void) { spawnfunc_nexball_out(); }
597 //=======================//
599 //=======================//
601 void W_Nexball_Touch (void)
603 entity ball, attacker;
604 attacker = self.owner;
607 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
608 if((ball = other.ballcarried) && (attacker.classname == "player"))
610 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
611 other.flags &~= FL_ONGROUND;
612 if(!attacker.ballcarried)
614 LogNB("stole", attacker);
615 sound (other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTN_NORM);
617 if(attacker.team == other.team && time > attacker.teamkill_complain)
619 attacker.teamkill_complain = time + 5;
620 attacker.teamkill_soundtime = time + 0.4;
621 attacker.teamkill_soundsource = other;
624 GiveBall(attacker, other.ballcarried);
630 void W_Nexball_Attack (float t)
634 if (!(ball = self.ballcarried))
637 W_SetupShot (self, FALSE, 4, "nexball/shoot1.wav", CH_WEAPON_A, 0);
638 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
642 self.metertime = 0; // Shot failed, hide the power meter
646 //Calculate multiplier
651 mi = autocvar_g_nexball_basketball_meter_minpower;
652 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
653 //One triangle wave period with 1 as max
654 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
657 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
659 DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, FALSE));
660 //TODO: use the speed_up cvar too ??
663 void W_Nexball_Attack2 (void)
666 if (!(balls & BALL_BASKET))
668 W_SetupShot (self, FALSE, 2, "nexball/shoot2.wav", CH_WEAPON_A, 0);
669 // pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
672 missile.owner = self;
673 missile.classname = "ballstealer";
675 missile.movetype = MOVETYPE_FLY;
676 PROJECTILE_MAKETRIGGER(missile);
678 setmodel (missile, "models/elaser.mdl"); // precision set below
679 setsize (missile, '0 0 0', '0 0 0');
680 setorigin (missile, w_shotorg);
682 W_SetupProjectileVelocity(missile, autocvar_g_balance_nexball_secondary_speed, 0);
683 missile.angles = vectoangles (missile.velocity);
684 missile.touch = W_Nexball_Touch;
685 missile.think = SUB_Remove;
686 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
688 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
689 missile.flags = FL_PROJECTILE;
692 float w_nexball_weapon(float req)
696 if (self.BUTTON_ATCK)
697 if (weapon_prepareattack(0, autocvar_g_balance_nexball_primary_refire))
698 if (autocvar_g_nexball_basketball_meter)
700 if (self.ballcarried && !self.metertime)
701 self.metertime = time;
703 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
707 W_Nexball_Attack(-1);
708 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
710 if (self.BUTTON_ATCK2)
711 if (weapon_prepareattack(1, autocvar_g_balance_nexball_secondary_refire))
714 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
717 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
719 W_Nexball_Attack(time - self.metertime);
720 // DropBall or stealing will set metertime back to 0
721 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
724 else if (req == WR_PRECACHE)
726 precache_model ("models/weapons/g_porto.md3");
727 precache_model ("models/weapons/v_porto.md3");
728 precache_model ("models/weapons/h_porto.iqm");
729 precache_model ("models/elaser.mdl");
730 precache_sound ("nexball/shoot1.wav");
731 precache_sound ("nexball/shoot2.wav");
732 precache_sound ("misc/typehit.wav");
734 else if (req == WR_SETUP)
735 weapon_setup(WEP_PORTO);
736 else if (req == WR_SUICIDEMESSAGE)
738 w_deathtypestring = "is a weirdo";
740 else if (req == WR_KILLMESSAGE)
742 w_deathtypestring = "got killed by #'s black magic";
744 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE