Files
dsrc/sku.0/sys.server/compiled/game/script/library/locations.scriptlib
T
2013-09-10 23:17:15 -07:00

1259 lines
32 KiB
Plaintext

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 = locExtents[0];
locUpperRight = locExtents[1];
// //////////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; intI<rgnRegions.length; intI++)
{
//LOG("mission", "Old region name is "+rgnSmallestRegion.getName());
//LOG("mission", "Current region name is "+ rgnRegions[intI].getName());
//LOG("mission", "old extents is "+fltExtents);
float fltRegionExtents = getRegionExtents(rgnRegions[intI]);
//LOG("mission", "new extents is "+fltRegionExtents);
if(fltRegionExtents<fltExtents)
{
//LOG("mission", "changing small region to "+rgnRegions[intI].getName());
rgnSmallestRegion = rgnRegions[intI];
fltExtents = fltRegionExtents;
}
}
return rgnSmallestRegion;
}
// returns x size
float getRegionXSize(region rgnSearchRegion)
{
location[] locExtents = getRegionExtent(rgnSearchRegion);
location locLowerLeft = locExtents[0];
location locUpperRight = locExtents[1];
// //////////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
return fltXDistance;
}
// returns z size
float getRegionZSize(region rgnSearchRegion)
{
location[] locExtents = getRegionExtent(rgnSearchRegion);
location locLowerLeft = locExtents[0];
location locUpperRight = locExtents[1];
// //////////LOG("mission", "Lower Left is "+locLowerLeft.toString());
////////////LOG("mission", "Upper Right is "+locUpperRight.toString());
float fltZDistance = locUpperRight.z - locLowerLeft.z; // see above
return fltZDistance;
}
// returns array x, z size
float[] getRegionSize(region rgnSearchRegion)
{
location[] locExtents = getRegionExtent(rgnSearchRegion);
location locLowerLeft = locExtents[0];
location locUpperRight = locExtents[1];
// //////////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
float[] fltRegionSize = new float[2];
fltRegionSize[0] = fltXDistance;
fltRegionSize[1] = fltZDistance;
return fltRegionSize;
}
// gets region center
location getRegionCenter(region rgnSearchRegion)
{
location locLowerLeft = new location();
location locUpperRight = new location();
location[] locExtents = getRegionExtent(rgnSearchRegion);
locLowerLeft = locExtents[0];
locUpperRight = locExtents[1];
location locRegionCenter = locLowerLeft;
locRegionCenter.x = (locLowerLeft.x + locUpperRight.x)/2;
locRegionCenter.z = (locLowerLeft.z + locUpperRight.z)/2;
////////////LOG("missions", "locRegionCenter is "+locRegionCenter.toString());
return locRegionCenter;
}
// duh!
location getGoodLocationOutsideOfRegion(region rgnSearchRegion, float fltXSize, float fltZSize, float fltDistance)
{
if ( rgnSearchRegion == null )
return null;
debugServerConsoleMsg(null, "getting good locoutsideofregion");
//////////LOG("mission", "getting good location outside of region");
float fltRegionExtent = getRegionExtents(rgnSearchRegion);
location locRegionCenter = getRegionCenter(rgnSearchRegion);
//////////LOG("mission", "got centers and extents");
location locDestination = utils.getRandomLocationInRing(locRegionCenter, fltRegionExtent, fltRegionExtent+fltDistance);
location locLowerLeft = locDestination;
locLowerLeft.x = locLowerLeft.x - GOOD_LOCATION_SEARCH_SIZE+fltXSize;
locLowerLeft.z = locLowerLeft.z - GOOD_LOCATION_SEARCH_SIZE+fltZSize;
location locUpperRight = locDestination;
locUpperRight.x = locUpperRight.x + GOOD_LOCATION_SEARCH_SIZE+fltXSize;
locUpperRight.z = locUpperRight.z + GOOD_LOCATION_SEARCH_SIZE+fltZSize;
location locGoodLocation = getGoodLocation(fltXSize, fltZSize, locLowerLeft, locUpperRight, false, false);
//////////LOG("mission", "gotGoodLocation");
return locGoodLocation;
}
location getGoodLocationOutsideOfRegion(region rgnSearchRegion, float fltXSize, float fltZSize, float fltDistance, boolean boolIgnoreWater, boolean boolIgnoreSlope)
{
debugServerConsoleMsg(null, "getting good locoutsideofregion");
//////////LOG("mission", "getting good location outside of region");
float fltRegionExtent = getRegionExtents(rgnSearchRegion);
location locRegionCenter = getRegionCenter(rgnSearchRegion);
//////////LOG("mission", "got centers and extents");
location locDestination = utils.getRandomLocationInRing(locRegionCenter, fltRegionExtent, fltRegionExtent+fltDistance);
location locLowerLeft = locDestination;
locLowerLeft.x = locLowerLeft.x - GOOD_LOCATION_SEARCH_SIZE+fltXSize;
locLowerLeft.z = locLowerLeft.z - GOOD_LOCATION_SEARCH_SIZE+fltZSize;
location locUpperRight = locDestination;
locUpperRight.x = locUpperRight.x + GOOD_LOCATION_SEARCH_SIZE+fltXSize;
locUpperRight.z = locUpperRight.z + GOOD_LOCATION_SEARCH_SIZE+fltZSize;
location locGoodLocation = getGoodLocation(fltXSize, fltZSize, locLowerLeft, locUpperRight, boolIgnoreWater, boolIgnoreSlope);
//////////LOG("mission", "gotGoodLocation");
return locGoodLocation;
}
// finds closest city region on planet
region getClosestCityRegion(region rgnStartRegion)
{
string strName = rgnStartRegion.getName();
////LOG("mission", "in getclosest region, name is "+strName);
region[] rgnCities = getRegionsWithMunicipal(rgnStartRegion.getPlanetName(), regions.MUNI_TRUE);
if(rgnCities==null)
{
return null;
}
region rgnClosestRegion = rgnCities[0];
float fltDistance;
float fltLowestDistance = 500000000;
location locCenterPoint;
location locCurrentCenter;
locCurrentCenter = getRegionCenter(rgnStartRegion);
int intI = 0;
while(intI<rgnCities.length)
{
//////////LOG("mission", "objRegion is "+objRegion);
//////////LOG("mission", "StartRegion is "+objStartRegion);
string strNewName = rgnCities[intI].getName();
////LOG("missions", "strNewName is "+strNewName);
if(strNewName!=strName)
{
fltDistance = getDistance(locCurrentCenter, getRegionCenter(rgnCities[intI]));
//////////LOG("mission", "fltDistance is "+fltDistance);
//////////LOG("mission", "fltLowestDistance is "+fltLowestDistance);
//////////LOG("mission", "closest region is "+objClosestRegion);
if(fltDistance<fltLowestDistance)
{
fltLowestDistance = fltDistance;
rgnClosestRegion = rgnCities[intI];
}
}
intI = intI+1;
}
//////////LOG("mission", "returned region is "+objClosestRegion);
return rgnClosestRegion;
}
region getDeliverCityRegion(region rgnStartRegion)
{
resizeable string[] strPlanets= new string[0];
string strPlanet = rgnStartRegion.getPlanetName();
region[] rgnCities = getRegionsWithMunicipal(strPlanet, regions.MUNI_TRUE);
resizeable region[] rgnNewCities = new region[0];
if(rgnCities==null)
{
return null;
}
if(rgnCities.length==0)
{
return null;
}
LOG("locations", "length is "+rgnCities.length);
if(rgnCities.length<3)
{
// OOOOOH! OFFPLANET! WAHOO!
for(int intI = 0; intI<PLANETS.length; intI++)
{
string strTestString = PLANETS[intI]; // to make sure we don't hit preprocessor bug;
LOG("locations", "strTestString is "+strTestString);
LOG("locations", "strPlanet is "+strPlanet);
if(strTestString!=strPlanet)
{
strPlanets = utils.addElement(strPlanets, strTestString);
}
}
// now we've got a planet!
string strNewPlanet = strPlanets[rand(0, strPlanets.length-1)];
LOG("locations", "new planet is "+strNewPlanet);
rgnCities= getRegionsWithMunicipal(strNewPlanet, regions.MUNI_TRUE);
if((rgnCities!=null)&&(rgnCities.length>0))
{
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<rgnCities.length)
{
// we've gotta kick start region out of the array
string strNewName = rgnCities[intI].getName();
if(strStartName!=strNewName)
{
rgnNewCities= utils.addElement(rgnNewCities, rgnCities[intI]);
}
intI = intI+1;
}
region rgnCity = rgnNewCities[rand(0, rgnNewCities.length-1)];
return rgnCity;
}
}
// finds a city region on a planet that isn't the same as the passed region
region getCityRegion(region rgnStartRegion)
{
region[] rgnCitiesArray = getRegionsWithMunicipal(rgnStartRegion.getPlanetName(), regions.MUNI_TRUE);
resizeable region[] rgnCities = rgnCitiesArray;
if(rgnCities==null)
{
return null;
}
if(rgnCitiesArray==null)
{
return null;
}
if(rgnCities.length==0)
{
return null;
}
if(rgnCitiesArray.length==0)
{
return null;
}
int intI = 0;
string strStartName = rgnStartRegion.getName();
while(intI<rgnCities.length)
{
// we've gotta kick start region out of the array
string strNewName = rgnCities[intI].getName();
if(strStartName==strNewName)
{
rgnCities = utils.removeElementAt(rgnCities, intI);
intI = rgnCities.length+10;
}
intI = intI+1;
}
region rgnCity = rgnCities[rand(0, rgnCities.length-1)];
return rgnCity;
}
region getCityRegion(location locCurrentLocation)
{
region[] rgnCities = getRegionsWithMunicipalAtPoint(locCurrentLocation, regions.MUNI_TRUE);
if(rgnCities==null)
{
return null;
}
region rgnCity = rgnCities[rand(0, rgnCities.length-1)];
return rgnCity;
}
boolean isInCity(location locTestLocation)
{
region[] rgnCities = getRegionsWithMunicipalAtPoint(locTestLocation, regions.MUNI_TRUE);
if(rgnCities!=null)
{
return true; // in city
}
return false;
}
boolean isInMissionCity(location locTestLocation)
{
// Check for player cities.
if ( city.isInCity( locTestLocation ) )
return true;
region[] rgnCities = getRegionsWithMunicipalAtPoint(locTestLocation, regions.MUNI_TRUE);
if(rgnCities!=null)
{
return true; // in city
}
rgnCities = getRegionsWithGeographicalAtPoint(locTestLocation, regions.GEO_CITY);
if(rgnCities!=null)
{
return true;
}
return false;
}
// gets good location of given size in a region
location getGoodLocationInRegion(region rgnSearchRegion, float fltXSize, float fltZSize)
{
// make sure to check for a circle
location locLowerLeft = new location();
location locUpperRight = new location();
location[] locExtents = getRegionExtent(rgnSearchRegion);
locLowerLeft = locExtents[0];
locUpperRight = locExtents[1];
location locGoodLocation = getGoodLocation(fltXSize, fltZSize, locLowerLeft, locUpperRight, false, false);
return locGoodLocation;
}
location getGoodLocationInRegion(region rgnSearchRegion, float fltXSize, float fltZSize, boolean boolIgnoreWater, boolean boolIgnoreSlope)
{
// make sure to check for a circle
location locLowerLeft = new location();
location locUpperRight = new location();
location[] locExtents = getRegionExtent(rgnSearchRegion);
locLowerLeft = locExtents[0];
locUpperRight = locExtents[1];
location locGoodLocation = getGoodLocation(fltXSize, fltZSize, locLowerLeft, locUpperRight, boolIgnoreWater, boolIgnoreSlope);
return locGoodLocation;
}
// find a good location near the x, z coordinates specified, with a minimum size of
// locationSize, searching for a distance spefied by searchRadius
location getRandomGoodLocation(location start, float searchMin, float searchMax, float bestSize)
{
location result = null;
location l = utils.getRandomLocationInRing(start, searchMin, searchMax);
location lowerLeft = new location();
location upperRight = new location();
lowerLeft.x = l.x - bestSize;
lowerLeft.z = l.z - bestSize;
upperRight.x = l.x + bestSize;
upperRight.z = l.z + bestSize;
float radius = bestSize;
while(result == null && radius > 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 = locSearchLocation;
locLowerLeft.x = locLowerLeft.x - fltXSearchSize;
locLowerLeft.z = locLowerLeft.z - fltZSearchSize;
////LOG("mission", "locLowerLeft is "+locLowerLeft.toString());
location locUpperRight = locSearchLocation;
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 = locSearchLocation;
locLowerLeft.x = locLowerLeft.x - fltXSearchSize;
locLowerLeft.z = locLowerLeft.z - fltZSearchSize;
////LOG("mission", "locLowerLeft is "+locLowerLeft.toString());
location locUpperRight = locSearchLocation;
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 = locSearchLocation;
locLowerLeft.x = locLowerLeft.x - fltXSearchSize;
locLowerLeft.z = locLowerLeft.z - fltZSearchSize;
////LOG("mission", "locLowerLeft is "+locLowerLeft.toString());
location locUpperRight = locSearchLocation;
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 = locStartLocation;
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 "+intRegionType);
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 "+intRegionType);
return null;
}
int intI = 0;
while(intI<rgnGoodLocations.length)
{
string strNewName = rgnGoodLocations[intI].getName();
if(strNewName==strOldName)
{
rgnGoodLocations = utils.removeElementAt(rgnGoodLocations, intI);
intI = rgnGoodLocations.length +19;
}
intI = intI+1;
}
region rgnSpawnRegion = rgnGoodLocations[rand(0, rgnGoodLocations.length-1)];
locGoodLocation = findPointInRegion(rgnSpawnRegion);
//////LOG("mission_spam", "Got good location of "+locGoodLocation.toString() + " in locations.getGoodCityLocation");
return locGoodLocation;
}
location getDifferentGoodCityRegionLocation(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 "+intRegionType);
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 "+intRegionType);
return null;
}
int intI = 0;
while(intI<rgnGoodLocations.length)
{
string strNewName = rgnGoodLocations[intI].getName();
if(strNewName==strOldName)
{
rgnGoodLocations = utils.removeElementAt(rgnGoodLocations, intI);
intI = rgnGoodLocations.length +19;
}
intI = intI+1;
}
region rgnSpawnRegion = rgnGoodLocations[rand(0, rgnGoodLocations.length-1)];
locGoodLocation = getRegionCenter(rgnSpawnRegion);
//////LOG("mission_spam", "Got good location of "+locGoodLocation.toString() + " in locations.getGoodCityLocation");
return locGoodLocation;
}
location getGoodCityLocation(region rgnCity, string strPlanet)
{
if ( rgnCity == null || strPlanet == null)
return null;
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 "+intRegionType);
region[] rgnGoodLocations = getRegionsWithMission(strPlanet, regionType);
//////LOG("mission_spam", "strPlanet is "+strPlanet);
if(rgnGoodLocations==null)
{
//////LOG("mission_spam", "No regions were foind of type "+intRegionType);
return null;
}
region rgnSpawnRegion = rgnGoodLocations[rand(0, rgnGoodLocations.length-1)];
int intI = 0;
while(intI<rgnGoodLocations.length)
{
//////LOG("locations", "rgnGoodLocationsRegion[intI] Type is "+ rgnGoodLocations[intI].getMissionType());
//////LOG("locations", "rgnGoodLocationsRegion[intI] planet is "+rgnGoodLocations[intI].getPlanetName());
intI = intI+1;
}
locGoodLocation = findPointInRegion(rgnSpawnRegion);
//////LOG("mission_spam", "Got good location of "+locGoodLocation.toString() + " in locations.getGoodCityLocation");
return locGoodLocation;
}
location getGoodCityRegionLocation(region rgnCity, string strPlanet)
{
if ( rgnCity == null || strPlanet == null)
return null;
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 "+intRegionType);
region[] rgnGoodLocations = getRegionsWithMission(strPlanet, regionType);
//////LOG("mission_spam", "strPlanet is "+strPlanet);
if(rgnGoodLocations==null)
{
//////LOG("mission_spam", "No regions were foind of type "+intRegionType);
return null;
}
region rgnSpawnRegion = rgnGoodLocations[rand(0, rgnGoodLocations.length-1)];
locGoodLocation = getRegionCenter(rgnSpawnRegion);
return locGoodLocation;
}
int normalizeDifficultyForRegion(int intDifficulty, location locTest)
{
// this converts the passed difficulty into an appropriate min/max difficulty for the area
region[] rgnRegionsAtPoint = getRegionsWithSpawnableAtPoint(locTest, regions.SPAWN_TRUE);
if(rgnRegionsAtPoint == null || rgnRegionsAtPoint.length == 0)
{
rgnRegionsAtPoint = getRegionsWithSpawnableAtPoint(locTest, regions.SPAWN_DEFAULT);
if(rgnRegionsAtPoint == null)
{
//LOG("DESIGNER_FATAL", "No regions at location "+locTest);
return intDifficulty;
}
}
region rgnSmallestRegion = getSmallestRegion(rgnRegionsAtPoint);
if(rgnSmallestRegion == null)
{
//LOG("locations", "Smallest region was null");
return intDifficulty;
}
int intMinRegionDifficulty = rgnSmallestRegion.getMinDifficultyType();
int intMaxRegionDifficulty = rgnSmallestRegion.getMaxDifficultyType();
//LOG("locations", "intMinRegionDifficulty: " + intMinRegionDifficulty + " intMaxRegionDifficulty: " + intMaxRegionDifficulty + " intDifficulty: " + intDifficulty);
return rand(intMinRegionDifficulty, intMaxRegionDifficulty);
}
region[] getDifficultyRegionsAtLocation(location locTest)
{
region[] rgnRegionsAtPoint = getRegionsWithSpawnableAtPoint(locTest, regions.SPAWN_TRUE);
if(rgnRegionsAtPoint == null || rgnRegionsAtPoint.length == 0)
{
rgnRegionsAtPoint = getRegionsWithSpawnableAtPoint(locTest, regions.SPAWN_DEFAULT);
if (rgnRegionsAtPoint == null || rgnRegionsAtPoint.length == 0)
return null;
}
return rgnRegionsAtPoint;
}
int getMinMissionDifficultyAtLocation(location locTest)
{
region[] rgnRegionsAtPoint = getRegionsWithMissionAtPoint(locTest, regions.MISSION_OTHER);
if(rgnRegionsAtPoint == null || rgnRegionsAtPoint.length == 0)
{
rgnRegionsAtPoint = getRegionsWithSpawnableAtPoint(locTest, regions.SPAWN_DEFAULT);
if(rgnRegionsAtPoint == null || rgnRegionsAtPoint.length == 0)
{
return 10;
}
}
int minDifficulty = 90;
for(int i = 0; i < rgnRegionsAtPoint.length; i++)
{
int regionMinDifficulty = rgnRegionsAtPoint[i].getMinDifficultyType();
if(minDifficulty > 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<rows;i++)
{
dictionary dict = dataTableGetRow(buildout_table, i);
float xMin = dict.getFloat("x1");
float xMax = dict.getFloat("x2");
float zMin = dict.getFloat("z1");
float zMax = dict.getFloat("z2");
if (locX >= 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<rows;i++)
{
dictionary dict = dataTableGetRow(buildout_table, i);
float xMin = dict.getFloat("x1");
float xMax = dict.getFloat("x2");
float zMin = dict.getFloat("z1");
float zMax = dict.getFloat("z2");
if (locX >= 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;
}