1 //EF_BRIGHTFIELD|EF_BRIGHTLIGHT|EF_DIMLIGHT|EF_BLUE|EF_RED|EF_FLAME
2 #define BALL_EFFECTMASK 1229
3 #define BALL_MINS '-16 -16 -16' // The model is 24*24*24
4 #define BALL_MAXS '16 16 16'
5 #define BALL_ATTACHORG '3 0 16'
6 #define BALL_SPRITECOLOR '.91 .85 .62'
10 #define GOAL_TOUCHPLAYER 1
15 #define CVTOV(s) s = cvar( #s )
17 float g_nexball_football_boost_forward;
18 float g_nexball_football_boost_up;
19 float g_nexball_football_physics;
20 float g_nexball_delay_idle;
21 float g_nexball_basketball_delay_hold;
22 float g_nexball_basketball_delay_hold_forteam;
23 float g_nexball_basketball_effects_default;
24 float g_nexball_basketball_teamsteal;
31 void nb_delayedinit();
32 void nb_init() // Called early (worldspawn stage)
34 CVTOV(g_nexball_meter_period); //sent with the client init entity
35 if (g_nexball_meter_period <= 0)
36 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
37 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
38 addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
41 CVTOV(g_nexball_football_boost_forward); //100
42 CVTOV(g_nexball_football_boost_up); //200
43 CVTOV(g_nexball_delay_idle); //10
44 CVTOV(g_nexball_football_physics); //0
46 radar_showennemies = cvar("g_nexball_radar_showallplayers");
48 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
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");
62 void LogNB(string mode, entity actor)
65 if(!cvar("sv_eventlog"))
67 s = strcat(":nexball:", mode);
69 s = strcat(s, ":", ftos(actor.playerid));
73 void ball_restart (void)
76 DropBall(self, self.owner.origin, '0 0 0');
80 void nexball_setstatus (void)
87 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
89 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
91 self = self.ballcarried;
92 DropBall(self, self.owner.origin, '0 0 0');
96 self.items |= IT_KEY1;
100 void relocate_nexball (void)
102 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
103 if (trace_startsolid)
107 if(!move_out_of_solid(self))
108 objerror("could not get out of solid at all!");
109 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
110 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
111 print(" ", ftos(self.origin_y - o_y));
112 print(" ", ftos(self.origin_z - o_z), "'\n");
117 void basketball_touch();
118 void football_touch();
120 void DropOwner (void)
124 DropBall(self, ownr.origin, ownr.velocity);
125 makevectors(ownr.v_angle_y * '0 1 0');
126 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
127 ownr.flags &~= FL_ONGROUND;
130 void GiveBall (entity plyr, entity ball)
134 if ((ownr = ball.owner))
136 ownr.effects &~= g_nexball_basketball_effects_default;
137 ownr.ballcarried = world;
141 ownr.weaponentity.state = WS_READY;
143 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
147 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
150 setattachment(ball, plyr, "");
151 setorigin(ball, BALL_ATTACHORG);
153 if (ball.team != plyr.team)
154 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
156 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
157 ball.team = plyr.team;
158 plyr.ballcarried = ball;
159 ball.dropperid = plyr.playerid;
161 plyr.effects |= g_nexball_basketball_effects_default;
162 ball.effects &~= g_nexball_basketball_effects_default;
164 ball.velocity = '0 0 0';
165 ball.movetype = MOVETYPE_NONE;
166 ball.touch = SUB_Null;
167 ball.effects |= EF_NOSHADOW;
168 ball.scale = 1; // scale down.
170 WaypointSprite_AttachCarrier("nb-ball", plyr);
171 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
172 WaypointSprite_UpdateTeamRadar(plyr.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
174 if (g_nexball_basketball_delay_hold)
176 ball.think = DropOwner;
177 ball.nextthink = time + g_nexball_basketball_delay_hold;
181 void DropBall (entity ball, vector org, vector vel)
183 ball.effects |= g_nexball_basketball_effects_default;
184 ball.effects &~= EF_NOSHADOW;
185 ball.owner.effects &~= g_nexball_basketball_effects_default;
187 setattachment(ball, world, "");
188 setorigin (ball, org);
189 ball.movetype = MOVETYPE_BOUNCE;
190 ball.flags &~= FL_ONGROUND;
191 ball.scale = ball_scale;
193 ball.ctf_droptime = time;
194 ball.touch = basketball_touch;
195 ball.think = ResetBall;
196 ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
198 if (ball.owner.metertime)
200 ball.owner.metertime = 0;
201 ball.owner.weaponentity.state = WS_READY;
204 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
205 //WaypointSprite_AttachCarrier("nb-ball", ball);
206 WaypointSprite_Spawn("nb-ball", 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, FALSE); // no health bar please
207 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
208 WaypointSprite_UpdateTeamRadar(ball.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
210 ball.owner.ballcarried = world;
216 if (gameover) return;
217 self.flags &~= FL_ONGROUND;
218 self.movetype = MOVETYPE_BOUNCE;
219 if (self.classname == "nexball_basketball")
220 self.touch = basketball_touch;
221 else if (self.classname == "nexball_football")
222 self.touch = football_touch;
224 self.think = ResetBall;
225 self.nextthink = time + g_nexball_delay_idle + 3;
229 sound (self, CHAN_PROJECTILE, self.noise1, VOL_BASE, ATTN_NORM);
230 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
231 LogNB("init", world);
234 void ResetBall (void)
236 if (self.cnt < 2) { // step 1
237 if (time == self.teamtime)
238 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
239 self.touch = SUB_Null;
240 self.movetype = MOVETYPE_NOCLIP;
241 self.velocity = '0 0 0'; // just in case?
243 LogNB("resetidle", world);
245 self.nextthink = time;
246 } else if (self.cnt < 4) { // step 2 and 3
247 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
248 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
249 self.nextthink = time + 0.5;
252 // dprint("Step 4: time: ", ftos(time), "\n");
253 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
254 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
255 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
256 self.velocity = '0 0 0';
257 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
258 self.movetype = MOVETYPE_NONE;
259 self.think = InitBall;
260 self.nextthink = max(time, game_starttime) + cvar("g_nexball_delay_start");
264 void football_touch (void)
266 if (other.solid == SOLID_BSP) {
267 if (time > self.lastground + 0.1)
269 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
270 self.lastground = time;
272 if (vlen(self.velocity) && !self.cnt)
273 self.nextthink = time + g_nexball_delay_idle;
276 if (other.classname != "player")
278 if (other.health < 1)
281 self.nextthink = time + g_nexball_delay_idle;
284 self.team = other.team;
286 if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
287 if (vlen(other.velocity))
288 self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
289 } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
290 makevectors(other.v_angle);
291 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
292 } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
293 makevectors(other.v_angle_y * '0 1 0');
294 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
295 } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
296 makevectors(other.v_angle);
297 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
299 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
302 void basketball_touch (void)
304 if (other.ballcarried)
309 if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_nexball_delay_collect"))) {
310 if (other.health <= 0)
312 LogNB("caught", other);
313 GiveBall(other, self);
314 } else if (other.solid == SOLID_BSP) {
315 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
316 if (vlen(self.velocity) && !self.cnt)
317 self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
321 void GoalTouch (void)
324 float isclient, pscore, otherteam;
327 if (gameover) return;
328 if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
329 ball = other.ballcarried;
332 if (ball.classname != "nexball_basketball")
333 if (ball.classname != "nexball_football")
335 if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
341 otherteam = OtherTeam(ball.team);
343 if((isclient = ball.pusher.flags & FL_CLIENT))
344 pname = ball.pusher.netname;
346 pname = "Someone (?)";
348 if (ball.team == self.team) //owngoal (regular goals)
350 LogNB("owngoal", ball.pusher);
351 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
353 } else if (self.team == GOAL_FAULT) {
354 LogNB("fault", ball.pusher);
356 bprint(ColoredTeamName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
358 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
360 } else if (self.team == GOAL_OUT) {
361 LogNB("out", ball.pusher);
362 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
363 bprint(pname, "^7 went out of bounds.\n");
365 bprint("The ball was returned.\n");
368 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
369 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
373 sound (ball, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
375 if(ball.team && pscore)
377 if (nb_teams == 2 && pscore < 0)
378 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
380 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
385 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
387 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
390 if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
391 DropBall(ball, ball.owner.origin, ball.owner.velocity);
393 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
396 ball.think = ResetBall;
397 if (ball.classname == "nexball_basketball")
398 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
399 ball.nextthink = time + cvar("g_nexball_delay_goal") * (self.team != GOAL_OUT);
402 //=======================//
404 //=======================//
405 void spawnfunc_nexball_team (void)
407 if(!g_nexball) { remove(self); return; }
408 self.team = self.cnt + 1;
411 void nb_spawnteam (string teamname, float teamcolor)
413 dprint("^2spawned team ", teamname, "\n");
416 e.classname = "nexball_team";
417 e.netname = teamname;
423 void nb_spawnteams (void)
425 float t_r, t_b, t_y, t_p;
427 for(e = world; (e = find(e, classname, "nexball_goal")); )
431 case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1) ; t_r = 1; } break;
432 case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1) ; t_b = 1; } break;
433 case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
434 case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1) ; t_p = 1; } break;
439 void nb_delayedinit (void)
441 if (find(world, classname, "nexball_team") == world)
443 ScoreRules_nexball(nb_teams);
447 //=======================//
449 //=======================//
451 void SpawnBall (void)
453 if(!g_nexball) { remove(self); return; }
455 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
458 self.model = "models/nexball/ball.md3";
462 precache_model (self.model);
463 setmodel (self, self.model);
464 setsize (self, BALL_MINS, BALL_MAXS);
465 ball_scale = self.scale;
468 self.spawnorigin = self.origin;
470 self.effects = self.effects | EF_LOWPRECISION;
472 if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
474 self.glow_color = cvar("g_nexball_trail_color");
475 self.glow_trail = TRUE;
478 self.movetype = MOVETYPE_FLY;
480 if (!cvar("g_nexball_sound_bounce"))
482 else if (!self.noise)
483 self.noise = "sound/nexball/bounce.wav";
484 //bounce sound placeholder (FIXME)
486 self.noise1 = "sound/nexball/drop.wav";
487 //ball drop sound placeholder (FIXME)
489 self.noise2 = "sound/nexball/steal.wav";
490 //stealing sound placeholder (FIXME)
491 if (self.noise) precache_sound (self.noise);
492 precache_sound (self.noise1);
493 precache_sound (self.noise2);
495 WaypointSprite_AttachCarrier("nb-ball", self); // the ball's team is not set yet, no rule update needed
496 WaypointSprite_UpdateTeamRadar(self.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
498 self.reset = ball_restart;
499 self.think = InitBall;
500 self.nextthink = game_starttime + cvar("g_nexball_delay_start");
503 void spawnfunc_nexball_basketball (void)
505 self.classname = "nexball_basketball";
506 if not(balls & BALL_BASKET)
508 CVTOV(g_nexball_basketball_effects_default);
509 CVTOV(g_nexball_basketball_delay_hold);
510 CVTOV(g_nexball_basketball_delay_hold_forteam);
511 CVTOV(g_nexball_basketball_teamsteal);
512 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
515 self.effects = g_nexball_basketball_effects_default;
516 self.solid = SOLID_TRIGGER;
517 balls |= BALL_BASKET;
518 self.bouncefactor = cvar("g_nexball_basketball_bouncefactor");
519 self.bouncestop = cvar("g_nexball_basketball_bouncestop");
523 void spawnfunc_nexball_football (void)
525 self.classname = "nexball_football";
526 self.solid = SOLID_TRIGGER;
528 self.bouncefactor = cvar("g_nexball_football_bouncefactor");
529 self.bouncestop = cvar("g_nexball_football_bouncestop");
533 void SpawnGoal (void)
535 if(!g_nexball) { remove(self); return; }
537 self.classname = "nexball_goal";
539 self.noise = "ctf/respawn.wav";
540 precache_sound(self.noise);
541 self.touch = GoalTouch;
544 void spawnfunc_nexball_redgoal (void)
546 self.team = COLOR_TEAM1;
549 void spawnfunc_nexball_bluegoal (void)
551 self.team = COLOR_TEAM2;
554 void spawnfunc_nexball_yellowgoal (void)
556 self.team = COLOR_TEAM3;
559 void spawnfunc_nexball_pinkgoal (void)
561 self.team = COLOR_TEAM4;
565 void spawnfunc_nexball_fault (void)
567 self.team = GOAL_FAULT;
569 self.noise = "misc/typehit.wav";
573 void spawnfunc_nexball_out (void)
575 self.team = GOAL_OUT;
577 self.noise = "misc/typehit.wav";
582 //Spawnfuncs preserved for compatibility
585 void spawnfunc_ball (void) { spawnfunc_nexball_football(); }
586 void spawnfunc_ball_football (void) { spawnfunc_nexball_football(); }
587 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
588 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
589 void spawnfunc_ball_redgoal (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
590 void spawnfunc_ball_bluegoal (void) { spawnfunc_nexball_redgoal(); } // but he didn't mean to cause trouble :p
591 void spawnfunc_ball_fault (void) { spawnfunc_nexball_fault(); }
592 void spawnfunc_ball_bound (void) { spawnfunc_nexball_out(); }
594 //=======================//
596 //=======================//
598 void W_Nexball_Touch (void)
600 local entity ball, attacker;
601 attacker = self.owner;
604 if(attacker.team != other.team || g_nexball_basketball_teamsteal)
605 if((ball = other.ballcarried) && (attacker.classname == "player" || attacker.classname == "gib"))
607 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * cvar("g_balance_nexball_secondary_force");
608 other.flags &~= FL_ONGROUND;
609 if(!attacker.ballcarried)
611 LogNB("stole", attacker);
612 sound (other, CHAN_AUTO, ball.noise2, VOL_BASE, ATTN_NORM);
614 if(attacker.team == other.team && time > attacker.teamkill_complain)
616 attacker.teamkill_complain = time + 5;
617 attacker.teamkill_soundtime = time + 0.4;
618 attacker.teamkill_soundsource = other;
621 GiveBall(attacker, other.ballcarried);
627 void W_Nexball_Attack (float t)
630 local float mul, mi, ma;
631 if (!(ball = self.ballcarried))
634 W_SetupShot (self, FALSE, 4, "nexball/shoot1.wav",0);
635 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
639 self.metertime = 0; // Shot failed, hide the power meter
643 //Calculate multiplier
648 mi = cvar("g_nexball_basketball_meter_minpower");
649 ma = max(mi, cvar("g_nexball_basketball_meter_maxpower")); // avoid confusion
650 //One triangle wave period with 1 as max
651 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
654 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
656 DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * cvar("g_balance_nexball_primary_speed") * mul, FALSE));
657 //TODO: use the speed_up cvar too ??
660 void W_Nexball_Attack2 (void)
662 local entity missile;
663 if (!(balls & BALL_BASKET))
665 W_SetupShot (self, FALSE, 2, "nexball/shoot2.wav",0);
666 // pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
669 missile.owner = self;
670 missile.classname = "ballstealer";
672 missile.movetype = MOVETYPE_FLY;
673 PROJECTILE_MAKETRIGGER(missile);
675 setmodel (missile, "models/elaser.mdl"); // precision set below
676 setsize (missile, '0 0 0', '0 0 0');
677 setorigin (missile, w_shotorg);
679 W_SetupProjectileVelocity(missile, cvar("g_balance_nexball_secondary_speed"), 0);
680 missile.angles = vectoangles (missile.velocity);
681 missile.touch = W_Nexball_Touch;
682 missile.think = SUB_Remove;
683 missile.nextthink = time + cvar("g_balance_nexball_secondary_lifetime"); //FIXME: use a distance instead?
685 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
686 missile.flags = FL_PROJECTILE;
689 float w_nexball_weapon(float req)
693 if (self.BUTTON_ATCK)
694 if (weapon_prepareattack(0, cvar("g_balance_nexball_primary_refire")))
695 if (cvar("g_nexball_basketball_meter"))
697 if (self.ballcarried && !self.metertime)
698 self.metertime = time;
700 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
704 W_Nexball_Attack(-1);
705 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
707 if (self.BUTTON_ATCK2)
708 if (weapon_prepareattack(1, cvar("g_balance_nexball_secondary_refire")))
711 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_nexball_secondary_animtime"), w_ready);
714 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
716 W_Nexball_Attack(time - self.metertime);
717 // DropBall or stealing will set metertime back to 0
718 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
721 else if (req == WR_PRECACHE)
723 precache_model ("models/weapons/g_porto.md3");
724 precache_model ("models/weapons/v_porto.md3");
725 precache_model ("models/weapons/h_porto.dpm");
726 precache_model ("models/elaser.mdl");
727 precache_sound ("nexball/shoot1.wav");
728 precache_sound ("nexball/shoot2.wav");
730 else if (req == WR_SETUP)
731 weapon_setup(WEP_PORTO);
732 else if (req == WR_SUICIDEMESSAGE)
734 w_deathtypestring = "is a weirdo";
736 else if (req == WR_KILLMESSAGE)
738 w_deathtypestring = "got killed by #'s black magic";
740 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE