Jump to content
Sign in to follow this  
Big Dawg KS

Algorithm for Getting Turret Path

Recommended Posts

Maybe some of you who are better algorithmists than I can lend me some help. I am looking to create a function that finds the turret path of any particular gunner in a vehicle. My method was to recurse through the turret classes in the vehicle's turret. I'm fairly confident that I can produce the algorithm to find the config path (CfgVehicles\vehclass\Turrets\etc....), but converting that into an array (or producing an array from the start) is proving too much for my experience.

Share this post


Link to post
Share on other sites

If it's for a particular gunner in a vehicle? You can use the assignedVehicleRole command.

If you want a list of all turrets, then yeah. Your going to need a recursive function.

Share this post


Link to post
Share on other sites

FPDR

For once I am myself deserving of a facepalm. Thanks UNN I can't believe I totally overlooked that command. The need for going from config path (string) to turret path (array) may still be there however, so if anyone has any good ideas...

Share this post


Link to post
Share on other sites
FPDR

For once I am myself deserving of a facepalm. Thanks UNN I can't believe I totally overlooked that command. The need for going from config path (string) to turret path (array) may still be there however, so if anyone has any good ideas...

Here's an example of a recursive function that builds turretpaths from the config structure ....

_vehicle = vehicle player;
_type = typeOf _vehicle;
[_vehicle,_rearmInterval,(configFile >> "CfgVehicles" >> _type),[]] call rearmTurretRecursive; // highest level call contains essential starting conditions in params 2 and 3


rearmTurretRecursive = {
   private ["_vehicle","_config","_rearmInterval","_turretConfig","_turretPath","_currentTurretPath","_max"];
   _vehicle = _this select 0;
   _rearmInterval = _this select 1;
   _config = _this select 2;
   _turretPath = _this select 3;
   _currentTurretPath = +_turretPath;

   _turretConfig = (_config >> "Turrets");
   _max = count _turretConfig;
   if ( _max > 0 ) then {
       for "_i" from 0 to (_max - 1) do {
           _turret = _turretConfig select _i;
           _turretName = getText (_turret >> "gunnerName");

           _vehicle vehicleChat format ["Rearming %1", _turretName];
           _currentTurretPath set [count _turretPath,_i]; // working around some BI variable scoping fubar
           _magazines = getArray (_turret >> "magazines");
           {
               sleep _rearmInterval;
               _vehicle removeMagazinesTurret [_x,_currentTurretPath];
               sleep _rearmInterval;
               _vehicle vehicleChat format ["... %1", _x];
               _vehicle addMagazineTurret [_x,_currentTurretPath];
           } count _magazines;

           [_vehicle,_rearmInterval,_turretConfig,_currentTurretPath] call rearmTurretRecursive;
       };
   };
};

There may already be a BIS function since 2010. If so, please share.

Edited by cyckuan

Share this post


Link to post
Share on other sites

Your answer is not related to the topic starter's question. We have developed some kind of shit that may help to solve your issue.

Related ticket #17998

/*******************************************************************************
* Project:          Mushi
* Module:           fnc_GetAllTurretPaths.sqf
* Project version:  [1.0.0] 20.03.2014
* Module version:   [1]     20.03.2014
* Author:           RAB, Prodavec, Marbot, DumbkRat, SPESNAZ
* Function:         fnc_GetAllTurretPaths
* Comments:         --//--
*******************************************************************************/

/*
INPUT:
 vehicle : OBJECT

OUTPUT:
 paths_array : ARRAY

EXAMPLE:
 _allPaths = MyTank call fnc_GetAllTurretPaths;
// _allPaths: [[0], [0,0], [0,1]]
*/

private
[
   "_result",
   "_vehicle",
   "_currentNode",
   "_depth",
   "_currentConfig",
   "_cfgTurrets"
];

_result = [];

if ((!isNil "_this") && {(typeName _this) in ["ARRAY", "OBJECT"]}) then
{
   _vehicle = objNull;
   _currentNode = [];
   _depth = -1;
   _currentConfig = objNull;

   switch (typeName _this) do
   {
       case "ARRAY":
       {
           if ((count _this) == 5) then
           {
               _vehicle = _this select 0;
               _currentConfig = _this select 1;
               _currentNode = _this select 2;
               _depth = _this select 3;
               _result = _this select 4;
           };
       };
       case "OBJECT":
       {
           _vehicle = _this;
           _currentConfig = configFile >> "CfgVehicles" >> (typeOf _vehicle);
           _depth = 0;
       };
   };

   if ((!isNil "_vehicle") && (!isNil "_currentNode") && (!isNil "_depth") && (!isNil "_result") && (!isNil "_currentConfig") && {((typeName _vehicle) == "OBJECT") && ((typeName _currentNode) == "ARRAY") && ((typeName _depth) == "SCALAR") && ((typeName _result) == "ARRAY") && ((typeName _currentConfig) == "CONFIG")} && {!isNull _vehicle}) then
   {
       _cfgTurrets = _currentConfig >> "Turrets";

       if (isClass _cfgTurrets) then
       {
           for "_i" from 0 to ((count _cfgTurrets) - 1) step 1 do
           {
               _currentNode set [_depth, _i];
               _result set [count _result, +_currentNode];
               [_vehicle, _cfgTurrets select _i, _currentNode, _depth + 1, _result] call fnc_GetAllTurretPaths;
           };
       };
   };
};

_result;

Edited by Prodavec

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  

×