// Note: You don't have to bother about the things about if(units_inside>=7) and --units_inside; and ++units_inside
// Normally the FBI and engine handle counting the units and you don't have to worry about that in script
// Just here I wanted to be sure the script doesn't crap if you edit the FBI
// Here I store each unit to a different "basket" holding position
// Normally you have none of this if(units_inside==7) attach-unit id to basket7;
// And instead a single attach-unit id to 0 - 1;
// Here I calculate a speed so that the loading and unloading movement complete exactly in a given time.
// Normally you use a fixed speed, ex speed [30]; and some wait-for instead of the sleep
// unload_shoulder and load_shoulder can be the same piece
// unload_arm and load_arm can be the same piece
// torax is the center of the "transportation turret"
// units will go toward and from "torax" during loading/unload animation
// *_shoulder is child of base, with 0 offset, and *_arm is child of *_shoulder, which 0 offset
// Hmm, I wrote it badly, so you can have "torax" higher than the base along Y, but not on a different xz position.
#define MAX_LOAD_RADIUS [120]
#define MAX_UNLOAD_RADIUS [300]
#define LOAD_TIME 2500
#define UNLOAD_TIME 1500
TransportPickup(id)
{
//Abort if already filled up
if(units_inside>=7)
{
return;
}
// If close enough to allow loading:
if(get XZ_HYPOT(get PIECE_XZ(torax) - get UNIT_XZ(id))<=MAX_LOAD_RADIUS)
{
// we're busy loading, don't disturb:
set BUSY to 1;
// instantly move the magical invisible arm to the position where the unit to load is
turn load_shoulder to y-axis get XZ_ATAN(get PIECE_XZ(load_shoulder) - get UNIT_XZ(id)) now;
move load_arm to z-axis get XZ_HYPOT(get PIECE_XZ(load_shoulder) - get UNIT_XZ(id)) now;
move load_arm to y-axis get UNIT_Y(id) - get PIECE_Y(load_shoulder) now;
attach-unit id to load_arm;
//slowly move the arm, carrying the unit, to the spider center (moving to proper basket pos would be too complex for now)
move load_arm to z-axis 0 speed ((get XZ_HYPOT(get PIECE_XZ(load_shoulder) - get UNIT_XZ(id)))/(LOAD_TIME))*1000;
move load_arm to y-axis get PIECE_Y(torax) - get PIECE_Y(load_shoulder) speed ((get PIECE_Y(torax) - get UNIT_Y(id))/(LOAD_TIME))*1000;// I assumed the torax would have a higher Y than the loaded unit, if not the speed would be negative and that would be BAD!
sleep LOAD_TIME;
// Ideally here I would check that the loading was successful. Bah, let's not to simplify.
// Let's not forget to update the counter
++units_inside;
// now that part that specifically interest you:
if(units_inside==1)
{
attach-unit id to basket1;
}
if(units_inside==2)
{
attach-unit id to basket2;
}
if(units_inside==3)
{
attach-unit id to basket3;
}
if(units_inside==4)
{
attach-unit id to basket4;
}
if(units_inside==5)
{
attach-unit id to basket5;
}
if(units_inside==6)
{
attach-unit id to basket6;
}
if(units_inside==7)
{
attach-unit id to basket7;
}
// Ok, we're done, the engine may proceed to next action. (Or something like that, I'm not even sure that "BUSY" really do something.)
set BUSY to 0;
}
}
TransportDrop(id,xz)
{
// If close enough to allow unloading:
if(get XZ_HYPOT(get PIECE_XZ(torax) - get UNIT_XZ(id))<=MAX_UNLOAD_RADIUS)
{
// we're busy unloading, don't disturb:
set BUSY to 1;
// instantly reset the position of the magical invisible arm (and turn it already, ok)
turn unload_shoulder to y-axis get XZ_ATAN(get PIECE_XZ(unload_shoulder) - xz) now;
move unload_arm to z-axis 0 now;
move unload_arm to y-axis get PIECE_Y(torax) - get PIECE_Y(unload_shoulder) now;
attach-unit id to unload_arm;
//slowly move the arm, carrying the unit, to the pos where to unload
move unload_arm to z-axis get XZ_HYPOT(get PIECE_XZ(unload_shoulder) - xz) speed ((get XZ_HYPOT(get PIECE_XZ(unload_shoulder) - xz))/(UNLOAD_TIME))*1000;
move unload_arm to y-axis get GROUND_HEIGHT(xz) - get PIECE_Y(unload_shoulder) speed ((get PIECE_Y(torax) - get GROUND_HEIGHT(xz))/(UNLOAD_TIME))*1000;//again, I assumed that torax was above ground, if not, speed would be negative, and things could go BAD!!
sleep UNLOAD_TIME;
// Ideally here I would check that the unloading was successful. Bah, let's not to simplify.
// Let's not forget to update the counter
--units_inside;
// And now, ladies and gentlemen, the drop command:
drop-unit id;
// Ok, we're done, the engine may proceed to next action. (Or something like that, I'm not even sure that "BUSY" really do something.)
set BUSY to 0;
}
}