Balancing, mob self.-walk

v5stable
Ondřej Hruška 11 years ago
parent 29b831259d
commit a4ccee71ed
  1. 7
      build/Makefile
  2. BIN
      build/stub.jar
  3. 11
      src/mightypork/gamecore/util/math/Calc.java
  4. 6
      src/mightypork/gamecore/util/math/Range.java
  5. 8
      src/mightypork/gamecore/util/math/algo/Sides.java
  6. 6
      src/mightypork/rogue/screens/game/ScreenGame.java
  7. 2
      src/mightypork/rogue/world/entity/Entity.java
  8. 1
      src/mightypork/rogue/world/entity/EntityModule.java
  9. 7
      src/mightypork/rogue/world/entity/impl/BossRatAi.java
  10. 7
      src/mightypork/rogue/world/entity/impl/BrownRatAi.java
  11. 2
      src/mightypork/rogue/world/entity/impl/EntityBossRat.java
  12. 15
      src/mightypork/rogue/world/entity/impl/EntityBrownRat.java
  13. 12
      src/mightypork/rogue/world/entity/impl/EntityGrayRat.java
  14. 7
      src/mightypork/rogue/world/entity/impl/GrayRatAi.java
  15. 10
      src/mightypork/rogue/world/entity/impl/MonsterAi.java
  16. 16
      src/mightypork/rogue/world/gen/LevelGenerator.java
  17. 2
      src/mightypork/rogue/world/gen/ScratchMap.java
  18. 2
      src/mightypork/rogue/world/gen/WorldCreator.java
  19. 2
      src/mightypork/rogue/world/gen/rooms/TreasureRoom.java
  20. 2
      src/mightypork/rogue/world/item/Item.java
  21. 4
      src/mightypork/rogue/world/item/ItemModel.java
  22. 9
      src/mightypork/rogue/world/level/Level.java
  23. 3
      src/mightypork/rogue/world/tile/Tile.java
  24. 3
      src/mightypork/rogue/world/tile/impl/TileBaseSecretDoor.java

@ -22,7 +22,9 @@ $(OUT): $(IN) $(STUB)
unzip $(STUB) -d $(TMP_DIR) unzip $(STUB) -d $(TMP_DIR)
# export find $(TMP_DIR) -name "*.xcf" -type f -delete
# export
(cd $(TMP_DIR); zip -r9 ./pack.zip .) (cd $(TMP_DIR); zip -r9 ./pack.zip .)
mv -f $(TMP_DIR)/pack.zip $(OUT) mv -f $(TMP_DIR)/pack.zip $(OUT)
chmod +x $(OUT) chmod +x $(OUT)
@ -34,5 +36,8 @@ $(OUT): $(IN) $(STUB)
run: $(OUT) run: $(OUT)
java -jar $(OUT) java -jar $(OUT)
clean:
rm -rf $(OUT)
deploy: $(OUT) deploy: $(OUT)
cp -f $(OUT) /home/ondra/Dokumenty/Dropbox/Public/Rogue cp -f $(OUT) /home/ondra/Dokumenty/Dropbox/Public/Rogue

Binary file not shown.

