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;
30 void nb_delayedinit();
31 void nb_init() // Called early (worldspawn stage)
33 CVTOV(g_nexball_meter_period); //sent with the client init entity
34 if (g_nexball_meter_period <= 0)
35 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
36 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
37 addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
40 CVTOV(g_nexball_football_boost_forward); //100
41 CVTOV(g_nexball_football_boost_up); //200
42 CVTOV(g_nexball_delay_idle); //10
43 CVTOV(g_nexball_football_physics); //0
45 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
50 void LogNB(string mode, entity actor)
53 if(!cvar("sv_eventlog"))
55 s = strcat(":nexball:", mode);
57 s = strcat(s, ":", ftos(actor.playerid));
61 void ball_restart (void)
64 DropBall(self, self.owner.origin, '0 0 0');
68 void nexball_setstatus (void)
75 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
77 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
79 self = self.ballcarried;
80 DropBall(self, self.owner.origin, '0 0 0');
84 self.items |= IT_KEY1;
88 void relocate_nexball (void)
90 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
95 if(!move_out_of_solid(self))
96 objerror("could not get out of solid at all!");
97 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
98 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
99 print(" ", ftos(self.origin_y - o_y));
100 print(" ", ftos(self.origin_z - o_z), "'\n");
105 void basketball_touch();
106 void football_touch();
108 void DropOwner (void)
112 DropBall(self, ownr.origin, ownr.velocity);
113 makevectors(ownr.v_angle_y * '0 1 0');
114 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
115 ownr.flags &~= FL_ONGROUND;
118 void GiveBall (entity plyr, entity ball)
122 if ((ownr = ball.owner))
124 ownr.effects &~= g_nexball_basketball_effects_default;
125 ownr.ballcarried = world;
129 ownr.weaponentity.state = WS_READY;
133 setattachment(ball, plyr, "");
134 setorigin(ball, BALL_ATTACHORG);
136 if (ball.team != plyr.team)
137 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
139 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
140 ball.team = plyr.team;
141 plyr.ballcarried = ball;
142 ball.dropperid = plyr.playerid;
144 plyr.effects |= g_nexball_basketball_effects_default;
145 ball.effects &~= g_nexball_basketball_effects_default;
147 ball.velocity = '0 0 0';
148 ball.movetype = MOVETYPE_NONE;
149 ball.touch = SUB_Null;
150 ball.effects |= EF_NOSHADOW;
151 ball.scale = 1; // scale down.
153 ball.waypointsprite_attachedforcarrier.exteriormodeltoclient = plyr;
155 if (g_nexball_basketball_delay_hold)
157 ball.think = DropOwner;
158 ball.nextthink = time + g_nexball_basketball_delay_hold;
162 void DropBall (entity ball, vector org, vector vel)
164 ball.effects |= g_nexball_basketball_effects_default;
165 ball.effects &~= EF_NOSHADOW;
166 ball.owner.effects &~= g_nexball_basketball_effects_default;
168 setattachment(ball, world, "");
169 setorigin (ball, org);
170 ball.movetype = MOVETYPE_BOUNCE;
171 ball.flags &~= FL_ONGROUND;
172 ball.scale = ball_scale;
174 ball.ctf_droptime = time;
175 ball.touch = basketball_touch;
176 ball.think = ResetBall;
177 ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
179 if (ball.owner.metertime)
181 ball.owner.metertime = 0;
182 ball.owner.weaponentity.state = WS_READY;
185 ball.waypointsprite_attachedforcarrier.exteriormodeltoclient = world;
187 ball.owner.ballcarried = world;
193 if (gameover) return;
194 self.flags &~= FL_ONGROUND;
195 self.movetype = MOVETYPE_BOUNCE;
196 if (self.classname == "nexball_basketball")
197 self.touch = basketball_touch;
198 else if (self.classname == "nexball_football")
199 self.touch = football_touch;
201 self.think = ResetBall;
202 self.nextthink = time + g_nexball_delay_idle + 3;
206 sound (self, CHAN_PROJECTILE, self.noise1, VOL_BASE, ATTN_NORM);
207 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
208 LogNB("init", world);
211 void ResetBall (void)
213 if (self.cnt < 2) { // step 1
214 if (time == self.teamtime)
215 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
216 self.touch = SUB_Null;
217 self.movetype = MOVETYPE_NOCLIP;
218 self.velocity = '0 0 0'; // just in case?
220 LogNB("resetidle", world);
222 self.nextthink = time;
223 } else if (self.cnt < 4) { // step 2 and 3
224 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
225 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
226 self.nextthink = time + 0.5;
229 // dprint("Step 4: time: ", ftos(time), "\n");
230 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
231 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
232 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
233 self.velocity = '0 0 0';
234 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
235 self.movetype = MOVETYPE_NONE;
236 self.think = InitBall;
237 self.nextthink = max(time, game_starttime) + cvar("g_nexball_delay_start");
241 void football_touch (void)
243 if (other.solid == SOLID_BSP) {
244 if (time > self.lastground + 0.1)
246 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
247 self.lastground = time;
249 if (vlen(self.velocity) && !self.cnt)
250 self.nextthink = time + g_nexball_delay_idle;
253 if (other.classname != "player")
255 if (other.health < 1)
258 self.nextthink = time + g_nexball_delay_idle;
261 self.team = other.team;
263 if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
264 if (vlen(other.velocity))
265 self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
266 } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
267 makevectors(other.v_angle);
268 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
269 } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
270 makevectors(other.v_angle_y * '0 1 0');
271 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
272 } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
273 makevectors(other.v_angle);
274 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
276 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
279 void basketball_touch (void)
281 if (other.ballcarried)
286 if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_nexball_delay_collect"))) {
287 if (other.health <= 0)
289 LogNB("caught", other);
290 GiveBall(other, self);
291 } else if (other.solid == SOLID_BSP) {
292 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
293 if (vlen(self.velocity) && !self.cnt)
294 self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
298 void GoalTouch (void)
301 float isclient, pscore;
304 if (gameover) return;
305 if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
306 ball = other.ballcarried;
309 if (ball.classname != "nexball_basketball")
310 if (ball.classname != "nexball_football")
312 if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
317 if((isclient = ball.pusher.flags & FL_CLIENT))
318 pname = ball.pusher.netname;
320 pname = "Someone (?)";
322 if (ball.team == self.team) //owngoal (regular goals)
324 LogNB("owngoal", ball.pusher);
325 bprint("Boo! ", pname, "^7 scored a goal against his own team!\n");
327 } else if (self.team == GOAL_FAULT) {
328 LogNB("fault", ball.pusher);
329 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
331 } else if (self.team == GOAL_OUT) {
332 LogNB("out", ball.pusher);
333 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
334 bprint(pname, "^7 went out of bounds.\n");
336 bprint("The ball was returned.\n");
339 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
340 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
344 sound (ball, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
346 if(ball.team && pscore)
347 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
348 if (isclient && pscore > 0)
349 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
350 else if (isclient && pscore < 0)
351 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, pscore);
353 if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
354 DropBall(ball, ball.owner.origin, ball.owner.velocity);
356 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
359 ball.think = ResetBall;
360 if (ball.classname == "nexball_basketball")
361 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
362 ball.nextthink = time + cvar("g_nexball_delay_goal") * (self.team != GOAL_OUT);
365 //=======================//
367 //=======================//
368 void spawnfunc_nexball_team (void)
370 if(!g_nexball) { remove(self); return; }
371 self.team = self.cnt + 1;
374 void nb_spawnteam (string teamname, float teamcolor)
376 dprint("^2spawned team ", teamname, "\n");
379 e.classname = "nexball_team";
380 e.netname = teamname;
385 void nb_spawnteams (void)
387 float t_r, t_b, t_y, t_p;
389 for(e = world; (e = find(e, classname, "nexball_goal")); )
393 case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1) ; t_r = 1; } break;
394 case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1) ; t_b = 1; } break;
395 case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
396 case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1) ; t_p = 1; } break;
401 void nb_delayedinit (void)
403 if (find(world, classname, "nexball_team") == world)
405 ScoreRules_nexball();
409 //=======================//
411 //=======================//
413 void SpawnBall (void)
415 if(!g_nexball) { remove(self); return; }
417 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
420 self.model = "models/nexball/ball.md3";
424 precache_model (self.model);
425 setmodel (self, self.model);
426 setsize (self, BALL_MINS, BALL_MAXS);
427 ball_scale = self.scale;
430 self.spawnorigin = self.origin;
432 self.effects = self.effects | EF_LOWPRECISION;
434 if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
436 self.glow_color = cvar("g_nexball_trail_color");
437 self.glow_trail = TRUE;
440 self.movetype = MOVETYPE_FLY;
442 if (!cvar("g_nexball_sound_bounce"))
444 else if (!self.noise)
445 self.noise = "sound/nexball/bounce.wav";
446 //bounce sound placeholder (FIXME)
448 self.noise1 = "sound/nexball/drop.wav";
449 //ball drop sound placeholder (FIXME)
451 self.noise2 = "sound/nexball/steal.wav";
452 //stealing sound placeholder (FIXME)
453 if (self.noise) precache_sound (self.noise);
454 precache_sound (self.noise1);
455 precache_sound (self.noise2);
457 WaypointSprite_AttachCarrier("nb-ball", self); // the ball's team is not set yet, no rule update needed
458 WaypointSprite_UpdateTeamRadar(self.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
460 self.reset = ball_restart;
461 self.think = InitBall;
462 self.nextthink = game_starttime + cvar("g_nexball_delay_start");
465 void spawnfunc_nexball_basketball (void)
467 self.classname = "nexball_basketball";
468 if(!balls & BALL_BASKET)
470 CVTOV(g_nexball_basketball_effects_default);
471 CVTOV(g_nexball_basketball_delay_hold);
472 CVTOV(g_nexball_basketball_delay_hold_forteam);
473 CVTOV(g_nexball_basketball_teamsteal);
474 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
477 self.effects = g_nexball_basketball_effects_default;
478 self.solid = SOLID_TRIGGER;
479 balls |= BALL_BASKET;
480 self.bouncefactor = cvar("g_nexball_basketball_bouncefactor");
481 self.bouncestop = cvar("g_nexball_basketball_bouncestop");
485 void spawnfunc_nexball_football (void)
487 self.classname = "nexball_football";
488 self.solid = SOLID_TRIGGER;
490 self.bouncefactor = cvar("g_nexball_football_bouncefactor");
491 self.bouncestop = cvar("g_nexball_football_bouncestop");
495 void SpawnGoal (void)
497 if(!g_nexball) { remove(self); return; }
499 self.classname = "nexball_goal";
501 self.noise = "ctf/respawn.wav";
502 precache_sound(self.noise);
503 self.touch = GoalTouch;
506 void spawnfunc_nexball_redgoal (void)
508 self.team = COLOR_TEAM1;
511 void spawnfunc_nexball_bluegoal (void)
513 self.team = COLOR_TEAM2;
516 void spawnfunc_nexball_yellowgoal (void)
518 self.team = COLOR_TEAM3;
521 void spawnfunc_nexball_pinkgoal (void)
523 self.team = COLOR_TEAM4;
527 void spawnfunc_nexball_fault (void)
529 self.team = GOAL_FAULT;
531 self.noise = "misc/typehit.wav";
535 void spawnfunc_nexball_out (void)
537 self.team = GOAL_OUT;
539 self.noise = "misc/typehit.wav";
544 //Spawnfuncs preserved for compatibility
547 void spawnfunc_ball (void) { spawnfunc_nexball_football(); }
548 void spawnfunc_ball_football (void) { spawnfunc_nexball_football(); }
549 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
550 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
551 void spawnfunc_ball_redgoal (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
552 void spawnfunc_ball_bluegoal (void) { spawnfunc_nexball_redgoal(); } // but he didn't mean to cause trouble :p
553 void spawnfunc_ball_fault (void) { spawnfunc_nexball_fault(); }
554 void spawnfunc_ball_bound (void) { spawnfunc_nexball_out(); }
556 //=======================//
558 //=======================//
560 void W_Nexball_Touch (void)
562 local entity ball, attacker;
563 attacker = self.owner;
566 if(attacker.team != other.team || g_nexball_basketball_teamsteal)
567 if((ball = other.ballcarried) && (attacker.classname == "player" || attacker.classname == "gib"))
569 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * cvar("g_balance_nexball_secondary_force");
570 other.flags &~= FL_ONGROUND;
571 if(!attacker.ballcarried)
573 LogNB("stole", attacker);
574 sound (other, CHAN_AUTO, ball.noise2, VOL_BASE, ATTN_NORM);
576 if(attacker.team == other.team && time > attacker.teamkill_complain)
578 attacker.teamkill_complain = time + 5;
579 attacker.teamkill_soundtime = time + 0.4;
580 attacker.teamkill_soundsource = other;
583 GiveBall(attacker, other.ballcarried);
589 void W_Nexball_Attack (float t)
592 local float mul, mi, ma;
593 if (!(ball = self.ballcarried))
596 W_SetupShot (self, FALSE, 4, "nexball/shoot1.wav",0);
597 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
601 self.metertime = 0; // Shot failed, hide the power meter
605 //Calculate multiplier
610 mi = cvar("g_nexball_basketball_meter_minpower");
611 ma = max(mi, cvar("g_nexball_basketball_meter_maxpower")); // avoid confusion
612 //One triangle wave period with 1 as max
613 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
616 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
618 DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * cvar("g_balance_nexball_primary_speed") * mul));
619 //TODO: use the speed_up cvar too ??
622 void W_Nexball_Attack2 (void)
624 local entity missile;
625 if (!(balls & BALL_BASKET))
627 W_SetupShot (self, FALSE, 2, "nexball/shoot2.wav",0);
628 // pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
631 missile.owner = self;
632 missile.classname = "ballstealer";
634 missile.movetype = MOVETYPE_FLY;
635 missile.solid = SOLID_BBOX;
637 setmodel (missile, "models/elaser.mdl"); // precision set below
638 setsize (missile, '0 0 0', '0 0 0');
639 setorigin (missile, w_shotorg);
641 missile.velocity = w_shotdir * cvar("g_balance_nexball_secondary_speed");
642 W_SetupProjectileVelocity(missile);
643 missile.angles = vectoangles (missile.velocity);
644 missile.touch = W_Nexball_Touch;
645 missile.think = SUB_Remove;
646 missile.nextthink = time + cvar("g_balance_nexball_secondary_lifetime"); //FIXME: use a distance instead?
648 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
649 missile.flags = FL_PROJECTILE;
652 float w_nexball_weapon(float req)
656 if (self.BUTTON_ATCK)
657 if (weapon_prepareattack(0, cvar("g_balance_nexball_primary_refire")))
658 if (cvar("g_nexball_basketball_meter"))
660 if (self.ballcarried && !self.metertime)
661 self.metertime = time;
663 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
667 W_Nexball_Attack(-1);
668 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
670 if (self.BUTTON_ATCK2)
671 if (weapon_prepareattack(1, cvar("g_balance_nexball_secondary_refire")))
674 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_nexball_secondary_animtime"), w_ready);
677 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
679 W_Nexball_Attack(time - self.metertime);
680 // DropBall or stealing will set metertime back to 0
681 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
684 else if (req == WR_PRECACHE)
686 precache_model ("models/weapons/g_porto.md3");
687 precache_model ("models/weapons/v_porto.md3");
688 precache_model ("models/weapons/h_porto.dpm");
689 precache_model ("models/elaser.mdl");
690 precache_sound ("nexball/shoot1.wav");
691 precache_sound ("nexball/shoot2.wav");
693 else if (req == WR_SETUP)
694 weapon_setup(WEP_PORTO);
695 else if (req == WR_SUICIDEMESSAGE)
697 w_deathtypestring = "is a weirdo";
699 else if (req == WR_KILLMESSAGE)
701 w_deathtypestring = "got killed by #'s black magic";
703 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE