]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/door.qc
Merge branch 'master' into TimePath/unified_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / door.qc
index 9c5a625e1ba861995593d1af49fca3145db925a2..fed8e9fa424515b9c3aa8aa5aa3f5029e07b3529 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)
@@ -85,33 +85,33 @@ void door_blocked()
 }
 
 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
        if (self.classname == "door")
        {
-               self.think = door_go_down;
+               self.SUB_THINK = door_go_down;
        } else
        {
-               self.think = door_rotating_go_down;
+               self.SUB_THINK = door_rotating_go_down;
        }
-       trigger_setnextthink(self, self.ltime + self.wait);
+       self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
 }
 
 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,18 +123,18 @@ void door_go_down()
 }
 
 void door_go_up()
-{
+{SELFPARAM();
        if (self.state == STATE_UP)
                return;         // already going up
 
        if (self.state == STATE_TOP)
        {       // reset top wait time
-               trigger_setnextthink(self, self.ltime + self.wait);
+               self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
                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_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, door_hit_top);
 
@@ -155,7 +155,7 @@ ACTIVATION FUNCTIONS
 */
 
 float door_check_keys(void)
-{
+{SELFPARAM();
        local entity door;
 
 
@@ -180,7 +180,7 @@ float door_check_keys(void)
                if (other.key_door_messagetime <= time)
                {
 
-                       play2(other, "misc/talk.wav");
+                       play2(other, SND(TALK));
                        Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys));
                        other.key_door_messagetime = time + 2;
                }
@@ -190,7 +190,7 @@ float door_check_keys(void)
                // no keys were used
                if (other.key_door_messagetime <= time)
                {
-                       play2(other, "misc/talk.wav");
+                       play2(other, SND(TALK));
                        Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys));
 
                        other.key_door_messagetime = time + 2;
@@ -202,7 +202,7 @@ float door_check_keys(void)
        {
 #ifdef SVQC
                // door is now unlocked
-               play2(other, "misc/talk.wav");
+               play2(other, SND(TALK));
                Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_UNLOCKED);
 #endif
                return true;
@@ -212,15 +212,12 @@ float door_check_keys(void)
 }
 
 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 +233,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 +262,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 +292,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 +308,7 @@ Prints messages
 */
 
 void door_touch()
