]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/door.qc
Merge branch 'master' into Mario/use1
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / door.qc
index 921642406e6d8b357e9a2250e755572ec5fae855..0546b2eae009f83316d4b83448dc8aa09bcad15e 100644 (file)
@@ -31,7 +31,7 @@ void door_blocked()
 #ifdef SVQC
                && (other.takedamage != DAMAGE_NO)
 #elif defined(CSQC)
-               && !PHYS_DEAD(other)
+               && !IS_DEAD(other)
 #endif
        )
        { // KIll Kill Kill!!
@@ -47,7 +47,7 @@ void door_blocked()
 #endif
 
                 // don't change direction for dead or dying stuff
-               if(PHYS_DEAD(other)
+               if(IS_DEAD(other)
 #ifdef SVQC
                        && (other.takedamage == DAMAGE_NO)
 #endif
@@ -141,7 +141,7 @@ void door_go_up()
        string oldmessage;
        oldmessage = self.message;
        self.message = "";
-       SUB_UseTargets();
+       SUB_UseTargets(self, NULL, NULL);
        self.message = oldmessage;
 }
 
@@ -185,7 +185,7 @@ bool door_check_keys(entity door, entity player)
 #ifdef SVQC
                if(player.key_door_messagetime <= time)
                {
-                       play2(player, SND(TALK));
+                       play2(player, door.noise3);
                        Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys));
                        player.key_door_messagetime = time + 2;
                }
@@ -197,7 +197,7 @@ bool door_check_keys(entity door, entity player)
 #ifdef SVQC
        if(player.key_door_messagetime <= time)
        {
-               play2(player, SND(TALK));
+               play2(player, door.noise3);
                Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys));
                player.key_door_messagetime = time + 2;
        }
@@ -206,16 +206,15 @@ bool door_check_keys(entity door, entity player)
        return false;
 }
 
