Skip to content

Commit

Permalink
ref: applied fixes from 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Apr 29, 2024
1 parent fcd3a61 commit 988e6ee
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion guilib
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public SignalBoxPathway getPathway() {
return pathway;
}

public boolean isPathwayPossibleButCurrentyBlocked() {
return this == ALREADY_USED;
public boolean canBeAddedToSaver() {
return this == ALREADY_USED || this == NO_PATH;
}

public boolean isPass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void deserializeServer(final ReadBuffer buffer) {
}
final PathwayRequestResult request = grid.requestWay(start, end);
if (request != PathwayRequestResult.PASS) {
if (request.isPathwayPossibleButCurrentyBlocked() && grid.addNextPathway(start, end)) {
if (request.canBeAddedToSaver() && grid.addNextPathway(start, end)) {
final WriteBuffer sucess = new WriteBuffer();
sucess.putEnumValue(SignalBoxNetwork.ADDED_TO_SAVER);
sucess.putEnumValue(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public static void loadNames(final List<StateLoadHolder> infos, final @Nullable
return;
String name;
synchronized (ALL_NAMES) {
name = ALL_NAMES.getOrDefault(info, "");
name = ALL_NAMES.getOrDefault(info.info, "");
}
if (name.isEmpty())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private void tryNextPathways() {
entry.getKey().writeNetwork(buffer);
entry.getValue().writeNetwork(buffer);
OpenSignalsMain.network.sendTo(tile.get(0).getPlayer(), buffer);
return true;
}
return false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static PathwayRequestResult requestPathway(final Map<Point, SignalBoxNode
for (final PathIdentifier pathIdent : nextNode.toPathIdentifier()) {
checker.path = pathIdent.path;
result = checker.check();
if (nextPoint.equals(p2) || result == PathwayRequestResult.PASS) {
if (nextPoint.equals(p2) || result.isPass()) {
scores.put(pathIdent, getCosts(pathIdent.getMode(), nextNode, nextPoint, p2));
closedList.put(nextPoint, previousPoint);
visited.add(pathIdent.path);
Expand All @@ -153,21 +153,30 @@ public static PathwayRequestResult requestPathway(final Map<Point, SignalBoxNode
return result;
}

private static final int MAX_COSTS = 100000;

private static double getCosts(final ModeSet mode, final SignalBoxNode currentNode,
final Point currentPoint, final Point endPoint) {
final double costs = calculateHeuristic(currentPoint, endPoint)
+ currentNode.getOption(mode).get().getEntry(PathEntryType.PATHWAY_COSTS)
.orElse(getDefaultCosts(mode));
return costs;
return calculateHeuristic(currentPoint, endPoint) + currentNode.getOption(mode).get()
.getEntry(PathEntryType.PATHWAY_COSTS).orElse(getDefaultCosts(mode));
}

public static int getDefaultCosts(final ModeSet mode) {
final EnumGuiMode guiMode = mode.mode;
if (guiMode == EnumGuiMode.STRAIGHT)
return 0;
if (guiMode == EnumGuiMode.CORNER)
return 1;
return Integer.MAX_VALUE;
switch (guiMode) {
case STRAIGHT:
case END:
case IN_CONNECTION:
case OUT_CONNECTION: {
return 0;
}
case CORNER: {
return 1;
}
default: {
return MAX_COSTS;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void requestPathway() {
} else {
final PathwayRequestResult result =
grid.requestWay(pathway.getKey(), pathway.getValue());
if (!result.isPass() && result.isPathwayPossibleButCurrentyBlocked() && addPWToSaver) {
if (!result.isPass() && result.canBeAddedToSaver() && addPWToSaver) {
grid.addNextPathway(pathway.getKey(), pathway.getValue());
}
}
Expand Down

0 comments on commit 988e6ee

Please sign in to comment.