- #define COLOR_GREEN "#(argb,8,8,3)color(0,1,0,0.3,ca)"
- #define COLOR_RED "#(argb,8,8,3)color(1,0,0,0.3,ca)"
- #define COLOR_GRAY "#(argb,8,8,3)color(0,0,0,0.3,ca)"
- ////////////////////////////////
- if (isnil {_this getvariable "MSO_cnstrct_radius"}) then {
- if (isnil {_this getvariable "MSO_cnstrct_supplies"}) then {
- _this setvariable ["MSO_cnstrct_supplies",500,true];
- };
- if (isnil {_this getvariable "MSO_cnstrct_radius"}) then {
- _this setvariable ["MSO_cnstrct_radius",20];
- };
- if (isnil {_this getvariable "MSO_cnstrct_buildings"}) then {
- _this setvariable ["MSO_cnstrct_buildings",[]];
- };
- //List of items, fixed for OA
- if (isnil {_this getvariable "MSO_cnstrct_categories"}) then {
- _this setvariable ["MSO_cnstrct_categories",["Barriers","Sandbags","HESCO","Bunkers","Trenches","Netting","Misc"]];
- };
- if (isnil {_this getvariable "MSO_cnstrct_items"}) then {
- _this setvariable ["MSO_cnstrct_items",[
- ["Fort_RazorWire","Barriers",200],
- ["Hedgehog_EP1","Barriers",200],
- ["Land_fort_bagfence_long","Sandbags",100],
- ["Land_fort_bagfence_round","Sandbags",300],
- ["Land_HBarrier1","HESCO",70],
- ["Land_HBarrier3","HESCO",200],
- ["Land_HBarrier5","HESCO",300],
- ["Land_HBarrier_large","HESCO",800],
- ["Land_fortified_nest_small_EP1","Bunkers",800],
- ["Land_fortified_nest_big_EP1","Bunkers",1800],
- ["Land_Fort_Watchtower_EP1","Bunkers",2000],
- ["Fort_EnvelopeSmall_EP1","Trenches",0],
- ["Fort_EnvelopeBig_EP1","Trenches",0],
- ["Land_CamoNetVar_NATO_EP1","Netting",500],
- ["Land_CamoNetB_NATO_EP1","Netting",900],
- ["Land_CamoNet_NATO_EP1","Netting",400],
- ["CampEast_EP1","Misc",1200],
- ["MASH_EP1","Misc",1500],
- ["Land_GuardShed","Misc",800],
- ["Land_Antenna","Misc",500],
- ["Misc_cargo_cont_net1","Misc",1000],
- ["Misc_cargo_cont_net2","Misc",3000],
- ["Misc_cargo_cont_net3","Misc",7000]
- ]];
- };
- _this setvariable ["MSO_cnstrct_usenvg",false];
- };
- ////////////////////////////////
- if (isnil "MSO_cnstrct_fnc_create") then {
- MSO_cnstrct_fnc_create = {
- if ((MSO_cnstrct_preview getvariable "MSO_cnstrct_color") != COLOR_GREEN) exitwith {};
- private ["_class"];
- _class = MSO_cnstrct_preview getvariable "MSO_cnstrct_type";
- {
- if ((_x select 0) == _class) exitwith {
- private ["_supplies"];
- _supplies = MSO_cnstrct_center getvariable "MSO_cnstrct_supplies";
- if (_supplies - (_x select 2) >= 0) then {
- MSO_cnstrct_center setvariable ["MSO_cnstrct_supplies", _supplies - (_x select 2)];
- private ["_direction","_position","_object"];
- _direction = getdir MSO_cnstrct_preview;
- _position = screentoworld [0.5,0.5];
- _object = createvehicle [_class,_position,[],0,"NONE"];
- _object setdir _direction;
- _object setpos _position;
- [MSO_cnstrct_center,"MSO_cnstrct_buildings",_object,true] call bis_fnc_variablespaceadd;
- };
- deletevehicle MSO_cnstrct_preview;
- };
- } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_items");
- };
- MSO_cnstrct_fnc_handler = {
- private ["_terminate"];
- _terminate = false;
- private ["_keyscancel","_keysnvg","_keyssell"];
- _keyscancel = (actionKeys "MenuBack") + [1];
- _keysnvg = actionKeys "NightVision";
- _keyssell = actionKeys "Compass";
- private ["_key","_shift","_ctrl","_alt"];
- _key = _this select 1;
- if (count _this > 5) then {
- //mouse
- //_shift = _this select 4;
- _ctrl = _this select 5;
- //_alt = _this select 6;
- } else {
- //keyboard
- //_shift = _this select 2;
- _ctrl = _this select 3;
- //_alt = _this select 4;
- };
- if !(isnil {MSO_cnstrct_center getvariable "MSO_cnstrct_busy"}) exitwith {
- sleep 0.2;
- MSO_cnstrct_center setvariable ["MSO_cnstrct_busy",nil];
- };
- MSO_cnstrct_center setvariable ["MSO_cnstrct_busy",true];
- ////////////////////////////////
- if ((_key == 0) and (not isnull MSO_cnstrct_preview) and (not _ctrl)) then {
- [] call MSO_cnstrct_fnc_create;
- [] call MSO_cnstrct_fnc_refresh;
- } else {
- if (_key in _keyscancel) then {
- switch (tolower(typename MSO_cnstrct_params)) do {
- case "scalar" : {
- [] call MSO_cnstrct_fnc_refresh;
- };
- case "string" : {
- deletevehicle MSO_cnstrct_preview;
- };
- default {
- if (not isnull MSO_cnstrct_preview) then {
- [] call MSO_cnstrct_fnc_refresh;
- deletevehicle MSO_cnstrct_preview;
- } else {
- _terminate = true;
- };
- };
- };
- };
- if (_key in _keyssell) then {
- [] call MSO_cnstrct_fnc_sell;
- };
- if (_key in _keysnvg) then {
- if (player hasweapon "NVGoggles") then {
- private ["_bool"];
- _bool = not (MSO_cnstrct_center getvariable "MSO_cnstrct_usenvg");
- MSO_cnstrct_center setvariable ["MSO_cnstrct_usenvg",_bool];
- camusenvg _bool;
- };
- };
- };
- if (_terminate) then {
- if (not isnull MSO_cnstrct_preview) then {
- deletevehicle MSO_cnstrct_preview;
- };
- MSO_cnstrct_center = nil;
- MSO_cnstrct_preview = nil;
- };
- };
- MSO_cnstrct_fnc_refresh = {
- MSO_cnstrct_params = false;
- showcommandingmenu "";
- showcommandingmenu "#USER:MSO_cnstrct_menu_0";
- };
- MSO_cnstrct_fnc_sell = {
- private ["_position","_object"];
- _position = screentoworld [0.5,0.5];
- _object = _position nearestobject "all";
- if (isnull _object) exitwith {};
- if (_object distance _position > 7) exitwith {};
- private ["_type"];
- _type = typeof _object;
- {
- if ((_x select 0) == _type) exitwith {
- MSO_cnstrct_center setvariable ["MSO_cnstrct_supplies", (MSO_cnstrct_center getvariable "MSO_cnstrct_supplies") + (_x select 2)];
- [MSO_cnstrct_center,"MSO_cnstrct_buildings",_object,true] call bis_fnc_variablespaceremove;
- deletevehicle _object;
- };
- } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_items");
- };
- MSO_cnstrct_fnc_update = {
- private ["_supplies"];
- _supplies = MSO_cnstrct_center getvariable "MSO_cnstrct_supplies";
- ((uinamespace getvariable "BIS_CONTROL_CAM_DISPLAY") displayctrl 112224) ctrlsetstructuredtext (parsetext format["<t color='#ddffdd' size='2.2'>S%1</t>",_supplies]);
- switch (tolower(typename MSO_cnstrct_params)) do {
- case "scalar" : {
- //open menu
- private ["_i"];
- _i = 0;
- {
- private ["_category"];
- _category = _x;
- if (_i == MSO_cnstrct_params) exitwith {
- private ["_types","_names","_enabled"];
- _types = []; _names = []; _enabled = [];
- {
- if (_category == (_x select 1)) then {
- private ["_type","_cost"];
- _type = _x select 0;
- _cost = _x select 2;
- _types = _types + [_type];
- _names = _names + [(gettext (configfile >> "CfgVehicles" >> _type >> "displayName")) + format [" %1", _cost]];
- _enabled = _enabled + [if (_supplies - _cost >= 0) then {1} else {0}];
- };
- } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_items");
- [[_category,true],"MSO_cnstrct_menu2",[_types,_names,_enabled],"","MSO_cnstrct_params = '%1'; showcommandingmenu ''"] call BIS_fnc_createmenu;
- };
- _i = _i + 1;
- } foreach (MSO_cnstrct_center getvariable "MSO_cnstrct_categories");
- showcommandingmenu "#USER:MSO_cnstrct_menu2_0";
- };
- case "string" : {
- //create preview
- private ["_class","_position"];
- _class = MSO_cnstrct_params;
- MSO_cnstrct_params = false;
- showcommandingmenu "";
- if (_class == "") exitwith {};
- _position = screentoworld [0.5,0.5];
- if (_position distance MSO_cnstrct_center > (MSO_cnstrct_center getvariable "MSO_cnstrct_radius")) exitwith {};
- private ["_camera","_ghost"];
- _camera = MSO_cnstrct_center getvariable "MSO_cnstrct_camera";
- _ghost = gettext (configfile >> "CfgVehicles" >> _class >> "ghostpreview");
- if (_ghost == "") then {_ghost = _class};
- MSO_cnstrct_preview = _ghost createvehiclelocal _position;
- MSO_cnstrct_preview setvariable ["MSO_cnstrct_type",_class];
- MSO_cnstrct_preview setobjecttexture [0,COLOR_GRAY];
- _camera camsettarget MSO_cnstrct_preview;
- _camera camcommit 0;
- while {not isnull MSO_cnstrct_preview} do {
- private ["_color","_position"];
- _position = getpos MSO_cnstrct_preview;
- _color = if (count (_position isflatempty [(sizeof _class) / 4,0,0.8,(sizeof _class),0,false,MSO_cnstrct_preview]) > 0) then {COLOR_GREEN} else {COLOR_GRAY};
- MSO_cnstrct_preview setobjecttexture [0,_color];
- if (_position distance MSO_cnstrct_center > (MSO_cnstrct_center getvariable "MSO_cnstrct_radius")) exitwith {
- deletevehicle MSO_cnstrct_preview;
- [] call MSO_cnstrct_fnc_refresh;
- };
- MSO_cnstrct_preview setvariable ["MSO_cnstrct_color",_color];
- sleep 0.2;
- };
- };
- default {
- [] call MSO_cnstrct_fnc_refresh;
- };
- };
- };
- };
- ////////////////////////////////
- disableserialization;
- private ["_position","_viewdistance"];
- _position = getpos _this;
- _viewdistance = viewdistance;
- setviewdistance ((_this getvariable "MSO_cnstrct_radius") max 50);
- _camera = "camconstruct" camcreate [_position select 0, _position select 1, 5];
- _camera cameraeffect ["internal","back"];
- _camera campreparefov 0.900;
- _camera campreparefocus [-1,-1];
- _camera camcommitprepared 0;
- cameraeffectenablehud true;
- _camera camConstuctionSetParams ([_position] + [_this getvariable "MSO_cnstrct_radius",10]);
- BIS_CONTROL_CAM = _camera;
- showcinemaborder false;
- 1122 cutrsc ["constructioninterface","plain"];
- ////////////////////////////////
- MSO_cnstrct_center = _this;
- MSO_cnstrct_params = "";
- MSO_cnstrct_preview = objnull;
- MSO_cnstrct_center setvariable ["MSO_cnstrct_camera",_camera];
- MSO_cnstrct_center setvariable ["MSO_cnstrct_usenvg",false];
- ////////////////////////////////
- private ["_display"];
- _display = findDisplay 46;
- private ["_keydown","_keyup","_mousedown"];
- _keydown = _display displayaddeventhandler ["KeyDown","0 = _this spawn MSO_cnstrct_fnc_handler;"];
- _keyup = _display displayaddeventhandler ["KeyUp","0 = _this spawn MSO_cnstrct_fnc_handler;"];
- _mousedown = _display displayaddeventhandler ["MouseButtonDown","0 = _this spawn MSO_cnstrct_fnc_handler;"];
- ////////////////////////////////
- [["Categories",true],"MSO_cnstrct_menu",_this getvariable "MSO_cnstrct_categories","","MSO_cnstrct_params = %2"] call BIS_fnc_createmenu;
- [] call MSO_cnstrct_fnc_refresh;
- ////////////////////////////////
- while {not isnil "MSO_cnstrct_center"} do {
- [] call MSO_cnstrct_fnc_update;
- sleep 0.2;
- };
- ////////////////////////////////
- _camera cameraeffect ["terminate","back"];
- camdestroy _camera;
- 1122 cuttext ["","plain"];
- BIS_CONTROL_CAM = nil;
- showcommandingmenu "";
- setviewdistance _viewdistance;
- _display displayremoveeventhandler ["KeyDown",_keydown];
- _display displayremoveeventhandler ["KeyUp",_keyup];
- _display displayremoveeventhandler ["MouseButtonDown",_mousedown];