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

// 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] Oil Depot]: 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_Ind_TankBig",[(_position select 0) - 9.5, (_position select 1) +7,-0.15],[], 0, "CAN_COLLIDE"];
_baserunover1 = createVehicle ["MAP_Ind_TankBig",[(_position select 0) + 11, (_position select 1) +4,-0.15],[], 0, "CAN_COLLIDE"];
_baserunover2 = createVehicle ["MAP_Ind_TankBig",[(_position select 0) +8, (_position select 1) -6,-0.15],[], 0, "CAN_COLLIDE"];
_baserunover3 = createVehicle ["MAP_Ind_TankBig",[(_position select 0) -11, (_position select 1) -12,-0.15],[], 0, "CAN_COLLIDE"];
_baserunover4 = createVehicle ["MAP_Ind_TankBig",[(_position select 0) -28.5, (_position select 1) -1.2,-0.15],[], 0, "CAN_COLLIDE"];
_baserunover5 = createVehicle ["MAP_Ind_TankBig",[(_position select 0) - 26.2, (_position select 1) +20,-0.15],[], 0, "CAN_COLLIDE"];
_baserunover6 = createVehicle ["MAP_Ind_TankBig",[(_position select 0) - 6, (_position select 1) +28,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover7 = createVehicle ["GUE_WarfareBVehicleServicePoint",[(_position select 0) -30, (_position select 1) -15,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover8 = createVehicle ["GUE_WarfareBVehicleServicePoint",[(_position select 0) +21, (_position select 1) +3,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover9 = createVehicle ["GUE_WarfareBVehicleServicePoint",[(_position select 0) - 7, (_position select 1) +43,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover10 = createVehicle ["Barrels",[(_position select 0) +0.1, (_position select 1) +6,-0.015],[], 0, "CAN_COLLIDE"];

_baserunover11 = createVehicle ["Barrels",[(_position select 0) - 17, (_position select 1) +15,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover12 = createVehicle ["Barrels",[(_position select 0) +18, (_position select 1) -2,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover13 = createVehicle ["Barrel1",[(_position select 0) -16, (_position select 1) -2,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover14 = createVehicle ["Barrel1",[(_position select 0) +3, (_position select 1) +6,-0.015],[], 0, "CAN_COLLIDE"];
_baserunover15 = createVehicle ["Barrel1",[(_position select 0) -11.6, (_position select 1) +18,-0.015],[], 0, "CAN_COLLIDE"];


// Adding buildings to one variable just for tidiness
_baserunover = [_baserunover0,_baserunover1,_baserunover2,_baserunover3,_baserunover4,_baserunover5,_baserunover6,_baserunover7,_baserunover8,_baserunover9,_baserunover10,_baserunover11,_baserunover12,_baserunover13,_baserunover14,_baserunover15];

// Set some directions for our buildings
_directions = [0,0,0,0,0,0,0,-176.24,122.11,-0.11,82.81,-0.5,-48,0,0,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) - 25, (_position select 1) - 21, 0],5,"Medium",["Random","AT"],4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) + 32, (_position select 1) + 2, 0],5,"Medium","Random",4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) + 9, (_position select 1) +40, 0],4,"Medium","Random",4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;
[[(_position select 0) -41, (_position select 1) +6, 0],_rndnum,"Medium","Random",4,"Random",_aiType,"Random",_aiType,_mission] call spawn_group;

//Static Guns
[[[(_position select 0) +6.2, (_position select 1) -28, 0]],"KORD_high_TK_EP1","Easy",_aiType,_aiType,0,2,"Random","Random",_mission] call spawn_static;
[[[(_position select 0) -26, (_position select 1) +47, 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
	"Oil Depot", // 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_OIL_ANNOUNCE", // mission announcement
	"STR_CL_HERO_OIL_WIN", // mission success
	"STR_CL_HERO_OIL_FAIL", // mission fail
	[10,5,20,3,2] // Dynamic crate array
] call mission_winorfail;