ID:175721
 
New()
..()
spawn(50)
if(src)
justmade=0
Bump(var/obstacle)
if(isobj(obstacle))
var/obj/Water/w=obstacle
w.waterlevel+=src.waterlevel
del src

mob/verb/CheckWater()
set background=1
var/newturfwl=0
var/turf/turfon
for(var/obj/Water/w)
if(w.justmade!=1)
if(isturf(w.loc)) turfon=w.loc
if(w.waterlevel>1)
for(var/turf/t in oview(1,w))
// for(var/obj/Water/w3 in t.contents)newturfwl+=w3.waterlevel
// world << t.elevation+newturfwl
if((t.elevation+newturfwl)<(w.waterlevel+turfon.elevation))
var/obj/Water/w2=new /obj/Water(w.loc)
step_towards(w2,t)
w.waterlevel--
if(w2)
w2.waterlevel++
w2.justmade=1
if(w.waterlevel==0) del w

obj
Water
density=1
icon='water.dmi'
icon_state="flowing"
name="Water"
var/justmade=0
var/waterlevel=1
StartWater
waterlevel=10
icon_state="still"

Water doesn't go very far... Just 1 space then keeps going back. Not only that, but water doesn't delete
Jp wrote:
                          Bump(var/obstacle)
if(isobj(obstacle))
var/obj/Water/w=obstacle
w.waterlevel+=src.waterlevel
del src

The tabbing is messed up here; it appears that Bump is indented too far. Also it's a mistake to use isobj(), which you should instead be using istype(obstacle,/obj/Water).

I'm changing the tabs in the code quoted below to 2 spaces so it's more readable.
mob/verb/CheckWater()
set background=1
var/newturfwl=0
var/turf/turfon
for(var/obj/Water/w)
if(w.justmade!=1)
if(isturf(w.loc)) turfon=w.loc
if(w.waterlevel>1)
for(var/turf/t in oview(1,w))
// for(var/obj/Water/w3 in t.contents)newturfwl+=w3.waterlevel
// world << t.elevation+newturfwl
if((t.elevation+newturfwl)<(w.waterlevel+turfon.elevation))
var/obj/Water/w2=new /obj/Water(w.loc)
step_towards(w2,t)
w.waterlevel--
if(w2)
w2.waterlevel++
w2.justmade=1
if(w.waterlevel==0) del w

Okay, some problems with this off the bat:

  • I don't like the if(justmade!=1) line; this should be if(!justmade) for better clarity.
  • Similarly, the if(w.waterlevel==0) line is a problem; make this if(w.waterlevel<=0) instead, so it'll catch stray bugs that might eventually pop out.
  • newturfw1 is never actually set because you commented out the line that sets it, yet you need it for your calculations. Furthermore, you need to set newturfw1=0 at the beginning of the loop so it doesn't just keep increasing.
  • A waterlevel of 1 or less will never slide downhill.
  • The proc never accounts for water already in a location, and will always create a new water obj on top of it. This may be desirable for a special effect, though, so what you need to do is sleep() and then combine water objs.
  • Items that should be set in obj/Water/New() are set instead in this verb, like the justmade var being set to 1.

    So there's a lot here that I'd change. I think you're on the right track but there are some mistakes in the overall construction of the algorithm.

    First, I'd find all places where water could flow to a lower elevation and level.
for(w)
if(w.sliding || !isturf(w.loc)) continue
turfon=w
var/totaldiff=0
var/myel=turfon.GetWaterAndElevation()
// find total difference in elevation
// ignore very small differences
for(var/turf/T in orange(1,turfon))
var/el=T.GetWaterAndElevation()
if(myel-el>0.1) totaldiff+=el
// now spill water over the edges according to the difference
for(var/turf/T in orange(1,turfon))
var/el=T.GetWaterAndElevation()
if(myel-el>0.1)
var/obj/Water/w2=new(turfon,w,w.waterlevel*el/totalel)
w2.SlideTo(T)

...

turf
proc/GetWaterAndElevation()
var/el=elevation
for(var/obj/Water/w in src) el+=w.waterlevel

obj/Water
// DO NOT SET density=1

var/sliding=0

New(newloc,obj/Water/w,newlevel)
if(newlevel)
waterlevel=newlevel
if(w)
w.waterlevel-=newlevel
justmade=1
spawn(50) justmade=0

proc/SlideTo(turf/T)
sliding=1
icon_state="flowing"
step_towards(src,T)
sleep(4) // a movement delay
sliding=0
for(var/obj/Water/w in T)
if(w!=src && !w.sliding)
w.waterlevel+=waterlevel
del(src)
icon_state="still"
And the reason water probably stops moving for you is that it's dense, and step_towards() is going to choke on that. You might want to put in a check to see if the turfs being checked for elevation are dense, and just skip those.

Lummox JR