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

Connecting power cables between appliances and vehicles #60851

Closed
wants to merge 3 commits into from

Conversation

dseguin
Copy link
Member

@dseguin dseguin commented Sep 8, 2022

Summary

None

Purpose of change

The other concern pointed out in the comments in the linked issue is that you shouldn't be able to transfer power directly between vehicles and appliances, since vehicles run on DC power while most appliances connect to AC sources. In reality that would require some kind of rectifier (like the ones found in power supplies) or a commercial power inverter:

image

Describe the solution

  • Fix the linked issue - (extension cables can connect to vehicles)
  • Add power inverters - (using an abstract term here, the nitty-gritty details are not important)
    • Item action for converting cables with a power inverter - (can be activated from the cable or the inverter)
    • Restrict appliance-vehicle connections to cables with an attached inverter
    • Add recipe and item group spawns for power inverters
  • Unit test

So the order of operations for connecting an appliance to a vehicle would be:

  1. Get an extension cable and power inverter
  2. activate either the cable or the inverter to attach the inverter to the cable
  3. activate the converted cable and connect both the appliance and the vehicle
2022-09-08.02-10-30.mp4

Describe alternatives you've considered

Forgetting the AC-DC power conversion and just fixing the linked issue. In that case, the fix would only be 2 lines:

diff --git a/src/iuse.cpp b/src/iuse.cpp
index 713caf1d23..18950a50f1 100644
--- a/src/iuse.cpp
+++ b/src/iuse.cpp
@@ -8850,7 +8850,7 @@ cata::optional<int> iuse::cord_attach( Character *p, item *it, bool, const tripo
         }
         const tripoint posp = *posp_;
         const optional_vpart_position vp = here.veh_at( posp );
-        if( !vp || !vp->vehicle().has_tag( "APPLIANCE" ) ) {
+        if( !vp ) {
             p->add_msg_if_player( _( "There's no appliance here." ) );
             return cata::nullopt;
         } else {
@@ -8911,7 +8911,7 @@ cata::optional<int> iuse::cord_attach( Character *p, item *it, bool, const tripo
         const tripoint vpos = *vpos_;
 
         const optional_vpart_position target_vp = here.veh_at( vpos );
-        if( !target_vp || !target_vp->vehicle().has_tag( "APPLIANCE" ) ) {
+        if( !target_vp ) {
             p->add_msg_if_player( _( "There's no appliance there." ) );
             return cata::nullopt;
         } else {

Testing

Added a unit test to check that the power inverter iuse action works from both the inverter and the cable:

./tests/cata_test --rng-seed time "power inverter"

Also tested in-game:

  • Converting a cable by activating the cable ✔️
  • Converting a cable by activating the inverter ✔️
  • Detaching the inverter by activating the converted cable ✔️
  • Attaching a normal cable from appliance to appliance ✔️
    • Cannot use a power cable with an inverter attached
  • Attaching a normal cable from vehicle to vehicle ✔️
    • Cannot use a power cable with an inverter attached
  • Attaching a converted cable from appliance to vehicle ✔️
    • Cannot use a power cable without an inverter

Additional context

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Appliance/Power Grid Anything to do with appliances and power grid Code: Tests Measurement, self-control, statistics, balancing. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Spawn Creatures, items, vehicles, locations appearing on map <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Sep 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

Spell checker encountered unrecognized words in the in-game text added in this pull request. See below for details.

Click to expand
  • This is an implement that rectifies the current between AC and DC sources. Can be fitted to a power cable for connecting appliances and vehicles.
  • power inverters

This alert is automatically generated. You can simply disregard if this is inaccurate, or (optionally) you can also add the new words to tools/spell_checker/dictionary.txt so they will not trigger an alert next time.

@actually-a-cat
Copy link
Contributor

actually-a-cat commented Sep 8, 2022

If we are bringing in the AC/DC distinction, does it make any sense to limit it to just vehicles? Solar panels and batteries are also DC and would require inverters to power AC appliances, and charging batteries from AC sources would require a charger (rectifier and regulator). Plus it's not always true that vehicle = DC. The "Portable Generator" vehicle should output mostly AC (while having its own internal DC electrical system with limited capacity)

Don't get me wrong I would love realistic electrical systems I'm just not sure if this is a can of worms worth opening, considering all the implications.

@dseguin
Copy link
Member Author

dseguin commented Sep 8, 2022

I'm not really attached to the power conversion stuff, I'm fine with the simple fix as well. But I see your point about current types in vehicles/appliances. I'll add a way for vehicle/appliance definitions to declare how they should be treated in the grid.

@dseguin dseguin marked this pull request as draft September 8, 2022 07:35
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 8, 2022
@Ciac32
Copy link
Contributor

Ciac32 commented Sep 9, 2022

I don't think the AC/DC distinction is as big as a deal for anything other than the big motor appliances. Lamps and heating elements don't care what the current is doing, and DC will make it through a rectifier fine for any of the control circuits (albeit not at peak efficiency/reliability). In addition, universal motors are surprisingly common in smaller appliances and will cope well with either type of current.

The bigger issue is voltage & amperage, but that is already pretty abstracted from what the survivor is doing. If its really that important we could just make a middling electronics skill and the generic "power converter" item required for setting up some of the more sensitive types of appliances; presumably that would cover any glaring AC/DC problems too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Appliance/Power Grid Anything to do with appliances and power grid astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Spawn Creatures, items, vehicles, locations appearing on map
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extension cord cannot be plugged into vehicle
3 participants