Working with behaviors

This commit is contained in:
Retera 2020-11-08 18:16:32 -05:00
parent b74b2f6c91
commit cf9beb9923
32 changed files with 1417 additions and 988 deletions

View File

@ -55,6 +55,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.ui.MeleeUI;
import com.etheller.warsmash.viewer5.handlers.w3x.ui.command.CommandErrorListener;
public class WarsmashGdxMapGame extends ApplicationAdapter implements CanvasProvider, InputProcessor {
private static final boolean ENABLE_AUDIO = false;
private static final boolean ENABLE_MUSIC = false;
private DataSource codebase;
private War3MapViewer viewer;
@ -124,8 +125,10 @@ public class WarsmashGdxMapGame extends ApplicationAdapter implements CanvasProv
this.codebase = new CompoundDataSourceDescriptor(dataSourcesList).createDataSource();
this.viewer = new War3MapViewer(this.codebase, this);
this.viewer.worldScene.enableAudio();
this.viewer.enableAudio();
if (ENABLE_AUDIO) {
this.viewer.worldScene.enableAudio();
this.viewer.enableAudio();
}
try {
this.viewer.loadMap(this.warsmashIni.get("Map").getField("FilePath"));
}
@ -157,7 +160,9 @@ public class WarsmashGdxMapGame extends ApplicationAdapter implements CanvasProv
final Scene portraitScene = this.viewer.addSimpleScene();
this.uiScene = this.viewer.addSimpleScene();
this.uiScene.alpha = true;
this.uiScene.enableAudio();
if (ENABLE_AUDIO) {
this.uiScene.enableAudio();
}
// this.mainModel = (MdxModel) this.viewer.load("UI\\Glues\\MainMenu\\MainMenu3D_exp\\MainMenu3D_exp.mdx",

View File

@ -38,6 +38,9 @@ public class EventObjectSpn extends EmittedObject<MdxComplexInstance, EventObjec
final MdxModel model = (MdxModel) instance.model;
// Once the sequence finishes, this event object dies
if (model.getSequences().isEmpty()) {
System.err.println("NO SEQ FOR " + model.name);
}
if (instance.frame >= model.getSequences().get(0).getInterval()[1]) {
this.health = 0;

View File

@ -95,6 +95,9 @@ public final class UnitSound {
return false;
}
if (audioContext == null) {
return true;
}
final AudioPanner panner = audioContext.createPanner();
final AudioBufferSource source = audioContext.createBufferSource();

View File

@ -520,6 +520,12 @@ public class War3MapViewer extends ModelViewer {
return War3MapViewer.this
.getBuildingPathingPixelMap(War3MapViewer.this.allObjectData.getUnits().get(rawcode));
}
@Override
public CUnit createUnit(final CSimulation simulation, final War3ID typeId, final int playerIndex,
final float x, final float y, final float facing) {
return null;
}
}, this.terrain.pathingGrid, this.terrain.getEntireMap(), this.seededRandom, w3iFile.getPlayers());
this.walkableObjectsTree = new Quadtree<>(this.terrain.getEntireMap());

View File