-void door_fire()
-{SELFPARAM();
-       entity  starte;
-
-       if (self.owner != self)
-               objerror ("door_fire: self.owner != self");
+void door_fire(entity this, entity actor, entity trigger)
+{
+       entity starte;
+       if (this.owner != this)
+               objerror ("door_fire: this.owner != this");
 
-       if (self.spawnflags & DOOR_TOGGLE)
+       if (this.spawnflags & DOOR_TOGGLE)
        {
-               if (self.state == STATE_UP || self.state == STATE_TOP)
+               if (this.state == STATE_UP || this.state == STATE_TOP)
                {
                        starte = self;
                        do
@@ -262,37 +261,36 @@ void door_fire()
        setself(this);
 }
 
-void door_use()
-{SELFPARAM();
+void door_use(entity this, entity actor, entity trigger)
+{
        //dprint("door_use (model: ");dprint(self.model);dprint(")\n");
 
-       if (self.owner)
-       {
-               WITH(entity, self, self.owner, door_fire());
-       }
+       if (this.owner)
+               WITHSELF(this.owner, door_fire(this.owner, actor, trigger));
 }
 
-void door_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
-{SELFPARAM();
-       if(self.spawnflags & DOOR_NOSPLASH)
+void door_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{
+       if(this.spawnflags & DOOR_NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
-       self.health = self.health - damage;
+       this.health = this.health - damage;
 
-       if (self.itemkeys)
+       if (this.itemkeys)
        {
                // don't allow opening doors through damage if keys are required
                return;
        }
 
-       if (self.health <= 0)
+       if (this.health <= 0)
        {
-               self.owner.health = self.owner.max_health;
-               self.owner.takedamage = DAMAGE_NO;      // wil be reset upon return
-               WITH(entity, self, self.owner, door_use());
+               this.owner.health = this.owner.max_health;
+               this.owner.takedamage = DAMAGE_NO;      // wil be reset upon return
+               door_use(this.owner, NULL, NULL);
        }
 }
 
+.float door_finished;
 
 /*
 ================
@@ -306,10 +304,10 @@ void door_touch()
 {SELFPARAM();
        if (!IS_PLAYER(other))
                return;
-       if (self.owner.attack_finished_single > time)
+       if (self.owner.door_finished > time)
                return;
 
-       self.owner.attack_finished_single = time + 2;
+       self.owner.door_finished = time + 2;
 
 #ifdef SVQC
        if (!(self.owner.dmg) && (self.owner.message != ""))
@@ -338,7 +336,7 @@ void door_generic_plat_blocked()
 #endif
 
                 //Dont chamge direction for dead or dying stuff
-               if(PHYS_DEAD(other) && (other.takedamage == DAMAGE_NO))
+               if(IS_DEAD(other) && (other.takedamage == DAMAGE_NO))
                {
                        if (self.wait >= 0)
                        {
@@ -414,7 +412,7 @@ void door_rotating_go_up()
        string oldmessage;
        oldmessage = self.message;
        self.message = "";
-       SUB_UseTargets();
+       SUB_UseTargets(self, NULL, other); // TODO: is other needed here?
        self.message = oldmessage;
 }
 
@@ -431,25 +429,22 @@ void door_trigger_touch()
 {SELFPARAM();
        if (other.health < 1)
 #ifdef SVQC
-               if (!((other.iscreature || (other.flags & FL_PROJECTILE)) && !PHYS_DEAD(other)))
+               if (!((other.iscreature || (other.flags & FL_PROJECTILE)) && !IS_DEAD(other)))
 #elif defined(CSQC)
-               if(!((IS_CLIENT(other) || other.classname == "csqcprojectile") && !PHYS_DEAD(other)))
+               if(!((IS_CLIENT(other) || other.classname == "csqcprojectile") && !IS_DEAD(other)))
 #endif
                        return;
 
-       if (time < self.attack_finished_single)
+       if (time < self.door_finished)
                return;
 
        // check if door is locked
        if (!door_check_keys(self, other))
                return;
 
-       self.attack_finished_single = time + 1;
-
-       activator = other;
+       self.door_finished = time + 1;
 
-       setself(self.owner);
-       door_use ();
+       door_use(this.owner, other, NULL);
 }
 
 void door_spawnfield(vector fmins, vector fmaxs)
@@ -457,8 +452,7 @@ void door_spawnfield(vector fmins, vector fmaxs)
        entity  trigger;
        vector  t1 = fmins, t2 = fmaxs;
 
-       trigger = spawn();
-       trigger.classname = "doortriggerfield";
+       trigger = new(doortriggerfield);
        trigger.movetype = MOVETYPE_NONE;
        trigger.solid = SOLID_TRIGGER;
        trigger.owner = self;
@@ -506,8 +500,8 @@ bool LinkDoors_isconnected(entity e1, entity e2, entity pass)
 #ifdef SVQC
 void door_link();
 #endif
-void LinkDoors()
-{SELFPARAM();
+void LinkDoors(entity this)
+{
        entity  t;
        vector  cmins, cmaxs;
 
@@ -599,6 +593,8 @@ void LinkDoors()
        door_spawnfield(cmins, cmaxs);
 }
 
+REGISTER_NET_LINKED(ENT_CLIENT_DOOR)
+
 #ifdef SVQC
 /*QUAKED spawnfunc_func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK GOLD_KEY SILVER_KEY TOGGLE
 if two doors touch, they are assumed to be connected and operate as a unit.
@@ -631,7 +627,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);
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_DOOR);
        WriteByte(MSG_ENTITY, sf);
 
        if(sf & SF_TRIGGER_INIT)
@@ -641,7 +637,7 @@ float door_send(entity to, float sf)
 
                WriteString(MSG_ENTITY, self.model);
 
-               trigger_common_write(true);
+               trigger_common_write(self, true);
 
                WriteCoord(MSG_ENTITY, self.pos1_x);
                WriteCoord(MSG_ENTITY, self.pos1_y);
@@ -691,8 +687,8 @@ void door_link()
 }
 #endif
 
-void door_init_startopen()
-{SELFPARAM();
+void door_init_startopen(entity this)
+{
        SUB_SETORIGIN(self, self.pos2);
        self.pos2 = self.pos1;
        self.pos1 = self.origin;
@@ -702,16 +698,16 @@ void door_init_startopen()
 #endif
 }
 
-void door_reset()
-{SELFPARAM();
-       SUB_SETORIGIN(self, self.pos1);
-       self.SUB_VELOCITY = '0 0 0';
-       self.state = STATE_BOTTOM;
-       self.SUB_THINK = func_null;
-       self.SUB_NEXTTHINK = 0;
+void door_reset(entity this)
+{
+       SUB_SETORIGIN(this, this.pos1);
+       this.SUB_VELOCITY = '0 0 0';
+       this.state = STATE_BOTTOM;
+       this.SUB_THINK = func_null;
+       this.SUB_NEXTTHINK = 0;
 
 #ifdef SVQC
-       self.SendFlags |= SF_TRIGGER_RESET;
+       this.SendFlags |= SF_TRIGGER_RESET;
 #endif
 }
 
@@ -736,9 +732,13 @@ spawnfunc(func_door)
 
        if(self.noise == "")
                self.noise = "misc/talk.wav";
+       if(self.noise3 == "")
+               self.noise3 = "misc/talk.wav";
+       precache_sound(self.noise);
+       precache_sound(self.noise3);
 
        self.blocked = door_blocked;
-       self.use = door_use;
+       self.use1 = door_use;
 
        if(self.dmg && (self.message == ""))
                self.message = "was squished";
@@ -795,81 +795,88 @@ spawnfunc(func_door)
 
 void door_draw(entity this)
 {
-       Movetype_Physics_NoMatchServer();
+       Movetype_Physics_NoMatchServer(this);
 
        trigger_draw_generic(this);
 }
 
-void ent_door()
-{SELFPARAM();
+NET_HANDLE(ENT_CLIENT_DOOR, bool isnew)
+{
        float sf = ReadByte();
 
        if(sf & SF_TRIGGER_INIT)
        {
-               self.classname = strzone(ReadString());
-               self.spawnflags = ReadByte();
+               this.classname = strzone(ReadString());
+               this.spawnflags = ReadByte();
 
-               self.mdl = strzone(ReadString());
-               _setmodel(self, self.mdl);
+               this.mdl = strzone(ReadString());
+               _setmodel(this, this.mdl);
 
                trigger_common_read(true);
 
-               self.pos1_x = ReadCoord();
-               self.pos1_y = ReadCoord();
-               self.pos1_z = ReadCoord();
-               self.pos2_x = ReadCoord();
-               self.pos2_y = ReadCoord();
-               self.pos2_z = ReadCoord();
-
-               self.size_x = ReadCoord();
-               self.size_y = ReadCoord();
-               self.size_z = ReadCoord();
-
-               self.wait = ReadShort();
-               self.speed = ReadShort();
-               self.lip = ReadByte();
-               self.state = ReadByte();
-               self.SUB_LTIME = ReadCoord();
-
-               self.solid = SOLID_BSP;
-               self.movetype = MOVETYPE_PUSH;
-               self.trigger_touch = door_touch;
-               self.draw = door_draw;
-               self.drawmask = MASK_NORMAL;
-               self.use = door_use;
-
-               LinkDoors();
-
-               if(self.spawnflags & DOOR_START_OPEN)
-                       door_init_startopen();
-
-               self.move_time = time;
-               self.move_origin = self.origin;
-               self.move_movetype = MOVETYPE_PUSH;
-               self.move_angles = self.angles;
-               self.move_blocked = door_blocked;
+               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;
+
+               v.x = ReadCoord();
+               v.y = ReadCoord();
+               v.z = ReadCoord();
+               this.size = v;
+
+               this.wait = ReadShort();
+               this.speed = ReadShort();
+               this.lip = ReadByte();
+               this.state = ReadByte();
+               this.SUB_LTIME = ReadCoord();
+
+               this.solid = SOLID_BSP;
+               this.movetype = MOVETYPE_PUSH;
+               this.trigger_touch = door_touch;
+               this.draw = door_draw;
+               this.drawmask = MASK_NORMAL;
+               this.use1 = door_use;
+
+               LinkDoors(this);
+
+               if(this.spawnflags & DOOR_START_OPEN)
+                       door_init_startopen(this);
+
+               this.move_time = time;
+               this.move_origin = this.origin;
+               this.move_movetype = MOVETYPE_PUSH;
+               this.move_angles = this.angles;
+               this.move_blocked = door_blocked;
        }
 
        if(sf & SF_TRIGGER_RESET)
        {
-               door_reset();
+               door_reset(this);
        }
 
        if(sf & SF_TRIGGER_UPDATE)
        {
-               self.origin_x = ReadCoord();
-               self.origin_y = ReadCoord();
-               self.origin_z = ReadCoord();
-               setorigin(self, self.origin);
-               self.move_origin = self.origin;
-
-               self.pos1_x = ReadCoord();
-               self.pos1_y = ReadCoord();
-               self.pos1_z = ReadCoord();
-               self.pos2_x = ReadCoord();
-               self.pos2_y = ReadCoord();
-               self.pos2_z = ReadCoord();
+               this.origin_x = ReadCoord();
+               this.origin_y = ReadCoord();
+               this.origin_z = ReadCoord();
+               setorigin(this, this.origin);
+               this.move_origin = 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();
        }
+       return true;
 }
 
 #endif