//------------------------------------------------ // salvage.script // William Wallace //------------------------------------------------ /* - Spawn a ship to be salvaged. */ //------------------------------------------------ // 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" ); const string_id SID_REMAINDER_UPDATE = new string_id( "space/quest", "mining_remainder_update" ); //------------------------------------------------ // 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 how many resources are to be salvaged from this ship, and of what type setObjVar( self, "salvageResources", questInfo.getInt("salvageResources") ); setObjVar( self, "salvageResourceType", questInfo.getString("salvageResourceType") ); setObjVar( self, "currentCount", 0); // Determine the type of ship being salvaged. 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= salvageCount ) { questCompleted( self ); } int msgCount = getIntObjVar( self, "msgCount" ); if ( currentCount > (.50 * salvageCount ) && currentCount < (.75 * salvageCount) && msgCount == 1) { setObjVar(self, "msgCount", 0); messageTo( self, "launchAttack", null, 0, false ); space_quest.showQuestUpdate( self, SID_REMAINDER_UPDATE, salvageCount-currentCount ); } else if ( currentCount > (.25 * salvageCount ) && currentCount < (.50 * salvageCount) && msgCount == 2) { setObjVar(self, "msgCount", 1); messageTo( self, "launchAttack", null, 0, false ); space_quest.showQuestUpdate( self, SID_REMAINDER_UPDATE, salvageCount-currentCount ); } else if ( currentCount > (0) && currentCount < (.25 * salvageCount) && msgCount == 3) { setObjVar(self, "msgCount", 2); messageTo( self, "launchAttack", null, 0, false ); space_quest.showQuestUpdate( self, SID_REMAINDER_UPDATE, salvageCount-currentCount ); } } return SCRIPT_CONTINUE; } //------------------------------------------------ // launchAttack //------------------------------------------------ messageHandler launchAttack() { // Abort if the ship already arrived or hasn't shown up yet. if ( !hasObjVar( self, "initialized" ) || !hasObjVar( self, "target" ) ) return SCRIPT_CONTINUE; // if ( !hasObjVar( self, "attacksok" ) ) // { // int attackPeriod = getIntObjVar( self, "attackPeriod" ); // messageTo( self, "launchAttack", null, attackPeriod, false ); // return SCRIPT_CONTINUE; // } // It's time to launch an attack on the convoy. 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 ); // Gather the info we need to spawn. obj_id ship = getObjIdObjVar( self, "target" ); if ( !isIdValid( ship ) || !exists( ship ) ) return SCRIPT_CONTINUE; int numAttackShipLists = getIntObjVar( self, "numAttackShipLists" ); if ( numAttackShipLists == 0 ) return SCRIPT_CONTINUE; // Use attack lists incrementally. int attack = getIntObjVar( self, "attackindex" ); if ( (attack < 1) || (attack > numAttackShipLists) ) attack = 1; setObjVar( self, "attackindex", attack+1 ); if ( getIntObjVar( self, "attackListType" ) == 1 ) attack = rand( 1, numAttackShipLists ); string[] shipList = getStringArrayObjVar( self, "attackShips"+attack ); if ( shipList == null ) return SCRIPT_CONTINUE; int count = shipList.length; int k = 0; obj_id[] targets = null; obj_id[] oldtargets = getObjIdArrayObjVar( self, "targets" ); if ( oldtargets == null ) targets = new obj_id[count]; else { targets = new obj_id[count+oldtargets.length]; k = oldtargets.length; // Copy old targets into buffer. for ( int i=0; i 3 ) ship_ai.unitSetSquadId( newship, squad ); attachScript( newship, "space.quest_logic.dynamic_ship" ); attachScript( newship, "space.quest_logic.destroyduty_ship" ); targets[i] = newship; setObjVar( newship, "quest", self ); space_quest._addMissionCriticalShip( player, self, newship ); setObjVar( newship, "objMissionOwner", player ); ship_ai.unitAddExclusiveAggro( newship, player ); obj_id playerShip = getPilotedShip(player); ship_ai.spaceAttack( newship, playerShip); // Mark the ship with its wave. j++; if ( j >= shipList.length ) j = 0; } setObjVar( self, "targets", targets ); // Set a formation. if ( count > 3 ) ship_ai.squadSetFormationRandom( squad ); // Notify the player. string_id attack_notify = new string_id( "spacequest/"+questType+"/"+questName, "attack_notify" ); space_quest.sendQuestMessage( player, attack_notify ); playClientEffectObj( player, SOUND_SPAWN_WAVE, player, "" ); return SCRIPT_CONTINUE; } void questAborted( obj_id self ) { // Clear the mission waypoint. clearMissionWaypoint( self ); // We finished the quest! obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER ); space_quest.setQuestAborted( player, self ); } messageHandler abortMission() { if ( hasObjVar( self, "noAbort" ) ) return SCRIPT_CONTINUE; // We aborted the mission, warp the escort ship out. obj_id player = getObjIdObjVar( self, space_quest.QUEST_OWNER ); obj_id ship = getObjIdObjVar( self, "target" ); if ( isIdValid( ship ) && exists( ship ) ) { if ( hasObjVar( self, "captured" ) ) { string questName = getStringObjVar( self, space_quest.QUEST_NAME ); string questType = getStringObjVar( self, space_quest.QUEST_TYPE ); string_id abort = new string_id( "spacequest/"+questType+"/"+questName, "abort" ); prose_package pp = prose.getPackage( abort, 0 ); space_quest.groupTaunt( ship, player, pp ); messageTo( ship, "missionAbort", null, 2.f, false ); } else { messageTo( ship, "missionAbort", null, 10.f, false ); } // Warp out the remaining escort fighters. obj_id[] escorts = getObjIdArrayObjVar( self, "escorts" ); if ( escorts != null ) { for ( int i=0; i