Home   Help Search Login Register  

Author Topic: Check if Plane is out of bombs  (Read 1902 times)

0 Members and 2 Guests are viewing this topic.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Check if Plane is out of bombs
« on: 27 Mar 2008, 00:15:49 »
Hey folks, long time not read.  :D

I'm working on a "carrier simulation script" which basically simulates a not-physically (in virtual terms) Aircraft carrier. Mission makers can call AI-controlled Air squadrons from this carrier. I have several conditions i check for the squadron to return to carrier (out of fuel, out of ammo, dammaged).

The problem comes up with the ammo tracking. As missionmakers should be able to alter the payload to theyr needs, each plane could carry any sort of weapon. Beside th onboard machine gun, almost everything else is possible (rockets, FFAR, GBU, Maverick and whatever is around in addons).

What i need is a way to track the remaining payload without the machine gun.

Practically speaking:
I have a A10 (as example) and in the script i remove all magazines. I add the Bomblauncher as weapon and it's respective magazines also. As the machine gun is empty, a simple someammo will return false as soon all bombs are dropped.
So far so good. Thats basically what i want.

The problems comes up when i load a magazine for the machine gun into the A10. Now a check with someammo will return true even if all bombs are dropped and only MG has ammo.

I tried the commands primaryWeapon and secondaryWeapon to get a way to sort the weapons and maybe on this way find a solution, but these commands always return empty strings only.


So what i need is a way to determine if a plane/chopper which has a MG and other weapons is out of ammo for the "other weapons".

As i want to keep the script as open as possible for addons, a predefinition of all MG classes seems not the best way to me, except i'll find no other way around.

Help really appreciated.


Myke out

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re: Check if Plane is out of bombs
« Reply #1 on: 27 Mar 2008, 00:52:53 »
Try the hasweapon command.
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Check if Plane is out of bombs
« Reply #2 on: 27 Mar 2008, 01:01:46 »
Doesn't really help. The script basically "knows" already which weapons and magazines are in use. What i need is a way to sort out Machine guns.


