]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/w_minelayer.qc
I have no idea why, but this fixes the mine layer.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_minelayer.qc
index 20442e86fe03208748a381e0b5e25c42acf3d3d8..da847d2709c19de897d57b1610a293537960cc75 100644 (file)
@@ -1,32 +1,57 @@
-/*TODO list (things left to do before this weapon should be ready, delete once it's all done):
-- The weapon currently uses sounds and models from other weapons. We need a modeler and sound artist to make this weapon its own (the gun model should probably be something between the porto and rocket launcher design-wise).
-- Mines remain stuck in the air if they hit a moving entity (like an elevator or players). They should normally stick to them... perhaps set them as an attachment?
-- Bot code for the weapon may be needed. The bot AI may not have any info about this gun yet.
-- The mine model needs to face properly when it sticks to a surface. Once we'll have a correct mine model, we can't afford the model facing any way it falls to the ground. Should probably look at the porto code to see how portals face in the right direction when sticking to walls. 
-*/
-
 #ifdef REGISTER_WEAPON
 REGISTER_WEAPON(MINE_LAYER, w_minelayer, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "minelayer", "minelayer", "Mine Layer");
 #else
 #ifdef SVQC
-.float minelayer_detonate;
-.float mine_number, mine_time;
+void W_Mine_Think (void);
+.float minelayer_detonate, minelayer_mines;
+.float mine_time;
 
 void spawnfunc_weapon_minelayer (void)
 {
        weapon_defaultspawnfunc(WEP_MINE_LAYER);
 }
 
