1 void basketball_touch();
5 float OtherTeam(float t) //works only if there are two teams on the map!
8 e = find(world, classname, "nexball_team");
10 e = find(e, classname, "nexball_team");
15 void LogNB(string mode, entity actor)
18 if(!autocvar_sv_eventlog)
20 s = strcat(":nexball:", mode);
22 s = strcat(s, ":", ftos(actor.playerid));
26 void ball_restart(void)
29 DropBall(self, self.owner.origin, '0 0 0');
33 void nexball_setstatus(void)
36 self.items &~= IT_KEY1;
39 if(self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
41 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
43 self = self.ballcarried;
44 DropBall(self, self.owner.origin, '0 0 0');
49 self.items |= IT_KEY1;
53 void relocate_nexball(void)
55 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
60 if(!move_out_of_solid(self))
61 objerror("could not get out of solid at all!");
62 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
63 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
64 print(" ", ftos(self.origin_y - o_y));
65 print(" ", ftos(self.origin_z - o_z), "'\n");
74 DropBall(self, ownr.origin, ownr.velocity);
75 makevectors(ownr.v_angle_y * '0 1 0');
76 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
77 ownr.flags &~= FL_ONGROUND;
80 void GiveBall(entity plyr, entity ball)
84 if((ownr = ball.owner))
86 ownr.effects &~= autocvar_g_nexball_basketball_effects_default;
87 ownr.ballcarried = world;
91 ownr.weaponentity.state = WS_READY;
93 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
97 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
100 setattachment(ball, plyr, "");
101 setorigin(ball, BALL_ATTACHORG);
103 if(ball.team != plyr.team)
104 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
106 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
107 ball.team = plyr.team;
108 plyr.ballcarried = ball;
109 ball.dropperid = plyr.playerid;
111 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
112 ball.effects &~= autocvar_g_nexball_basketball_effects_default;
114 ball.velocity = '0 0 0';
115 ball.movetype = MOVETYPE_NONE;
116 ball.touch = SUB_Null;
117 ball.effects |= EF_NOSHADOW;
118 ball.scale = 1; // scale down.
120 WaypointSprite_AttachCarrier("nb-ball", plyr, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
121 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
123 if(autocvar_g_nexball_basketball_delay_hold)
125 ball.think = DropOwner;
126 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
130 void DropBall(entity ball, vector org, vector vel)
132 ball.effects |= autocvar_g_nexball_basketball_effects_default;
133 ball.effects &~= EF_NOSHADOW;
134 ball.owner.effects &~= autocvar_g_nexball_basketball_effects_default;
136 setattachment(ball, world, "");
137 setorigin(ball, org);
138 ball.movetype = MOVETYPE_BOUNCE;
139 ball.flags &~= FL_ONGROUND;
140 ball.scale = ball_scale;
142 ball.ctf_droptime = time;
143 ball.touch = basketball_touch;
144 ball.think = ResetBall;
145 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
147 if(ball.owner.metertime)
149 ball.owner.metertime = 0;
150 ball.owner.weaponentity.state = WS_READY;
153 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
154 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
155 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
157 ball.owner.ballcarried = world;
164 self.flags &~= FL_ONGROUND;
165 self.movetype = MOVETYPE_BOUNCE;
166 if(self.classname == "nexball_basketball")
167 self.touch = basketball_touch;
168 else if(self.classname == "nexball_football")
169 self.touch = football_touch;
171 self.think = ResetBall;
172 self.nextthink = time + autocvar_g_nexball_delay_idle + 3;
176 sound(self, CH_TRIGGER, self.noise1, VOL_BASE, ATTN_NORM);
177 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
178 LogNB("init", world);
183 if(self.cnt < 2) // step 1
185 if(time == self.teamtime)
186 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
187 self.touch = SUB_Null;
188 self.movetype = MOVETYPE_NOCLIP;
189 self.velocity = '0 0 0'; // just in case?
191 LogNB("resetidle", world);
193 self.nextthink = time;
195 else if(self.cnt < 4) // step 2 and 3
197 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
198 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
199 self.nextthink = time + 0.5;
204 // dprint("Step 4: time: ", ftos(time), "\n");
205 if(vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
206 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
207 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
208 self.velocity = '0 0 0';
209 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
210 self.movetype = MOVETYPE_NONE;
211 self.think = InitBall;
212 self.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
216 void football_touch(void)
218 if(other.solid == SOLID_BSP)
220 if(time > self.lastground + 0.1)
222 sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
223 self.lastground = time;
225 if(vlen(self.velocity) && !self.cnt)
226 self.nextthink = time + autocvar_g_nexball_delay_idle;
229 if(other.classname != "player")
234 self.nextthink = time + autocvar_g_nexball_delay_idle;
237 self.team = other.team;
239 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
241 if(vlen(other.velocity))
242 self.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
244 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
246 makevectors(other.v_angle);
247 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
249 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
251 makevectors(other.v_angle_y * '0 1 0');
252 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
254 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
256 makevectors(other.v_angle);
257 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
259 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
262 void basketball_touch(void)
264 if(other.ballcarried)
269 if(!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_nexball_delay_collect))
271 if(other.health <= 0)
273 LogNB("caught", other);
274 GiveBall(other, self);
276 else if(other.solid == SOLID_BSP)
278 sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
279 if(vlen(self.velocity) && !self.cnt)
280 self.nextthink = min(time + autocvar_g_nexball_delay_idle, self.teamtime);
287 float isclient, pscore, otherteam;
291 if((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
292 ball = other.ballcarried;
295 if(ball.classname != "nexball_basketball")
296 if(ball.classname != "nexball_football")
298 if((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
304 otherteam = OtherTeam(ball.team);
306 if((isclient = ball.pusher.flags & FL_CLIENT))
307 pname = ball.pusher.netname;
309 pname = "Someone (?)";
311 if(ball.team == self.team) //owngoal (regular goals)
313 LogNB("owngoal", ball.pusher);
314 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
317 else if(self.team == GOAL_FAULT)
319 LogNB("fault", ball.pusher);
321 bprint(ColoredTeamName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
323 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
326 else if(self.team == GOAL_OUT)
328 LogNB("out", ball.pusher);
329 if((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
330 bprint(pname, "^7 went out of bounds.\n");
332 bprint("The ball was returned.\n");
337 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
338 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
342 sound(ball, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NONE);
344 if(ball.team && pscore)
346 if(nb_teams == 2 && pscore < 0)
347 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
349 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
354 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
356 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
359 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
360 DropBall(ball, ball.owner.origin, ball.owner.velocity);
362 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
365 ball.think = ResetBall;
366 if(ball.classname == "nexball_basketball")
367 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
368 ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
371 //=======================//
373 //=======================//
374 void spawnfunc_nexball_team(void)
381 self.team = self.cnt + 1;
384 void nb_spawnteam(string teamname, float teamcolor)
386 dprint("^2spawned team ", teamname, "\n");
389 e.classname = "nexball_team";
390 e.netname = teamname;
396 void nb_spawnteams(void)
398 float t_r, t_b, t_y, t_p;
400 for(e = world; (e = find(e, classname, "nexball_goal"));)
407 nb_spawnteam("Red", e.team-1) ;
414 nb_spawnteam("Blue", e.team-1) ;
421 nb_spawnteam("Yellow", e.team-1);
428 nb_spawnteam("Pink", e.team-1) ;
436 void nb_delayedinit(void)
438 if(find(world, classname, "nexball_team") == world)
440 ScoreRules_nexball(nb_teams);
444 //=======================//
446 //=======================//
456 // 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)
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;
544 self.classname = "nexball_goal";
546 self.noise = "ctf/respawn.wav";
547 precache_sound(self.noise);
548 self.touch = GoalTouch;
551 void spawnfunc_nexball_redgoal(void)
553 self.team = COLOR_TEAM1;
556 void spawnfunc_nexball_bluegoal(void)
558 self.team = COLOR_TEAM2;
561 void spawnfunc_nexball_yellowgoal(void)
563 self.team = COLOR_TEAM3;
566 void spawnfunc_nexball_pinkgoal(void)
568 self.team = COLOR_TEAM4;
572 void spawnfunc_nexball_fault(void)
574 self.team = GOAL_FAULT;
576 self.noise = "misc/typehit.wav";
580 void spawnfunc_nexball_out(void)
582 self.team = GOAL_OUT;
584 self.noise = "misc/typehit.wav";
589 //Spawnfuncs preserved for compatibility
592 void spawnfunc_ball(void)
594 spawnfunc_nexball_football();
596 void spawnfunc_ball_football(void)
598 spawnfunc_nexball_football();
600 void spawnfunc_ball_basketball(void)
602 spawnfunc_nexball_basketball();
604 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
605 void spawnfunc_ball_redgoal(void)
607 spawnfunc_nexball_bluegoal(); // I blame Revenant
609 void spawnfunc_ball_bluegoal(void)
611 spawnfunc_nexball_redgoal(); // but he didn't mean to cause trouble :p
613 void spawnfunc_ball_fault(void)
615 spawnfunc_nexball_fault();
617 void spawnfunc_ball_bound(void)
619 spawnfunc_nexball_out();
622 //=======================//
624 //=======================//
626 void W_Nexball_Touch(void)
628 entity ball, attacker;
629 attacker = self.owner;
632 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
633 if((ball = other.ballcarried) && (attacker.classname == "player"))
635 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
636 other.flags &~= FL_ONGROUND;
637 if(!attacker.ballcarried)
639 LogNB("stole", attacker);
640 sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTN_NORM);
642 if(attacker.team == other.team && time > attacker.teamkill_complain)
644 attacker.teamkill_complain = time + 5;
645 attacker.teamkill_soundtime = time + 0.4;
646 attacker.teamkill_soundsource = other;
649 GiveBall(attacker, other.ballcarried);
655 void W_Nexball_Attack(float t)
659 if(!(ball = self.ballcarried))
662 W_SetupShot(self, FALSE, 4, "nexball/shoot1.wav", CH_WEAPON_A, 0);
663 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
667 self.metertime = 0; // Shot failed, hide the power meter
671 //Calculate multiplier
676 mi = autocvar_g_nexball_basketball_meter_minpower;
677 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
678 //One triangle wave period with 1 as max
679 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
682 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
684 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, FALSE));
685 //TODO: use the speed_up cvar too ??
688 void W_Nexball_Attack2(void)
691 if(!(balls & BALL_BASKET))
693 W_SetupShot(self, FALSE, 2, "nexball/shoot2.wav", CH_WEAPON_A, 0);
694 // pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
697 missile.owner = self;
698 missile.classname = "ballstealer";
700 missile.movetype = MOVETYPE_FLY;
701 PROJECTILE_MAKETRIGGER(missile);
703 setmodel(missile, "models/elaser.mdl"); // precision set below
704 setsize(missile, '0 0 0', '0 0 0');
705 setorigin(missile, w_shotorg);
707 W_SetupProjectileVelocity(missile, autocvar_g_balance_nexball_secondary_speed, 0);
708 missile.angles = vectoangles(missile.velocity);
709 missile.touch = W_Nexball_Touch;
710 missile.think = SUB_Remove;
711 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
713 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
714 missile.flags = FL_PROJECTILE;
717 float w_nexball_weapon(float req)
722 if(weapon_prepareattack(0, autocvar_g_balance_nexball_primary_refire))
723 if(autocvar_g_nexball_basketball_meter)
725 if(self.ballcarried && !self.metertime)
726 self.metertime = time;
728 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
732 W_Nexball_Attack(-1);
733 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
735 if(self.BUTTON_ATCK2)
736 if(weapon_prepareattack(1, autocvar_g_balance_nexball_secondary_refire))
739 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
742 if(!self.BUTTON_ATCK && self.metertime && self.ballcarried)
744 W_Nexball_Attack(time - self.metertime);
745 // DropBall or stealing will set metertime back to 0
746 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
749 else if(req == WR_PRECACHE)
751 precache_model("models/weapons/g_porto.md3");
752 precache_model("models/weapons/v_porto.md3");
753 precache_model("models/weapons/h_porto.iqm");
754 precache_model("models/elaser.mdl");
755 precache_sound("nexball/shoot1.wav");
756 precache_sound("nexball/shoot2.wav");
757 precache_sound("misc/typehit.wav");
759 else if(req == WR_SETUP)
760 weapon_setup(WEP_PORTO);
761 else if(req == WR_SUICIDEMESSAGE)
763 w_deathtypestring = "is a weirdo";
765 else if(req == WR_KILLMESSAGE)
767 w_deathtypestring = "got killed by #'s black magic";
769 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE
773 MUTATOR_HOOKFUNCTION(nexball_BallDrop)
775 if(self.ballcarried && g_nexball)
776 DropBall(self.ballcarried, self.origin, self.velocity);
781 MUTATOR_HOOKFUNCTION(nexball_BuildMutatorsString)
783 ret_string = strcat(ret_string, ":NB");
787 MUTATOR_HOOKFUNCTION(nexball_BuildMutatorsPrettyString)
789 ret_string = strcat(ret_string, ", NexBall");
793 MUTATOR_DEFINITION(gamemode_nexball)
795 MUTATOR_HOOK(PlayerDies, nexball_BallDrop, CBC_ORDER_ANY);
796 MUTATOR_HOOK(MakePlayerObserver, nexball_BallDrop, CBC_ORDER_ANY);
797 MUTATOR_HOOK(ClientDisconnect, nexball_BallDrop, CBC_ORDER_ANY);
798 MUTATOR_HOOK(BuildMutatorsPrettyString, nexball_BuildMutatorsPrettyString, CBC_ORDER_ANY);
799 MUTATOR_HOOK(BuildMutatorsString, nexball_BuildMutatorsString, CBC_ORDER_ANY);
803 g_nexball_meter_period = autocvar_g_nexball_meter_period;
804 if(g_nexball_meter_period <= 0)
805 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
806 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
807 addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
811 CVTOV(g_nexball_football_boost_forward); //100
812 CVTOV(g_nexball_football_boost_up); //200
813 CVTOV(g_nexball_delay_idle); //10
814 CVTOV(g_nexball_football_physics); //0
816 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
818 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);