From 4299b2742203b548c92cadc12d2a23ac12f2fbd4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 27 Oct 2026 19:28:58 -0400 Subject: [PATCH] Build zone templates from CZONE instead of static_zone_templates ZoneManager._zone_templates now holds the parser's CZoneTemplate: every CZONE template plus the player-city template 0, still built in code. Zone and Terrain read the mbEnums sea level and terrain types instead of strings. The static_zone_templates loader goes with the old map type; the table stays until Task 4.2. Parity: all 861 templates, every column the server read (type, name, peace, radii, blends, sea level and type, water, terrain gen, type, max_y, image) identical to the JSON. Value changes: none. Co-Authored-By: Claude Opus 5.5 --- src/engine/InterestManagement/Terrain.java | 11 ++++--- src/engine/db/handlers/dbZoneHandler.java | 36 ---------------------- src/engine/devcmd/cmds/GetHeightCmd.java | 6 ++-- src/engine/gameManager/ZoneManager.java | 27 ++++++++++++++-- src/engine/objects/Zone.java | 23 +++++++------- src/engine/server/world/WorldServer.java | 5 ++- 6 files changed, 48 insertions(+), 60 deletions(-) diff --git a/src/engine/InterestManagement/Terrain.java b/src/engine/InterestManagement/Terrain.java index af69867d..b70fa6a3 100644 --- a/src/engine/InterestManagement/Terrain.java +++ b/src/engine/InterestManagement/Terrain.java @@ -11,6 +11,7 @@ package engine.InterestManagement; import engine.gameManager.ZoneManager; import engine.math.Vector2f; import engine.math.Vector3fImmutable; +import engine.mbEnums; import engine.objects.Zone; import org.pmw.tinylog.Logger; @@ -46,7 +47,7 @@ public class Terrain { // Configure PLANAR zones to use the same 16x16 pixel image // that all similar terrains share. (See JSON) - if (this.zone.template.terrain_type.equals("PLANAR")) + if (this.zone.template.terrain_type == mbEnums.TerrainGenType.PLANAR) this.heightmap = 1006300; // all 0 // Load pixel data for this terrain from cache @@ -71,8 +72,8 @@ public class Terrain { // the blending area between child and parent terrains when // they are stitched together. - this.blend_values.x = this.zone.template.max_blend; - this.blend_values.y = this.zone.template.min_blend; + this.blend_values.x = this.zone.template.zone_max_blend; + this.blend_values.y = this.zone.template.zone_min_blend; Vector2f major_blend = new Vector2f(this.blend_values.x / this.zone.major_radius, this.blend_values.y / this.zone.major_radius); @@ -217,8 +218,8 @@ public class Terrain { // Normalize terrain offset - Vector2f normalizedOffset = new Vector2f(Math.abs(zone_offset.x) / this.zone.template.major_radius, - Math.abs(zone_offset.y) / this.zone.template.minor_radius); + Vector2f normalizedOffset = new Vector2f(Math.abs(zone_offset.x) / this.zone.template.zone_major_radius, + Math.abs(zone_offset.y) / this.zone.template.zone_minor_radius); float blendCoefficient; diff --git a/src/engine/db/handlers/dbZoneHandler.java b/src/engine/db/handlers/dbZoneHandler.java index d5314a25..af0db2ad 100644 --- a/src/engine/db/handlers/dbZoneHandler.java +++ b/src/engine/db/handlers/dbZoneHandler.java @@ -10,10 +10,8 @@ package engine.db.handlers; import engine.gameManager.DbManager; -import engine.gameManager.ZoneManager; import engine.mbEnums; import engine.objects.Zone; -import engine.objects.ZoneTemplate; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -68,40 +66,6 @@ public class dbZoneHandler extends dbHandlerBase { return zone; } - public void LOAD_ALL_ZONE_TEMPLATES() { - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_zone_templates")) { - - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - ZoneTemplate zoneTemplate = new ZoneTemplate(rs); - ZoneManager._zone_templates.put(zoneTemplate.templateID, zoneTemplate); - } - - // Add player city - - ZoneTemplate zoneTemplate = new ZoneTemplate(); - - zoneTemplate.templateID = 0; - zoneTemplate.sea_level_type = "PARENT"; - zoneTemplate.sea_level = 0; - zoneTemplate.max_blend = 128; - zoneTemplate.min_blend = 128; - zoneTemplate.terrain_max_y = 5; - zoneTemplate.major_radius = (int) mbEnums.CityBoundsType.ZONE.halfExtents; - zoneTemplate.minor_radius = (int) mbEnums.CityBoundsType.ZONE.halfExtents; - zoneTemplate.terrain_type = "PLANAR"; - - ZoneManager._zone_templates.put(zoneTemplate.templateID, zoneTemplate); - - } catch (SQLException e) { - Logger.error(e); - } - - } - public boolean DELETE_ZONE(final Zone zone) { if (DbManager.refuseStaticWrite(zone)) diff --git a/src/engine/devcmd/cmds/GetHeightCmd.java b/src/engine/devcmd/cmds/GetHeightCmd.java index ead2e2f6..832e8533 100644 --- a/src/engine/devcmd/cmds/GetHeightCmd.java +++ b/src/engine/devcmd/cmds/GetHeightCmd.java @@ -37,8 +37,8 @@ public class GetHeightCmd extends AbstractDevCmd { Vector2f childZoneLoc = ZoneManager.worldToTerrainSpace(playerCharacter.getLoc(), heightmapZone); Vector2f childZoneOffset = ZoneManager.worldToZoneOffset(playerCharacter.getLoc(), heightmapZone); - Vector2f normalizedOffset = new Vector2f(Math.abs(childZoneOffset.x) / heightmapZone.template.major_radius, - Math.abs(childZoneOffset.y) / heightmapZone.template.minor_radius); + Vector2f normalizedOffset = new Vector2f(Math.abs(childZoneOffset.x) / heightmapZone.template.zone_major_radius, + Math.abs(childZoneOffset.y) / heightmapZone.template.zone_minor_radius); Vector2f parentZoneLoc = ZoneManager.worldToTerrainSpace(playerCharacter.getLoc(), parentZone); float childHeight = heightmapZone.terrain.getInterpolatedTerrainHeight(childZoneLoc); @@ -74,7 +74,7 @@ public class GetHeightCmd extends AbstractDevCmd { this.throwbackInfo(playerCharacter, "Child Zone Offset: " + "[" + childZoneOffset.x + "]" + "[" + childZoneOffset.y + "]"); this.throwbackInfo(playerCharacter, "Normalized offset: " + "[" + normalizedOffset.x + "]" + "[" + normalizedOffset.y + "]"); - this.throwbackInfo(playerCharacter, "template blend Values: (max/min): " + heightmapZone.template.max_blend + " /" + heightmapZone.template.min_blend); + this.throwbackInfo(playerCharacter, "template blend Values: (max/min): " + heightmapZone.template.zone_max_blend + " /" + heightmapZone.template.zone_min_blend); this.throwbackInfo(playerCharacter, "terrain values (max/min): " + heightmapZone.terrain.blend_values.x + " /" + heightmapZone.terrain.blend_values.y); this.throwbackInfo(playerCharacter, "Blend coefficient: " + heightmapZone.terrain.getTerrainBlendCoefficient(childZoneOffset)); diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 4b24073f..5653c0c1 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -17,7 +17,7 @@ import engine.mbEnums; import engine.objects.Building; import engine.objects.City; import engine.objects.Zone; -import engine.objects.ZoneTemplate; +import engine.parsers.objects.CZoneTemplate; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -36,7 +36,7 @@ public enum ZoneManager { ZONEMANAGER; - public static HashMap _zone_templates = new HashMap<>(); + public static HashMap _zone_templates = new HashMap<>(); public static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); @@ -51,6 +51,29 @@ public enum ZoneManager { /* Instance variables */ public static Zone seaFloor = null; + // CZONE templates plus the server's player-city template 0, which has no CZONE file + + public static void loadZoneTemplates() { + + CZoneTemplate playerCityTemplate = new CZoneTemplate(); + + _zone_templates.putAll(CZoneTemplate._zones); + + playerCityTemplate.template_id = 0; + playerCityTemplate.zone_sea_level_type = mbEnums.SeaLevelType.PARENT; + playerCityTemplate.zone_sea_level = 0; + playerCityTemplate.zone_max_blend = 128; + playerCityTemplate.zone_min_blend = 128; + playerCityTemplate.terrain_max_y = 5; + playerCityTemplate.zone_major_radius = (int) mbEnums.CityBoundsType.ZONE.halfExtents; + playerCityTemplate.zone_minor_radius = (int) mbEnums.CityBoundsType.ZONE.halfExtents; + playerCityTemplate.terrain_type = mbEnums.TerrainGenType.PLANAR; + + _zone_templates.put(playerCityTemplate.template_id, playerCityTemplate); + + Logger.info("Zone templates: " + _zone_templates.size()); + } + // Find all zones coordinates fit into, starting with Sea Floor public static ArrayList getAllZonesIn(final Vector3fImmutable loc) { diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 65aea255..725bb00a 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -17,6 +17,7 @@ import engine.math.Vector2f; import engine.math.Vector3fImmutable; import engine.mbEnums; import engine.net.ByteBufferWriter; +import engine.parsers.objects.CZoneTemplate; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -33,7 +34,7 @@ public class Zone extends AbstractWorldObject { public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public ZoneTemplate template; + public CZoneTemplate template; public final int playerCityUUID; public final String zoneName; @@ -168,14 +169,14 @@ public class Zone extends AbstractWorldObject { this.minor_radius = mbEnums.CityBoundsType.ZONE.halfExtents; this.major_radius = mbEnums.CityBoundsType.ZONE.halfExtents; } else { - this.minor_radius = this.template.minor_radius; - this.major_radius = this.template.major_radius; + this.minor_radius = this.template.zone_minor_radius; + this.major_radius = this.template.zone_major_radius; } this.setParent(); this.setBounds(); - if (this.template.terrain_type.equals("NONE")) + if (this.template.terrain_type == mbEnums.TerrainGenType.NONE) this.terrain = null; else this.terrain = new Terrain(this); @@ -244,15 +245,15 @@ public class Zone extends AbstractWorldObject { return; } - switch (this.template.sea_level_type) { - case "WORLD": - this.sea_level = world_sea_level + this.template.sea_level; + switch (this.template.zone_sea_level_type) { + case WORLD: + this.sea_level = world_sea_level + this.template.zone_sea_level; break; - case "PARENT": - this.sea_level = this.parent.sea_level + this.template.sea_level; + case PARENT: + this.sea_level = this.parent.sea_level + this.template.zone_sea_level; break; - case "SELF": - this.sea_level = this.global_height + this.template.sea_level; + case SELF: + this.sea_level = this.global_height + this.template.zone_sea_level; break; } } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index a2286729..18d7a29f 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -298,9 +298,6 @@ public class WorldServer { Logger.info("Initializing Errant Guild"); Guild.getErrantGuild(); - Logger.info("Loading zone template data"); - DbManager.ZoneQueries.LOAD_ALL_ZONE_TEMPLATES(); - Logger.info("Loading Compound Curves"); CompoundCurveTemplate._curves = CompoundCurveParser.parseCompoundCurvesFile(); @@ -440,6 +437,8 @@ public class WorldServer { exit(1); } + ZoneManager.loadZoneTemplates(); + Logger.info("Loading Rune Power Requirements"); PowerReq.loadRunePowers();