turf
deep_water
density = 1
Enter(var/atom/movable/O)
if(istype(O,/obj/boat))
for(var/atom/movable/B in src)
if(B.density)
return 0
return 1
else
return ..(O)
mob
var
obj/vehicle
client
Move(newloc,var/ndir)
if(src.mob.vehicle)
return src.mob.vehicle.Move(newloc,ndir)
else
return src.mob.Move(newloc,ndir)
obj
boat
icon='Boat.dmi'
var
mob/pilot
density = 1
verb
pilot()
if(!src.pilot)
src.pilot = usr
usr.vehicle = src
else
usr << "There is already a pilot!"
board()
set src in oview(1)
if(src.contents.len<4)
if(!src.pilot)
src.pilot = usr
usr.vehicle = src
src.contents += usr
unboard() //I don't forgot the word.
set src in oview(1)
src.loc = usr.loc
usr.loc = src.loc
Problem description:
This was actually a code I found on the forums, when I attempted to implant it however I was unable to figure this out. In world the boat/ship does not move from its location at all. It will turn with the keys but never move. Would anyone mind teaching/helping me with the ship code?
I played around with your idea a bit.
For starters, I really hate the overriding Enter() to allow specific objects through. IMO, this kind of a thing would be best done with a general approach that can be recycled for different objects later on.
The reason that programming specific turfs to react to specific objects is bad is because you are telling the water to tell the boat what it can do, rather than the boat deciding what it will do. With OOP, it's usually best to let the objects handle their own behavior. Entering water is a mutual behavior of water and boat, but IMO, water itself shouldn't have to check that a specific type of object is entering it unless the behavior is exclusively confined to the object in question.
Let's imagine a game where you have different types of terrain and vehicles for bypassing that terrain. We want to allow ships to move on the ocean, rowboats to move on rivers, people to move on regular ground, forests, and hills, a horse to be able to move on ground and forests, a wagon to move on regular ground only, and we want an airship that can move wherever it damn pleases.
With this approach, you'd have to write a system that would account for each type of vehicle with each type of tile.
Instead, we're going to do something much, much simpler.
Basically, all we did here was add a single variable to /atom/movable and /turf each which when used together determine what kind of terrain this movable atom can walk on. When we "&" (binary and) the two values together, it returns a set of the individual flags that happened to match added together.
Let's set up our turfs, player and vehicles:
That should about do it for handling turf density.
I'll continue this in part 2 for handling vehicle movement and fixing your actual issue.