/turf/traintracks/icon = 'track.dmi'
/mob/train/
icon = 'train.dmi'
verb/Board()
set src in view(1)
usr.loc = src
usr.client.eye = src
usr.client.perspective = EYE_PERSPECTIVE
usr.see_invisible = 1
usr.On_Train = 1
spawn() train_movement()
/atom/movable/proc/train_movement()
var/turf/traintracks/destination = null
for(var/turf/traintracks/t in oview(1))
if(get_dir(src, t) != turn(dir, 180))
destination = t
if(destination)
dir = get_dir(src, destination)
loc = destination
return 1
return 0
Problem description: I'm trying to create a train that players can enter and have it move along tracks during runtime. I have this code here to attempt to do that, but the problem is that the train doesn't move after I click Board(). Where'd I go wrong?
From a quick glance though, I can see a few things, you can probably use get_step(src,src.dir) instead of that loop and direction check, that will return the turf in that direction. You can then check the type using istype() to make sure it's a track.
However, if you were to make the train tracks into objects (probably should, so you can easily add/remove them at runtime and even move them if needed) you could do something like.
You'll notice I called Move() to move the train and not set the loc directly, this will allow things such as Enter()/Entered() to be called and collision checks and the sort to be executed. You can check the return value of Move() to see if the movement was successful or not (eg: if(Move(location)).
You'd want to alter the train's direction on corners and whatnot before the next movement takes place, this will also allow more complex track setups without pieces adjacent to each other conflicting.
Keep in mind this was all written off the top of my head to give you an idea of what direction to head with the system and it's not "just going to work" obviously.