]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/door.qc
Merge branch 'master' into TimePath/scrollpanel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / door.qc
index 706784eda7b18b13918269cbece6bad46d0bc3eb..f768717c6bbde4c18c6ba50c6b05a7e773466b3a 100644 (file)
@@ -1,3 +1,4 @@
+#include "door.qh"
 /*
 
 Doors are similar to buttons, but can spawn a fat trigger field around them
@@ -21,7 +22,7 @@ THINK FUNCTIONS
 */
 
 void door_go_down(entity this);
-void door_go_up(entity this);
+void door_go_up(entity this, entity actor, entity trigger);
 void door_rotating_go_down(entity this);
 void door_rotating_go_up(entity this, entity oth);
 
@@ -36,14 +37,14 @@ void door_blocked(entity this, entity blocker)
        )
        { // KIll Kill Kill!!
 #ifdef SVQC
-               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0');
+               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
 #endif
        }
        else
        {
 #ifdef SVQC
                if((this.dmg) && (blocker.takedamage == DAMAGE_YES))    // Shall we bite?
-                       Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0');
+                       Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
 #endif
 
                 // don't change direction for dead or dying stuff
@@ -58,7 +59,7 @@ void door_blocked(entity this, entity blocker)
                                if (this.state == STATE_DOWN)
                        if (this.classname == "door")
                        {
-                               door_go_up (this);
+                               door_go_up (this, NULL, NULL);
                        } else
                        {
                                door_rotating_go_up(this, blocker);
@@ -78,7 +79,7 @@ void door_blocked(entity this, entity blocker)
                {
                        //gib dying stuff just to make sure
                        if((this.dmg) && (blocker.takedamage != DAMAGE_NO))    // Shall we bite?
-                               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0');
+                               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
                }
 #endif
        }
@@ -93,12 +94,12 @@ void door_hit_top(entity this)
                return;         // don't come down automatically
        if (this.classname == "door")
        {
-               SUB_THINK(this, door_go_down);
+               setthink(this, door_go_down);
        } else
        {
-               SUB_THINK(this, door_rotating_go_down);
+               setthink(this, door_rotating_go_down);
        }
-       this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
+       this.nextthink = this.ltime + this.wait;
 }
 
 void door_hit_bottom(entity this)
@@ -122,14 +123,14 @@ void door_go_down(entity this)
        SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, door_hit_bottom);
 }
 
-void door_go_up(entity this)
+void door_go_up(entity this, entity actor, entity trigger)
 {
        if (this.state == STATE_UP)
                return;         // already going up
 
        if (this.state == STATE_TOP)
        {       // reset top wait time
-               this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
+               this.nextthink = this.ltime + this.wait;
                return;
        }
 
@@ -141,7 +142,7 @@ void door_go_up(entity this)
        string oldmessage;
        oldmessage = this.message;
        this.message = "";
-       SUB_UseTargets(this, NULL, NULL);
+       SUB_UseTargets(this, actor, trigger);
        this.message = oldmessage;
 }
 
@@ -168,7 +169,11 @@ bool door_check_keys(entity door, entity player)
        if(!IS_PLAYER(player))
                return false;
 
-       int valid = (door.itemkeys & player.itemkeys);
+       entity store = player;
+#ifdef SVQC
+       store = PS(player);
+#endif
+       int valid = (door.itemkeys & store.itemkeys);
        door.itemkeys &= ~valid; // only some of the needed keys were given
 
        if(!door.itemkeys)
