private ["_rndnum","_crate_type","_mission","_position","_crate","_baserunover","_baserunover0","_baserunover1","_baserunover2","_baserunover3","_baserunover4","_baserunover5","_baserunover6","_baserunover7","_baserunover8","_baserunover9","_baserunover10","_baserunover11","_baserunover12","_baserunover13","_baserunover14","_baserunover15","_baserunover16","_baserunover17","_baserunover18","_baserunover19","_baserunover20","_baserunover21","_baserunover22"];

// 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] Cargo]: Starting... %1",_position];

//Setup the crate
_crate_type = crates_small call BIS_fnc_selectRandom;
_crate = createVehicle [_crate_type,[(_position select 0) + 0.2,(_position select 1),0], [], 0, "CAN_COLLIDE"];
_crate call wai_crate_setup;
//Buildings 
_baserunover0 = createVehicle ["MAP_Misc_Cargo1Bo",[(_position select 0)+14, (_position select 1) -10, 0],[], 0, "CAN_COLLIDE"];
_baserunover1 = createVehicle ["MAP_Misc_Cargo2A",[(_position select 0) +18, (_position select 1) -10, 0],[], 0, "CAN_COLLIDE"];
_baserunover2 = createVehicle ["MAP_Misc_Cargo2B",[(_position select 0) +20, (_position select 1) - 3, 0],[], 0, "CAN_COLLIDE"];
_baserunover3 = createVehicle ["MAP_Misc_Cargo2C", [(_position select 0) +14, (_position select 1) +1, 0],[], 0, "CAN_COLLIDE"];
_baserunover4 = createVehicle ["MAP_Misc_Cargo2C", [(_position select 0) +21, (_position select 1) -17, 0],[], 0, "CAN_COLLIDE"];
_baserunover5 = createVehicle ["MAP_Misc_Cargo1G", [(_position select 0) +9, (_position select 1) -1, 0],[], 0, "CAN_COLLIDE"];
_baserunover6 = createVehicle ["MAP_Misc_Cargo1E",[(_position select 0) + 11, (_position select 1) +7, 0],[], 0, "CAN_COLLIDE"];
_baserunover7 = createVehicle ["MAP_Misc_Cargo1C",[(_position select 0) +2, (_position select 1) -15, 0],[], 0, "CAN_COLLIDE"];
_baserunover8 = createVehicle ["MAP_Misc_Cargo1B",[(_position select 0) +6, (_position select 1) -8, 0],[], 0, "CAN_COLLIDE"];
_baserunover9 = createVehicle ["MAP_Misc_Cargo2E", [(_position select 0) +3.5, (_position select 1) +6, 0],[], 0, "CAN_COLLIDE"];
_baserunover10 = createVehicle ["MAP_Misc_Cargo2D", [(_position select 0) -2, (_position select 1) -10, 0],[], 0, "CAN_COLLIDE"];
_baserunover11 = createVehicle ["MAP_Misc_Cargo1F", [(_position select 0) -11, (_position select 1) +10, 0],[], 0, "CAN_COLLIDE"];
_baserunover12 = createVehicle ["MAP_Misc_Cargo1E",[(_position select 0) -9, (_position select 1) -4, 0],[], 0, "CAN_COLLIDE"];
_baserunover13 = createVehicle ["MAP_Misc_Cargo1D",[(_position select 0) +21, (_position select 1) +6, 0],[], 0, "CAN_COLLIDE"];
_baserunover14 = createVehicle ["MAP_Misc_Cargo1Bo",[(_position select 0) -6, (_position select 1) +6, 0],[], 0, "CAN_COLLIDE"];
_baserunover15 = createVehicle ["MAP_Misc_Cargo1B",[(_position select 0) -19, (_position select 1) -7, 0],[], 0, "CAN_COLLIDE"];
_baserunover16 = createVehicle ["MAP_Misc_Cargo1A",[(_position select 0) -15, (_position select 1) -1, 0],[], 0, "CAN_COLLIDE"];
_baserunover17 = createVehicle ["MAP_Misc_Cargo1G", [(_position select 0) -4, (_position select 1) +16, 0],[], 0, "CAN_COLLIDE"];
_baserunover18 = createVehicle ["MAP_Misc_Cargo2C", [(_position select 0) +7, (_position select 1) +11, 0],[], 0, "CAN_COLLIDE"];
_baserunover19 = createVehicle ["MAP_Misc_Cargo2B", [(_position select 0) +4, (_position select 1) -24, 0],[], 0, "CAN_COLLIDE"];
_baserunover20 = createVehicle ["MAP_Misc_Cargo2C",[(_position select 0) +4, (_position select 1) +20, 0],[], 0, "CAN_COLLIDE"];
_baserunover21 = createVehicle ["MAP_Misc_Cargo2A",[(_position select 0) -12, (_position select 1) -13, 0],[], 0, "CAN_COLLIDE"];
_baserunover22 = createVehicle ["MAP_A_CraneCon",[(_position select 0) -21, (_position select 1) +10, 0],[], 0, "CAN_COLLIDE"];

_baserunover = [_baserunover0,_baserunover1,_baserunover2,_baserunover3,_baserunover4,_baserunover5,_baserunover6,_baserunover7,_baserunover8,_baserunover9,_baserunover10,_baserunover11,_baserunover12,_baserunover13,_baserunover14,_baserunover15,_baserunover16,_baserunover17,_baserunover18,_baserunover19,_baserunover20,_baserunover21,_baserunover22];

_directions = [0,-89,2,0,119,39,86,0,111,-40,0,0,0,-48,-139,-41,14,109,-114,-74,-44,-22,0];
{ _x setDir (_directions select _forEachIndex) } forEach _baserunover;

{ _x setVectorUp surfaceNormal position  _x; } count _baserunover;

//Troops
_rndnum = round (random 5);
[[(_position select 0) +3, (_position select 1) +25, 0],5,"Hard",["Random","AT"],4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) -27, (_position select 1) -4, 0],5,"Hard","Random",4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) +33, (_position select 1) -2, 0],5,"Hard","Random",4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) +10, (_position select 1) -37, 0],_rndnum,"Hard","Random",4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;

//Humvee Patrol
[[(_position select 0) +60, _position select 1, 0],[(_position select 0) -60, _position select 1, 0],50,2,"HMMWV_Armored","Hard",_aiType,_aiType,_mission] call vehicle_patrol;
 
//Static Guns
[[[(_position select 0) +80, (_position select 1) -28, 0]],"KORD_high_TK_EP1","Easy",_aiType,_aiType,0,2,"Random","Random",_mission] call spawn_static;
[[[(_position select 0) +27, (_position select 1) -40, 0]],"KORD_high_TK_EP1","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
	"Cargo", // 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],
	[_baserunover], // cleanup objects
	"STR_CL_HERO_CARGO_ANNOUNCE", // mission announcement
	"STR_CL_HERO_CARGO_WIN", // mission success
	"STR_CL_HERO_CARGO_FAIL", // mission fail
	[10,5,20,3,2] // Dynamic crate array
] call mission_winorfail;