Jump to content
Sign in to follow this  
Gekkibi

Script: Triangulation

Recommended Posts

Updated my old OFP-script. It allows objects (units, vehicles or static objects) to triangulate one single specified target. Good for finding hidden enemy camps, hidden weapon caches etc where it is not wise to give specific coordinates to the player(s), but just a general direction.

Haven't tested in MP.

The script is two-fold: Triangulation.sqs allows objects to triangulate their target. Triangulation_marker.sqs places marker pointing the average position of the target. Both are WIP, but they works.

Not sure if anyone would want to use it, but at least test it and give me feedback. Here are the scripts:

triangulation.sqs:

; Triangulation by Gekkibi

; Version 0.01

; Copying and distributing this SQS-script is under EVVKTVH/ICCLEIYSIUYA license:

; http://evvk.com/evvktvh.html

;

; Features:

; - Units, vehicles, aircrafts or static objects can triangulate designated target. The more units triangulates at the same time the more precise the triangulation.

; - If one unit triangulates, only direction is revealed.

; - If two units triangulates, rough location is revealed (Spot where the triangulation lines crosses).

; - If three or more units triangulates, the target will most likely be in the area defined by triangulation lines.

; - Marker pointing the average position of the target is created if there are three units to triangulate one single target.

; - Triangulation has a maximum range. No line is drawn when target is further than the triangulation range.

; - Triangulation has a margin of error. The closer the target is related to the maximum range, the less this margin of error affects the triangulation.

; - Doppler-effect causes the marker to shift its position if target is moving.

;

; Known bugs:

; - Program don't stop even if the unit who triangulates gets destroyed (Easy to fix, I am just too lazy atm).

; - Doppler-effect isn't working very well...

; - Average marker won't disappear if target went out of range.

;

; TO-DO -list:

; - Allow multiple targets per script (array).

; - Trianguled range from stated defined position.

; - Adjustable "FOV" (No more 360 degrees. 10 is more realistic).

; - Allow this to be executed and stopped by using exec.

; - Sound when target is in range. Sound enhances when unit turns to the target.

; - Allow triangulation line color change.

; - Allow debug mode to be activated via exec.

; - Simple marker to designate the position of triangulator.

; - New error randomization during script.

; - Objects and targets speeds affects the error.

; - For now, the marker pointing the average position of target is calculated by only three units, no matter how many truly does triangulation.

; - Allow average marker color & shape change.

;

; Thanks to:

; - Fincuan for helping with call compile format.

;

; Installation:

; Copy triangulation.sqs and triangulation_marker.sqs to \missions\mission.island\Triangulation folder.

; Execute triangulation.sqs (As many as you like) in any init field(s).

; If you want to see marker pointing the average position of target, execute triangulation_marker.sqs in any init field (Execute only once).

;

; Syntax to execute: [<_object | string>, <_target | string>, <_range | number>, <_errormargin | number>, <_line_width | number>, <_refresh_rate | number>] exec "Triangulation\triangulation.sqs";

; Where: _object The unit or object that triangulates.

; _target The target what is triangulated.

; _range Maximum range of triangulation.

; _errormargin Margin of error. How much in degrees can the triangulation line differ from the true direction (Final error is randomized by using this variable).

; _line_width The width of the triangulation line. If set to 0, no line is drawn.

; _refresh_rate How often does the script check if the target is out of range and how often the position and direction of the line is updated.

; Example: [this, enemy_antenna, 750, 10, 1, 0.1] exec "Triangulation\triangulation.sqs";

;

; Syntax to execute: [<_objects | array>, _refresh_rate | number> exec "Triangulation\triangulation_marker.sqs";

; Where: _objects The units who are triangulating one single target (Must be three units).

; _refresh_rate How often the calculations are done and the marker position is changed.

; Example: [[car1, spotter, helicopter1], 0.1] exec "Triangulation\triangulation_marker.sqs";

?(!isServer): exit;

_object = _this select 0;

_target = _this select 1;

_range = _this select 2;

_errormargin = _this select 3;

_line_width = _this select 4;

_refresh_rate = _this select 5;

_error = random _errormargin - random _errormargin;

_triangulation_line = str(_object) + "_triangulation_line";

createMarker [_triangulation_line, getPos _object];

_triangulation_line setMarkerShape "RECTANGLE";

_triangulation_line setMarkerColor "ColorBlack";

_triangulation_line setMarkerSize [0, 0];

#NO TARGET

?(getMarkerSize _triangulation_line select 0 == _line_width): _triangulation_line setMarkerSize [0, 0];

?(_object distance _target) < _range): goto "TARGET";

