mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
130 lines
3.2 KiB
Plaintext
130 lines
3.2 KiB
Plaintext
/**
|
|
|
|
* Title: cloning_facility.script
|
|
* Description: script for cloning facilities
|
|
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.create;
|
|
include library.structure;
|
|
include library.player_structure;
|
|
include library.utils;
|
|
|
|
/***** INHERITS ********************************************************/
|
|
|
|
inherits structure.municipal.cloning_base;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string SCRIPT_CLONING_FACILITY = "structure.municipal.cloning_facility";
|
|
|
|
//FACILITY DATATABLES
|
|
const string DATATABLE_TERMINAL_LIST = "datatables/structure/municipal/cloning_facility_terminal.iff";
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
messageTo( self, "handleTerminalSpawning", null, 5f, false );
|
|
return super.OnInitialize(self);
|
|
}
|
|
|
|
trigger OnDetach()
|
|
{
|
|
obj_id planet = getPlanetByName(getCurrentSceneName());
|
|
if (isIdValid(planet))
|
|
{
|
|
dictionary params = new dictionary();
|
|
params.put("id", self);
|
|
messageTo(planet, "unregisterCloningFacility", params, 1.0f, false);
|
|
}
|
|
|
|
return super.OnDetach(self);
|
|
}
|
|
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
|
|
|
|
/***** MESSAGEHANDLERS *************************************************/
|
|
messageHandler handleTerminalSpawning()
|
|
{
|
|
createCloningDroid(self);
|
|
if(!player_structure.isCivic(self))
|
|
structure.createStructureTerminals(self, SCRIPT_CLONING_FACILITY, DATATABLE_TERMINAL_LIST);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void createCloningDroid(obj_id facility)
|
|
{
|
|
|
|
if(!isIdValid(facility))
|
|
return;
|
|
|
|
string facilityTemplate = getTemplateName(facility);
|
|
|
|
float fYaw = getYaw(facility);
|
|
|
|
string sceneName = getCurrentSceneName();
|
|
|
|
int numRows = dataTableGetNumRows(DATATABLE_TERMINAL_LIST);
|
|
|
|
resizeable obj_id[] terminals = new obj_id[0];
|
|
|
|
for(int i = 0; i < numRows; i++)
|
|
{
|
|
string buildingTemplate = dataTableGetString(DATATABLE_TERMINAL_LIST, i, structure.DATATABLE_COL_STRUCTURE);
|
|
|
|
if(buildingTemplate.equals(facilityTemplate))
|
|
{
|
|
dictionary item = dataTableGetRow(DATATABLE_TERMINAL_LIST, i);
|
|
|
|
string droid_name = item.getString("DROID");
|
|
|
|
if(droid_name == null || droid_name.equals(""))
|
|
continue;
|
|
|
|
float x = item.getFloat(structure.DATATABLE_COL_X);
|
|
float y = item.getFloat(structure.DATATABLE_COL_Y);
|
|
float z = item.getFloat(structure.DATATABLE_COL_Z);
|
|
float relativeHeading = item.getFloat(structure.DATATABLE_COL_HEADING);
|
|
|
|
string cell_name = item.getString(structure.DATATABLE_COL_CELL);
|
|
obj_id cell_id = obj_id.NULL_ID;
|
|
|
|
if(!cell_name.equals(structure.WORLD_DELTA))
|
|
{
|
|
cell_id = getCellId(facility, cell_name);
|
|
}
|
|
|
|
if(cell_id != null)
|
|
{
|
|
obj_id droid_id = obj_id.NULL_ID;
|
|
location spot = new location(x, y, z, sceneName, cell_id);
|
|
|
|
float heading = relativeHeading;
|
|
|
|
if(cell_id == obj_id.NULL_ID)
|
|
{
|
|
location fLoc = getLocation(facility);
|
|
spot = new location(fLoc.x + x, fLoc.y + y, fLoc.z + z, sceneName, cell_id);
|
|
|
|
if(fYaw != 0)
|
|
{
|
|
spot = utils.rotatePointXZ(fLoc, spot, fYaw);
|
|
heading -= (90 - fYaw);
|
|
}
|
|
}
|
|
|
|
droid_id = create.object(droid_name, spot);
|
|
|
|
if((droid_id != null) && (droid_id != obj_id.NULL_ID))
|
|
setYaw(droid_id, heading);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|