mirror of
https://github.com/Retera/WarsmashModEngine.git
synced 2022-07-31 17:38:59 +02:00
Remove code from behaviortest branch
This commit is contained in:
parent
cf9beb9923
commit
bc9f7d37a0
@ -27,8 +27,6 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.COrder;
|
|||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.OrderIds;
|
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.OrderIds;
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CAllianceType;
|
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CAllianceType;
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer;
|
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer;
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IBehavior;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IState;
|
|
||||||
|
|
||||||
public class CUnit extends CWidget {
|
public class CUnit extends CWidget {
|
||||||
private static final Rectangle tempRect = new Rectangle();
|
private static final Rectangle tempRect = new Rectangle();
|
||||||
@ -72,8 +70,6 @@ public class CUnit extends CWidget {
|
|||||||
private transient CBehaviorFollow followBehavior;
|
private transient CBehaviorFollow followBehavior;
|
||||||
private transient CBehaviorPatrol patrolBehavior;
|
private transient CBehaviorPatrol patrolBehavior;
|
||||||
private transient CBehaviorStop stopBehavior;
|
private transient CBehaviorStop stopBehavior;
|
||||||
private IBehavior behavior;
|
|
||||||
private IState state;
|
|
||||||
|
|
||||||
public CUnit(final int handleId, final int playerIndex, final float x, final float y, final float life,
|
public CUnit(final int handleId, final int playerIndex, final float x, final float y, final float life,
|
||||||
final War3ID typeId, final float facing, final float mana, final int maximumLife, final int maximumMana,
|
final War3ID typeId, final float facing, final float mana, final int maximumLife, final int maximumMana,
|
||||||
@ -664,8 +660,4 @@ public class CUnit extends CWidget {
|
|||||||
return getCurrentBehavior() instanceof CBehaviorMove;
|
return getCurrentBehavior() instanceof CBehaviorMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBehavior(final IBehavior behavior) {
|
|
||||||
this.behavior = behavior;
|
|
||||||
this.state = behavior.resolveNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
|
|
||||||
|
|
||||||
public abstract class BaseBehavior {
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
|
|
||||||
|
|
||||||
public abstract class BaseState implements IState {
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
|
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* IAbility
|
|
||||||
Execute(unit caster, int orderId, unit targetUnit, point targetPoint);
|
|
||||||
|
|
||||||
IBehavior
|
|
||||||
ResolveNext();
|
|
||||||
|
|
||||||
IState
|
|
||||||
Execute();
|
|
||||||
|
|
||||||
abstract BaseState
|
|
||||||
ctor(unit unit, IBehavior behavior)
|
|
||||||
abstract Execute();
|
|
||||||
|
|
||||||
abstract BaseBehavior
|
|
||||||
ctor(unit unit)
|
|
||||||
|
|
||||||
*/
|
|
||||||
public interface IAbility {
|
|
||||||
void execute(CUnit caster, int orderId, CWidget targetUnit, Point targetPoint);
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
|
|
||||||
|
|
||||||
public interface IBehavior {
|
|
||||||
IState resolveNext();
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
|
|
||||||
|
|
||||||
public interface IState {
|
|
||||||
void execute();
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.ability;
|
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.OrderIds;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IAbility;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.behavior.AttackTarget;
|
|
||||||
|
|
||||||
public class AttackAbility implements IAbility {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CUnit caster, final int orderId, final CWidget target, final Point targetPoint) {
|
|
||||||
if (target != null) {
|
|
||||||
new AttackTarget(caster, target);
|
|
||||||
}
|
|
||||||
else if (targetPoint != null) {
|
|
||||||
if (orderId == OrderIds.attackground) {
|
|
||||||
// TODO some stuff
|
|
||||||
}
|
|
||||||
else if (orderId == OrderIds.attack) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.ability;
|
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IAbility;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.behavior.MoveToPoint;
|
|
||||||
|
|
||||||
public class MoveAbility implements IAbility {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(final CUnit caster, final int orderId, final CWidget targetUnit, final Point targetPoint) {
|
|
||||||
if (targetUnit == null) {
|
|
||||||
caster.setBehavior(new MoveToPoint(caster, targetPoint));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.behavior;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IBehavior;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IState;
|
|
||||||
|
|
||||||
public class AttackTarget implements IBehavior {
|
|
||||||
private final CUnit attackingUnit;
|
|
||||||
private final CWidget targetUnit;
|
|
||||||
|
|
||||||
public AttackTarget(final CUnit attackingUnit, final CWidget targetUnit) {
|
|
||||||
this.attackingUnit = attackingUnit;
|
|
||||||
this.targetUnit = targetUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IState resolveNext() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.behavior;
|
|
||||||
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Point2D.Float;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IBehavior;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.state.MoveState;
|
|
||||||
|
|
||||||
public class MoveToPoint implements IBehavior {
|
|
||||||
|
|
||||||
private final CSimulation simulation;
|
|
||||||
private final CUnit unit;
|
|
||||||
private final Point point;
|
|
||||||
private final MoveState moveState;
|
|
||||||
private final List<Float> waypointList;
|
|
||||||
|
|
||||||
public MoveToPoint(final CSimulation simulation, final CUnit unit, final Point point) {
|
|
||||||
this.simulation = simulation;
|
|
||||||
this.unit = unit;
|
|
||||||
this.point = point;
|
|
||||||
this.waypointList = this.simulation.findNaiveSlowPath(unit, null, unit.getX(), unit.getY(),
|
|
||||||
new Point2D.Float(point.x, point.y), unit.getUnitType().getMovementType(),
|
|
||||||
unit.getUnitType().getCollisionSize(), true);
|
|
||||||
this.moveState = new MoveState();
|
|
||||||
this.unit.setBehavior(this);
|
|
||||||
this.unit.setState(this.moveState);
|
|
||||||
resolveNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resolveNext() {
|
|
||||||
if (this.waypointList.isEmpty()) {
|
|
||||||
this.unit.setState(state);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
final Float firstWaypoint = this.waypointList.remove(0);
|
|
||||||
this.unit.setState(this.moveState.reset(this, this.unit, firstWaypoint.x, firstWaypoint.y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.state;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IBehavior;
|
|
||||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.test.IState;
|
|
||||||
|
|
||||||
public class MoveState implements IState {
|
|
||||||
public IBehavior behavior;
|
|
||||||
public CUnit unit;
|
|
||||||
public float targetX;
|
|
||||||
public float targetY;
|
|
||||||
|
|
||||||
public MoveState reset(final IBehavior behavior, final CUnit unit, final float targetX, final float targetY) {
|
|
||||||
this.behavior = behavior;
|
|
||||||
this.unit = unit;
|
|
||||||
this.targetX = targetX;
|
|
||||||
this.targetY = targetY;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute() {
|
|
||||||
final float dx = this.targetX - this.unit.getX();
|
|
||||||
final float dy = this.targetY - this.unit.getY();
|
|
||||||
this.unit.setX(this.unit.getX(), collision);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user