squidy5 / cargo_ships

factorio mod that adds cargo ships and other content to the game
25 stars 39 forks source link

Create interface for mods to add new ships #86

Closed robot256 closed 1 year ago

robot256 commented 2 years ago

This will require a large refactoring, which I got partially working about a year ago.

robot256 commented 2 years ago

Making notes here instead of some other random place. This is still a notional long-term plan, if it ever works. Feel free to comment with any new ideas.

  1. The only absolute reason this mod needs to be involved is to handle third-party ships that travel on waterways. Otherwise, these will be treated as trains and removed by Cargo Ships.
  2. One solution to this would simply be a "whitelist" of entities that are allowed on waterways. Then the other mod would have to have its own ship engines and engine-spawning logic.
  3. The more general case, which would also make it easier to add ships in this mod too, is to create a registry of each ship type with all the specific parameters required to detect it and create its engine. This is what I've basically done in Vehicle Wagon.
  4. Parameters needed would be: name of placed ship entity, name of engine to be created (if any), whether engine is in front or behind ship entity (localize_engine, has_connected_stock), distance away to make the ship engine (localize_engine), whether the player can enter it from a distance. Also need an interface to add new engines, and whether players can enter those from a distance.
  5. Mods would add cargo-ships as a dependency, and call the remote interface during on_configuration_changed to add both ships and engines. cargo-ships would maintain global tables:
    • Ship name -> engine building data. (list of ships and their localize_engine data)
    • Engine name -> engine data. (list of engines and whether they use fuel that needs to be recovered)
    • Ship/engine name -> true. (list of stock that can be entered with the Enter Ship command)
  6. This might be a good time to retire the glitchy boat placement code, by allowing the player to intentionally craft the waterway-boat (like converting between AI and normal vehicles) and not needing the script to choose which the player intended. Then we would not have to expand it to handle other dual-mode boats.
  7. This refactor should also move some of the larger blocks of code out of control.lua into logic files. The ship, oil rig, and waterway build/mine/delete code should be moved, and the "enter vehicle" code as well.
  8. In fact, one possibility is to use the well-supported FLIB events library (which is maintained by Krastorio and Factory Planner devs). This allows multiple subcomponents of a single mod to subscribe to the same event. It would take the place of the existing logic which decides whether to act on a boat, ship, oilrig, waterway, rail, or bridge.
squidy5 commented 2 years ago

Hey! I don't know how far you are into this work, but I am against removing the boat placement logic. I really like the idea that you can use the boat in one or the other way, and there isn't really a logical reason why this should not be the case.

And even with this still in place, any new boats don't need to have the same dual use character!

robot256 commented 2 years ago

I haven't actually started this code yet, so I'll try to keep that in place. It's a neat gimmick, but I'm just speaking as a user who has found it a little confusing sometimes. I also don't use rail boats much so an extra step to make them (converting from a car boat) doesn't seem like a hassle.

robot256 commented 2 years ago

@rudegrass @snouz I completed the Ship API interface and published a beta version on Github, along with a beta Electric Boat mod to use with it. Let me know if you get a chance to test it. I don't want to release until someone else does!

I included the dual boat / ship behavior so that any new entity can use it too. I think overall it ended up being less invasive than I had originally envisioned.

https://github.com/robot256/cargo_ships/releases/tag/api-beta-19 https://github.com/robot256/electric-boat/releases/tag/beta-1

robot256 commented 1 year ago

I let this code sit for way too long. We had at least two beta testers back in May whose testing agreed with mine, so I went ahead and released it in 0.1.19. Commit of the interface itself was fd5e3649955983b06e7b140ea074bfe733689286