# Best way to implement "reverse battery compartment mod" within current code structure?

**URL:** <https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718>\
**Category:** The Lab\
**Created:** [July 21, 2021, 12:30pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718 "2021-07-21T12:30:48Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 23, 2021, 1:50am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/21 "2021-07-23T01:50:13Z")

</div>

> [@Tamior](#):
>
> Sigh…  
> […]  
> Always has been. That’s the only line directly relevant to the flags in question.

First, don’t imitate and mock me. You want help, provide enough information in the first place to get them.

Second, no. You’ve answered a lot of other questions in between and in that very post I’ve referenced you were talking about the point of definition of `BATTERY_MOUNT` and the `“location”: “on_battery_mount”`, not that particular line that was mentioned 9 posts above.  
I don’t see what file you’re currently looking at, and I (thankfully) can’t read your mind, so you need to provide these information directly.

Third, even though you’ve really pissed me off by this point, the answer to your question is 11 lines above where my link points:

> // if a windshield is removed (usually destroyed) also remove curtains  
> // attached to it.

So, translated onto that specific line, the use would be: `"If the battery holder gets destroyed, it also removes the battery attached to it."`

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 23, 2021, 2:01am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/22 "2021-07-23T02:01:26Z")

</div>

> [@Valase](#):
>
> First, don’t imitate and mock me.

Then how about you don’t start off with the incredibly patronizing assumptions that I legitimately had no idea what _all_ of C++ code is for, not just one specific line?

> [@Valase](#):
>
> Third, even though you’ve really pissed me off by this point, the answer to your question is 11 lines above where my link points \<…\>

That’s much more helpful, thank you. Will try and test if that C++ line is still required for this interaction if .json flags have been properly defined.

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 23, 2021, 2:09am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/23 "2021-07-23T02:09:17Z")

</div>

> [@Tamior](#):
>
> […] don’t start off with the incredibly patronizing assumptions that I legitimately had no idea what _all_ of C++ code is for, […]

Once again: I don’t know what you’re thinking, I don’t know your level of knowledge, and I have to go by what you asking. I’ve answered your question as accurate as possible.  
I have no idea how you think that answering a question directly is “patonizing”, but if you prefer me to not answer you at all, I can do that…

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 23, 2021, 2:23am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/24 "2021-07-23T02:23:54Z")

</div>

> [@Valase](#):
>
> Once again: I don’t know what you’re thinking, I don’t know your level of knowledge, and I have to go by what you asking. I’ve answered your question as accurate as possible.

If you want to continue playing this game, sure:  
do notice how I wasn’t really _asking_ anything. I just made an off-hand comment how I don’t understand the exact role of a segment of C++ code. It was you who decided to interpret that as an actual question and “answer” it.

> [@Valase](#):
>
> I have no idea how you think that answering a question directly is “patonizing”

It very much is, when there wasn’t really a question to begin with, and you started your “answer” with the assumption I have no idea what _any_ of C++ code does.

Anyway, I do apologize for any miscommunication on my part.

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 23, 2021, 2:55am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/25 "2021-07-23T02:55:19Z")

</div>

> [@Tamior](#):
>
> If you want to continue playing this game […]

I don’t play any games with you. But I will continue this discussion in private messaging to not derail this topic.

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 25, 2021, 1:57pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/26 "2021-07-25T13:57:49Z")

</div>

> [@Valase](#):
>
> So, translated onto that specific line, the use would be: `"If the battery holder gets destroyed, it also removes the battery attached to it."`

I tested this theory.  
What I did was merge the .json code, but _NOT_ the C++ code.

```auto
remove_dependent_part( "HANDHELD_BATTERY_MOUNT", "NEEDS_HANDHELD_BATTERY_MOUNT" );

```

Then I installed the new tool battery mount that works via HANDHELD\_BATTERY\_MOUNT flag + a battery that works via NEEDS\_HANDHELD\_BATTERY\_MOUNT flag.  
And then I smashed it. Here is the result:

 ![battery_detach](https://us1.discourse-cdn.com/flex016/uploads/cataclysmdda/original/2X/c/c99a43dbfbb6d978fd87df9739eefcf51efa7563.png)

As you can see, destruction with damage still detaches the dependent part even without the C++ code.

As such, I’m still not sure if this C++ line:

```auto
remove_dependent_part( "BATTERY_MOUNT", "NEEDS_BATTERY_MOUNT" )

```

is actually anything but obsolete.

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 25, 2021, 5:45pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/27 "2021-07-25T17:45:56Z")

</div>

Created a PR for it, all feedback would be welcome:

> <https://github.com/CleverRaven/Cataclysm-DDA/pull/50217>
>
> \#### Summary
> Content "Add tool battery mount for vehicles (reverse battery comp…artment mod)."
> 
> \#### Purpose of change
> 
> Battery compartment mod allows you to use vehicle batteries in handheld tools. 
> This PR adds a vehicle part — "tool battery mount" — that allows you to use conventional batteries from handheld tools as primary battery in a vehicle. Basically the reverse functionally of battery compartment mod.
> 
> \#### Describe the solution
> Same as normal tools require a mod (battery compartment mod) to use vehicle batteries, vehicles now require a mod (vehicle part that works similar to \`storage battery case\`) to use conventional batteries from handheld tools.
> 
> \#### Testing
> 
> Mostly .json change, works fine locally.
> There is a single line in vehicle.cpp, but I don't think any extensive testing is required for that one one.
> 
> \#### Additional context
> Speaking of the line in vehicle.cpp: is it actually required?
> I feel like everything that line does (and similar line for \`storage battery case\`) has already been jsonized.
> 
> Also, implementation has been somewhat discussed here: https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/26

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 25, 2021, 6:32pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/28 "2021-07-25T18:32:14Z")

</div>

> [@Tamior](#):
>
> [_specific_ C++ code] is actually anything but obsolete.

I tested this a bit and came to the conclusion that I have to disagree with you.

When I’ve started testing I did not have your pull request, so I’ve worked with the things that were already there, namely: `remove_dependent_part( "SEAT", "SEATBELT" )` and `remove_dependent_part( "WINDOW", "CURTAIN" )`.

I’ve commented out one of the lines (seat/seatbelt) and left the other one active (window/curtain).  
Smashing the tile did actually drop it, yes.  
But giving my character the mutation `Debug Hammerspace` and then tried to remove the seat, it removed it and left the seatbelt in the vehicle. Doing the same with a window with a curtain removed the window (dropping the `sheet of glass` to my feet) and the curtain (leaving it as a `sheet` item on the tile it was installed).

Undoing the code change and trying it with the seat/seatbelt again gave the same result as the window/curtain, proving that there are actually still cases that make use of that part of the code.

I had a 14 hour work shift and little sleep before and after, and I’m too exhausted to try to hunt down more situations in which this can occure or to test if your pull request behaves in the same way; so I would appreciate if you could run that test on your code yourself.

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 25, 2021, 6:48pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/29 "2021-07-25T18:48:19Z")

</div>

> [@Valase](#):
>
> But giving my character the mutation `Debug Hammerspace` and then tried to remove the seat, it removed it and left the seatbelt in the vehicle.

Trying to remove my new part (tool battery mount) with a battery attached to it gives me this:

 ![battery_detach_2](https://us1.discourse-cdn.com/flex016/uploads/cataclysmdda/original/2X/a/a93cc1c3851074fa7c305c09db0e2f18c2e3c35c.png)

And that’s _WITHOUT_ the C++ line added to the game.

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 25, 2021, 6:50pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/30 "2021-07-25T18:50:36Z")

</div>

Yes. But hitting enter on it will still remove the part, leaving the attached part on the vehicle (as from the experience I had with the seat/seatbelt situation).

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 25, 2021, 6:52pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/31 "2021-07-25T18:52:40Z")

</div>

Hitting enter my hardest, nothing happens. ¯\_(ツ)\_/¯  
(If I move 1 position down and hit enter on the battery, it’s removed right away.)

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 25, 2021, 6:56pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/32 "2021-07-25T18:56:28Z")

</div>

> [@Tamior](#):
>
> Hitting enter my hardest, nothing happens. ¯\_(ツ)\_/¯

…while having the mutation `Debug Hammerspace` active (just making sure)?  
Because as stated, you can remove parts that have others attached to it with the Hammerspace mutation… It just drops the attached part in place.  
Not having the mutation usually results in no movement at all.

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 25, 2021, 7:06pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/33 "2021-07-25T19:06:00Z")

</div>

> [@Valase](#):
>
> …while having the mutation `Debug Hammerspace` active (just making sure)?

Ah, yes, with the mutation active I can remove the mount without removing the battery first.  
And it leaves the battery atteched _without_ the C++ line, and removes it _with_ the C++ line.

However, this brings another question: what non-debug scenario is this type of removal equivalent to?  
I don’t mind having a similar C++ line for my parts just-in-case, I just wonder if there still is a “natural” scenario for it to become relevant.

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 25, 2021, 7:14pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/34 "2021-07-25T19:14:24Z")

</div>

> [@Tamior](#):
>
> However, this brings another question: what non-debug scenario is this type of removal equivalent to?

Usually I’d go code diving to find more cases and also track down in which cases the debug mutation differentiates from other remove cases (and if some remove cases can go that path too, resulting in the same behavior). I’ve mentioned above why I didn’t do that this time.

For now all I’ve wondered was if it is actually obsolete or not.

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 25, 2021, 7:17pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/35 "2021-07-25T19:17:35Z")

</div>

> [@Valase](#):
>
> For now all I’ve wondered was if it is actually obsolete or not.

Understandable.  
Thank you.

I’ve added an equivalent C++ line for my parts anyway, so it’s more of a theoretical question at this point…

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 26, 2021, 9:39am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/36 "2021-07-26T09:39:11Z")

</div>

While we are at it: is there an online tool for C++ code linting?  
Github complains about linting despite my line being formatted seemingly exactly the same as the line above it…

---

<div class="post-metadata">

**Author:** ![Valase](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/valase/32/6972_2.png) [@Valase](https://discourse.cataclysmdda.org/u/Valase)\
**Post date:** [July 26, 2021, 3:07pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/37 "2021-07-26T15:07:56Z")

</div>

> [@Tamior](#):
>
> is there an online tool for C++ code linting?

From what I see in your pull request, it complains about the `vehicle_parts.json` file, so it’s not the C++ part you have to worry about.  
As for your question: [Based on JSON\_STYLE.md](https://github.com/CleverRaven/Cataclysm-DDA/blob/fb6455faff529fc9502f0e36d52f3f8282c34572/doc/JSON_STYLE.md) it uses a custom formatting (“We haven’t been able to find a decent JSON styling tool, so we wrote our own.”) and tools are provided in the releases (“`json_formatter.exe` or `json_formatter.cgi`”), as well as online at [http://dev.narc.ro/cataclysm/format.html](http://dev.narc.ro/cataclysm/format.html) .

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [July 26, 2021, 6:39pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/38 "2021-07-26T18:39:06Z")

</div>

Yea, you are right.  
For some reason I thought there was also a linting error for C++, but I guess I just imagined it.

---

<div class="post-metadata">

**Author:** ![esotericist](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/esotericist/32/5170_2.png) [@esotericist](https://discourse.cataclysmdda.org/u/esotericist)\
**Post date:** [July 28, 2021, 8:57am UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/39 "2021-07-28T08:57:32Z")

</div>

we use astyle for c++ linting, and yes PRs will fail tests if they have c++ code that violates expected formatting.

please see `doc/CODE_STYLE.md` for more details.

(if you had some c++ code at some point then removed it, it’s possible for tests to catch that and complain, if the tests completed before you removed it)

---

<div class="post-metadata">

**Author:** ![Tamior](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tamior](https://discourse.cataclysmdda.org/u/Tamior)\
**Post date:** [August 1, 2021, 7:50pm UTC](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718/40 "2021-08-01T19:50:46Z")

</div>

Any ideas what’s up with merging?  
Been a solid week… Anything I need to do to speed it up?

[Previous page](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718.md?page=1)

[Next page](https://discourse.cataclysmdda.org/t/best-way-to-implement-reverse-battery-compartment-mod-within-current-code-structure/26718.md?page=3)
