From 26ad33e49fc6189da5bc48725ebec3cbd2ef498e Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 5 Mar 2018 21:57:40 +0100 Subject: [PATCH] Remove code duplication for func_door and func_door_rotating spawnfuncs --- qcsrc/common/triggers/func/door.qc | 99 ++++++++++++++------- qcsrc/common/triggers/func/door_rotating.qc | 42 +-------- 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/qcsrc/common/triggers/func/door.qc b/qcsrc/common/triggers/func/door.qc index 731cacb33..6b3161669 100644 --- a/qcsrc/common/triggers/func/door.qc +++ b/qcsrc/common/triggers/func/door.qc @@ -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 diff --git a/qcsrc/common/triggers/func/door_rotating.qc b/qcsrc/common/triggers/func/door_rotating.qc index f52b221ba..41fd05e57 100644 --- a/qcsrc/common/triggers/func/door_rotating.qc +++ b/qcsrc/common/triggers/func/door_rotating.qc @@ -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); -- 2.39.2