Transport Fever 2

Transport Fever 2

LineManager
This topic has been locked
RustyBucket  [developer] 21 Dec, 2021 @ 6:35am
The bug with the electric tram lines
posting (or rather copypasting) it here to get around the comment character limit:

Well, all I know is that I finally tried this mod and was greatly disappointed by it doing nothing at all, thus figuring out how to access the console, getting disappointed that it doesn't work with the date paused.

(change suggestion one: make the interval one minute in game [the billing cycle] to ensure equal operation despite varying date speed)

Then, I made the date advance to find that the console reported 0 lines to be affected - to my great confusion as my savegame at that point contained a dozen Z lines with trams and one A line with trains, in an effort to debug the mod as I would've liked it to work, I dug into the files to figure out just what exactly you were doing and trying to figure out the exact point where my -at that point 19 lines (A1, the Z lines and parallelling new X lines in case it only worked on new lines)- went from detected to ignored by adding some print statements:

-- print("line ")
-- for i=0, #lineData do
-- print(lineData)
-- end
--attempt to print the sampled lines

under samping and

-- print("detected lines: ")
-- for i=0, #lines do
-- print(lines)
-- end
--attempt to print out detected lines

under updating

in order to see what the mod saw and was astonished the lines detected them all but by sampling it tried to sample two "nil" lines, thus I suspected the helper.getLineData() function, since there was the line.vehicle.transportMode checks were done, letting categories 4,7,10 and 13 pass, which conflicted with the transport categories I found by digging through the reference website from the transportMode details, whose link I provided in my subsequent comment, suggesting that the return categories are:

-- api.engine.getComponent(line_id, api.type.ComponentType.LINE)
-- vehicleInfo = {
-- transportModes = {
-- [0] = 0, Person
-- [1] = 0, Cargo
-- [2] = 0, Car
-- [3] = 0, Bus
-- [4] = 0, Truck
-- [5] = 0, Tram
-- [6] = 0, Electric Tram
-- [7] = 0, Train
-- [8] = 0, Electric Train
-- [9] = 0, Aircraft
-- [10] = 0, Ship
-- [11] = 0, small Aircraft
-- [12] = 0, small Ship
-- },

This interpretation was seemingly confirmed by me running the console command:
api.engine.getComponent(line_id, api.type.ComponentType.LINE) on one line, now replicated on an old savegame in 1888 with more diverse lines:
(D1-3,E1 with pax steam trains, F1 on small cargo ships, G1-4 with cargo steam trains, R1 with electric trams, a V line with local buses, W1 with small pax ships, two Y lines with local cargo and 9 Z Lines with non electric local trams)

api.engine.system.lineSystem.getLines()
returns

{
[1] = 226146,
[2] = 226145,
[3] = 223807,
[4] = 221261,
[5] = 219804,
[6] = 218502,
[7] = 218086,
[8] = 214695,
[9] = 214435,
[10] = 211395,
[11] = 205708,
[12] = 198981,
[13] = 178112,
[14] = 173521,
[15] = 170278,
[16] = 57760,
[17] = 215864,
[18] = 175278,
[19] = 234213,
[20] = 187356,
[21] = 199258,
[22] = 179258,
[23] = 222379,
}

running api.engine.getComponent(226146, api.type.ComponentType.NAME) tells me it's a Z electric line, thus running api.engine.getComponent(226146, api.type.ComponentType.LINE)
returns among others the table

vehicleInfo = {
transportModes = {
[1] = 0,
[2] = 0,
[3] = 0,
[4] = 0,
[5] = 0,
[6] = 1,
[7] = 0,
[8] = 0,
[9] = 0,
[10] = 0,
[11] = 0,
[12] = 0,
[13] = 0,
[14] = 0,
[15] = 0,
[16] = 0,
},

which I now notice doesn't conform with my alleged information, though my fix still seems to work as this is an electric local tram in category 6 (yesterday, I didn't se that list and blindly edited the categories inquiry to reflect my opinion of what should work and it did, so now I'm stumped...

my modified for loop now reads:

for _, line_id in pairs(lines) do
-- Check type of line first
local line = api.engine.getComponent(line_id, api.type.ComponentType.LINE)
-- transportModes[4] = ROAD, transportModes[7] = TRAM, transportModes[10] = AIR, transportModes[13] = WATER
if line and line.vehicleInfo and line.vehicleInfo.transportModes and (line.vehicleInfo.transportModes[3] == 1 or line.vehicleInfo.transportModes[4] == 1 or line.vehicleInfo.transportModes[5] == 1 or line.vehicleInfo.transportModes[6] == 1 or line.vehicleInfo.transportModes[9] == 1 or line.vehicleInfo.transportModes[10] == 1 or line.vehicleInfo.transportModes[11] == 1 or line.vehicleInfo.transportModes[12] == 1) then

and this kinda worked, at least on tram lines... soooo, sorry for the giant post, but I'm not writing that again, I guess this means you get to figure out the fix...

again for copypaste here's the assignments I found
https://transportfever2.com/wiki/api/modules/api.type.html#enum.TransportMode
< >
Showing 1-1 of 1 comments
CARTOK  [developer] 30 Dec, 2021 @ 6:15am 
Apologies, I never got a notification of this post and completely missed it. However, with your recent contributions, I gather this has been resolved proper! Thanks for your assistance!
< >
Showing 1-1 of 1 comments
Per page: 1530 50