v0.6.1: levels are now more densely packed on average

This commit is contained in:
Evan Debenham
2017-08-11 21:46:32 -04:00
parent 0cdd99e389
commit 0e033720c7
4 changed files with 51 additions and 15 deletions
@@ -21,7 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.levels; package com.shatteredpixel.shatteredpixeldungeon.levels;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Bones; import com.shatteredpixel.shatteredpixeldungeon.Bones;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
@@ -53,10 +52,8 @@ import com.watabou.utils.Bundle;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public abstract class RegularLevel extends Level { public abstract class RegularLevel extends Level {
@@ -126,7 +123,7 @@ public abstract class RegularLevel extends Level {
protected Builder builder(){ protected Builder builder(){
return new LoopBuilder() return new LoopBuilder()
.setLoopShape( 2 , .setLoopShape( 2 ,
Random.Float(0.55f, 0.85f), Random.Float(0.4f, 0.7f),
Random.Float(0f, 0.5f)); Random.Float(0f, 0.5f));
} }
@@ -146,10 +146,14 @@ public abstract class Builder {
protected static float angleBetweenRooms( Room from, Room to){ protected static float angleBetweenRooms( Room from, Room to){
PointF fromCenter = new PointF((from.left + from.right)/2f, (from.top + from.bottom)/2f); PointF fromCenter = new PointF((from.left + from.right)/2f, (from.top + from.bottom)/2f);
PointF toCenter = new PointF((to.left + to.right)/2f, (to.top + to.bottom)/2f); PointF toCenter = new PointF((to.left + to.right)/2f, (to.top + to.bottom)/2f);
double m = (toCenter.y - fromCenter.y)/(toCenter.x - fromCenter.x); return angleBetweenPoints(fromCenter, toCenter);
}
protected static float angleBetweenPoints( PointF from, PointF to ){
double m = (to.y - from.y)/(to.x - from.x);
float angle = (float)(A*(Math.atan(m) + Math.PI/2.0)); float angle = (float)(A*(Math.atan(m) + Math.PI/2.0));
if (fromCenter.x > toCenter.x) angle -= 180f; if (from.x > to.x) angle -= 180f;
return angle; return angle;
} }
@@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.builders;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom;
import com.watabou.utils.PointF;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
@@ -66,6 +67,8 @@ public class LoopBuilder extends RegularBuilder {
+ 0.25 + 0.5*Math.floor(2*x); + 0.25 + 0.5*Math.floor(2*x);
} }
private PointF loopCenter;
@Override @Override
public ArrayList<Room> build(ArrayList<Room> rooms) { public ArrayList<Room> build(ArrayList<Room> rooms) {
@@ -127,6 +130,14 @@ public class LoopBuilder extends RegularBuilder {
prev = c; prev = c;
} }
loopCenter = new PointF();
for (Room r : loop){
loopCenter.x += (r.left + r.right)/2f;
loopCenter.y += (r.top + r.bottom)/2f;
}
loopCenter.x /= loop.size();
loopCenter.y /= loop.size();
if (shop != null) { if (shop != null) {
float angle; float angle;
int tries = 10; int tries = 10;
@@ -158,4 +169,24 @@ public class LoopBuilder extends RegularBuilder {
return rooms; return rooms;
} }
@Override
protected float randomBranchAngle( Room r ) {
if (loopCenter == null)
return super.randomBranchAngle( r );
else {
//generate four angles randomly and return the one which points closer to the center
float toCenter = angleBetweenPoints( new PointF((r.left + r.right)/2f, (r.top + r.bottom)/2f), loopCenter);
if (toCenter < 0) toCenter += 360f;
float currAngle = Random.Float(360f);
for( int i = 0; i < 4; i ++){
float newAngle = Random.Float(360f);
if (Math.abs(toCenter - newAngle) < Math.abs(toCenter - currAngle)){
currAngle = newAngle;
}
}
return currAngle;
}
}
} }
@@ -47,7 +47,7 @@ public abstract class RegularBuilder extends Builder {
} }
//path length is the percentage of pathable rooms that are on //path length is the percentage of pathable rooms that are on
protected float pathLength = 0.67f; protected float pathLength = 0.6f;
//The chance weights for extra rooms to be added to the path //The chance weights for extra rooms to be added to the path
protected float[] pathLenJitterChances = new float[]{1, 0, 0}; protected float[] pathLenJitterChances = new float[]{1, 0, 0};
@@ -66,7 +66,7 @@ public abstract class RegularBuilder extends Builder {
return this; return this;
} }
protected float extraConnectionChance = 0.1f; protected float extraConnectionChance = 0.2f;
public RegularBuilder setExtraConnectionChance( float chance ){ public RegularBuilder setExtraConnectionChance( float chance ){
extraConnectionChance = chance; extraConnectionChance = chance;
@@ -112,7 +112,7 @@ public abstract class RegularBuilder extends Builder {
// *** Branch Placement *** // *** Branch Placement ***
protected static void weightRooms(ArrayList<Room> rooms){ protected void weightRooms(ArrayList<Room> rooms){
for (Room r : rooms.toArray(new Room[0])){ for (Room r : rooms.toArray(new Room[0])){
if (r instanceof StandardRoom){ if (r instanceof StandardRoom){
for (int i = 1; i < ((StandardRoom) r).sizeCat.connectionWeight(); i++) for (int i = 1; i < ((StandardRoom) r).sizeCat.connectionWeight(); i++)
@@ -123,7 +123,7 @@ public abstract class RegularBuilder extends Builder {
//places the rooms in roomsToBranch into branches from rooms in branchable. //places the rooms in roomsToBranch into branches from rooms in branchable.
//note that the three arrays should be separate, they may contain the same rooms however //note that the three arrays should be separate, they may contain the same rooms however
protected static void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable, protected void createBranches(ArrayList<Room> rooms, ArrayList<Room> branchable,
ArrayList<Room> roomsToBranch, float[] connChances){ ArrayList<Room> roomsToBranch, float[] connChances){
int i = 0; int i = 0;
@@ -139,12 +139,12 @@ public abstract class RegularBuilder extends Builder {
int connectingRooms = Random.chances(connChances); int connectingRooms = Random.chances(connChances);
for (int j = 0; j < connectingRooms; j++){ for (int j = 0; j < connectingRooms; j++){
ConnectionRoom t = ConnectionRoom.createRoom(); ConnectionRoom t = ConnectionRoom.createRoom();
tries = 10; tries = 3;
do { do {
angle = placeRoom(rooms, curr, t, Random.Float(360f)); angle = placeRoom(rooms, curr, t, randomBranchAngle(curr));
tries--; tries--;
} while (angle == -1 && tries >= 0); } while (angle == -1 && tries > 0);
if (angle == -1) { if (angle == -1) {
for (Room r : connectingRoomsThisBranch){ for (Room r : connectingRoomsThisBranch){
@@ -170,9 +170,9 @@ public abstract class RegularBuilder extends Builder {
tries = 10; tries = 10;
do { do {
angle = placeRoom(rooms, curr, r, Random.Float(360f)); angle = placeRoom(rooms, curr, r, randomBranchAngle(curr));
tries--; tries--;
} while (angle == -1 && tries >= 0); } while (angle == -1 && tries > 0);
if (angle == -1){ if (angle == -1){
for (Room t : connectingRoomsThisBranch){ for (Room t : connectingRoomsThisBranch){
@@ -200,4 +200,8 @@ public abstract class RegularBuilder extends Builder {
} }
} }
protected float randomBranchAngle( Room r ){
return Random.Float(360f);
}
} }