include library.regions; include library.trial; const float GOOD_LOCATION_SEARCH_SIZE = 200; // we search in a square double this size const string[] PLANETS = {"tatooine", "naboo", "talus", "corellia", "yavin4", "dantooine", "dathomir", "lok", "rori", "endor"}; // all planets in the game const string NO_AREA = "no_area"; const string PLANET_LEVEL_TABLE = "datatables/spawning/planetary_data/planet_level.iff"; // how big is the region? this returns biggest size float getRegionExtents(region rgnTest) { // lower left is 0 , upper right is 1 // make sure to check for a circle location locLowerLeft = new location(); location locUpperRight = new location(); location[] locExtents = getRegionExtent(rgnTest); locLowerLeft = (location)locExtents[0].clone(); locUpperRight = (location)locExtents[1].clone(); LOG("mission", "Lower Left is "+locLowerLeft.toString()); LOG("mission", "Upper Right is "+locUpperRight.toString()); float fltXDistance = locUpperRight.x - locLowerLeft.x; // assuming my understanding of coords is right float fltZDistance = locUpperRight.z - locLowerLeft.z; // see above if(fltXDistance>fltZDistance) { LOG("mission", "fltXDistance returning with a value of "+fltXDistance); return fltXDistance; } else { LOG("mission", "fltZDistance returning with a value of "+fltZDistance); return fltZDistance; } } region getSmallestRegion(region[] rgnRegions) { if(rgnRegions==null) { return null; } if(rgnRegions.length==0) { return null; } region rgnSmallestRegion = rgnRegions[0]; float fltExtents = 1000000000; for(int intI = 0; intI0)) { region rgnCity = rgnCities[rand(0, rgnCities.length-1)]; LOG("locations", "rgnCity is "+rgnCity.getName()); return rgnCity; } else { return null; } } else { int intI = 0; string strStartName = rgnStartRegion.getName(); while(intI 2.0f) { result = getGoodLocation(radius, radius, lowerLeft, upperRight, false, false); radius = radius * 0.5f; } return result; } // gets a good location wrapped location getGoodLocationAroundLocation(location locSearchLocation, float fltXSize, float fltZSize, float fltXSearchSize, float fltZSearchSize) { location locLowerLeft = (location)locSearchLocation.clone(); locLowerLeft.x = locLowerLeft.x - fltXSearchSize; locLowerLeft.z = locLowerLeft.z - fltZSearchSize; LOG("mission", "locLowerLeft is "+locLowerLeft.toString()); location locUpperRight = (location)locSearchLocation.clone(); locUpperRight.x = locUpperRight.x + fltXSearchSize; locUpperRight.z = locUpperRight.z + fltZSearchSize; LOG("mission", "locUpperRight is "+locUpperRight.toString()); // this might spawn too close to the player.. we'll fix it later. location locGoodLocation = getGoodLocation( fltXSize, fltZSize, locLowerLeft, locUpperRight, false, false); return locGoodLocation; } location getGoodLocationAroundLocation(location locSearchLocation, float fltXSize, float fltZSize, float fltXSearchSize, float fltZSearchSize, boolean boolIgnoreWater, boolean boolIgnoreSlope) { location locLowerLeft = (location)locSearchLocation.clone(); locLowerLeft.x = locLowerLeft.x - fltXSearchSize; locLowerLeft.z = locLowerLeft.z - fltZSearchSize; LOG("mission", "locLowerLeft is "+locLowerLeft.toString()); location locUpperRight = (location)locSearchLocation.clone(); locUpperRight.x = locUpperRight.x + fltXSearchSize; locUpperRight.z = locUpperRight.z + fltZSearchSize; LOG("mission", "locUpperRight is "+locUpperRight.toString()); // this might spawn too close to the player.. we'll fix it later. location locGoodLocation = getGoodLocation( fltXSize, fltZSize, locLowerLeft, locUpperRight, boolIgnoreWater, boolIgnoreSlope); if(locGoodLocation==null) { LOG("DESIGNER_FATAL", "X search size is "+fltXSearchSize); LOG("DESIGNER_FATAL", "Z search size is "+fltZSearchSize); LOG("DESIGNER_FATAL", "size of thing is "+fltZSize); LOG("DESIGNER_FATAL", "Lower left is "+locLowerLeft); LOG("DESIGNER_FATAL", "Upper Right is "+locUpperRight); LOG("DESIGNER_FATAL", "Start location is "+locSearchLocation); } return locGoodLocation; } location getGoodLocationAroundLocationAvoidCollidables(location locSearchLocation, float fltXSize, float fltZSize, float fltXSearchSize, float fltZSearchSize, boolean boolIgnoreWater, boolean boolIgnoreSlope, float staticObjDistance) { location locLowerLeft = (location)locSearchLocation.clone(); locLowerLeft.x = locLowerLeft.x - fltXSearchSize; locLowerLeft.z = locLowerLeft.z - fltZSearchSize; LOG("mission", "locLowerLeft is "+locLowerLeft.toString()); location locUpperRight = (location)locSearchLocation.clone(); locUpperRight.x = locUpperRight.x + fltXSearchSize; locUpperRight.z = locUpperRight.z + fltZSearchSize; LOG("mission", "locUpperRight is "+locUpperRight.toString()); // this might spawn too close to the player.. we'll fix it later. location locGoodLocation = getGoodLocationAvoidCollidables( fltXSize, fltZSize, locLowerLeft, locUpperRight, boolIgnoreWater, boolIgnoreSlope, staticObjDistance); if(locGoodLocation==null) { LOG("DESIGNER_FATAL", "X search size is "+fltXSearchSize); LOG("DESIGNER_FATAL", "Z search size is "+fltZSearchSize); LOG("DESIGNER_FATAL", "size of thing is "+fltZSize); LOG("DESIGNER_FATAL", "Lower left is "+locLowerLeft); LOG("DESIGNER_FATAL", "Upper Right is "+locUpperRight); LOG("DESIGNER_FATAL", "Start location is "+locSearchLocation); } return locGoodLocation; } string getCityName(location locCurrentLocation) { region[] rgnCities = getRegionsWithMunicipalAtPoint(locCurrentLocation, regions.MUNI_TRUE); if(rgnCities==null) { return null; // in city } region rgnCity = rgnCities[0]; string_id strFictionalName = utils.unpackString(rgnCity.getName()); string strAsciiId = strFictionalName.getAsciiId(); return strAsciiId; } string getGuardSpawnerRegionName(location locCurrentLocation) { if(locCurrentLocation==null) { return null; } region[] rgnCities = getRegionsWithGeographicalAtPoint(locCurrentLocation, regions.GEO_CITY); if(rgnCities==null) { return null; // not in city } region rgnCity = rgnCities[0]; string strName = rgnCity.getName(); return strName; } location getBountyLocation(string strPlanet) { region[] rgnCities = getRegionsWithMunicipal(strPlanet, regions.MUNI_TRUE); if(rgnCities==null) { return null; } if(rgnCities.length>0) { int intRoll = rand(0, rgnCities.length-1); region rgnCity = rgnCities[intRoll]; location locDestination = getGoodCityLocation(rgnCity, strPlanet); location locCenter = getRegionCenter(rgnCities[intRoll]); return locCenter; } else { // we need to get a randomer location location locDestination = new location(); locDestination.x = rand(-6500, 6500); locDestination.z = rand(-6500, 6500); locDestination.area = strPlanet; locDestination = locations.getGoodLocationAroundLocation(locDestination, 1, 1, 400, 400, false, true); if(locDestination ==null) { LOG("DESIGNER_FATAL", "No good location found for planet "+strPlanet); locDestination = new location(); locDestination.area = strPlanet; locDestination.x = 0; locDestination.y = 0; locDestination.z = 0; } return locDestination; } } location moveLocationTowardsLocation(location locStartLocation, location locEndLocation, float fltDistance) { // moves a point from one point to another a certain distance. location locNewLocation = (location)locStartLocation.clone(); float fltTotalDistance = getDistance(locStartLocation, locEndLocation); if(fltTotalDistance<=0) { return locEndLocation; } float fltNewX = ((locEndLocation.x - locStartLocation.x) / fltTotalDistance); fltNewX = fltNewX * fltDistance; locNewLocation.x = locNewLocation.x + fltNewX; float fltNewZ = ((locEndLocation.z - locStartLocation.z)/fltTotalDistance); fltNewZ = fltNewZ * fltDistance; locNewLocation.z = locNewLocation.z + fltNewZ; return locNewLocation; } boolean isCityRegion(region rgnTest) { if(rgnTest.getMunicipalType()==regions.MUNI_TRUE) { return true; } return false; } // this function gets a different region/location in the passed in city. It requires a city to have multiple delivery regions location getDifferentGoodCityLocation(location locStartLocation) { LOG("missions", "getting different city location"); region[] rgnCities = getRegionsWithMunicipalAtPoint(locStartLocation, regions.MUNI_TRUE); if(rgnCities==null) { LOG("missions", "no cities found at locStartLocation "); return null; } region rgnCity = rgnCities[0]; location locGoodLocation = new location(); string_id strFictionalName = utils.unpackString(rgnCity.getName()); string strAsciiId = strFictionalName.getAsciiId(); LOG("mission_spam", "strAsciiId is "+strAsciiId); int regionType = regions.getDeliverMissionRegionType(strAsciiId); LOG("mission_spam", "Intregion type is "+ regionType); rgnCities = getRegionsWithMissionAtPoint(locStartLocation, regionType); if(rgnCities==null) { LOG("missions", "at start location of "+locStartLocation+", we found no mission types of bestine. "); return null; } string strOldName = rgnCities[0].getName(); // old name region[] rgnGoodLocationsArray = getRegionsWithMission(locStartLocation.area, regionType); resizeable region[] rgnGoodLocations = rgnGoodLocationsArray; LOG("missions", "strOldName is "+strOldName); /////LOG("mission_spam", "strPlanet is "+strPlanet); if(rgnGoodLocations==null) { LOG("missions", "no regions found with mission type on planet "+locStartLocation.area); LOG("mission_spam", "No regions were foind of type "+ regionType); return null; } int intI = 0; while(intI regionMinDifficulty) { minDifficulty = regionMinDifficulty; } } return minDifficulty; } int getMinDifficultyForPlanet(string planet) { int difficulty = 1; if(planet == "" || planet.length() <= 0) { return difficulty; } dictionary planetLevels = utils.dataTableGetRow(PLANET_LEVEL_TABLE, planet); if(planetLevels != null) { difficulty = planetLevels.getInt("minLevel"); } else { difficulty = -1; } if(difficulty < 1) { difficulty = 1; } return difficulty; } int getMaxDifficultyForPlanet(string planet) { int difficulty = 90; if(planet == "" || planet.length() <= 0) { return difficulty; } dictionary planetLevels = utils.dataTableGetRow(PLANET_LEVEL_TABLE, planet); if(planetLevels != null) { difficulty = planetLevels.getInt("maxLevel"); } else { difficulty = -1; } if(difficulty > 90) { difficulty = 90; } return difficulty; } int getMinDifficultyForLocation(location locTest) { region[] rgnRegionList = getDifficultyRegionsAtLocation(locTest); if (rgnRegionList == null || rgnRegionList.length == 0) { return 0; } int minDifficulty = Integer.MAX_VALUE; for (int i = 0; i < rgnRegionList.length; i++) { int regionMinDifficulty = rgnRegionList[i].getMinDifficultyType(); if (minDifficulty > regionMinDifficulty ) minDifficulty = regionMinDifficulty; } return minDifficulty; } int getMaxDifficultyForLocation(location locTest) { region[] rgnRegionList = getDifficultyRegionsAtLocation(locTest); if (rgnRegionList == null || rgnRegionList.length == 0) { return Integer.MAX_VALUE; } int maxDifficulty = Integer.MIN_VALUE; for (int i = 0; i < rgnRegionList.length; i++) { int regionMaxDifficulty = rgnRegionList[i].getMaxDifficultyType(); if (maxDifficulty < regionMaxDifficulty) maxDifficulty = regionMaxDifficulty; } return maxDifficulty; } int capMinDifficultyForLocation(location locTest, int intDifficulty) { int intMinRegionDifficulty = getMinDifficultyForLocation(locTest); if (intDifficulty < intMinRegionDifficulty) intDifficulty = intMinRegionDifficulty; return intDifficulty; } int capMaxDifficultyForLocation(location locTest, int intDifficulty) { int intMaxRegionDifficulty = getMaxDifficultyForLocation(locTest); if (intDifficulty > intMaxRegionDifficulty) intDifficulty = intMaxRegionDifficulty; return intDifficulty; } // Used to destroy the reservation object used by requestLocation() // the obj_id needed is returned to trigger OnLocationReceived and is the obj_id of the reservation object. boolean destroyLocationObject(obj_id locationObject) { if ( isIdValid(locationObject) ) { messageTo(locationObject, "handlerDestroyLocationObject", null, 1, false); return true; } return false; } string getBuildoutAreaName(obj_id object) { if (!isIdValid(object) || !exists(object)) return NO_AREA; return getBuildoutAreaName(getLocation(trial.getTop(object))); } string getBuildoutAreaName(location loc) { if (isIdValid(loc.cell)) { obj_id topBuilding = trial.getTop(loc.cell); loc = getLocation(topBuilding); } string buildout_table = "datatables/buildout/areas_"+loc.area+".iff"; float locX = loc.x; float locZ = loc.z; if (!dataTableOpen(buildout_table)) { return NO_AREA; } int rows = dataTableGetNumRows(buildout_table); string area_name = NO_AREA; for (int i=0;i= xMin && locX <= xMax && locZ >= zMin && locZ <= zMax) area_name = dict.getString("area"); } return area_name; } int getBuildoutAreaRow(obj_id object) { if (!isIdValid(object) || !exists(object)) return -1; return getBuildoutAreaRow(getLocation(trial.getTop(object))); } int getBuildoutAreaRow(location loc) { if (isIdValid(loc.cell)) { obj_id topBuilding = trial.getTop(loc.cell); loc = getLocation(topBuilding); } string buildout_table = "datatables/buildout/areas_"+loc.area+".iff"; float locX = loc.x; float locZ = loc.z; if (!dataTableOpen(buildout_table)) { return -1; } int rows = dataTableGetNumRows(buildout_table); int row = -1; for (int i=0;i= xMin && locX <= xMax && locZ >= zMin && locZ <= zMax) row = i; } return row; } boolean isInRegion(obj_id player, string regionName) { region[] regionList = getRegionsAtPoint(getLocation(player)); obj_id planetId = getPlanetByName(getLocation(player).area); if(regionList == null || regionList.length == 0) return false; for(int i = 0; i < regionList.length; i++) { if(regionList[i] == null || regionList[i].getName().length() <= 0) continue; if(regionName.equals(regionList[i].getName())) { return true; } } return false; }