private ["_crate_type","_mission","_position","_crate","_rndnum","_baserunover","_baserunover0","_baserunover1","_baserunover2","_baserunover3","_baserunover4","_baserunover5"];

// Get mission number, important we do this early
_mission = count wai_mission_data -1;
_missionType = _this select 0; // Type of mission: "MainHero" or "MainBandit"
_aiType = _this select 1; // Type of AI - opposite of mission type
_position = [30] call find_position;

diag_log format["WAI: [Mission:[Hero] Fallen Satellite]: Starting... %1",_position];

//Setup the crate
_crate_type = crates_small call BIS_fnc_selectRandom;
_crate = createVehicle [_crate_type,[5935.9839,12235.38,0],[],0,"CAN_COLLIDE"];
_crate call wai_crate_setup;


//Buildings 
_baserunover0 = createVehicle ["Satelit",[(_position select 0) - 8.41, (_position select 1) + 3.37, -0.013],[], 0, "CAN_COLLIDE"];
_baserunover1 = createVehicle ["MAP_rubble_metal_plates_03",[(_position select 0) - 8.1, (_position select 1) - 3.8, 0.01],[], 0, "CAN_COLLIDE"];
_baserunover2 = createVehicle ["MAP_rubble_metal_plates_01",[(_position select 0) - 6.8, (_position select 1) - 1.6, -0.015],[], 0, "CAN_COLLIDE"];
_baserunover3 = createVehicle ["Land_Dirthump01",[(_position select 0) - 7.4, (_position select 1) -2.8, -1.96],[], 0, "CAN_COLLIDE"];
_baserunover4 = createVehicle ["Land_Dirthump01",[(_position select 0) - 6.6, (_position select 1) -2.8, -1.99],[], 0, "CAN_COLLIDE"];
_baserunover5 = createVehicle ["Land_Fire_barrel_burning",[(_position select 0) -6.1, (_position select 1) -3.8, -0.85],[], 0, "CAN_COLLIDE"];


// Adding buildings to one variable just for tidiness
_baserunover = [_baserunover0,_baserunover1,_baserunover2,_baserunover3,_baserunover4,_baserunover5];

// Set some directions for our buildings
_directions = [0,0,61.76,-2.706,-66.12,0];
{ _x setDir (_directions select _forEachIndex) } forEach _baserunover;

// Make buildings flat on terrain surface
{ _x setVectorUp surfaceNormal position _x; } count _baserunover;

//Troops
_rndnum = round (random 5);
[[(_position select 0) - 22, (_position select 1) +7,0],5,"Easy",["Random","AT"],3,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) +15, (_position select 1) -19,0],5,"Easy","Random",3,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) +15, (_position select 1) +3,0],4,"Easy","Random",3,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) - 16, (_position select 1) -13,0],_rndnum,"Easy","Random",3,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;

//Static Guns
[[
	[(_position select 0) - 8, (_position select 1) + 12, 0.1],
	[(_position select 0) - 4.7, (_position select 1) - 16, 0.1]
],"M2StaticMG","Easy",_aiType,_aiType,0,2,"Random","Random",_mission] call spawn_static;

// Array of mission variables to send
[
	_mission, // Mission number
	_position, // Position of mission
	"Medium", // Difficulty
	"Fallen Satellite", // Name of Mission
	_missionType, // Mission Type: MainHero or MainBandit
	true, // show mission marker?
	true, // make minefields available for this mission
	_crate,	// crate object info
	["crate"], // Completion type: ["crate"], ["kill"], or ["assassinate", _unitGroup],
	[], // cleanup objects
	"STR_CL_HERO_FALLENSATELLITE_ANNOUNCE", // mission announcement
	"STR_CL_HERO_FALLENSATELLITE_WIN", // mission success
	"STR_CL_HERO_FALLENSATELLITE_FAIL", // mission fail
	[10,4,0,3,2] // Dynamic crate array
] call mission_winorfail;