getEntities => type ?

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • Hi there,


    would anyone know the possible variables for that getEntities command?

    I know that type = "CONSTRUCTION" works but I would like to filter more precisely the industries that are producing goods.

    Here are the ones I found in the lua files :


    ANIMAL

    ASSET_GROUP

    BASE_EDGE

    CONSTRUCTION

    STATION

    VEHICLE

    VEHICLE_DEPOT



    Cheers

    Einmal editiert, zuletzt von Claude ()

  • Hi Claude, I am currently figuring out how the entity system is working. I also replied to the other post about getting information about input/output of industries. However, it's different because that was about editing the construction via loadConstruction where you have information about the construction file. The entities work different and have other variables.


    So, I get all entities of a specific type with

    Code
     local constructions = game.interface.getEntities( {radius = 999999}, {type = "CONSTRUCTION", includeData=true} )

    It includes many entries, all constructions of the current game: town buildings, industries, assets.


    Example:

    Now what you could do, is filtering the entities via

    Code
    entity.fileName == "industry/*"

    But that entry does not contain information about the industry itself, I think it contents just information about the model. So I became aware of simBuildings = { 16513 }:

    This might be more interesting for you because it contains information about the production. type = "SIM_BUILDING" seems to be the industries, although I wouldn't have guessed that by the name.

    There is still an issue, I had industries on my test map that didn't produce anything and didn't have any entries of Cargotype in their simbuilding table.


    I don't know a better solution yet. Maybe there are possibilities with game.interface.getIndustryProduction but my tries with that resulted in a crash.

  • Hi VaccumTube,


    thanks a lot for your input.


    Do you know what "includeData=true" does exactly?

    What Ido use is

    Code
    local CId = (game.interface.getEntities({ radius = 1e100 }, { type = "CONSTRUCTION" }))
    for j = 1, #CId do
      local id = CId[j]
      print(commonapi.dmp (game.interface.getEntity (id)))
    end

    (I don't really know why "j" by the way, I simply seen it like that in a tutorial)


    And it seems to output the same result, for a Quarry eg.

    Here is what I believe is a town's industrial building :

    As you did mention, simBuildings does have an ID in the first case, a production facility, while it's empty in the second, a workplace.
    The opposite for townBuildings.
    I've also noticed that non production industries have "name = "no name",".
    I'll lookup in the files if I can find some simBuildings id soemwhere.


    What industries on your test map "didn't produce anything and didn't have any entries of Cargotype in their simbuilding table."?
    Would you have an stdout or even a savegame?


    Cheers

  • Do you know what "includeData=true" does exactly?

    It just includes the entity data (you get with getEntity) rather than returning only ids.


    If you use a for each loop, you don't need a counter variable j and it's the same like:

    Code
    local IDs = game.interface.getEntities({ radius = 1e100 }, { type = "CONSTRUCTION" })
    for _,id in pairs(IDs) do  -- _ for unneeded variable 
     commonapi.dmp (game.interface.getEntity (id))
    end

    for i,j in pairs(table) iterates over a table with i as index (1,2,3...) and j=table[i]


    Another advice: if you print commonapi.dmp () is always nil. dmp prints automatically to console.


    What industries on your test map "didn't produce anything and didn't have any entries of Cargotype in their simbuilding table."?
    Would you have an stdout or even a savegame?

    I tested on a very small map with 3 industries only. That industry was a building materials factory and hasn't been deliverd, so it didn't produce. There are no entries in the list, so it's not possible to determine input/output cargo type.


  • My understanding of lua code is very basic, I'm learning it in a very empirical way.

    So due to my own limitations, I cannot get your code to work

    Code
    for j = 1, #TownsId do
    local id = TownsId[j]
    commonapi.dmp (game.interface.getEntity (id)), commonapi.dmp (game.interface. getTownCapacities (id)), commonapi.dmp (game.interface. getTownCargoSupplyAndLimit(id) )
    end

    And removing print prompt an error. I must be lost in translation.


    I would like to test out that ", includeData=true" paramater to refine the getEntities => type list but, well, for now, I just don't know how to use it.


    PS : by the way, getIndustryProduction returns an integer. For example :

    print(commonapi.dmp (game.interface.getIndustryProduction (10411)))

    350


    PSbis: nevermind my misunderstanding, I think I get it now :
    print(commonapi.dmp ((game.interface.getEntities({ radius = 1e100 }, { type = "SIM_BUILDING", includeData=true }))))

    2 Mal editiert, zuletzt von Claude ()

  • You are seperating commands with ,

    commonapi.dmp(), commonapi.dmp(), ...

    this doesnt work


    the following should work:

    Code
    for j = 1, #TownsId do
        local id = TownsId[j]
        commonapi.dmp(game.interface.getEntity(id))
        commonapi.dmp(game.interface.getTownCapacities(id))
        commonapi.dmp(game.interface.getTownCargoSupplyAndLimit(id))
    end


    did you try out getCargoType (id) yet?

  • Hi VacuumTube,


    sorry, it was quite earlate and I pasted the wrong lines.

    I ment that this code, I cannot get to work :

    local IDs = game.interface.getEntities({ radius = 1e100 }, { type = "CONSTRUCTION" })

    for _,id in pairs(IDs) do -- _ for unneeded variable

    commonapi.dmp (game.interface.getEntity (id))



    "commonapi.dmp(), commonapi.dmp()," do work actually, that is by using CommonAPI2's console.

    Code
    local TownsId = (game.interface.getTowns ())
    for j = 1, #TownsId do
    local id = TownsId[j]
    print(commonapi.dmp (game.interface.getEntity (id)), commonapi.dmp (game.interface. getTownCapacities (id)), commonapi.dmp (game.interface. getTownCargoSupplyAndLimit(id) ) )
    end


    returns





    As for getCargoType, here's what I do get with it :

    INPUTOUTPUT
    print(commonapi.dmp (game.interface.getCargoTypes ())){ "PASSENGERS", "LOGS", "COAL", "IRON_ORE", "STONE", "GRAIN", "CRUDE", "STEEL", "PLANKS", "PLASTIC", "OIL", "CONSTRUCTION_MATERIALS", "MACHINES", "FUEL", "TOOLS", "FOOD", "GOODS" }
    print(commonapi.dmp (game.interface.getCargoType ("PASSENGERS"))){ discreteModels = {}, icon = "ui/hud/cargo_passengers.tga", iconSmall = "", id = "PASSENGERS", levelModels = {}, name = "Passengers", order = 0, townInput = {}, weight = 200 }



    I would like to reiterate that you found how to get only the production facilities to be listed, by using type = "SIM_BUILDING" instead of the broader type = "CONSTRUCTION"


    print(commonapi.dmp ((game.interface.getEntities({ radius = 1e100 }, { type = "SIM_BUILDING", includeData=true }))))

  • As an FYI, here is the list of entity types I got when calling game.interface.getEntity() without any type qualifier:

    entitiesSummary.ANIMAL; count; 4408; number

    entitiesSummary; ANIMAL; table: 000001BC9F1A6F70; table

    entitiesSummary.ASSET_GROUP; count; 61491; number

    entitiesSummary; ASSET_GROUP; table: 000001BC9F19EE10; table

    entitiesSummary.BASE_EDGE; count; 20286; number

    entitiesSummary; BASE_EDGE; table: 000001BB0A946810; table

    entitiesSummary.BASE_NODE; count; 18973; number

    entitiesSummary; BASE_NODE; table: 000001BB0A945E10; table

    entitiesSummary.CONSTRUCTION; count; 17203; number

    entitiesSummary; CONSTRUCTION; table: 000001BB0A953C40; table

    entitiesSummary.RAILROAD_CROSSING; count; 79; number

    entitiesSummary; RAILROAD_CROSSING; table: 000001BBE586C400; table

    entitiesSummary.SIGNAL; count; 550; number

    entitiesSummary; SIGNAL; table: 000001BB0A951D00; table

    entitiesSummary.SIM_BUILDING; count; 164; number

    entitiesSummary; SIM_BUILDING; table: 000001BB9AFFFE00; table

    entitiesSummary.SIM_CARGO; count; 3465; number

    entitiesSummary; SIM_CARGO; table: 000001BB903CD890; table

    entitiesSummary.SIM_PERSON; count; 9727; number

    entitiesSummary; SIM_PERSON; table: 000001BB0A947BC0; table

    entitiesSummary.STATION; count; 790; number

    entitiesSummary; STATION; table: 000001BB0A94D610; table

    entitiesSummary.STATION_GROUP; count; 505; number

    entitiesSummary; STATION_GROUP; table: 000001BB0A94D750; table

    entitiesSummary.TOWN; count; 16; number

    entitiesSummary; TOWN; table: 000001BBADDD5EF0; table

    entitiesSummary.TOWN_BUILDING; count; 16763; number

    entitiesSummary; TOWN_BUILDING; table: 000001BB9AFCB360; table

    entitiesSummary.VEHICLE; count; 1489; number

    entitiesSummary; VEHICLE; table: 000001BB0A951710; table

    entitiesSummary.VEHICLE_DEPOT; count; 84; number

    entitiesSummary; VEHICLE_DEPOT; table: 000001BB9AE91E60; table

    entitiesSummary.WORLD; count; 1; number

    entitiesSummary; WORLD; table: 000001BC9F1A6A20; table

  • I would like to reiterate that you found how to get only the production facilities to be listed, by using type = "SIM_BUILDING" instead of the broader type = "CONSTRUCTION"

    Why don't you just take the code you posted earlier and replace CONSTRUCTION by SIM_BUILDING?

    Code
    local CId = (game.interface.getEntities({ radius = 1e100 }, { type = "SIM_BUILDING" }))
    for j = 1, #CId do
     local id = CId[j]
     print(commonapi.dmp (game.interface.getEntity (id)))
    end


    I just simplified that code a bit. Doesn't it work? I think it should but didn't test it. Is there an error message?

    Code
    local IDs = game.interface.getEntities({ radius = 1e100 }, { type = "SIM_BUILDING" })
    for _,id in pairs(IDs) do
        commonapi.dmp (game.interface.getEntity(id))
    end
  • 1) Why don't you just take the code you posted earlier and replace CONSTRUCTION by SIM_BUILDING?

    Both way gives, almost, the same result. Thus I now use the shortest code.
    (with "includeData=true" on the left, with "for" on the right")

    [Blockierte Grafik: https://i.gyazo.com/0ae21a03e86cae4975118ce061672622.png]


    2) I just simplified that code a bit. Doesn't it work? I think it should but didn't test it. Is there an error message?

    It does work now, thank you. I forgot to not include the comment. My bad ;)


    doug interesting list indeed, thanks for sharing it. You didn't have any line set on the map?

  • I've never had issues with frame rates in this game. If I get close to one of Enzo's underground stations, or I leave a whole bunch of windows open on the screen, they'll drop down to 25 or so, but otherwise they're usually in the 50 - 60 range.

    Each person needs three buildings - home, shopping, work, so it does make sense that there are more town buildings than people.

  • Using a ton of mods, mostly vehicles. I don't think there are any that will directly affect the number of buildings - I'll have to check.

    As to the skyscrapers, I'm wondering if it would be possible to build a mod that will simply replace the stock period C buildings with copies of the period B ones. Just musing out loud here - don't know what affect that would have on town development...

  • thats how i get all industry-buildings:

    Code
        local conIds = game.interface.getEntities({pos = {0, 0, 0}, radius = 1e100}, { type = "CONSTRUCTION" })
        for key,conId in pairs(conIds) do
            local con = game.interface.getEntity(conId)
            if con.fileName:match("industry/") then
                -- its an industry construction
            end
        end

    so i just use the file-path and assume every industry construction file is and will every be in the industry directory


    doug

    to replace the C buildings with B just make a mod that overwrites all C buildings with the B ones (*.con files).

    For town development it will not have any effect on how many people the town will have. As the town just creates more and more buildings until it reaches the current limit.



    MFG PMV

  • But if the town creates more and more buildings, the towns wil be way larger. If the town uses a bigger area with the same amount of people, it will change some things:

    -less pedestrians

    -more car traffic

    -less frequentet and larger lines

    -unable to cover the same amount of people with a train station

    -lower emmisions

    -...

    This will probably lead to less inhabitans and higher investion costs.


    (OT: MFG in nem englischen Beitrag macht irgenwie keinen Sinn ;))

  • Bauer33333

    Same amount of people lead to same amount of car traffic ... the size of town you are speaking about will be that big, that most people already drive by car. Or use your lines. Cost of inner city lines is that low, compared to everything else ... it doesn't matter.

    Wth a bigger foodpint it is more easy to get flowing traffic.


    And in TPF2 you will never try to cover any train station with in city range (except cargo if its far away from residantial). Or you ignore emission.


    And btw. this is complete offtopic, not just your "OT" :D



    MFG PMV

BlueBrixx