Jump to content

Sign in to follow this  
Drongo69

Finding higher inheritance

Recommended Posts

Using inheritsFrom, we can determine the immediate type of vehicle that another vehicle inherited from. However, I wish to determine if higher up the chain the vehicle inherited from Car, Tank, etc. Is there an efficient way to do this?

The reason I want this is for applying the correct marker type for mod vehicles. At the moment I have hard-coded the system to recognize the BIS MBTs etc as such and apply the correct marker, but unrecognized vehicles all the the same generic marker regardless of type. Hardcoding and re-releasing the system every time a new mod comes out is not practical.

Any ideas?

Here are the arrays of types I currently use:

dtTypesInfantry = [];
dtTypesSniper = ["B_Soldier_sniper_base_F","B_spotter_F","B_sniper_F","O_Soldier_sniper_base_F","O_spotter_F","O_sniper_F","I_Soldier_sniper_base_F","I_Spotter_F","I_Sniper_F"];
dtTypesCrew = [];
dtTypesWheeled = ["B_G_Offroad_01_F","B_G_Offroad_01_armed_F"];
dtTypesRecon = ["B_MRAP_01_F","B_MRAP_01_gmg_F","B_MRAP_01_hmg_F","O_MRAP_02_F","O_MRAP_02_hmg_F","O_MRAP_02_gmg_F","I_MRAP_03_F","I_MRAP_03_hmg_F","I_MRAP_03_gmg_F"];
dtTypesAPC = ["B_APC_Wheeled_01_base_F","B_APC_Wheeled_01_cannon_F","O_APC_Wheeled_02_base_F","O_APC_Wheeled_02_rcws_F","B_APC_Tracked_01_rcws_F","O_APC_Tracked_02_cannon_F","I_APC_Wheeled_03_cannon_F","I_APC_tracked_03_cannon_F"];
dtTypesMBT = ["B_MBT_01_cannon_F","O_MBT_02_cannon_F","I_MBT_03_cannon_F","B_MBT_01_TUSK_F"];
// For general armoured vehicles
dtTypesAFV = [];
dtTypesSPAA = ["B_APC_Tracked_01_AA_F","O_APC_Tracked_02_AA_F"];
dtTypesTruck = ["B_Truck_01_transport_F","B_Truck_01_covered_F","O_Truck_02_covered_F","O_Truck_02_transport_F","I_Truck_02_covered_F","I_Truck_02_transport_F"];
dtTypesCar = ["C_Offroad_01_F","C_SUV_01_F","C_Van_01_transport_F","B_G_Van_01_transport_F","C_Van_01_box_F","C_Hatchback_01_F","C_Hatchback_01_sport_F"];
dtTypesArtillery = ["B_MBT_01_arty_F","B_MBT_01_mlrs_F","O_MBT_02_arty_F","I_Mortar_01_F","O_Mortar_01_F","B_G_Mortar_01_F","B_Mortar_01_F"];
dtTypesStructure = [];
dtTypesGunship = ["B_Heli_Light_01_armed_F","B_Heli_Attack_01_F","O_Heli_Light_02_F","O_Heli_Attack_02_black_F","O_Heli_Attack_02_F"];
dtTypesTransportHelo = ["B_Heli_Light_01_F","B_Heli_Transport_01_F","O_Heli_Light_02_unarmed_F","I_Heli_Transport_02_F","I_Heli_light_03_F","I_Heli_light_03_unarmed_F"];
dtTypesFixedWing = ["I_Plane_Fighter_03_AA_F","I_Plane_Fighter_03_CAS_F","B_Plane_CAS_01_F","O_Plane_CAS_02_F"];

dtTypesShip = ["B_Boat_Armed_01_minigun_F","B_Boat_Transport_01_F","B_Lifeboat","O_Boat_Armed_01_hmg_F","O_Boat_Transport_01_F","O_Lifeboat","I_Boat_Armed_01_minigun_F","I_Boat_Transport_01_F","C_Rubberboat"];
dtTypesCivilian = ["C_man_1","C_man_polo_1_F","C_man_polo_2_F","C_man_polo_4_F","C_man_polo_5_F","C_man_polo_6_F","C_man_p_fugitive_F","C_man_hunt_1_F","C_man_w_worker_F","C_Nikos"];
dtTypesStatic = [];
dtTypesBike = ["B_Quadbike_01_F","O_Quadbike_01_F","I_Quadbike_01_F","C_Quadbike_01_F","B_G_Quadbike_01_F"];

dtTypesUAV = ["B_UAV_01_F","B_UAV_02_F","B_UAV_02_CAS_F","O_UAV_02_F","O_UAV_02_CAS_F","O_UAV_01_F","I_UAV_01_F","I_UAV_02_F","I_UAV_02_CAS_F"];
dtTypesUGV = ["B_UGV_01_F","B_UGV_01_rcws_F","O_UGV_01_F","O_UGV_01_rcws_F","I_UGV_01_F","I_UGV_01_rcws_F"];

dtTypesCivilianVehicles = ["C_Offroad_01_F","C_Quadbike_01_F","C_Offroad_01_F","C_SUV_01_F","C_Van_01_transport_F","B_G_Van_01_transport_F","C_Van_01_box_F","C_Hatchback_01_F","C_Hatchback_01_sport_F"];

Share this post


Link to post
Share on other sites

You can write a "cycled" function which does search up the tree until a specific category or the root node is found.

Like this:

_desiredtype = (configFile >> "CfgVehicles" >> "Car");
_type = typeOf myUnit;
_isOfDesiredType = false;
_stop = false;

while {!_stop} do {
   _parentType = inheritsFrom _type; //Get parent type
   if (_parentType == _desiredType) then {
          _isOfDesiredType = true;
          _stop = true;
   }
   if (isNil "_parentType" || _parentType == "") then {
          _stop = true;
   }
}

(be warned: the code is just to illustrate the principle and may not work as it is)

EDIT: actually, there may be a simpler way. Have you tried isKindOf?

myVehicle isKindOf "Tank";

Edited by DarkWanderer

Share this post


Link to post
Share on other sites

For objects you can simply use "isKindOf" which should suffice in your case.

If you wan't to do the same with config classes, then you can use something like this:

FNC_kindOf = {
   _inherit = inheritsFrom _this;
   _list = [configName _this];
   while { (configName _inherit) != "" } do {
       _list set[count _list,configName _inherit];    
       _inherit = inheritsFrom( _inherit );
   }; 
   _list
};

(returns an array of all parentclasses of a specified config entry)

Share this post


Link to post
Share on other sites

I had no idea isKindOf existed. I gave it a quick test and it should do the trick.

Thanks very much DarkWanderer :)

Thanks also Tajin.

Edited by Drongo69

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  

×