Code: Select all
task boarding_handler( hsim attacker, hsim defender, bool is_station )
{
hisim boarding_ship = iSim.Cast( attacker );
hisim boarded_ship = iSim.Cast( defender );
hfaction boarding_faction = iSim.Faction( boarding_ship );
hfaction boarded_faction = iSim.Faction( boarded_ship );
hgroup boarding_ship_group = Sim.Group( boarding_ship );
hgroup boarded_ship_group = Sim.Group( boarded_ship );
float count;
int attackers;
int defenders;
int sim_type;
int max_crew = FindMaxCrew( boarded_ship );
int available_attackers;
debug Debug.PrintString( "iFleet.boarding_handler Started\n" );
schedule
{
every 2 :
{
if ( iSim.IsDockedTo( boarding_ship, boarded_ship ) )
{
iSim.SetDockingLock( boarding_ship, boarded_ship, true );
break;
}
else
{
if ( Object.BoolProperty( boarding_ship, "boarding_underway" ) == false )
{
debug Debug.PrintString( "iFleet.BoardingHandler Ship has been readded to wingman list, aborting.\n" );
iAI.PurgeOrders( boarding_ship );
Object.RemoveProperty( boarding_ship, "boarding_underway" );
iHUD.Print ( "BOARDING ATTEMPT CANCELLED" );
iHUD.PlayAudioCue( AC_InvalidInput );
return;
}
}
}
}
if ( is_station == false )
{ // This sets the 'penalties' for boarding a ship
if ( boarding_ship_group == false )
{
boarding_ship_group = Group.Create( );
Group.AddSim( boarding_ship_group, boarding_ship );
}
if ( boarded_ship_group )
{
for ( count = 0; count < Group.SimCount( boarded_ship_group ); ++count )
{
iSim.SetHostile( iSim.Cast( Group.NthSim( boarded_ship_group, count ) ), true );
}
iAI.GiveAttackOrder( boarded_ship_group, boarding_ship_group );
}
else
{
iSim.SetHostile( boarded_ship, true );
iAI.GiveAttackOrder( boarded_ship, boarding_ship_group );
}
if ( boarding_ship_group )
{
Group.Destroy( boarding_ship_group, false );
}
IncrementCurrentFactionFeelings( boarding_faction,
boarded_faction,
-( Object.FloatProperty( boarded_ship, "threat" ) / 100 ) );
IncrementCurrentFactionFeelings( boarded_faction,
boarding_faction,
-( Object.FloatProperty( boarded_ship, "threat" ) / 100 ) );
} // end of if not station
Task.Sleep( Task.Current(), Object.FloatProperty( boarded_ship, "armour" ) / 10 );
// Launch the boarding action if not already done
if ( Object.PropertyExists( boarded_ship, "attacker_count" ) == false )
{
Object.AddIntProperty( boarded_ship, "attacker_count", 0 );
// Give a starting message based on the initial ratio
if ( CrewCount( CT_EMarines, boarded_ship ) != 0 )
count = CrewCount( CT_Marines, boarding_ship ) / CrewCount( CT_Marines, boarded_ship );
else
count = 2;
if ( !is_station )
{
if ( count < .75 )
iConversation.OneLiner( boarded_ship, "ifleet_boarding_team", "ifleet_boarding_team_enter_ship_message_1" );
if ( count >= .75 && count <= 1.33 )
iConversation.OneLiner( boarded_ship, "ifleet_boarding_team", "ifleet_boarding_team_enter_ship_message_3" );
if ( count > 1.33 )
iConversation.OneLiner( boarded_ship, "ifleet_boarding_team", "ifleet_boarding_team_enter_ship_message_2" );
}
else
{
if ( count < .75 )
iConversation.OneLiner( boarded_ship, "ifleet_boarding_team", "ifleet_boarding_team_enter_station_message_1" );
if ( count >= .75 && count <= 1.33 )
iConversation.OneLiner( boarded_ship, "ifleet_boarding_team", "ifleet_boarding_team_enter_station_message_3" );
if ( count > 1.33 )
iConversation.OneLiner( boarded_ship, "ifleet_boarding_team", "ifleet_boarding_team_enter_station_message_2" );
}
Task.Detach( start BoardingAction( boarded_ship, boarding_faction, is_station, true ) );
}
// move marines over to the boarded_ship/station
do
{
// multiple catch to stop moving marines when it makes no sense to do so
if( iSim.IsDying( boarding_ship ) ||
iSim.IsDying( boarded_ship ) ||
iSim.IsDockedTo( boarding_ship, boarded_ship ) == false )
{
break;
}
atomic
{
available_attackers = CrewCount( CT_Marines, boarding_ship );
attackers = CrewCount( CT_EMarines, boarded_ship );
// move some marines from the attacking ship to the defending one
// we'll say no more than 4 at a time, and no more than the max crew of the boarded ship
if ( available_attackers > 4 )
available_attackers = 4;
if ( available_attackers > ( max_crew - attackers ) )
available_attackers = ( max_crew - attackers );
AdjustCrewCount( CT_Enemy, boarded_ship, available_attackers );
AdjustCrewCount( CT_Marines, boarding_ship, -available_attackers );
}
Task.Sleep( Task.Current(), .7 );
} while( available_attackers != 0 && Object.PropertyExists( boarded_ship, "attacker_count" ) );
iSim.SetDockingLock( boarding_ship, boarded_ship, false ); // Enables the two ships to undock
iSim.Undock( boarding_ship, iShip.Cast( boarded_ship ) ); // Forcefully undocks both ships
Object.RemoveProperty( boarding_ship, "boarding_underway" );
}
CaptureShip( hship ship, hfaction faction, bool player )
{
list fleet_list;
string string1;
string string2;
int number;
int crew;
int selection;
int prisoners;
float feeling;
hfaction original_faction = iSim.Faction( ship );
iSim.SetFaction( ship, faction ); // Sets the boarded ships faction to the boarding ship
Sim.SetCullable( ship, false );
iAI.PurgeOrders( ship );
if ( !player ) return;
atomic // add ship to fleet list, record it's index number and previous faction
{
fleet_list = Global.List( "g_player_fleet_list" );
List.AddTail ( fleet_list, ship );
Global.SetList ( "g_player_fleet_list", fleet_list );
number = Global.Int( "g_player_ship_index" ) + 1;
Object.AddIntProperty( ship, "if_fleet_index", number );
Global.SetInt( "g_player_ship_index", number );
Object.AddStringProperty( ship, "if_orig_fac", iFaction.Name( original_faction ) );
}
iHUD.Print( String.Join( Object.StringProperty ( ship, "name" ), " has been captured." ) );
debug atomic
{
Debug.PrintString( "iFleet.boarding_handler Boarding Action Successful " );
Debug.PrintString( Object.StringProperty ( ship, "name" ) );
Debug.PrintString( " captured.\n" );
}
ToggleShipToWingmanGroup( ship, Global.Int( "g_if_player_currently_selected_group" ) ); // adds the boarded ship to player group
iSim.SetHostile( ship, false );
Global.SetInt( "g_if_player_hate_index", Global.Int( "g_if_player_hate_index" ) + Object.FloatProperty( ship, "threat" ) );
debug Debug.PrintString( String.FormatInt( "iFleet.BoardingHandler - Player hate index set to %d.\n", Global.Int( "g_if_player_hate_index" ) ) );
feeling = iFaction.Feeling( original_faction,
faction );
crew = FindCrewCount( ship );
number = crew * ( ( feeling + 1 ) * Math.Random( 0.2, 0.4 ) );
prisoners = crew - number;
AdjustCrewCount( CT_Crew, ship, -prisoners );
string1 = Text.Field( "ifleet_boarding_conversation_we_found_crew", FT_Text );
string1 = String.FormatInt( string1, crew );
iConversation.OneLiner( ship, "ifleet_boarding_team", string1 );
Task.Sleep( Task.Current(), 3 );
string2 = Text.Field( "ifleet_boarding_conversation_willing_to_join", FT_Text );
string2 = String.FormatInt( string2, number );
iConversation.OneLiner( ship, "ifleet_boarding_team", string2 );
Task.Sleep( Task.Current(), 3 );
iConversation.Begin();
iConversation.AddResponse( "ifleet_boarding_conversation_option_1", "ifleet_boarding_conversation_option_1" );
iConversation.AddResponse( "ifleet_boarding_conversation_option_2", "ifleet_boarding_conversation_option_2" );
iConversation.AddResponse( "ifleet_boarding_conversation_option_3", "ifleet_boarding_conversation_option_3" );
selection = iConversation.Ask( ship, "ifleet_boarding_team", String.Join( string1, string2 ) );
iConversation.End();
switch( selection )
{
case 0:
iConversation.OneLiner( ship, "ifleet_boarding_team", "We are releasing the prisoners." );
break;
case 1:
iConversation.OneLiner( ship, "ifleet_boarding_team", "The prisoners have been placed under guard." );
AdjustCrewCount( CT_Prisoners, ship, prisoners );
IncrementCurrentFactionFeelings( original_faction, faction, -(prisoners*0.001) );
break;
case 2:
iConversation.OneLiner( ship, "ifleet_boarding_team", "The prisoners are being eliminated." );
Global.SetInt( "g_if_player_hate_index", Global.Int( "g_if_player_hate_index" ) + prisoners );
IncrementCurrentFactionFeelings( original_faction, faction, -(prisoners*0.005) );
break;
}
}