mousey random walkis

v5stable
ondra 11 years ago
parent 8d23f7959c
commit df3ec39a03
  1. 5
      src/mightypork/rogue/world/entity/impl/GrayRatAi.java
  2. 62
      src/mightypork/rogue/world/entity/impl/MonsterAi.java

@ -13,7 +13,6 @@ public class GrayRatAi extends MonsterAi {
setAttackTime(1.2); setAttackTime(1.2);
setScanTime(1.5); setScanTime(1.5);
setSleepTime(10);
} }
@ -48,13 +47,13 @@ public class GrayRatAi extends MonsterAi {
@Override @Override
protected boolean shouldSkipScan() protected boolean shouldSkipScan()
{ {
return false;//rand.nextInt(3) == 0; return false;
} }
@Override @Override
protected boolean shouldRandomlyAbandonPrey() protected boolean shouldRandomlyAbandonPrey()
{ {
return false;//rand.nextInt(8) == 0; return false;
} }
} }

@ -35,16 +35,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
} }
}; };
private final AiTimer timerSleepStart = new AiTimer(10) {
@Override
public void run()
{
if (chasing) return;
sleeping = true;
}
};
private final AiTimer timerAttack = new AiTimer(3) { private final AiTimer timerAttack = new AiTimer(3) {
@Override @Override
@ -66,8 +56,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
private int preyId = -1; private int preyId = -1;
public MonsterAi(final Entity entity) public MonsterAi(final Entity entity) {
{
super(entity); super(entity);
noDoorPf = new PathFinderProxy(entity.getPathFinder()) { noDoorPf = new PathFinderProxy(entity.getPathFinder()) {
@ -87,7 +76,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
timerAttack.start(); timerAttack.start();
timerFindPrey.start(); timerFindPrey.start();
timerSleepStart.start();
} }
@ -131,7 +119,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
public void save(IonBundle bundle) throws IOException public void save(IonBundle bundle) throws IOException
{ {
bundle.putBundled("tscan", timerFindPrey); bundle.putBundled("tscan", timerFindPrey);
bundle.putBundled("tsleep", timerSleepStart);
bundle.putBundled("tattack", timerAttack); bundle.putBundled("tattack", timerAttack);
bundle.put("chasing", chasing); bundle.put("chasing", chasing);
@ -145,7 +132,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
public void load(IonBundle bundle) throws IOException public void load(IonBundle bundle) throws IOException
{ {
bundle.loadBundled("tscan", timerFindPrey); bundle.loadBundled("tscan", timerFindPrey);
bundle.loadBundled("tsleep", timerSleepStart);
bundle.loadBundled("tattack", timerAttack); bundle.loadBundled("tattack", timerAttack);
chasing = bundle.get("chasing", chasing); chasing = bundle.get("chasing", chasing);
@ -168,7 +154,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
if (entity.isDead()) return; if (entity.isDead()) return;
timerFindPrey.update(delta); timerFindPrey.update(delta);
timerSleepStart.update(delta);
timerAttack.update(delta); timerAttack.update(delta);
if (chasing && !entity.pos.isMoving()) { if (chasing && !entity.pos.isMoving()) {
@ -181,8 +166,21 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
if (!isPreyInAttackRange(prey)) { if (!isPreyInAttackRange(prey)) {
stepTowardsPrey(prey); stepTowardsPrey(prey);
return;
} }
} }
if (sleeping && shouldRandomlyWake()) {
sleeping = false;
}
if (!chasing && shouldRandomlyFallAsleep()) {
sleeping = true;
}
if (!chasing && !sleeping && !entity.pos.isMoving() && Calc.rand.nextInt(6) == 0) {
entity.pos.addStep(Sides.randomCardinal());
}
} }
@ -197,7 +195,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
if (entity.isDead()) return; if (entity.isDead()) return;
if (shouldSkipScan()) return; // not hungry right now if (shouldSkipScan()) return; // not hungry right now
final Entity prey = entity.getLevel().getClosestEntity(entity.pos.getVisualPos(), EntityType.PLAYER, getScanRadius()); final Entity prey = entity.getLevel().getClosestEntity(entity.pos.getVisualPos(), EntityType.PLAYER, getScanRadius());
if (prey != null) { if (prey != null) {
@ -205,12 +203,8 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
final List<Coord> noDoorPath = noDoorPf.findPath(entity.getCoord(), prey.getCoord()); final List<Coord> noDoorPath = noDoorPf.findPath(entity.getCoord(), prey.getCoord());
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());
}
} }
} }
@ -241,9 +235,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
chasing = true; chasing = true;
sleeping = false; sleeping = false;
// not good to take a nap while chasing
timerSleepStart.pause();
// follow this one prey // follow this one prey
timerFindPrey.pause(); timerFindPrey.pause();
@ -255,7 +246,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
{ {
chasing = false; chasing = false;
preyId = -1; preyId = -1;
timerSleepStart.restart();
timerFindPrey.restart(); timerFindPrey.restart();
} }
@ -302,12 +292,6 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
} }
protected void setSleepTime(double secs)
{
timerSleepStart.setDuration(secs);
}
protected void setAttackTime(double secs) protected void setAttackTime(double secs)
{ {
timerAttack.setDuration(secs); timerAttack.setDuration(secs);
@ -360,4 +344,18 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
{ {
return false; return false;
} }
@DefaultImpl
protected boolean shouldRandomlyWake()
{
return Calc.rand.nextInt(3) == 0;
}
@DefaultImpl
protected boolean shouldRandomlyFallAsleep()
{
return Calc.rand.nextInt(5) == 0;
}
} }

Loading…
Cancel
Save