-void W_Mine_Unregister()
+void W_Mine_Stick ()
 {
-       if(self.owner && self.owner.lastmine == self)
-               self.owner.lastmine = world;
+       spamsound (self, CHAN_PROJECTILE, "weapons/mine_stick.wav", VOL_BASE, ATTN_NORM);
+
+       // in order for mines to face properly when sticking to the ground, they must be a server side entity rather than a csqc projectile
+
+       local entity newmine;
+       newmine = spawn();
+       newmine.classname = self.classname;
+
+       newmine.bot_dodge = self.bot_dodge;
+       newmine.bot_dodgerating = self.bot_dodgerating;
+
+       newmine.owner = self.owner;
+       setsize(newmine, '-4 -4 -4', '4 4 4');
+       setorigin(newmine, self.origin);
+       setmodel(newmine, "models/mine.md3");
+       newmine.angles = vectoangles(-trace_plane_normal); // face against the surface
+
+       newmine.takedamage = self.takedamage;
+       newmine.damageforcescale = self.damageforcescale;
+       newmine.health = self.health;
+       newmine.event_damage = self.event_damage;
+
+       newmine.movetype = MOVETYPE_NONE; // lock the mine in place
+       newmine.projectiledeathtype = self.projectiledeathtype;
+
+       newmine.mine_time = self.mine_time;
+
+       newmine.touch = SUB_Null;
+       newmine.think = W_Mine_Think;
+       newmine.nextthink = time;
+       newmine.cnt = self.cnt;
+       newmine.flags = self.flags;
+
+       remove(self);
+       self = newmine;
 }
 
 void W_Mine_Explode ()
 {
-       W_Mine_Unregister();
-
        if(other.takedamage == DAMAGE_AIM)
                if(other.classname == "player")
                        if(IsDifferentTeam(self.owner, other))
@@ -52,8 +77,6 @@ void W_Mine_Explode ()
 
 void W_Mine_DoRemoteExplode ()
 {
-       W_Mine_Unregister();
-
        self.event_damage = SUB_Null;
        self.takedamage = DAMAGE_NO;
 
@@ -71,11 +94,9 @@ void W_Mine_DoRemoteExplode ()
        remove (self);
 }
 
-void W_Mine_RemoteExplode()
+void W_Mine_RemoteExplode ()
 {
        if(self.owner.deadflag == DEAD_NO)
-       if(self.owner.lastmine)
-       {
                if((self.spawnshieldtime >= 0)
                        ? (time >= self.spawnshieldtime) // timer
                        : (vlen(NearestPointOnBox(self.owner, self.origin) - self.origin) > cvar("g_balance_minelayer_radius")) // safety device
@@ -83,10 +104,9 @@ void W_Mine_RemoteExplode()
                {
                        W_Mine_DoRemoteExplode();
                }
-       }
 }
 
-void W_Mine_ProximityExplode()
+void W_Mine_ProximityExplode ()
 {
        // make sure no friend is in the mine's radius. If there is any, explosion is delayed until he's at a safe distance
        if(cvar("g_balance_minelayer_protection"))
@@ -114,12 +134,22 @@ void W_Mine_Think (void)
        {
                other = world;
                self.projectiledeathtype |= HITTYPE_BOUNCE;
-               W_Mine_Explode ();
+               W_Mine_Explode();
                return;
        }
 
-       // set the mine for detonation when a foe gets too close
-       head = findradius(self.origin, cvar("g_balance_minelayer_detectionradius"));
+       // a player's mines shall explode if he disconnects or dies
+       // TODO: Do this on team change too
+       if(self.owner.classname != "player" || self.owner.deadflag != DEAD_NO)
+       {
+               other = world;
+               self.projectiledeathtype |= HITTYPE_BOUNCE;
+               W_Mine_Explode();
+               return;
+       }
+
+       // set the mine for detonation when a foe gets close enough
+       head = findradius(self.origin, cvar("g_balance_minelayer_proximityradius"));
        while(head)
        {
                if(head.classname == "player" && head.deadflag == DEAD_NO)
@@ -149,9 +179,10 @@ void W_Mine_Think (void)
 void W_Mine_Touch (void)
 {
        PROJECTILE_TOUCH;
-       spamsound (self, CHAN_PROJECTILE, "weapons/mine_stick.wav", VOL_BASE, ATTN_NORM);
-       self.movetype = MOVETYPE_NONE; // lock the mine in place
-       // TODO: make sure this doesn't cause the mine to get stuck in the air if it falls over a moving entity
+       if(!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))
+               W_Mine_Stick();
+       else if(self.movetype != MOVETYPE_NONE) // don't unstick a locked mine when someone touches it
+               self.velocity = '0 0 0';
 }
 
 void W_Mine_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
@@ -172,12 +203,11 @@ void W_Mine_Attack (void)
        // scan how many mines we placed, and return if we reached our limit
        if(cvar("g_balance_minelayer_limit"))
        {
-               entity mine;
-               self.mine_number = 0;
+               self.minelayer_mines = 0;
                for(mine = world; (mine = find(mine, classname, "mine")); ) if(mine.owner == self)
-                       self.mine_number += 1;
+                       self.minelayer_mines += 1;
 
-               if(self.mine_number >= cvar("g_balance_minelayer_limit"))
+               if(self.minelayer_mines >= cvar("g_balance_minelayer_limit"))
                {
                        // the refire delay keeps this message from being spammed
                        sprint(self, strcat("You cannot place more than ^2", cvar_string("g_balance_minelayer_limit"), " ^7mines at a time\n") );
@@ -194,7 +224,6 @@ void W_Mine_Attack (void)
 
        mine = WarpZone_RefSys_SpawnSameRefSys(self);
        mine.owner = self;
-       self.lastmine = mine;
        if(cvar("g_balance_minelayer_detonatedelay") >= 0)
                mine.spawnshieldtime = time + cvar("g_balance_minelayer_detonatedelay");
        else
@@ -214,7 +243,7 @@ void W_Mine_Attack (void)
        setsize (mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot
 
        setorigin (mine, w_shotorg - v_forward * 4); // move it back so it hits the wall at the right point
-       W_SetupProjectileVelocity(mine, cvar("g_balance_minelayer_speedstart"), 0);
+       W_SetupProjectileVelocity(mine, cvar("g_balance_minelayer_speed"), 0);
        mine.angles = vectoangles (mine.velocity);
 
        mine.touch = W_Mine_Touch;
@@ -365,6 +394,7 @@ float w_minelayer(float req)
        else if (req == WR_PRECACHE)
        {
                precache_model ("models/flash.md3");
+               precache_model ("models/mine.md3");
                precache_model ("models/weapons/g_minelayer.md3");
                precache_model ("models/weapons/v_minelayer.md3");
                precache_model ("models/weapons/h_minelayer.iqm");