]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Remove code duplication for func_door and func_door_rotating spawnfuncs
authorFreddy <schro.sb@gmail.com>
Mon, 5 Mar 2018 20:57:40 +0000 (21:57 +0100)
committerFreddy <schro.sb@gmail.com>
Mon, 5 Mar 2018 20:57:40 +0000 (21:57 +0100)
qcsrc/common/triggers/func/door.qc
qcsrc/common/triggers/func/door_rotating.qc

index 731cacb33f74e5f33049bbb1b80d7934f64c1d1b..6b3161669933f1d0ec90d825e11ca83b77ca5b7d 100644 (file)
@@ -178,7 +178,7 @@ bool door_check_keys(entity door, entity player)
        if(!door.itemkeys)
        {
 #ifdef SVQC
-               play2(player, SND(TALK));
+               play2(player, door.noise);
                Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_UNLOCKED);
 #endif
                return true;
@@ -629,53 +629,93 @@ void door_reset(entity this)
 
 #ifdef SVQC
 
-// spawnflags require key (for now only func_door)
-spawnfunc(func_door)
+// common code for func_door and func_door_rotating spawnfuncs
+void door_init_shared(entity this)
 {
-       // Quake 1 keys compatibility
-       if (this.spawnflags & SPAWNFLAGS_GOLD_KEY)
-               this.itemkeys |= ITEM_KEY_BIT(0);
-       if (this.spawnflags & SPAWNFLAGS_SILVER_KEY)
-               this.itemkeys |= ITEM_KEY_BIT(1);
-
-       SetMovedir(this);
-
        this.max_health = this.health;
-       if (!InitMovingBrushTrigger(this))
-               return;
-       this.effects |= EF_LOWPRECISION;
-       this.classname = "door";
 
+       // unlock sound
        if(this.noise == "")
+       {
                this.noise = "misc/talk.wav";
+       }
+       // door still locked sound
        if(this.noise3 == "")
+       {
                this.noise3 = "misc/talk.wav";
+       }
        precache_sound(this.noise);
        precache_sound(this.noise3);
 
-       setblocked(this, door_blocked);
-       this.use = door_use;
-
-       if(this.dmg && (this.message == ""))
+       if((this.dmg || (this.spawnflags & DOOR_CRUSH)) && (this.message == ""))
+       {
                this.message = "was squished";
-       if(this.dmg && (this.message2 == ""))
+       }
+       if((this.dmg || (this.spawnflags & DOOR_CRUSH)) && (this.message2 == ""))
+       {
                this.message2 = "was squished by";
+       }
 
+       // TODO: other soundpacks
        if (this.sounds > 0)
        {
                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); }
+       // sound when door stops moving
+       if(this.noise1 && this.noise1 != "")
+       {
+               precache_sound(this.noise1);
+       }
+       // sound when door is moving
+       if(this.noise2 && this.noise2 != "")
+       {
+               precache_sound(this.noise2);
+       }
 
-       if (!this.speed)
-               this.speed = 100;
        if (!this.wait)
+       {
                this.wait = 3;
+       }
        if (!this.lip)
+       {
                this.lip = 8;
+       }
+
+       this.state = STATE_BOTTOM;
+
+       if (this.health)
+       {
+               //this.canteamdamage = true; // TODO
+               this.takedamage = DAMAGE_YES;
+               this.event_damage = door_damage;
+       }
+
+       if (this.items)
+       {
+               this.wait = -1;
+       }
+}
+
+// spawnflags require key (for now only func_door)
+spawnfunc(func_door)
+{
+       // Quake 1 keys compatibility
+       if (this.spawnflags & SPAWNFLAGS_GOLD_KEY)
+               this.itemkeys |= ITEM_KEY_BIT(0);
+       if (this.spawnflags & SPAWNFLAGS_SILVER_KEY)
+               this.itemkeys |= ITEM_KEY_BIT(1);
+
+       SetMovedir(this);
+
+       if (!InitMovingBrushTrigger(this))
+               return;
+       this.effects |= EF_LOWPRECISION;
+       this.classname = "door";
+
+       setblocked(this, door_blocked);
+       this.use = door_use;
 
        this.pos1 = this.origin;
        this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
@@ -688,18 +728,13 @@ spawnfunc(func_door)
        if (this.spawnflags & DOOR_START_OPEN)
                InitializeEntity(this, door_init_startopen, INITPRIO_SETLOCATION);
 
-       this.state = STATE_BOTTOM;
+       door_init_shared(this);
 
-       if (this.health)
+       if (!this.speed)
        {
-               //this.canteamdamage = true; // TODO
-               this.takedamage = DAMAGE_YES;
-               this.event_damage = door_damage;
+               this.speed = 100;
        }
 
-       if (this.items)
-               this.wait = -1;
-
        settouch(this, door_touch);
 
 // LinkDoors can't be done until all of the doors have been spawned, so
index f52b221ba0127c28a6eda5ff9b0b079c7c5578f7..41fd05e574af53295a71c6b105c3a76f3ac78e52 100644 (file)
@@ -107,9 +107,6 @@ void door_rotating_init_startopen(entity this)
 
 spawnfunc(func_door_rotating)
 {
-       // possible TODO: support for Quake1 keys (like func_door)
-       // however SPAWNFLAGS_GOLD_KEY (==8) has the same value as BIDIR_IN_DOWN
-
        //if (!this.deathtype) // map makers can override this
        //      this.deathtype = " got in the way";
 
@@ -126,7 +123,6 @@ spawnfunc(func_door_rotating)
        this.movedir = this.movedir * this.angles_y;
        this.angles = '0 0 0';
 
-       this.max_health = this.health;
        this.avelocity = this.movedir;
        if (!InitMovingBrushTrigger(this))
                return;
@@ -137,31 +133,6 @@ spawnfunc(func_door_rotating)
        setblocked(this, door_blocked);
        this.use = door_use;
 
-    if(this.dmg && (this.message == ""))
-               this.message = "was squished";
-    if(this.dmg && (this.message2 == ""))
-               this.message2 = "was squished by";
-
-       if (this.sounds > 0)
-       {
-               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 = 50;
-       if (!this.wait)
-               this.wait = 1;
-       this.lip = 0; // this.lip is used to remember reverse opening direction for door_rotating
-
        this.pos1 = '0 0 0';
        this.pos2 = this.movedir;
 
@@ -170,17 +141,12 @@ spawnfunc(func_door_rotating)
        if (this.spawnflags & DOOR_START_OPEN)
                InitializeEntity(this, door_rotating_init_startopen, INITPRIO_SETLOCATION);
 
-       this.state = STATE_BOTTOM;
-
-       if (this.health)
+       door_init_shared(this);
+       if (!this.speed)
        {
-               //this.canteamdamage = true; // TODO
-               this.takedamage = DAMAGE_YES;
-               this.event_damage = door_damage;
+               this.speed = 50;
        }
-
-       if (this.items)
-               this.wait = -1;
+       this.lip = 0; // this.lip is used to remember reverse opening direction for door_rotating
 
        settouch(this, door_touch);