Skip to content

Commit 9e08f22

Browse files
committed
fix crash when loading the game with an overflown inventory
1 parent ee0450e commit 9e08f22

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

main/src/org/destinationsol/game/item/ItemContainer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import java.util.*;
2323

2424
public class ItemContainer implements Iterable<List<SolItem>> {
25-
public static final int MAX_GROUP_COUNT = 4 * Const.ITEM_GROUPS_PER_PAGE;
26-
public static final int MAX_GROUP_SZ = 30;
25+
public static final int MAX_INVENTORY_PAGES = 4;
26+
public static final int MAX_GROUP_COUNT = MAX_INVENTORY_PAGES * Const.ITEM_GROUPS_PER_PAGE;
27+
public static final int MAX_STACK_SIZE = 30; // e.g.: ammo, repair kit
2728

2829
private List<List<SolItem>> myGroups;
2930
private Set<List<SolItem>> myNewGroups;
@@ -57,7 +58,7 @@ public boolean canAdd(SolItem example) {
5758
for (int i = 0, myGroupsSize = myGroups.size(); i < myGroupsSize; i++) {
5859
List<SolItem> group = myGroups.get(i);
5960
SolItem item = group.get(0);
60-
if (item.isSame(example)) return group.size() < MAX_GROUP_SZ;
61+
if (item.isSame(example)) return group.size() < MAX_STACK_SIZE;
6162
}
6263
return myGroups.size() < MAX_GROUP_COUNT;
6364
}
@@ -68,15 +69,14 @@ public void add(SolItem addedItem) {
6869
List<SolItem> group = myGroups.get(i);
6970
SolItem item = group.get(0);
7071
if (item.isSame(addedItem)) {
71-
if ((group.size() < MAX_GROUP_SZ))
72-
{
72+
if ((group.size() < MAX_STACK_SIZE)) {
7373
group.add(addedItem);
7474
}
7575
return;
76-
7776
}
7877
}
79-
if (myGroups.size() >= MAX_GROUP_COUNT) throw new AssertionError("reached group count limit");
78+
// From now on, silently ignore if by some chance an extra inventory page is created
79+
//if (myGroups.size() >= MAX_GROUP_COUNT) throw new AssertionError("reached group count limit");
8080
ArrayList<SolItem> group = new ArrayList<>();
8181
group.add(addedItem);
8282
myGroups.add(0, group);

0 commit comments

Comments
 (0)