@ -382,7 +382,7 @@ public class Calc {
} }
} }
private static Random rand = new Random(); public static final Random rand = new Random();
public static double sphereSurface(double radius) public static double sphereSurface(double radius)
@ -670,11 +670,14 @@ public class Calc {
public static int randInt(Random rand, int low, int high) public static int randInt(Random rand, int low, int high)
{ {
int range = high - low + 1; int range = Math.abs(high - low) + 1;
if (range < 1) range = 1;
return low + rand.nextInt(range); return low + rand.nextInt(range);
} }
public static int randInt(int low, int high)
{
return randInt(rand, low, high);
}
/** /**
* Get ordinal version of numbers (1 = 1st, 5 = 5th etc.) * Get ordinal version of numbers (1 = 1st, 5 = 5th etc.)

@ -19,8 +19,6 @@ public class Range {
private double min = 0; private double min = 0;
private double max = 1; private double max = 1;
private static Random rand = new Random();
/** /**
* Implicit range constructor 0-1 * Implicit range constructor 0-1
@ -76,7 +74,7 @@ public class Range {
*/ */
public int randInt() public int randInt()
{ {
return (int) (Math.round(min) + rand.nextInt((int) (Math.round(max) - Math.round(min)) + 1)); return Calc.randInt(Calc.rand, (int)Math.round(min), (int)Math.round(min));
} }
@ -87,7 +85,7 @@ public class Range {
*/ */
public double randDouble() public double randDouble()
{ {
return min + rand.nextDouble() * (max - min); return min + Calc.rand.nextDouble() * (max - min);
} }

@ -1,5 +1,7 @@
package mightypork.gamecore.util.math.algo; package mightypork.gamecore.util.math.algo;
import mightypork.gamecore.util.math.Calc;
public class Sides { public class Sides {
@ -67,4 +69,10 @@ public class Sides {
{ {
return (byte) (1 << (7 - i)); return (byte) (1 << (7 - i));
} }
public static Step randomCardinal()
{
return CARDINAL_SIDES[Calc.randInt(0, 3)];
}
} }

@ -9,6 +9,7 @@ import mightypork.gamecore.gui.ActionGroup;
import mightypork.gamecore.gui.screens.LayeredScreen; import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys; import mightypork.gamecore.input.Keys;
import mightypork.gamecore.util.math.Calc;
import mightypork.rogue.Config; import mightypork.rogue.Config;
import mightypork.rogue.world.PlayerFacade; import mightypork.rogue.world.PlayerFacade;
import mightypork.rogue.world.WorldProvider; import mightypork.rogue.world.WorldProvider;
@ -28,7 +29,6 @@ public class ScreenGame extends LayeredScreen {
WORLD, INV; WORLD, INV;
} }
private final Random rand = new Random();
private InvLayer invLayer; private InvLayer invLayer;
private HudLayer hudLayer; private HudLayer hudLayer;
@ -44,7 +44,7 @@ public class ScreenGame extends LayeredScreen {
public void execute() public void execute()
{ {
final PlayerFacade pl = WorldProvider.get().getPlayer(); final PlayerFacade pl = WorldProvider.get().getPlayer();
if (pl.isDead()) return; if (pl.isDead() || pl.getWorld().isPaused()) return;
pl.tryToEatSomeFood(); pl.tryToEatSomeFood();
} }
}; };
@ -147,7 +147,7 @@ public class ScreenGame extends LayeredScreen {
@Override @Override
public void run() public void run()
{ {
WorldProvider.get().createWorld(rand.nextLong()); WorldProvider.get().createWorld(Calc.rand.nextLong());
} }
}); });

@ -34,8 +34,6 @@ public abstract class Entity implements IonObjBundled, Updateable, DelegatingCli
private Level level; private Level level;
private final EntityModel model; private final EntityModel model;
protected final Random rand = new Random();
/** Entity ID */ /** Entity ID */
private int entityId = -1; private int entityId = -1;

