warzone2100/data/script/text/vtols.slo

416 lines
9.3 KiB
Plaintext
Raw Normal View History

/*
* Control VTOL attacks
*
*/
/* ******************** */
/* Declared Variables */
/* ******************** */
private int count, group, temp;
private BASEOBJ viewerObj, targetObj, targetObj2;
private DROID droid;
private int clusterID;
//VTOL Pads
public STRUCTURESTAT pad;
public int padX[8], padY[8], numPads, padPlayer;
public STRUCTUREID HQbuilding;
public BOOL dontStopFlag;
private STRUCTURE pads[8];
// control whether vtols use rearm pads or appear at the edge of the map
private bool noPads;
//VTOL groups and targets
public int numGroups;
public int VTOLsize[4], groupX[4], groupY[4];
public TEMPLATE templates[4];
public int targetObjType[4], startTime[4], everyTime[4];
public int numPrefStruc, prefStruc[4], numPrefDroid, prefDroid[4];
private GROUP VTOLgroup[4];
private BASEOBJ attackObj[4];
private int attackCluster[4], countTime[4];
// area within which vtols can be killed
public int killX1,killY1, killX2,killY2;
// where the vtols return to and vanish
public int vanishX,vanishY;
// which player is the human player
public int player;
// whether to use the no visibility target system
public bool noVisTargetting;
trigger addVTOLTrig(every, 3000); //every 5 mins to get reinforcements
trigger killVTOLSTrig(every, 43);
//trigger vtolStartTrig(wait, 600);
trigger vtolOffMapStartTrig(every, 23);
trigger nextTargetTrig(every, 80);
// declare events
event targetFound;
event clusterReset;
event nextTarget;
event resetVis;
event nextTargetNoVis;
event start(CALL_GAMEINIT)
{
//add a VTOL rearming pad
count = 0;
while (count < numPads)
{
pads[count] = addStructure(pad, padPlayer, padX[count], padY[count]);
count = count + 1;
}
// if there are no rearm pads vtols come from the edge of the map
noPads = (numPads == 0);
//eventTraceLevel(1); //dbWin32 stuff
// set the target system preferences
resetStructTargets();
setStructTarIgnore(ST_WALL); //ignore walls
count = 0;
while (count < numPrefStruc)
{
setStructTarPref(prefStruc[count]);
count = count + 1;
}
resetDroidTargets();
setDroidTarIgnore(DT_SUPER_HEAVY); //ignore transport
count = 0;
while (count < numPrefDroid)
{
setDroidTarPref(prefDroid[count]);
count = count + 1;
}
setVTOLReturnPos(padPlayer, vanishX,vanishY);
count = 0;
while (count < numGroups)
{
countTime[count] = startTime[count];
count = count + 1;
}
// turn off the visibility targetting system
if (noVisTargetting)
{
// turn off the normal system
setEventTrigger(targetFound, inactive);
setEventTrigger(clusterReset, inactive);
setEventTrigger(nextTarget, inactive);
setEventTrigger(resetVis, inactive);
// turn on the no visibility system
setEventTrigger(nextTargetNoVis, nextTargetTrig);
}
}
// do VTOL reinforcements (startTime, everyTime)
event addVTOL(every, 107) //every 10secs
{
group = 0;
while (group < numGroups)
{
countTime[group] = countTime[group] - 1;
if (countTime[group] <= 0)
{
countTime[group] = everyTime[group]; //set back to every
temp = VTOLgroup[group].members;
if (((not noPads) and (temp < VTOLsize[group])) or // reinforcing a group using rearm pads
(noPads and (temp == 0) and (attackObj[group] != NULLOBJECT))) // creating a group at the edge of the map
{
debugBox(100);
count = 0;
temp = VTOLsize[group] - VTOLgroup[group].members;
while (count < temp)
{
droid = addDroid(templates[group], groupX[group], groupY[group], padPlayer);
if (droid != NULLOBJECT)
{
groupAddDroid(VTOLgroup[group], droid);
}
count = count + 1;
}
if (attackObj[group] != NULLOBJECT)
{
debugBox(101);
orderGroupObj(VTOLgroup[group], DORDER_ATTACK, attackObj[group]);
}
}
}
group = group + 1;
}
/*
// only reset this event if using pads
if (not noPads)
{
setEventTrigger (addVTOL, addVTOLTrig);
}
*/
}
event vtolOffMap(CALL_VTOL_OFF_MAP, padPlayer, ref droid)
{
// vtol has reached the edge of the map - vanish them
vanishUnit(droid);
}
// set up a target for the vtol groups
event targetFound(CALL_OBJ_SEEN, padPlayer, ref targetObj, ref viewerObj)
{
if (targetObj != NULLOBJECT )
{
group = 0;
if (targetObj.type == OBJ_DROID)
{
if (objToDroid(targetObj).droidType == DROID_TRANSPORTER)
{
// skip transporters
group = numGroups;
}
}
while(group < numGroups)
{
//clarify target type here!
if (targetObj.type == targetObjType[group])
{
//store only if new one req'd
if ((attackObj[group] == NULLOBJECT) and (attackCluster[group] == 0))
{
attackCluster[group] = targetObj.clusterID;
// clusterID can be 0 for droids - especially near start
// when they havn't moved yet
if (attackCluster[group] != 0)
{
targetObj2 = targetInCluster(targetObj.clusterID, padPlayer);
}
else
{
targetObj2 = NULLOBJECT;
}
// if we've found a target, store it
if (targetObj2 != NULLOBJECT)
{
attackObj[group] = targetObj2;
attackCluster[group] = targetObj2.clusterID;
debugBox(0);
debugBox(attackObj[group].id);
debugBox(attackObj[group].clusterID);
}
}
}
group = group + 1;
}
}
}
// remove a cluster from the system if there isn't anything in it
event clusterReset(CALL_CLUSTER_EMPTY, ref clusterID)
{
group = 0;
while (group < numGroups)
{
if (attackCluster[group] == clusterID)
{
debugBox(200);
debugBox(clusterID);
attackObj[group] = NULLOBJECT;
attackCluster[group] = 0;
group = numGroups;
}
group = group + 1;
}
}
/* Newer System! Iterates clusters and keeps 5 targets! */
event nextTarget(every, 80)
{
group = 0;
while (group < numGroups)
{
// if the current target has died find the next in the cluster
if ((attackObj[group] == NULLOBJECT) and (attackCluster[group] != 0))
{
debugBox(2);
attackObj[group] = targetInCluster(attackCluster[group], padPlayer);
if (attackObj[group] == NULLOBJECT)
{
attackCluster[group] = 0;
}
else
{
debugBox(attackObj[group].id);
}
}
//order VTOL group to target (if it exists and not already busy)
if ((attackObj[group] != NULLOBJECT) and (idleGroup(VTOLgroup[group]) > (VTOLgroup[group].members / 2)))
{
debugBox(3);
debugBox(attackObj[group].id);
orderGroupObj(VTOLgroup[group], DORDER_ATTACK, attackObj[group]);
}
group = group + 1;
}
}
// give targets to vtols without using visibility
event nextTargetNoVis(inactive)
{
group = 0;
while (group < numGroups)
{
// find a target for the group
if (targetObjType[group] == OBJ_DROID)
{
attackObj[group] = droidTargetOnMap(player, -1);
}
else
{
attackObj[group] = structTargetOnMap(player, -1);
}
//order VTOL group to target (if not already busy)
if ((attackObj[group] != NULLOBJECT) and (idleGroup(VTOLgroup[group]) > (VTOLgroup[group].members / 2)))
{
debugBox(3);
debugBox(attackObj[group].id);
orderGroupObj(VTOLgroup[group], DORDER_ATTACK, attackObj[group]);
}
group = group + 1;
}
}
// reset player visibility if no targets
event resetVis(every, 333)
{
// see if there are any stored targets
temp = -1;
count = 0;
while (count < numGroups)
{
if ((attackObj[count] == NULLOBJECT) and (attackCluster[count] == 0))
{
// no targets stored for this group - reset visibility
// other groups will keep their current target clusters
temp = count;
count = numGroups;
}
count = count + 1;
}
if (temp != -1)
{
// no targets stored, reset visibility
debugBox(4);
resetPlayerVisibility(padPlayer);
}
}
event killVTOLS(inactive)
{
// see if all the vtols are dead
temp = -1;
group = 0;
while (group < numGroups)
{
if (VTOLgroup[group].members != 0)
{
temp = group;
group = numGroups;
}
group = group + 1;
}
if (temp == -1)
{
// all the vtols are dead
count = 0;
while (count < numPads)
{
if (pads[count] != NULLOBJECT)
{
destroyStructure(pads[count]); //get rid of rearming pads
}
count = count + 1;
}
setEventTrigger(killVTOLS, inactive);
}
else
{
// some vtols left see if we can kill them off
group = 0;
while (group < numGroups)
{
initIterateGroup(VTOLgroup[group]);
droid = iterateGroup(VTOLgroup[group]);
while (droid != NULLOBJECT)
{
if ((droid.x >= killX1 * 128) and (droid.x <= killX2 * 128) and
(droid.y >= killY1 * 128) and (droid.y <= killY2 * 128))
{
vanishUnit(droid);
}
droid = iterateGroup(VTOLgroup[group]);
}
group = group + 1;
}
}
}
event stopVTOL(buildingDestroyed(HQbuilding, padPlayer), 45)
{
//turn off VTOL attacks if command centre dead
if (not dontStopFlag)
{
setEventTrigger(killVTOLS, killVTOLSTrig);
setEventTrigger(nextTarget, inactive);
setEventTrigger(targetFound, inactive);
setEventTrigger(addVTOL, inactive);
}
setEventTrigger(stopVTOL, inactive);
}
event cheatEvnt(CALL_MISSION_START) //cheat button ctrl M
{
//get rid of pads and vtols if cheat!
count = 0;
while (count < numPads)
{
if (pads[count] != NULLOBJECT)
{
destroyStructure(pads[count]); //get rid of rearming pads
}
count = count + 1;
}
group = 0;
while (group < numGroups)
{
initIterateGroup(VTOLgroup[group]);
droid = iterateGroup(VTOLgroup[group]);
while (droid != NULLOBJECT)
{
vanishUnit(droid);
droid = iterateGroup(VTOLgroup[group]);
}
group = group + 1;
}
}