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'
9 #define GOAL_TOUCHPLAYER 1
14 #define CVTOV(s) s = cvar( #s )
16 float g_nexball_football_boost_forward;
17 float g_nexball_football_boost_up;
18 float g_nexball_football_physics;
19 float g_nexball_delay_idle;
20 float g_nexball_basketball_delay_hold;
21 float g_nexball_basketball_delay_hold_forteam;
22 float g_nexball_basketball_effects_default;
23 float g_nexball_basketball_teamsteal;
29 void nb_delayedinit();
30 void nb_init() // Called early (worldspawn stage)
32 CVTOV(g_nexball_meter_period); //sent with the client init entity
33 if (g_nexball_meter_period <= 0)
34 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
35 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
36 addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
39 CVTOV(g_nexball_football_boost_forward); //100
40 CVTOV(g_nexball_football_boost_up); //200
41 CVTOV(g_nexball_delay_idle); //10
42 CVTOV(g_nexball_football_physics); //0
44 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
49 void LogNB(string mode, entity actor)
52 if(!cvar("sv_eventlog"))
54 s = strcat(":nexball:", mode);
56 s = strcat(s, ":", ftos(actor.playerid));
60 void ball_restart (void)
63 DropBall(self, self.owner.origin, '0 0 0');
67 void nexball_setstatus (void)
74 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
76 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
78 self = self.ballcarried;
79 DropBall(self, self.owner.origin, '0 0 0');
83 self.items |= IT_KEY1;
87 void relocate_nexball (void)
89 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
94 if(!move_out_of_solid(self))
95 objerror("could not get out of solid at all!");
96 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
97 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
98 print(" ", ftos(self.origin_y - o_y));
99 print(" ", ftos(self.origin_z - o_z), "'\n");
104 void basketball_touch();
105 void football_touch();
107 void DropOwner (void)
111 DropBall(self, ownr.origin, ownr.velocity);
112 makevectors(ownr.v_angle_y * '0 1 0');
113 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
114 ownr.flags &~= FL_ONGROUND;
117 void DropBall (entity ball, vector org, vector vel)
119 ball.effects |= g_nexball_basketball_effects_default;
120 ball.effects &~= EF_NOSHADOW;
121 ball.owner.effects &~= g_nexball_basketball_effects_default; // this may be problematic.
123 setattachment(ball, world, "");
124 setorigin (ball, org);
125 ball.movetype = MOVETYPE_BOUNCE;
126 ball.flags &~= FL_ONGROUND;
127 ball.scale = ball_scale;
129 ball.ctf_droptime = time;
130 ball.touch = basketball_touch;
131 ball.think = ResetBall;
132 ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
134 if (ball.owner.metertime)
136 ball.owner.metertime = 0;
137 ball.owner.weaponentity.state = WS_READY;
140 ball.owner.ballcarried = world;
146 if (gameover) return;
147 self.flags &~= FL_ONGROUND;
148 self.movetype = MOVETYPE_BOUNCE;
149 if (self.classname == "nexball_basketball")
150 self.touch = basketball_touch;
151 else if (self.classname == "nexball_football")
152 self.touch = football_touch;
154 self.think = ResetBall;
155 self.nextthink = time + g_nexball_delay_idle + 3;
159 sound (self, CHAN_PROJECTILE, self.noise1, VOL_BASE, ATTN_NORM);
160 LogNB("init", world);
163 void ResetBall (void)
165 if (self.cnt < 2) { // step 1
166 if (time == self.teamtime)
167 bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
168 self.touch = SUB_Null;
169 self.movetype = MOVETYPE_NOCLIP;
170 self.velocity = '0 0 0'; // just in case?
172 LogNB("resetidle", world);
174 self.nextthink = time;
175 } else if (self.cnt < 4) { // step 2 and 3
176 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
177 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
178 self.nextthink = time + 0.5;
181 // dprint("Step 4: time: ", ftos(time), "\n");
182 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
183 dprint("The ball moved too far away from its spawn origin.\nOffset: ",
184 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
185 self.velocity = '0 0 0';
186 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
187 self.movetype = MOVETYPE_NONE;
188 self.think = InitBall;
189 self.nextthink = max(time, game_starttime) + cvar("g_nexball_delay_start");
193 void football_touch (void)
195 if (other.solid == SOLID_BSP) {
196 if (time > self.lastground + 0.1)
198 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
199 self.lastground = time;
201 if (vlen(self.velocity) && !self.cnt)
202 self.nextthink = time + g_nexball_delay_idle;
205 if (other.classname != "player")
207 if (other.health < 1)
210 self.nextthink = time + g_nexball_delay_idle;
213 self.team = other.team;
215 if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
216 if (vlen(other.velocity))
217 self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
218 } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
219 makevectors(other.v_angle);
220 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
221 } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
222 makevectors(other.v_angle_y * '0 1 0');
223 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
224 } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
225 makevectors(other.v_angle);
226 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
228 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
231 void basketball_touch (void)
233 if (other.ballcarried)
238 if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_nexball_delay_collect"))) {
239 if (other.health <= 0)
241 LogNB("caught", other);
243 if (self.team != other.team)
244 self.teamtime = time + g_nexball_basketball_delay_hold_forteam;
246 self.owner = self.pusher = other; //"owner" is set to the player carrying, "pusher" to the last player who touched it
247 self.team = other.team;
248 other.ballcarried = self;
249 other.effects = other.effects | g_nexball_basketball_effects_default;
250 self.effects &~= g_nexball_basketball_effects_default;
251 self.effects |= EF_NOSHADOW;
252 self.scale = 1; // scale down.
253 self.dropperid = other.playerid;
254 setattachment(self, other, "");
255 setorigin(self, BALL_ATTACHORG);
256 self.velocity = '0 0 0';
257 self.movetype = MOVETYPE_NONE;
258 self.touch = SUB_Null;
259 if (g_nexball_basketball_delay_hold)
261 self.think = DropOwner;
262 self.nextthink = time + g_nexball_basketball_delay_hold;
264 } else if (other.solid == SOLID_BSP) {
265 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
266 if (vlen(self.velocity) && !self.cnt)
267 self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
271 void GoalTouch (void)
274 float isclient, pscore;
277 if (gameover) return;
278 if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
279 ball = other.ballcarried;
282 if (ball.classname != "nexball_basketball")
283 if (ball.classname != "nexball_football")
285 if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
290 if((isclient = ball.pusher.flags & FL_CLIENT))
291 pname = ball.pusher.netname;
293 pname = "Someone (?)";
295 if (ball.team == self.team) //owngoal (regular goals)
297 LogNB("owngoal", ball.pusher);
298 bprint("Boo! ", pname, "^7 scored a goal against his own team!\n");
300 } else if (self.team == GOAL_FAULT) {
301 LogNB("fault", ball.pusher);
302 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
304 } else if (self.team == GOAL_OUT) {
305 LogNB("out", ball.pusher);
306 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
307 bprint(pname, "^7 went out of bounds.\n");
309 bprint("The ball was returned.\n");
312 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
313 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
317 sound (ball, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
319 if(ball.team && pscore)
320 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
321 if (isclient && pscore > 0)
322 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
323 else if (isclient && pscore < 0)
324 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, pscore);
326 if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
327 DropBall(ball, ball.owner.origin, ball.owner.velocity);
329 ball.think = ResetBall;
330 if (ball.classname == "nexball_basketball")
331 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
332 ball.nextthink = time + cvar("g_nexball_delay_goal") * (self.team != GOAL_OUT);
335 //=======================//
337 //=======================//
338 void spawnfunc_nexball_team (void)
340 if(!g_nexball) { remove(self); return; }
341 self.team = self.cnt + 1;
344 void nb_spawnteam (string teamname, float teamcolor)
346 dprint("^2spawned team ", teamname, "\n");
349 e.classname = "nexball_team";
350 e.netname = teamname;
355 void nb_spawnteams (void)
357 float t_r, t_b, t_y, t_p;
359 for(e = world; (e = find(e, classname, "nexball_goal")); )
363 case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1) ; t_r = 1; } break;
364 case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1) ; t_b = 1; } break;
365 case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
366 case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1) ; t_p = 1; } break;
371 void nb_delayedinit (void)
373 if (find(world, classname, "nexball_team") == world)
375 ScoreRules_nexball();
379 //=======================//
381 //=======================//
383 void SpawnBall (void)
385 if(!g_nexball) { remove(self); return; }
388 self.model = "models/nexball/ball.md3";
392 precache_model (self.model);
393 setmodel (self, self.model);
394 setsize (self, BALL_MINS, BALL_MAXS);
395 ball_scale = self.scale;
398 self.spawnorigin = self.origin;
400 self.effects = self.effects | EF_LOWPRECISION;
402 if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
404 self.glow_color = cvar("g_nexball_trail_color");
405 self.glow_trail = TRUE;
408 self.movetype = MOVETYPE_FLY;
410 if (!cvar("g_nexball_sound_bounce"))
412 else if (!self.noise)
413 self.noise = "sound/nexball/bounce.ogg";
414 //bounce sound placeholder (FIXME)
416 self.noise1 = "sound/nexball/drop.ogg";
417 //ball drop sound placeholder (FIXME)
419 self.noise2 = "sound/nexball/steal.ogg";
420 //stealing sound placeholder (FIXME)
421 if (self.noise) precache_sound (self.noise);
422 precache_sound (self.noise1);
423 precache_sound (self.noise2);
425 self.reset = ball_restart;
426 self.think = InitBall;
427 self.nextthink = game_starttime + cvar("g_nexball_delay_start");
430 void spawnfunc_nexball_basketball (void)
432 self.classname = "nexball_basketball";
433 if(!balls & BALL_BASKET)
435 CVTOV(g_nexball_basketball_effects_default);
436 CVTOV(g_nexball_basketball_delay_hold);
437 CVTOV(g_nexball_basketball_delay_hold_forteam);
438 CVTOV(g_nexball_basketball_teamsteal);
439 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
442 self.effects = g_nexball_basketball_effects_default;
443 self.solid = SOLID_TRIGGER;
444 balls |= BALL_BASKET;
448 void spawnfunc_nexball_football (void)
450 self.classname = "nexball_football";
451 self.solid = SOLID_TRIGGER;
456 void SpawnGoal (void)
458 if(!g_nexball) { remove(self); return; }
460 self.classname = "nexball_goal";
462 self.noise = "ctf/respawn.wav";
463 precache_sound(self.noise);
464 self.touch = GoalTouch;
467 void spawnfunc_nexball_redgoal (void)
469 self.team = COLOR_TEAM1;
472 void spawnfunc_nexball_bluegoal (void)
474 self.team = COLOR_TEAM2;
477 void spawnfunc_nexball_yellowgoal (void)
479 self.team = COLOR_TEAM3;
482 void spawnfunc_nexball_pinkgoal (void)
484 self.team = COLOR_TEAM4;
488 void spawnfunc_nexball_fault (void)
490 self.team = GOAL_FAULT;
492 self.noise = "misc/typehit.wav";
496 void spawnfunc_nexball_out (void)
498 self.team = GOAL_OUT;
500 self.noise = "misc/typehit.wav";
505 //Spawnfuncs preserved for compatibility
508 void spawnfunc_ball (void) { spawnfunc_nexball_football(); }
509 void spawnfunc_ball_football (void) { spawnfunc_nexball_football(); }
510 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
511 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
512 void spawnfunc_ball_redgoal (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
513 void spawnfunc_ball_bluegoal (void) { spawnfunc_nexball_redgoal(); } // but he didn't mean to cause trouble :p
514 void spawnfunc_ball_fault (void) { spawnfunc_nexball_fault(); }
515 void spawnfunc_ball_bound (void) { spawnfunc_nexball_out(); }
517 //=======================//
519 //=======================//
521 void W_Nexball_Touch (void)
523 local entity ball, attacker;
524 attacker = self.owner;
527 if(attacker.team != other.team || g_nexball_basketball_teamsteal)
528 if((ball = other.ballcarried) && (attacker.classname == "player" || attacker.classname == "gib"))
530 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * cvar("g_balance_nexball_secondary_force");
531 other.flags &~= FL_ONGROUND;
532 if(!attacker.ballcarried)
534 other.effects &~= g_nexball_basketball_effects_default;
535 other.ballcarried = world;
537 if (g_nexball_basketball_delay_hold)
539 ball.think = DropOwner;
540 ball.nextthink = time + g_nexball_basketball_delay_hold;
543 attacker.effects = attacker.effects | g_nexball_basketball_effects_default;
544 attacker.ballcarried = ball;
548 other.weaponentity.state = WS_READY;
551 setattachment(ball, attacker, "");
552 ball.owner = ball.pusher = attacker;
553 ball.team = attacker.team;
554 ball.dropperid = attacker.playerid;
556 if (other.team != attacker.team)
557 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
559 LogNB("stole", attacker);
560 sound (other, CHAN_AUTO, ball.noise2, VOL_BASE, ATTN_NORM);
562 if(attacker.team == other.team && time > attacker.teamkill_complain)
564 attacker.teamkill_complain = time + 5;
565 attacker.teamkill_soundtime = time + 0.4;
566 attacker.teamkill_soundsource = other;
573 void W_Nexball_Attack (float t)
576 local float mul, mi, ma;
577 if (!(ball = self.ballcarried))
580 W_SetupShot (self, FALSE, 4, "weapons/grenade_fire.wav");
581 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
585 self.metertime = 0; // Shot failed, hide the power meter
589 //Calculate multiplier
594 mi = cvar("g_nexball_basketball_meter_minpower");
595 ma = max(mi, cvar("g_nexball_basketball_meter_maxpower")); // avoid confusion
596 //One triangle wave period with 1 as max
597 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
600 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
602 DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * cvar("g_balance_nexball_primary_speed") * mul));
603 //TODO: use the speed_up cvar too ??
606 void W_Nexball_Attack2 (void)
608 local entity missile;
609 if (!(balls & BALL_BASKET))
611 W_SetupShot (self, FALSE, 2, "weapons/grenade_fire.wav");
612 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
615 missile.owner = self;
616 missile.classname = "ballstealer";
618 missile.movetype = MOVETYPE_FLY;
619 missile.solid = SOLID_BBOX;
621 setmodel (missile, "models/elaser.mdl"); // precision set below
622 setsize (missile, '0 0 0', '0 0 0');
623 setorigin (missile, w_shotorg);
625 missile.velocity = w_shotdir * cvar("g_balance_nexball_secondary_speed");
626 W_SetupProjectileVelocity(missile);
627 missile.angles = vectoangles (missile.velocity);
628 missile.touch = W_Nexball_Touch;
629 missile.think = SUB_Remove;
630 missile.nextthink = time + cvar("g_balance_nexball_secondary_lifetime"); //FIXME: use a distance instead?
632 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
633 missile.flags = FL_PROJECTILE;
636 float w_nexball_weapon(float req)
640 if (self.BUTTON_ATCK)
641 if (weapon_prepareattack(0, cvar("g_balance_nexball_primary_refire")))
642 if (cvar("g_nexball_basketball_meter"))
644 if (self.ballcarried && !self.metertime)
645 self.metertime = time;
647 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
651 W_Nexball_Attack(-1);
652 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
654 if (self.BUTTON_ATCK2)
655 if (weapon_prepareattack(1, cvar("g_balance_nexball_secondary_refire")))
658 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_nexball_secondary_animtime"), w_ready);
661 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
663 W_Nexball_Attack(time - self.metertime);
664 // DropBall or stealing will set metertime back to 0
665 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
668 else if (req == WR_PRECACHE)
670 precache_model ("models/weapons/g_gl.md3");
671 precache_model ("models/weapons/v_gl.md3");
672 precache_model ("models/weapons/h_gl.dpm");
673 precache_model ("models/elaser.mdl");
674 precache_sound ("weapons/grenade_fire.wav");
676 else if (req == WR_SETUP)
677 weapon_setup(WEP_GRENADE_LAUNCHER);
678 else if (req == WR_SUICIDEMESSAGE)
680 w_deathtypestring = "is a weirdo";
682 else if (req == WR_KILLMESSAGE)
684 w_deathtypestring = "got killed by #'s black magic";
686 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE