From 8f191128751c7de23494145b68c452c174e3c3ed Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 29 Apr 2017 01:44:00 -0400 Subject: [PATCH] v0.6.0: implemented a branches only builder --- .../levels/builders/BranchesBuilder.java | 103 ++++++++++++++++++ .../levels/builders/Builder.java | 4 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/BranchesBuilder.java diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/BranchesBuilder.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/BranchesBuilder.java new file mode 100644 index 000000000..3458ab5b0 --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/BranchesBuilder.java @@ -0,0 +1,103 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2017 Evan Debenham + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package com.shatteredpixel.shatteredpixeldungeon.levels.builders; + +import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; +import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom; +import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.EntranceRoom; +import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom; +import com.watabou.utils.Random; + +import java.util.ArrayList; + +//A builder that creates only branches, very simple and very random +public class BranchesBuilder extends Builder { + + private float[] branchTunnelChances = new float[]{3, 2, 1}; + + public BranchesBuilder setTunnelLength( float[] branch){ + branchTunnelChances = branch; + return this; + } + + private float extraConnectionChance = 0.1f; + + public BranchesBuilder setExtraConnectionChance( float chance ){ + extraConnectionChance = chance; + return this; + } + + @Override + public ArrayList build(ArrayList rooms) { + + Room entrance = null; + Room exit = null; + Room shop = null; + + ArrayList multiConnections = new ArrayList<>(); + ArrayList singleConnections = new ArrayList<>(); + + for (Room r : rooms){ + if (r instanceof EntranceRoom){ + entrance = r; + } else if (r instanceof ExitRoom) { + exit = r; + } else if (r instanceof ShopRoom && r.maxConnections(Room.ALL) == 1){ + shop = r; + } else if (r.maxConnections(Room.ALL) > 1){ + multiConnections.add(r); + } else if (r.maxConnections(Room.ALL) == 1){ + singleConnections.add(r); + } + } + + if (entrance == null){ + return null; + } + + ArrayList branchable = new ArrayList<>(); + + entrance.setSize(); + entrance.setPos(0, 0); + branchable.add(entrance); + + ArrayList roomsToBranch = new ArrayList<>(); + if (shop != null) roomsToBranch.add(shop); + roomsToBranch.addAll(multiConnections); + if (exit != null) roomsToBranch.add(exit); + roomsToBranch.addAll(singleConnections); + createBranches(rooms, branchable, roomsToBranch, branchTunnelChances); + + findNeighbours(rooms); + + for (Room r : rooms){ + for (Room n : r.neigbours){ + if (!n.connected.containsKey(r) + && Random.Float() < extraConnectionChance){ + r.connect(n); + } + } + } + + return rooms; + } +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/Builder.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/Builder.java index 842630766..71a1d62d2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/Builder.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/builders/Builder.java @@ -305,7 +305,9 @@ public abstract class Builder { continue; } - + for (Room t : tunnelsThisBranch){ + branchable.add(t); + } if (r.maxConnections(Room.ALL) > 1 && Random.Int(2) == 0) branchable.add(r);