]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_nexball.qc
Merge remote-tracking branch 'origin/master' into samual/mutator_ctf
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_nexball.qc
index fab7523505f9488fa90d9ccb397d73a559209ea8..1b94746356c85ee15576d809f3e0ce3b57f9c076 100644 (file)
@@ -1,3 +1,10 @@
+float autocvar_g_nexball_safepass_turnrate;
+float autocvar_g_nexball_safepass_maxdist;
+float autocvar_g_nexball_safepass_holdtime;
+float autocvar_g_nexball_viewmodel_scale;
+float autocvar_g_nexball_tackling;
+vector autocvar_g_nexball_viewmodel_offset;
+
 void basketball_touch();
 void football_touch();
 void ResetBall();
@@ -110,7 +117,7 @@ void GiveBall(entity plyr, entity ball)
        ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
        ball.team = plyr.team;
        plyr.ballcarried = ball;
-       ball.dropperid = plyr.playerid;
+       ball.ctf_dropper = plyr;
 
        plyr.effects |= autocvar_g_nexball_basketball_effects_default;
        ball.effects &~= autocvar_g_nexball_basketball_effects_default;
@@ -132,9 +139,9 @@ void GiveBall(entity plyr, entity ball)
        
     ownr = self;
     self = plyr;    
-    self.weaponentity.weapons = self.weapons;
+    WEPSET_COPY_EE(self.weaponentity, self);
     self.weaponentity.switchweapon = self.weapon;
-    self.weapons = W_WeaponBit(WEP_PORTO);            
+    WEPSET_COPY_EW(self, WEP_PORTO);
     weapon_action(WEP_PORTO, WR_RESETPLAYER);
     self.switchweapon = WEP_PORTO;
     W_SwitchWeapon(WEP_PORTO);
@@ -280,7 +287,7 @@ void basketball_touch(void)
                football_touch();
                return;
        }
-       if(!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + autocvar_g_nexball_delay_collect))
+       if(!self.cnt && other.classname == "player" && (other != self.ctf_dropper || time > self.ctf_droptime + autocvar_g_nexball_delay_collect))
        {
                if(other.health <= 0)
                        return;
@@ -316,6 +323,8 @@ void GoalTouch(void)
 
        if(nb_teams == 2)
                otherteam = OtherTeam(ball.team);
+       else
+               otherteam = 0;
 
        if((isclient = ball.pusher.flags & FL_CLIENT))
                pname = ball.pusher.netname;
@@ -409,7 +418,7 @@ void nb_spawnteam(string teamname, float teamcolor)
 
 void nb_spawnteams(void)
 {
-       float t_r, t_b, t_y, t_p;
+       float t_r = 0, t_b = 0, t_y = 0, t_p = 0;
        entity e;
        for(e = world; (e = find(e, classname, "nexball_goal"));)
        {
@@ -639,11 +648,29 @@ void spawnfunc_ball_bound(void)
 //      Weapon code      //
 //=======================//
 
+
+void W_Nexball_Think()
+{
+    //dprint("W_Nexball_Think\n");
+    //vector new_dir = steerlib_arrive(self.enemy.origin, 2500);
+    vector new_dir = normalize(self.enemy.origin - self.origin);
+    vector old_dir = normalize(self.velocity);     
+    float _speed = vlen(self.velocity);    
+    vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
+    //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
+    
+    self.velocity = new_vel;
+    
+    self.nextthink = time;
+}
+
 void W_Nexball_Touch(void)
 {
        entity ball, attacker;
        attacker = self.owner;
-
+    //self.think = SUB_Null;
+    //self.enemy = world;
+    
        PROJECTILE_TOUCH;
        if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
                if((ball = other.ballcarried) && (attacker.classname == "player"))
@@ -697,12 +724,28 @@ void W_Nexball_Attack(float t)
                        mul = 2 - mul;
                mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
        }
-       DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, FALSE));
+       
+    DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, FALSE));
+       
+
        //TODO: use the speed_up cvar too ??
 }
 
 void W_Nexball_Attack2(void)
 {
+       if(self.ballcarried.enemy)
+       {
+           entity _ball = self.ballcarried;
+        W_SetupShot(self, FALSE, 4, "nexball/shoot1.wav", CH_WEAPON_A, 0);
+           DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
+        _ball.think = W_Nexball_Think;
+        _ball.nextthink = time;
+           return;
+       }
+    
+    if(!autocvar_g_nexball_tackling)
+        return;
+       
        entity missile;
        if(!(balls & BALL_BASKET))
                return;
@@ -734,12 +777,27 @@ var const float() nullfunc;
 float ball_customize()
 {
     if(!self.owner)
+    {
+        self.effects &~= EF_FLAME;
+        self.scale = 1;
         self.customizeentityforclient = nullfunc;
+        return TRUE;
+    }        
     
     if(other == self.owner)
-        self.scale = 0.5;
+    {
+        self.scale = autocvar_g_nexball_viewmodel_scale;
+        if(self.enemy)
+            self.effects |= EF_FLAME;
+        else
+            self.effects &~= EF_FLAME;
+    }    
     else
+    {
+        self.effects &~= EF_FLAME;
         self.scale = 1;
+    }
+        
     return TRUE;
 }
 
@@ -819,44 +877,76 @@ MUTATOR_HOOKFUNCTION(nexball_BuildMutatorsPrettyString)
        return 0;
 }
 
