Files
dsrc/sku.0/sys.server/compiled/game/script/space/quest_logic/rescue.script
T

406 lines
13 KiB
Plaintext

//------------------------------------------------
// rescue.script
// Brandon Reinhart
//------------------------------------------------
/*
- Spawn rescue ship.
*/
//------------------------------------------------
// Includes
//------------------------------------------------
include library.space_create;
include library.space_quest;
include library.space_utils;
include library.space_crafting;
include library.space_transition;
include library.utils;
include library.ship_ai;
include library.prose;
//------------------------------------------------
// Inherits
//------------------------------------------------
inherits space.quest_logic.recovery;
//------------------------------------------------
// Constants
//------------------------------------------------
// Strings
const string_id SID_ABANDONED_RESCUE = new string_id( "space/quest", "rescue_abandoned" );
//------------------------------------------------
// OnAttach
//------------------------------------------------
trigger OnAttach()
{
// Set up quest specific objvars.
string questName = getStringObjVar( self, space_quest.QUEST_NAME );
string questType = getStringObjVar( self, space_quest.QUEST_TYPE );
obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER );
if ( (questName == null) || (questType == null) )
{
// Failed to find basic quest info.
return SCRIPT_OVERRIDE;
}
string qTable = "datatables/spacequest/"+questType+"/"+questName+".iff";
dictionary questInfo = dataTableGetRow( qTable, 0 );
if ( questInfo == null )
{
// Failed to find quest info.
sendSystemMessageTestingOnly( player, "Debug: Failed to open quest table "+qTable );
return SCRIPT_OVERRIDE;
}
// Determine the amount of time to elapse before arrival.
setObjVar( self, "targetArrivalDelay", questInfo.getInt("targetArrivalDelay") );
// Determine the amount of time to elapse before conversion.
setObjVar( self, "targetRecoverTime", questInfo.getInt("targetRecoverTime") );
// Determine the type of ship being rescued.
string targetShip = questInfo.getString("targetShipType");
if ( targetShip != null )
setObjVar( self, "targetShipType", targetShip );
// Get attack info.
int numAttackShipLists = questInfo.getInt( "numAttackShipLists" );
setObjVar( self, "numAttackShipLists", numAttackShipLists );
for ( int i=0; i<numAttackShipLists; i++ )
{
string[] attackShips = dataTableGetStringColumn( qTable, "attackShips"+(i+1) );
space_quest.cleanArray( self, "attackShips"+(i+1), attackShips );
}
setObjVar( self, "attackPeriod", questInfo.getInt( "attackPeriod" ) );
// Get our responses.
setObjVar( self, "numResponses", questInfo.getInt( "numResponses" ) );
// Get our recovery path.
string[] recoveryPath = dataTableGetStringColumn( qTable, "recoveryPath" );
space_quest.cleanArray( self, "recoveryPath", recoveryPath );
// Damage multiplier.
setObjVar( self, "damageMultiplier", questInfo.getInt( "damageMultiplier" ) );
// Rescue appearance.
string rescueApp = questInfo.getString( "rescueAppearance" );
if ( rescueApp != null )
{
setObjVar( self, "rescueAppearance", rescueApp );
}
// Try to notify the player of the first objective (if we are in the quest zone).
string questZone = getStringObjVar( self, space_quest.QUEST_ZONE );
if ( getCurrentSceneName().startsWith( questZone ) )
{
dictionary outparams = new dictionary();
outparams.put( "player", player );
messageTo( self, "initializedQuestPlayer", outparams, 1.f, false );
}
// Add quest journal objectives.
int questid = questGetQuestId( "spacequest/"+questType+"/"+questName );
if ( questid != 0 )
{
questActivateTask( questid, 0, player );
}
return SCRIPT_OVERRIDE;
}
//------------------------------------------------
// initializedQuestPlayer
//------------------------------------------------
messageHandler initializedQuestPlayer()
{
if ( params == null )
return SCRIPT_OVERRIDE;
// Set us up if we are in the appropriate zone.
string questZone = getStringObjVar( self, space_quest.QUEST_ZONE );
obj_id player = params.getObjId( "player" );
// Do not initialize quests if we are in a yacht.
obj_id containing_ship = space_transition.getContainingShip( player );
if ( isIdValid( containing_ship ) )
{
string strChassisType = getShipChassisType( containing_ship );
if ( (strChassisType != null) && strChassisType.equals( "player_sorosuub_space_yacht" ) )
{
return SCRIPT_CONTINUE;
}
}
if ( !getCurrentSceneName().startsWith( questZone ) )
{
if ( space_quest.isQuestInProgress( self ) )
{
clearMissionWaypoint( self );
space_quest.showQuestUpdate( self, SID_ABANDONED_RESCUE );
space_quest.setQuestFailed( player, self, false );
}
return SCRIPT_OVERRIDE;
}
if ( hasObjVar( self, "initialized" ) )
return SCRIPT_OVERRIDE;
// Determine the starting location of the target ship.
string[] recoveryPoints = getStringArrayObjVar( self, "recoveryPath" );
if ( recoveryPoints == null )
return SCRIPT_OVERRIDE;
string destPoint = recoveryPoints[0];
java.util.StringTokenizer st = new java.util.StringTokenizer( destPoint, ":" );
string scene = st.nextToken();
destPoint = st.nextToken();
if ( getCurrentSceneName().startsWith( scene ) )
findTargetStart( self, player, destPoint );
// Update the quest journal.
string questName = getStringObjVar( self, space_quest.QUEST_NAME );
string questType = getStringObjVar( self, space_quest.QUEST_TYPE );
int questid = questGetQuestId( "spacequest/"+questType+"/"+questName );
if ( questid != 0 )
{
setObjVar( self, "taskId", 1 );
questActivateTask( questid, 1, player );
if ( questIsTaskActive( questid, 0, player ) )
questCompleteTask( questid, 0, player );
}
return SCRIPT_OVERRIDE;
}
//------------------------------------------------
// warpInTarget
//------------------------------------------------
messageHandler warpInTarget()
{
obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER );
// Make sure we are still in the correct zone.
string questZone = getStringObjVar( self, space_quest.QUEST_ZONE );
if ( !getCurrentSceneName().startsWith( questZone ) )
return SCRIPT_OVERRIDE;
int squad = ship_ai.squadCreateSquadId();
// Create the target formation.
obj_id ship = createTargetShip( self );
space_quest._addMissionCriticalShip( player, self, ship );
ship_ai.unitSetSquadId( ship, squad );
setObjVar( self, "target", ship );
setObjVar( ship, "noNotifyDisable", 1 );
utils.setScriptVar( ship, "dockable", 1 );
setLookAtTarget( player, ship );
setObjVar( ship, "quest", self );
attachScript( ship, "space.quest_logic.rescue_target" );
ship_ai.unitSetAttackOrders( ship, ship_ai.ATTACK_ORDERS_HOLD_FIRE );
setObjVar( ship, "objMissionOwner", player );
ship_ai.unitAddExclusiveAggro( ship, player );
// Set the damage multiplier.
int dmult = getIntObjVar( self, "damageMultiplier" );
if ( dmult < 1 )
dmult = 1;
setObjVar( ship, "damageMultiplier", dmult );
// Set the ship's speed limits.
float maxspeed = getShipEngineSpeedMaximum( ship );
if ( maxspeed < 15.f )
setShipEngineSpeedMaximum( ship, 15.f + rand()*10.f );
else if ( maxspeed > 25.f )
setShipEngineSpeedMaximum( ship, 23.f + rand()*5.f );
// Disable the ship.
dictionary outp = new dictionary();
outp.put( "objShip", space_transition.getContainingShip( player ) );
messageTo( ship, "disableSelf", outp, 1.f, false );
// Set the pilot's appearance.
string rescueAppearance = getStringObjVar( self, "rescueAppearance" );
if ( rescueAppearance != null )
{
setObjVar( ship, "convo.appearance", rescueAppearance );
}
// Move the waypoint?
// This is a HACK.
messageTo( self, "updateTargetWaypoint", null, 1.f, false );
/*
// Set up the ship's patrol path.
transform[] translist = getPathTransforms( self, true );
ship_ai.unitAddPatrolPath( ship, translist );
dictionary outparams = new dictionary();
outparams.put( "quest", self );
outparams.put( "loc", getLocationObjVar( self, "last_loc" ) );
outparams.put( "player", player );
outparams.put( "dest", "escape" );
messageTo( ship, "registerDestination", outparams, 1.f, false );
*/
/*
// Warp in support ships.
string[] shipTypes = getStringArrayObjVar( self, "escortShips" );
obj_id[] escorts = new obj_id[shipTypes.length];
for ( int i=0; i<shipTypes.length; i++ )
{
// Spawn the escorts.
transform t = getTransform_o2w( ship );
transform spawnLoc = space_quest.getRandomPositionInSphere( t, 10, 20 );
escorts[i] = space_create.createShip( shipTypes[i], spawnLoc, null );
ship_ai.unitSetSquadId( escorts[i], squad );
// NEW AI CODE FOR FORMATIONS / FOLLOWING SHOULD GO HERE.
// Use the old stuff for now.
ship_ai.unitSetAttackOrders( escorts[i], ship_ai.ATTACK_ORDERS_RETURN_FIRE );
ship_ai.unitFollow( escorts[i], ship, new vector(0,0,1), 10 );
ship_ai.spaceGuard( escorts[i], ship );
}
setObjVar( self, "escorts", escorts );
ship_ai.squadSetLeader( squad, ship );
ship_ai.squadSetFormationRandom( squad );
*/
// Notify the player.
string questName = getStringObjVar( self, space_quest.QUEST_NAME );
string questType = getStringObjVar( self, space_quest.QUEST_TYPE );
string_id status_update = new string_id( "spacequest/"+questType+"/"+questName, "arrival_phase_2" );
questUpdate( self, status_update );
return SCRIPT_OVERRIDE;
}
//------------------------------------------------
// recoverShipDisabled
//------------------------------------------------
messageHandler recoverShipDisabled()
{
obj_id ship = getObjIdObjVar( self, "target" );
utils.setScriptVar( ship, "dockable", 1 );
return SCRIPT_OVERRIDE;
}
//------------------------------------------------
// dockingStarted
//------------------------------------------------
messageHandler dockingStarted()
{
obj_id target = params.getObjId( "target" );
obj_id ship = getObjIdObjVar( self, "target" );
if ( target != ship )
return SCRIPT_CONTINUE;
obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER );
string questName = getStringObjVar( self, space_quest.QUEST_NAME );
string questType = getStringObjVar( self, space_quest.QUEST_TYPE );
string_id status_update = new string_id( "spacequest/"+questType+"/"+questName, "docking_started" );
questUpdate( self, status_update );
status_update = new string_id( "spacequest/"+questType+"/"+questName, getCapturePhrase1( self ) );
prose_package pp = prose.getPackage( status_update, 0 );
space_quest.groupTaunt( ship, player, pp );
return SCRIPT_OVERRIDE;
}
string getCapturePhrase1( obj_id self )
{
return "rescue_phase_1";
}
//------------------------------------------------
// dockingComplete
//------------------------------------------------
messageHandler dockingComplete()
{
obj_id target = params.getObjId( "target" );
obj_id ship = getObjIdObjVar( self, "target" );
if ( target != ship )
return SCRIPT_CONTINUE;
obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER );
string questName = getStringObjVar( self, space_quest.QUEST_NAME );
string questType = getStringObjVar( self, space_quest.QUEST_TYPE );
string_id status_update = new string_id( "spacequest/"+questType+"/"+questName, "docking_complete" );
questUpdate( self, status_update );
status_update = new string_id( "spacequest/"+questType+"/"+questName, getCapturePhrase2( self ) );
prose_package pp = prose.getPackage( status_update, 0 );
space_quest.groupTaunt( ship, player, pp );
// Update the quest journal.
int questid = questGetQuestId( "spacequest/"+questType+"/"+questName );
if ( questid != 0 )
{
setObjVar( self, "taskId", 2 );
questActivateTask( questid, 2, player );
if ( questIsTaskActive( questid, 1, player ) )
questCompleteTask( questid, 1, player );
}
utils.removeScriptVar( ship, "dockable" );
messageTo( self, "startCapturedShipPathing", null, 10.f, false );
return SCRIPT_OVERRIDE;
}
string getCapturePhrase2( obj_id self )
{
return "rescue_phase_2";
}
//------------------------------------------------
// recoveryComplete
//------------------------------------------------
messageHandler recoveryComplete()
{
if ( params == null )
return SCRIPT_OVERRIDE;
string questName = getStringObjVar( self, space_quest.QUEST_NAME );
string questType = getStringObjVar( self, space_quest.QUEST_TYPE );
obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER );
obj_id ship = params.getObjId( "ship" );
// Notify the player.
string_id update = new string_id( "spacequest/"+questType+"/"+questName, "recovery_success" );
questUpdate( self, update );
// Update the quest journal.
int questid = questGetQuestId( "spacequest/"+questType+"/"+questName );
if ( questid != 0 )
{
if ( questIsTaskActive( questid, 2, player ) )
questCompleteTask( questid, 2, player );
}
// Warp the ship out.
string_id abort = new string_id( "spacequest/"+questType+"/"+questName, getCompletePhrase( self ) );
prose_package pp = prose.getPackage( abort, 0 );
space_quest.groupTaunt( ship, player, pp );
messageTo( self, "cleanupShipsMsg", null, 2.f, false );
messageTo( self, "completeQuestMsg", null, 3.f, false );
return SCRIPT_OVERRIDE;
}