From 8064980e5bb1d5fdd0381eb935e3aa0d70bcab5a Mon Sep 17 00:00:00 2001 From: Obique Date: Sat, 19 Jul 2014 15:49:04 -0500 Subject: [PATCH] Fixed resource and survey system --- .../swg/ResourceListForSurveyMessage.java | 2 + .../objects/resource/GalacticResource.java | 104 +++++++------ src/services/SurveyService.java | 31 +++- src/services/resources/ResourceService.java | 137 +++++++++--------- 4 files changed, 147 insertions(+), 127 deletions(-) diff --git a/src/protocol/swg/ResourceListForSurveyMessage.java b/src/protocol/swg/ResourceListForSurveyMessage.java index e46b8f39..a7dd2b68 100644 --- a/src/protocol/swg/ResourceListForSurveyMessage.java +++ b/src/protocol/swg/ResourceListForSurveyMessage.java @@ -67,6 +67,8 @@ public class ResourceListForSurveyMessage extends SWGMessage { if (toolName.equals("survey_tool_liquid")) generalType = (byte) 7; + if (core.resourceService == null) + System.out.println("heyyyy guess who's confused?!"); List planetVector = core.resourceService.getSpawnedResourcesByPlanetAndType(surveyor.getPlanetId(),generalType); resourceList = new ArrayList(planetVector); diff --git a/src/resources/objects/resource/GalacticResource.java b/src/resources/objects/resource/GalacticResource.java index cff11776..93977915 100644 --- a/src/resources/objects/resource/GalacticResource.java +++ b/src/resources/objects/resource/GalacticResource.java @@ -137,13 +137,21 @@ public class GalacticResource extends SWGObject implements Serializable { private transient double minDist = 99999.0; - public GalacticResource(){ + public GalacticResource() { super(); + createResourceName(); } public GalacticResource(long objectID, Planet planet, Point3D position, Quaternion orientation, String template){ super(objectID, planet, position, orientation, template); this.id = objectID; + createResourceName(); + } + + private void createResourceName() { + this.name = NAME_SYLLABLE_1[(int) new Random().nextInt(NAME_SYLLABLE_1.length-1)] + + NAME_SYLLABLE_2[(int) new Random().nextInt(NAME_SYLLABLE_2.length-1)] + + NAME_SYLLABLE_3[(int) new Random().nextInt(NAME_SYLLABLE_3.length-1)]; } public GalacticResource(long id){ @@ -155,8 +163,8 @@ public class GalacticResource extends SWGObject implements Serializable { init(); } - public GalacticResource(String name, String fileName, String category){ - this.name = name; + public GalacticResource(String fileName, String category){ + createResourceName(); this.fileName = fileName; this.category = category; //this.type = type; @@ -177,10 +185,6 @@ public class GalacticResource extends SWGObject implements Serializable { return name; } - public void setName(String name){ - this.name = name; - } - public String getFileName(){ return fileName; } @@ -211,10 +215,9 @@ public class GalacticResource extends SWGObject implements Serializable { return false; } - public void initializeNewGalaxyResource(Vector completeResourceNameHistory){ + public void initializeNewGalaxyResource(){ galacticDepositList.clear(); - constructResourceName(completeResourceNameHistory); generateResourceType(); generateResourceStats(); generatePlanetarySpawns(); @@ -274,17 +277,18 @@ public class GalacticResource extends SWGObject implements Serializable { } public int[] generateRandomPlanetArray(){ - int planets = 6 + new Random().nextInt(2); - int[] outpool = new int[planets]; - int[] pool = new int[10]; // 10 Number of SWG planets - for (int i = 0; i < 10; i++) pool[i] = i+1; - for (int i = 0; i < planets; i++) outpool[i] = i+1; - shuffleArray(pool); - for (int i = 0; i < outpool.length; i++) - { - outpool[i]=pool[i]; - } - return outpool; +// int planets = 6 + new Random().nextInt(2); +// int[] outpool = new int[planets]; +// int[] pool = new int[10]; // 10 Number of SWG planets +// for (int i = 0; i < 10; i++) pool[i] = i+1; +// for (int i = 0; i < planets; i++) outpool[i] = i+1; +// shuffleArray(pool); +// for (int i = 0; i < outpool.length; i++) +// { +// outpool[i]=pool[i]; +// } +// return outpool; + return new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; } public void shuffleArray(int[] ar) @@ -325,20 +329,36 @@ public class GalacticResource extends SWGObject implements Serializable { // Calculate deposit positions Random generator = new Random(); - int depositQuantity = 8 + generator.nextInt(24); + int depositQuantity = 20; +// int depositQuantity = 100; // datatables/clientregion -> cities for (int i = 0; i < depositQuantity; i++) { ResourceDeposit deposit = new ResourceDeposit(); generator = new Random(); // Exclude mountains at the edge of the maps - int spawnCoordsX = generator.nextInt(15000) - 7500; - int spawnCoordsZ = generator.nextInt(15000) - 7500; + int spawnCoordsX = 0; + int spawnCoordsZ = 0; + for (int k = 0; k < 10; k++) { + spawnCoordsX = generator.nextInt(15000) - 7500; + spawnCoordsZ = generator.nextInt(15000) - 7500; + boolean works = true; + for (ResourceDeposit r : depositList) { + double dist = Math.pow(r.getSpawnCoordinatesX()-spawnCoordsX, 2); + dist += Math.pow(r.getSpawnCoordinatesZ()-spawnCoordsZ, 2); + dist = Math.sqrt(dist); + if (dist < 1500) { + works = false; + break; + } + } + if (works) + break; + } // check maybe for: if (!core.terrainService.isWater(player.getPlanetId(), spawnCoordsX, spawnCoordsZ)) ? - generator = new Random(); int spawnConcentration = 30 + generator.nextInt(70); - generator = new Random(); - int spawnRadius = 360 + generator.nextInt(1200-360); +// int spawnRadius = 360 + generator.nextInt(1200-360); + int spawnRadius = 1500 + generator.nextInt(1000); deposit.setSpawnRadius(spawnRadius); deposit.setSpawnConcentration(spawnConcentration); //System.out.println("spawnConcentration " + spawnConcentration); @@ -348,7 +368,7 @@ public class GalacticResource extends SWGObject implements Serializable { } return depositList; } - + public float deliverConcentrationForSurvey(int planetId, float coordsX, float coordsY) { float measuredOutput = 0; for (int i = 0; i < galacticDepositList.size(); i++) { @@ -359,7 +379,7 @@ public class GalacticResource extends SWGObject implements Serializable { ResourceDeposit resourceDeposit = depositList.get(j); int spawnCoordsX = (int)resourceDeposit.getSpawnCoordinatesX(); int spawnCoordsZ = (int)resourceDeposit.getSpawnCoordinatesZ(); - int spawnRadius = (int)resourceDeposit.getSpawnRadius(); + float spawnRadius = resourceDeposit.getSpawnRadius(); float deltaX = coordsX-spawnCoordsX; float deltaY = coordsY-spawnCoordsZ; float localConcentration=0; @@ -368,7 +388,8 @@ public class GalacticResource extends SWGObject implements Serializable { minDist = hypothen; if (hypothenmeasuredOutput) { measuredOutput=localConcentration; } @@ -460,18 +481,6 @@ public class GalacticResource extends SWGObject implements Serializable { return minDist; } - public void constructResourceName(Vector completeResourceNameHistory){ - // ToDo: This is where the database check for past names must be added - boolean check=true; - while(check) - { - this.name = NAME_SYLLABLE_1[(int) new Random().nextInt(NAME_SYLLABLE_1.length-1)] - + NAME_SYLLABLE_2[(int) new Random().nextInt(NAME_SYLLABLE_2.length-1)] - + NAME_SYLLABLE_3[(int) new Random().nextInt(NAME_SYLLABLE_3.length-1)]; - check = completeResourceNameHistory.contains(this.name); - } - } - public Vector getGalacticDepositList(){ return galacticDepositList; } @@ -668,19 +677,6 @@ public class GalacticResource extends SWGObject implements Serializable { this.getresourceType = getresourceType; } - public GalacticResource convertToHistoricResource(){ - GalacticResource historicResource = new GalacticResource(); - historicResource.setName(this.getName()); - historicResource.setResourceClass(this.getResourceClass()); - historicResource.setResourceStats(this.getResourceStats()); - historicResource.setResourceType(this.getResourceType()); - historicResource.setGeneralType(this.getGeneralType()); - historicResource.setId(this.getId()); - historicResource.setIffFileName(this.getIffFileName()); - - return historicResource; - } - @Override public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { // TODO Auto-generated method stub diff --git a/src/services/SurveyService.java b/src/services/SurveyService.java index 030a85ff..008ad3a7 100644 --- a/src/services/SurveyService.java +++ b/src/services/SurveyService.java @@ -35,6 +35,7 @@ import resources.harvest.SurveyTool; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; import resources.objects.resource.GalacticResource; +import resources.objects.resource.ResourceConcentration; import resources.objects.resource.ResourceContainerObject; import resources.objects.resource.ResourceRoot; import resources.objects.tangible.TangibleObject; @@ -323,7 +324,35 @@ public class SurveyService implements INetworkDispatch { PlayClientEffectLocMessage cEffMsg = new PlayClientEffectLocMessage(effectFile,crafter.getPlanet().getName(),crafter.getPosition()); crafter.getClient().getSession().write(cEffMsg.serialize()); crafter.sendSystemMessage("You begin to survey for " + commandArgs, (byte) 0); - + + float surveyRadius = 64.0f; + int surveyToolRangeSetting = surveyTool.getSurveyRangeSetting(); + //surveyToolRangeSetting = 4; + int divisor = 0; + if (surveyToolRangeSetting==0) { + divisor = 2; + surveyRadius = 64.0f; + } else if (surveyToolRangeSetting==1) { + divisor = 3; + surveyRadius = 128.0f; + } else if (surveyToolRangeSetting==2) { + divisor = 3; + surveyRadius = 192.0f; + } else if (surveyToolRangeSetting==3) { + divisor = 4; + surveyRadius = 256.0f; + } else if (surveyToolRangeSetting==4) { + divisor = 4; + surveyRadius = 320.0f; + } else { + divisor = 5; + surveyRadius = 3072.0f; + } + + float differential = surveyRadius / (float) divisor; + GalacticResource resourceToSurvey = resource; + Vector concentrationMap = resourceToSurvey.buildConcentrationsCollection(crafter.getPosition(),resourceToSurvey, surveyRadius, differential, crafter.getPlanetId()); + resourceToSurvey.constructSurveyMapMessage(crafter, concentrationMap, surveyRadius); } public void requestSampling(CreatureObject crafter, SWGObject target, String commandArgs){ diff --git a/src/services/resources/ResourceService.java b/src/services/resources/ResourceService.java index 00ca528e..92a602ad 100644 --- a/src/services/resources/ResourceService.java +++ b/src/services/resources/ResourceService.java @@ -52,11 +52,6 @@ import resources.objects.resource.ResourceContainerObject; import resources.objects.resource.ResourceRoot; import services.ai.AIActor; -/** - * @author Charon - */ - -@SuppressWarnings("unused") public class ResourceService implements INetworkDispatch { private NGECore core; @@ -115,10 +110,6 @@ public class ResourceService implements INetworkDispatch { // createCollections2(); // createCollections3(); // } else { - ODBCursor cursor = core.getResourceRootsODB().getCursor(); - if (!cursor.hasNext()) { - loadFromTextFile(); - } // } core.commandService.registerCommand("harvestcorpse"); core.commandService.registerCommand("milkcreature"); @@ -132,59 +123,60 @@ public class ResourceService implements INetworkDispatch { // loads the resource roots at server start public void loadResourceRoots() { - ODBCursor cursor = core.getResourceRootsODB().getCursor(); - int loadedResourceRootsCounter = 0; - System.out.println("Loading resource roots..."); - while (cursor.hasNext()) { - final ResourceRoot resourceRoot = (ResourceRoot) cursor.next(); - System.err.println("resourceRoot loaded ID: " + resourceRoot.getResourceRootID() + " " + resourceRoot.getResourceFileName()); - createResource(ResourceClass.forString(resourceRoot.getResourceFileName()), resourceRoot); - loadedResourceRootsCounter++; - } - - if (loadedResourceRootsCounter == 0) { - // big bang will take care of it - } - // System.err.println("loadedResourceRootsCounter " + - // loadedResourceRootsCounter); - cursor.close(); - System.out.println("Finished loading resource roots."); +// ODBCursor cursor = core.getResourceRootsODB().getCursor(); +// int loadedResourceRootsCounter = 0; +// System.out.println("Loading resource roots..."); +// while (cursor.hasNext()) { +// final ResourceRoot resourceRoot = (ResourceRoot) cursor.next(); +// System.err.println("resourceRoot loaded ID: " + resourceRoot.getResourceRootID() + " " + resourceRoot.getResourceFileName()); +// createResource(ResourceClass.forString(resourceRoot.getResourceFileName()), resourceRoot); +// loadedResourceRootsCounter++; +// } +// +// if (loadedResourceRootsCounter == 0) { +// // big bang will take care of it +// } +// // System.err.println("loadedResourceRootsCounter " + +// // loadedResourceRootsCounter); +// cursor.close(); +// System.out.println("Finished loading resource roots."); } // loads the currently spawned resources at server start public void loadResources() { - ODBCursor cursor = core.getResourcesODB().getCursor(); - int loadedResourceCounter = 0; - System.out.println("Loading resources..."); - while (cursor.hasNext()) { - final GalacticResource resource = (GalacticResource) cursor.next(); - System.out.println("Resource: " + resource.getName() + " rootID " + resource.getResourceRootID()); - core.objectService.getObjectList().put(resource.getId(), resource); - - // re-reference ResourceRoot - int resourceRootID = resource.getResourceRootID(); - ResourceRoot resourceRoot = resourceRootTable.get(resourceRootID); - resource.setResourceRoot(resourceRoot); - - // recreate the collections - addSpawnedResource(resource); - byte pool = resource.getPoolNumber(); - if (poolResources.containsKey(pool)) - poolResources.get(pool).add(resource); - else { - System.err.println("Loaded resource " + resource.getName() + " has no valid pool value!"); - resource.setPoolNumber((byte) 4); // Make it a pool 4 - } - - loadedResourceCounter++; - } - - if (loadedResourceCounter == 0) { - kickOffBigBang(); // spawn resources initially once - } - - cursor.close(); - System.out.println("Finished loading resources."); + loadFromTextFile(); +// ODBCursor cursor = core.getResourcesODB().getCursor(); +// int loadedResourceCounter = 0; +// System.out.println("Loading resources..."); +// while (cursor.hasNext()) { +// final GalacticResource resource = (GalacticResource) cursor.next(); +// System.out.println("Resource: " + resource.getName() + " rootID " + resource.getResourceRootID()); +// core.objectService.getObjectList().put(resource.getId(), resource); +// +// // re-reference ResourceRoot +// int resourceRootID = resource.getResourceRootID(); +// ResourceRoot resourceRoot = resourceRootTable.get(resourceRootID); +// resource.setResourceRoot(resourceRoot); +// +// // recreate the collections +// addSpawnedResource(resource); +// byte pool = resource.getPoolNumber(); +// if (poolResources.containsKey(pool)) +// poolResources.get(pool).add(resource); +// else { +// System.err.println("Loaded resource " + resource.getName() + " has no valid pool value!"); +// resource.setPoolNumber((byte) 4); // Make it a pool 4 +// } +// +// loadedResourceCounter++; +// } +// +// if (loadedResourceCounter == 0) { +// kickOffBigBang(); // spawn resources initially once +// } +// +// cursor.close(); +// System.out.println("Finished loading resources."); } public SWGObject createResource() { @@ -233,7 +225,7 @@ public class ResourceService implements INetworkDispatch { SEDIMENTARY_ORE("Sedimentary Ore"), IGNEOUS_ORE("Igneous Ore"), GEMSTONE("Gemstone"), - PETRO_FUEL("Petro Fuel"), + PETRO_FUEL("Petro Fuel"), OIL("Oil"), INERT_GAS("Inert Gas"), WATER_VAPOR("Water Vapor"), @@ -326,6 +318,7 @@ public class ResourceService implements INetworkDispatch { resourceRoot.setMaximalLifeTime(maxLife); System.out.println("Created Resource: " + fileName + ". Class: " + rClass.getName() + " Type: " + type); createResource(rClass, resourceRoot); + spawnResource(1, resourceRoot); } private void loadFromTextFile() { @@ -634,30 +627,30 @@ public class ResourceService implements INetworkDispatch { return roots.get((int) (Math.random() * roots.size())); } - private GalacticResource spawnResource(int pool, ResourceRoot root) { - return spawnResource(pool, root, -1); + private void spawnResource(int pool, ResourceRoot root) { + spawnResource(pool, root, -1); } - private GalacticResource spawnResource(int pool, ResourceRoot root, int planetId) { + private void spawnResource(int pool, ResourceRoot root, int planetId) { GalacticResource resource = (GalacticResource) createResource(); if (root == null) - return resource; + return; try { resource.setResourceRoot(root); resource.setPoolNumber((byte) pool); if (planetId != -1) resource.setPlanetID(planetId); - resource.initializeNewGalaxyResource(completeResourceNameHistory); + resource.initializeNewGalaxyResource(); - core.getResourcesODB().put(resource.getObjectID(), resource); - - if (enableResourceHistory) { - GalacticResource historicResource = resource.convertToHistoricResource(); - core.getResourceHistoryODB().put(historicResource.getObjectID(), historicResource); - } +// core.getResourcesODB().put(resource.getObjectID(), resource); +// +// if (enableResourceHistory) { +// GalacticResource historicResource = resource.convertToHistoricResource(); +// core.getResourceHistoryODB().put(historicResource.getObjectID(), historicResource); +// } completeResourceNameHistory.add(resource.getName()); - allSpawnedResources.add(resource); + addSpawnedResource(resource); totalSpawnedResourcesNumber++; } catch (Exception e) { System.err.println("Error in spawning resource: " + root.getResourceFileName()); @@ -665,7 +658,7 @@ public class ResourceService implements INetworkDispatch { System.err.println(" On Planet: " + planetId); e.printStackTrace(); } - return resource; + return; } public GalacticResource grabResourceByName(String searchName) {