warzone2100/data/script/text/vtols2.slo

277 lines
6.3 KiB
Plaintext
Raw Normal View History

//Script to handle VTOLs for 2C (includes factory production)
//VTOLS2.SLO
/* ******************** */
/* Declared Variables */
/* ******************** */
//VTOL stuff
public int padPlayer;
public int numGroups;
public int VTOLsize[4], groupX1[4], groupY1[4], groupX2[4], groupY2[4];
public TEMPLATE templates[4];
public STRUCTURE groupFactory[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];
private int count, group, temp;
private BASEOBJ viewerObj, targetObj, targetObj2;
private DROID droid;
private int clusterID;
private STRUCTURE newDroidFactory;
// which player is the human player
public int player;
// whether to use the no visibility target system
public bool noVisTargetting;
trigger nextTargetTrig(every, 80);
// declare events
event targetFound;
event clusterReset;
event nextTarget;
event resetVis;
event nextTargetNoVis;
event start(CALL_GAMEINIT)
{
//set up groups
count = 0;
while (count < numGroups)
{
groupAddArea(VTOLgroup[count], padPlayer, groupX1[count], groupY1[count], groupX2[count], groupY2[count]);
count = count + 1;
}
// 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;
}
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) and (groupFactory[group] != NULLOBJECT))
{
countTime[group] = everyTime[group]; //set back to every
temp = VTOLgroup[group].members;
if ((temp < VTOLsize[group]) and (structureIdle(groupFactory[group])))
{
//start factory producing here
buildDroid (templates[group], groupFactory[group], padPlayer, 1);
}
}
group = group + 1;
}
}
//add droid to correct group
event droidBuilt(CALL_NEWDROID, padPlayer, ref droid, ref newDroidFactory)
{
group = 0;
while (group < numGroups)
{
if (newDroidFactory == groupFactory[group])
{
groupAddDroid(VTOLgroup[group], droid);
if (attackObj[group] != NULLOBJECT)
{
orderGroupObj(VTOLgroup[group], DORDER_ATTACK, attackObj[group]);
}
}
group = group + 1;
}
}
// 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;
}
}
}
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)
{
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))
{
attackObj[group] = targetInCluster(attackCluster[group], padPlayer);
if (attackObj[group] == NULLOBJECT)
{
attackCluster[group] = 0;
}
}
//order VTOL group to target (if it exists and not already busy)
if ((attackObj[group] != NULLOBJECT) and (idleGroup(VTOLgroup[group]) > (VTOLgroup[group].members / 2)))
{
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
resetPlayerVisibility(padPlayer);
}
}