@ -18,7 +18,6 @@ import mightypork.gamecore.util.ion.IonObjBundled;
public abstract class EntityModule implements IonObjBundled, Updateable { public abstract class EntityModule implements IonObjBundled, Updateable {
protected final Entity entity; protected final Entity entity;
protected static final Random rand = new Random();
public EntityModule(Entity entity) public EntityModule(Entity entity)

@ -1,6 +1,7 @@
package mightypork.rogue.world.entity.impl; package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.Calc;
import mightypork.rogue.world.entity.AiTimer; import mightypork.rogue.world.entity.AiTimer;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
@ -21,21 +22,21 @@ public class BossRatAi extends GrayRatAi {
{ {
super(entity); super(entity);
setAttackTime(0.6); setAttackTime(0.7);
} }
@Override @Override
protected int getAttackStrength() protected int getAttackStrength()
{ {
return 5 + rand.nextInt(4); return Calc.randInt(5, 11);
} }
@Override @Override
protected int getPreyAbandonDistance() protected int getPreyAbandonDistance()
{ {
return 15 + rand.nextInt(4); return Calc.randInt(15, 18);
} }

@ -1,6 +1,7 @@
package mightypork.rogue.world.entity.impl; package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.Calc;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
@ -18,20 +19,20 @@ public class BrownRatAi extends GrayRatAi {
@Override @Override
protected double getScanRadius() protected double getScanRadius()
{ {
return isSleeping() ? 3 + rand.nextInt(3) : 5 + rand.nextInt(3); return isSleeping() ? Calc.randInt(3, 5) : Calc.randInt(5, 8);
} }
@Override @Override
protected int getAttackStrength() protected int getAttackStrength()
{ {
return 2 + rand.nextInt(3); return Calc.randInt(2, 5);
} }
@Override @Override
protected int getPreyAbandonDistance() protected int getPreyAbandonDistance()
{ {
return 11 + rand.nextInt(4); return Calc.randInt(11, 14);
} }
} }

@ -32,7 +32,7 @@ public class EntityBossRat extends Entity {
health.setHealthMax(80); health.setHealthMax(80);
health.setHealth(80); health.setHealth(80);
health.setHitCooldownTime(0.35); health.setHitCooldownTime(0.33);
} }

@ -28,11 +28,11 @@ public class EntityBrownRat extends Entity {
addModule("ai", ai); addModule("ai", ai);
pos.addMoveListener(ai); pos.addMoveListener(ai);
pos.setStepTime(0.39); // faster than gray rat pos.setStepTime(0.38); // faster than gray rat
setDespawnDelay(1); setDespawnDelay(1);
health.setHealthMax(14); health.setHealthMax(20);
health.setHealth(Calc.randInt(rand, 8, 14)); // tougher to kill health.setHealth(Calc.randInt(12, 20)); // tougher to kill
health.setHitCooldownTime(0.35); // a bit longer than gray rat health.setHitCooldownTime(0.35); // a bit longer than gray rat
} }
@ -67,17 +67,12 @@ public class EntityBrownRat extends Entity {
{ {
// drop rat stuff // drop rat stuff
if (rand.nextInt(7) == 0) { if (Calc.rand.nextInt(2) == 0) {
getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(10));
return;
}
if (rand.nextInt(3) == 0) {
getLevel().dropNear(getCoord(), Items.MEAT.createItem()); getLevel().dropNear(getCoord(), Items.MEAT.createItem());
return; return;
} }
if (rand.nextInt(6) == 0) { if (Calc.rand.nextInt(4) == 0) {
getLevel().dropNear(getCoord(), Items.CHEESE.createItem()); getLevel().dropNear(getCoord(), Items.CHEESE.createItem());
return; return;
} }

@ -32,7 +32,7 @@ public class EntityGrayRat extends Entity {
setDespawnDelay(1); setDespawnDelay(1);
health.setHealthMax(6); health.setHealthMax(6);
health.setHealth(Calc.randInt(rand, 4, 6)); health.setHealth(Calc.randInt(4, 6));
health.setHitCooldownTime(0.3); health.setHitCooldownTime(0.3);
} }
@ -67,18 +67,18 @@ public class EntityGrayRat extends Entity {
{ {
// drop rat stuff // drop rat stuff
if (rand.nextInt(4) == 0) { if (Calc.rand.nextInt(6) == 0) {
getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(40)); getLevel().dropNear(getCoord(), Items.BONE.createItemDamaged(40));
return; return;
} }
if (rand.nextInt(6) == 0) { if (Calc.rand.nextInt(3) == 0) {
getLevel().dropNear(getCoord(), Items.MEAT.createItem()); getLevel().dropNear(getCoord(), Items.CHEESE.createItem());
return; return;
} }
if (rand.nextInt(3) == 0) { if (Calc.rand.nextInt(3) == 0) {
getLevel().dropNear(getCoord(), Items.CHEESE.createItem()); getLevel().dropNear(getCoord(), Items.MEAT.createItem());
return; return;
} }
} }

@ -1,6 +1,7 @@
package mightypork.rogue.world.entity.impl; package mightypork.rogue.world.entity.impl;
import mightypork.gamecore.util.math.Calc;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
@ -19,7 +20,7 @@ public class GrayRatAi extends MonsterAi {
@Override @Override
protected double getScanRadius() protected double getScanRadius()
{ {
return isSleeping() ? 2 + rand.nextInt(3) : 4 + rand.nextInt(3); return isSleeping() ? Calc.randInt(2, 4) : Calc.randInt(4, 6);
} }
@ -33,14 +34,14 @@ public class GrayRatAi extends MonsterAi {
@Override @Override
protected int getAttackStrength() protected int getAttackStrength()
{ {
return 1 + (rand.nextInt(5) == 0 ? 1 : 0); return 1 + (Calc.rand.nextInt(5) == 0 ? 1 : 0);
} }
@Override @Override
protected int getPreyAbandonDistance() protected int getPreyAbandonDistance()
{ {
return 8 + rand.nextInt(4); return Calc.randInt(8, 11);
} }

@ -6,7 +6,9 @@ import java.util.List;
import mightypork.gamecore.util.annot.DefaultImpl; import mightypork.gamecore.util.annot.DefaultImpl;
import mightypork.gamecore.util.ion.IonBundle; import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.algo.Coord; 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.Step;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinder; import mightypork.gamecore.util.math.algo.pathfinding.PathFinder;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinderProxy; import mightypork.gamecore.util.math.algo.pathfinding.PathFinderProxy;
@ -205,6 +207,10 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
if (noDoorPath == null) return; // cant reach, give up if (noDoorPath == null) return; // cant reach, give up
startChasing(prey); startChasing(prey);
} else {
if(Calc.rand.nextBoolean()) {
entity.pos.addStep(Sides.randomCardinal());
}
} }
} }
@ -317,14 +323,14 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
@DefaultImpl @DefaultImpl
protected double getScanRadius() protected double getScanRadius()
{ {
return sleeping ? 1 + rand.nextInt(3) : 4 + rand.nextInt(4); // For override return sleeping ? Calc.randInt(1, 3) : Calc.randInt(4, 8); // For override
} }
@DefaultImpl @DefaultImpl
protected int getPreyAbandonDistance() protected int getPreyAbandonDistance()
{ {
return 5 + rand.nextInt(4); // For override return Calc.randInt(5, 8); // For override
} }

