v0.6.0: implemented a branches only builder

This commit is contained in:
Evan Debenham 2017-04-29 01:44:00 -04:00
parent 2a1690945f
commit 8f19112875
2 changed files with 106 additions and 1 deletions

View File

@ -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 <http://www.gnu.org/licenses/>
*/
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<Room> build(ArrayList<Room> rooms) {
Room entrance = null;
Room exit = null;
Room shop = null;
ArrayList<Room> multiConnections = new ArrayList<>();
ArrayList<Room> 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<Room> branchable = new ArrayList<>();
entrance.setSize();
entrance.setPos(0, 0);
branchable.add(entrance);
ArrayList<Room> 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;
}
}

View File

@ -305,7 +305,9 @@ public abstract class Builder {
continue; continue;
} }
for (Room t : tunnelsThisBranch){
branchable.add(t);
}
if (r.maxConnections(Room.ALL) > 1 && Random.Int(2) == 0) if (r.maxConnections(Room.ALL) > 1 && Random.Int(2) == 0)
branchable.add(r); branchable.add(r);