Page 1 of 1

[0.14.1] Electric vehicles

Posted: Sun Aug 28, 2016 10:28 pm
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 5769 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 5769 times
coil.png
coil.png (61.47 KiB) Viewed 5769 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.

Re: [0.14.1] Electric vehicles

Posted: Mon Aug 29, 2016 2:23 am
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

Re: [0.14.1] Electric vehicles

Posted: Mon Aug 29, 2016 4:21 pm
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).

Re: [0.14.1] Electric vehicles

Posted: Mon Aug 29, 2016 6:50 pm
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.

Re: [0.14.1] Electric vehicles

Posted: Mon Aug 29, 2016 6:57 pm
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.

Re: [0.14.1] Electric vehicles

Posted: Mon Aug 29, 2016 7:32 pm
by aubergine18
The error with custom events crashing game might be fixed in 0.13.20

Re: [0.14.1] Electric vehicles

Posted: Mon Aug 29, 2016 8:42 pm
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.

Re: [0.14.1] Electric vehicles

Posted: Wed Aug 31, 2016 11:31 am
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"

Re: [0.14.1] Electric vehicles

Posted: Wed Aug 31, 2016 11:49 am
by Koub
[Koub] Added link to non-alpha version of this mod in first post, and locked the topic.