Refactored some things in world

v5stable
Ondřej Hruška 11 years ago
parent abc1db104c
commit fa1d2b577b
  1. 2
      src/mightypork/gamecore/eventbus/EventBus.java
  2. 6
      src/mightypork/gamecore/eventbus/EventChannel.java
  3. 2
      src/mightypork/gamecore/eventbus/clients/DelegatingClient.java
  4. 31
      src/mightypork/gamecore/util/math/algo/floodfill/FillContext.java
  5. 38
      src/mightypork/gamecore/util/math/algo/floodfill/FloodFill.java
  6. 4
      src/mightypork/rogue/screens/game/InvLayer.java
  7. 2
      src/mightypork/rogue/screens/game/InvSlot.java
  8. 2
      src/mightypork/rogue/screens/game/ScreenGame.java
  9. 1
      src/mightypork/rogue/world/PlayerControl.java
  10. 21
      src/mightypork/rogue/world/PlayerData.java
  11. 369
      src/mightypork/rogue/world/PlayerFacade.java
  12. 453
      src/mightypork/rogue/world/World.java
  13. 80
      src/mightypork/rogue/world/WorldConsole.java
  14. 12
      src/mightypork/rogue/world/WorldProvider.java
  15. 8
      src/mightypork/rogue/world/entity/Entities.java
  16. 23
      src/mightypork/rogue/world/entity/Entity.java
  17. 2
      src/mightypork/rogue/world/entity/EntityModule.java
  18. 2
      src/mightypork/rogue/world/entity/impl/BossRatAi.java
  19. 2
      src/mightypork/rogue/world/entity/impl/BrownRatAi.java
  20. 2
      src/mightypork/rogue/world/entity/impl/EntityBossRat.java
  21. 2
      src/mightypork/rogue/world/entity/impl/EntityBrownRat.java
  22. 2
      src/mightypork/rogue/world/entity/impl/EntityGrayRat.java
  23. 2
      src/mightypork/rogue/world/entity/impl/GrayRatAi.java
  24. 2
      src/mightypork/rogue/world/entity/impl/MonsterAi.java
  25. 4
      src/mightypork/rogue/world/entity/impl/PlayerEntity.java
  26. 2
      src/mightypork/rogue/world/events/PlayerStepEndEvent.java
  27. 2
      src/mightypork/rogue/world/events/PlayerStepEndListener.java
  28. 2
      src/mightypork/rogue/world/gen/LevelGenerator.java
  29. 4
      src/mightypork/rogue/world/gen/ScratchMap.java
  30. 4
      src/mightypork/rogue/world/gen/WorldCreator.java
  31. 2
      src/mightypork/rogue/world/gui/Minimap.java
  32. 2
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java
  33. 2
      src/mightypork/rogue/world/gui/interaction/MIPMouse.java
  34. 2
      src/mightypork/rogue/world/gui/interaction/MapInteractionPlugin.java
  35. 2
      src/mightypork/rogue/world/item/Item.java
  36. 18
      src/mightypork/rogue/world/item/Items.java
  37. 2
      src/mightypork/rogue/world/item/impl/ItemBaseFood.java
  38. 2
      src/mightypork/rogue/world/item/impl/ItemBaseWeapon.java
  39. 6
      src/mightypork/rogue/world/item/impl/active/ItemHeartPiece.java
  40. 4
      src/mightypork/rogue/world/item/impl/food/ItemCheese.java
  41. 4
      src/mightypork/rogue/world/item/impl/food/ItemMeat.java
  42. 4
      src/mightypork/rogue/world/item/impl/food/ItemSandwich.java
  43. 4
      src/mightypork/rogue/world/item/impl/weapons/ItemBone.java
  44. 4
      src/mightypork/rogue/world/item/impl/weapons/ItemClub.java
  45. 4
      src/mightypork/rogue/world/item/impl/weapons/ItemHammer.java
  46. 4
      src/mightypork/rogue/world/item/impl/weapons/ItemStone.java
  47. 4
      src/mightypork/rogue/world/item/impl/weapons/ItemSword.java
  48. 85
      src/mightypork/rogue/world/level/Level.java
  49. 4
      src/mightypork/rogue/world/tile/Tiles.java
  50. 2
      src/mightypork/rogue/world/tile/impl/NullTile.java
  51. 2
      src/mightypork/rogue/world/tile/impl/TileBaseDoor.java
  52. 2
      src/mightypork/rogue/world/tile/impl/TileBaseEntrance.java
  53. 2
      src/mightypork/rogue/world/tile/impl/TileBaseExit.java
  54. 2
      src/mightypork/rogue/world/tile/impl/TileBaseFloor.java
  55. 2
      src/mightypork/rogue/world/tile/impl/TileBasePassage.java
  56. 4
      src/mightypork/rogue/world/tile/impl/TileBaseSecretDoor.java
  57. 2
      src/mightypork/rogue/world/tile/impl/TileBaseStairs.java
  58. 2
      src/mightypork/rogue/world/tile/impl/TileBaseWall.java
  59. 2
      src/mightypork/rogue/world/tile/impl/TileSolid.java
  60. 2
      src/mightypork/rogue/world/tile/impl/TileWithItems.java
  61. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickDoor.java
  62. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickEntrance.java
  63. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickExit.java
  64. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickFloor.java
  65. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickPassage.java
  66. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickSecretDoor.java
  67. 4
      src/mightypork/rogue/world/tile/impl/brick/TileBrickWall.java
  68. 2
      src/mightypork/rogue/world/tile/render/DoorTileRenderer.java