@ -43,7 +43,7 @@ public class LevelGenerator {
if (rand.nextInt(6) > 0) map.addRoom(Rooms.DEAD_END, false); if (rand.nextInt(6) > 0) map.addRoom(Rooms.DEAD_END, false);
} }
for (int i = 0; i < Calc.randInt(rand, 1, level / 3); i++) { for (int i = 0; i < Calc.randInt(rand, 1, (int)Math.ceil(level / 2D)); i++) {
map.addRoom(Rooms.TREASURE, false); map.addRoom(Rooms.TREASURE, false);
} }
@ -86,13 +86,13 @@ public class LevelGenerator {
} }
if (level == 4) { if (level == 4) {
map.putItemInMap(Items.HAMMER.createItemDamaged(60), 100); map.putItemInMap(Items.HAMMER.createItemDamaged(40), 100);
} }
// entities - random rats // entities - random rats
for (int i = 0; i < Calc.randInt(rand, (int) (3 + level * 1.5), 3 + level * 3); i++) { for (int i = 0; i < Calc.randInt(rand, 2 + level * 2, 5 + level * 3); i++) {
Entity e; Entity e;
if (level > 2 && rand.nextInt(level - 2 + 1) != 0) { if (level > 2 && rand.nextInt(level - 2 + 1) != 0) {
@ -101,7 +101,15 @@ public class LevelGenerator {
e = Entities.RAT_GRAY.createEntity(); e = Entities.RAT_GRAY.createEntity();
} }
map.putEntityInMap(e, 20); map.putEntityInMap(e, 30);
if(rand.nextInt(6+level/2)==0) {
map.putItemInMap(Items.CHEESE.createItem(), 10);
}
if(rand.nextInt(6)==0) {
map.putItemInMap(Items.MEAT.createItem(), 10);
}
} }

@ -639,7 +639,7 @@ public class ScratchMap {
{ {
if (!isIn(pos)) return false; if (!isIn(pos)) return false;
if (pos.dist(enterPoint) < 5) return false; // protected distance. if (pos.dist(enterPoint) < 4) return false; // protected distance.
final Tile t = getTile(pos); final Tile t = getTile(pos);
if (!t.isWalkable()) return false; if (!t.isWalkable()) return false;

@ -8,7 +8,7 @@ import mightypork.rogue.world.World;
public class WorldCreator { public class WorldCreator {
public static final Random rand = new Random(); public static Random rand = new Random();
public static World createWorld(long seed) public static World createWorld(long seed)

@ -27,7 +27,7 @@ public class TreasureRoom extends SecretRoom {
map.putItemInArea(Items.ROCK.createItemDamaged(30), min, max, 50); map.putItemInArea(Items.ROCK.createItemDamaged(30), min, max, 50);
} }
for (int i = 0; i < Calc.randInt(rand, 0, 2); i++) { for (int i = 0; i < Calc.randInt(rand, 0, 3); i++) {
map.putItemInArea(Items.MEAT.createItem(), min, max, 50); map.putItemInArea(Items.MEAT.createItem(), min, max, 50);
} }

@ -21,8 +21,6 @@ public abstract class Item implements IonObjBlob {
private int amount = 1; private int amount = 1;
private int uses = 1; private int uses = 1;
protected static final Random rand = new Random();
public Item(ItemModel model) public Item(ItemModel model)
{ {

@ -20,8 +20,6 @@ public final class ItemModel {
public final int id; public final int id;
public final Class<? extends Item> itemClass; public final Class<? extends Item> itemClass;
public static final Random rand = new Random();
public ItemModel(int id, Class<? extends Item> item) public ItemModel(int id, Class<? extends Item> item)
{ {
@ -68,7 +66,7 @@ public final class ItemModel {
public Item createItemDamaged(int minimalHealthPercent) public Item createItemDamaged(int minimalHealthPercent)
{ {
final Item item = createItem(); final Item item = createItem();
item.setRemainingUses(Calc.randInt(rand, (int) Math.ceil(item.getMaxUses() * (minimalHealthPercent / 100D)), item.getMaxUses())); item.setRemainingUses(Calc.randInt((int) Math.ceil(item.getMaxUses() * (minimalHealthPercent / 100D)), item.getMaxUses()));
return item; return item;
} }
} }

@ -14,6 +14,7 @@ import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonInput; import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonObjBinary; import mightypork.gamecore.util.ion.IonObjBinary;
import mightypork.gamecore.util.ion.IonOutput; import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Sides; import mightypork.gamecore.util.math.algo.Sides;
import mightypork.gamecore.util.math.algo.Step; import mightypork.gamecore.util.math.algo.Step;
@ -98,8 +99,6 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
} }
}; };
private static final Random rand = new Random();
public static final int ION_MARK = 53; public static final int ION_MARK = 53;
private static final Comparator<Entity> ENTITY_RENDER_CMP = new EntityRenderComparator(); private static final Comparator<Entity> ENTITY_RENDER_CMP = new EntityRenderComparator();
@ -361,13 +360,13 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
// closer // closer
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
final Coord c = pos.add(-1 + rand.nextInt(3), -1 + rand.nextInt(3)); final Coord c = pos.add(Calc.randInt(-1, 1), Calc.randInt(-1, 1));
if (addEntity(entity, c)) return true; if (addEntity(entity, c)) return true;
} }
// further // further
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
final Coord c = pos.add(-2 + rand.nextInt(5), -2 + rand.nextInt(5)); final Coord c = pos.add(Calc.randInt(-2, 2),Calc.randInt(-2, 2));
if (addEntity(entity, c)) return true; if (addEntity(entity, c)) return true;
} }
@ -699,7 +698,7 @@ public class Level implements BusAccess, Updateable, DelegatingClient, Toggleabl
if (getTile(coord).dropItem(itm)) return true; if (getTile(coord).dropItem(itm)) return true;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
final Coord c = coord.add(-1 + rand.nextInt(3), -1 + rand.nextInt(3)); final Coord c = coord.add(Calc.randInt(-1, 1), Calc.randInt(-1, 1));
if (getTile(c).dropItem(itm)) return true; if (getTile(c).dropItem(itm)) return true;
} }

@ -29,9 +29,6 @@ public abstract class Tile implements BusAccess, IonObjBlob {
// tmp extras // tmp extras
public final TileGenData genData = new TileGenData(); public final TileGenData genData = new TileGenData();
/** RNG for random stuff in tiles */
protected static final Random rand = new Random();
public final TileModel model; public final TileModel model;
// temporary flag for map. // temporary flag for map.

@ -6,6 +6,7 @@ import java.io.IOException;
import mightypork.gamecore.resources.textures.TxSheet; import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.gamecore.util.ion.IonInput; import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput; import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.Calc;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
@ -14,7 +15,7 @@ import mightypork.rogue.world.tile.TileType;
public abstract class TileBaseSecretDoor extends TileBaseDoor { public abstract class TileBaseSecretDoor extends TileBaseDoor {
private int clicks = 2 + rand.nextInt(2); private int clicks = Calc.randInt(2, 3);
public TileBaseSecretDoor(TileModel model, TxSheet secret, TxSheet closed, TxSheet open) public TileBaseSecretDoor(TileModel model, TxSheet secret, TxSheet closed, TxSheet open)

Loading…
Cancel
Save