Refactor smart underground belt logic

This commit is contained in:
tobspr 2020-06-22 12:48:35 +02:00
parent d452234c72
commit f204189fdb
3 changed files with 38 additions and 12 deletions

View File

@ -4,6 +4,7 @@ export const CHANGELOG = [
date: "unreleased", date: "unreleased",
entries: [ entries: [
"Allow configuring autosave interval and disabling it in the settings", "Allow configuring autosave interval and disabling it in the settings",
"The smart-tunnel placement has been reworked to properly replace belts. Thus the setting has been turned on again by default",
"The soundtrack now has a higher quality on the standalone version than the web version", "The soundtrack now has a higher quality on the standalone version than the web version",
"Add setting to disable cut/delete warnings (by hexy)", "Add setting to disable cut/delete warnings (by hexy)",
"Fix bug where belts in blueprints don't orient correctly (by hexy)", "Fix bug where belts in blueprints don't orient correctly (by hexy)",

View File

@ -77,6 +77,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
const tier = undergroundComp.tier; const tier = undergroundComp.tier;
const range = globalConfig.undergroundBeltMaxTilesByTier[tier]; const range = globalConfig.undergroundBeltMaxTilesByTier[tier];
// FIND ENTRANCE
// Search for the entrance which is furthes apart (this is why we can't reuse logic here) // Search for the entrance which is furthes apart (this is why we can't reuse logic here)
let matchingEntrance = null; let matchingEntrance = null;
for (let i = 0; i < range; ++i) { for (let i = 0; i < range; ++i) {
@ -104,31 +105,49 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
return; return;
} }
// Remove any belts between entrance and exit which have the same direction // DETECT OBSOLETE BELTS BETWEEN
// Remove any belts between entrance and exit which have the same direction,
// but only if they *all* have the right direction
currentPos = tile.copy(); currentPos = tile.copy();
let allBeltsMatch = true;
for (let i = 0; i < matchingEntrance.range; ++i) { for (let i = 0; i < matchingEntrance.range; ++i) {
currentPos.addInplace(offset); currentPos.addInplace(offset);
const contents = this.root.map.getTileContent(currentPos); const contents = this.root.map.getTileContent(currentPos);
if (!contents) { if (!contents) {
continue; allBeltsMatch = false;
break;
} }
const contentsStaticComp = contents.components.StaticMapEntity; const contentsStaticComp = contents.components.StaticMapEntity;
const contentsBeltComp = contents.components.Belt; const contentsBeltComp = contents.components.Belt;
if (!contentsBeltComp) {
allBeltsMatch = false;
break;
}
if (contentsBeltComp) { // It's a belt
// It's a belt if (
if ( contentsBeltComp.direction !== enumDirection.top ||
contentsBeltComp.direction === enumDirection.top && enumAngleToDirection[contentsStaticComp.rotation] !== direction
enumAngleToDirection[contentsStaticComp.rotation] === direction ) {
) { allBeltsMatch = false;
// It's same rotation, drop it break;
this.root.logic.tryDeleteBuilding(contents);
}
} }
} }
currentPos = tile.copy();
if (allBeltsMatch) {
// All belts between this are obsolete, so drop them
for (let i = 0; i < matchingEntrance.range; ++i) {
currentPos.addInplace(offset);
const contents = this.root.map.getTileContent(currentPos);
assert(contents, "Invalid smart underground belt logic");
this.root.logic.tryDeleteBuilding(contents);
}
}
// REMOVE OBSOLETE TUNNELS
// Remove any double tunnels, by checking the tile plus the tile above // Remove any double tunnels, by checking the tile plus the tile above
currentPos = tile.copy().add(offset); currentPos = tile.copy().add(offset);
for (let i = 0; i < matchingEntrance.range - 1; ++i) { for (let i = 0; i < matchingEntrance.range - 1; ++i) {

View File

@ -468,7 +468,7 @@ export class ApplicationSettings extends ReadWriteProxy {
} }
getCurrentVersion() { getCurrentVersion() {
return 15; return 16;
} }
/** @param {{settings: SettingsStorage, version: number}} data */ /** @param {{settings: SettingsStorage, version: number}} data */
@ -530,6 +530,12 @@ export class ApplicationSettings extends ReadWriteProxy {
data.version = 15; data.version = 15;
} }
if (data.version < 16) {
// RE-ENABLE this setting, it already existed
data.settings.enableTunnelSmartplace = true;
data.version = 16;
}
return ExplainedResult.good(); return ExplainedResult.good();
} }
} }