]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
func_door: fix erratic behaviour of spawned trigger field
authorbones_was_here <bones_was_here@xonotic.au>
Fri, 7 Oct 2022 12:37:58 +0000 (22:37 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Fri, 15 Sep 2023 07:11:38 +0000 (17:11 +1000)
This was most noticeable with door .wait <= 1 but would eventually occur
at higher wait values if players hang around in the trigger field.

Also the door(s) usually did not stay open for the full .wait time after
the player left the trigger field, as some time had passed since the
.door_finished timestamp was set.

To make this reliable AND efficient requires updating the state of the
door(s), instead of maintaining a separate state in the trigger field entity.

qcsrc/common/mapobjects/func/door.qc

index 1316c3283003e6ce5b5a573e47960eebdb9c2020..aed02cf3d7c4de966c9d11309d4cdcb27f9cf9d8 100644 (file)
@@ -369,14 +369,25 @@ void door_trigger_touch(entity this, entity toucher)
 #endif
                        return;
 
-       if (time < this.door_finished)
+       if (this.owner.state == STATE_UP)
                return;
 
        // check if door is locked
        if (!door_check_keys(this, toucher))
                return;
 
-       this.door_finished = time + 1;
+       if (this.owner.state == STATE_TOP)
+       {
+               if (this.owner.nextthink < this.owner.ltime + this.owner.wait)
+               {
+                       entity e = this.owner;
+                       do {
+                               e.nextthink = e.ltime + e.wait;
+                               e = e.enemy;
+                       } while (e != this.owner);
+               }
+               return;
+       }
 
        door_use(this.owner, toucher, NULL);
 }