~_refresh_rate

goto "NO TARGET";

#TARGET

?(getMarkerSize _triangulation_line select 0 != _line_width): _triangulation_line setMarkerSize [_line_width, _range / 2];

?(_object distance _target > _range): goto "NO TARGET";

_triangulation_line setMarkerDir ((getPos _target select 0) - (getPos _object select 0)) atan2 ((getPos _target select 1) - (getPos _object select 1)) + ((_object distance _target) / _range) * _error;

_triangulation_line setMarkerPos [(getPos _object select 0) + (sin (markerDir _triangulation_line) * _range / 2), (getPos _object select 1) + (cos (markerDir _triangulation_line) * _range / 2)];

call compile format ["%1_triangulation_direction = MarkerDir _triangulation_line;", _object];

~_refresh_rate

goto "TARGET";

triangulation_marker.sqs:

_objects = _this select 0;

_refresh_rate = _this select 1;

_object1 = _objects select 0;

_object2 = _objects select 1;

_object3 = _objects select 2;

createMarker ["triangulation_marker", [0, 0]];

"triangulation_marker" setMarkerShape "ICON";

"triangulation_marker" setMarkerType "mil_dot";

"triangulation_marker" setMarkerColor "ColorRed";

"triangulation_marker" setMarkerSize [5, 5];

#LOOP

_ab_line = _object1 distance _object2;

_ac_line = _object1 distance _object3;

_bc_line = _object2 distance _object3;

_ab_angle = ((getPos _object2 select 0) - (getPos _object1 select 0)) atan2 ((getPos _object2 select 1) - (getPos _object1 select 1));

_ac_angle = ((getPos _object3 select 0) - (getPos _object1 select 0)) atan2 ((getPos _object3 select 1) - (getPos _object1 select 1));

_ba_angle = ((getPos _object1 select 0) - (getPos _object2 select 0)) atan2 ((getPos _object1 select 1) - (getPos _object2 select 1));

_bc_angle = ((getPos _object3 select 0) - (getPos _object2 select 0)) atan2 ((getPos _object3 select 1) - (getPos _object2 select 1));

_ca_angle = ((getPos _object1 select 0) - (getPos _object3 select 0)) atan2 ((getPos _object1 select 1) - (getPos _object3 select 1));

_cb_angle = ((getPos _object2 select 0) - (getPos _object3 select 0)) atan2 ((getPos _object2 select 1) - (getPos _object3 select 1));

?(_ab_angle < 0): _ab_angle = _ab_angle + 360;

?(_ac_angle < 0): _ac_angle = _ac_angle + 360;

?(_ba_angle < 0): _ba_angle = _ba_angle + 360;

?(_bc_angle < 0): _bc_angle = _bc_angle + 360;

?(_ca_angle < 0): _ca_angle = _ca_angle + 360;

?(_cb_angle < 0): _cb_angle = _cb_angle + 360;

call compile format ["a_triangulation_angle = %1_triangulation_direction;", _object1];

call compile format ["b_triangulation_angle = %1_triangulation_direction;", _object2];

call compile format ["c_triangulation_angle = %1_triangulation_direction;", _object3];

?(a_triangulation_angle < 0): a_triangulation_angle = a_triangulation_angle + 360;

?(b_triangulation_angle < 0): b_triangulation_angle = b_triangulation_angle + 360;

?(c_triangulation_angle < 0): c_triangulation_angle = c_triangulation_angle + 360;

_ab_triangle_angle = abs (_ab_angle - a_triangulation_angle);

_ac_triangle_angle = abs (_ac_angle - a_triangulation_angle);

_ba_triangle_angle = abs (_ba_angle - b_triangulation_angle);

_bc_triangle_angle = abs (_bc_angle - b_triangulation_angle);

_ca_triangle_angle = abs (_ca_angle - c_triangulation_angle);

