//------------------------------------------------ // convoy.script // Brandon Reinhart // // Protect the convoy of ships as they path through the system. // Group mission. //------------------------------------------------ //------------------------------------------------ // Includes //------------------------------------------------ include library.space_create; include library.space_quest; include library.space_utils; include library.space_transition; include library.utils; include library.ship_ai; include library.prose; include library.group; include library.money; //------------------------------------------------ // Inherits //------------------------------------------------ inherits space.quest_logic.escort; //------------------------------------------------ // Constants //------------------------------------------------ // Strings const string_id SID_CONVOY_SURVIVED = new string_id( "space/quest", "convoy_survived" ); const string_id SID_CONVOY_PERFECT = new string_id( "space/quest", "convoy_perfect" ); //------------------------------------------------ // 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. LOG("convoy_quest", "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. LOG("convoy_quest", "Failed to find more quest info"); sendSystemMessageTestingOnly( player, "Debug: Failed to open quest table "+qTable ); return SCRIPT_CONTINUE; } // Get the number of convoy ships to spawn on this mission. setObjVar( self, "convoySize", questInfo.getInt( "convoySize" ) ); setObjVar( self, "originalConvoySize", questInfo.getInt( "convoySize" ) ); // Get the delay between ships' arrival. setObjVar( self, "arrivalDelay", questInfo.getInt( "arrivalDelay" ) ); // Get the rewards. setObjVar( self, "arrivalReward", questInfo.getInt( "arrivalReward" ) ); setObjVar( self, "perfectReward", questInfo.getInt( "perfectReward" ) ); // Determine the types of ships for escort. string[] rawEscortShipTypes = dataTableGetStringColumn( qTable, "escortShipTypes" ); if ( rawEscortShipTypes == null ) { rawEscortShipTypes = new string[1]; rawEscortShipTypes[0] = questInfo.getString( "escortShipType" ); if ( rawEscortShipTypes == null ) { sendSystemMessageTestingOnly( player, "Debug: escortShipTypes are missing from "+qTable ); return SCRIPT_CONTINUE; } } space_quest.cleanArray( self, "escortShipTypes", rawEscortShipTypes ); // Get our escort point list. string[] rawEscortPoints = dataTableGetStringColumn( qTable, "escortPoints" ); if ( rawEscortPoints == null ) { rawEscortPoints = dataTableGetStringColumn( qTable, "escortPath" ); if ( rawEscortPoints == null ) { sendSystemMessageTestingOnly( player, "Debug: escortPoints are missing from "+qTable ); return SCRIPT_CONTINUE; } } space_quest.cleanArray( self, "escortPoints", rawEscortPoints ); // Get our responses. setObjVar( self, "numResponses", questInfo.getInt( "numResponses" ) ); // Get attack info. int numAttackShipLists = questInfo.getInt( "numAttackShipLists" ); setObjVar( self, "numAttackShipLists", numAttackShipLists ); for ( int i=0; i 25.f ) // setShipEngineSpeedMaximum( ship, 23.f + rand()*5.f ); // Store our current convoy list. obj_id[] newConvoy; if ( convoy == null ) { newConvoy = new obj_id[1]; newConvoy[0] = ship; } else { newConvoy = new obj_id[convoy.length+1]; for ( int i=0; i 0 ) { dictionary outparamss = new dictionary(); outparamss.put( "code", getIntObjVar( self, "attackcode" ) ); messageTo( self, "launchAttack", outparamss, attackPeriod, false ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // cleanupShips //------------------------------------------------ void cleanupShips( obj_id self ) { // Warp out the convoy. obj_id[] convoy = getObjIdArrayObjVar( self, "convoy" ); if ( convoy != null ) { for ( int i=0; i= 0 ) { for ( int i=0; i numAttackShipLists) ) attack = 1; setObjVar( self, "attackindex", attack+1 ); if ( getIntObjVar( self, "attackListType" ) == 1 ) attack = rand( 1, numAttackShipLists ); string[] shipList = getStringArrayObjVar( self, "attackShips"+attack ); int count = shipList.length; // Update the "targets" list. 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; for ( int x=0; x= shipList.length ) j = 0; } // Record this wave count. setObjVar( self, "wave"+wavenum, count ); // Set a formation. if ( count > 3 ) ship_ai.squadSetFormationRandom( squad ); setObjVar( self, "targets", targets ); // 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, "" ); // The ship should say something. int reasons = getIntObjVar( self, "numResponses" ); string_id hello = new string_id( "spacequest/"+questType+"/"+questName, "panic_" + rand( 1, reasons ) ); prose_package pp = prose.getPackage( hello, 0 ); space_quest.groupTaunt( ship, player, pp ); // Launch another attack. int attackPeriod = getIntObjVar( self, "attackPeriod" ); dictionary outparamss = new dictionary(); outparamss.put( "code", getIntObjVar( self, "attackcode" ) ); messageTo( self, "launchAttack", outparamss, attackPeriod, false ); return SCRIPT_OVERRIDE; }