]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/door.qc
Apply the same fix to regular doors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / door.qc
index 1a1c82b9addb74741c8ae8013f97f09863dae133..921642406e6d8b357e9a2250e755572ec5fae855 100644 (file)
@@ -26,8 +26,8 @@ void() door_rotating_go_down;
 void() door_rotating_go_up;
 
 void door_blocked()
-{
-       if((self.spawnflags & 8) 
+{SELFPARAM();
+       if((self.spawnflags & 8)
 #ifdef SVQC
                && (other.takedamage != DAMAGE_NO)
 #elif defined(CSQC)
@@ -36,14 +36,14 @@ void door_blocked()
        )
        { // KIll Kill Kill!!
 #ifdef SVQC
-               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
        }
        else
        {
 #ifdef SVQC
                if((self.dmg) && (other.takedamage == DAMAGE_YES))    // Shall we bite?
-                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
 
                 // don't change direction for dead or dying stuff
@@ -78,16 +78,16 @@ void door_blocked()
                {
                        //gib dying stuff just to make sure
                        if((self.dmg) && (other.takedamage != DAMAGE_NO))    // Shall we bite?
-                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
                }
 #endif
        }
 }
 
 void door_hit_top()
-{
+{SELFPARAM();
        if (self.noise1 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
        self.state = STATE_TOP;
        if (self.spawnflags & DOOR_TOGGLE)
                return;         // don't come down automatically
@@ -102,16 +102,16 @@ void door_hit_top()
 }
 
 void door_hit_bottom()
-{
+{SELFPARAM();
        if (self.noise1 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
        self.state = STATE_BOTTOM;
 }
 
 void door_go_down()
-{
+{SELFPARAM();
        if (self.noise2 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
        if (self.max_health)
        {
                self.takedamage = DAMAGE_YES;
@@ -123,7 +123,7 @@ void door_go_down()
 }
 
 void door_go_up()
-{
+{SELFPARAM();
        if (self.state == STATE_UP)
                return;         // already going up
 
@@ -134,7 +134,7 @@ void door_go_up()
        }
 
        if (self.noise2 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
        self.state = STATE_UP;
        SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, door_hit_top);
 
@@ -154,73 +154,65 @@ ACTIVATION FUNCTIONS
 =============================================================================
 */
 
-float door_check_keys(void)
+bool door_check_keys(entity door, entity player)
 {
-       local entity door;
-
-
-       if (self.owner)
-               door = self.owner;
-       else
-               door = self;
+       if(door.owner)
+               door = door.owner;
 
        // no key needed
-       if (!door.itemkeys)
+       if(!door.itemkeys)
                return true;
 
        // this door require a key
        // only a player can have a key
-       if (!IS_PLAYER(other))
+       if(!IS_PLAYER(player))
                return false;
 
-#ifdef SVQC
-       if (item_keys_usekey(door, other))
-       {
-               // some keys were used
-               if (other.key_door_messagetime <= time)
-               {
+       int valid = (door.itemkeys & player.itemkeys);
+       door.itemkeys &= ~valid; // only some of the needed keys were given
 
-                       play2(other, "misc/talk.wav");
-                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys));
-                       other.key_door_messagetime = time + 2;
-               }
+       if(!door.itemkeys)
+       {
+#ifdef SVQC
+               play2(player, SND(TALK));
+               Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_UNLOCKED);
+#endif
+               return true;
        }
-       else
+
+       if(!valid)
        {
-               // no keys were used
-               if (other.key_door_messagetime <= time)
+#ifdef SVQC
+               if(player.key_door_messagetime <= time)
                {
-                       play2(other, "misc/talk.wav");
-                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys));
-
-                       other.key_door_messagetime = time + 2;
+                       play2(player, SND(TALK));
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys));
+                       player.key_door_messagetime = time + 2;
                }
-       }
 #endif
+               return false;
+       }
 
-       if (door.itemkeys)
-       {
+       // door needs keys the player doesn't have
 #ifdef SVQC
-               // door is now unlocked
-               play2(other, "misc/talk.wav");
-               Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_UNLOCKED);
-#endif
-               return true;
+       if(player.key_door_messagetime <= time)
+       {
+               play2(player, SND(TALK));
+               Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys));
+               player.key_door_messagetime = time + 2;
        }
-       else
-               return false;
+#endif
+
+       return false;
 }
 
 void door_fire()
-{
-       entity  oself;
+{SELFPARAM();
        entity  starte;
 
        if (self.owner != self)
                objerror ("door_fire: self.owner != self");
 
-       oself = self;
-
        if (self.spawnflags & DOOR_TOGGLE)
        {
                if (self.state == STATE_UP || self.state == STATE_TOP)
@@ -236,9 +228,9 @@ void door_fire()
                                {
                                        door_rotating_go_down ();
                                }
-                               self = self.enemy;
+                               setself(self.enemy);
                        } while ( (self != starte) && (self != world) );
-                       self = oself;
+                       setself(this);
                        return;
                }
        }
@@ -265,29 +257,23 @@ void door_fire()
                                door_rotating_go_up ();
                        }
                }
