Skip to content

Commit

Permalink
Fix history related errors caused by some changes being done twice. (#…
Browse files Browse the repository at this point in the history
…10429)

* Fix errors related to history code caused by some changes being applied twice.

* Revert ai clean up.
  • Loading branch information
asvitkine authored May 11, 2022
1 parent 0a86a72 commit f6d0400
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void removeResource(final Resource resource, final int quantity) {
final int current = getQuantity(resource);
if ((current - quantity) < 0) {
throw new IllegalArgumentException(
"Cant remove more than player has of resource: "
"Can't remove more than player has of resource: "
+ resource.getName()
+ ". current:"
+ current
Expand All @@ -60,10 +60,6 @@ public void removeResource(final Resource resource, final int quantity) {
change(resource, -quantity);
}

public void removeAllOfResource(final Resource resource) {
resources.removeKey(resource);
}

private void change(final Resource resource, final int quantity) {
resources.add(resource, quantity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private int getLastChange(final HistoryNode node) {
} else if (node instanceof EventChild) {
lastChangeIndex = ((Event) node.getParent()).getChangeEndIndex();
} else if (node instanceof IndexedHistoryNode) {
lastChangeIndex = ((IndexedHistoryNode) node).getChangeStartIndex();
lastChangeIndex = ((IndexedHistoryNode) node).getChangeEndIndex();
} else {
lastChangeIndex = 0;
}
Expand All @@ -114,7 +114,7 @@ public Change getDelta(final HistoryNode start, final HistoryNode end) {
/** Changes the game state to reflect the historical state at {@code node}. */
public synchronized void gotoNode(final HistoryNode node) {
assertCorrectThread();
getGameData().acquireWriteLock();
gameData.acquireWriteLock();
try {
if (currentNode == null) {
currentNode = getLastNode();
Expand All @@ -125,7 +125,7 @@ public synchronized void gotoNode(final HistoryNode node) {
gameData.performChange(dataChange);
}
} finally {
getGameData().releaseWriteLock();
gameData.releaseWriteLock();
}
}

Expand All @@ -136,7 +136,7 @@ public synchronized void gotoNode(final HistoryNode node) {
public synchronized void removeAllHistoryAfterNode(final HistoryNode removeAfterNode) {
gotoNode(removeAfterNode);
assertCorrectThread();
getGameData().acquireWriteLock();
gameData.acquireWriteLock();
try {
final int lastChange = getLastChange(removeAfterNode) + 1;
while (changes.size() > lastChange) {
Expand All @@ -163,7 +163,7 @@ public synchronized void removeAllHistoryAfterNode(final HistoryNode removeAfter
this.removeNodeFromParent(nodesToRemove.remove(0));
}
} finally {
getGameData().releaseWriteLock();
gameData.releaseWriteLock();
}
}

Expand Down

0 comments on commit f6d0400

Please sign in to comment.