Ignore repeat orders

This commit is contained in:
Retera 2021-01-24 15:10:13 -05:00
parent d4245e2e65
commit 8111441f16
5 changed files with 125 additions and 3 deletions

View File

@ -64,4 +64,5 @@ public class AudioContext {
public AudioBufferSource createBufferSource() {
return new AudioBufferSource();
}
}

View File

@ -92,7 +92,7 @@ public class CUnit extends CWidget {
private boolean acceptingOrders = true;
private boolean invulnerable = false;
private CBehavior defaultBehavior;
private COrder currentOrder = null;
private COrder lastStartedOrder = null;
private CUnit workerInside;
private final War3ID[] buildQueue = new War3ID[WarsmashConstants.BUILD_QUEUE_SIZE];
private final QueueItemType[] buildQueueTypes = new QueueItemType[WarsmashConstants.BUILD_QUEUE_SIZE];
@ -384,6 +384,12 @@ public class CUnit extends CWidget {
}
}
if ((this.lastStartedOrder != null) && this.lastStartedOrder.equals(order)
&& (this.lastStartedOrder.getOrderId() == OrderIds.smart)) {
// I skip your spammed move orders, TODO this will probably break some repeat
// attack order or something later
return;
}
if ((queue || !this.acceptingOrders) && ((this.currentBehavior != this.stopBehavior)
&& (this.currentBehavior != this.holdPositionBehavior))) {
this.orderQueue.add(order);
@ -405,7 +411,7 @@ public class CUnit extends CWidget {
}
private CBehavior beginOrder(final CSimulation game, final COrder order) {
this.currentOrder = order;
this.lastStartedOrder = order;
CBehavior nextBehavior;
if (order != null) {
nextBehavior = order.begin(game, this);
@ -1214,6 +1220,6 @@ public class CUnit extends CWidget {
}
public COrder getCurrentOrder() {
return this.currentOrder;
return this.lastStartedOrder;
}
}

View File

@ -59,4 +59,38 @@ public class COrderNoTarget implements COrder {
return null;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.abilityHandleId;
result = (prime * result) + this.orderId;
result = (prime * result) + (this.queued ? 1231 : 1237);
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final COrderNoTarget other = (COrderNoTarget) obj;
if (this.abilityHandleId != other.abilityHandleId) {
return false;
}
if (this.orderId != other.orderId) {
return false;
}
if (this.queued != other.queued) {
return false;
}
return true;
}
}

View File

@ -63,4 +63,47 @@ public class COrderTargetPoint implements COrder {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.abilityHandleId;
result = (prime * result) + this.orderId;
result = (prime * result) + (this.queued ? 1231 : 1237);
result = (prime * result) + ((this.target == null) ? 0 : this.target.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final COrderTargetPoint other = (COrderTargetPoint) obj;
if (this.abilityHandleId != other.abilityHandleId) {
return false;
}
if (this.orderId != other.orderId) {
return false;
}
if (this.queued != other.queued) {
return false;
}
if (this.target == null) {
if (other.target != null) {
return false;
}
}
else if (!this.target.equals(other.target)) {
return false;
}
return true;
}
}

View File

@ -64,4 +64,42 @@ public class COrderTargetWidget implements COrder {
return caster.pollNextOrderBehavior(game);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.abilityHandleId;
result = (prime * result) + this.orderId;
result = (prime * result) + (this.queued ? 1231 : 1237);
result = (prime * result) + this.targetHandleId;
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final COrderTargetWidget other = (COrderTargetWidget) obj;
if (this.abilityHandleId != other.abilityHandleId) {
return false;
}
if (this.orderId != other.orderId) {
return false;
}
if (this.queued != other.queued) {
return false;
}
if (this.targetHandleId != other.targetHandleId) {
return false;
}
return true;
}
}