Skip to content

Commit f6d0400

Browse files
authored
Fix history related errors caused by some changes being done twice. (#10429)
* Fix errors related to history code caused by some changes being applied twice. * Revert ai clean up.
1 parent 0a86a72 commit f6d0400

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

game-app/game-core/src/main/java/games/strategy/engine/data/ResourceCollection.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void removeResource(final Resource resource, final int quantity) {
5050
final int current = getQuantity(resource);
5151
if ((current - quantity) < 0) {
5252
throw new IllegalArgumentException(
53-
"Cant remove more than player has of resource: "
53+
"Can't remove more than player has of resource: "
5454
+ resource.getName()
5555
+ ". current:"
5656
+ current
@@ -60,10 +60,6 @@ public void removeResource(final Resource resource, final int quantity) {
6060
change(resource, -quantity);
6161
}
6262

63-
public void removeAllOfResource(final Resource resource) {
64-
resources.removeKey(resource);
65-
}
66-
6763
private void change(final Resource resource, final int quantity) {
6864
resources.add(resource, quantity);
6965
}

game-app/game-core/src/main/java/games/strategy/engine/history/History.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private int getLastChange(final HistoryNode node) {
8888
} else if (node instanceof EventChild) {
8989
lastChangeIndex = ((Event) node.getParent()).getChangeEndIndex();
9090
} else if (node instanceof IndexedHistoryNode) {
91-
lastChangeIndex = ((IndexedHistoryNode) node).getChangeStartIndex();
91+
lastChangeIndex = ((IndexedHistoryNode) node).getChangeEndIndex();
9292
} else {
9393
lastChangeIndex = 0;
9494
}
@@ -114,7 +114,7 @@ public Change getDelta(final HistoryNode start, final HistoryNode end) {
114114
/** Changes the game state to reflect the historical state at {@code node}. */
115115
public synchronized void gotoNode(final HistoryNode node) {
116116
assertCorrectThread();
117-
getGameData().acquireWriteLock();
117+
gameData.acquireWriteLock();
118118
try {
119119
if (currentNode == null) {
120120
currentNode = getLastNode();
@@ -125,7 +125,7 @@ public synchronized void gotoNode(final HistoryNode node) {
125125
gameData.performChange(dataChange);
126126
}
127127
} finally {
128-
getGameData().releaseWriteLock();
128+
gameData.releaseWriteLock();
129129
}
130130
}
131131

@@ -136,7 +136,7 @@ public synchronized void gotoNode(final HistoryNode node) {
136136
public synchronized void removeAllHistoryAfterNode(final HistoryNode removeAfterNode) {
137137
gotoNode(removeAfterNode);
138138
assertCorrectThread();
139-
getGameData().acquireWriteLock();
139+
gameData.acquireWriteLock();
140140
try {
141141
final int lastChange = getLastChange(removeAfterNode) + 1;
142142
while (changes.size() > lastChange) {
@@ -163,7 +163,7 @@ public synchronized void removeAllHistoryAfterNode(final HistoryNode removeAfter
163163
this.removeNodeFromParent(nodesToRemove.remove(0));
164164
}
165165
} finally {
166-
getGameData().releaseWriteLock();
166+
gameData.releaseWriteLock();
167167
}
168168
}
169169

0 commit comments

Comments
 (0)