diff --git a/addons/trenches/functions/fnc_blockTrench_place.sqf b/addons/trenches/functions/fnc_blockTrench_place.sqf index f2aa062fe8..f602a871e0 100644 --- a/addons/trenches/functions/fnc_blockTrench_place.sqf +++ b/addons/trenches/functions/fnc_blockTrench_place.sqf @@ -8,6 +8,7 @@ * 1: Position * 2: Force - ignoring saftey checks (optional: false) * 3: Cut Grass (optional: false) + * 4: Dry Run - Just test if possible (can run on clients) * * Return Value: * @@ -21,10 +22,10 @@ * Public: No */ -if (!isServer) exitWith { ERROR("function must be called on server"); [false, "server-only"]; }; +params [["_start2d", [], [[]]], ["_end2d", [], [[]]], ["_force", false, [false]], ["_cutGrass", false, [false]], ["_dryRun", false, [false]]]; +TRACE_4("blockTrench_place",_start2d,_end2d,_force,_dryRun); -params [["_start2d", [], [[]]], ["_end2d", [], [[]]], ["_force", false, [false]], ["_cutGrass", false, [false]]]; -TRACE_3("blockTrench_place",_start2d,_end2d,_force); +if ((!isServer) && {!_dryRun}) exitWith { ERROR("function must be called on server"); [false, "server-only"]; }; scopeName "main"; @@ -71,6 +72,14 @@ if (_east) then { TRACE_3("",_east,_origin2D,_length); if (_length < 2) exitWith { [false, "too short"] breakOut "main" }; +if (_dryRun) exitWith { // return an array of block positions + private _positions = []; + for "_i" from 0 to _length do { // intentionally inclusive + _positions pushBack (_origin2D vectorAdd (if (_east) then {[(_i + 0.5) * _cellsize, 0]} else {[0, (_i + 0.5) * _cellsize]})); + }; + [true, "dry run", _positions] +}; + // Test and get block data private _blockData = []; diff --git a/addons/zeus/functions/fnc_getModuleDestination.sqf b/addons/zeus/functions/fnc_getModuleDestination.sqf index bc939445dc..b328201d6c 100644 --- a/addons/zeus/functions/fnc_getModuleDestination.sqf +++ b/addons/zeus/functions/fnc_getModuleDestination.sqf @@ -8,7 +8,7 @@ * 1: Code to run when position is ready (will be passed the following array) * - 0: Successful * - 1: Object - * - 2: Position ASL + * - 2: Mouse Pos ASL * - 3: State of Shift * - 4: State of Ctrl * - 5: State of Alt @@ -16,6 +16,9 @@ * 3: Icon image file (default: "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa") * 4: Icon color (default: [1,0,0,1]) * 5: Icon Angle (default: 0) + * 6: Draw Code (default: {}) + * - 0: Object + * - 1: Mouse Pos ASL * * Return Value: * None @@ -26,7 +29,7 @@ * Public: No */ -params ["_object", "_code", ["_text", ""], ["_icon", "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa"], ["_color", [1,0,0,1]], ["_angle", 0]]; +params ["_object", "_code", ["_text", ""], ["_icon", "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa"], ["_color", [1,0,0,1]], ["_angle", 0], ["_drawCode", {}]]; if (missionNamespace getVariable [QGVAR(moduleDestination_running), false]) exitWith { [false, _object, [0,0,0], false, false, false] call _code; @@ -95,7 +98,7 @@ GVAR(moduleDestination_mapDrawEH) = [((findDisplay 312) displayCtrl 50), "draw", // Add draw EH for 3D camera view - draws the 3D icon and line [{ - (_this select 0) params ["_object", "_code", "_text", "_icon", "_color", "_angle"]; + (_this select 0) params ["_object", "_code", "_text", "_icon", "_color", "_angle", "_drawCode"]; if ((isNull _object) || {isNull findDisplay 312} || {!isNull findDisplay 49}) then { TRACE_3("null-exit",isNull _object,isNull findDisplay 312,isNull findDisplay 49); GVAR(moduleDestination_running) = false; @@ -104,6 +107,7 @@ GVAR(moduleDestination_mapDrawEH) = [((findDisplay 312) displayCtrl 50), "draw", if (GVAR(moduleDestination_running)) then { // Draw the 3d icon and line private _mousePosAGL = screenToWorld getMousePosition; + [_object, AGLToASL _mousePosAGL] call _drawCode; drawIcon3D [_icon, _color, _mousePosAGL, 1.5, 1.5, _angle, _text]; drawLine3D [_mousePosAGL, ASLtoAGL (getPosASL _object), _color];; } else { @@ -116,4 +120,4 @@ GVAR(moduleDestination_mapDrawEH) = [((findDisplay 312) displayCtrl 50), "draw", GVAR(moduleDestination_displayEHKeyboard) = nil; GVAR(moduleDestination_mapDrawEH) = nil; }; -}, 0, [_object, _code, _text, _icon, _color, _angle]] call CBA_fnc_addPerFrameHandler; +}, 0, [_object, _code, _text, _icon, _color, _angle, _drawCode]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/zeus/functions/fnc_moduleLayTrench.sqf b/addons/zeus/functions/fnc_moduleLayTrench.sqf index ae9d60f2f2..e92725138f 100644 --- a/addons/zeus/functions/fnc_moduleLayTrench.sqf +++ b/addons/zeus/functions/fnc_moduleLayTrench.sqf @@ -27,24 +27,31 @@ if !(["ace_trenches"] call EFUNC(common,isModLoaded)) exitWith { [LSTRING(RequiresAddon)] call FUNC(showMessage); }; -private _startPos = getPosASL _logic; // change position of logic to be aligned with grid -getTerrainInfo params ["", "", "_cellsize"]; -_startPos = (_startPos select [0,2]) apply {_cellsize * round (_x / _cellsize)}; -_logic setPos _startPos; +private _drawCode = { + params ["_object", "_mousePos"]; + private _startPos = getPos _object; + ([_startPos, _mousePos, false, false, true] call EFUNC(trenches,blockTrench_place)) params ["_valid", "_reason", "_extra"]; + if (_valid) then { + { + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [0,0,1,1], (_x select [0,2]) + [0], 1.5, 1.5, 0, ""]; + } forEach _extra; + } else { + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,0,1,1], (_startPos select [0,2]) + [0], 1.5, 1.5, 0, ""]; + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,0,1,1], (_mousePos select [0,2]) + [0], 1.5, 1.5, 0, ""]; + }; +}; - -// todo: it would be nice to show visually that trenches can only be dug north/south or east/west private _text = format ["%1 %2", LELSTRING(trenches,ConfirmDig), LLSTRING(ModuleLayTrenchline_Tooltip)]; [_logic, { params ["_successful", "_logic", "_mousePosASL", "_shift"]; TRACE_4("getModuleDestination",_successful,_logic,_mousePosASL,_shift); + if (isNull _logic) exitWith { WARNING("logic missing"); }; private _startPosASL = getPosASL _logic; deleteVehicle _logic; - if (isNull _logic) exitWith { TRACE_1("exit",isNull _logic); }; if (!_successful) exitWith { TRACE_1("exit",_successful); }; private _args = [_startPosASL, _mousePosASL, _shift]; TRACE_1("sending event",_args); [QEGVAR(trenches,layTrenchline), [ace_player, _args]] call CBA_fnc_serverEvent; -}, _text, "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [0, 1, 0, 1], 45] call FUNC(getModuleDestination); +}, _text, "\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [0, 1, 0, 1], 45, _drawCode] call FUNC(getModuleDestination);