@@ -232,7 +237,7 @@ void door_fire(entity this, entity actor, entity trigger)
        entity e = this;
        do {
                if (e.classname == "door") {
-                       door_go_up(e);
+                       door_go_up(e, actor, trigger);
                } else {
                        // if the BIDIR spawnflag (==2) is set and the trigger has set trigger_reverse, reverse the opening direction
                        if ((e.spawnflags & 2) && trigger.trigger_reverse!=0 && e.lip != 666 && e.state == STATE_BOTTOM) {
@@ -258,7 +263,7 @@ void door_use(entity this, entity actor, entity trigger)
                door_fire(this.owner, actor, trigger);
 }
 
-void door_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+void door_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
 {
        if(this.spawnflags & DOOR_NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
@@ -312,7 +317,7 @@ void door_generic_plat_blocked(entity this, entity blocker)
 {
        if((this.spawnflags & 8) && (blocker.takedamage != DAMAGE_NO)) { // Kill Kill Kill!!
 #ifdef SVQC
-               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0');
+               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
 #endif
        }
        else
@@ -320,7 +325,7 @@ void door_generic_plat_blocked(entity this, entity blocker)
 
 #ifdef SVQC
                if((this.dmg) && (blocker.takedamage == DAMAGE_YES))    // Shall we bite?
-                       Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0');
+                       Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
 #endif
 
                 //Dont chamge direction for dead or dying stuff
@@ -339,7 +344,7 @@ void door_generic_plat_blocked(entity this, entity blocker)
                {
                        //gib dying stuff just to make sure
                        if((this.dmg) && (blocker.takedamage != DAMAGE_NO))    // Shall we bite?
-                               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0');
+                               Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
                }
 #endif
        }
@@ -352,8 +357,8 @@ void door_rotating_hit_top(entity this)
        this.state = STATE_TOP;
        if (this.spawnflags & DOOR_TOGGLE)
                return;         // don't come down automatically
-       SUB_THINK(this, door_rotating_go_down);
-       this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
+       setthink(this, door_rotating_go_down);
+       this.nextthink = this.ltime + this.wait;
 }
 
 void door_rotating_hit_bottom(entity this)
@@ -389,7 +394,7 @@ void door_rotating_go_up(entity this, entity oth)
 
        if (this.state == STATE_TOP)
        {       // reset top wait time
-               this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
+               this.nextthink = this.ltime + this.wait;
                return;
        }
        if (this.noise2 != "")
@@ -623,22 +628,16 @@ float door_send(entity this, entity to, float sf)
 
                trigger_common_write(this, true);
 
-               WriteCoord(MSG_ENTITY, this.pos1_x);
-               WriteCoord(MSG_ENTITY, this.pos1_y);
-               WriteCoord(MSG_ENTITY, this.pos1_z);
-               WriteCoord(MSG_ENTITY, this.pos2_x);
-               WriteCoord(MSG_ENTITY, this.pos2_y);
-               WriteCoord(MSG_ENTITY, this.pos2_z);
+               WriteVector(MSG_ENTITY, this.pos1);
+               WriteVector(MSG_ENTITY, this.pos2);
 
-               WriteCoord(MSG_ENTITY, this.size_x);
-               WriteCoord(MSG_ENTITY, this.size_y);
-               WriteCoord(MSG_ENTITY, this.size_z);
+               WriteVector(MSG_ENTITY, this.size);
 
                WriteShort(MSG_ENTITY, this.wait);
                WriteShort(MSG_ENTITY, this.speed);
                WriteByte(MSG_ENTITY, this.lip);
                WriteByte(MSG_ENTITY, this.state);
-               WriteCoord(MSG_ENTITY, this.SUB_LTIME);
+               WriteCoord(MSG_ENTITY, this.ltime);
        }
 
        if(sf & SF_TRIGGER_RESET)
@@ -648,16 +647,10 @@ float door_send(entity this, entity to, float sf)
 
        if(sf & SF_TRIGGER_UPDATE)
        {
-               WriteCoord(MSG_ENTITY, this.origin_x);
-               WriteCoord(MSG_ENTITY, this.origin_y);
-               WriteCoord(MSG_ENTITY, this.origin_z);
-
-               WriteCoord(MSG_ENTITY, this.pos1_x);
-               WriteCoord(MSG_ENTITY, this.pos1_y);
-               WriteCoord(MSG_ENTITY, this.pos1_z);
-               WriteCoord(MSG_ENTITY, this.pos2_x);
-               WriteCoord(MSG_ENTITY, this.pos2_y);
-               WriteCoord(MSG_ENTITY, this.pos2_z);
+               WriteVector(MSG_ENTITY, this.origin);
+
+               WriteVector(MSG_ENTITY, this.pos1);
+               WriteVector(MSG_ENTITY, this.pos2);
        }
 
        return true;
@@ -673,7 +666,7 @@ void door_link()
 
 void door_init_startopen(entity this)
 {
-       SUB_SETORIGIN(this, this.pos2);
+       setorigin(this, this.pos2);
        this.pos2 = this.pos1;
        this.pos1 = this.origin;
 
@@ -684,11 +677,11 @@ void door_init_startopen(entity this)
 
 void door_reset(entity this)
 {
-       SUB_SETORIGIN(this, this.pos1);
-       this.SUB_VELOCITY = '0 0 0';
+       setorigin(this, this.pos1);
+       this.velocity = '0 0 0';
        this.state = STATE_BOTTOM;
-       SUB_THINK(this, func_null);
-       this.SUB_NEXTTHINK = 0;
+       setthink(this, func_null);
+       this.nextthink = 0;
 
 #ifdef SVQC
        this.SendFlags |= SF_TRIGGER_RESET;
@@ -731,12 +724,13 @@ spawnfunc(func_door)
 
        if (this.sounds > 0)
        {
-               precache_sound ("plats/medplat1.wav");
-               precache_sound ("plats/medplat2.wav");
                this.noise2 = "plats/medplat1.wav";
                this.noise1 = "plats/medplat2.wav";
        }
 
+       if(this.noise1 && this.noise1 != "") { precache_sound(this.noise1); }
+       if(this.noise2 && this.noise2 != "") { precache_sound(this.noise2); }
+
        if (!this.speed)
                this.speed = 100;
        if (!this.wait)
@@ -744,7 +738,7 @@ spawnfunc(func_door)
        if (!this.lip)
                this.lip = 8;
 
-       this.pos1 = this.SUB_ORIGIN;
+       this.pos1 = this.origin;
        this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
 
        if(this.spawnflags & DOOR_NONSOLID)
@@ -759,6 +753,7 @@ spawnfunc(func_door)
 
        if (this.health)
        {
+               //this.canteamdamage = true; // TODO
                this.takedamage = DAMAGE_YES;
                this.event_damage = door_damage;
        }
@@ -791,28 +786,16 @@ NET_HANDLE(ENT_CLIENT_DOOR, bool isnew)
 
                trigger_common_read(this, true);
 
-               vector v;
-
-               v.x = ReadCoord();
-               v.y = ReadCoord();
-               v.z = ReadCoord();
-               this.pos1 = v;
-
-               v.x = ReadCoord();
-               v.y = ReadCoord();
-               v.z = ReadCoord();
-               this.pos2 = v;
+               this.pos1 = ReadVector();
+               this.pos2 = ReadVector();
 
-               v.x = ReadCoord();
-               v.y = ReadCoord();
-               v.z = ReadCoord();
-               this.size = v;
+               this.size = ReadVector();
 
                this.wait = ReadShort();
                this.speed = ReadShort();
                this.lip = ReadByte();
                this.state = ReadByte();
-               this.SUB_LTIME = ReadCoord();
+               this.ltime = ReadCoord();
 
                this.solid = SOLID_BSP;
                set_movetype(this, MOVETYPE_PUSH);
@@ -834,17 +817,11 @@ NET_HANDLE(ENT_CLIENT_DOOR, bool isnew)
 
        if(sf & SF_TRIGGER_UPDATE)
        {
-               this.origin_x = ReadCoord();
-               this.origin_y = ReadCoord();
-               this.origin_z = ReadCoord();
+               this.origin = ReadVector();
                setorigin(this, this.origin);
 
-               this.pos1_x = ReadCoord();
-               this.pos1_y = ReadCoord();
-               this.pos1_z = ReadCoord();
-               this.pos2_x = ReadCoord();
-               this.pos2_y = ReadCoord();
-               this.pos2_z = ReadCoord();
+               this.pos1 = ReadVector();
+               this.pos2 = ReadVector();
        }
        return true;
 }