;formunit.sqs
;part of the custom formations script pack
;see the readme for instructions on usage
;by General Barron
;aw_barron@hotmail.com
;5/1/04

;This script is called on each unit in the formation (exept the leader), and
;keeps them moving to their spot in the new formation. It is passed the
;variables: [unit,[coords]], where coords is an array containing the
; x and y coordinates for the unit, relative to the leader (see the readme)
; It also calls up formstop.sqs on the unit.

_man = _this select 0
? leader _man != player : [_man] exec "formstop.sqs"
_xpos = (_this select 1) select 0
_ypos = (_this select 1) select 1

_rad = ((_xpos ^ 2) + (_ypos ^ 2)) ^ .5
;distance the unit is supposed to be from the leader (radius)
_Fdir = _xpos atan2 _ypos
;formation direction = compass direction from leader to _man's formation spot, if leader is facing north


#top

_Lpos = getpos leader _man
;get leader's current postion
_Cdir = _Fdir + getdir leader _man
;add direction leader is facing to get current compass direction to formation spot

_man domove [(_Lpos select 0) + (sin _Cdir) * _rad, (_Lpos select 1) + (cos _Cdir) * _rad]
;use trig to find the coordinates of where the man should be, order man to go there

~2

@ !(unitready leader _man) OR (leader _man) == _man

@ (unitready leader _man) OR (leader _man) == _man
;@ speed leader _man > 1 OR (leader _man) == _man
;wait until the leader moves, script is told to end (by formation change), or unit becomes leader



?(leader group _man) != _man AND alive _man : goto "top"
;end the script once the formation changes from wedge (see readme)
;or end if the unit becomes the leader, or if the unit enters a vehicle and is not
;the driver, or if the unit is killed, or if they are in the leader's vehicle
;this prevents the units from exiting their vehicles
