iTrafficCreation and iScriptedOrders
19 years 7 months ago #12822
by Joco
Replied by Joco on topic iTrafficCreation and iScriptedOrders
Ok - pirate function as it currently stands. Any comments/thoughts?
New ini file to be placed in folder sims/explosions
Filename: ldsi_trap_explosion.ini
Code:
//
// By Joco.
//
// package iPirates
//
// iPirates.pog
//
// Package name ///////////////////////////////////////////////////////////////
package iPirates;
// Imports ////////////////////////////////////////////////////////////////////
// these are the packages were going to use
uses Debug, Global, Math, INIFile, Task, Sim, iAI, iSim, iShip, iGame, iUtilities, iTrafficCreation;
// Exports ////////////////////////////////////////////////////////////////////
// these are the functions that are going to be called from other packages
// n.b. these start with uppercase letters, no underscores
provides StartLDSPirates, StopLDSPirates;
// /Prototypes/Local functions ////////////////////////////////////////////////////////////
prototype task target_scanner(float scanball,
float disrupt_time,
int initial_attack_threshold,
int freighter_adjust,
int escort_adjust,
string pirate_grp_fn);
///////////////////////////////////////////////////////////////////////////////
// iPirates Code
///////////////////////////////////////////////////////////////////////////////
task target_scanner(float scanball,
float disrupt_time,
int initial_attack_threshold,
int freighter_adjust,
int escort_adjust,
string pirate_grp_fn)
{
// look for targets to hit with a pirate attack
set escorted_ships;
set escorted_freighters;
set defenders;
set stations;
hship ship;
hship player;
hsim attacker_waypoint;
bool do_raid;
int attack_threshold;
//float disrupt_time = 60.0;
//float scanball = 100km;
float last_pirate_attack = 0;
hgroup pirate_group;
hgroup target_group;
hsim blast;
schedule
{
every 5:
{
player = iShip.FindPlayerShip( );
attack_threshold = initial_attack_threshold;
if( Object.PropertyExists( player, "last_pirate_attack" ) )
{
last_pirate_attack = Object.FloatProperty( player, "last_pirate_attack" );
}
// we only need to look every so often.
debug Debug.PrintString(" Searching for Pirate targets. Time since last attack: " );
debug Debug.PrintFloat((iGame.GameTime() - last_pirate_attack));
debug Debug.PrintString( "\n" );
// Determine if exclusion conditions apply
stations = iSim.SimsInRadius( player, 1000km, T_Station );
if( iShip.IsInLDS( player ) && ((iGame.GameTime() - last_pirate_attack) > (60*2)) && (Set.IsEmpty(stations)) )
{
// try and find any ships along the players flight path that they might reasonably be escorting.
escorted_ships = iSim.SimsInRadius( player, scanball, TM_Ship );
escorted_freighters = iSim.SimsInRadius( player, scanball, T_Utility|T_Freighter|T_Passenger );
defenders = iSim.SimsInRadius( player, scanball, T_Fighter|T_Tug|T_Patcom|T_Interceptor|T_Corvette|T_Freighter|T_Destroyer|T_Cruiser|T_Carrier );
// do some semi random stuff to decide if will intercept the player.
attack_threshold += (Set.ItemCount( escorted_freighters ) * freighter_adjust); // + chance for each good target found
attack_threshold -= (Set.ItemCount( defenders ) * escort_adjust); // - chance for each defender found
do_raid = (Math.RandomInt(1,100) <= attack_threshold);
do_raid = do_raid && (!Set.IsEmpty(escorted_ships));
if( do_raid )
{
// we are going to do a pirate raid! So hit them with LDS Disrupt
debug Debug.PrintString( "PIRATE RAID!!\n" );
// add player to set of escorted ships
Set.Add( escorted_ships, player );
// save copy of set in a group
target_group = Group.FromSet( escorted_ships );
atomic
{
while( !Set.IsEmpty(escorted_ships) )
{
ship = iShip.Cast( Set.FirstElement(escorted_ships) );
iShip.DisruptLDSDrive( ship, disrupt_time );
Set.Remove( escorted_ships, ship );
}
}
//iShip.DisruptLDSDrive( player, disrupt_time );
if( Object.PropertyExists( player, "last_pirate_attack" ) )
Object.SetFloatProperty( player, "last_pirate_attack", iGame.GameTime() );
else
Object.AddFloatProperty( player, "last_pirate_attack", iGame.GameTime() );
//Task.Sleep( Task.Current(), 1 );
// show the explosion in game
blast = Sim.Create ( "ini:/sims/explosions/ldsi_trap_explosion", "Pirate Trap" );
if( blast == none )
debug Debug.PrintString( "blast effect handle is none\n" );
Sim.PlaceNear( blast, player, 100 );
// call the users custom pirate group create/manage script
Task.Detach( Task.Start( pirate_grp_fn ) );
}
}
}
}
}
StartLDSPirates(float scanball,
float disrupt_time,
int initial_attack_threshold,
int freighter_adjust,
int escort_adjust,
string pirate_grp_fn)
{
htask hmonitor;
if( Global.Exists( "pirate_task_handle" ) )
{
// already have a handle so should already have monitor task, 1 is enough
debug Debug.PrintString( "StartLDSPirates: tried to start more than one monitor task.\n" );
return;
}
hmonitor = start target_scanner(scanball, disrupt_time, initial_attack_threshold, freighter_adjust, escort_adjust, pirate_grp_fn);
Task.Detach( hmonitor );
// store handle in a global
Global.CreateHandle( "pirate_task_handle", GA_Read|GA_NoSave, hmonitor );
}
StopLDSPirates()
{
htask hmonitor;
if( Global.Exists( "pirate_task_handle" ) )
{
hmonitor = Task.Cast( Global.Handle( "pirate_task_handle" ) );
Task.Halt( hmonitor );
Global.Destroy( "pirate_task_handle" );
}
}
New ini file to be placed in folder sims/explosions
Filename: ldsi_trap_explosion.ini
Code:
;
; (c) 2000-2001 Particle Systems Ltd. All Rights Reserved
;
; ldsi_trap_explosion.ini
;
; Template for a 1m radius ldsi detonation used by LDSi missiles.
; This is intended to be used by the game, not directly by scripts.
; It is scaled according to the missile's properties.
;
; Revision control information:
; 24-May-2005:Joco: Modified to be an ldsi trap explosion for iPirate use.
;
; $Header: /iwar2/resource/sims/explosions/ldsi_missile_explosion.ini 1 11/04/01 22:34 Will $
;
[Class]
name=icShockwave
[Properties]
; Explosion final radius in metres
final_radius=15000.0
; Explosion lifetime
lifetime = 5.0
; Depth of the explosion front, as a percentage of the radius
front_depth = 0.1
; How much damage per second does the explosion do at the start?
initial_damage_rate = 0
; This is an ldsi explosion
ldsi=1
Please Log in or Create an account to join the conversation.
- GrandpaTrout
- Offline
- King of Space
19 years 7 months ago #12827
by GrandpaTrout
Replied by GrandpaTrout on topic iTrafficCreation and iScriptedOrders
Good work. So it worked better to just disrupt each one. I think it would be a good idea to put that little loop into an atomic statement block - just to be sure no other tasks can slip in between and scatter the ships.
I will give this a try on Sunday (company visiting this week, cutting into my game time!)
I will give this a try on Sunday (company visiting this week, cutting into my game time!)
Please Log in or Create an account to join the conversation.
19 years 7 months ago #12828
by Joco
Replied by Joco on topic iTrafficCreation and iScriptedOrders
Ok - will probably have posted an updated version of code by then.
I need to add in the atomic, lds disrupt effect and 1000km gap from station check.
--- edit ---
Add these in now, code post has been updated. But the I can't seem to get the disrupt effect to appear. Any help on what I am doing wrong there would be great.
Cheers,
Joco.
I need to add in the atomic, lds disrupt effect and 1000km gap from station check.
--- edit ---
Add these in now, code post has been updated. But the I can't seem to get the disrupt effect to appear. Any help on what I am doing wrong there would be great.
Cheers,
Joco.
Please Log in or Create an account to join the conversation.
- GrandpaTrout
- Offline
- King of Space
19 years 6 months ago #12836
by GrandpaTrout
Replied by GrandpaTrout on topic iTrafficCreation and iScriptedOrders
I don't think the LDS disrupt has a visual effect. (crackles and sparks). Unless you mean the green explosion effect. What you could do is create an LDS Mine and drop it in the middle of the unmoving ships (say, a second or two after the disrupt effect). Then the player will get to see the shockwave pass over the ships. Just an idea.
Please Log in or Create an account to join the conversation.
19 years 6 months ago #12840
by Joco
Replied by Joco on topic iTrafficCreation and iScriptedOrders
Yeah refering to the green explosion like stuff. Have a look at the code and you will see how I was trying to do it with an explosion effect.
Please Log in or Create an account to join the conversation.
19 years 6 months ago #12841
by MajorTom
Replied by MajorTom on topic iTrafficCreation and iScriptedOrders
The blast method will definately work. We have lots of explosions in the MP scripts that use the same method. You could do a debug (Debug.PrintHandle) to be sure if "blast" was created. Maybe there is something wrong with your ini file or the path.
I dunno, but it could be that Sim.PlaceInFrontOf can't be used to place a new sim in the game for the first time. If thats the case, try Sim.PlaceAt or Sim.PlaceBetween.
Iwar2 Multiplayer Fan Site
I dunno, but it could be that Sim.PlaceInFrontOf can't be used to place a new sim in the game for the first time. If thats the case, try Sim.PlaceAt or Sim.PlaceBetween.
Iwar2 Multiplayer Fan Site
Please Log in or Create an account to join the conversation.