Page 1 of 1
Something like getTrainStops() or event.onattack
Posted: Mon Dec 22, 2014 10:40 am
by Choumiko
Like the title says, is there some function to get all the names of existing train stops and/or an event that get's fired when you are under attack?
I looked at most of the release notes, but didn't notice anything. It's probably all there in the core game, as you get the icon when under attack and you get a list of stops when renaming an existing one. For trainstops i could use findentitiesfiltered, but that seems messy and what area should i use? For the attack i have absolutely no idea.
Re: Something like getTrainStops() or event.onattack
Posted: Mon Dec 22, 2014 3:46 pm
by JLBShecky
There is nothing that give's you a list of all the train stops on the map, so you are going to have find them manually. That said you should only ever have to use findentitiesfiltered once, when the mod is first initialized in oninit.
game.getchunks() will tell you all the about all the chunks that have possibly been generated and you should be able to use it to get a bounding box for your search. Once you have the bonding box you can store the list of entities and then you can listen for onbuiltentity to see if it is a train stop and then add it to your list.
I don't see a built in method to get the list of train stops as being the most useful in the long run as one would still need to do post processing work as it stands, for example the built in list is not able to differentiate what stop is on what list so for automated train routing one would need to figure that out for oneself. And lets not get into how should the game handle the list when players are able to be in different factions, should the function get train stops from all factions or just their own?
As for an onattacked event I can't help you there but to my knowledge there is nothing there as it stands so that might be a good thing to ask for over in
Modding interface requests. I would say that an onattacked event would need to know what did the damage, (rocket, explosion, etc) who did the attack, who was attacked. It would probably also need to know the type of attack damage so that might need to be in there though you might be able to get that from what caused the damage.
Re: Something like getTrainStops() or event.onattack
Posted: Mon Dec 22, 2014 5:16 pm
by Choumiko
JLBShecky wrote:There is nothing that give's you a list of all the train stops on the map, so you are going to have find them manually. That said you should only ever have to use findentitiesfiltered once, when the mod is first initialized in oninit.
game.getchunks() will tell you all the about all the chunks that have possibly been generated and you should be able to use it to get a bounding box for your search. Once you have the bonding box you can store the list of entities and then you can listen for onbuiltentity to see if it is a train stop and then add it to your list.
That's what i thought, i simply hoped to have overlooked something. But thanks for game.getchunks(), was not aware of it and afraid how i'd figure out the area.
JLBShecky wrote:
I don't see a built in method to get the list of train stops as being the most useful in the long run as one would still need to do post processing work as it stands, for example the built in list is not able to differentiate what stop is on what list so for automated train routing one would need to figure that out for oneself. And lets not get into how should the game handle the list when players are able to be in different factions, should the function get train stops from all factions or just their own?
Not sure what you mean with list. But as i recall not even the train gui (where you setup your schedule) cares whether the train can reach it via the current network or not.
JLBShecky wrote:As for an onattacked event I can't help you there but to my knowledge there is nothing there as it stands so that might be a good thing to ask for over in
Modding interface requests.
That's what i might do. I just got the idea for something like The Fat Controller: When being attacked, click a button and your camera switches to the attack. As i really like seeing those biters get killed but rarely am close enough
Re: Something like getTrainStops() or event.onattack
Posted: Mon Dec 22, 2014 6:50 pm
by JLBShecky
Choumiko wrote:JLBShecky wrote:
I don't see a built in method to get the list of train stops as being the most useful in the long run as one would still need to do post processing work as it stands, for example the built in list is not able to differentiate what stop is on what list so for automated train routing one would need to figure that out for oneself. And lets not get into how should the game handle the list when players are able to be in different factions, should the function get train stops from all factions or just their own?
Not sure what you mean with list. But as i recall not even the train gui (where you setup your schedule) cares whether the train can reach it via the current network or not.
I think that is basically what I was trying to say, in a slightly round about way. I haven't played around with attempting automated train routing since 0.10, and the new API interfaces that were added in 0.11 make a number of the things that I was having issues with less troubling, namely there is an actual way to get station names now, and ontrainchangedstate. ontrainchangedstate should allow one to detect if a station is reachable, meaning that it should also be possible to build a graph mod side of what stations are reachable from each other. The only part that would need to be verified is if you can place a fake locomotive on the track next to the train stop in the desired direction, if you can do that then you can have everything that is needed to make a network graph. You can't change the direction that rolling stock is facing once it has been placed down and since trains will only path forward if you can't control the direction of the locomotive from the script then one can't guarantee that they can get all valid destinations. (But I guess that is getting a little out of the scope of the original question.)