Beispiel #1
0
  protected void stepWalking(GameWorld world) {
    float dx = this.targetX - this.x;
    float dy = this.targetY - this.y;
    // float d = (float) Math.sqrt(dx * dx + dy * dy);
    GameThing thing = null;

    if (this.targetUnitID != 0) {
      thing = world.getThing(this.targetUnitID);
    }

    if (thing == null) {
      // Target unit doesn't exist so just walk to the location

      if (withinRange(this.targetX, this.targetY)) {
        finishWalking(world, thing);
        return;
      }

      walkStep(dx, dy);
    } else {
      if (withinRange(thing)) {
        finishWalking(world, thing);
        return;
      }

      dx = thing.getX() - this.x;
      dy = thing.getY() - this.y;
      walkStep(dx, dy);

      // if (withinRange(thing)) {
      // finishWalking(world, thing);
      // }
    }
  }
Beispiel #2
0
  protected void stepHarvestingReturn(GameWorld world) {
    Colony home;
    GamePlayer player = world.getPlayer(this);

    if (player == null) {
      return;
    }

    home = world.findThing(player, Colony.class);

    if (home == null) {
      return;
    }

    if (withinRange(home)) {
      player.addMinerals(carryingMinerals);
      carryingMinerals = 0;
      return;
    }

    walkStep(home);
  }
Beispiel #3
0
  protected void stepAttacking(GameWorld world) {
    GameThing target = world.getThing(targetUnitID);

    if (target == null) {
      // Thing being attacked is gone
      finishAttacking(world);
      return;
    }

    // if (target instanceof Mineral) {
    // stepAttackingMineral(world, (Mineral) target);
    // } else

    if (target instanceof Unit) {
      stepAttackingUnit(world, (Unit) target);
    }
  }
Beispiel #4
0
  protected void stepHarvesting(GameWorld world) {
    GameThing target = world.getThing(targetUnitID);

    if (carryingMinerals >= 10) {
      stepHarvestingReturn(world);
      return;
    }

    if (target == null) {
      // Thing being attacked is gone
      // finishAttacking(world);
      return;
    }

    if (!withinRange(target)) {
      walkStep(target);
      return;
    }

    if (target instanceof Mineral) {
      stepAttackingMineral(world, (Mineral) target);
    }
  }