@ -6,7 +6,6 @@ import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.CyclicBarrier;
import com.badlogic.gdx.math.Rectangle;
import com.etheller.warsmash.util.War3ID;
@ -28,6 +27,8 @@ 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.players.CAllianceType;
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 {
private static final Rectangle tempRect = new Rectangle();
@ -71,6 +72,8 @@ public class CUnit extends CWidget {
private transient CBehaviorFollow followBehavior;
private transient CBehaviorPatrol patrolBehavior;
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,
final War3ID typeId, final float facing, final float mana, final int maximumLife, final int maximumMana,
@ -201,9 +204,9 @@ public class CUnit extends CWidget {
}
}
else if (this.currentBehavior != null) {
CBehavior lastBehavior = this.currentBehavior;
final CBehavior lastBehavior = this.currentBehavior;
this.currentBehavior = this.currentBehavior.update(game);
if(this.currentBehavior.getHighlightOrderId() != lastBehavior.getHighlightOrderId()) {
if (this.currentBehavior.getHighlightOrderId() != lastBehavior.getHighlightOrderId()) {
this.stateNotifier.ordersChanged(getCurrentAbilityHandleId(), getCurrentOrderId());
}
}
@ -242,6 +245,17 @@ public class CUnit extends CWidget {
if (isDead()) {
return;
}
final CAbility ability = game.getAbility(order.getAbilityHandleId());
if (ability != null) {
// Allow the ability to response to the order without actually placing itself in
// the queue, nor modifying (interrupting) the queue.
if (!ability.checkBeforeQueue(game, this, order.getOrderId())) {
this.stateNotifier.ordersChanged(getCurrentAbilityHandleId(), getCurrentOrderId());
return;
}
}
if (queue && (this.currentOrder != null)) {
this.orderQueue.add(order);
}
@ -595,7 +609,8 @@ public class CUnit extends CWidget {
if (this.source.canReach(unit, this.source.acquisitionRange)
&& unit.canBeTargetedBy(this.game, this.source, attack.getTargetsAllowed())
&& (this.source.distance(unit) >= this.source.getUnitType().getMinimumAttackRange())) {
this.source.currentBehavior = this.source.getAttackBehavior().reset(OrderIds.attack, attack, unit);
this.source.currentBehavior = this.source.getAttackBehavior().reset(OrderIds.attack, attack,
unit);
return true;
}
}
@ -644,4 +659,13 @@ public class CUnit extends CWidget {
final COrder order = this.orderQueue.poll();
return beginOrder(game, order);
}
public boolean isMoving() {
return getCurrentBehavior() instanceof CBehaviorMove;
}
public void setBehavior(final IBehavior behavior) {
this.behavior = behavior;
this.state = behavior.resolveNext();
}
}

View File

@ -13,6 +13,9 @@ public interface CAbility extends CAbilityView {
/* should fire when ability removed from unit */
void onRemove(CSimulation game, CUnit unit);
/* return false to not do anything, such as for toggling autocast */
boolean checkBeforeQueue(CSimulation game, CUnit caster, int orderId);
CBehavior begin(CSimulation game, CUnit caster, int orderId, CWidget target);
CBehavior begin(CSimulation game, CUnit caster, int orderId, Vector2 point);

View File

@ -10,11 +10,12 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.combat.CWeaponType;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.combat.attacks.CUnitAttack;
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.test.IAbility;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityActivationReceiver;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityTargetCheckReceiver;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityTargetCheckReceiver.TargetType;
public class CAbilityAttack implements CAbility {
public class CAbilityAttack implements CAbility, IAbility {
private final int handleId;
public CAbilityAttack(final int handleId) {
@ -60,6 +61,11 @@ public class CAbilityAttack implements CAbility {
}
}
@Override
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId) {
return true;
}
@Override
public void checkCanTarget(final CSimulation game, final CUnit unit, final int orderId, final Vector2 target,
final AbilityTargetCheckReceiver<Vector2> receiver) {

View File

@ -67,6 +67,11 @@ public class CAbilityGeneric implements CAbility {
public void onRemove(final CSimulation game, final CUnit unit) {
}
@Override
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId) {
return false;
}
@Override
public CBehavior begin(final CSimulation game, final CUnit caster, final int orderId, final CWidget target) {
return caster.pollNextOrderBehavior(game);

View File

@ -85,6 +85,11 @@ public class CAbilityMove implements CAbility {
}
@Override
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId) {
return true;
}
@Override
public CBehavior begin(final CSimulation game, final CUnit caster, final int orderId, final CWidget target) {
return caster.getFollowBehavior().reset(OrderIds.move, (CUnit) target);

View File

@ -75,4 +75,9 @@ public abstract class AbstractCAbilityBuild extends AbstractCAbility implements
final AbilityTargetCheckReceiver<Void> receiver) {
receiver.orderIdNotAccepted();
}
@Override
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId) {
return false;
}
}

View File

@ -43,7 +43,7 @@ public class CAbilityHumanBuild extends AbstractCAbilityBuild {
@Override
public CBehavior begin(final CSimulation game, final CUnit caster, final int orderId, final Vector2 point) {
// TODO Auto-generated method stub
// caster.getMoveBehavior().reset(point.x, point.y, )
return null;
}

View File

@ -91,6 +91,18 @@ public class CAbilityColdArrows implements CAbility {
public void onRemove(final CSimulation game, final CUnit unit) {
}
@Override
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId) {
switch (orderId) {
case OrderIds.coldarrows:
case OrderIds.uncoldarrows:
this.autoCastActive = !this.autoCastActive;
return false;
default:
return true;
}
}
@Override
public CBehavior begin(final CSimulation game, final CUnit caster, final int orderId, final CWidget target) {
CBehavior behavior = null;
@ -113,7 +125,6 @@ public class CAbilityColdArrows implements CAbility {
@Override
public CBehavior beginNoTarget(final CSimulation game, final CUnit caster, final int orderId) {
this.autoCastActive = !this.autoCastActive;
return caster.pollNextOrderBehavior(game);
}
}

View File

@ -2,7 +2,6 @@ package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors;
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.CWidget;
public abstract class CAbstractRangedBehavior implements CRangedBehavior {
protected final CUnit unit;
@ -12,28 +11,29 @@ public abstract class CAbstractRangedBehavior implements CRangedBehavior {
}
private boolean wasWithinPropWindow = false;
protected CWidget target;
private boolean wasInRange = false;
private CBehaviorMove moveBehavior;
protected final CAbstractRangedBehavior innerReset(final CWidget target) {
protected final CAbstractRangedBehavior innerReset() {
this.wasWithinPropWindow = false;
this.target = target;
this.wasInRange = false;
CBehaviorMove moveBehavior;
if (!this.unit.isMovementDisabled()) {
if ((target instanceof CUnit) && !((CUnit) target).getUnitType().isBuilding()) {
this.moveBehavior = this.unit.getMoveBehavior().reset((CUnit) target, this);
}
else {
this.moveBehavior = this.unit.getMoveBehavior().reset(target.getX(), target.getY(), this);
}
moveBehavior = setupMoveBehavior();
}
else {
this.moveBehavior = null;
moveBehavior = null;
}
this.moveBehavior = moveBehavior;
return this;
}
protected abstract CBehaviorMove setupMoveBehavior();
protected abstract float getTargetX();
protected abstract float getTargetY();
protected abstract CBehavior update(CSimulation simulation, boolean withinRange);
protected abstract boolean checkTargetStillValid(CSimulation simulation);
@ -51,15 +51,14 @@ public abstract class CAbstractRangedBehavior implements CRangedBehavior {
}
this.wasInRange = false;
resetBeforeMoving(simulation);
;
return this.unit.getMoveBehavior();
}
this.wasInRange = true;
if (!this.unit.isMovementDisabled()) {
final float prevX = this.unit.getX();
final float prevY = this.unit.getY();
final float deltaY = this.target.getY() - prevY;
final float deltaX = this.target.getX() - prevX;
final float deltaY = getTargetY() - prevY;
final float deltaX = getTargetX() - prevX;
final double goalAngleRad = Math.atan2(deltaY, deltaX);
float goalAngle = (float) Math.toDegrees(goalAngleRad);
if (goalAngle < 0) {

View File

@ -0,0 +1,35 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
public abstract class CAbstractRangedPointTargetBehavior extends CAbstractRangedBehavior {
protected float targetX;
protected float targetY;
public CAbstractRangedPointTargetBehavior(final CUnit unit) {
super(unit);
}
protected final CAbstractRangedBehavior innerReset(final float targetX, final float targetY) {
this.targetX = targetX;
this.targetY = targetY;
return innerReset();
}
@Override
protected float getTargetX() {
return this.targetX;
}
@Override
protected float getTargetY() {
return this.targetY;
}
@Override
protected CBehaviorMove setupMoveBehavior() {
return this.unit.getMoveBehavior().reset(this.targetX, this.targetY, this);
}
}

View File

@ -0,0 +1,39 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget;
public abstract class CAbstractRangedWidgetTargetBehavior extends CAbstractRangedBehavior {
protected CWidget target;
public CAbstractRangedWidgetTargetBehavior(final CUnit unit) {
super(unit);
}
protected final CAbstractRangedBehavior innerReset(final CWidget target) {
this.target = target;
return innerReset();
}
@Override
protected float getTargetX() {
return this.target.getX();
}
@Override
protected float getTargetY() {
return this.target.getY();
}
@Override
protected CBehaviorMove setupMoveBehavior() {
if ((this.target instanceof CUnit) && !((CUnit) this.target).getUnitType().isBuilding()) {
return this.unit.getMoveBehavior().reset((CUnit) this.target, this);
}
else {
return this.unit.getMoveBehavior().reset(this.target.getX(), this.target.getY(), this);
}
}
}

View File

@ -8,7 +8,7 @@ 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.combat.attacks.CUnitAttack;
public class CBehaviorAttack extends CAbstractRangedBehavior {
public class CBehaviorAttack extends CAbstractRangedWidgetTargetBehavior {
private int highlightOrderId;
@ -21,7 +21,7 @@ public class CBehaviorAttack extends CAbstractRangedBehavior {
private int backSwingTime;
private int thisOrderCooldownEndTime;
public CBehaviorAttack reset(int highlightOrderId, final CUnitAttack unitAttack, final CWidget target) {
public CBehaviorAttack reset(final int highlightOrderId, final CUnitAttack unitAttack, final CWidget target) {
this.highlightOrderId = highlightOrderId;
super.innerReset(target);
this.unitAttack = unitAttack;
@ -33,18 +33,18 @@ public class CBehaviorAttack extends CAbstractRangedBehavior {
@Override
public int getHighlightOrderId() {
return highlightOrderId;
return this.highlightOrderId;
}
@Override
public boolean isWithinRange(final CSimulation simulation) {
float range = this.unitAttack.getRange();
if ((this.target instanceof CUnit) && (((CUnit) this.target).getCurrentBehavior() instanceof CBehaviorMove)
&& (this.damagePointLaunchTime != 0 /*
* only apply range motion buffer if they were already in range and
* attacked
*/)) {
range += this.unitAttack.getRangeMotionBuffer();
if ((this.target instanceof CUnit) && (((CUnit) this.target).isMoving()) && (simulation
.getGameTurnTick() < this.unit.getCooldownEndTime() /*
* only apply range motion buffer if they were
* already in range and attacked
*/)) {
range += this.unitAttack.getRangeMotionBuffer() + 1000;
}
return this.unit.canReach(this.target, range)
&& (this.unit.distance(this.target) >= this.unit.getUnitType().getMinimumAttackRange());

View File

@ -5,7 +5,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.SequenceUtils;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
public class CBehaviorFollow extends CAbstractRangedBehavior {
public class CBehaviorFollow extends CAbstractRangedWidgetTargetBehavior {
private int higlightOrderId;
@ -13,14 +13,14 @@ public class CBehaviorFollow extends CAbstractRangedBehavior {
super(unit);
}
public CBehavior reset(int higlightOrderId, final CUnit target) {
public CBehavior reset(final int higlightOrderId, final CUnit target) {
this.higlightOrderId = higlightOrderId;
return innerReset(target);
}
@Override
public int getHighlightOrderId() {
return higlightOrderId;
return this.higlightOrderId;
}
@Override

View File

@ -0,0 +1,45 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.build;
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.behaviors.CAbstractRangedPointTargetBehavior;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.CBehavior;
public class CBehaviorBuild extends CAbstractRangedPointTargetBehavior {
private int orderId;
public CBehaviorBuild(final CUnit unit) {
super(unit);
}
public CBehavior reset(final float targetX, final float targetY, final int orderId) {
this.orderId = orderId;
return innerReset(targetX, targetY);
}
@Override
public boolean isWithinRange(final CSimulation simulation) {
return this.unit.distance(this.targetX, this.targetY) <= 23525;
}
@Override
public int getHighlightOrderId() {
return this.orderId;
}
@Override
protected CBehavior update(final CSimulation simulation, final boolean withinRange) {
return this;
}
@Override
protected boolean checkTargetStillValid(final CSimulation simulation) {
return true;
}
@Override
protected void resetBeforeMoving(final CSimulation simulation) {
}
}

View File

@ -12,8 +12,8 @@ public class CPlayer {
private final CRace race;
private final float[] startLocation;
private final EnumSet<CRacePreference> racePrefs;
private int gold;
private int lumber;
private int gold = 5000;
private int lumber = 5000;
private final EnumSet<CAllianceType>[] alliances = new EnumSet[WarsmashConstants.MAX_PLAYERS];
public CPlayer(final int id, final CMapControl controlType, final String name, final CRace race,

View File

@ -0,0 +1,5 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
public abstract class BaseBehavior {
}

View File

@ -0,0 +1,5 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
public abstract class BaseState implements IState {
}

View File

@ -0,0 +1,28 @@
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);
}

View File

@ -0,0 +1,5 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
public interface IBehavior {
IState resolveNext();
}

View File

@ -0,0 +1,5 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.test;
public interface IState {
void execute();
}

View File

@ -0,0 +1,28 @@
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) {
}
}
}
}

View File

@ -0,0 +1,22 @@
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 {
}
}
}

View File

@ -0,0 +1,22 @@
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;
}
}

View File

@ -0,0 +1,45 @@
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));
}
}
}

View File

@ -0,0 +1,28 @@
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);
}
}

View File

@ -14,6 +14,9 @@ public interface SimulationRenderController {
CAttackProjectile createAttackProjectile(CSimulation simulation, float launchX, float launchY, float launchFacing,
CUnit source, CUnitAttackMissile attack, CWidget target, float damage, int bounceIndex);
CUnit createUnit(CSimulation simulation, final War3ID typeId, final int playerIndex, final float x, final float y,
final float facing);
void createInstantAttackEffect(CSimulation cSimulation, CUnit source, CUnitAttackInstant attack, CWidget target);
void spawnUnitDamageSound(CUnit damagedUnit, final String weaponSound, String armorType);

View File

@ -64,6 +64,9 @@ public class DesktopLauncher {
Extensions.soundLengthExtension = new SoundLengthExtension() {
@Override
public float getDuration(final Sound sound) {
if (sound == null) {
return 1;
}
return ((OpenALSound) sound).duration();
}
};