v0.6.0: corrected usage of spaces instead of tabs
This commit is contained in:
parent
3e9beb1d99
commit
2b574fd71e
|
@ -402,7 +402,7 @@ public abstract class RegularLevel extends Level {
|
||||||
|
|
||||||
rooms = new ArrayList<>( (Collection<Room>) ((Collection<?>) bundle.getCollection( "rooms" )) );
|
rooms = new ArrayList<>( (Collection<Room>) ((Collection<?>) bundle.getCollection( "rooms" )) );
|
||||||
for (Room r : rooms) {
|
for (Room r : rooms) {
|
||||||
r.onLevelLoad( this );
|
r.onLevelLoad( this );
|
||||||
if (r instanceof EntranceRoom || r.legacyType.equals("ENTRANCE")){
|
if (r instanceof EntranceRoom || r.legacyType.equals("ENTRANCE")){
|
||||||
roomEntrance = r;
|
roomEntrance = r;
|
||||||
} else if (r instanceof ExitRoom || r.legacyType.equals("EXIT")){
|
} else if (r instanceof ExitRoom || r.legacyType.equals("EXIT")){
|
||||||
|
|
|
@ -40,8 +40,8 @@ public abstract class Builder {
|
||||||
//returns null on failure
|
//returns null on failure
|
||||||
public abstract ArrayList<Room> build(ArrayList<Room> rooms);
|
public abstract ArrayList<Room> build(ArrayList<Room> rooms);
|
||||||
|
|
||||||
//returns a rectangle representing the maximum amount of free space from a specific start point
|
//returns a rectangle representing the maximum amount of free space from a specific start point
|
||||||
protected Rect findFreeSpace(Point start, ArrayList<Room> collision, int maxSize){
|
protected static Rect findFreeSpace(Point start, ArrayList<Room> collision, int maxSize){
|
||||||
Rect space = new Rect(start.x-maxSize, start.y-maxSize, start.x+maxSize, start.y+maxSize);
|
Rect space = new Rect(start.x-maxSize, start.y-maxSize, start.x+maxSize, start.y+maxSize);
|
||||||
|
|
||||||
//shallow copy
|
//shallow copy
|
||||||
|
@ -130,100 +130,100 @@ public abstract class Builder {
|
||||||
// and it matches the given angle ([0-360), where 0 is straight up) as closely as possible.
|
// and it matches the given angle ([0-360), where 0 is straight up) as closely as possible.
|
||||||
//Note that getting an exactly correct angle is harder the closer that angle is to diagonal.
|
//Note that getting an exactly correct angle is harder the closer that angle is to diagonal.
|
||||||
//Returns the exact angle between the centerpoints of the two rooms, or -1 if placement fails.
|
//Returns the exact angle between the centerpoints of the two rooms, or -1 if placement fails.
|
||||||
protected float placeRoom( ArrayList<Room> collision, Room prev, Room next, float angle){
|
protected static float placeRoom( ArrayList<Room> collision, Room prev, Room next, float angle){
|
||||||
|
|
||||||
//wrap angle around to always be [0-360)
|
//wrap angle around to always be [0-360)
|
||||||
angle %= 360f;
|
angle %= 360f;
|
||||||
if (angle < 0){
|
if (angle < 0){
|
||||||
angle += 360f;
|
angle += 360f;
|
||||||
}
|
}
|
||||||
|
|
||||||
PointF prevCenter = new PointF((prev.left + prev.right)/2f, (prev.top + prev.bottom)/2f);
|
PointF prevCenter = new PointF((prev.left + prev.right)/2f, (prev.top + prev.bottom)/2f);
|
||||||
|
|
||||||
// calculating using y = mx+b, straight line formula
|
// calculating using y = mx+b, straight line formula
|
||||||
double m = Math.tan(angle/A + Math.PI/2.0);
|
double m = Math.tan(angle/A + Math.PI/2.0);
|
||||||
double b = prevCenter.y -m*prevCenter.x;
|
double b = prevCenter.y -m*prevCenter.x;
|
||||||
|
|
||||||
//using the line equation, we find the point along the prev room where the line exists
|
//using the line equation, we find the point along the prev room where the line exists
|
||||||
Point start;
|
Point start;
|
||||||
int direction;
|
int direction;
|
||||||
if (Math.abs(m) >= 1){
|
if (Math.abs(m) >= 1){
|
||||||
if (angle < 90 || angle > 270){
|
if (angle < 90 || angle > 270){
|
||||||
direction = Room.TOP;
|
direction = Room.TOP;
|
||||||
start = new Point( (int)Math.round((prev.top - b)/m), prev.top);
|
start = new Point( (int)Math.round((prev.top - b)/m), prev.top);
|
||||||
} else {
|
} else {
|
||||||
direction = Room.BOTTOM;
|
direction = Room.BOTTOM;
|
||||||
start = new Point( (int)Math.round((prev.bottom - b)/m), prev.bottom);
|
start = new Point( (int)Math.round((prev.bottom - b)/m), prev.bottom);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (angle < 180){
|
if (angle < 180){
|
||||||
direction = Room.RIGHT;
|
direction = Room.RIGHT;
|
||||||
start = new Point(prev.right, (int) Math.round(m * prev.right + b));
|
start = new Point(prev.right, (int) Math.round(m * prev.right + b));
|
||||||
} else {
|
} else {
|
||||||
direction = Room.LEFT;
|
direction = Room.LEFT;
|
||||||
start = new Point(prev.left, (int) Math.round(m * prev.left + b));
|
start = new Point(prev.left, (int) Math.round(m * prev.left + b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//cap it to a valid connection point for most rooms
|
//cap it to a valid connection point for most rooms
|
||||||
if (direction == Room.TOP || direction == Room.BOTTOM) {
|
if (direction == Room.TOP || direction == Room.BOTTOM) {
|
||||||
start.x = (int) GameMath.gate(prev.left + 1, start.x, prev.right - 1);
|
start.x = (int) GameMath.gate(prev.left + 1, start.x, prev.right - 1);
|
||||||
} else {
|
} else {
|
||||||
start.y = (int) GameMath.gate(prev.top + 1, start.y, prev.bottom - 1);
|
start.y = (int) GameMath.gate(prev.top + 1, start.y, prev.bottom - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//space checking
|
//space checking
|
||||||
Rect space = findFreeSpace(start, collision, Math.max(next.maxWidth(), next.maxHeight()));
|
Rect space = findFreeSpace(start, collision, Math.max(next.maxWidth(), next.maxHeight()));
|
||||||
if (!next.setSizeWithLimit(space.width()+1, space.height()+1)){
|
if (!next.setSizeWithLimit(space.width()+1, space.height()+1)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//find the ideal center for this new room using the line equation and known dimensions
|
//find the ideal center for this new room using the line equation and known dimensions
|
||||||
PointF targetCenter = new PointF();
|
PointF targetCenter = new PointF();
|
||||||
if (direction == Room.TOP) {
|
if (direction == Room.TOP) {
|
||||||
targetCenter.y = prev.top - (next.height() - 1) / 2f;
|
targetCenter.y = prev.top - (next.height() - 1) / 2f;
|
||||||
targetCenter.x = (float) ((targetCenter.y - b) / m);
|
targetCenter.x = (float) ((targetCenter.y - b) / m);
|
||||||
next.setPos(Math.round(targetCenter.x - (next.width() - 1) / 2f), prev.top - (next.height() - 1));
|
next.setPos(Math.round(targetCenter.x - (next.width() - 1) / 2f), prev.top - (next.height() - 1));
|
||||||
|
|
||||||
} else if (direction == Room.BOTTOM) {
|
} else if (direction == Room.BOTTOM) {
|
||||||
targetCenter.y = prev.bottom + (next.height() - 1) / 2f;
|
targetCenter.y = prev.bottom + (next.height() - 1) / 2f;
|
||||||
targetCenter.x = (float) ((targetCenter.y - b) / m);
|
targetCenter.x = (float) ((targetCenter.y - b) / m);
|
||||||
next.setPos(Math.round(targetCenter.x - (next.width() - 1) / 2f), prev.bottom);
|
next.setPos(Math.round(targetCenter.x - (next.width() - 1) / 2f), prev.bottom);
|
||||||
|
|
||||||
} else if (direction == Room.RIGHT) {
|
} else if (direction == Room.RIGHT) {
|
||||||
targetCenter.x = prev.right + (next.width()-1)/2f;
|
targetCenter.x = prev.right + (next.width()-1)/2f;
|
||||||
targetCenter.y = (float)(m*targetCenter.x + b);
|
targetCenter.y = (float)(m*targetCenter.x + b);
|
||||||
next.setPos( prev.right, Math.round(targetCenter.y - (next.height()-1)/2f));
|
next.setPos( prev.right, Math.round(targetCenter.y - (next.height()-1)/2f));
|
||||||
|
|
||||||
} else if (direction == Room.LEFT) {
|
} else if (direction == Room.LEFT) {
|
||||||
targetCenter.x = prev.left - (next.width()-1)/2f;
|
targetCenter.x = prev.left - (next.width()-1)/2f;
|
||||||
targetCenter.y = (float)(m*targetCenter.x + b);
|
targetCenter.y = (float)(m*targetCenter.x + b);
|
||||||
next.setPos( prev.left - (next.width() - 1), Math.round(targetCenter.y - (next.height()-1)/2f));
|
next.setPos( prev.left - (next.width() - 1), Math.round(targetCenter.y - (next.height()-1)/2f));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//perform connection bounds and target checking, move the room if necessary
|
//perform connection bounds and target checking, move the room if necessary
|
||||||
if (direction == Room.TOP || direction == Room.BOTTOM){
|
if (direction == Room.TOP || direction == Room.BOTTOM){
|
||||||
if (next.right < prev.left+2) next.shift(prev.left+2-next.right, 0);
|
if (next.right < prev.left+2) next.shift(prev.left+2-next.right, 0);
|
||||||
else if (next.left > prev.right-2) next.shift(prev.right-2-next.left, 0);
|
else if (next.left > prev.right-2) next.shift(prev.right-2-next.left, 0);
|
||||||
|
|
||||||
if (next.right > space.right) next.shift( space.right - next.right, 0);
|
if (next.right > space.right) next.shift( space.right - next.right, 0);
|
||||||
else if (next.left < space.left) next.shift( space.left - next.left, 0);
|
else if (next.left < space.left) next.shift( space.left - next.left, 0);
|
||||||
} else {
|
} else {
|
||||||
if (next.bottom < prev.top+2) next.shift(0, prev.top+2-next.bottom);
|
if (next.bottom < prev.top+2) next.shift(0, prev.top+2-next.bottom);
|
||||||
else if (next.top > prev.bottom-2) next.shift(0, prev.bottom-2-next.top);
|
else if (next.top > prev.bottom-2) next.shift(0, prev.bottom-2-next.top);
|
||||||
|
|
||||||
if (next.bottom > space.bottom) next.shift( 0, space.bottom - next.bottom);
|
if (next.bottom > space.bottom) next.shift( 0, space.bottom - next.bottom);
|
||||||
else if (next.top < space.top) next.shift( 0, space.top - next.top);
|
else if (next.top < space.top) next.shift( 0, space.top - next.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
//attempt to connect, return the result angle if successful.
|
//attempt to connect, return the result angle if successful.
|
||||||
if (next.connect(prev)){
|
if (next.connect(prev)){
|
||||||
PointF nextCenter = new PointF((next.left + next.right)/2f, (next.top + next.bottom)/2f);
|
PointF nextCenter = new PointF((next.left + next.right)/2f, (next.top + next.bottom)/2f);
|
||||||
double trueM = (nextCenter.y - prevCenter.y)/(nextCenter.x - prevCenter.x);
|
double trueM = (nextCenter.y - prevCenter.y)/(nextCenter.x - prevCenter.x);
|
||||||
return (float)(A*(Math.atan(trueM) + Math.PI/2f));
|
return (float)(A*(Math.atan(trueM) + Math.PI/2f));
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,105 +21,100 @@
|
||||||
|
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard;
|
package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Imp;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Imp;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.ImpShopkeeper;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.ImpShopkeeper;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Shopkeeper;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.LastShopLevel;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
import com.watabou.utils.PathFinder;
|
|
||||||
|
|
||||||
//shops probably shouldn't extend special room, because of cases like this.
|
//shops probably shouldn't extend special room, because of cases like this.
|
||||||
public class ImpShopRoom extends ShopRoom {
|
public class ImpShopRoom extends ShopRoom {
|
||||||
|
|
||||||
private boolean impSpawned = false;
|
private boolean impSpawned = false;
|
||||||
|
|
||||||
//force a certain size here to guarantee enough room for 48 items, and the same center space
|
//force a certain size here to guarantee enough room for 48 items, and the same center space
|
||||||
@Override
|
@Override
|
||||||
public int minWidth() {
|
public int minWidth() {
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
public int minHeight() {
|
public int minHeight() {
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
public int maxWidth() { return 9; }
|
public int maxWidth() { return 9; }
|
||||||
public int maxHeight() { return 9; }
|
public int maxHeight() { return 9; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int maxConnections(int direction) {
|
public int maxConnections(int direction) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Level level) {
|
public void paint(Level level) {
|
||||||
Painter.fill( level, this, Terrain.WALL );
|
Painter.fill( level, this, Terrain.WALL );
|
||||||
Painter.fill( level, this, 1, Terrain.EMPTY_SP );
|
Painter.fill( level, this, 1, Terrain.EMPTY_SP );
|
||||||
Painter.fill( level, this, 3, Terrain.WATER);
|
Painter.fill( level, this, 3, Terrain.WATER);
|
||||||
|
|
||||||
for (Door door : connected.values()) {
|
for (Door door : connected.values()) {
|
||||||
door.set( Door.Type.REGULAR );
|
door.set( Door.Type.REGULAR );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Imp.Quest.isCompleted()){
|
if (Imp.Quest.isCompleted()){
|
||||||
impSpawned = true;
|
impSpawned = true;
|
||||||
placeItems(level);
|
placeItems(level);
|
||||||
placeShopkeeper(level);
|
placeShopkeeper(level);
|
||||||
} else {
|
} else {
|
||||||
impSpawned = false;
|
impSpawned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void placeShopkeeper(Level level) {
|
protected void placeShopkeeper(Level level) {
|
||||||
|
|
||||||
int pos = level.pointToCell(center());
|
int pos = level.pointToCell(center());
|
||||||
|
|
||||||
Mob shopkeeper = new ImpShopkeeper();
|
Mob shopkeeper = new ImpShopkeeper();
|
||||||
shopkeeper.pos = pos;
|
shopkeeper.pos = pos;
|
||||||
level.mobs.add( shopkeeper );
|
level.mobs.add( shopkeeper );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//fix for connections not being bundled normally
|
//fix for connections not being bundled normally
|
||||||
@Override
|
@Override
|
||||||
public Door entrance() {
|
public Door entrance() {
|
||||||
return connected.isEmpty() ? new Door(left, top+2) : super.entrance();
|
return connected.isEmpty() ? new Door(left, top+2) : super.entrance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnShop(Level level){
|
private void spawnShop(Level level){
|
||||||
impSpawned = true;
|
impSpawned = true;
|
||||||
super.paint(level);
|
super.paint(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String IMP = "imp_spawned";
|
private static final String IMP = "imp_spawned";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeInBundle(Bundle bundle) {
|
public void storeInBundle(Bundle bundle) {
|
||||||
super.storeInBundle(bundle);
|
super.storeInBundle(bundle);
|
||||||
bundle.put(IMP, impSpawned);
|
bundle.put(IMP, impSpawned);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restoreFromBundle(Bundle bundle) {
|
public void restoreFromBundle(Bundle bundle) {
|
||||||
super.restoreFromBundle(bundle);
|
super.restoreFromBundle(bundle);
|
||||||
impSpawned = bundle.getBoolean(IMP);
|
impSpawned = bundle.getBoolean(IMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLevelLoad(Level level) {
|
public void onLevelLoad(Level level) {
|
||||||
super.onLevelLoad(level);
|
super.onLevelLoad(level);
|
||||||
|
|
||||||
if (Imp.Quest.isCompleted() && !impSpawned){
|
if (Imp.Quest.isCompleted() && !impSpawned){
|
||||||
impSpawned = true;
|
impSpawned = true;
|
||||||
placeItems(level);
|
placeItems(level);
|
||||||
placeShopkeeper(level);
|
placeShopkeeper(level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user