[0.14.1] Electric vehicles

Topics and discussion about specific mods
mknejp
Fast Inserter
Fast Inserter
Posts: 154
Joined: Wed Apr 27, 2016 8:29 pm
Contact:

[0.14.1] Electric vehicles

Post by mknejp »

Non-alpha version of this mod is released here : viewtopic.php?f=93&t=31911. Therefore, this topic has been locked.

If you are brave enough to play on 0.14 here is something new to play with: electrically powered vehicles.
Interestingly I have been working on electric vehicles the past week already and then suddenly out of the blue 0.14 hits with vehicle equipment and changes everything. So basically scrapped all the code I worked on for a week, started from scratch (which is a good thing the previous solution was so hacky) and this is now the result of a sleepless crunch-time weekend. Guess I got a bit too excited about this update.

This mod adds electrically powered variations of the car, locomotive and tank by giving them equipment grids and introducing special items that allow using the energy in the grid's batteries to drive the vehicle. This does not affect the vanilla vehicles as they aren't built with electrical engine units.

Even though only the vehicles provided by this mod can be electrically driven there is nothing special about them. Any vehicle can be turned into an electric one as the mod doesn't actually care about the vehicle type but rather its equipped items. The class of items that allow vehicles to be fueled from their batteries is called a transformer. There are two provided by this mod: a small one for the car and a bigger one for anything else. Once a transformer is present in a vehicle's equipment grid it will prioritize batteries for fuel. You can in theory still fuel any vehicle with ordinary fuel items, except for the ones provided by this mod as they don't have fuel slots. So if your electric tank's batteries run dry you can't just shove coal in and keep going.
transformer.png
transformer.png (146.77 KiB) Viewed 5767 times
And that brings me to the next big point: charging! There is no vanilla way of adding energy to an equipment grid other than having a generator item inside. So in theory nothing stands in your way of putting a portable fusion reactor in your car and be done with it. But if you feel (like me) that the portable fusion reactor is more cheat than balance, or you cannot afford one, then there is the option of charging batteries from the outside. For this let me introduce the induction charging stations and coils:
chargers.png
chargers.png (233.07 KiB) Viewed 5767 times
coil.png
coil.png (61.47 KiB) Viewed 5767 times
Simply park your vehicle on top of a station and put a coil in its equipment. As long as the station is powered it will charge the vehicle's batteries. As you can see in the screenshot above there are charging stations for vehicles and trains (not an actual station but rail segments), although the rail version won't deny charging your cars (if you think parking cars on train tracks is a good idea that is). In a future update the charging stations will be capable of sending the vehicle's charge level to the circuit network, however that feature is currently disabled because it manages to reliably crash the game.

And that is basically all there is to it, for now. Give it a try and let me know what you think. Everything is meant to be balanced and as an end-game vehicle the electric tank not only runs on power but is also slightly buffed compared to the conventional tank.

If you're a modder the following information might be useful:

The mod is split in two: "electric-vehicles-lib" containing all the logic for charging and driving electric vehicles, and "electric-vehicles" providing all the concrete items and entities. To make your own vehicles support electric propulsion simply give its prototype an equipment grid with the "electric-vehicles-equipment" category enabled and you're set. The library provides remote calls for telling it what item/entity/equipment prototypes are induction stations, induction coils, or transformers. So if you want to add electric vehicle support to your own mod, and do not need (or want) any of the items or vehicles in "electric-vehicles" simply use "electric-vehicles-lib" as dependency and register your own stuff with it as needed. There are events for notifying when a vehicle starts/stops charging but they are disabled right now because they crash the game.

Here are the links (you need both)
electric-vehicles_0.1.0.zip
electric-vehicles-lib_0.1.0
I hope you enjoy it. Looking forward to all the bugs.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [0.14.1] Electric vehicles

Post by aubergine18 »

Very nice! Can't test right now as I'm still on 0.13 but excited to finally see electric vehicles. Love the induction charging pads, although I don't think I'll be parking on train tracks any time soon lolol
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
y.petremann
Filter Inserter
Filter Inserter
Posts: 421
Joined: Mon Mar 17, 2014 4:24 pm
Contact:

Re: [0.14.1] Electric vehicles

Post by y.petremann »

Really interesting idea, would look a bit more on the mod to see what it does and what can be done with the same concept (mainly powering equipements with fuel).
mknejp
Fast Inserter
Fast Inserter
Posts: 154
Joined: Wed Apr 27, 2016 8:29 pm
Contact:

Re: [0.14.1] Electric vehicles

Post by mknejp »

y.petremann wrote:Really interesting idea, would look a bit more on the mod to see what it does and what can be done with the same concept (mainly powering equipements with fuel).
That should be rather trivial. Just create a "battery-equipment", set its "usage_priority" to "primary-output" and any energy you put into its buffer is immediately spread to other items at the "output_flow" limit. You probably also want to set "input_flow" to 0W so nothing goes back into it. Now the only work you have to do yourself is converting inventory items to fill the battery's energy buffer.
mknejp
Fast Inserter
Fast Inserter
Posts: 154
Joined: Wed Apr 27, 2016 8:29 pm
Contact:

Re: [0.14.1] Electric vehicles

Post by mknejp »

Wait, so are you saying that I now made electric vehicles that cannot be powered by conventional fuel and you're now making a mod that allows them to be powered by conventional fuel? What a world we live in.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [0.14.1] Electric vehicles

Post by aubergine18 »

The error with custom events crashing game might be fixed in 0.13.20
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
orzelek
Smart Inserter
Smart Inserter
Posts: 3924
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [0.14.1] Electric vehicles

Post by orzelek »

Tbh it would be cool if we could do this without scripting involved - vehicles would have engine component that would use fuel or electricity to move the car.
DanteDHunter
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sun Aug 28, 2016 6:55 pm
Contact:

Re: [0.14.1] Electric vehicles

Post by DanteDHunter »

When i try load my save without any mod.
"Error while running the on_configuration_changed: electric-vehicles-lib/src/main.lua:102: table index is nil"
Koub
Global Moderator
Global Moderator
Posts: 7790
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: [0.14.1] Electric vehicles

Post by Koub »

[Koub] Added link to non-alpha version of this mod in first post, and locked the topic.
Koub - Please consider English is not my native language.
Locked

Return to “Mods”