_cb_triangle_angle = abs (_cb_angle - c_triangulation_angle);

?(_ab_triangle_angle > 180): _ab_triangle_angle = abs (_ab_triangle_angle - 360);

?(_ac_triangle_angle > 180): _ac_triangle_angle = abs (_ac_triangle_angle - 360);

?(_ba_triangle_angle > 180): _ba_triangle_angle = abs (_ba_triangle_angle - 360);

?(_bc_triangle_angle > 180): _bc_triangle_angle = abs (_bc_triangle_angle - 360);

?(_ca_triangle_angle > 180): _ca_triangle_angle = abs (_ca_triangle_angle - 360);

?(_cb_triangle_angle > 180): _cb_triangle_angle = abs (_cb_triangle_angle - 360);

_ab_triangle_line = ((_ab_line * abs (sin _ba_triangle_angle)) / (abs (sin (180 - _ab_triangle_angle - _ba_triangle_angle))));

_ac_triangle_line = ((_ac_line * abs (sin _ca_triangle_angle)) / (abs (sin (180 - _ac_triangle_angle - _ca_triangle_angle))));

_ba_triangle_line = ((_ab_line * abs (sin _ab_triangle_angle)) / (abs (sin (180 - _ba_triangle_angle - _ab_triangle_angle))));

_bc_triangle_line = ((_bc_line * abs (sin _cb_triangle_angle)) / (abs (sin (180 - _bc_triangle_angle - _cb_triangle_angle))));

_ca_triangle_line = ((_ac_line * abs (sin _ac_triangle_angle)) / (abs (sin (180 - _ca_triangle_angle - _ac_triangle_angle))));

_cb_triangle_line = ((_bc_line * abs (sin _bc_triangle_angle)) / (abs (sin (180 - _cb_triangle_angle - _bc_triangle_angle))));

call compile format ["a_triangulation_angle = %1_triangulation_direction;", _object1];

call compile format ["b_triangulation_angle = %1_triangulation_direction;", _object2];

call compile format ["c_triangulation_angle = %1_triangulation_direction;", _object3];

_a_1_position = [((getPos _object1 select 0) + (sin (a_triangulation_angle) * _ab_triangle_line)), ((getPos _object1 select 1) + (cos (a_triangulation_angle) * _ab_triangle_line))];

_a_2_position = [((getPos _object1 select 0) + (sin (a_triangulation_angle) * _ac_triangle_line)), ((getPos _object1 select 1) + (cos (a_triangulation_angle) * _ac_triangle_line))];

_b_1_position = [((getPos _object2 select 0) + (sin (b_triangulation_angle) * _ba_triangle_line)), ((getPos _object2 select 1) + (cos (b_triangulation_angle) * _ba_triangle_line))];

_b_2_position = [((getPos _object2 select 0) + (sin (b_triangulation_angle) * _bc_triangle_line)), ((getPos _object2 select 1) + (cos (b_triangulation_angle) * _bc_triangle_line))];

_c_1_position = [((getPos _object3 select 0) + (sin (c_triangulation_angle) * _ca_triangle_line)), ((getPos _object3 select 1) + (cos (c_triangulation_angle) * _ca_triangle_line))];

_c_2_position = [((getPos _object3 select 0) + (sin (c_triangulation_angle) * _cb_triangle_line)), ((getPos _object3 select 1) + (cos (c_triangulation_angle) * _cb_triangle_line))];

_average_x_position = ((_a_1_position select 0) + (_a_2_position select 0) + (_b_1_position select 0) + (_b_2_position select 0) + (_c_1_position select 0) + (_c_2_position select 0)) / 6;

_average_y_position = ((_a_1_position select 1) + (_a_2_position select 1) + (_b_1_position select 1) + (_b_2_position select 1) + (_c_1_position select 1) + (_c_2_position select 1)) / 6;

_average_position = [_average_x_position, _average_y_position];

"triangulation_marker" setMarkerPos _average_position;

~_refresh_rate

goto "LOOP";

Share this post


Link to post
Share on other sites

Nice script, thx. Any chance for a sqf version?

Share this post


Link to post
Share on other sites
Nice script, thx. Any chance for a sqf version?

Yes.

...After I learn SQF! :D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×