FortressCraft Evolved

FortressCraft Evolved

steveman0's Freight Carts
steveman0  [developer] 12 Feb, 2017 @ 11:12pm
[Modding] Freight System Interface
The following is the direct implementation of the FreightSystemInterface. This is the code as compiled in the included dll. If you'd like your mod to interact with the freight system include the dll as a reference and have your entity inherit the interface. Stations will then attach to your machine as they would mass storage or hoppers.

Post questions here if you need more info.

public interface FreightSystemInterface { /// <summary> /// List of all items that the interface has available to provide to the freight system /// </summary> List<FreightListing> FreightOfferings { get; } /// <summary> /// List of all items that the interface wants delivered to it by the freight system /// </summary> List<FreightListing> FreightRequests { get; } /// <summary> /// List of the interface's current inventory available for transit /// Must exist on either FreightOfferings or FreightRequests list to be tallied /// </summary> List<FreightListing> FreightInventory { get; } /// <summary> /// Checked each tick by the connected freight station. If true the station will query /// the master freight registry for the freight data associated with the stations network. /// This request is costly, avoid making frequent requests! The registry fully updates /// every 3 seconds so requests more frequent than this are unnecessary. Cache locally! /// </summary> bool FreightDataRequest { get; } /// <summary> /// Queried freight network data is passed to the interface here /// </summary> /// <param name="data">Current freight status for the connected station's network.</param> void FreightNetworkData(List<FreightData> data); /// <summary> /// The freight system calls this when it has an item to offer to the interface /// </summary> /// <param name="item">The item being offered to the interface</param> /// <returns>True if the item is accepted</returns> bool ReceiveFreight(ItemBase item); /// <summary> /// The freight system calls this when requesting an item from the interface /// </summary> /// <param name="item">The item the freight system wants the interface to provide</param> /// <returns>True if the interface successfully provides the item</returns> bool ProvideFreight(ItemBase item); } /// <summary> /// Class representing a freight item and offered/requested quantity /// </summary> public class FreightListing { public ItemBase Item { get; } public int Quantity { get; set; } public FreightListing(ItemBase item, int quantity) { Item = item; Quantity = quantity; } //Some operator and comparison overrides to make them directly comparable to ItemBase } /// <summary> /// Class containing basic freight system status information /// </summary> public class FreightData { /// <summary> /// The Freight Item traded on the network /// </summary> public ItemBase FreightItem { get; } /// <summary> /// Total quantity of this freight item among all mass storage with networked stations /// Hoppers do not contribute to network inventory. /// </summary> public int Inventory { get; } /// <summary> /// The sum of all demand across the network for this item /// </summary> public int Deficit { get; } /// <summary> /// The sum of all excess offered available for delivery to requesting stations /// </summary> public int Surplus { get; } /// <summary> /// Current stock of this item in transit in the freight system /// </summary> public int Stock { get; } public FreightData(ItemBase item, int inv, int def, int sur, int stock) { FreightItem = item; Inventory = inv; Deficit = def; Surplus = sur; Stock = stock; } }
Last edited by steveman0; 26 Mar, 2018 @ 7:07pm
< >
Showing 1-4 of 4 comments
ack_ptbhbhbhb 15 Jun, 2017 @ 10:17am 
Thank you. This indeed was the missing piece. I cloned this mod from your github reposittory, but couldn't get it to compile because it was missing this bit right here.

Maybe it's intended to be in a seperate project? IDK, I couldn't find a seperate project. But in the meantime:

Yeah! It compiles!

And I think I'll start by screwing around with the existing code. Later I might refactor as a seperate plugin that interacts with FreightSystemInterface, but I think it'll be easier to figure out if I've got your code staring me right in the face. I've never done c# before, nor anything with unity, nor anything with fortresscraft. It'll be educational :(

First step is to verify my compile is actually effecting things in-game by modifying a label. I've been bitten by THAT one before :)

Baby steps.

Besides which, at first blush what I think I want to do looks more like "completely revamp cart routing", and "use the depot to store unused carts when not in use instead of having them wander randomly over the network of tracks." Which would probably require replaceing, modifying, or overriding your mods code anyway.

Though I'll admit my first reaction was "10K lines of code? This might be more involved than I though..." :)

So who knows? Maybe a different approach will turn out to be easier.
steveman0  [developer] 15 Jun, 2017 @ 6:33pm 
Yes, it's a separate project. I'm not even sure if the code on github is 100% up to date. I'm without proper internet for 2 weeks so I can't upload the latest. You could always decompile the workshop dll to compare if you run into anything.

Cart pathfinding can't be much improved but the decision tree on deciding where to go could certainly improve. That is a largely underdeveloped bit of the code but it doesn't have an easy and efficient answer. I errored on the side of simplicity to keep the load down on the mob thread. More recent analysis suggests there is room to increase complexity with little risk of overloading it.

Using the depot to store carts is similar to an idea I had but I tend to favor function and my list of projects was too long to justify time on a visual nicety.

steveman0  [developer] 7 Sep, 2017 @ 4:22pm 
OP updated with upgrade of the interface. This new functionality will be going live shortly.
steveman0  [developer] 26 Mar, 2018 @ 7:09pm 
OP updated with another upgrade of the interface. The FreightInventory has been added as this provides a means to track contents in addition to straight offers and requests. This is used by the cart to determine the % satisfaction of a given offer or need in order to provide service to the most desired station.
< >
Showing 1-4 of 4 comments
Per page: 1530 50