-{
+{SELFPARAM();
        if (!IS_PLAYER(other))
                return;
        if (self.owner.attack_finished_single > time)
@@ -333,13 +321,13 @@ void door_touch()
        {
                if (IS_CLIENT(other))
                        centerprint(other, self.owner.message);
-               play2(other, "misc/talk.wav");
+               play2(other, SND(TALK));
        }
 #endif
 }
 
 void door_generic_plat_blocked()
-{
+{SELFPARAM();
 
        if((self.spawnflags & 8) && (other.takedamage != DAMAGE_NO)) { // KIll Kill Kill!!
 #ifdef SVQC
@@ -377,20 +365,20 @@ void door_generic_plat_blocked()
 }
 
 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
-       self.think = door_rotating_go_down;
-       self.nextthink = self.ltime + self.wait;
+       self.SUB_THINK = door_rotating_go_down;
+       self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
 }
 
 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 +388,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,17 +402,17 @@ void door_rotating_go_down()
 }
 
 void door_rotating_go_up()
-{
+{SELFPARAM();
        if (self.state == STATE_UP)
                return;         // already going up
 
        if (self.state == STATE_TOP)
        {       // reset top wait time
-               trigger_setnextthink(self, self.ltime + self.wait);
+               self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
                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,12 +433,12 @@ Spawned if a door lacks a real activator
 */
 
 void door_trigger_touch()
-{
+{SELFPARAM();
        if (other.health < 1)
 #ifdef SVQC
-               if (!(other.iscreature && !PHYS_DEAD(other)))
+               if (!((other.iscreature || (other.flags & FL_PROJECTILE)) && !PHYS_DEAD(other)))
 #elif defined(CSQC)
-               if(!(IS_CLIENT(other) && !PHYS_DEAD(other)))
+               if(!((IS_CLIENT(other) || other.classname == "csqcprojectile") && !PHYS_DEAD(other)))
 #endif
                        return;
 
@@ -465,38 +453,12 @@ void door_trigger_touch()
 
        activator = other;
 
-       self = self.owner;
+       setself(self.owner);
        door_use ();
 }
 
-#ifdef SVQC
-
-float door_trigger_send(entity to, float sf)
-{
-       WriteByte(MSG_ENTITY, ENT_CLIENT_DOOR_TRIGGER);
-
-       WriteShort(MSG_ENTITY, num_for_edict(self.owner));
-       WriteCoord(MSG_ENTITY, self.origin_x);
-       WriteCoord(MSG_ENTITY, self.origin_y);
-       WriteCoord(MSG_ENTITY, self.origin_z);
-
-       WriteCoord(MSG_ENTITY, self.mins_x);
-       WriteCoord(MSG_ENTITY, self.mins_y);
-       WriteCoord(MSG_ENTITY, self.mins_z);
-       WriteCoord(MSG_ENTITY, self.maxs_x);
-       WriteCoord(MSG_ENTITY, self.maxs_y);
-       WriteCoord(MSG_ENTITY, self.maxs_z);
-
-       return true;
-}
-
-void door_trigger_link(entity trig)
-{
-       Net_LinkEntity(trig, false, 0, door_trigger_send);
-}
-
 void spawn_field(vector fmins, vector fmaxs)
-{
+{SELFPARAM();
        entity  trigger;
        vector  t1 = fmins, t2 = fmaxs;
 
@@ -505,41 +467,18 @@ void spawn_field(vector fmins, vector fmaxs)
        trigger.movetype = MOVETYPE_NONE;
        trigger.solid = SOLID_TRIGGER;
        trigger.owner = self;
+#ifdef SVQC
        trigger.touch = door_trigger_touch;
+#elif defined(CSQC)
+       trigger.trigger_touch = door_trigger_touch;
+       trigger.draw = trigger_draw_generic;
+       trigger.drawmask = MASK_NORMAL;
+#endif
 
        setsize (trigger, t1 - '60 60 8', t2 + '60 60 8');
-       door_trigger_link(trigger);
 }
 
-#elif defined(CSQC)
-
-void ent_door_trigger()
-{
-       float entnum = ReadShort();
-       self.origin_x = ReadCoord();
-       self.origin_y = ReadCoord();
-       self.origin_z = ReadCoord();
-       setorigin(self, self.origin);
-       self.mins_x = ReadCoord();
-       self.mins_y = ReadCoord();
-       self.mins_z = ReadCoord();
-       self.maxs_x = ReadCoord();
-       self.maxs_y = ReadCoord();
-       self.maxs_z = ReadCoord();
-       setsize(self, self.mins, self.maxs);
-
-       self.owner = findfloat(world, sv_entnum, entnum); // if owner doesn't exist, it shouldn't matter much
-       self.classname = "doortriggerfield";
-       self.movetype = MOVETYPE_NONE;
-       self.solid = SOLID_TRIGGER;
-       self.trigger_touch = door_trigger_touch;
-       self.draw = trigger_draw_generic;
-       self.drawmask = MASK_NORMAL;
-       self.move_time = time;
-}
 
-#endif
-#ifdef SVQC
 /*
 =============
 LinkDoors
@@ -549,7 +488,7 @@ LinkDoors
 */
 
 entity LinkDoors_nextent(entity cur, entity near, entity pass)
-{
+{SELFPARAM();
        while((cur = find(cur, classname, self.classname)) && ((cur.spawnflags & 4) || cur.enemy))
        {
        }
@@ -569,13 +508,17 @@ bool LinkDoors_isconnected(entity e1, entity e2, entity pass)
        return true;
 }
 
+#ifdef SVQC
 void door_link();
+#endif
 void LinkDoors()
-{
+{SELFPARAM();
        entity  t;
        vector  cmins, cmaxs;
 
+#ifdef SVQC
        door_link();
+#endif
 
        if (self.enemy)
                return;         // already linked by another door
@@ -589,6 +532,7 @@ void LinkDoors()
                        return;
                if (self.items)
                        return;
+
                spawn_field(self.absmin, self.absmax);
 
                return;         // don't want to link this door
@@ -597,10 +541,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)
                {
@@ -608,7 +552,7 @@ void LinkDoors()
                        break;
                }
        }
-       dprint("\n");
+       LOG_TRACE("\n");
 
        // collect health, targetname, message, size
        cmins = self.absmin;
@@ -660,7 +604,7 @@ void LinkDoors()
        spawn_field(cmins, cmaxs);
 }
 
-
+#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.
 
@@ -691,7 +635,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);
 
@@ -699,32 +643,10 @@ float door_send(entity to, float sf)
        {
                WriteString(MSG_ENTITY, self.classname);
                WriteByte(MSG_ENTITY, self.spawnflags);
-               WriteShort(MSG_ENTITY, ((self.owner == self || !self.owner) ? -1 : num_for_edict(self.owner)));
-               WriteShort(MSG_ENTITY, ((self.enemy == self || !self.enemy) ? -1 : num_for_edict(self.enemy)));
-               WriteShort(MSG_ENTITY, num_for_edict(self));
-
-               WriteByte(MSG_ENTITY, self.scale);
-
-               WriteCoord(MSG_ENTITY, self.origin_x);
-               WriteCoord(MSG_ENTITY, self.origin_y);
-               WriteCoord(MSG_ENTITY, self.origin_z);
 
                WriteString(MSG_ENTITY, self.model);
 
-               WriteCoord(MSG_ENTITY, self.mins_x);
-               WriteCoord(MSG_ENTITY, self.mins_y);
-               WriteCoord(MSG_ENTITY, self.mins_z);
-               WriteCoord(MSG_ENTITY, self.maxs_x);
-               WriteCoord(MSG_ENTITY, self.maxs_y);
-               WriteCoord(MSG_ENTITY, self.maxs_z);
-
-               WriteCoord(MSG_ENTITY, self.movedir_x);
-               WriteCoord(MSG_ENTITY, self.movedir_y);
-               WriteCoord(MSG_ENTITY, self.movedir_z);
-
-               WriteAngle(MSG_ENTITY, self.angles_x);
-               WriteAngle(MSG_ENTITY, self.angles_y);
-               WriteAngle(MSG_ENTITY, self.angles_z);
+               trigger_common_write(true);
 
                WriteCoord(MSG_ENTITY, self.pos1_x);
                WriteCoord(MSG_ENTITY, self.pos1_y);
@@ -741,7 +663,7 @@ float door_send(entity to, float sf)
                WriteShort(MSG_ENTITY, self.speed);
                WriteByte(MSG_ENTITY, self.lip);
                WriteByte(MSG_ENTITY, self.state);
-               WriteCoord(MSG_ENTITY, self.ltime);
+               WriteCoord(MSG_ENTITY, self.SUB_LTIME);
        }
 
        if(sf & SF_TRIGGER_RESET)
@@ -769,28 +691,29 @@ 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()
-{
-       setorigin (self, self.pos2);
+{SELFPARAM();
+       SUB_SETORIGIN(self, self.pos2);
        self.pos2 = self.pos1;
        self.pos1 = self.origin;
 
+#ifdef SVQC
        self.SendFlags |= SF_TRIGGER_UPDATE;
-}
-
 #endif
+}
 
 void door_reset()
-{
-       setorigin(self, self.pos1);
-       self.velocity = '0 0 0';
+{SELFPARAM();
+       SUB_SETORIGIN(self, self.pos1);
+       self.SUB_VELOCITY = '0 0 0';
        self.state = STATE_BOTTOM;
-       self.think = func_null;
-       self.nextthink = 0;
+       self.SUB_THINK = func_null;
+       self.SUB_NEXTTHINK = 0;
 
 #ifdef SVQC
        self.SendFlags |= SF_TRIGGER_RESET;
@@ -800,7 +723,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)
@@ -839,9 +762,12 @@ void spawnfunc_func_door()
        if (!self.lip)
                self.lip = 8;
 
-       self.pos1 = self.origin;
+       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)
@@ -869,43 +795,26 @@ void spawnfunc_func_door()
 
 #elif defined(CSQC)
 
-void ent_door()
+void door_draw()
 {
+       Movetype_Physics_NoMatchServer();
+
+       trigger_draw_generic();
+}
+
+void ent_door()
+{SELFPARAM();
        float sf = ReadByte();
 
        if(sf & SF_TRIGGER_INIT)
        {
                self.classname = strzone(ReadString());
                self.spawnflags = ReadByte();
-               float myowner = ReadShort();
-               float myenemy = ReadShort();
-               self.sv_entnum = ReadShort();
-
-               self.scale = ReadByte();
-
-               self.origin_x = ReadCoord();
-               self.origin_y = ReadCoord();
-               self.origin_z = ReadCoord();
-               setorigin(self, self.origin);
 
                self.mdl = strzone(ReadString());
-               setmodel(self, self.mdl);
-
-               self.mins_x = ReadCoord();
-               self.mins_y = ReadCoord();
-               self.mins_z = ReadCoord();
-               self.maxs_x = ReadCoord();
-               self.maxs_y = ReadCoord();
-               self.maxs_z = ReadCoord();
-               setsize(self, self.mins, self.maxs);
-
-               self.movedir_x = ReadCoord();
-               self.movedir_y = ReadCoord();
-               self.movedir_z = ReadCoord();
+               _setmodel(self, self.mdl);
 
-               self.angles_x = ReadAngle();
-               self.angles_y = ReadAngle();
-               self.angles_z = ReadAngle();
+               trigger_common_read(true);
 
                self.pos1_x = ReadCoord();
                self.pos1_y = ReadCoord();
@@ -922,21 +831,25 @@ void ent_door()
                self.speed = ReadShort();
                self.lip = ReadByte();
                self.state = ReadByte();
-               self.ltime = ReadCoord();
+               self.SUB_LTIME = ReadCoord();
 
-               self.movetype = MOVETYPE_PUSH;
                self.solid = SOLID_BSP;
+               self.movetype = MOVETYPE_PUSH;
                self.trigger_touch = door_touch;
-               self.draw = trigger_draw_generic;
+               self.draw = door_draw;
                self.drawmask = MASK_NORMAL;
-               self.move_time = time;
                self.use = door_use;
-               self.blocked = door_blocked;
 
-               print(ftos(self.entnum), " ", ftos(self.sv_entnum), "\n");
+               LinkDoors();
 
-               self.owner = ((myowner == -1) ? self : findfloat(world, sv_entnum, myowner));
-               self.enemy = ((myenemy == -1) ? self : findfloat(world, sv_entnum, myenemy));
+               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;
        }
 
        if(sf & SF_TRIGGER_RESET)
@@ -950,6 +863,7 @@ void ent_door()
                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();