Skip to content

Commit 2f5a85a

Browse files
committed
Preliminary fix for bridge-based landscape objects
1 parent 589853d commit 2f5a85a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/game-engine/world/map/chunk-manager.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export class Tile {
2626
}
2727

2828
export interface MapRegion {
29-
tiles: Tile[];
3029
objects: LandscapeObject[];
3130
mapFile: MapFile;
3231
}
@@ -101,25 +100,30 @@ export class ChunkManager {
101100
logger.error(`Error decoding landscape file ${mapRegionX},${mapRegionY}`);
102101
}
103102

104-
const region: MapRegion = { mapFile, tiles: [],
105-
objects: landscapeFile?.landscapeObjects || [] };
103+
const region: MapRegion = { mapFile, objects: landscapeFile?.landscapeObjects || [] };
106104

107105
this.regionMap.set(key, region);
108-
this.registerObjects(region.objects, region.tiles || []);
106+
this.registerObjects(region.objects, mapFile);
109107
}
110108

111-
public registerObjects(objects: LandscapeObject[], tiles: Tile[]): void {
109+
public registerObjects(objects: LandscapeObject[], mapFile: MapFile): void {
112110
if(!objects || objects.length === 0) {
113111
return;
114112
}
115113

114+
const mapWorldPositionX = (mapFile.regionX & 0xff) * 64;
115+
const mapWorldPositionY = mapFile.regionY * 64;
116+
116117
for(const object of objects) {
117118
const position = new Position(object.x, object.y, object.level);
118-
119-
if(tiles.some(tile => (tile?.settings & 0x2) === 2 &&
120-
tile?.x === object.x && tile?.y === object.y && tile?.level >= object.level)) {
121-
// Object is on or underneath a bridge tile and needs to move down one level
122-
position.move(object.x, object.y, object.level - 1);
119+
const localX = object.x - mapWorldPositionX;
120+
const localY = object.y - mapWorldPositionY;
121+
122+
for(let level = 3; level >= 0; level--) {
123+
if((mapFile.tileSettings[level][localX][localY] & 0x2) === 2) {
124+
// Object is on or underneath a bridge tile and needs to move down one level
125+
position.move(object.x, object.y, object.level - 1);
126+
}
123127
}
124128

125129
this.getChunkForWorldPosition(position).setFilestoreLandscapeObject(object);

0 commit comments

Comments
 (0)