Loading of GCW region locations #29

This commit is contained in:
Ziggy
2020-03-20 19:01:16 +01:00
parent 295396e93a
commit afb3ac8a38
3 changed files with 100 additions and 2 deletions
@@ -56,7 +56,8 @@ abstract class DataLoader {
fun vehicles(): VehicleLoader = ServerData.vehicles
fun specialLines(): SpecialLineLoader = ServerData.specialLines
fun staticPvpZones(): StaticPvpZoneLoader = ServerData.staticPvpZones
fun gcwRegionLoader(): GcwRegionLoader = ServerData.gcwRegionLoader
}
}
@@ -0,0 +1,96 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.server_info.loader;
import com.projectswg.common.data.location.Terrain;
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class GcwRegionLoader extends DataLoader {
private final Map<Terrain, Collection<GcwRegionInfo>> regions;
public GcwRegionLoader() {
regions = new HashMap<>();
}
@NotNull
public Map<Terrain, Collection<GcwRegionInfo>> getRegionsByTerrain() {
return Collections.unmodifiableMap(regions);
}
@Override
public void load() throws IOException {
try (SdbLoader.SdbResultSet set = SdbLoader.load(new File("serverdata/nge/gcw/regions_gcw.sdb"))) {
while (set.next()) {
GcwRegionInfo regionInfo = new GcwRegionInfo(set);
regions.computeIfAbsent(regionInfo.getTerrain(), a -> new ArrayList<>()).add(regionInfo);
}
}
}
public static class GcwRegionInfo {
private final Terrain terrain;
private final String regionName;
private final long centerX;
private final long centerZ;
private final long radius;
public GcwRegionInfo(SdbLoader.SdbResultSet set) {
terrain = Terrain.getTerrainFromName(set.getText("terrain"));
regionName = set.getText("regionName");
centerX = set.getInt("centerX");
centerZ = set.getInt("centerZ");
radius = set.getInt("radius");
}
public Terrain getTerrain() {
return terrain;
}
public String getRegionName() {
return regionName;
}
public long getCenterX() {
return centerX;
}
public long getCenterZ() {
return centerZ;
}
public long getRadius() {
return radius;
}
}
}
@@ -92,7 +92,8 @@ object ServerData {
val travelCosts by SoftDataLoaderDelegate(::TravelCostLoader)
val vehicles by SoftDataLoaderDelegate(::VehicleLoader)
val staticPvpZones by SoftDataLoaderDelegate(::StaticPvpZoneLoader)
val gcwRegionLoader by SoftDataLoaderDelegate(::GcwRegionLoader)
private class WeakDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::WeakReference, loaderCreator)
private class SoftDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::SoftReference, loaderCreator)