The problem:
I want to make a mod that tries to guess what a line made by the user is used for.
A cargo line may be used to grab oil and take to refinery to get refined oil. That same line or another line may take the refined oil and take to a fuel refinery which turns it into fuel which takes to nearby a town. In that station the cargo goes to another line until reaching a town that has the fuel need.
I want to try to guess that, for those 2/3 lines, it's circuit of: "Oil -> refinedOil -> fuel -> townA"
For the mod, I want to figure out through which lines the contents went to and through and then calculate from there.
Finally, the mod would show some data to the user regarding that. So I will need to translate the Entities into names (still have no idea how) so the user doesn't just see numbers.
I'm trying to follow the API manual: https://transportfever2.com/wiki/api/index.html
Specially the engine part, which seems to contain most of these stuff: https://transportfever2.com/wi….html#getSimCargosForLine
In detail:
I know I can do:
Which gives me the lines that exist.
That means I can execute:
api.engine.getComponent(
api.engine.system.lineSystem.getLines()[1],
api.type.ComponentType.LINE
)
Which will give me some of the information about the line (the name isn't here. Is it in api.gui?):
{
stops = {
[1] = {
stationGroup = 16553,
station = 0,
terminal = 0,
loadMode = 2,
minWaitingTime = 0,
maxWaitingTime = 60,
waypoints = {
},
stopConfig = userdata: 0x403584f8,
},
[2] = {
stationGroup = 16565,
station = 0,
terminal = 0,
loadMode = 0,
minWaitingTime = 0,
maxWaitingTime = 180,
waypoints = {
},
stopConfig = userdata: 0x409fbeb8,
},
},
waitingTime = 180,
vehicleInfo = {
transportModes = {
[1] = 0,
[2] = 0,
[3] = 0,
[4] = 0,
[5] = 1,
[6] = 0,
[7] = 0,
[8] = 0,
[9] = 0,
[10] = 0,
[11] = 0,
[12] = 0,
[13] = 0,
[14] = 0,
[15] = 0,
[16] = 0,
},
defaultPrice = 40.307800292969,
},
}
Alles anzeigen
That gives me the station group for each stop. That's useful.
Now, with the station group, I can get the stations by getting the component
api.engine.getComponent(
api.engine.getComponent(
api.engine.system.lineSystem.getLines()[1],
api.type.ComponentType.LINE
).stops[2].stationGroup
,
api.type.ComponentType.STATION_GROUP)
(with hardcoded knowledge), I can get the delivery station in the line (trucks deliver to town in this station):
terminusDeliveryStation = api.engine.getComponent(api.engine.getComponent(api.engine.system.lineSystem.getLines()[1], api.type.ComponentType.LINE).stops[2].stationGroup, api.type.ComponentType.STATION_GROUP).stations[1]
api.engine.getComponent(api.engine.system.stationSystem.getTown(terminusDeliveryStation), api.type.ComponentType.TOWN)
This gives info about the town. Some info can be useful for me such as the cargo needs. However, where's the name of the town?
Different part of the line now
Now to choose a stop that has a factory that takes crude oil and transforms into refined oil. This is connected to a train line.
transfStation = api.engine.getComponent(api.engine.getComponent(api.engine.system.lineSystem.getLines()[2], api.type.ComponentType.LINE).stops[2].stationGroup, api.type.ComponentType.STATION_GROUP).stations[1]
api.engine.getComponent(api.engine.system.streetConnectorSystem.getConstructionEntityForStation(transfStation), api.type.ComponentType.CONSTRUCTION)
This tells me a lot of information but nothing I can use to relate with the Refinery.
In the manual, I find getConstructionEntityForSimBuilding(), which takes an industryEntity (https://transportfever2.com/wi…ctionEntityForSimBuilding). However, I can't find how to get the industry entity...
How do I get the industryEntity in order to know what it takes as input and what it makes as output? Or is there another way to get that info?
I've tried to investigate this way but nothing gained... I'm getting Nil
>> a = api.engine.system.simCargoSystem.getSimCargosForLine(api.engine.system.lineSystem.getLines()[1])
>> a
{
[1] = 13297,
[2] = 17542,
[3] = 18558,
[4] = 14184,
[5] = 17304,
[6] = 18617,
[7] = 18620,
[8] = 18622,
[9] = 16923,
[10] = 18392,
[11] = 18626,
}
>> a[1]
nil
Alles anzeigen
What options am I missing?