(script static boolean test1_warthog1_active
	; There are two guys left and there is a gunner
	(and
		(> (ai_living_count test1_marines) 1)
		(or
			(vehicle_test_seat test1_warthog "W-gunner" (unit (list_get (ai_actors test1_marines) 0)))
			(vehicle_test_seat test1_warthog "W-gunner" (unit (list_get (ai_actors test1_marines) 1)))
		)
	)
)


;(script static boolean test1_warthog2_active
;	; There are two guys left and there is a gunner
;	(and
;		(> (ai_living_count test1_marines2) 1)
;		(or
;			(vehicle_test_seat test1_warthog2 "W-gunner" (unit (list_get (ai_actors test1_marines2) 0)))
;			(vehicle_test_seat test1_warthog2 "W-gunner" (unit (list_get (ai_actors test1_marines2) 1)))
;		)
;	)
;)


(script static boolean test1_shadow1_active
	; There are two guys left and there is a gunner
	(and
		(> (ai_living_count test1_cov) 1)
		(or
			(vehicle_test_seat test1_shadow "GT-gunner" (unit (list_get (ai_actors test1_cov) 0)))
			(vehicle_test_seat test1_shadow "GT-gunner" (unit (list_get (ai_actors test1_cov) 1)))
		)
	)
)


(script static boolean test1_shadow2_active
	; There are two guys left and there is a gunner
	(and
		(> (ai_living_count test1_cov2) 1)
		(or
			(vehicle_test_seat test1_shadow2 "GT-gunner" (unit (list_get (ai_actors test1_cov2) 0)))
			(vehicle_test_seat test1_shadow2 "GT-gunner" (unit (list_get (ai_actors test1_cov2) 1)))
		)
	)
)


(script static boolean test1_warthogs_active
	; Active if both are active
;	(and
		(test1_warthog1_active)
;		(test1_warthog2_active)
;	)
)


(script static boolean test1_shadows_active
	; Active if both are active
	(and
		(test1_shadow1_active)
		(test1_shadow2_active)
	)
)


(script continuous test1_marines_restocker
	; Place the vehicle if there's no driver
	(if 
		(and
			(not (vehicle_test_seat test1_warthog "W-driver" (unit (list_get (ai_actors test1_marines) 0)) ))
			(not (vehicle_test_seat test1_warthog "W-driver" (unit (list_get (ai_actors test1_marines) 1)) ))
		)
		(object_create_anew test1_warthog)
	)
	
	; If necessary, place the marines
	(if (< (ai_living_count test1_marines) 2) (ai_spawn_actor test1_marines))
	(if (< (ai_living_count test1_marines) 2) (ai_spawn_actor test1_marines))
	
	; Load them up and activate the hog
	(unit_enter_vehicle (unit (list_get (ai_actors test1_marines) 0)) test1_warthog "W-driver")
	(unit_enter_vehicle (unit (list_get (ai_actors test1_marines) 1)) test1_warthog "W-gunner")
	
	; Give them orders
	(ai_set_orders test1_marines test1/marines_center)

	; Sleep until we're inactive
	(sleep_until
		(not (test1_warthog1_active))
	30)
	
	; Is a gunner still active?
	(if (vehicle_test_seat test1_warthog "W-gunner" (unit (list_get (ai_actors test1_marines) 0)) )
		(begin
			; Move the gunner into the driver's seat
			(unit_exit_vehicle (unit (list_get (ai_actors test1_marines) 0)))
			(unit_enter_vehicle (unit (list_get (ai_actors test1_marines) 0)) test1_warthog "W-driver")
		)
	)
	
	; Order them to return to base if they're still alive, and deactivate the hog
	(ai_renew test1_marines) ;chetz 4 marin3s
;	(ai_set_orders test1_marines test1/marines_retreat)
	
	; Sleep until we should respawn them (either everyone is dead, or on a 30sec timeout)
	(sleep_until (<= (ai_living_count marines) 0) 30 600)
)


(script startup test1_marines2_restocker
	; Place the vehicle if there's no driver
	(if 
;		(and
			(not (vehicle_test_seat test1_warthog2 "W-driver" (unit (list_get (ai_actors test1_marines2) 0)) ))
;			(not (vehicle_test_seat test1_warthog2 "W-driver" (unit (list_get (ai_actors test1_marines2) 1)) ))
;		)
		(object_create_anew test1_warthog2)
	)
	
	; If necessary, place the marines
	(if (< (ai_living_count test1_marines2) 2) (ai_spawn_actor test1_marines2))
;	(if (< (ai_living_count test1_marines2) 2) (ai_spawn_actor test1_marines2))
	
	; Load them up
	(unit_enter_vehicle (unit (list_get (ai_actors test1_marines2) 0)) test1_warthog2 "W-driver")
;	(unit_enter_vehicle (unit (list_get (ai_actors test1_marines2) 1)) test1_warthog2 "W-gunner")
	
	; Give them orders
	(ai_set_orders test1_marines2 test1/marines_center)

	; Sleep until we're inactive
;	(sleep_until
;		(not (test1_warthog2_active))
;	30)
	
	; Is the gunner still active?
;	(if (vehicle_test_seat test1_warthog2 "W-gunner" (unit (list_get (ai_actors test1_marines2) 0)) )
;		(begin
			; Move the gunner into the driver's seat
;			(unit_exit_vehicle (unit (list_get (ai_actors test1_marines2) 0)))
;			(unit_enter_vehicle (unit (list_get (ai_actors test1_marines2) 0)) test1_warthog2 "W-driver")
;		)
;	)
	
	; Order them to return to base if they're still alive
;	(ai_renew test1_marines2) ;chetz 4 marin3s
;	(ai_set_orders test1_marines2 test1/marines_retreat)
	
	; Sleep until we should respawn them (either everyone is dead, or on a 30sec timeout)
;	(sleep_until (<= (ai_living_count marines) 0) 30 600)
)


