Train spawning
Posted: Sun Jul 17, 2016 11:52 am
Hello everyone,
I'm trying to destroy a train and spawn it somewhere else in space, time and even save file.
So far I have run into three problems I have yet to solve:
1. How do I get the direction of locomotives (conveniently)? And how do I set this direction when creating the locomotive entities? A binary direction suffices, since I can do the rest by checking the direction of the station that the train is at.
It seems the 'direction' field of the locomotive entities is always north. To obtain the direction I could do some magic involving the direction of the station or rail, and whether locomotive is a front or rear carriage. This would be a little wacky since I would need to find the station based on the location of the train and the name of the station, as the schedule does not include a reference to the station, only a name. But this does not solve the question on how to spawn the locomotives in different directions, since my tests also show that the 'direction' field has no effect on spawning the locomotive.
2. How do I get the name of the locomotive? The 'name' field is nil, even though the locomotive has the name of a backer. I can get things to work without storing the name, but it would be nice to to also copy the name.
3. Is there a way to access the remaining fuel level of a locomotive? It is possible to get the efficiency bonus percentage, but I did not see where to access the remaining fuel level. Again, this is just a nice-to-have as the player should be able to live with some fuel losses.
I'm trying to destroy a train and spawn it somewhere else in space, time and even save file.
So far I have run into three problems I have yet to solve:
1. How do I get the direction of locomotives (conveniently)? And how do I set this direction when creating the locomotive entities? A binary direction suffices, since I can do the rest by checking the direction of the station that the train is at.
It seems the 'direction' field of the locomotive entities is always north. To obtain the direction I could do some magic involving the direction of the station or rail, and whether locomotive is a front or rear carriage. This would be a little wacky since I would need to find the station based on the location of the train and the name of the station, as the schedule does not include a reference to the station, only a name. But this does not solve the question on how to spawn the locomotives in different directions, since my tests also show that the 'direction' field has no effect on spawning the locomotive.
2. How do I get the name of the locomotive? The 'name' field is nil, even though the locomotive has the name of a backer. I can get things to work without storing the name, but it would be nice to to also copy the name.
3. Is there a way to access the remaining fuel level of a locomotive? It is possible to get the efficiency bonus percentage, but I did not see where to access the remaining fuel level. Again, this is just a nice-to-have as the player should be able to live with some fuel losses.