mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
302 lines
7.3 KiB
Plaintext
302 lines
7.3 KiB
Plaintext
include library.utils;
|
|
include library.ai_lib;
|
|
include library.space_utils;
|
|
include library.spawning;
|
|
include library.create;
|
|
|
|
|
|
|
|
|
|
trigger OnAttach()
|
|
{
|
|
//LOG("spawning", "ONATTACACHA!");
|
|
if (!hasObjVar(self, "registerWithController"))
|
|
setObjVar(self, "registerWithController", 1);
|
|
if (hasObjVar(self, "strName"))
|
|
setName(self, getStringObjVar(self, "strName"));
|
|
|
|
if (canSpawnByConfigSetting())
|
|
messageTo(self, "doSpawnEvent", null, 20, false);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
//LOG("spawning", "ONINITN");
|
|
if (!hasObjVar(self, "registerWithController"))
|
|
setObjVar(self, "registerWithController", 1);
|
|
if (hasObjVar(self, "strName"))
|
|
setName(self, getStringObjVar(self, "strName"));
|
|
|
|
if (canSpawnByConfigSetting())
|
|
messageTo(self, "doSpawnEvent", null, 20, false);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
messageHandler doSpawnEvent()
|
|
{
|
|
if(!spawning.checkSpawnCount(self))
|
|
{
|
|
//LOG("spawning", "No count 1");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
int intGoodLocationSpawner = getIntObjVar(self, "intGoodLocationSpawner");
|
|
float fltRadius = getFloatObjVar(self, "fltRadius");
|
|
string strSpawnType = getStringObjVar(self, "strSpawns");
|
|
|
|
// if strSpawnType is the name of a spawning table, use it.
|
|
// Otherwise, strSpawnType should be directly from creatures.tab
|
|
float fltSize = 8.0f;
|
|
string strSpawn = strSpawnType;
|
|
|
|
string strFileName = "datatables/spawning/ground_spawning/types/"+strSpawnType+".iff";
|
|
if ( dataTableOpen(strFileName) )
|
|
{
|
|
string[] strSpawns = dataTableGetStringColumnNoDefaults(strFileName, "strItem");
|
|
float[] fltSizes= dataTableGetFloatColumn(strFileName, "fltSize");
|
|
|
|
if( strSpawns==null || strSpawns.length==0 )
|
|
{
|
|
//LOG("spawning", "NO SPAWNS IN FILE "+strFileName);
|
|
setName(self, "Mangled spawner. strFileName is "+strFileName+" I couldnt find any spawns in that file.");
|
|
}
|
|
|
|
int intRoll = rand(0, strSpawns.length-1);
|
|
//LOG("spawning", "looking for "+strFileName);
|
|
|
|
if(fltSizes.length==0)
|
|
{
|
|
//LOG("spawning", "BAD NUMBER OF SIZES !@!@@ IN FILE "+strFileName);
|
|
setName(self, "BAD NUMBER OF SIZES !@!@@ IN FILE "+strFileName);
|
|
}
|
|
if(fltSizes.length!=strSpawns.length)
|
|
{
|
|
//LOG("spawning", "Missing either spawns or sizes in "+strFileName);
|
|
setName(self, "Missing either spawns or sizes in "+strFileName);
|
|
}
|
|
|
|
fltSize = fltSizes[intRoll];
|
|
strSpawn = strSpawns[intRoll];
|
|
}
|
|
//LOG("spawning", "spawning "+strSpawn);
|
|
|
|
if( strSpawn==null || strSpawn.length() < 1 )
|
|
{
|
|
setName(self, "Mangled spawner. strSpawn is " + strSpawn + ".");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
location locTest = spawning.getRandomLocationInCircle(getLocation(self), fltRadius);
|
|
fltSize = getClosestSize(fltSize);
|
|
//LOG("spawning", "fltSize is "+fltSize);
|
|
if(intGoodLocationSpawner>0)
|
|
{
|
|
//LOG("spawning", "getting a good location around "+locTest+" with size "+fltSize);
|
|
requestLocation(self, strSpawn, locTest, rand(100, 200), fltSize, true, true);
|
|
}
|
|
else
|
|
{
|
|
createMob(strSpawn, null, locTest, fltRadius, self);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
float getClosestSize(float fltOriginalSize)
|
|
{
|
|
|
|
if(fltOriginalSize<=4.0f)
|
|
{
|
|
return 4.0f;
|
|
}
|
|
if(fltOriginalSize<=8.0f)
|
|
{
|
|
return 8.0f;
|
|
}
|
|
if(fltOriginalSize<=12.0f)
|
|
{
|
|
return 12.0f;
|
|
}
|
|
if(fltOriginalSize<=16.0f)
|
|
{
|
|
return 16.0f;
|
|
}
|
|
|
|
if(fltOriginalSize<=32.0f)
|
|
{
|
|
return 32.0f;
|
|
}
|
|
else if(fltOriginalSize <= 48.0f)
|
|
{
|
|
return 48.0f;
|
|
}
|
|
else if(fltOriginalSize <= 64.0f)
|
|
{
|
|
return 64.0f;
|
|
}
|
|
else if(fltOriginalSize <= 80.0f)
|
|
{
|
|
return 80f;
|
|
}
|
|
else if(fltOriginalSize <= 96.0f)
|
|
{
|
|
return 96f;
|
|
}
|
|
return 32f;
|
|
|
|
}
|
|
void createMob(string strId, obj_id objLocationObject, location locLocation, float fltRadius, obj_id self)
|
|
{
|
|
|
|
if(!spawning.checkSpawnCount(self))
|
|
{
|
|
return;
|
|
}
|
|
|
|
float spawnerYaw = getYaw(self);
|
|
|
|
// SPAWN@!@!@!@!@!
|
|
|
|
// the string is actuallywaht we spawn.
|
|
int intIndex = strId.indexOf(".iff");
|
|
float fltMinSpawnTime = getFloatObjVar(self, "fltMinSpawnTime");
|
|
float fltMaxSpawnTime = getFloatObjVar(self, "fltMaxSpawnTime");
|
|
float fltRespawnTime = rand(fltMinSpawnTime, fltMaxSpawnTime);
|
|
if(intIndex>-1)
|
|
{
|
|
// template
|
|
obj_id objTemplate = createObject(strId, locLocation);
|
|
if(isIdValid(objLocationObject))
|
|
{
|
|
destroyObject(objLocationObject);
|
|
}
|
|
|
|
if(!isIdValid(objTemplate))
|
|
{
|
|
return;
|
|
}
|
|
spawning.incrementSpawnCount(self);
|
|
spawning.addToSpawnDebugList(self, objTemplate);
|
|
setObjVar(objTemplate, "objParent", self);
|
|
setObjVar(objTemplate, "fltRespawnTime", fltRespawnTime);
|
|
attachScript(objTemplate, "systems.spawning.spawned_tracker");
|
|
|
|
setYaw(objTemplate, spawnerYaw);
|
|
|
|
}
|
|
else
|
|
{
|
|
// monster
|
|
//LOG("spawning", "I am going to make a "+strId);
|
|
if(isIdValid(objLocationObject))
|
|
{
|
|
destroyObject(objLocationObject);
|
|
}
|
|
obj_id objMob = create.object(strId, locLocation);
|
|
if(!isIdValid(objMob))
|
|
{
|
|
|
|
setName(self , "BAD MOB OF TYPE "+strId);
|
|
return;
|
|
}
|
|
int intBehavior = getIntObjVar(self, "intDefaultBehavior");
|
|
ai_lib.setDefaultCalmBehavior(objMob, intBehavior);
|
|
|
|
spawning.incrementSpawnCount(self);
|
|
spawning.addToSpawnDebugList(self, objMob);
|
|
setObjVar(objMob, "objParent", self);
|
|
setObjVar(objMob, "fltRespawnTime", fltRespawnTime);
|
|
attachScript(objMob, "systems.spawning.spawned_tracker");
|
|
|
|
setYaw(objMob, spawnerYaw);
|
|
|
|
}
|
|
if(!spawning.checkSpawnCount(self))
|
|
{
|
|
//LOG("spawn", "Failed ot check spawncount");
|
|
return;
|
|
}
|
|
//LOG("spawn", "resending doSpawnEvent");
|
|
messageTo(self, "doSpawnEvent", null, fltRespawnTime, false);
|
|
return;
|
|
|
|
|
|
}
|
|
trigger OnLocationReceived(string strId, obj_id objLocationObject, location locLocation, float fltRadius)
|
|
{
|
|
|
|
//LOG("spawning", "strId is "+strId+" and objLocationObject is "+objLocationObject+" and location os "+locLocation);
|
|
if(isIdValid(objLocationObject))
|
|
{
|
|
//LOG("spawning", "got goodlocation 2");
|
|
// we make our thang. Otherwise
|
|
createMob(strId, objLocationObject, locLocation, fltRadius, self);
|
|
}
|
|
else
|
|
{
|
|
float fltMinSpawnTime = getFloatObjVar(self, "fltMinSpawnTime");
|
|
float fltMaxSpawnTime = getFloatObjVar(self, "fltMaxSpawnTime");
|
|
float fltRespawnTime = rand(fltMinSpawnTime, fltMaxSpawnTime);
|
|
// keep trying
|
|
messageTo(self, "doSpawnEvent", null, fltRespawnTime, false);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
|
|
|
|
}
|
|
|
|
messageHandler spawnDestroyed()
|
|
{
|
|
int intCurrentSpawnCount = utils.getIntScriptVar(self, "intCurrentSpawnCount");
|
|
intCurrentSpawnCount = intCurrentSpawnCount - 1;
|
|
if(intCurrentSpawnCount>-1)
|
|
{
|
|
utils.setScriptVar(self, "intCurrentSpawnCount", intCurrentSpawnCount);
|
|
|
|
}
|
|
else
|
|
{
|
|
utils.setScriptVar(self, "intCurrentSpawnCount", 0);
|
|
}
|
|
messageTo(self, "doSpawnEvent", null, 2, false);
|
|
return SCRIPT_CONTINUE;
|
|
|
|
}
|
|
|
|
boolean canSpawnByConfigSetting()
|
|
{
|
|
string disableSpawners = getConfigSetting("GameServer", "disableAreaSpawners");
|
|
if (disableSpawners == null)
|
|
return true;
|
|
|
|
if (disableSpawners.equals("true") || disableSpawners.equals("1"))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
//Destroy spawned objects when spawner is destroyed.
|
|
trigger OnDestroy()
|
|
{
|
|
if (utils.hasScriptVar(self, "debugSpawnList"))
|
|
{
|
|
//LOG("spawning", "Reached debugSpawnList");
|
|
obj_id[] spawns = utils.getObjIdArrayScriptVar(self, "debugSpawnList");
|
|
|
|
if(spawns == null || spawns.length == 0)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
for(int i = 0; i < spawns.length; ++i)
|
|
{
|
|
//LOG("spawning", "Reached loop");
|
|
if(isIdValid(spawns[i]) && exists(spawns[i]))
|
|
messageTo(spawns[i], "selfDestruct", null, 5, false);
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
} |