(script continuous test1_cov_restocker
	; Place the vehicle if there's no driver
	(if 
		(and
			(not (vehicle_test_seat test1_shadow "G-driver" (unit (list_get (ai_actors test1_cov) 0)) ))
			(not (vehicle_test_seat test1_shadow "G-driver" (unit (list_get (ai_actors test1_cov) 1)) ))
		)
		(object_create_anew test1_shadow)
	)
	
	; If necessary, place the marines
	(if (< (ai_living_count test1_cov) 2) (ai_spawn_actor test1_cov))
	(if (< (ai_living_count test1_cov) 2) (ai_spawn_actor test1_cov))
	
	; Load them up
	(unit_enter_vehicle (unit (list_get (ai_actors test1_cov) 0)) test1_shadow "G-driver")
	(unit_enter_vehicle (unit (list_get (ai_actors test1_cov) 1)) test1_shadow "GT-gunner")
	
	; Give them orders
	(ai_set_orders test1_cov test1/cov_center)

	; Sleep until we're inactive
	(sleep_until
		(not (test1_shadow1_active))
	30)
	
	; Sleep until one of us is dead
	(sleep_until (< (ai_living_count test1_cov) 2) 5)
	
	; Is the gunner still active?
	(if (vehicle_test_seat test1_shadow "GT-gunner" (unit (list_get (ai_actors test1_cov) 0)) )
		(begin
			; Move the gunner into the driver's seat
			(unit_exit_vehicle (unit (list_get (ai_actors test1_cov) 0)))
			(unit_enter_vehicle (unit (list_get (ai_actors test1_cov) 0)) test1_shadow "G-driver")
		)
	)
	
	; Order them to return to base if they're still alive
;	(ai_set_orders test1_cov test1/cov_retreat)
	
	; Sleep until we should respawn them (either everyone is dead, or on a 30sec timeout)
	(sleep_until (<= (ai_living_count cov) 0) 30 600)
)


(script continuous test1_cov2_restocker
	; Place the vehicle if there's no driver
	(if 
		(and
			(not (vehicle_test_seat test1_shadow2 "G-driver" (unit (list_get (ai_actors test1_cov2) 0)) ))
			(not (vehicle_test_seat test1_shadow2 "G-driver" (unit (list_get (ai_actors test1_cov2) 1)) ))
		)
		(object_create_anew test1_shadow2)
	)
	
	; If necessary, place the marines
	(if (< (ai_living_count test1_cov2) 2) (ai_spawn_actor test1_cov2))
	(if (< (ai_living_count test1_cov2) 2) (ai_spawn_actor test1_cov2))
	
	; Load them up
	(unit_enter_vehicle (unit (list_get (ai_actors test1_cov2) 0)) test1_shadow2 "G-driver")
	(unit_enter_vehicle (unit (list_get (ai_actors test1_cov2) 1)) test1_shadow2 "GT-gunner")
	
	; Give them orders
	(ai_set_orders test1_cov2 test1/cov_center)

	; Sleep until we're inactive
	(sleep_until
		(not (test1_shadow2_active))
	30)
	
	; Is the gunner still active?
	(if (vehicle_test_seat test1_shadow2 "GT-gunner" (unit (list_get (ai_actors test1_cov2) 0)) )
		(begin
			; Move the gunner into the driver's seat
			(unit_exit_vehicle (unit (list_get (ai_actors test1_cov2) 0)))
			(unit_enter_vehicle (unit (list_get (ai_actors test1_cov2) 0)) test1_shadow2 "G-driver")
		)
	)
	
	; Order them to return to base if they're still alive
;	(ai_set_orders test1_cov2 test1/cov_retreat)
	
	; Sleep until we should respawn them (either everyone is dead, or on a 30sec timeout)
	(sleep_until (<= (ai_living_count cov) 0) 30 600)
)


(script continuous cleanup
	(sleep 900)
	(garbage_collect_unsafe)
)


(script startup mission
	(print "WAR!")
	(ai_allegiance player human)
	(sleep 30)
	(ai_braindead test1_marines2 1)
	(sleep 180)
	(ai_braindead test1_marines2 0)
)
