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