final Entity ae = game.getEntity(attackerId); final Entity te = game.getEntity(targetId); Coords chargeSrc = ae.getPosition(); MovementData.Step chargeStep = null;   if (!md.contains(MovementData.STEP_CHARGE)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Charge action not found in movment path"); }   if (md.contains(MovementData.STEP_START_JUMP)) { return new ToHitData(ToHitData.IMPOSSIBLE, "No jumping allowed while charging"); }   if (md.contains(MovementData.STEP_BACKWARDS)) { return new ToHitData(ToHitData.IMPOSSIBLE, "No backwards movement allowed while charging"); }   compile(game, attackerId, md); for (final Enumeration i = md.getSteps(); i.hasMoreElements();) { final MovementData.Step step = (MovementData.Step)i.nextElement(); if (step.getMovementType() == Entity.MOVE_ILLEGAL) { break; } else { if (step.getType() == MovementData.STEP_CHARGE) { chargeStep = step; } else { chargeSrc = step.getPosition(); } } }   if (chargeStep == null || !te.getPosition().equals(chargeStep.getPosition())) { return new ToHitData(ToHitData.IMPOSSIBLE, "Could not reach target with movement"); }   if (te.ready) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target must be done with movement"); }  return toHitCharge(game, attackerId, targetId, chargeSrc); }
int movement=Entity.MOVE_WALK;  if (md.getMpUsed() > game.getEntity(attackerId).walkMP) { movement=Entity.MOVE_RUN; };  if (md.contains(MovementData.STEP_START_JUMP)) { movement=Entity.MOVE_JUMP; };  return toHitCharge(game, attackerId, targetId, md, movement); };
    public static ToHitData toHitCharge(Game game, int attackerId, int targetId, MovementData md) {        final Entity ae = game.getEntity(attackerId);        final Entity te = game.getEntity(targetId);        Coords chargeSrc = ae.getPosition();        MovementData.Step chargeStep = null;                // let's just check this        if (!md.contains(MovementData.STEP_CHARGE)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Charge action not found in movment path");        }                // no jumping        if (md.contains(MovementData.STEP_START_JUMP)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "No jumping allowed while charging");        }                // no backwards        if (md.contains(MovementData.STEP_BACKWARDS)) {            return new ToHitData(ToHitData.IMPOSSIBLE, "No backwards movement allowed while charging");        }                // determine last valid step        compile(game, attackerId, md);        for (final Enumeration i = md.getSteps(); i.hasMoreElements();) {            final MovementData.Step step = (MovementData.Step)i.nextElement();            if (step.getMovementType() == Entity.MOVE_ILLEGAL) {                break;            } else {                if (step.getType() == MovementData.STEP_CHARGE) {                    chargeStep = step;                } else {                    chargeSrc = step.getPosition();                }            }        }                // need to reach target        if (chargeStep == null || !te.getPosition().equals(chargeStep.getPosition())) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Could not reach target with movement");        }                // target must have moved already        if (te.ready) {            return new ToHitData(ToHitData.IMPOSSIBLE, "Target must be done with movement");        }                return toHitCharge(game, attackerId, targetId, chargeSrc);    }