Files
dsrc/sku.0/sys.server/compiled/game/script/poi/prisonbreak/master.script
T

799 lines
21 KiB
Plaintext

/**
*
* Title: master.script
* Description: master poi object script: POI = prisonbreak
*/
//------------------------------------------------
// Includes
//------------------------------------------------
include library.poi;
include library.npc;
include library.scenario;
include library.debug;
include library.theater;
include library.ai_lib;
include library.utils;
//------------------------------------------------
// Inherits
//------------------------------------------------
inherits theme_park.poi.base;
//------------------------------------------------
// Constants
//------------------------------------------------
const string SCENARIO_NAME = "prisonbreak";
const string LOG_NAME = "poiPrisonBreak Master";
const string SCENARIO_THEATER = "object/building/poi//tatooine_prison_break.iff";
const string BASE_PATH = "poi." + SCENARIO_NAME;
const string SCRIPT_ANTAGONIST = BASE_PATH + ".antagonist";
const string SCRIPT_MEDIATOR = BASE_PATH + ".mediator";
const string SCRIPT_PRISONER = BASE_PATH + ".prisoner";
const string SCRIPT_CAPTOR = BASE_PATH + ".captor";
const string SCRIPT_CONVERSE = "npc.converse.npc_converse_menu";
const string TBL = "datatables/poi/" + SCENARIO_NAME + "/setup.iff";
const string MEDIATOR_EASY = "MEDIATOR_TEMPLATE_EASY";
const string MEDIATOR_MEDIUM = "MEDIATOR_TEMPLATE_MEDIUM";
const string MEDIATOR_HARD = "MEDIATOR_TEMPLATE_HARD";
const string MEDIATOR_TYPE = "MEDIATOR_TYPE";
const string ANTAGONIST_EASY = "ANTAGONIST_TEMPLATE_EASY";
const string ANTAGONIST_MEDIUM = "ANTAGONIST_TEMPLATE_MEDIUM";
const string ANTAGONIST_HARD = "ANTAGONIST_TEMPLATE_HARD";
const string ANTAGONIST_TYPE = "ANTAGONIST_TYPE";
const int DEFAULT_ANTAGONIST_COUNT = 1;
const int mediatorCoordsX[] = { -13, -16, -5, 3 };
const int mediatorCoordsZ[] = { 0, -20, 14, -18 };
const int MAX_DIFF = 70;
//------------------------------------------------
// Methods
//------------------------------------------------
//------------------------------------------------
// OnAttach
//------------------------------------------------
trigger OnAttach()
{
if ( !scenario.initScenario( self, TBL ) )
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnInitialize
//------------------------------------------------
trigger OnInitialize()
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnUnloadedFromMemory
//------------------------------------------------
trigger OnUnloadedFromMemory()
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// cleanupScenario
//------------------------------------------------
messageHandler cleanupScenario()
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// destroySelf
//------------------------------------------------
messageHandler destroySelf()
{
destroyObject( self );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// initScenario
//
// Called by message from OnAttach.
// This calls all methods necessary to set up the POI.
//------------------------------------------------
messageHandler initScenario()
{
// Validate parameters.
if ( (params == null) || (params.isEmpty()) )
{
scenario.cleanup(self);
return SCRIPT_CONTINUE;
}
/*
Environment Setup
*/
// Get our mediator types.
setObjVar( self, MEDIATOR_EASY, params.getString( MEDIATOR_EASY ) );
setObjVar( self, MEDIATOR_MEDIUM, params.getString( MEDIATOR_MEDIUM ) );
setObjVar( self, MEDIATOR_HARD, params.getString( MEDIATOR_HARD ) );
// Get our antagonist type.
setObjVar( self, ANTAGONIST_EASY, params.getString( ANTAGONIST_EASY ) );
setObjVar( self, ANTAGONIST_MEDIUM, params.getString( ANTAGONIST_MEDIUM ) );
setObjVar( self, ANTAGONIST_HARD, params.getString( ANTAGONIST_HARD ) );
// Get our difficulty level (we support 5 to 70).
// Easy 5-27
// Medium 28-47
// Hard 48-70
int difficultyLevel = getIntObjVar( self, "spawning.intDifficultyLevel" );
if ( difficultyLevel == 0 ) // Force for debug.
difficultyLevel = 5;
if ( (difficultyLevel >= 5) && (difficultyLevel < 28) )
{
// Prepare an easy scenario.
setObjVar( self, ANTAGONIST_TYPE, getStringObjVar( self, ANTAGONIST_EASY ) );
setObjVar( self, MEDIATOR_TYPE, getStringObjVar( self, MEDIATOR_EASY ) );
}
else if ( (difficultyLevel >= 28) && (difficultyLevel < 48) )
{
// Prepare a medium scenario.
setObjVar( self, ANTAGONIST_TYPE, getStringObjVar( self, ANTAGONIST_MEDIUM ) );
setObjVar( self, MEDIATOR_TYPE, getStringObjVar( self, MEDIATOR_MEDIUM ) );
}
else
{
// Cap at max difficulty?
if ( difficultyLevel > MAX_DIFF )
difficultyLevel = MAX_DIFF;
// Prepare a hard scenario.
setObjVar( self, ANTAGONIST_TYPE, getStringObjVar( self, ANTAGONIST_HARD ) );
setObjVar( self, MEDIATOR_TYPE, getStringObjVar( self, MEDIATOR_HARD ) );
}
// Create teams.
scenario.createTeam( self, "antagonist", self.toString() + "_antagonist" );
scenario.createTeam( self, "mediator", self.toString() + "_mediator" );
/*
Spawn Theaters
*/
if ( !createTheater( self ) )
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
/*
Spawn Antagonist
*/
if ( !createAntagonist( self ) )
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
if ( !createAntagonistMinions( self ) )
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
/*
Spawn Mediators
*/
if ( !createMediator( self ) )
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
if ( !createMediatorMinions( self ) )
{
scenario.cleanup( self );
return SCRIPT_CONTINUE;
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// createTheater
//
// Spawns the theater for the scenario.
//------------------------------------------------
boolean createTheater( obj_id self )
{
// Create the theater.
obj_id theater = poi.createObject( SCENARIO_THEATER, 0, 0 );
if ( (theater == null) || (theater == obj_id.NULL_ID) )
return false;
// Store theater reference.
setObjVar( self, "theater", theater );
return true;
}
//------------------------------------------------
// handleTheaterComplete
//
// Called when the theaters load.
//------------------------------------------------
messageHandler handleTheaterComplete()
{
/*
Finalize Theater
*/
// Get theater ref.
obj_id donetheater = params.getObjId( theater.DICT_MASTER );
// Attach destroyable wall scripts to the prison.
attachWallScripts( self, donetheater );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// attachWallScripts
//
// Attaches wall scripts to the prison walls.
// The scripts handle wall damage.
//------------------------------------------------
void attachWallScripts( obj_id self, obj_id prison )
{
if ( (prison == null) || (prison == obj_id.NULL_ID) )
return;
obj_id[] children = getObjIdArrayObjVar( prison, theater.VAR_CHILDREN );
if ( (children == null) || (children.length == 0) )
{
return;
}
else
{
int j = 0;
for ( int i = 0; i < children.length; i++ )
{
obj_id child = children[i];
if ( (child == null) || (child == obj_id.NULL_ID) )
{
}
else
{
// We found a child. See if it is a wall.
string childname = getName( child );
LOG (LOG_NAME, "Child found: Name = " + childname);
if ( childname.equals( "battlefield:barbed_wall" ) )
{
// Go ahead and attach the wall script.
if ( j == 0 )
{
// Load localization file and assign a name to the wall.
string convo = getStringObjVar( self, scenario.VAR_SCENARIO_CONVO );
if ( convo.equals("") )
return;
// The destroyable wall.
attachScript( child, "poi.prisonbreak.bombed_wall" );
// Store location.
location loc = getLocation( child );
setObjVar( self, "weakwallLoc", loc );
// Store reference.
setObjVar( self, "weakwall", child ); // Suppress linting - The lint script is incorrectly
} // catching this due to a similarly named arracy
else // This wall cannot be destroyed.
attachScript( child, "poi.factoryliberation.invulnerable_wall" );
// Set the wall's base object.
setObjVar( child, POI_BASE_OBJECT, self );
j++; // Increment wall count.
}
}
}
}
return;
}
//------------------------------------------------
// createAntagonist
//
// Creates the leader of the antagonist gang.
//------------------------------------------------
boolean createAntagonist( obj_id self )
{
// Spawn the scenario antagonist (pirate captain).
string type = getStringObjVar( self, ANTAGONIST_TYPE );
string ident = "antagonist_0";
location loc = getLocation( self );
loc.x += 5;
obj_id antagonist = scenario.createTeamNpc( self, "antagonist", type, ident, loc );
if ( (antagonist == null) || (antagonist == obj_id.NULL_ID) )
return false;
poi.setTitle( antagonist, "a_title" );
// Assign initial behavior to the antagonist.
attachScript( antagonist, SCRIPT_ANTAGONIST );
attachScript( antagonist, SCRIPT_PRISONER );
ai_lib.setDefaultCalmBehavior( antagonist, ai_lib.BEHAVIOR_SENTINEL );
return true;
}
//------------------------------------------------
// createAntagonistMinions
//
// Creates the rest of the antagonist group.
//------------------------------------------------
boolean createAntagonistMinions( obj_id self )
{
location baseloc = getLocation( self );
string type = getStringObjVar( self, ANTAGONIST_TYPE );
if ( !type.equals("") )
{
for ( int i = 0; i < 4; i++ )
{
string ident = "antagonist_" + (i + 1);
float xdelta = rand( 2f, 5f );
if ( i%2 == 1 )
xdelta *= -1f;
float zdelta = rand( 2f, 5f );
if ( i%2 == 0 )
zdelta *= -1f;
location loiterloc = new location( baseloc );
loiterloc.x += xdelta - 2;
loiterloc.z += zdelta - 2;
obj_id antagonist = scenario.createTeamNpc( self, "antagonist", type, ident, loiterloc );
if ( (antagonist == null) || (antagonist == obj_id.NULL_ID) )
{
LOG( LOG_NAME, "Couldn't create antagonist minion." );
}
else
{
setYaw( antagonist, rand(0, 359) );
attachScript( antagonist, SCRIPT_ANTAGONIST );
attachScript( antagonist, SCRIPT_PRISONER );
ai_lib.setDefaultCalmBehavior( antagonist, ai_lib.BEHAVIOR_SENTINEL ); //BEHAVIOR_LOITER );
ai_lib.setLoiterRanges( antagonist, 0, 2 );
}
}
}
return true;
}
//------------------------------------------------
// createMediator
//
// Creates the leader of the mediator group.
//------------------------------------------------
boolean createMediator( obj_id self )
{
// Spawn the scenario mediator (prisoner leader).
string type = getStringObjVar( self, MEDIATOR_TYPE );
string ident = "mediator_0";
location loc = getLocation( self );
loc.x += 1;
loc.z += 20;
obj_id mediator = scenario.createTeamNpc( self, "mediator", type, ident, loc );
if ( (mediator == null) || (mediator == obj_id.NULL_ID) )
return false;
poi.setTitle( mediator, "m_title" );
// Assign initial behavior to the mediator.
attachScript( mediator, SCRIPT_MEDIATOR );
attachScript( mediator, SCRIPT_CAPTOR );
ai_lib.setDefaultCalmBehavior( mediator, ai_lib.BEHAVIOR_SENTINEL );
return true;
}
//------------------------------------------------
// createMediatorMinions
//
// Creates the rest of the mediator group.
//------------------------------------------------
boolean createMediatorMinions( obj_id self )
{
location baseloc = getLocation( self );
string type = getStringObjVar( self, MEDIATOR_TYPE );
if ( !type.equals("") )
{
for ( int i = 0; i < 4; i++ )
{
string ident = "mediator_" + (i + 1);
location loiterloc = new location( baseloc );
loiterloc.x += mediatorCoordsX[i];
loiterloc.z += mediatorCoordsZ[i];
obj_id mediator = scenario.createTeamNpc( self, "mediator", type, ident, loiterloc );
if ( (mediator == null) || (mediator == obj_id.NULL_ID) )
{
LOG( LOG_NAME, "Couldn't create mediator minion." );
}
else
{
setYaw( mediator, rand(0, 359) );
attachScript( mediator, SCRIPT_MEDIATOR );
attachScript( mediator, SCRIPT_CAPTOR );
ai_lib.setDefaultCalmBehavior( mediator, ai_lib.BEHAVIOR_SENTINEL ); //BEHAVIOR_LOITER );
ai_lib.setLoiterRanges( mediator, 0, 3 );
// Make the first one a guard.
if ( i == 0 )
{
// Set the guard title.
poi.setTitle( mediator, "m_guard_title" );
ai_lib.setDefaultCalmBehavior( mediator, ai_lib.BEHAVIOR_SENTINEL );
setObjVar( mediator, "guard", true );
}
else
{
ai_lib.setDefaultCalmBehavior( mediator, ai_lib.BEHAVIOR_SENTINEL ); //BEHAVIOR_LOITER );
ai_lib.setLoiterRanges( mediator, 0, 3 );
}
}
}
}
return true;
}
//------------------------------------------------
// startAttack
//
// Called by the mediator script.
// The mediator guarding the pen goes to the restroom.
//------------------------------------------------
messageHandler startAttack()
{
// Find the guard and tell him to go pee.
obj_id guard = poi.findObject( "mediator_1" );
if ( (guard == null) || (guard == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
messageTo( guard, "goPee", null, 0, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// guardGone
//
// Called by the mediator script.
// The head antagonist orders the bombing of the target wall.
//------------------------------------------------
messageHandler guardGone()
{
// Find the leader antagonist and tell him to order the attack.
obj_id m = poi.findObject( "antagonist_0" );
if ( !isIdValid(m) )
return SCRIPT_CONTINUE;
messageTo( m, "attackWallLeader", null, 0, false );
// Make the leader stay still.
stop( m );
// Find our bomber.
obj_id a = poi.findObject( "antagonist_1" );
if ( !isIdValid(a) )
return SCRIPT_CONTINUE;
// Tag him as the bomber.
setObjVar( a, "bomber", true ); // Movement track.
setObjVar( a, "POIbomber", true ); // POI bomber track.
setObjVar( self, "bombPlan", true ); // Doing bomb plan.
// Find our move location.
location bombloc = getLocationObjVar( self, "weakwallLoc" );
if ( bombloc == null )
return SCRIPT_CONTINUE;
bombloc.z += -1.5f;
// Move to the wall.
detachScript( a, SCRIPT_CONVERSE );
setMovementRun( a );
ai_lib.aiPathTo( a, bombloc );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// blowBomb
//
// Called by the prisoner script.
// The bomb is set to blow, spawn an effect.
//------------------------------------------------
messageHandler blowBomb()
{
// Find the location of the bomb.
location bombloc = getLocationObjVar( self, "weakwallLoc" );
bombloc.z += -1.5;
// Spawn an explosion at that point.
obj_id players[] = getPlayerCreaturesInRange( bombloc, 40 );
for ( int i=0; i<players.length; i++ )
{
if ( (players[i] != null) && (players[i] != obj_id.NULL_ID) )
playClientEffectLoc( players[i], "clienteffect/combat_grenade_large_01.cef", bombloc, 0 );
}
// Destroy the wall real soon.
messageTo( self, "destroyBombedWall", null, 0.25f, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// blowDroppedBomb
//
// Called by the prisoner script.
// The guy dropped the bomb. Blow 'em all up.
//------------------------------------------------
messageHandler blowDroppedBomb()
{
// The player sabotaged the plan.
setObjVar( poi.getBaseObject(self), "playerSabotage", true );
// Find the location of the bomb.
location bombloc = getLocationObjVar( self, "weakwallLoc" );
bombloc.x += 5;
// Spawn an explosion at that point.
obj_id players[] = getPlayerCreaturesInRange( bombloc, 40 );
for ( int i=0; i<players.length; i++ )
{
if ( (players[i] != null) && (players[i] != obj_id.NULL_ID) )
playClientEffectLoc( players[i], "clienteffect/combat_grenade_large_01.cef", bombloc, 0 );
}
// Destroy the wall real soon.
messageTo( self, "destroyBombedWallDeath", null, 0.25f, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// destroyBombedWall
//
// Called by blowBomb.
// The bomb is going off, remove the wall.
//------------------------------------------------
messageHandler destroyBombedWall()
{
// Remove the wall now.
obj_id bombedWall = getBombedWall( self );
if ( (bombedWall == null) || (bombedWall == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
destroyObject( bombedWall );
// Find the leader and tell him to order an all out assault.
obj_id m = poi.findObject( "antagonist_0" );
if ( (m == null) || (m == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
messageTo( m, "attackEveryone", null, 0, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// destroyBombedWallDeath
//
// Called by blowDroppedBomb.
// A variation that kills everyone.
//------------------------------------------------
messageHandler destroyBombedWallDeath()
{
// Remove the wall now.
obj_id bombedWall = getBombedWall( self );
if ( (bombedWall == null) || (bombedWall == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
destroyObject( bombedWall );
// Kill some of them, injure the rest.
obj_id[] antagonists = scenario.getTeamMembers( self, "antagonist" );
if ( antagonists == null )
return SCRIPT_CONTINUE;
for ( int i=0; i<antagonists.length; i++ )
{
// Find this guy.
obj_id found = antagonists[i];
if ( (found == null) || (found == obj_id.NULL_ID) )
continue;
if ( isIncapacitated( found ) || isDead( found ) )
continue;
if ( i%2 == 1 )
{
// Kill him.
setHealth( found, -50 );
}
else
{
// Just injure him.
setHealth( found, getMaxHealth( found ) / 3 );
}
}
// Find the leader and tell him to order an all out assault.
obj_id m = poi.findObject( "antagonist_0" );
if ( (m == null) || (m == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
dictionary parms = new dictionary();
parms.put( "idiot", true );
messageTo( m, "attackEveryone", parms, 0, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleActorDeath
//
// Called by the antagonist script.
// Used to track antagonist deaths.
//------------------------------------------------
messageHandler handleActorDeath()
{
if ( params == null )
return SCRIPT_CONTINUE;
obj_id actor = params.getObjId( scenario.DICT_OBJID );
string name = params.getString( scenario.DICT_NAME );
string type = params.getString( "type" );
string deadlist;
if ( type.equals( "antagonist" ) )
deadlist = scenario.VAR_SCENARIO_DEAD_ANTAGONIST;
else
deadlist = scenario.VAR_SCENARIO_DEAD_MEDIATOR;
// Add this poor SOB to the list of the dead.
resizeable string[] dead = getResizeableStringArrayObjVar( self, deadlist );
dead = utils.addElement( dead, name );
if(dead.length > 0) { // Zero length array check
setObjVar( self, deadlist, dead );
} else {
if(hasObjVar(self, deadlist)) {
removeObjVar(self, deadlist);
}
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// getBombedWall
//
// Returns reference to the wall to bomb.
//------------------------------------------------
obj_id getBombedWall( obj_id self )
{
obj_id myTheater = getObjIdObjVar( self, "theater" );
if ( (myTheater == null) || (myTheater == obj_id.NULL_ID) )
return null;
obj_id[] children = getObjIdArrayObjVar( myTheater, theater.VAR_CHILDREN );
if ( (children == null) || (children.length == 0) )
{
return null;
}
else
{
int j = 0;
for ( int i = 0; i < children.length; i++ )
{
obj_id child = children[i];
if ( (child == null) || (child == obj_id.NULL_ID) )
{
}
else
{
// We found a child. See if it is a wall.
string childname = getName( child );
if ( childname.equals( "battlefield:barbed_wall" ) )
{
// Return the one we want.
if ( j == 0 )
return child;
j++; // Increment wall count.
}
}
}
}
return null;
}
//------------------------------------------------
// enableBombedWall
//
// We should enable the wall to be bombed.
//------------------------------------------------
messageHandler enableBombedWall()
{
// Get reference to wall.
obj_id weakwall = getObjIdObjVar( self, "weakwall" );
if ( (weakwall == null) || (weakwall == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
// Tell the wall to enable.
messageTo( weakwall, "enableBombedWall", null, 0, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// wallDamaged
//
// Called by weakened wall.
//------------------------------------------------
messageHandler wallDamaged()
{
// Check params.
if ( params == null )
return SCRIPT_CONTINUE;
// Get the bomber reference.
obj_id bomber = poi.findObject( "antagonist_1" );
if ( (bomber == null) || (bomber == obj_id.NULL_ID) )
return SCRIPT_CONTINUE;
// Tell the bomber to handle getting shot.
messageTo( bomber, "wallDamaged", params, 0, false );
return SCRIPT_OVERRIDE;
}