Files
dsrc/sku.0/sys.server/compiled/game/script/systems/gcw/flip_banner.script
T

163 lines
3.9 KiB
Plaintext

include library.create;
include library.ai_lib;
include library.utils;
include library.gcw;
include library.locations;
//------------------------------------------------
// OnInitialize
//------------------------------------------------
trigger OnInitialize()
{
// messageTo( self, "spawnBanner", null, 1.f, false );
messageTo( self, "checkBannerImpulse", null, 1.f, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnAttach
//------------------------------------------------
trigger OnAttach()
{
// messageTo( self, "spawnBanner", null, 1.f, false );
messageTo( self, "checkBannerImpulse", null, 1.f, false );
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnDestroy
//------------------------------------------------
trigger OnDestroy()
{
if ( utils.hasScriptVar( self, "banner" ) )
{
obj_id banner = utils.getObjIdScriptVar( self, "banner" );
if ( isIdValid( banner ) )
destroyObject( banner );
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnUnloadedFromMemory
//
// This will prevent duplicate banners by unloading the banners when the spawner unloads.
//------------------------------------------------
trigger OnUnloadedFromMemory()
{
if ( utils.hasScriptVar( self, "banner" ) )
{
obj_id banner = utils.getObjIdScriptVar( self, "banner" );
if ( isIdValid( banner ) )
destroyObject( banner );
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// checkBannerImpulse
//------------------------------------------------
messageHandler checkBannerImpulse()
{
// Determine who the winner is.
// float imp_r = gcw.getImperialRatio( self );
// float reb_r = gcw.getRebelRatio( self );
float imp_r = gcw.getImperialPercentileByRegion(self);
float reb_r = gcw.getRebelPercentileByRegion(self);
// LOG("gcw_region", "checkBannerImpulse imp_r: " + imp_r + " reb_r: " + reb_r);
if((imp_r > reb_r))// && (utils.getIntScriptVar(self, "faction" ) != 1))
{
// Switch to an Imp banner.
utils.setScriptVar( self, "faction", 1 );
// Destroy existing banner.
obj_id banner = utils.getObjIdScriptVar( self, "banner" );
if ( isIdValid( banner ) )
destroyObject( banner );
// Spawn a new banner.
spawnBanner( self, "imperial" );
}
else if((reb_r > imp_r))// && (utils.getIntScriptVar(self, "faction") != 2))
{
// Switch to a Reb banner.
utils.setScriptVar(self, "faction", 2);
// Destroy existing banner.
obj_id banner = utils.getObjIdScriptVar(self, "banner");
if(isIdValid(banner))
destroyObject(banner);
// Spawn a new banner.
spawnBanner(self, "rebel");
}
messageTo(self, "checkBannerImpulse", null, 3600.f, false);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// spawnBanner
//------------------------------------------------
void spawnBanner( obj_id self, string faction )
{
string empiredayRunning = getConfigSetting("GameServer", "empireday_ceremony");
// LOG("gcw_region", "spawnBanner self: " + self + " faction: " + faction);
if(empiredayRunning != null && (empiredayRunning.equals("true") || empiredayRunning.equals("1")))
{
// Figure out where we are!
location here = getLocation( self );
string city = locations.getCityName( here );
if ( city == null )
city = locations.getGuardSpawnerRegionName( here );
if ( city != null && city.length() > 0 )
{
if ( city.equals("coronet") )
{
faction = "rebel";
}
else if ( city.equals("theed") )
{
faction = "imperial";
}
}
}
transform t = getTransform_o2w( self );
if(faction.equals("rebel"))
t = t.move_l( new vector( 0,0,2 ) );
obj_id banner = createObject( "object/tangible/gcw/flip_banner_"+faction+".iff", t, null );
if ( banner == null || !isIdValid( banner ) )
{
// Failed for some reason?
return;
}
setObjVar( banner, "spawner", self );
utils.setScriptVar( self, "banner", banner );
return;
}