//------------------------------------------------ // destroy.script // Brandon Reinhart // // Kill of . //------------------------------------------------ //------------------------------------------------ // Includes //------------------------------------------------ include library.space_quest; include library.space_utils; include library.space_transition; include library.utils; //------------------------------------------------ // Constants //------------------------------------------------ // Strings const string_id SID_REMAINDER_UPDATE = new string_id( "space/quest", "destroy_remainder_update" ); const string_id SID_TARGET_WAYPOINTS = new string_id( "space/quest", "destroy_target_waypoints" ); const string_id SID_ABANDONED_DESTROY = new string_id( "space/quest", "destroy_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 = utils.getContainingPlayer(self); if ( (questName == null) || (questType == null) ) { // Failed to find basic quest info. return SCRIPT_CONTINUE; } 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_CONTINUE; } // Determine the types of ships to destroy. string[] ships = dataTableGetStringColumn( qTable, "shipList" ); space_quest.cleanArray( self, "shipTypes", ships ); // Determine the number of ships we have to destroy, modified by a variance. int killCount = questInfo.getInt( "killCount" ); int killVariance = questInfo.getInt( "killVariance" ); if ( killVariance > 0 ) { if ( rand() >= 0.5 ) killCount += rand( 1, killVariance ); else if ( rand() < 0.5 ) killCount -= rand( 1, killVariance ); } setObjVar( self, "killCount", killCount ); setObjVar( self, "maxCount", killCount ); questSetQuestTaskCounter(player, "spacequest/"+questType+"/"+questName, 1, "quest/groundquests:destroy_counter", 0, killCount); // Store a list of our valid source spawners. string[] spawns = dataTableGetStringColumn( qTable, "validSpawns" ); space_quest.cleanArray( self, "validSpawns", spawns ); int give_waypoint = questInfo.getInt( "giveSpawnWaypoint" ); setObjVar( self, "give_waypoint", give_waypoint ); int spawnsForWaypointsOnly = questInfo.getInt( "spawnsForWaypointsOnly" ); setObjVar( self, "spawnsForWaypointsOnly", spawnsForWaypointsOnly ); // Add quest journal objectives. int questid = questGetQuestId( "spacequest/"+questType+"/"+questName ); if ( questid != 0 ) { questActivateTask( questid, 0, player ); } // Notify the player of the first objective (if we are already 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 ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // initializedQuestPlayer //------------------------------------------------ messageHandler initializedQuestPlayer() { if ( params == null ) return SCRIPT_CONTINUE; // Set us up if we are in the appropriate zone. string questName = getStringObjVar( self, space_quest.QUEST_NAME ); string questType = getStringObjVar( self, space_quest.QUEST_TYPE ); 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 ) ) { clearTargetWaypoints( self ); space_quest.showQuestUpdate( self, SID_ABANDONED_DESTROY ); space_quest.setQuestFailed( player, self, false ); } return SCRIPT_CONTINUE; } obj_id questManager = getNamedObject( space_quest.QUEST_MANAGER ); if ( questManager == null ) return SCRIPT_CONTINUE; int give_waypoint = getIntObjVar( self, "give_waypoint" ); string[] spawns = getStringArrayObjVar( self, "validSpawns" ); // Update the quest journal. int questid = questGetQuestId( "spacequest/"+questType+"/"+questName ); if ( questid != 0 ) { questActivateTask( questid, 1, player ); if ( questIsTaskActive( questid, 0, player ) ) questCompleteTask( questid, 0, player ); } if ( spawns == null ) return SCRIPT_CONTINUE; if ( hasObjVar( self, "target_waypoints" ) ) return SCRIPT_CONTINUE; int added = 0; for ( int i=0; i 0 ) { dictionary outparams = new dictionary(); outparams.put( "added", added ); messageTo( self, "notifyTargetWaypoints", outparams, 1.f, false ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // notifyTargetWaypoints //------------------------------------------------ messageHandler notifyTargetWaypoints() { int added = params.getInt( "added" ); space_quest.showQuestUpdate( self, SID_TARGET_WAYPOINTS, added ); return SCRIPT_CONTINUE; } //------------------------------------------------ // createdWaypointToSpawner //------------------------------------------------ messageHandler createdWaypointToSpawner() { if ( params == null ) return SCRIPT_CONTINUE; obj_id newpoint = params.getObjId( "waypoint" ); obj_id[] waypoints = getObjIdArrayObjVar( self, "target_waypoints" ); if ( waypoints == null ) { waypoints = new obj_id[1]; waypoints[0] = newpoint; setObjVar( self, "target_waypoints", waypoints ); } else { obj_id[] newlist = new obj_id[waypoints.length+1]; for ( int i=0; i