@ -356,7 +356,7 @@ final public class EventBus implements Destroyable, BusAccess {
* @param clients clients
* @param event event
*/
private synchronized void doDispatch(Collection<Object> clients, BusEvent<?> event)
private synchronized void doDispatch(Collection<?> clients, BusEvent<?> event)
{
boolean accepted = false;

@ -47,7 +47,7 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
* @param event a event to be sent
* @param clients collection of clients
*/
public void broadcast(BusEvent<?> event, Collection<Object> clients)
public void broadcast(BusEvent<?> event, Collection<?> clients)
{
if (!canBroadcast(event)) return;
@ -62,7 +62,7 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
* @param clients subscribing clients
* @param processed clients already processed
*/
private void doBroadcast(final EVENT event, final Collection<Object> clients, final Collection<Object> processed)
private void doBroadcast(final EVENT event, final Collection<?> clients, final Collection<Object> processed)
{
for (final Object client : clients) {
@ -91,7 +91,7 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
if (client instanceof DelegatingClient) {
if (((DelegatingClient) client).doesDelegate()) {
final Collection<Object> children = ((DelegatingClient) client).getChildClients();
final Collection<?> children = ((DelegatingClient) client).getChildClients();
if (children != null && children.size() > 0) {
doBroadcast(event, children, processed);

@ -16,7 +16,7 @@ public interface DelegatingClient {
/**
* @return collection of child clients. Can not be null.
*/
public Collection<Object> getChildClients();
public Collection<?> getChildClients();
/**

@ -1,31 +0,0 @@
package mightypork.gamecore.util.math.algo.floodfill;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
public interface FillContext {
boolean canEnter(Coord pos);
boolean canSpreadFrom(Coord pos);
Step[] getSpreadSides();
/**
* Get the max distance filled form start point. Use -1 for unlimited range.
*
* @return max distance
*/
double getMaxDistance();
/**
* @return true if start should be spread no matter what
*/
boolean forceSpreadStart();
}

@ -9,26 +9,48 @@ import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
public class FloodFill {
public abstract class FloodFill {
public abstract boolean canEnter(Coord pos);
public abstract boolean canSpreadFrom(Coord pos);
public abstract Step[] getSpreadSides();
/**
* Get the max distance filled form start point. Use -1 for unlimited range.
*
* @return max distance
*/
public abstract double getMaxDistance();
/**
* @return true if start should be spread no matter what
*/
public abstract boolean forceSpreadStart();
/**
* Fill an area
*
* @param start start point
* @param context filling context
* @param foundNodes collection to put filled coords in
* @return true if fill was successful; false if max range was reached.
*/
public static final boolean fill(Coord start, FillContext context, Collection<Coord> foundNodes)
public final boolean fill(Coord start, Collection<Coord> foundNodes)
{
final Queue<Coord> activeNodes = new LinkedList<>();
final double maxDist = context.getMaxDistance();
final double maxDist = getMaxDistance();
activeNodes.add(start);
final Step[] sides = context.getSpreadSides();
boolean forceSpreadNext = context.forceSpreadStart();
final Step[] sides = getSpreadSides();
boolean forceSpreadNext = forceSpreadStart();
boolean limitReached = false;
@ -36,7 +58,7 @@ public class FloodFill {
final Coord current = activeNodes.poll();
foundNodes.add(current);
if (!context.canSpreadFrom(current) && !forceSpreadNext) continue;
if (!canSpreadFrom(current) && !forceSpreadNext) continue;
forceSpreadNext = false;
@ -49,7 +71,7 @@ public class FloodFill {
continue;
}
if (context.canEnter(next)) {
if (canEnter(next)) {
activeNodes.add(next);
} else {
foundNodes.add(next);

@ -15,8 +15,8 @@ import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.strings.StringProvider;
import mightypork.rogue.Res;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.World;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemType;
@ -175,7 +175,7 @@ public class InvLayer extends ScreenLayer {
} else {
pl.selectWeapon(selected);
}
world.msgEquipWeapon(pl.getSelectedWeapon());
world.getConsole().msgEquipWeapon(pl.getSelectedWeapon());
}
}

@ -14,7 +14,7 @@ import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.caching.RectCache;
import mightypork.rogue.Res;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemType;

@ -10,7 +10,7 @@ import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.rogue.Config;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.events.WorldPauseRequest;
import mightypork.rogue.world.events.WorldPauseRequest.PauseAction;

@ -7,7 +7,6 @@ import java.util.Set;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.modules.EntityMoveListener;

@ -13,14 +13,11 @@ import mightypork.rogue.world.item.Item;
*
* @author MightyPork
*/
public class PlayerInfo implements IonObjBundled {
public class PlayerData implements IonObjBundled {
/** Player inventory size */
private static final int INV_SIZE = 8;
/** Constant indicating that no weapon is selected. */
public static final int NO_WEAPON = -1;
/** Attack str with bare hands */
public static final int BARE_ATTACK = 1;
@ -30,7 +27,7 @@ public class PlayerInfo implements IonObjBundled {
private Inventory inventory = new Inventory(INV_SIZE);
private int selectedWeapon = NO_WEAPON;
private int selectedWeapon = -1;
@Override
@ -97,20 +94,24 @@ public class PlayerInfo implements IonObjBundled {
}
public boolean hasWeaponSelected()
{
return !(selectedWeapon < 0 || selectedWeapon >= getInventory().getSize());
}
public Item getSelectedWeapon()
{
if (selectedWeapon == NO_WEAPON) return null;
if (!hasWeaponSelected()) return null;
return inventory.getItem(selectedWeapon);
}
public void selectWeapon(int selectedWeapon)
{
if (selectedWeapon < 0 || selectedWeapon >= getInventory().getSize()) {
selectedWeapon = NO_WEAPON;
}
this.selectedWeapon = selectedWeapon;
if (!hasWeaponSelected()) selectedWeapon = -1; // normalize
}
}

@ -0,0 +1,369 @@
package mightypork.rogue.world;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemType;
import mightypork.rogue.world.level.Level;
/**
* Convenient access to player-related methods and data in world.
*
* @author MightyPork
*/
public class PlayerFacade {
/** */
private final World world;
/**
* @param world
*/
PlayerFacade(World world)
{
this.world = world;
}
public boolean canAscend()
{
return world.playerData.getLevelNumber() > 0;
}
public void descend()
{
if (!canDescend()) return;
final int lvl_num = getLevelNumber();
getLevel().removeEntity(world.playerEntity);
world.playerData.setLevelNumber(lvl_num + 1);
getLevel().forceFreeTile(getLevel().getEnterPoint());
getLevel().addEntity(world.playerEntity, getLevel().getEnterPoint());
getLevel().explore(getCoord());
world.console.msgEnterFloor(getLevelNumber());
}
public boolean canDescend()
{
return world.playerData.getLevelNumber() < world.levels.size() - 1;
}
public void ascend()
{
if (!canAscend()) return;
final int lvl_num = getLevelNumber();
getLevel().removeEntity(world.playerEntity);
world.playerData.setLevelNumber(lvl_num - 1);
getLevel().forceFreeTile(getLevel().getExitPoint());
getLevel().addEntity(world.playerEntity, getLevel().getExitPoint());
getLevel().explore(getCoord());
world.console.msgEnterFloor(getLevelNumber());
}
/**
* @return current level number, zero based.
*/
public int getLevelNumber()
{
return world.playerData.getLevelNumber();
}
public Level getLevel()
{
return world.levels.get(world.playerData.getLevelNumber());
}
public int getEID()
{
return world.playerData.getEID();
}
public Coord getCoord()
{
return world.playerEntity.getCoord();
}
public Vect getVisualPos()
{
return world.playerEntity.pos.getVisualPos();
}
public void navigateTo(Coord pos)
{
world.playerEntity.pos.navigateTo(pos);
}
public void cancelPath()
{
world.playerEntity.pos.cancelPath();
}
public void addPathStep(Step step)
{
world.playerEntity.pos.addStep(step);
}
public boolean isMoving()
{
return world.playerEntity.pos.isMoving();
}
public double getMoveProgress()
{
return world.playerEntity.pos.getProgress();
}
public boolean isDead()
{
return world.playerEntity.isDead();
}
public int getHealth()
{
return world.playerEntity.health.getHealth();
}
public int getHealthMax()
{
return world.playerEntity.health.getHealthMax();
}
public Inventory getInventory()
{
return world.playerData.getInventory();
}
public Entity getEntity()
{
return world.playerEntity;
}
public int getAttackStrength()
{
final Item weapon = world.playerData.getSelectedWeapon();
if (weapon == null) return PlayerData.BARE_ATTACK;
return PlayerData.BARE_ATTACK + weapon.getAttackPoints();
}
/**
* Eat food.
*
* @param itm food item
* @return if something was eaten
*/
public boolean eatFood(Item itm)
{
if (itm == null || itm.isEmpty() || itm.getType() != ItemType.FOOD) return false;
if (getHealth() < getHealthMax()) {
world.playerEntity.health.addHealth(itm.getFoodPoints());
itm.consume();
world.console.msgEat(itm);
return true;
}
return false;
}
public void selectWeapon(int selected)
{
world.playerData.selectWeapon(selected);
}
public Item getSelectedWeapon()
{
return world.playerData.getSelectedWeapon();
}
public int getSelectedWeaponIndex()
{
return world.playerData.getSelectedWeaponIndex();
}
public void tryToEatSomeFood()
{
final List<Item> foods = new ArrayList<>();
for (int i = 0; i < getInventory().getSize(); i++) {
final Item itm = getInventory().getItem(i);
if (itm != null && itm.getType() == ItemType.FOOD) {
foods.add(itm);
}
}
// sort from smallest to biggest foods
Collections.sort(foods, new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2)
{
return (o1.getFoodPoints() - o2.getFoodPoints());
}
});
for (final Item itm : foods) {
if (eatFood(itm)) {
getInventory().clean();
return;
}
}
if (getHealth() < getHealthMax()) {
world.console.msgNoMoreFood();
} else {
world.console.msgNotHungry();
}
}
public void attack(Entity prey)
{
final int attackPoints = getAttackStrength();
prey.receiveAttack(world.getPlayer().getEntity(), attackPoints);
if (prey.isDead()) {
world.console.msgKill(prey);
}
final Item wpn = getSelectedWeapon();
if (wpn != null) {
wpn.use();
if (wpn.isEmpty()) {
world.console.msgWeaponBreak(wpn);
getInventory().clean();
selectWeapon(-1);
pickBestWeaponIfNoneSelected();
}
}
}
private void pickBestWeaponIfNoneSelected()
{
if (getSelectedWeapon() != null) return;
final List<Item> wpns = new ArrayList<>();
for (int i = 0; i < getInventory().getSize(); i++) {
final Item itm = getInventory().getItem(i);
if (itm != null && itm.getType() == ItemType.WEAPON) {
wpns.add(itm);
}
}
// sort from smallest to biggest foods
Collections.sort(wpns, new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2)
{
return (o2.getAttackPoints() - o1.getAttackPoints());
}
});
for (final Item itm : wpns) {
for (int i = 0; i < getInventory().getSize(); i++) {
final Item itm2 = getInventory().getItem(i);
if (itm2 == itm) {
selectWeapon(i);
break;
}
}
break; // just one cycle
}
world.console.msgEquipWeapon(getSelectedWeapon());
}
public boolean addItem(Item item)
{
if (!getInventory().addItem(item)) {
world.console.msgCannotPick();
return false;
}
world.console.msgPick(item);
if (item.getType() == ItemType.WEAPON) {
if (getSelectedWeapon() != null) {
if (item.getAttackPoints() > getSelectedWeapon().getAttackPoints()) {
selectWeapon(-1); // unselect to grab the best one
}
}
pickBestWeaponIfNoneSelected();
}
return true;
}
public void setHealth(int health)
{
world.playerEntity.health.setHealth(health);
}
public void setHealthMax(int health)
{
world.playerEntity.health.setHealthMax(health);
}
public World getWorld()
{
return world;
}
}

@ -2,7 +2,9 @@ package mightypork.rogue.world;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import mightypork.gamecore.eventbus.BusAccess;
import mightypork.gamecore.eventbus.EventBus;
@ -11,13 +13,9 @@ import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonObjBundled;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.timing.Pauseable;
import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemType;
import mightypork.rogue.world.level.Level;
@ -28,356 +26,19 @@ import mightypork.rogue.world.level.Level;
*/
public class World implements DelegatingClient, BusAccess, IonObjBundled, Pauseable, Updateable {
/**
* Convenient access to player-related methods and data
*
* @author MightyPork
*/
public class PlayerFacade {
public boolean canAscend()
{
return playerInfo.getLevelNumber() > 0;
}
public void descend()
{
if (!canDescend()) return;
final int lvl_num = getLevelNumber();
getLevel().removeEntity(playerEntity);
playerInfo.setLevelNumber(lvl_num + 1);
getLevel().forceFreeTile(getLevel().getEnterPoint());
getLevel().addEntity(playerEntity, getLevel().getEnterPoint());
getLevel().explore(getCoord());
msgEnterFloor(getLevelNumber());
}
public boolean canDescend()
{
return playerInfo.getLevelNumber() < levels.size() - 1;
}
public void ascend()
{
if (!canAscend()) return;
final int lvl_num = getLevelNumber();
getLevel().removeEntity(playerEntity);
playerInfo.setLevelNumber(lvl_num - 1);
getLevel().forceFreeTile(getLevel().getExitPoint());
getLevel().addEntity(playerEntity, getLevel().getExitPoint());
getLevel().explore(getCoord());
msgEnterFloor(getLevelNumber());
}
/**
* @return current level number, zero based.
*/
public int getLevelNumber()
{
return playerInfo.getLevelNumber();
}
public Level getLevel()
{
return levels.get(playerInfo.getLevelNumber());
}
public int getEID()
{
return playerInfo.getEID();
}
public Coord getCoord()
{
return playerEntity.getCoord();
}
public Vect getVisualPos()
{
return playerEntity.pos.getVisualPos();
}
public void navigateTo(Coord pos)
{
playerEntity.pos.navigateTo(pos);
}
public void cancelPath()
{
playerEntity.pos.cancelPath();
}
public void addPathStep(Step step)
{
playerEntity.pos.addStep(step);
}
public boolean isMoving()
{
return playerEntity.pos.isMoving();
}
public double getMoveProgress()
{
return playerEntity.pos.getProgress();
}
public boolean isDead()
{
return playerEntity.isDead();
}
public int getHealth()
{
return playerEntity.health.getHealth();
}
public int getHealthMax()
{
return playerEntity.health.getHealthMax();
}
public Inventory getInventory()
{
return playerInfo.getInventory();
}
public Entity getEntity()
{
return playerEntity;
}
public int getAttackStrength()
{
final Item weapon = playerInfo.getSelectedWeapon();
if (weapon == null) return PlayerInfo.BARE_ATTACK;
return PlayerInfo.BARE_ATTACK + weapon.getAttackPoints();
}
/**
* Eat food.
*
* @param itm food item
* @return if something was eaten
*/
public boolean eatFood(Item itm)
{
if (itm == null || itm.isEmpty() || itm.getType() != ItemType.FOOD) return false;
if (getHealth() < getHealthMax()) {
playerEntity.health.addHealth(itm.getFoodPoints());
itm.consume();
msgEat(itm);
return true;
}
return false;
}
public void selectWeapon(int selected)
{
playerInfo.selectWeapon(selected);
}
public Item getSelectedWeapon()
{
return playerInfo.getSelectedWeapon();
}
public int getSelectedWeaponIndex()
{
return playerInfo.getSelectedWeaponIndex();
}
public void tryToEatSomeFood()
{
final List<Item> foods = new ArrayList<>();
for (int i = 0; i < getInventory().getSize(); i++) {
final Item itm = getInventory().getItem(i);
if (itm != null && itm.getType() == ItemType.FOOD) {
foods.add(itm);
}
}
// sort from smallest to biggest foods
Collections.sort(foods, new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2)
{
return (o1.getFoodPoints() - o2.getFoodPoints());
}
});
for (final Item itm : foods) {
if (eatFood(itm)) {
getInventory().clean();
return;
}
}
if (getHealth() < getHealthMax()) {
msgNoMoreFood();
} else {
msgNotHungry();
}
}
public void attack(Entity prey)
{
final int attackPoints = getAttackStrength();
prey.receiveAttack(getPlayer().getEntity(), attackPoints);
if (prey.isDead()) {
msgKill(prey);
}
final Item wpn = getSelectedWeapon();
if (wpn != null) {
wpn.use();
if (wpn.isEmpty()) {
msgWeaponBreak(wpn);
getInventory().clean();
selectWeapon(-1);
pickBestWeaponIfNoneSelected();
}
}
}
private void pickBestWeaponIfNoneSelected()
{
if (getSelectedWeapon() != null) return;
final List<Item> wpns = new ArrayList<>();
for (int i = 0; i < getInventory().getSize(); i++) {
final Item itm = getInventory().getItem(i);
if (itm != null && itm.getType() == ItemType.WEAPON) {
wpns.add(itm);
}
}
// sort from smallest to biggest foods
Collections.sort(wpns, new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2)
{
return (o2.getAttackPoints() - o1.getAttackPoints());
}
});
for (final Item itm : wpns) {
for (int i = 0; i < getInventory().getSize(); i++) {
final Item itm2 = getInventory().getItem(i);
if (itm2 == itm) {
selectWeapon(i);
break;
}
}
break; // just one cycle
}
msgEquipWeapon(getSelectedWeapon());
}
public boolean addItem(Item item)
{
if (!getInventory().addItem(item)) {
msgCannotPick();
return false;
}
msgPick(item);
if (item.getType() == ItemType.WEAPON) {
if (getSelectedWeapon() != null) {
if (item.getAttackPoints() > getSelectedWeapon().getAttackPoints()) {
selectWeapon(-1); // unselect to grab the best one
}
}
pickBestWeaponIfNoneSelected();
}
return true;
}
public void setHealth(int health)
{
playerEntity.health.setHealth(health);
}
public void setHealthMax(int health)
{
playerEntity.health.setHealthMax(health);
}
public World getWorld()
{
return World.this;
}
}
// not saved stuffs
private final PlayerFacade player = new PlayerFacade();
private Entity playerEntity;
private final PlayerFacade playerFacade = new PlayerFacade(this);
final WorldConsole console = new WorldConsole();
Entity playerEntity;
private BusAccess bus;
private int pauseDepth = 0;
private final ArrayList<Level> levels = new ArrayList<>();
private final PlayerInfo playerInfo = new PlayerInfo();
/** List of world's levels */
final ArrayList<Level> levels = new ArrayList<>();
private final WorldConsole console = new WorldConsole();
/** Player data saved together with world */
final PlayerData playerData = new PlayerData();
/** World seed */
private long seed;
@ -413,9 +74,9 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
lvl.setWorld(this);
}
in.loadBundled("player", playerInfo);
in.loadBundled("player", playerData);
playerEntity = levels.get(playerInfo.getLevelNumber()).getEntity(playerInfo.getEID());
playerEntity = levels.get(playerData.getLevelNumber()).getEntity(playerData.getEID());
if (playerEntity == null) {
throw new RuntimeException("Player entity not found in the world.");
}
@ -428,7 +89,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
out.put("seed", seed);
out.put("next_eid", eid);
out.putSequence("levels", levels);
out.putBundled("player", playerInfo);
out.putBundled("player", playerData);
}
@ -462,7 +123,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
public void createPlayer()
{
if (playerInfo.isInitialized()) {
if (playerData.isInitialized()) {
throw new RuntimeException("Player already created.");
}
@ -485,10 +146,10 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
floor.explore(spawn);
playerInfo.setLevelNumber(0);
playerInfo.setEID(playerEid);
playerData.setLevelNumber(0);
playerData.setEID(playerEid);
msgEnterFloor(0);
console.msgEnterFloor(0);
}
@ -534,7 +195,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
public PlayerFacade getPlayer()
{
return player;
return playerFacade;
}
@ -543,7 +204,7 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
{
if (isPaused()) return;
// update console timing
// update console timing - not as child client
console.update(delta);
}
@ -552,78 +213,4 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
{
return console;
}
public void msgPick(Item item)
{
console.addMessage("You've picked up a " + item.getVisualName() + ".");
console.lastPickupItem = item;
console.timeSinceLastPickup = 0;
}
public void msgWeaponBreak(Item item)
{
console.addMessage("Your " + item.getVisualName() + " has broken!");
}
public void msgEquipWeapon(Item item)
{
console.addMessage("You're now wielding " + (item == null ? "NOTHING" : "a " + item.getVisualName()) + ".");
}
public void msgEat(Item item)
{
console.addMessage("You've eaten a " + item.getVisualName() + ".");
}
public void msgKill(Entity prey)
{
console.addMessage("You've killed a " + prey.getVisualName() + ".");
}
public void msgDie(Entity attacker)
{
console.addMessage("You've been defeated by a " + attacker.getVisualName() + "!");
}
public void msgDiscoverSecretDoor()
{
console.addMessage("You've discovered a secret door.");
}
public void msgNoMoreFood()
{
console.addMessage("You don't have any food!");
}
public void msgNotHungry()
{
console.addMessage("You are not hungry.");
}
public void msgCannotPick()
{
console.addMessage("Can't collect items, inventory is full.");
}
public void msgEnterFloor(int floor)
{
console.addMessage("~ Welcome to floor " + (1+floor) + "! ~");
}
public void msgHeartPiece()
{
console.addMessage("Your health capacity has been increased.");
}
}

@ -9,9 +9,15 @@ import java.util.concurrent.LinkedBlockingDeque;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.math.Easing;
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.item.Item;
/**
* Message log in world view
*
* @author MightyPork
*/
public class WorldConsole implements Updateable {
/** Used only for display */
@ -113,4 +119,78 @@ public class WorldConsole implements Updateable {
{
entries.clear();
}
public void msgCannotPick()
{
addMessage("Can't collect items, inventory is full.");
}
public void msgDie(Entity attacker)
{
addMessage("You've been defeated by a " + attacker.getVisualName() + "!");
}
public void msgDiscoverSecretDoor()
{
addMessage("You've discovered a secret door.");
}
public void msgEat(Item item)
{
addMessage("You've eaten a " + item.getVisualName() + ".");
}
public void msgEnterFloor(int floor)
{
addMessage("~ Floor " + (1 + floor) + " ~");
}
public void msgEquipWeapon(Item item)
{
addMessage("You're now wielding " + (item == null ? "NOTHING" : "a " + item.getVisualName()) + ".");
}
public void msgHeartPiece()
{
addMessage("Your health capacity has been increased.");
}
public void msgKill(Entity prey)
{
addMessage("You've killed a " + prey.getVisualName() + ".");
}
public void msgNoMoreFood()
{
addMessage("You don't have any food!");
}
public void msgNotHungry()
{
addMessage("You are not hungry.");
}
public void msgPick(Item item)
{
addMessage("You've picked up a " + item.getVisualName() + ".");
lastPickupItem = item;
timeSinceLastPickup = 0;
}
public void msgWeaponBreak(Item item)
{
addMessage("Your " + item.getVisualName() + " has broken!");
}
}

@ -7,7 +7,7 @@ import java.io.IOException;
import mightypork.gamecore.eventbus.BusAccess;
import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.util.ion.Ion;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.gen.WorldCreator;
import mightypork.rogue.world.level.Level;
@ -56,6 +56,12 @@ public class WorldProvider extends RootBusNode {
}
public void destroyWorld()
{
setWorld(null);
}
public World getWorld()
{
return world;
@ -64,9 +70,11 @@ public class WorldProvider extends RootBusNode {
private void setWorld(World newWorld)
{
if (world != null) removeChildClient(world);
world = newWorld;
if (newWorld == null) return;
world.assignBus(this); // connect to bus (for event dispatching)
addChildClient(world);
}

@ -6,10 +6,10 @@ import java.util.Collection;
import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.world.entity.entities.EntityBossRat;
import mightypork.rogue.world.entity.entities.EntityBrownRat;
import mightypork.rogue.world.entity.entities.EntityGrayRat;
import mightypork.rogue.world.entity.entities.PlayerEntity;
import mightypork.rogue.world.entity.impl.EntityBossRat;
import mightypork.rogue.world.entity.impl.EntityBrownRat;
import mightypork.rogue.world.entity.impl.EntityGrayRat;
import mightypork.rogue.world.entity.impl.PlayerEntity;
/**

@ -2,11 +2,13 @@ package mightypork.rogue.world.entity;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.error.IllegalValueException;
@ -27,7 +29,7 @@ import mightypork.rogue.world.level.render.MapRenderContext;
*
* @author MightyPork
*/
public abstract class Entity implements IonObjBundled, Updateable {
public abstract class Entity implements IonObjBundled, Updateable, DelegatingClient {
private Level level;
private final EntityModel model;
@ -176,10 +178,6 @@ public abstract class Entity implements IonObjBundled, Updateable {
getLevel().freeTile(getCoord());
freed = true;
}
for (final Entry<String, EntityModule> entry : modules.entrySet()) {
entry.getValue().update(delta);
}
}
@ -278,4 +276,19 @@ public abstract class Entity implements IonObjBundled, Updateable {
public abstract String getVisualName();
@Override
public boolean doesDelegate()
{
return true;
}
@Override
public Collection<?> getChildClients()
{
return modules.values();
}
}

@ -11,7 +11,7 @@ import mightypork.gamecore.util.ion.IonObjBundled;
/**
* Abstract entity module
* Abstract entity module; Modules make up an entity AI and behavior.
*
* @author MightyPork
*/

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.rogue.world.entity.AiTimer;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.rogue.world.entity.Entity;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinder;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.Calc;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.Calc;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.rogue.world.entity.Entity;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import java.io.IOException;

@ -1,4 +1,4 @@
package mightypork.rogue.world.entity.entities;
package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.algo.Coord;
@ -138,7 +138,7 @@ public class PlayerEntity extends Entity {
// send kill event to listeners, after the entity has despawned (disappeared)
getWorld().getEventBus().sendDelayed(new PlayerKilledEvent(), getDespawnDelay());
getWorld().msgDie(lastAttacker);
getWorld().getConsole().msgDie(lastAttacker);
}

@ -3,7 +3,7 @@ package mightypork.rogue.world.events;
import mightypork.gamecore.eventbus.BusEvent;
import mightypork.gamecore.eventbus.event_flags.UnloggedEvent;
import mightypork.rogue.world.entity.entities.PlayerEntity;
import mightypork.rogue.world.entity.impl.PlayerEntity;
@UnloggedEvent

@ -1,7 +1,7 @@
package mightypork.rogue.world.events;
import mightypork.rogue.world.entity.entities.PlayerEntity;
import mightypork.rogue.world.entity.impl.PlayerEntity;
public interface PlayerStepEndListener {

@ -92,7 +92,7 @@ public class LevelGenerator {
// entities - random rats
for (int i = 0; i < Calc.randInt(rand, (int) (3 + level * 1.5), (int) (3 + level * 2.5)); i++) {
for (int i = 0; i < Calc.randInt(rand, (int) (3 + level * 1.5), 3 + level * 3); i++) {
Entity e;
if (level > 2 && rand.nextInt(level - 2 + 1) != 0) {

@ -454,6 +454,10 @@ public class ScratchMap {
public void writeToLevel(Level level)
{
if (level.getWorld() == null) {
throw new WorldGenError("Level has no world assigned."); // need for entities
}
// make sure no walkable are at edges.
final Coord c = Coord.make(0, 0);
final Coord c1 = Coord.make(0, 0);

@ -1,9 +1,9 @@
package mightypork.rogue.world;
package mightypork.rogue.world.gen;
import java.util.Random;
import mightypork.rogue.world.gen.LevelGenerator;
import mightypork.rogue.world.World;
public class WorldCreator {

@ -12,7 +12,7 @@ import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.constraints.rect.mutable.RectMutable;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.Tile;

@ -9,7 +9,7 @@ import mightypork.gamecore.input.events.KeyListener;
import mightypork.gamecore.util.math.algo.Sides;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.entity.entities.PlayerEntity;
import mightypork.rogue.world.entity.impl.PlayerEntity;
import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.gui.MapView;

@ -8,7 +8,7 @@ import mightypork.gamecore.util.math.Polar;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Sides;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.entity.entities.PlayerEntity;
import mightypork.rogue.world.entity.impl.PlayerEntity;
import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.tile.Tile;

@ -2,8 +2,8 @@ package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.World;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.MapView;

@ -11,7 +11,7 @@ import mightypork.gamecore.util.ion.IonObjBlob;
import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.PlayerFacade;
public abstract class Item implements IonObjBlob {

@ -6,15 +6,15 @@ import java.util.Collection;
import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.world.item.items.active.ItemHeartPiece;
import mightypork.rogue.world.item.items.food.ItemCheese;
import mightypork.rogue.world.item.items.food.ItemMeat;
import mightypork.rogue.world.item.items.food.ItemSandwich;
import mightypork.rogue.world.item.items.weapons.ItemBone;
import mightypork.rogue.world.item.items.weapons.ItemClub;
import mightypork.rogue.world.item.items.weapons.ItemHammer;
import mightypork.rogue.world.item.items.weapons.ItemStone;
import mightypork.rogue.world.item.items.weapons.ItemSword;
import mightypork.rogue.world.item.impl.active.ItemHeartPiece;
import mightypork.rogue.world.item.impl.food.ItemCheese;
import mightypork.rogue.world.item.impl.food.ItemMeat;
import mightypork.rogue.world.item.impl.food.ItemSandwich;
import mightypork.rogue.world.item.impl.weapons.ItemBone;
import mightypork.rogue.world.item.impl.weapons.ItemClub;
import mightypork.rogue.world.item.impl.weapons.ItemHammer;
import mightypork.rogue.world.item.impl.weapons.ItemStone;
import mightypork.rogue.world.item.impl.weapons.ItemSword;
/**

@ -1,4 +1,4 @@
package mightypork.rogue.world.item.items;
package mightypork.rogue.world.item.impl;
import mightypork.rogue.world.item.Item;

@ -1,4 +1,4 @@
package mightypork.rogue.world.item.items;
package mightypork.rogue.world.item.impl;
import mightypork.rogue.world.item.Item;

@ -1,8 +1,8 @@
package mightypork.rogue.world.item.items.active;
package mightypork.rogue.world.item.impl.active;
import mightypork.rogue.Res;
import mightypork.rogue.world.World.PlayerFacade;
import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
@ -80,7 +80,7 @@ public class ItemHeartPiece extends Item {
pl.setHealthMax(pl.getHealthMax() + 2); // two points / heart
pl.setHealth(pl.getHealthMax());
pl.getWorld().msgHeartPiece();
pl.getWorld().getConsole().msgHeartPiece();
return true;
}

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.food;
package mightypork.rogue.world.item.impl.food;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseFood;
import mightypork.rogue.world.item.impl.ItemBaseFood;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.food;
package mightypork.rogue.world.item.impl.food;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseFood;
import mightypork.rogue.world.item.impl.ItemBaseFood;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.food;
package mightypork.rogue.world.item.impl.food;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseFood;
import mightypork.rogue.world.item.impl.ItemBaseFood;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.weapons;
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseWeapon;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.weapons;
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseWeapon;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.weapons;
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseWeapon;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.weapons;
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseWeapon;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -1,10 +1,10 @@
package mightypork.rogue.world.item.items.weapons;
package mightypork.rogue.world.item.impl.weapons;
import mightypork.rogue.Res;
import mightypork.rogue.world.item.ItemModel;
import mightypork.rogue.world.item.ItemRenderer;
import mightypork.rogue.world.item.items.ItemBaseWeapon;
import mightypork.rogue.world.item.impl.ItemBaseWeapon;
import mightypork.rogue.world.item.render.QuadItemRenderer;

@ -17,7 +17,6 @@ import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Sides;
import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.algo.floodfill.FillContext;
import mightypork.gamecore.util.math.algo.floodfill.FloodFill;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.gamecore.util.math.noise.NoiseGen;
@ -25,7 +24,7 @@ import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.entities.PlayerEntity;
import mightypork.rogue.world.entity.impl.PlayerEntity;
import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel;
@ -60,6 +59,45 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
}
private final FloodFill exploreFiller = new FloodFill() {
@Override
public Step[] getSpreadSides()
{
return Sides.ALL_SIDES;
}
@Override
public double getMaxDistance()
{
return 5.4;
}
@Override
public boolean canSpreadFrom(Coord pos)
{
final Tile t = getTile(pos);
return t.isWalkable() && !t.isDoor();
}
@Override
public boolean canEnter(Coord pos)
{
final Tile t = getTile(pos);
return !t.isNull();
}
@Override
public boolean forceSpreadStart()
{
return true;
}
};
private static final Random rand = new Random();
public static final int ION_MARK = 53;
@ -524,52 +562,13 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
{
final Collection<Coord> filled = new HashSet<>();
FloodFill.fill(center, exploreFc, filled);
exploreFiller.fill(center, filled);
for (final Coord c : filled) {
getTile(c).setExplored();
}
}
private final FillContext exploreFc = new FillContext() {
@Override
public Step[] getSpreadSides()
{
return Sides.ALL_SIDES;
}
@Override
public double getMaxDistance()
{
return 5.4;
}
@Override
public boolean canSpreadFrom(Coord pos)
{
final Tile t = getTile(pos);
return t.isWalkable() && !t.isDoor();
}
@Override
public boolean canEnter(Coord pos)
{
final Tile t = getTile(pos);
return !t.isNull();
}
@Override
public boolean forceSpreadStart()
{
return true;
}
};
/**
* Get entity of type closest to coord
@ -676,7 +675,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
@Override
public boolean isListening()
{
return playerCount > 0;
return playerCount > 0; // listen only when player is in this level
}

@ -5,8 +5,8 @@ import java.io.IOException;
import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.world.tile.tiles.NullTile;
import mightypork.rogue.world.tile.tiles.brick.*;
import mightypork.rogue.world.tile.impl.NullTile;
import mightypork.rogue.world.tile.impl.brick.*;
/**

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.rogue.world.item.Item;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import java.io.IOException;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.gamecore.util.math.algo.Coord;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.gamecore.util.math.algo.Coord;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.gamecore.resources.textures.TxSheet;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.gamecore.resources.textures.TxSheet;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import java.io.IOException;
@ -32,7 +32,7 @@ public abstract class TileBaseSecretDoor extends TileBaseDoor {
if (clicks == 0) {
locked = false;
getWorld().msgDiscoverSecretDoor();
getWorld().getConsole().msgDiscoverSecretDoor();
}
return true;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.rogue.world.tile.TileModel;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.gamecore.resources.textures.TxSheet;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import mightypork.rogue.world.item.Item;

@ -1,4 +1,4 @@
package mightypork.rogue.world.tile.tiles;
package mightypork.rogue.world.tile.impl;
import java.io.IOException;

@ -1,9 +1,9 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
import mightypork.rogue.world.tile.impl.TileBaseDoor;
public class TileBrickDoor extends TileBaseDoor {

@ -1,11 +1,11 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.impl.TileBaseEntrance;
import mightypork.rogue.world.tile.render.OneFrameTileRenderer;
import mightypork.rogue.world.tile.tiles.TileBaseEntrance;
public class TileBrickEntrance extends TileBaseEntrance {

@ -1,11 +1,11 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.impl.TileBaseExit;
import mightypork.rogue.world.tile.render.OneFrameTileRenderer;
import mightypork.rogue.world.tile.tiles.TileBaseExit;
public class TileBrickExit extends TileBaseExit {

@ -1,9 +1,9 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseFloor;
import mightypork.rogue.world.tile.impl.TileBaseFloor;
public class TileBrickFloor extends TileBaseFloor {

@ -1,9 +1,9 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBasePassage;
import mightypork.rogue.world.tile.impl.TileBasePassage;
public class TileBrickPassage extends TileBasePassage {

@ -1,9 +1,9 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseSecretDoor;
import mightypork.rogue.world.tile.impl.TileBaseSecretDoor;
public class TileBrickSecretDoor extends TileBaseSecretDoor {

@ -1,9 +1,9 @@
package mightypork.rogue.world.tile.tiles.brick;
package mightypork.rogue.world.tile.impl.brick;
import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseWall;
import mightypork.rogue.world.tile.impl.TileBaseWall;
public class TileBrickWall extends TileBaseWall {

@ -7,7 +7,7 @@ import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
import mightypork.rogue.world.tile.impl.TileBaseDoor;
public class DoorTileRenderer extends TileRenderer {

Loading…
Cancel
Save