-
 MUTATOR_HOOKFUNCTION(nexball_PlayerPreThink)
 {
+    makevectors(self.v_angle);
     if(nexball_mode & NBM_BASKETBALL)
-    if(self.ballcarried)
-    {
-        makevectors(self.v_angle);
-        self.ballcarried.velocity = self.velocity;            
-        self.ballcarried.customizeentityforclient = ball_customize;
-        setorigin(self.ballcarried, self.origin + self.view_ofs + v_forward * 23 + v_right * 4);              
-    }
-    
-    if(!self.ballcarried && self.weaponentity.weapons)
-    {
-        self.weapons = self.weaponentity.weapons;        
-        weapon_action(WEP_PORTO, WR_RESETPLAYER);
-        self.switchweapon = self.weaponentity.switchweapon;
-        W_SwitchWeapon(self.switchweapon);
+    {        
+        if(self.ballcarried)
+        {
+            // 'view ball'
+            self.ballcarried.velocity = self.velocity;            
+            self.ballcarried.customizeentityforclient = ball_customize;
+            
+            setorigin(self.ballcarried, self.origin + self.view_ofs + 
+                      v_forward * autocvar_g_nexball_viewmodel_offset_x + 
+                      v_right * autocvar_g_nexball_viewmodel_offset_y + 
+                      v_up * autocvar_g_nexball_viewmodel_offset_z);    
+                      
+            // 'safe passing'
+            if(autocvar_g_nexball_safepass_maxdist)
+            {
+                if(self.ballcarried.wait < time && self.ballcarried.enemy)
+                {
+                    //centerprint(self, sprintf("Lost lock on %s", self.ballcarried.enemy.netname));
+                    self.ballcarried.enemy = world;
+                }
+                    
+                
+                //tracebox(self.origin + self.view_ofs, '-2 -2 -2', '2 2 2', self.origin + self.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
+                crosshair_trace(self);
+                if( trace_ent && 
+                    trace_ent.flags & FL_CLIENT &&
+                    trace_ent.deadflag == DEAD_NO &&
+                    trace_ent.team == self.team &&
+                    vlen(trace_ent.origin - self.origin) <= autocvar_g_nexball_safepass_maxdist )
+                {
+                    
+                    //if(self.ballcarried.enemy != trace_ent)
+                    //    centerprint(self, sprintf("Locked to %s", trace_ent.netname));
+                    self.ballcarried.enemy = trace_ent;
+                    self.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
+                    
+                    
+                }
+            }
+        }
+        else
+        {            
+            if(!WEPSET_EMPTY_E(self.weaponentity))
+            {
+                WEPSET_COPY_EE(self, self.weaponentity);
+                weapon_action(WEP_PORTO, WR_RESETPLAYER);
+                self.switchweapon = self.weaponentity.switchweapon;
+                W_SwitchWeapon(self.switchweapon);
+                
+               WEPSET_CLEAR_E(self.weaponentity);
+            }
+        }
         
-        self.weaponentity.weapons = 0;
-
     }
-    
     return FALSE;
 }
 
-
 MUTATOR_HOOKFUNCTION(nexball_PlayerSpawn)
 {    
-    self.weaponentity.weapons = 0;
+    WEPSET_CLEAR_E(self.weaponentity);
     
     if(nexball_mode & NBM_BASKETBALL)
-        return FALSE;
-    
-    if(autocvar_g_weapon_stay)
-        return FALSE;
+        WEPSET_OR_EW(self, WEP_PORTO);
+    else
+        WEPSET_CLEAR_E(self);
 
-    self.weapons = 0;
     return FALSE;
 }
 
@@ -872,7 +962,6 @@ MUTATOR_DEFINITION(gamemode_nexball)
 
        MUTATOR_ONADD
        {
-           g_nexball = 1;
                g_nexball_meter_period = autocvar_g_nexball_meter_period;
                if(g_nexball_meter_period <= 0)
                        g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users