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 = autocvar_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(!autocvar_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)
83 self.items &~= IT_KEY1;
86 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
88 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
90 self = self.ballcarried;
91 DropBall(self, self.owner.origin, '0 0 0');
95 self.items |= IT_KEY1;
99 void relocate_nexball (void)
101 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
102 if (trace_startsolid)
106 if(!move_out_of_solid(self))
107 objerror("could not get out of solid at all!");
108 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
109 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
110 print(" ", ftos(self.origin_y - o_y));
111 print(" ", ftos(self.origin_z - o_z), "'\n");
116 void basketball_touch();
117 void football_touch();
119 void DropOwner (void)
123 DropBall(self, ownr.origin, ownr.velocity);
124 makevectors(ownr.v_angle_y * '0 1 0');
125 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
126 ownr.flags &~= FL_ONGROUND;
129 void GiveBall (entity plyr, entity ball)
133 if ((ownr = ball.owner))
135 ownr.effects &~= g_nexball_basketball_effects_default;
136 ownr.ballcarried = world;
140 ownr.weaponentity.state = WS_READY;
142 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
146 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
149 setattachment(ball, plyr, "");
150 setorigin(ball, BALL_ATTACHORG);
152 if (ball.team != plyr.team)
153 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
155 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
156 ball.team = plyr.team;
157 plyr.ballcarried = ball;
158 ball.dropperid = plyr.playerid;
160 plyr.effects |= g_nexball_basketball_effects_default;
161 ball.effects &~= g_nexball_basketball_effects_default;
163 ball.velocity = '0 0 0';
164 ball.movetype = MOVETYPE_NONE;
165 ball.touch = SUB_Null;
166 ball.effects |= EF_NOSHADOW;
167 ball.scale = 1; // scale down.
169 WaypointSprite_AttachCarrier("nb-ball", plyr, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
170 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
172 if (g_nexball_basketball_delay_hold)
174 ball.think = DropOwner;
175 ball.nextthink = time + g_nexball_basketball_delay_hold;
179 void DropBall (entity ball, vector org, vector vel)
181 ball.effects |= g_nexball_basketball_effects_default;
182 ball.effects &~= EF_NOSHADOW;
183 ball.owner.effects &~= g_nexball_basketball_effects_default;
185 setattachment(ball, world, "");
186 setorigin (ball, org);
187 ball.movetype = MOVETYPE_BOUNCE;
188 ball.flags &~= FL_ONGROUND;
189 ball.scale = ball_scale;
191 ball.ctf_droptime = time;
192 ball.touch = basketball_touch;
193 ball.think = ResetBall;
194 ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
196 if (ball.owner.metertime)
198 ball.owner.metertime = 0;
199 ball.owner.weaponentity.state = WS_READY;
202 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
203 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
204 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
206 ball.owner.ballcarried = world;
212 if (gameover) return;
213 self.flags &~= FL_ONGROUND;
214 self.movetype = MOVETYPE_BOUNCE;
215 if (self.classname == "nexball_basketball")
216 self.touch = basketball_touch;
217 else if (self.classname == "nexball_football")
218 self.touch = football_touch;
220 self.think = ResetBall;
221 self.nextthink = time + g_nexball_delay_idle + 3;
225 sound (self, CH_TRIGGER, self.noise1, VOL_BASE, ATTN_NORM);
226 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
227 LogNB("init", world);
230 void ResetBall (void)
232 if (self.cnt < 2) { // step 1
233 if (time == self.teamtime)
234 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
235 self.touch = SUB_Null;
236 self.movetype = MOVETYPE_NOCLIP;
237 self.velocity = '0 0 0'; // just in case?
239 LogNB("resetidle", world);
241 self.nextthink = time;
242 } else if (self.cnt < 4) { // step 2 and 3
243 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
244 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
245 self.nextthink = time + 0.5;
248 // dprint("Step 4: time: ", ftos(time), "\n");
249 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
250 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
251 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
252 self.velocity = '0 0 0';
253 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
254 self.movetype = MOVETYPE_NONE;
255 self.think = InitBall;
256 self.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
260 void football_touch (void)
262 if (other.solid == SOLID_BSP) {
263 if (time > self.lastground + 0.1)
265 sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
266 self.lastground = time;
268 if (vlen(self.velocity) && !self.cnt)
269 self.nextthink = time + g_nexball_delay_idle;
272 if (other.classname != "player")
274 if (other.health < 1)
277 self.nextthink = time + g_nexball_delay_idle;
280 self.team = other.team;
282 if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
283 if (vlen(other.velocity))
284 self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
285 } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
286 makevectors(other.v_angle);
287 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
288 } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
289 makevectors(other.v_angle_y * '0 1 0');
290 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
291 } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
292 makevectors(other.v_angle);
293 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
295 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
298 void basketball_touch (void)
300 if (other.ballcarried)
305 if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_nexball_delay_collect)) {
306 if (other.health <= 0)
308 LogNB("caught", other);
309 GiveBall(other, self);
310 } else if (other.solid == SOLID_BSP) {
311 sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
312 if (vlen(self.velocity) && !self.cnt)
313 self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
317 void GoalTouch (void)
320 float isclient, pscore, otherteam;
323 if (gameover) return;
324 if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
325 ball = other.ballcarried;
328 if (ball.classname != "nexball_basketball")
329 if (ball.classname != "nexball_football")
331 if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
337 otherteam = OtherTeam(ball.team);
339 if((isclient = ball.pusher.flags & FL_CLIENT))
340 pname = ball.pusher.netname;
342 pname = "Someone (?)";
344 if (ball.team == self.team) //owngoal (regular goals)
346 LogNB("owngoal", ball.pusher);
347 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
349 } else if (self.team == GOAL_FAULT) {
350 LogNB("fault", ball.pusher);
352 bprint(ColoredTeamName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
354 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
356 } else if (self.team == GOAL_OUT) {
357 LogNB("out", ball.pusher);
358 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
359 bprint(pname, "^7 went out of bounds.\n");
361 bprint("The ball was returned.\n");
364 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
365 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
369 sound (ball, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NONE);
371 if(ball.team && pscore)
373 if (nb_teams == 2 && pscore < 0)
374 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
376 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
381 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
383 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
386 if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
387 DropBall(ball, ball.owner.origin, ball.owner.velocity);
389 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
392 ball.think = ResetBall;
393 if (ball.classname == "nexball_basketball")
394 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
395 ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
398 //=======================//
400 //=======================//
401 void spawnfunc_nexball_team (void)
403 if(!g_nexball) { remove(self); return; }
404 self.team = self.cnt + 1;
407 void nb_spawnteam (string teamname, float teamcolor)
409 dprint("^2spawned team ", teamname, "\n");
412 e.classname = "nexball_team";
413 e.netname = teamname;
419 void nb_spawnteams (void)
421 float t_r, t_b, t_y, t_p;
423 for(e = world; (e = find(e, classname, "nexball_goal")); )
427 case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1) ; t_r = 1; } break;
428 case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1) ; t_b = 1; } break;
429 case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
430 case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1) ; t_p = 1; } break;
435 void nb_delayedinit (void)
437 if (find(world, classname, "nexball_team") == world)
439 ScoreRules_nexball(nb_teams);
443 //=======================//
445 //=======================//
447 void SpawnBall (void)
449 if(!g_nexball) { remove(self); return; }
451 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
454 self.model = "models/nexball/ball.md3";
458 precache_model (self.model);
459 setmodel (self, self.model);
460 setsize (self, BALL_MINS, BALL_MAXS);
461 ball_scale = self.scale;
464 self.spawnorigin = self.origin;
466 self.effects = self.effects | EF_LOWPRECISION;
468 if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
470 self.glow_color = autocvar_g_nexball_trail_color;
471 self.glow_trail = TRUE;
474 self.movetype = MOVETYPE_FLY;
476 if (!autocvar_g_nexball_sound_bounce)
478 else if (!self.noise)
479 self.noise = "sound/nexball/bounce.wav";
480 //bounce sound placeholder (FIXME)
482 self.noise1 = "sound/nexball/drop.wav";
483 //ball drop sound placeholder (FIXME)
485 self.noise2 = "sound/nexball/steal.wav";
486 //stealing sound placeholder (FIXME)
487 if (self.noise) precache_sound (self.noise);
488 precache_sound (self.noise1);
489 precache_sound (self.noise2);
491 WaypointSprite_AttachCarrier("nb-ball", self, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR); // the ball's team is not set yet, no rule update needed
493 self.reset = ball_restart;
494 self.think = InitBall;
495 self.nextthink = game_starttime + autocvar_g_nexball_delay_start;
498 void spawnfunc_nexball_basketball (void)
500 self.classname = "nexball_basketball";
501 if not(balls & BALL_BASKET)
503 CVTOV(g_nexball_basketball_effects_default);
504 CVTOV(g_nexball_basketball_delay_hold);
505 CVTOV(g_nexball_basketball_delay_hold_forteam);
506 CVTOV(g_nexball_basketball_teamsteal);
507 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
510 self.effects = g_nexball_basketball_effects_default;
511 self.solid = SOLID_TRIGGER;
512 balls |= BALL_BASKET;
513 self.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
514 self.bouncestop = autocvar_g_nexball_basketball_bouncestop;
518 void spawnfunc_nexball_football (void)
520 self.classname = "nexball_football";
521 self.solid = SOLID_TRIGGER;
523 self.bouncefactor = autocvar_g_nexball_football_bouncefactor;
524 self.bouncestop = autocvar_g_nexball_football_bouncestop;
528 void SpawnGoal (void)
530 if(!g_nexball) { remove(self); return; }
532 self.classname = "nexball_goal";
534 self.noise = "ctf/respawn.wav";
535 precache_sound(self.noise);
536 self.touch = GoalTouch;
539 void spawnfunc_nexball_redgoal (void)
541 self.team = COLOR_TEAM1;
544 void spawnfunc_nexball_bluegoal (void)
546 self.team = COLOR_TEAM2;
549 void spawnfunc_nexball_yellowgoal (void)
551 self.team = COLOR_TEAM3;
554 void spawnfunc_nexball_pinkgoal (void)
556 self.team = COLOR_TEAM4;
560 void spawnfunc_nexball_fault (void)
562 self.team = GOAL_FAULT;
564 self.noise = "misc/typehit.wav";
568 void spawnfunc_nexball_out (void)
570 self.team = GOAL_OUT;
572 self.noise = "misc/typehit.wav";
577 //Spawnfuncs preserved for compatibility
580 void spawnfunc_ball (void) { spawnfunc_nexball_football(); }
581 void spawnfunc_ball_football (void) { spawnfunc_nexball_football(); }
582 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
583 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
584 void spawnfunc_ball_redgoal (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
585 void spawnfunc_ball_bluegoal (void) { spawnfunc_nexball_redgoal(); } // but he didn't mean to cause trouble :p
586 void spawnfunc_ball_fault (void) { spawnfunc_nexball_fault(); }
587 void spawnfunc_ball_bound (void) { spawnfunc_nexball_out(); }
589 //=======================//
591 //=======================//
593 void W_Nexball_Touch (void)
595 entity ball, attacker;
596 attacker = self.owner;
599 if(attacker.team != other.team || g_nexball_basketball_teamsteal)
600 if((ball = other.ballcarried) && (attacker.classname == "player"))
602 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
603 other.flags &~= FL_ONGROUND;
604 if(!attacker.ballcarried)
606 LogNB("stole", attacker);
607 sound (other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTN_NORM);
609 if(attacker.team == other.team && time > attacker.teamkill_complain)
611 attacker.teamkill_complain = time + 5;
612 attacker.teamkill_soundtime = time + 0.4;
613 attacker.teamkill_soundsource = other;
616 GiveBall(attacker, other.ballcarried);
622 void W_Nexball_Attack (float t)
626 if (!(ball = self.ballcarried))
629 W_SetupShot (self, FALSE, 4, "nexball/shoot1.wav", CH_WEAPON_A, 0);
630 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
634 self.metertime = 0; // Shot failed, hide the power meter
638 //Calculate multiplier
643 mi = autocvar_g_nexball_basketball_meter_minpower;
644 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
645 //One triangle wave period with 1 as max
646 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
649 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
651 DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, FALSE));
652 //TODO: use the speed_up cvar too ??
655 void W_Nexball_Attack2 (void)
658 if (!(balls & BALL_BASKET))
660 W_SetupShot (self, FALSE, 2, "nexball/shoot2.wav", CH_WEAPON_A, 0);
661 // pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
664 missile.owner = self;
665 missile.classname = "ballstealer";
667 missile.movetype = MOVETYPE_FLY;
668 PROJECTILE_MAKETRIGGER(missile);
670 setmodel (missile, "models/elaser.mdl"); // precision set below
671 setsize (missile, '0 0 0', '0 0 0');
672 setorigin (missile, w_shotorg);
674 W_SetupProjectileVelocity(missile, autocvar_g_balance_nexball_secondary_speed, 0);
675 missile.angles = vectoangles (missile.velocity);
676 missile.touch = W_Nexball_Touch;
677 missile.think = SUB_Remove;
678 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
680 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
681 missile.flags = FL_PROJECTILE;
684 float w_nexball_weapon(float req)
688 if (self.BUTTON_ATCK)
689 if (weapon_prepareattack(0, autocvar_g_balance_nexball_primary_refire))
690 if (autocvar_g_nexball_basketball_meter)
692 if (self.ballcarried && !self.metertime)
693 self.metertime = time;
695 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
699 W_Nexball_Attack(-1);
700 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
702 if (self.BUTTON_ATCK2)
703 if (weapon_prepareattack(1, autocvar_g_balance_nexball_secondary_refire))
706 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
709 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
711 W_Nexball_Attack(time - self.metertime);
712 // DropBall or stealing will set metertime back to 0
713 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
716 else if (req == WR_PRECACHE)
718 precache_model ("models/weapons/g_porto.md3");
719 precache_model ("models/weapons/v_porto.md3");
720 precache_model ("models/weapons/h_porto.iqm");
721 precache_model ("models/elaser.mdl");
722 precache_sound ("nexball/shoot1.wav");
723 precache_sound ("nexball/shoot2.wav");
724 precache_sound ("misc/typehit.wav");
726 else if (req == WR_SETUP)
727 weapon_setup(WEP_PORTO);
728 else if (req == WR_SUICIDEMESSAGE)
730 w_deathtypestring = "is a weirdo";
732 else if (req == WR_KILLMESSAGE)
734 w_deathtypestring = "got killed by #'s black magic";
736 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE