5 .float metertime = _STAT(NB_METERSTART);
7 int autocvar_g_nexball_goalleadlimit;
8 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
10 bool autocvar_g_nexball_basketball_jumppad = true;
11 float autocvar_g_nexball_basketball_bouncefactor;
12 float autocvar_g_nexball_basketball_bouncestop;
13 float autocvar_g_nexball_basketball_carrier_highspeed;
14 bool autocvar_g_nexball_basketball_meter;
15 float autocvar_g_nexball_basketball_meter_maxpower;
16 float autocvar_g_nexball_basketball_meter_minpower;
17 float autocvar_g_nexball_delay_collect;
18 float autocvar_g_nexball_delay_goal;
19 float autocvar_g_nexball_delay_start;
20 bool autocvar_g_nexball_football_jumppad = true;
21 float autocvar_g_nexball_football_bouncefactor;
22 float autocvar_g_nexball_football_bouncestop;
23 bool autocvar_g_nexball_radar_showallplayers;
24 bool autocvar_g_nexball_sound_bounce;
25 int autocvar_g_nexball_trail_color;
27 float autocvar_g_nexball_safepass_turnrate;
28 float autocvar_g_nexball_safepass_maxdist;
29 float autocvar_g_nexball_safepass_holdtime;
30 float autocvar_g_nexball_viewmodel_scale;
31 float autocvar_g_nexball_tackling;
32 vector autocvar_g_nexball_viewmodel_offset;
34 float autocvar_g_balance_nexball_primary_animtime;
35 float autocvar_g_balance_nexball_primary_refire;
36 float autocvar_g_balance_nexball_primary_speed;
37 float autocvar_g_balance_nexball_secondary_animtime;
38 float autocvar_g_balance_nexball_secondary_force;
39 float autocvar_g_balance_nexball_secondary_lifetime;
40 float autocvar_g_balance_nexball_secondary_refire;
41 float autocvar_g_balance_nexball_secondary_speed;
43 void basketball_touch();
44 void football_touch();
46 const int NBM_NONE = 0;
47 const int NBM_FOOTBALL = 2;
48 const int NBM_BASKETBALL = 4;
51 float OtherTeam(float t) //works only if there are two teams on the map!
54 e = find(world, classname, "nexball_team");
56 e = find(e, classname, "nexball_team");
60 const float ST_NEXBALL_GOALS = 1;
61 const float SP_NEXBALL_GOALS = 4;
62 const float SP_NEXBALL_FAULTS = 5;
63 void nb_ScoreRules(float teams)
65 ScoreRules_basics(teams, 0, 0, true);
66 ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
67 ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
68 ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
69 ScoreRules_basics_end();
72 void LogNB(string mode, entity actor)
75 if(!autocvar_sv_eventlog)
77 s = strcat(":nexball:", mode);
79 s = strcat(s, ":", ftos(actor.playerid));
83 void ball_restart(entity this)
86 DropBall(this, this.owner.origin, '0 0 0');
90 void nexball_setstatus()
92 self.items &= ~IT_KEY1;
95 if(self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
97 bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
98 setself(self.ballcarried);
99 DropBall(self, self.owner.origin, '0 0 0');
104 self.items |= IT_KEY1;
108 void relocate_nexball()
110 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, true, self);
115 if(!move_out_of_solid(self))
116 objerror("could not get out of solid at all!");
117 LOG_INFO("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
118 LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(self.origin.x - o.x));
119 LOG_INFO(" ", ftos(self.origin.y - o.y));
120 LOG_INFO(" ", ftos(self.origin.z - o.z), "'\n");
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 UNSET_ONGROUND(ownr);
135 void GiveBall(entity plyr, entity ball)
137 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
138 entity 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, plyr.origin + plyr.view_ofs);
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.nb_dropper = plyr;
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 = func_null;
172 ball.effects |= EF_NOSHADOW;
173 ball.scale = 1; // scale down.
175 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
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;
184 plyr.(weaponentity).weapons = plyr.weapons;
185 plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
186 plyr.weapons = WEPSET(NEXBALL);
188 Weapon w = WEP_NEXBALL;
190 PS(plyr).m_switchweapon = WEP_NEXBALL;
191 W_SwitchWeapon(WEP_NEXBALL);
195 void DropBall(entity ball, vector org, vector vel)
197 ball.effects |= autocvar_g_nexball_basketball_effects_default;
198 ball.effects &= ~EF_NOSHADOW;
199 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
201 setattachment(ball, world, "");
202 setorigin(ball, org);
203 ball.movetype = MOVETYPE_BOUNCE;
204 UNSET_ONGROUND(ball);
205 ball.scale = ball_scale;
207 ball.nb_droptime = time;
208 ball.touch = basketball_touch;
209 ball.think = ResetBall;
210 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
212 if(ball.owner.metertime)
214 ball.owner.metertime = 0;
215 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
216 ball.owner.(weaponentity).state = WS_READY;
219 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
220 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
221 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
223 ball.owner.ballcarried = world;
230 UNSET_ONGROUND(self);
231 self.movetype = MOVETYPE_BOUNCE;
232 if(self.classname == "nexball_basketball")
233 self.touch = basketball_touch;
234 else if(self.classname == "nexball_football")
235 self.touch = football_touch;
237 self.think = ResetBall;
238 self.nextthink = time + autocvar_g_nexball_delay_idle + 3;
242 _sound(self, CH_TRIGGER, self.noise1, VOL_BASE, ATTEN_NORM);
243 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
244 LogNB("init", world);
249 if(self.cnt < 2) // step 1
251 if(time == self.teamtime)
252 bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
254 self.touch = func_null;
255 self.movetype = MOVETYPE_NOCLIP;
256 self.velocity = '0 0 0'; // just in case?
258 LogNB("resetidle", world);
260 self.nextthink = time;
262 else if(self.cnt < 4) // step 2 and 3
264 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
265 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
266 self.nextthink = time + 0.5;
271 // dprint("Step 4: time: ", ftos(time), "\n");
272 if(vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
273 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
274 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
275 self.velocity = '0 0 0';
276 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
277 self.movetype = MOVETYPE_NONE;
278 self.think = InitBall;
279 self.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
283 void football_touch()
285 if(other.solid == SOLID_BSP)
287 if(time > self.lastground + 0.1)
289 _sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
290 self.lastground = time;
292 if(vlen(self.velocity) && !self.cnt)
293 self.nextthink = time + autocvar_g_nexball_delay_idle;
296 if (!IS_PLAYER(other))
301 self.nextthink = time + autocvar_g_nexball_delay_idle;
304 self.team = other.team;
306 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
308 if(vlen(other.velocity))
309 self.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
311 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
313 makevectors(other.v_angle);
314 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
316 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
318 makevectors(other.v_angle.y * '0 1 0');
319 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
321 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
323 makevectors(other.v_angle);
324 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
326 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
329 void basketball_touch()
331 if(other.ballcarried)
336 if(!self.cnt && IS_PLAYER(other) && !STAT(FROZEN, other) && !IS_DEAD(other) && (other != self.nb_dropper || time > self.nb_droptime + autocvar_g_nexball_delay_collect))
338 if(other.health <= 0)
340 LogNB("caught", other);
341 GiveBall(other, self);
343 else if(other.solid == SOLID_BSP)
345 _sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
346 if(vlen(self.velocity) && !self.cnt)
347 self.nextthink = min(time + autocvar_g_nexball_delay_idle, self.teamtime);
354 float isclient, pscore, otherteam;
358 if((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
359 ball = other.ballcarried;
362 if(ball.classname != "nexball_basketball")
363 if(ball.classname != "nexball_football")
365 if((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
371 otherteam = OtherTeam(ball.team);
375 if((isclient = IS_CLIENT(ball.pusher)))
376 pname = ball.pusher.netname;
378 pname = "Someone (?)";
380 if(ball.team == self.team) //owngoal (regular goals)
382 LogNB("owngoal", ball.pusher);
383 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
386 else if(self.team == GOAL_FAULT)
388 LogNB("fault", ball.pusher);
390 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
392 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
395 else if(self.team == GOAL_OUT)
397 LogNB("out", ball.pusher);
398 if((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
399 bprint(pname, "^7 went out of bounds.\n");
401 bprint("The ball was returned.\n");
406 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
407 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
411 _sound(ball, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NONE);
413 if(ball.team && pscore)
415 if(nb_teams == 2 && pscore < 0)
416 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
418 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
423 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
425 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
428 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
429 DropBall(ball, ball.owner.origin, ball.owner.velocity);
431 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
434 ball.think = ResetBall;
435 if(ball.classname == "nexball_basketball")
436 ball.touch = football_touch; // better than func_null: football control until the ball gets reset
437 ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
440 //=======================//
442 //=======================//
443 spawnfunc(nexball_team)
450 self.team = self.cnt + 1;
453 void nb_spawnteam(string teamname, float teamcolor)
455 LOG_TRACE("^2spawned team ", teamname, "\n");
456 entity e = new(nexball_team);
457 e.netname = teamname;
465 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
467 for(e = world; (e = find(e, classname, "nexball_goal"));)
474 nb_spawnteam("Red", e.team-1) ;
481 nb_spawnteam("Blue", e.team-1) ;
488 nb_spawnteam("Yellow", e.team-1);
495 nb_spawnteam("Pink", e.team-1) ;
503 void nb_delayedinit(entity this)
505 if(find(world, classname, "nexball_team") == world)
507 nb_ScoreRules(nb_teams);
511 //=======================//
513 //=======================//
517 if(!g_nexball) { remove(self); return; }
519 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
523 self.model = "models/nexball/ball.md3";
527 precache_model(self.model);
528 _setmodel(self, self.model);
529 setsize(self, BALL_MINS, BALL_MAXS);
530 ball_scale = self.scale;
533 self.spawnorigin = self.origin;
535 self.effects = self.effects | EF_LOWPRECISION;
537 if(cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
539 self.glow_color = autocvar_g_nexball_trail_color;
540 self.glow_trail = true;
543 self.movetype = MOVETYPE_FLY;
545 if(!autocvar_g_nexball_sound_bounce)
547 else if(self.noise == "")
548 self.noise = strzone(SND(NB_BOUNCE));
549 //bounce sound placeholder (FIXME)
550 if(self.noise1 == "")
551 self.noise1 = strzone(SND(NB_DROP));
552 //ball drop sound placeholder (FIXME)
553 if(self.noise2 == "")
554 self.noise2 = strzone(SND(NB_STEAL));
555 //stealing sound placeholder (FIXME)
556 if(self.noise) precache_sound(self.noise);
557 precache_sound(self.noise1);
558 precache_sound(self.noise2);
560 WaypointSprite_AttachCarrier(WP_NbBall, self, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
562 self.reset = ball_restart;
563 self.think = InitBall;
564 self.nextthink = game_starttime + autocvar_g_nexball_delay_start;
567 spawnfunc(nexball_basketball)
569 nexball_mode |= NBM_BASKETBALL;
570 self.classname = "nexball_basketball";
571 if (!(balls & BALL_BASKET))
574 CVTOV(g_nexball_basketball_effects_default);
575 CVTOV(g_nexball_basketball_delay_hold);
576 CVTOV(g_nexball_basketball_delay_hold_forteam);
577 CVTOV(g_nexball_basketball_teamsteal);
579 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
582 self.effects = autocvar_g_nexball_basketball_effects_default;
583 self.solid = SOLID_TRIGGER;
584 self.pushable = autocvar_g_nexball_basketball_jumppad;
585 balls |= BALL_BASKET;
586 self.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
587 self.bouncestop = autocvar_g_nexball_basketball_bouncestop;
591 spawnfunc(nexball_football)
593 nexball_mode |= NBM_FOOTBALL;
594 self.classname = "nexball_football";
595 self.solid = SOLID_TRIGGER;
597 self.pushable = autocvar_g_nexball_football_jumppad;
598 self.bouncefactor = autocvar_g_nexball_football_bouncefactor;
599 self.bouncestop = autocvar_g_nexball_football_bouncestop;
603 float nb_Goal_Customize()
606 e = WaypointSprite_getviewentity(other);
607 wp_owner = self.owner;
608 if(SAME_TEAM(e, wp_owner)) { return false; }
615 if(!g_nexball) { remove(self); return; }
619 if(self.team != GOAL_OUT && Team_TeamToNumber(self.team) != -1)
621 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (self.absmin + self.absmax) * 0.5, self, sprite, RADARICON_NONE);
622 wp.colormod = ((self.team) ? Team_ColorRGB(self.team) : '1 0.5 0');
623 self.sprite.customizeentityforclient = nb_Goal_Customize;
626 self.classname = "nexball_goal";
628 self.noise = "ctf/respawn.wav";
629 precache_sound(self.noise);
630 self.touch = GoalTouch;
633 spawnfunc(nexball_redgoal)
635 self.team = NUM_TEAM_1;
638 spawnfunc(nexball_bluegoal)
640 self.team = NUM_TEAM_2;
643 spawnfunc(nexball_yellowgoal)
645 self.team = NUM_TEAM_3;
648 spawnfunc(nexball_pinkgoal)
650 self.team = NUM_TEAM_4;
654 spawnfunc(nexball_fault)
656 self.team = GOAL_FAULT;
658 self.noise = strzone(SND(TYPEHIT));
662 spawnfunc(nexball_out)
664 self.team = GOAL_OUT;
666 self.noise = strzone(SND(TYPEHIT));
671 //Spawnfuncs preserved for compatibility
676 spawnfunc_nexball_football(this);
678 spawnfunc(ball_football)
680 spawnfunc_nexball_football(this);
682 spawnfunc(ball_basketball)
684 spawnfunc_nexball_basketball(this);
686 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
687 spawnfunc(ball_redgoal)
689 spawnfunc_nexball_bluegoal(this); // I blame Revenant
691 spawnfunc(ball_bluegoal)
693 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
695 spawnfunc(ball_fault)
697 spawnfunc_nexball_fault(this);
699 spawnfunc(ball_bound)
701 spawnfunc_nexball_out(this);
704 //=======================//
706 //=======================//
709 void W_Nexball_Think()
711 //dprint("W_Nexball_Think\n");
712 //vector new_dir = steerlib_arrive(self.enemy.origin, 2500);
713 vector new_dir = normalize(self.enemy.origin + '0 0 50' - self.origin);
714 vector old_dir = normalize(self.velocity);
715 float _speed = vlen(self.velocity);
716 vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
717 //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
719 self.velocity = new_vel;
721 self.nextthink = time;
724 void W_Nexball_Touch()
726 entity ball, attacker;
727 attacker = self.owner;
728 //self.think = func_null;
729 //self.enemy = world;
732 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
733 if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
735 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
736 UNSET_ONGROUND(other);
737 if(!attacker.ballcarried)
739 LogNB("stole", attacker);
740 _sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
742 if(SAME_TEAM(attacker, other) && time > attacker.teamkill_complain)
744 attacker.teamkill_complain = time + 5;
745 attacker.teamkill_soundtime = time + 0.4;
746 attacker.teamkill_soundsource = other;
749 GiveBall(attacker, other.ballcarried);
755 void W_Nexball_Attack(float t)
759 if(!(ball = self.ballcarried))
762 W_SetupShot(self, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
763 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
767 self.metertime = 0; // Shot failed, hide the power meter
771 //Calculate multiplier
776 mi = autocvar_g_nexball_basketball_meter_minpower;
777 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
778 //One triangle wave period with 1 as max
779 mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
782 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
785 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
788 //TODO: use the speed_up cvar too ??
791 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
793 void W_Nexball_Attack2()
795 if(self.ballcarried.enemy)
797 entity _ball = self.ballcarried;
798 W_SetupShot(self, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
799 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
800 _ball.think = W_Nexball_Think;
801 _ball.nextthink = time;
805 if(!autocvar_g_nexball_tackling)
808 W_SetupShot(self, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
809 entity missile = new(ballstealer);
811 missile.owner = self;
813 missile.movetype = MOVETYPE_FLY;
814 PROJECTILE_MAKETRIGGER(missile);
816 //setmodel(missile, "models/elaser.mdl"); // precision set below
817 setsize(missile, '0 0 0', '0 0 0');
818 setorigin(missile, w_shotorg);
820 W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
821 missile.angles = vectoangles(missile.velocity);
822 missile.touch = W_Nexball_Touch;
823 missile.think = SUB_Remove_self;
824 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
826 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
827 missile.flags = FL_PROJECTILE;
829 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
832 float ball_customize()
836 self.effects &= ~EF_FLAME;
838 self.customizeentityforclient = func_null;
842 if(other == self.owner)
844 self.scale = autocvar_g_nexball_viewmodel_scale;
846 self.effects |= EF_FLAME;
848 self.effects &= ~EF_FLAME;
852 self.effects &= ~EF_FLAME;
859 METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
862 TC(BallStealer, thiswep);
864 if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
865 if(autocvar_g_nexball_basketball_meter)
867 if(self.ballcarried && !self.metertime)
868 self.metertime = time;
870 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
874 W_Nexball_Attack(-1);
875 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
878 if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
881 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
884 if(!(fire & 1) && self.metertime && self.ballcarried)
886 W_Nexball_Attack(time - self.metertime);
887 // DropBall or stealing will set metertime back to 0
888 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
892 METHOD(BallStealer, wr_setup, void(BallStealer this))
894 TC(BallStealer, this);
895 //weapon_setup(WEP_PORTO.m_id);
898 METHOD(BallStealer, wr_checkammo1, bool(BallStealer this))
900 TC(BallStealer, this);
904 METHOD(BallStealer, wr_checkammo2, bool(BallStealer this))
906 TC(BallStealer, this);
910 void nb_DropBall(entity player)
912 if(player.ballcarried && g_nexball)
913 DropBall(player.ballcarried, player.origin, player.velocity);
916 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
922 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
924 nb_DropBall(frag_target);
928 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
934 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
936 makevectors(self.v_angle);
937 if(nexball_mode & NBM_BASKETBALL)
942 self.ballcarried.velocity = self.velocity;
943 self.ballcarried.customizeentityforclient = ball_customize;
945 vector org = self.origin + self.view_ofs +
946 v_forward * autocvar_g_nexball_viewmodel_offset.x +
947 v_right * autocvar_g_nexball_viewmodel_offset.y +
948 v_up * autocvar_g_nexball_viewmodel_offset.z;
949 setorigin(self.ballcarried, org);
952 if(autocvar_g_nexball_safepass_maxdist)
954 if(self.ballcarried.wait < time && self.ballcarried.enemy)
956 //centerprint(self, sprintf("Lost lock on %s", self.ballcarried.enemy.netname));
957 self.ballcarried.enemy = world;
961 //tracebox(self.origin + self.view_ofs, '-2 -2 -2', '2 2 2', self.origin + self.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
962 crosshair_trace(self);
964 IS_CLIENT(trace_ent) &&
965 !IS_DEAD(trace_ent) &&
966 trace_ent.team == self.team &&
967 vlen(trace_ent.origin - self.origin) <= autocvar_g_nexball_safepass_maxdist )
970 //if(self.ballcarried.enemy != trace_ent)
971 // centerprint(self, sprintf("Locked to %s", trace_ent.netname));
972 self.ballcarried.enemy = trace_ent;
973 self.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
981 .entity weaponentity = weaponentities[0]; // TODO
982 if(self.(weaponentity).weapons)
984 self.weapons = self.(weaponentity).weapons;
985 Weapon w = WEP_NEXBALL;
987 PS(self).m_switchweapon = self.(weaponentity).m_switchweapon;
988 W_SwitchWeapon(PS(self).m_switchweapon);
990 self.(weaponentity).weapons = '0 0 0';
1001 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
1004 this.metertime = other.metertime;
1007 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
1011 .entity weaponentity = weaponentities[0];
1012 this.(weaponentity).weapons = '0 0 0';
1014 if (nexball_mode & NBM_BASKETBALL)
1015 this.weapons |= WEPSET(NEXBALL);
1017 this.weapons = '0 0 0';
1022 .float stat_sv_airspeedlimit_nonqw;
1023 .float stat_sv_maxspeed;
1025 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
1027 if(self.ballcarried)
1029 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
1030 self.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
1035 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
1037 return PS(self).m_weapon == WEP_NEXBALL;
1040 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
1042 return PS(self).m_weapon == WEP_MORTAR; // TODO: what is this for?
1045 MUTATOR_HOOKFUNCTION(nb, FilterItem)
1047 if(self.classname == "droppedweapon")
1048 if(self.weapon == WEP_NEXBALL.m_id)
1054 MUTATOR_HOOKFUNCTION(nb, GetTeamCount)
1056 ret_string = "nexball_team";
1060 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
1062 ret_float = 0; // weapon is set a few lines later, apparently
1066 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
1068 if(frag_target.ballcarried)
1069 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
1074 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
1076 wp_sendflags &= ~0x80;
1080 REGISTER_MUTATOR(nb, g_nexball)
1084 g_nexball_meter_period = autocvar_g_nexball_meter_period;
1085 if(g_nexball_meter_period <= 0)
1086 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
1087 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
1091 CVTOV(g_nexball_football_boost_forward); //100
1092 CVTOV(g_nexball_football_boost_up); //200
1093 CVTOV(g_nexball_delay_idle); //10
1094 CVTOV(g_nexball_football_physics); //0
1096 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
1098 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
1099 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
1102 SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1);
1103 have_team_spawns = -1; // request team spawns
1106 MUTATOR_ONROLLBACK_OR_REMOVE
1108 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
1109 // we actually cannot roll back nb_delayedinit here
1110 // BUT: we don't need to! If this gets called, adding always
1116 LOG_INFO("This is a game type and it cannot be removed at runtime.");