248 lines
8.9 KiB
Plaintext
248 lines
8.9 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Siege Catapult Light - Initiates Load Sequence
|
|
// os_arm_catl
|
|
// by Don Anderson
|
|
// dandersonru@msn.com
|
|
//
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "os_inc"
|
|
|
|
void main()
|
|
{
|
|
object oCatapult = OBJECT_SELF;
|
|
|
|
int nSelfFaction = GetLocalInt(oCatapult,"FACTION");
|
|
int nLoaded = GetLocalInt(oCatapult,"LOADED");
|
|
location lLoc = GetLocation(oCatapult);
|
|
|
|
//Find closest related Switch
|
|
object oSwitch = GetNearestObjectByTag("SiegeSwitch",oCatapult,1);
|
|
float fSDist = GetDistanceToObject(oSwitch);
|
|
if(fSDist > SIEGE_SWITCH) return;
|
|
|
|
int nFaction;
|
|
object oTarget;
|
|
object oAcquire;
|
|
string sTarget;
|
|
|
|
//Check for Active Fire Mode
|
|
int nFMode = GetLocalInt(oSwitch,"FIREMODE");
|
|
if(nFMode < 1)
|
|
{
|
|
AssignCommand(oCatapult,SpeakString("Light Catapult standing down!"));
|
|
SetLocalInt(oCatapult,"LOADED",0);
|
|
SetLocalInt(oCatapult,"ACQUIRED",0);
|
|
return;
|
|
}
|
|
|
|
//Find a Valid Supply Barrel
|
|
object oBAcid = GetNearestObjectByTag("AcidGrenades",oCatapult,1);
|
|
object oBFire = GetNearestObjectByTag("FireGrenades",oCatapult,1);
|
|
if((oBAcid != OBJECT_INVALID || oBFire != OBJECT_INVALID) && nLoaded == 0)
|
|
{
|
|
float fDist = SIEGE_SUPPLY * 2.0;
|
|
float fADist = SIEGE_SUPPLY * 2.0;
|
|
float fFDist = SIEGE_SUPPLY * 2.0;
|
|
|
|
object oCBarrel;
|
|
|
|
//Which is the Closest Supply Barrel
|
|
if(oBAcid != OBJECT_INVALID) fADist = GetDistanceToObject(oBAcid);
|
|
if(oBFire != OBJECT_INVALID) fFDist = GetDistanceToObject(oBFire);
|
|
|
|
if(fADist < fFDist)
|
|
{
|
|
fDist = fADist;
|
|
oCBarrel = oBAcid;
|
|
}
|
|
if(fFDist <= fADist)
|
|
{
|
|
fDist = fFDist;
|
|
oCBarrel = oBFire;
|
|
}
|
|
|
|
if(fDist <= SIEGE_SUPPLY)
|
|
{
|
|
//Check for Available Ammunition
|
|
int nAmmo = GetLocalInt(oCBarrel,"AMMOQTY");
|
|
int nType = GetLocalInt(oCBarrel,"AMMOTYPE");
|
|
if(nAmmo > 0)
|
|
{
|
|
nAmmo--;
|
|
SetLocalInt(oCBarrel,"AMMOQTY",nAmmo);
|
|
SetLocalInt(oCatapult,"AMMOTYPE",nType);
|
|
SetLocalInt(oCatapult,"LOADED",1);
|
|
SetLocalInt(oCatapult,"ACQUIRED",0);
|
|
}
|
|
else
|
|
{
|
|
//Destroy Existing and Find Another
|
|
DestroyObject(oCBarrel,0.1);
|
|
DelayCommand(1.0,ExecuteScript("os_arm_catl",oCatapult));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DelayCommand(1.0,SpeakString("Light Catapult standing down....no Grenades available!"));
|
|
SetLocalInt(oCatapult,"LOADED",0);
|
|
SetLocalInt(oCatapult,"ACQUIRED",0);
|
|
return;
|
|
}
|
|
|
|
/*******************************************************************************/
|
|
//: SIEGE CATAPULT LIGHT
|
|
|
|
//Now the ammunition is properly loaded and the firing sequence takes place
|
|
if(GetLocalInt(oCatapult,"LOADED") == 1)
|
|
{
|
|
//Now we look for creatures
|
|
if(GetLocalInt(oCatapult,"ACQUIRED") == 0)
|
|
{
|
|
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGECATAPULT_LGT, lLoc, TRUE, OBJECT_TYPE_CREATURE);
|
|
while (GetIsObjectValid(oTarget))
|
|
{
|
|
location lType = GetLocation(oTarget);
|
|
string sType = GetTag(oTarget);
|
|
|
|
fSDist = GetDistanceToObject(oTarget);
|
|
if(fSDist >= MINRANGE_SIEGECATAPULT_LGT)
|
|
{
|
|
//OK to Fire On?
|
|
if(GetPlotFlag(oTarget) == FALSE)
|
|
{
|
|
nFaction = GetLocalInt(oTarget,"FACTION");
|
|
int nNPCHP = GetCurrentHitPoints(oTarget);
|
|
if(nNPCHP >= 1 && (nFaction != nSelfFaction))
|
|
{
|
|
SetLocalInt(oCatapult,"ACQUIRED",1);
|
|
oAcquire = oTarget;
|
|
break;//Acquired Target
|
|
}
|
|
}
|
|
}
|
|
oTarget = GetNextObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGECATAPULT_LGT, lLoc, TRUE, OBJECT_TYPE_CREATURE);
|
|
}
|
|
}
|
|
|
|
//Now we check for Siege Weapons
|
|
if(GetLocalInt(oCatapult,"ACQUIRED") == 0)
|
|
{
|
|
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGECATAPULT_LGT, lLoc, TRUE, OBJECT_TYPE_PLACEABLE);
|
|
while (GetIsObjectValid(oTarget))
|
|
{
|
|
location lType = GetLocation(oTarget);
|
|
string sType = GetTag(oTarget);
|
|
|
|
fSDist = GetDistanceToObject(oTarget);
|
|
if((fSDist >= MINRANGE_SIEGECATAPULT_LGT) &&
|
|
(sType == SIEGEARBALEST_LGT || sType == SIEGEARBALEST_HVY
|
|
|| sType == SIEGECATAPULT_LGT || sType == SIEGECATAPULT_HVY
|
|
|| sType == SIEGEBRICOLE || sType == SIEGECOUILLARD || sType == SIEGEPERRIERE
|
|
|| sType == SIEGEONAGER))
|
|
{
|
|
//OK to Fire On?
|
|
if(GetPlotFlag(oTarget) == FALSE)
|
|
{
|
|
nFaction = GetLocalInt(oTarget,"FACTION");
|
|
int nNPCHP = GetCurrentHitPoints(oTarget);
|
|
if(nNPCHP >= 1 && (nFaction != nSelfFaction))
|
|
{
|
|
SetLocalInt(oCatapult,"ACQUIRED",1);
|
|
oAcquire = oTarget;
|
|
break;//Acquired Target
|
|
}
|
|
}
|
|
}
|
|
oTarget = GetNextObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGECATAPULT_LGT, lLoc, TRUE, OBJECT_TYPE_PLACEABLE);
|
|
}
|
|
}
|
|
|
|
//Now we look for doors
|
|
if(GetLocalInt(oCatapult,"ACQUIRED") == 0)
|
|
{
|
|
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGECATAPULT_LGT, lLoc, TRUE, OBJECT_TYPE_DOOR);
|
|
while (GetIsObjectValid(oTarget))
|
|
{
|
|
location lType = GetLocation(oTarget);
|
|
string sType = GetTag(oTarget);
|
|
|
|
fSDist = GetDistanceToObject(oTarget);
|
|
if(fSDist >= MINRANGE_SIEGECATAPULT_LGT)
|
|
{
|
|
//OK to Fire On?
|
|
if(GetPlotFlag(oTarget) == FALSE)
|
|
{
|
|
int nNPCHP = GetCurrentHitPoints(oTarget);
|
|
if(nNPCHP >= 1)
|
|
{
|
|
SetLocalInt(oCatapult,"ACQUIRED",1);
|
|
oAcquire = oTarget;
|
|
break;//Acquired Target
|
|
}
|
|
}
|
|
}
|
|
oTarget = GetNextObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGECATAPULT_LGT, lLoc, TRUE, OBJECT_TYPE_DOOR);
|
|
}
|
|
}
|
|
}
|
|
|
|
//: SIEGE ARBALEST LIGHT
|
|
/*******************************************************************************/
|
|
|
|
if(GetLocalInt(oCatapult,"LOADED") == 1)
|
|
{
|
|
//Now we either stand down or range and face the target
|
|
if(GetLocalInt(oCatapult,"ACQUIRED") == 0)
|
|
{
|
|
DelayCommand(1.0,SpeakString("Light Catapult standing down....no valid targets!"));
|
|
SetLocalInt(oCatapult,"LOADED",0);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
sTarget = GetName(oAcquire);
|
|
float fDTarget = GetDistanceToObject(oAcquire);
|
|
SetLocalFloat(oCatapult,"RANGE",fDTarget);
|
|
SetFacingObject(oAcquire);
|
|
}
|
|
|
|
//Get Range in Integer Format
|
|
int nDTarget = FloatToInt(GetLocalFloat(oCatapult,"RANGE"));
|
|
|
|
//Now we start the Firing Process
|
|
if(GetLocalInt(oCatapult,"LOADED") == 1 && GetLocalInt(oCatapult,"AMMOTYPE") == ACID)
|
|
{
|
|
AssignCommand(oCatapult,DelayCommand(1.0,SpeakString("Light Catapult has acquired "+ sTarget +" as a Target!")));
|
|
AssignCommand(oCatapult,DelayCommand(3.0,SpeakString("Range: "+ IntToString(nDTarget) +" Meters")));
|
|
AssignCommand(oCatapult,DelayCommand(5.0,SpeakString("Catapult Acid Ammunition Received!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 10.0,PlaySound("as_cv_ropepully1")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 8.0,PlaySound("as_cv_ropecreak2")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 6.0,SpeakString("Loaded!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 3.0,SpeakString("Ready!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 0.5,SpeakString("FIRE!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT,ExecuteScript("os_fire_cat",oCatapult)));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT + 10.0,ExecuteScript("os_arm_catl",oCatapult)));
|
|
return;
|
|
}
|
|
|
|
//Now we start the Firing Process
|
|
if(GetLocalInt(oCatapult,"LOADED") == 1 && GetLocalInt(oCatapult,"AMMOTYPE") == FIRE)
|
|
{
|
|
AssignCommand(oCatapult,DelayCommand(1.0,SpeakString("Light Catapult has acquired "+ sTarget +" as a Target!")));
|
|
AssignCommand(oCatapult,DelayCommand(3.0,SpeakString("Range: "+ IntToString(nDTarget) +" Meters")));
|
|
AssignCommand(oCatapult,DelayCommand(5.0,SpeakString("Catapult Fire Ammunition Received!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 10.0,PlaySound("as_cv_ropepully1")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 8.0,PlaySound("as_cv_ropecreak2")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 6.0,SpeakString("Loaded!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 3.0,SpeakString("Ready!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT - 0.5,SpeakString("FIRE!")));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT,ExecuteScript("os_fire_cat",oCatapult)));
|
|
AssignCommand(oCatapult,DelayCommand(TIME_SIEGECATAPULT_LGT + 10.0,ExecuteScript("os_arm_catl",oCatapult)));
|
|
return;
|
|
}
|
|
}
|
|
}
|