From 4a96334b4fe4dcb6f83659d1575577ff2969ff54 Mon Sep 17 00:00:00 2001
From: Lippy13 <robotdan2003@yahoo.co.uk>
Date: Tue, 16 Feb 2021 00:39:25 +0000
Subject: [PATCH] Fix #689 - dungeon without stairs to boss floor

---
 CHANGELOG.md                  | 1 +
 world/src/site/dungeon/mod.rs | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 532b0a2e51..b0d87d7d85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   one of them active at the same time
 - Made zooming work on wayland
 - Fixed AI behavior so only humanoids will attempt to roll
+- Fixed a bug where the stairs to the boss floor in dungeons would sometimes not spawn
 
 ## [0.8.0] - 2020-11-28
 
diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs
index 061b68ce8c..9b9b5a3518 100644
--- a/world/src/site/dungeon/mod.rs
+++ b/world/src/site/dungeon/mod.rs
@@ -267,9 +267,10 @@ impl Floor {
         level: i32,
         difficulty: u32,
     ) -> (Self, Vec2<i32>) {
+        const MAX_WIDTH: u32 = 4;
         let floors = 3 + difficulty / 2;
         let final_level = level == floors as i32 - 1;
-        let width = (2 + difficulty / 2).min(4);
+        let width = (2 + difficulty / 2).min(MAX_WIDTH);
         let height = (15 + difficulty * 3).min(30);
 
         let new_stair_tile = if final_level {
@@ -309,8 +310,6 @@ impl Floor {
             pillars: None,
             difficulty,
         });
-        this.tiles
-            .set(stair_tile - tile_offset, Tile::UpStair(upstair_room));
         if final_level {
             // Boss room
             this.create_room(Room {
@@ -320,7 +319,7 @@ impl Floor {
                 miniboss: false,
                 boss: true,
                 area: Rect::from((
-                    new_stair_tile - tile_offset - 4,
+                    new_stair_tile - tile_offset - MAX_WIDTH as i32 - 1,
                     Extent2::broadcast(width as i32 * 2 + 1),
                 )),
                 height: height as i32,
@@ -345,6 +344,8 @@ impl Floor {
                 Tile::DownStair(downstair_room),
             );
         }
+        this.tiles
+            .set(stair_tile - tile_offset, Tile::UpStair(upstair_room));
 
         this.create_rooms(ctx, level, 7);
         // Create routes between all rooms