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 radar_showennemies = cvar("g_nexball_radar_showallplayers");
47 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
52 void LogNB(string mode, entity actor)
55 if(!cvar("sv_eventlog"))
57 s = strcat(":nexball:", mode);
59 s = strcat(s, ":", ftos(actor.playerid));
63 void ball_restart (void)
66 DropBall(self, self.owner.origin, '0 0 0');
70 void nexball_setstatus (void)
77 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
79 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
81 self = self.ballcarried;
82 DropBall(self, self.owner.origin, '0 0 0');
86 self.items |= IT_KEY1;
90 void relocate_nexball (void)
92 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
97 if(!move_out_of_solid(self))
98 objerror("could not get out of solid at all!");
99 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
100 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
101 print(" ", ftos(self.origin_y - o_y));
102 print(" ", ftos(self.origin_z - o_z), "'\n");
107 void basketball_touch();
108 void football_touch();
110 void DropOwner (void)
114 DropBall(self, ownr.origin, ownr.velocity);
115 makevectors(ownr.v_angle_y * '0 1 0');
116 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
117 ownr.flags &~= FL_ONGROUND;
120 void GiveBall (entity plyr, entity ball)
124 if ((ownr = ball.owner))
126 ownr.effects &~= g_nexball_basketball_effects_default;
127 ownr.ballcarried = world;
131 ownr.weaponentity.state = WS_READY;
135 setattachment(ball, plyr, "");
136 setorigin(ball, BALL_ATTACHORG);
138 if (ball.team != plyr.team)
139 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
141 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
142 ball.team = plyr.team;
143 plyr.ballcarried = ball;
144 ball.dropperid = plyr.playerid;
146 plyr.effects |= g_nexball_basketball_effects_default;
147 ball.effects &~= g_nexball_basketball_effects_default;
149 ball.velocity = '0 0 0';
150 ball.movetype = MOVETYPE_NONE;
151 ball.touch = SUB_Null;
152 ball.effects |= EF_NOSHADOW;
153 ball.scale = 1; // scale down.
155 ball.waypointsprite_attachedforcarrier.exteriormodeltoclient = plyr;
157 if (g_nexball_basketball_delay_hold)
159 ball.think = DropOwner;
160 ball.nextthink = time + g_nexball_basketball_delay_hold;
164 void DropBall (entity ball, vector org, vector vel)
166 ball.effects |= g_nexball_basketball_effects_default;
167 ball.effects &~= EF_NOSHADOW;
168 ball.owner.effects &~= g_nexball_basketball_effects_default;
170 setattachment(ball, world, "");
171 setorigin (ball, org);
172 ball.movetype = MOVETYPE_BOUNCE;
173 ball.flags &~= FL_ONGROUND;
174 ball.scale = ball_scale;
176 ball.ctf_droptime = time;
177 ball.touch = basketball_touch;
178 ball.think = ResetBall;
179 ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
181 if (ball.owner.metertime)
183 ball.owner.metertime = 0;
184 ball.owner.weaponentity.state = WS_READY;
187 ball.waypointsprite_attachedforcarrier.exteriormodeltoclient = world;
189 ball.owner.ballcarried = world;
195 if (gameover) return;
196 self.flags &~= FL_ONGROUND;
197 self.movetype = MOVETYPE_BOUNCE;
198 if (self.classname == "nexball_basketball")
199 self.touch = basketball_touch;
200 else if (self.classname == "nexball_football")
201 self.touch = football_touch;
203 self.think = ResetBall;
204 self.nextthink = time + g_nexball_delay_idle + 3;
208 sound (self, CHAN_PROJECTILE, self.noise1, VOL_BASE, ATTN_NORM);
209 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
210 LogNB("init", world);
213 void ResetBall (void)
215 if (self.cnt < 2) { // step 1
216 if (time == self.teamtime)
217 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
218 self.touch = SUB_Null;
219 self.movetype = MOVETYPE_NOCLIP;
220 self.velocity = '0 0 0'; // just in case?
222 LogNB("resetidle", world);
224 self.nextthink = time;
225 } else if (self.cnt < 4) { // step 2 and 3
226 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
227 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
228 self.nextthink = time + 0.5;
231 // dprint("Step 4: time: ", ftos(time), "\n");
232 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
233 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
234 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
235 self.velocity = '0 0 0';
236 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
237 self.movetype = MOVETYPE_NONE;
238 self.think = InitBall;
239 self.nextthink = max(time, game_starttime) + cvar("g_nexball_delay_start");
243 void football_touch (void)
245 if (other.solid == SOLID_BSP) {
246 if (time > self.lastground + 0.1)
248 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
249 self.lastground = time;
251 if (vlen(self.velocity) && !self.cnt)
252 self.nextthink = time + g_nexball_delay_idle;
255 if (other.classname != "player")
257 if (other.health < 1)
260 self.nextthink = time + g_nexball_delay_idle;
263 self.team = other.team;
265 if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
266 if (vlen(other.velocity))
267 self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
268 } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
269 makevectors(other.v_angle);
270 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
271 } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
272 makevectors(other.v_angle_y * '0 1 0');
273 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
274 } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
275 makevectors(other.v_angle);
276 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
278 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
281 void basketball_touch (void)
283 if (other.ballcarried)
288 if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_nexball_delay_collect"))) {
289 if (other.health <= 0)
291 LogNB("caught", other);
292 GiveBall(other, self);
293 } else if (other.solid == SOLID_BSP) {
294 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
295 if (vlen(self.velocity) && !self.cnt)
296 self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
300 void GoalTouch (void)
303 float isclient, pscore;
306 if (gameover) return;
307 if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
308 ball = other.ballcarried;
311 if (ball.classname != "nexball_basketball")
312 if (ball.classname != "nexball_football")
314 if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
319 if((isclient = ball.pusher.flags & FL_CLIENT))
320 pname = ball.pusher.netname;
322 pname = "Someone (?)";
324 if (ball.team == self.team) //owngoal (regular goals)
326 LogNB("owngoal", ball.pusher);
327 bprint("Boo! ", pname, "^7 scored a goal against his own team!\n");
329 } else if (self.team == GOAL_FAULT) {
330 LogNB("fault", ball.pusher);
331 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
333 } else if (self.team == GOAL_OUT) {
334 LogNB("out", ball.pusher);
335 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
336 bprint(pname, "^7 went out of bounds.\n");
338 bprint("The ball was returned.\n");
341 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
342 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
346 sound (ball, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
348 if(ball.team && pscore)
349 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
350 if (isclient && pscore > 0)
351 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
352 else if (isclient && pscore < 0)
353 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, pscore);
355 if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
356 DropBall(ball, ball.owner.origin, ball.owner.velocity);
358 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
361 ball.think = ResetBall;
362 if (ball.classname == "nexball_basketball")
363 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
364 ball.nextthink = time + cvar("g_nexball_delay_goal") * (self.team != GOAL_OUT);
367 //=======================//
369 //=======================//
370 void spawnfunc_nexball_team (void)
372 if(!g_nexball) { remove(self); return; }
373 self.team = self.cnt + 1;
376 void nb_spawnteam (string teamname, float teamcolor)
378 dprint("^2spawned team ", teamname, "\n");
381 e.classname = "nexball_team";
382 e.netname = teamname;
387 void nb_spawnteams (void)
389 float t_r, t_b, t_y, t_p;
391 for(e = world; (e = find(e, classname, "nexball_goal")); )
395 case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1) ; t_r = 1; } break;
396 case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1) ; t_b = 1; } break;
397 case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
398 case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1) ; t_p = 1; } break;
403 void nb_delayedinit (void)
405 if (find(world, classname, "nexball_team") == world)
407 ScoreRules_nexball();
411 //=======================//
413 //=======================//
415 void SpawnBall (void)
417 if(!g_nexball) { remove(self); return; }
419 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
422 self.model = "models/nexball/ball.md3";
426 precache_model (self.model);
427 setmodel (self, self.model);
428 setsize (self, BALL_MINS, BALL_MAXS);
429 ball_scale = self.scale;
432 self.spawnorigin = self.origin;
434 self.effects = self.effects | EF_LOWPRECISION;
436 if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
438 self.glow_color = cvar("g_nexball_trail_color");
439 self.glow_trail = TRUE;
442 self.movetype = MOVETYPE_FLY;
444 if (!cvar("g_nexball_sound_bounce"))
446 else if (!self.noise)
447 self.noise = "sound/nexball/bounce.wav";
448 //bounce sound placeholder (FIXME)
450 self.noise1 = "sound/nexball/drop.wav";
451 //ball drop sound placeholder (FIXME)
453 self.noise2 = "sound/nexball/steal.wav";
454 //stealing sound placeholder (FIXME)
455 if (self.noise) precache_sound (self.noise);
456 precache_sound (self.noise1);
457 precache_sound (self.noise2);
459 WaypointSprite_AttachCarrier("nb-ball", self); // the ball's team is not set yet, no rule update needed
460 WaypointSprite_UpdateTeamRadar(self.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
462 self.reset = ball_restart;
463 self.think = InitBall;
464 self.nextthink = game_starttime + cvar("g_nexball_delay_start");
467 void spawnfunc_nexball_basketball (void)
469 self.classname = "nexball_basketball";
470 if(!balls & BALL_BASKET)
472 CVTOV(g_nexball_basketball_effects_default);
473 CVTOV(g_nexball_basketball_delay_hold);
474 CVTOV(g_nexball_basketball_delay_hold_forteam);
475 CVTOV(g_nexball_basketball_teamsteal);
476 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
479 self.effects = g_nexball_basketball_effects_default;
480 self.solid = SOLID_TRIGGER;
481 balls |= BALL_BASKET;
482 self.bouncefactor = cvar("g_nexball_basketball_bouncefactor");
483 self.bouncestop = cvar("g_nexball_basketball_bouncestop");
487 void spawnfunc_nexball_football (void)
489 self.classname = "nexball_football";
490 self.solid = SOLID_TRIGGER;
492 self.bouncefactor = cvar("g_nexball_football_bouncefactor");
493 self.bouncestop = cvar("g_nexball_football_bouncestop");
497 void SpawnGoal (void)
499 if(!g_nexball) { remove(self); return; }
501 self.classname = "nexball_goal";
503 self.noise = "ctf/respawn.wav";
504 precache_sound(self.noise);
505 self.touch = GoalTouch;
508 void spawnfunc_nexball_redgoal (void)
510 self.team = COLOR_TEAM1;
513 void spawnfunc_nexball_bluegoal (void)
515 self.team = COLOR_TEAM2;
518 void spawnfunc_nexball_yellowgoal (void)
520 self.team = COLOR_TEAM3;
523 void spawnfunc_nexball_pinkgoal (void)
525 self.team = COLOR_TEAM4;
529 void spawnfunc_nexball_fault (void)
531 self.team = GOAL_FAULT;
533 self.noise = "misc/typehit.wav";
537 void spawnfunc_nexball_out (void)
539 self.team = GOAL_OUT;
541 self.noise = "misc/typehit.wav";
546 //Spawnfuncs preserved for compatibility
549 void spawnfunc_ball (void) { spawnfunc_nexball_football(); }
550 void spawnfunc_ball_football (void) { spawnfunc_nexball_football(); }
551 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
552 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
553 void spawnfunc_ball_redgoal (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
554 void spawnfunc_ball_bluegoal (void) { spawnfunc_nexball_redgoal(); } // but he didn't mean to cause trouble :p
555 void spawnfunc_ball_fault (void) { spawnfunc_nexball_fault(); }
556 void spawnfunc_ball_bound (void) { spawnfunc_nexball_out(); }
558 //=======================//
560 //=======================//
562 void W_Nexball_Touch (void)
564 local entity ball, attacker;
565 attacker = self.owner;
568 if(attacker.team != other.team || g_nexball_basketball_teamsteal)
569 if((ball = other.ballcarried) && (attacker.classname == "player" || attacker.classname == "gib"))
571 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * cvar("g_balance_nexball_secondary_force");
572 other.flags &~= FL_ONGROUND;
573 if(!attacker.ballcarried)
575 LogNB("stole", attacker);
576 sound (other, CHAN_AUTO, ball.noise2, VOL_BASE, ATTN_NORM);
578 if(attacker.team == other.team && time > attacker.teamkill_complain)
580 attacker.teamkill_complain = time + 5;
581 attacker.teamkill_soundtime = time + 0.4;
582 attacker.teamkill_soundsource = other;
585 GiveBall(attacker, other.ballcarried);
591 void W_Nexball_Attack (float t)
594 local float mul, mi, ma;
595 if (!(ball = self.ballcarried))
598 W_SetupShot (self, FALSE, 4, "nexball/shoot1.wav",0);
599 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
603 self.metertime = 0; // Shot failed, hide the power meter
607 //Calculate multiplier
612 mi = cvar("g_nexball_basketball_meter_minpower");
613 ma = max(mi, cvar("g_nexball_basketball_meter_maxpower")); // avoid confusion
614 //One triangle wave period with 1 as max
615 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
618 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
620 DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * cvar("g_balance_nexball_primary_speed") * mul));
621 //TODO: use the speed_up cvar too ??
624 void W_Nexball_Attack2 (void)
626 local entity missile;
627 if (!(balls & BALL_BASKET))
629 W_SetupShot (self, FALSE, 2, "nexball/shoot2.wav",0);
630 // pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
633 missile.owner = self;
634 missile.classname = "ballstealer";
636 missile.movetype = MOVETYPE_FLY;
637 missile.solid = SOLID_BBOX;
639 setmodel (missile, "models/elaser.mdl"); // precision set below
640 setsize (missile, '0 0 0', '0 0 0');
641 setorigin (missile, w_shotorg);
643 missile.velocity = w_shotdir * cvar("g_balance_nexball_secondary_speed");
644 W_SetupProjectileVelocity(missile);
645 missile.angles = vectoangles (missile.velocity);
646 missile.touch = W_Nexball_Touch;
647 missile.think = SUB_Remove;
648 missile.nextthink = time + cvar("g_balance_nexball_secondary_lifetime"); //FIXME: use a distance instead?
650 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
651 missile.flags = FL_PROJECTILE;
654 float w_nexball_weapon(float req)
658 if (self.BUTTON_ATCK)
659 if (weapon_prepareattack(0, cvar("g_balance_nexball_primary_refire")))
660 if (cvar("g_nexball_basketball_meter"))
662 if (self.ballcarried && !self.metertime)
663 self.metertime = time;
665 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
669 W_Nexball_Attack(-1);
670 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
672 if (self.BUTTON_ATCK2)
673 if (weapon_prepareattack(1, cvar("g_balance_nexball_secondary_refire")))
676 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_nexball_secondary_animtime"), w_ready);
679 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
681 W_Nexball_Attack(time - self.metertime);
682 // DropBall or stealing will set metertime back to 0
683 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
686 else if (req == WR_PRECACHE)
688 precache_model ("models/weapons/g_porto.md3");
689 precache_model ("models/weapons/v_porto.md3");
690 precache_model ("models/weapons/h_porto.dpm");
691 precache_model ("models/elaser.mdl");
692 precache_sound ("nexball/shoot1.wav");
693 precache_sound ("nexball/shoot2.wav");
695 else if (req == WR_SETUP)
696 weapon_setup(WEP_PORTO);
697 else if (req == WR_SUICIDEMESSAGE)
699 w_deathtypestring = "is a weirdo";
701 else if (req == WR_KILLMESSAGE)
703 w_deathtypestring = "got killed by #'s black magic";
705 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE