Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add destroyed boat ejecting #6330

Merged
merged 10 commits into from
Dec 16, 2019
Merged

Conversation

Dystopian
Copy link
Contributor

@Dystopian Dystopian commented May 7, 2018

When merged this pull request will:

  • add destroyed boat ejecting framework;
  • make Rubber Boat, Water Scooter, RHIB eject crew if destroyed.

Some boats like rubber boat or scooter are very easy to destroy even with 1-2 bullets or if they are just collided with other object (especially by engine). It's OK except it kills its crew (Arma feature) even if it's not really possible. This PR adds HandleDamage event handler which ejects crew when boat is destroyed.

This way has at least one defect: ejected crew is not damaged with any projectile type. You can destroy boat with grenade, HE rocket or even explosive charge but crew will survive when eject. From my point of view it's not a big deal in comparison with dying from stone collision but maybe you think otherwise.

Config values are safe for 3rd-party mods and can be easily added to them. E.g. CUP has suitable Zodiac and RHIB boats. Suitable CUP boats inherit vanilla boats and are fixed automatically.

I also tested solution with allowDamage command but it has more bugs without any advantages.

[QGVAR(ejectDestroyed), _vehicle] call CBA_fnc_globalEvent;
};
}];
_vehicle setVariable [QGVAR(ejectDestroyedHDEH), _eh];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to store this variable, just use _thisEventHandler in the event to remove itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it because HandleDamage is local and doesn't hit on all machines, so I don't have _thisEventHandler value everywhere

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Huh? Of course you have _thisEventHandler everywhere, it's a block of code used in an event handler added with addEventHandler.

Personally I would much rather have some leftover event handlers on some machines which will remove themselves if a dead vehicle ever changes locality and takes a single hit of damage again (which, let's be honest, isn't likely). It will make the code more elegant and remove unnecessary network traffic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why do you need it? https://github.com/acemod/ACE3/pull/6330/files#diff-71d8e1c52a77144d92094e89a77b7a55R6
That?
The eventhandler and variables are removed anyway when the vehicle is destroyed aren't they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have _thisEventHandler only where vehicle is local. EH is fired only on one machine so I have to clean up EHs on all other machines. I always thought cleanup is necessary. If you insist I can get rid of it, no problem.

The eventhandler and variables are removed anyway when the vehicle is destroyed aren't they?

No, they aren't removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will clean themselves up in the event that a dead vehicle switches locality and receives more damage (again, not likely). It's totally harmless to leave them sitting there doing nothing.

@kymckay
Copy link
Member

kymckay commented May 7, 2018

Regarding the defect you mention, we could surely have it check for explosives (etc.) and let the units be killed in those cases.

Also not sure whether this belong here or in cookoff (as it has damage handling for other vehicles which don't actually cook off)

@kymckay kymckay added the kind/feature Release Notes: **ADDED:** label May 7, 2018
@kymckay kymckay added this to the 3.13.0 milestone May 7, 2018
@Dystopian
Copy link
Contributor Author

we could surely have it check for explosives (etc.) and let the units be killed in those cases.

But we don't know how big explosion is, if it's small grenade or big satchel. Also distance is important. ATM I don't think it's worth it to check all of these parameters.

@dedmen
Copy link
Contributor

dedmen commented May 8, 2018

But we don't know how big explosion is, if it's small grenade or big satchel.

HandleDamage get's the amount of damage though. Wouldn't that be enough?

@Dystopian
Copy link
Contributor Author

HandleDamage get's the amount of damage though. Wouldn't that be enough?

Here is HDEH [alive _vehicle, _this] output for 30mm AP (which shouldn't kill crew) and 40mm HEDP (which should do) hits:

"[true,[s,"""",11.7853,p,""B_30mm_APFSDS_Tracer_Green"",-1,p,""""]]"
"[false,[s,""hull"",7.54619,p,""B_30mm_APFSDS_Tracer_Green"",0,p,""hitbody""]]"
"[false,[s,""engine"",0.919199,p,""B_30mm_APFSDS_Tracer_Green"",1,p,""hitengine""]]"

"[true,[s,"""",0.854012,p,""G_40mm_HEDP"",-1,p,""""]]"
"[true,[s,"""",10.1193,p,""G_40mm_HEDP"",-1,p,""""]]"
"[false,[s,""hull"",7.14085,p,""G_40mm_HEDP"",0,p,""hitbody""]]"
"[false,[s,""engine"",1.37552,p,""G_40mm_HEDP"",1,p,""hitengine""]]"

Note AP damage is more than HE damage. So looks like out of luck.

@dedmen
Copy link
Contributor

dedmen commented May 9, 2018

I guessss...... One could look into the ammo config to look for explosiveness and damage

@kymckay
Copy link
Member

kymckay commented May 9, 2018

We already do this in cook off so it's nothing new 😛

@dedmen
Copy link
Contributor

dedmen commented May 9, 2018

@Dystopian
Copy link
Contributor Author

OK it works.
How do you think about component? If cookoff then config value will be ace_cookoff_ejectDestroyed. Isn't it strange?

@kymckay
Copy link
Member

kymckay commented May 9, 2018

Good point, I'm happy to leave it in vehicles 👍

Can see what other maintainers say

@dedmen
Copy link
Contributor

dedmen commented May 9, 2018

If in vehicles then maybe change https://github.com/Dystopian/ACE3/blame/master/addons/vehicles/README.md#L4
to

Various tweaks to vehicles and vehicle weapons.

Cookoff seems a little out of place. This thing is more like fixing a vanilla bug.
Also how about hard coding XEH init EH's in config. Instead of adding config entries and iterating over all vehicles?

Though mods couldn't integrate into it that well or they would need to check if ACE is present in the XEH code. So not sure if worth it. Probably not

Aand another also: https://github.com/acemod/ACE3/pull/6330/files#diff-71d8e1c52a77144d92094e89a77b7a55R15 Eventhandler recompilation. Please don't give me fps drops when getting shot ._.

if (0.5 >= getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive")) then {
{
if (alive _x) then {
moveOut _x;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't there a problem that moveOut didn't work with dead bodies? Or was that fixed recently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't move out them ^^ if (alive _x).
Or you want to move out them also? I don't think it's logical.

Copy link
Contributor

@dedmen dedmen May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol duh... Must read. Read good for thinking. 🤕
I was thinking about unconscious units but this already handles that fine. Then my brain moved from unconscious to dead.

TRACE_2("init ejectDestroyed vehicle",_vehicle,typeOf _vehicle);
_vehicle addEventHandler ["HandleDamage", {
params ["_vehicle", "", "", "", "_ammo"];
if (!alive _vehicle) then {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (alive _vehicle) exitWith?
get's rid of indentation (readability)
and get's rid of the ! (performance)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't exitWith slower than then?

@PabstMirror
Copy link
Contributor

Instead of the config number, scanning and adding xeh
we could just directly add a xeh for Boat_Transport_02_base_F and Rubber_duck_base_F

private _ejectDestroyedClasses = [];
{
private _ejectDestroyedClass = configName _x;
if (-1 == _ejectDestroyedClasses findIf {_ejectDestroyedClass isKindOf _x}) then {
Copy link
Contributor

@dedmen dedmen May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. if (-1 !=... ) exitWith to have less indentation.
I'd also add a comment like //Only want to add the EH once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it would exit forEach loop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also.. doesn't his add a problem?

I don't know if the configClasses output is properly ordered.
But if you add it to the child class first. And after that get to the parent class you might add twice?
Can only happen if configClasses can return child before parent. Which it shouldn't be able to if it linearly traverses the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well ACE uses some of such config loops and there were no problems yet AFAIK.

@dedmen
Copy link
Contributor

dedmen commented May 9, 2018

@PabstMirror #6330 (comment) :D
But what about the 3rd party mod accessibility that I mentioned there?

@Dystopian
Copy link
Contributor Author

Instead of the config number, scanning and adding xeh
we could just directly add a xeh for Boat_Transport_02_base_F and Rubber_duck_base_F

But it would prevent us to use it in 3rd-party addons, no? See the 1st post. Or we'll have to add it to compats which is not so good.

@PabstMirror
Copy link
Contributor

Current method doesn't check inheritance, e.g. it still runs on this child:

    class C_Boat_Transport_02_F: Boat_Transport_02_base_F {
        GVAR(ejectDestroyed) = 0;
    };

{} forEach ("1 == getNumber (_x >> ""ace_vehicles_ejectDestroyed"")" configClasses (configFile >> "CfgVehicles")); is about 25ms with rhs+cup

I think adding like this will be cleaner and faster.

    class Boat_Transport_02_base_F {
        class GVAR(ejectDestroyed) {
            init = QUOTE(call FUNC(ejectDestroyed));
        };
    };    
    class Rubber_duck_base_F {
        class GVAR(ejectDestroyed) {
            init = QUOTE(call FUNC(ejectDestroyed));
        };
    };

We could even add RHS vehicles directly in here as there is no load order/inheritance problems with xeh.

@dedmen
Copy link
Contributor

dedmen commented May 9, 2018

Do RHS vehicles still have the same issue?

Also please stop recompiling the whole eventhandler code on every shot that hits the boat.

@Dystopian
Copy link
Contributor Author

Current method doesn't check inheritance, e.g. it still runs on this child

It's intended because I didn't find suitable classes to exclude. I didn't want to add unnecessary logic.

I think adding like this will be cleaner and faster

I agree with faster. But I didn't agree with cleaner. Until I have known that CUP boats inherit from Rubber_duck_base_F 😆. So now I don't have real examples of 3rd-party addons which need this PR. If anybody know some or think this PR should rely on config value - say. Otherwise I'll rewrite PR like @PabstMirror says. Also in this case I don't object moving code to cookoff.

Do RHS vehicles still have the same issue?

RHS don't have suitable boats.

Also please stop recompiling the whole eventhandler code on every shot that hits the boat.

will do 👌

@dedmen
Copy link
Contributor

dedmen commented May 16, 2018

Found a solution for the config scan problem.
Do it like ASDG_JR. Just make a global class where everyone enters
classname = 1
That way we only scan over that.

@Dystopian
Copy link
Contributor Author

@dedmen really good solution. Could be used if it's needed.

@Dystopian
Copy link
Contributor Author

hmm working on static weapons - they should be handled another way

@Dystopian
Copy link
Contributor Author

Static weapons don't fire HDEH when become dead and can be alive if _damage == 0.950505. I don't want to mess with them. I think this PR is done.

@jonpas
Copy link
Member

jonpas commented Dec 7, 2019

Needs testing if this still happens with medical, specifically on boats.

@jonpas jonpas modified the milestones: 3.13.0, 3.13.1 Dec 7, 2019
@PabstMirror
Copy link
Contributor

This was needed on old medical, but now units won't take damage from vehicle deaths.

20191212171141_1

Pilot doing fine and staying on a sinking ship 😄

We actually need to do work on making vehicle crashes/dying more dangerous to units, keeping in mind to not just always make it lethal

@Dystopian
Copy link
Contributor Author

I don't completely understand why you link unit HD and vehicle HD. This PR is about vehicle HD only. It was made with disabled ACE Medical at all. The purpose was just to eject unit from shot rubber boat.
If you think this is OK:

Pilot doing fine and staying on a sinking ship smile

then I can add somewhat like !IS_MOD_LOADED(medical).

@PabstMirror
Copy link
Contributor

Merging now, will keep this in mind while working on #7305

@PabstMirror PabstMirror merged commit 392a077 into acemod:master Dec 16, 2019
@PabstMirror PabstMirror modified the milestones: 3.13.0, 3.13.0-temp3 Dec 30, 2019
@Dystopian Dystopian deleted the prevent_death_in_boat branch March 16, 2020 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Release Notes: **ADDED:**
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants