178 lines
6.3 KiB
Plaintext
178 lines
6.3 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Siege Onager - Initiates Load Sequence
|
|
// os_arm_ona
|
|
// by Don Anderson
|
|
// dandersonru@msn.com
|
|
//
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "os_inc"
|
|
|
|
void main()
|
|
{
|
|
object oOnager = OBJECT_SELF;
|
|
|
|
int nSelfFaction = GetLocalInt(oOnager,"FACTION");
|
|
int nLoaded = GetLocalInt(oOnager,"LOADED");
|
|
location lLoc = GetLocation(oOnager);
|
|
|
|
//Find closest related Switch
|
|
object oSwitch = GetNearestObjectByTag("SiegeSwitch",oOnager,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(oOnager,SpeakString("Onager standing down!"));
|
|
SetLocalInt(oOnager,"LOADED",0);
|
|
SetLocalInt(oOnager,"ACQUIRED",0);
|
|
return;
|
|
}
|
|
|
|
//Find a Valid Supply Barrel
|
|
object oBOil = GetNearestObjectByTag("OilGrenades",oOnager,1);
|
|
object oBCaltrops = GetNearestObjectByTag("CaltropsGrenades",oOnager,1);
|
|
if((oBOil != OBJECT_INVALID || oBCaltrops != OBJECT_INVALID) && nLoaded == 0)
|
|
{
|
|
float fDist = SIEGE_SUPPLY * 2.0;
|
|
float fODist = SIEGE_SUPPLY * 2.0;
|
|
float fCDist = SIEGE_SUPPLY * 2.0;
|
|
|
|
object oCBarrel;
|
|
|
|
//Which is the Closest Supply Barrel
|
|
if(oBOil != OBJECT_INVALID) fODist = GetDistanceToObject(oBOil);
|
|
if(oBCaltrops != OBJECT_INVALID) fCDist = GetDistanceToObject(oBCaltrops);
|
|
|
|
if(fODist < fCDist)
|
|
{
|
|
fDist = fODist;
|
|
oCBarrel = oBOil;
|
|
}
|
|
if(fCDist <= fODist)
|
|
{
|
|
fDist = fCDist;
|
|
oCBarrel = oBCaltrops;
|
|
}
|
|
|
|
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(oOnager,"AMMOTYPE",nType);
|
|
SetLocalInt(oOnager,"LOADED",1);
|
|
SetLocalInt(oOnager,"ACQUIRED",0);
|
|
}
|
|
else
|
|
{
|
|
//Destroy Existing and Find Another
|
|
DestroyObject(oCBarrel,0.1);
|
|
DelayCommand(1.0,ExecuteScript("os_arm_ona",oOnager));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DelayCommand(1.0,SpeakString("Onager standing down....no Grenades available!"));
|
|
SetLocalInt(oOnager,"LOADED",0);
|
|
SetLocalInt(oOnager,"ACQUIRED",0);
|
|
return;
|
|
}
|
|
|
|
//Now the ammunition is properly loaded and the firing sequence takes place
|
|
if(GetLocalInt(oOnager,"LOADED") == 1)
|
|
{
|
|
//Now we look for creatures
|
|
if(GetLocalInt(oOnager,"ACQUIRED") == 0)
|
|
{
|
|
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGEONAGER, lLoc, TRUE, OBJECT_TYPE_CREATURE);
|
|
while (GetIsObjectValid(oTarget))
|
|
{
|
|
location lType = GetLocation(oTarget);
|
|
string sType = GetTag(oTarget);
|
|
|
|
fSDist = GetDistanceToObject(oTarget);
|
|
if(fSDist >= MINRANGE_SIEGEONAGER)
|
|
{
|
|
//OK to Fire On?
|
|
if(GetPlotFlag(oTarget) == FALSE)
|
|
{
|
|
nFaction = GetLocalInt(oTarget,"FACTION");
|
|
int nNPCHP = GetCurrentHitPoints(oTarget);
|
|
if(nNPCHP >= 1 && (nFaction != nSelfFaction))
|
|
{
|
|
SetLocalInt(oOnager,"ACQUIRED",1);
|
|
oAcquire = oTarget;
|
|
break;//Acquired Target
|
|
}
|
|
}
|
|
}
|
|
oTarget = GetNextObjectInShape(SHAPE_SPHERE, MAXRANGE_SIEGEONAGER, lLoc, TRUE, OBJECT_TYPE_CREATURE);
|
|
}
|
|
}
|
|
|
|
//Now we either stand down or range and face the target
|
|
if(GetLocalInt(oOnager,"ACQUIRED") == 0)
|
|
{
|
|
DelayCommand(1.0,SpeakString("Onager standing down....no valid targets!"));
|
|
SetLocalInt(oOnager,"LOADED",0);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
sTarget = GetName(oAcquire);
|
|
float fDTarget = GetDistanceToObject(oAcquire);
|
|
SetLocalFloat(oOnager,"RANGE",fDTarget);
|
|
SetFacingObject(oAcquire);
|
|
}
|
|
|
|
//Get Range in Integer Format
|
|
int nDTarget = FloatToInt(GetLocalFloat(oOnager,"RANGE"));
|
|
|
|
//Now we start the Firing Process
|
|
if(GetLocalInt(oOnager,"LOADED") == 1 && GetLocalInt(oOnager,"AMMOTYPE") == CALTROPS)
|
|
{
|
|
AssignCommand(oOnager,DelayCommand(1.0,SpeakString("Onager has acquired "+ sTarget +" as a Target!")));
|
|
AssignCommand(oOnager,DelayCommand(3.0,SpeakString("Range: "+ IntToString(nDTarget) +" Meters")));
|
|
AssignCommand(oOnager,DelayCommand(5.0,SpeakString("Onager Caltrops Ammunition Received!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 10.0,PlaySound("as_cv_ropepully1")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 8.0,PlaySound("as_cv_ropecreak2")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 6.0,SpeakString("Loaded!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 3.0,SpeakString("Ready!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 0.5,SpeakString("FIRE!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER,ExecuteScript("os_fire_ona",oOnager)));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER + 10.0,ExecuteScript("os_arm_ona",oOnager)));
|
|
return;
|
|
}
|
|
|
|
//Now we start the Firing Process
|
|
if(GetLocalInt(oOnager,"LOADED") == 1 && GetLocalInt(oOnager,"AMMOTYPE") == OIL)
|
|
{
|
|
AssignCommand(oOnager,DelayCommand(1.0,SpeakString("Onager has acquired "+ sTarget +" as a Target!")));
|
|
AssignCommand(oOnager,DelayCommand(3.0,SpeakString("Range: "+ IntToString(nDTarget) +" Meters")));
|
|
AssignCommand(oOnager,DelayCommand(5.0,SpeakString("Onager Oil Ammunition Received!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 10.0,PlaySound("as_cv_ropepully1")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 8.0,PlaySound("as_cv_ropecreak2")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 6.0,SpeakString("Loaded!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 3.0,SpeakString("Ready!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER - 0.5,SpeakString("FIRE!")));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER,ExecuteScript("os_fire_ona",oOnager)));
|
|
AssignCommand(oOnager,DelayCommand(TIME_SIEGEONAGER + 10.0,ExecuteScript("os_arm_ona",oOnager)));
|
|
return;
|
|
}
|
|
}
|
|
}
|