:EDIT:
Already tried the following commands:
primaryweapon(secondaryweapon
ammo
someammo
needreload
weapons
magazines

with none of them i was able to sort out the machine guns from the rest of the payload.

:edit:
As i'm not familiar with configs, maybe there could be a solution: if there's a config attribute which let me differ between MG and non-MG, i could collect these informations to sort out all mg types out of my ammo array.
« Last Edit: 27 Mar 2008, 11:50:08 by myke13021 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Check if Plane is out of bombs
« Reply #3 on: 27 Mar 2008, 21:19:01 »
Ah, I wasn't understanding your request, or I could have answered earlier. Either use SPON_getWeaponType or look at it to see how I work out the type of a weapon; it is working the type out based on the inheritance structure in the config file.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Check if Plane is out of bombs
« Reply #4 on: 27 Mar 2008, 22:40:18 »
@Spooner

indeed, your function looks promising to me. Although i'm a little lost when it comes to config issues, you might be able to show me the correct way and help me to get the correct terms i have to use.

First of all, i need to do this on the magazine class, not the weapon class but the approach seems to be the same (correct me if i'm wrong).

Here how far i understand the way.
First of all, the classnames are already known (part of the scriptcall so no big deal to get them).
Let us assume i add a BombLauncher and the respective magazine, 6Rnd_GBU12_AV8B.

Reading your script see the line
Code: [Select]
_unknownConfig = configFile >> "CfgWeapons" >> _unknownWeaponClass;
By replacing "CfgWeapons" with it's ammo counterpart (need help on this...is it "CfgAmmo"?) and setting the magazine classname at the place of _unknownWeaponClass, _unknownConfig should return either "MissileLauncher" or "RocketPods".

Please confirm i understood the priciples correctly and help me fill the gaps.

Thx for your time, Spooner.

:EDIT:
Found this topic which tells me that "CfgMagazines" it is what i have to look for. Another step further.

So would this line of code
Code: [Select]
_whatineedtoknow = configFile >> "CfgMagazines" >> "6Rnd_GBU12_AV8B";
tell me what i need to know: it's either "MissileLauncher" or "RocketPods"?

Corrected: had CfgWeapons instead of CfgMagazines in the last codesnippet.
« Last Edit: 28 Mar 2008, 01:36:36 by myke13021 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Check if Plane is out of bombs
« Reply #5 on: 28 Mar 2008, 01:38:43 »
Well, what my script is looking for is if the weapon is descended from one of the base classes. From this, we can identify it as a MG, rocket, missile, etc. I am not at all sure there is a clear inheritance path for magazines based on weapon type that uses that magazine, so I don't think you can just switch weapons for magazines in my script (I don't have the files available currently, but I think that is so).

What I think you need to do is iterate through the list of weapons on the vehicle, ignoring any that are MGs. Then, for each appropriate weapon you can check which magazine type(s) it can use:
Code: [Select]
_magazineTypesUsedByWeapon = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

and check if any of those magazines types is available in the weapon (magazines or ammo commands should win out there).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Check if Plane is out of bombs
« Reply #6 on: 28 Mar 2008, 01:42:39 »
Thanks Spooner

I guess for now i have enough info to start some tests about what exactly will provide the inormations i need for this. Whenever i hang, i'll come back.

Thx so far.


Myke out

:EDITH:
Ok, i'm stuck. Based on Spooners function "SPON_getWeaponType.sqf" i've tried to include a check of weapontype into my own script. I could use directly Spooners function but i would like to implement it in my script because 1.) i can adapt and shorten it to my needs and, more important to me 2.) i learn more by trying to do it instead of using ready-to-use functions (but i'm sure Spooner made an excellent work with his function, no doubt).

When i look at Spooners function, the relevant part vor me seems to be this:
Code: [Select]
..
...
private ["_unknownClass", "_type"];
_unknownWeaponClass = _this select 0;

_unknownConfig = configFile >> "CfgWeapons" >> _unknownWeaponClass;

if (isClass _unknownConfig) then
{
// Weapon type is unknown, unless we can find a type it belongs to.
_type = SPON_WEAPON_TYPE_UNKNOWN;

while {(isClass _unknownConfig) and (_type == SPON_WEAPON_TYPE_UNKNOWN)} do
{
switch (configName _unknownConfig) do
{
// Personal weapons.
case "PistolCore":
{
_type = SPON_WEAPON_TYPE_PISTOL;
};
case "RifleCore":
{
_type = SPON_WEAPON_TYPE_RIFLE;
};
case "Launcher":
{
_type = SPON_WEAPON_TYPE_LAUNCHER;
};
case "GrenadeLauncher":
{
_type = SPON_WEAPON_TYPE_GRENADE;
};
....
..
_unknownWeaponClass is a classname, given in the scriptcall.
Code: [Select]
_unknownConfig = configFile >> "CfgWeapons" >> _unknownWeaponClass;
As far i understand, this line should read a string out of the config, which is later in the script by this line:
Code: [Select]
switch (configName _unknownConfig) do
checked if the string matches one of the following cases: "RifleCore", "Launcher",...and so on.

For testing purposes i've added the following code into my script:
Code: [Select]
..
...
_whatineedtoknow = configFile >> "CfgWeapons" >> "GAU8";
hint format ["%1", configName _whatineedtoknow];
"GAU8" is the original Weapon of the A10, so the above code should imo return either "CannonCore" or "MGunCore" (referring Spooners function) which should allow me to identify the GAU8 as an MG.

But in preview, the hint i get just says "GAU8" and not what i've expected to see. Probably i'm doing something obvious completely wrong or i misunderstood Spooners function completely. Please, anyone may light me up.
« Last Edit: 31 Mar 2008, 16:35:00 by myke13021 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Check if Plane is out of bombs
« Reply #7 on: 31 Mar 2008, 17:14:11 »
I don't think you've really understood my function, perhaps because you don't understand the way that config files are constructed and/or the concept of class inheritance. A full explanation of object-oriented design and class inheritance is a bit beyond the scope of reply that I'm prepared to give ;P

In essence, there are a number of base classes defined by BIS (MGunCore, RifleCore, etc). All vehicle-based MGs inherit traits from the MGunCore and all rifles inherit traits from the RifleCore. There will also be chains of inheritance, so ABC_M4_leet_sniper_version (from an addon) might inherit from M4SPR which inherits from M4 which in turn inherits from RifleCore (Don't quote me on this inheritance chain, since I don't have the config files in front of me right now to check). Thus, you have to look all the way up an inheritance chain to see what type a weapon really is; this is what the while loop is doing in my script, stepping up the chain and seeing if it can find a base class that it recognises.

Anyway, here is what you actually want, because I think you will struggle with the complex concepts required if you are totally unfamiliar with them. Hopefully, since this script is a lot simpler, you might be able to understand what is going on:
Code: (isMG.sqf) [Select]
private ["_unknownWeaponClass", "_isMG", "_config"];
_unknownWeaponClass = _this select 0;

// Get the configuration data for the given weapon class.
_config = configFile >> "CfgWeapons" >> _unknownWeaponClass;

// Unless we find a machine-gun in the inheritance path, the weapon isn't a machine-gun.
_isMG = false;

// _config will stop being a class when we have reached the top of the inheritance chain.
while {isClass _config} do
{
    // If the config we are looking at is the base machine-gun, then our unknown class, or one of its ancestors, is the machine gun.
    if ((configName _config) == "MGunCore") exitWith
    {
        _isMG = true;
    };

    // This config isn't a machine-gun, but check if its parent (the class it inherits from) is one.
    _config = inheritsFrom _config;
};

_isMG; // Return value.

EDIT: Corrected syntax for while loop.
« Last Edit: 31 Mar 2008, 22:59:54 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Check if Plane is out of bombs
« Reply #8 on: 31 Mar 2008, 17:31:48 »
Indeed, i had absolutely no knowledge of configs and how they work. But your explanation brought me a huge step forward. Just to make sure i'm on the right way: it works with some kind of subclasses. Maybe a complete different example:

Viper << Dodge << Car << LandVehicle

or also:

Spooner << Male (guessing) << Human << Mammal

So it raises from unique class to more and more generalized classes. So the part i missed that i have to go through the whole chain of classes to check if it is MGunCore or not.

Thanks for your time and your straight-to-the-point explanation, Spooner.

I will try this out and come back when i'm stuck again...but probably i can work with your script.


Myke out

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Check if Plane is out of bombs
« Reply #9 on: 31 Mar 2008, 22:58:29 »
You are understanding that correctly, even including my gender ;P

It might help to glance at on of the BIS configs to understand further. It might make more sense if you see:
Code: [Select]
// Sometimes an empty class is defined, which tells the compiler how the inheritance works and tells us that
// the class is actually defined in another file.
class Car : LandVehicle { };

// "class" means we are defining a new class. : is "inherits from"
class Dodge : Car
{
   ...config here...
};

class Viper : Dodge
{
   ...config here...
};
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: Check if Plane is out of bombs
« Reply #10 on: 31 Mar 2008, 23:38:03 »
Excellent work from Spooner as usual. Some minor glitches were present but we already have sorted out these issues via MSN. Thx again mate.

As i already mentoined, a config tutorial for scripters would be a good idea since i think quite a lot people are in scripting OR in addon making, rarely in both involved. I guess fiew scripting problems could be solved by knowing how to fiddle with configs.

As my script now works like a charm (at least the Cannon deleting part) this thread is...

*CLOSED*