-               self = self.enemy;
+               setself(self.enemy);
        } while ( (self != starte) && (self != world) );
-       self = oself;
+       setself(this);
 }
 
 void door_use()
-{
-       entity oself;
-
+{SELFPARAM();
        //dprint("door_use (model: ");dprint(self.model);dprint(")\n");
 
        if (self.owner)
        {
-               oself = self;
-               self = self.owner;
-               door_fire ();
-               self = oself;
+               WITH(entity, self, self.owner, door_fire());
        }
 }
 
-void door_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
-{
-       entity oself;
+void door_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{SELFPARAM();
        if(self.spawnflags & DOOR_NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
@@ -301,12 +287,9 @@ void door_damage(entity inflictor, entity attacker, float damage, float deathtyp
 
        if (self.health <= 0)
        {
-               oself = self;
-               self = self.owner;
-               self.health = self.max_health;
-               self.takedamage = DAMAGE_NO;    // wil be reset upon return
-               door_use ();
-               self = oself;
+               self.owner.health = self.owner.max_health;
+               self.owner.takedamage = DAMAGE_NO;      // wil be reset upon return
+               WITH(entity, self, self.owner, door_use());
        }
 }
 
@@ -320,7 +303,7 @@ Prints messages
 */
 
 void door_touch()
-{
+{SELFPARAM();
        if (!IS_PLAYER(other))
                return;
        if (self.owner.attack_finished_single > time)
@@ -333,17 +316,17 @@ void door_touch()
        {
                if (IS_CLIENT(other))
                        centerprint(other, self.owner.message);
-               play2(other, "misc/talk.wav");
+               play2(other, self.owner.noise);
        }
 #endif
 }
 
 void door_generic_plat_blocked()
-{
+{SELFPARAM();
 
        if((self.spawnflags & 8) && (other.takedamage != DAMAGE_NO)) { // KIll Kill Kill!!
 #ifdef SVQC
-               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
        }
        else
@@ -351,7 +334,7 @@ void door_generic_plat_blocked()
 
 #ifdef SVQC
                if((self.dmg) && (other.takedamage == DAMAGE_YES))    // Shall we bite?
-                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
 
                 //Dont chamge direction for dead or dying stuff
@@ -370,16 +353,16 @@ void door_generic_plat_blocked()
                {
                        //gib dying stuff just to make sure
                        if((self.dmg) && (other.takedamage != DAMAGE_NO))    // Shall we bite?
-                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
                }
 #endif
        }
 }
 
 void door_rotating_hit_top()
-{
+{SELFPARAM();
        if (self.noise1 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
        self.state = STATE_TOP;
        if (self.spawnflags & DOOR_TOGGLE)
                return;         // don't come down automatically
@@ -388,9 +371,9 @@ void door_rotating_hit_top()
 }
 
 void door_rotating_hit_bottom()
-{
+{SELFPARAM();
        if (self.noise1 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
        if (self.lip==666) // self.lip is used to remember reverse opening direction for door_rotating
        {
                self.pos2 = '0 0 0' - self.pos2;
@@ -400,9 +383,9 @@ void door_rotating_hit_bottom()
 }
 
 void door_rotating_go_down()
-{
+{SELFPARAM();
        if (self.noise2 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
        if (self.max_health)
        {
                self.takedamage = DAMAGE_YES;
@@ -414,7 +397,7 @@ void door_rotating_go_down()
 }
 
 void door_rotating_go_up()
-{
+{SELFPARAM();
        if (self.state == STATE_UP)
                return;         // already going up
 
@@ -424,7 +407,7 @@ void door_rotating_go_up()
                return;
        }
        if (self.noise2 != "")
-               sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
+               _sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTEN_NORM);
        self.state = STATE_UP;
        SUB_CalcAngleMove (self.pos2, TSPEED_LINEAR, self.speed, door_rotating_hit_top);
 
@@ -445,7 +428,7 @@ Spawned if a door lacks a real activator
 */
 
 void door_trigger_touch()
-{
+{SELFPARAM();
        if (other.health < 1)
 #ifdef SVQC
                if (!((other.iscreature || (other.flags & FL_PROJECTILE)) && !PHYS_DEAD(other)))
@@ -458,19 +441,19 @@ void door_trigger_touch()
                return;
 
        // check if door is locked
-       if (!door_check_keys())
+       if (!door_check_keys(self, other))
                return;
 
        self.attack_finished_single = time + 1;
 
        activator = other;
 
-       self = self.owner;
+       setself(self.owner);
        door_use ();
 }
 
-void spawn_field(vector fmins, vector fmaxs)
-{
+void door_spawnfield(vector fmins, vector fmaxs)
+{SELFPARAM();
        entity  trigger;
        vector  t1 = fmins, t2 = fmaxs;
 
@@ -500,7 +483,7 @@ LinkDoors
 */
 
 entity LinkDoors_nextent(entity cur, entity near, entity pass)
-{
+{SELFPARAM();
        while((cur = find(cur, classname, self.classname)) && ((cur.spawnflags & 4) || cur.enemy))
        {
        }
@@ -524,7 +507,7 @@ bool LinkDoors_isconnected(entity e1, entity e2, entity pass)
 void door_link();
 #endif
 void LinkDoors()
-{
+{SELFPARAM();
        entity  t;
        vector  cmins, cmaxs;
 
@@ -545,7 +528,7 @@ void LinkDoors()
                if (self.items)
                        return;
 
-               spawn_field(self.absmin, self.absmax);
+               door_spawnfield(self.absmin, self.absmax);
 
                return;         // don't want to link this door
        }
@@ -553,10 +536,10 @@ void LinkDoors()
        FindConnectedComponent(self, enemy, LinkDoors_nextent, LinkDoors_isconnected, world);
 
        // set owner, and make a loop of the chain
-       dprint("LinkDoors: linking doors:");
+       LOG_TRACE("LinkDoors: linking doors:");
        for(t = self; ; t = t.enemy)
        {
-               dprint(" ", etos(t));
+               LOG_TRACE(" ", etos(t));
                t.owner = self;
                if(t.enemy == world)
                {
@@ -564,7 +547,7 @@ void LinkDoors()
                        break;
                }
        }
-       dprint("\n");
+       LOG_TRACE("\n");
 
        // collect health, targetname, message, size
        cmins = self.absmin;
@@ -613,7 +596,7 @@ void LinkDoors()
        if (self.items)
                return;
 
-       spawn_field(cmins, cmaxs);
+       door_spawnfield(cmins, cmaxs);
 }
 
 #ifdef SVQC
@@ -647,7 +630,7 @@ FIXME: only one sound set available at the time being
 */
 
 float door_send(entity to, float sf)
-{
+{SELFPARAM();
        WriteByte(MSG_ENTITY, ENT_CLIENT_DOOR);
        WriteByte(MSG_ENTITY, sf);
 
@@ -703,13 +686,13 @@ float door_send(entity to, float sf)
 void door_link()
 {
        // set size now, as everything is loaded
-       FixSize(self);
-       Net_LinkEntity(self, false, 0, door_send);
+       //FixSize(self);
+       //Net_LinkEntity(self, false, 0, door_send);
 }
 #endif
 
 void door_init_startopen()
-{
+{SELFPARAM();
        SUB_SETORIGIN(self, self.pos2);
        self.pos2 = self.pos1;
        self.pos1 = self.origin;
@@ -720,7 +703,7 @@ void door_init_startopen()
 }
 
 void door_reset()
-{
+{SELFPARAM();
        SUB_SETORIGIN(self, self.pos1);
        self.SUB_VELOCITY = '0 0 0';
        self.state = STATE_BOTTOM;
@@ -735,7 +718,7 @@ void door_reset()
 #ifdef SVQC
 
 // spawnflags require key (for now only func_door)
-void spawnfunc_func_door()
+spawnfunc(func_door)
 {
        // Quake 1 keys compatibility
        if (self.spawnflags & SPAWNFLAGS_GOLD_KEY)
@@ -743,7 +726,7 @@ void spawnfunc_func_door()
        if (self.spawnflags & SPAWNFLAGS_SILVER_KEY)
                self.itemkeys |= ITEM_KEY_BIT(1);
 
-       SetMovedir ();
+       SetMovedir(self);
 
        self.max_health = self.health;
        if (!InitMovingBrushTrigger())
@@ -751,6 +734,9 @@ void spawnfunc_func_door()
        self.effects |= EF_LOWPRECISION;
        self.classname = "door";
 
+       if(self.noise == "")
+               self.noise = "misc/talk.wav";
+
        self.blocked = door_blocked;
        self.use = door_use;
 
@@ -777,6 +763,9 @@ void spawnfunc_func_door()
        self.pos1 = self.SUB_ORIGIN;
        self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
 
+       if(self.spawnflags & DOOR_NONSOLID)
+               self.solid = SOLID_NOT;
+
 // DOOR_START_OPEN is to allow an entity to be lighted in the closed position
 // but spawn in the open position
        if (self.spawnflags & DOOR_START_OPEN)
@@ -804,15 +793,15 @@ void spawnfunc_func_door()
 
 #elif defined(CSQC)
 
-void door_draw()
+void door_draw(entity this)
 {
        Movetype_Physics_NoMatchServer();
 
-       trigger_draw_generic();
+       trigger_draw_generic(this);
 }
 
 void ent_door()
-{
+{SELFPARAM();
        float sf = ReadByte();
 
        if(sf & SF_TRIGGER_INIT)
@@ -821,7 +810,7 @@ void ent_door()
                self.spawnflags = ReadByte();
 
                self.mdl = strzone(ReadString());
-               setmodel(self, self.mdl);
+               _setmodel(self, self.mdl);
 
                trigger_common_read(true);