//Title: Modified Conveyor Belt
//Credit to: Gughunter (modified by Jtgibson)
//Contributed by: Jtgibson
//This is a weighted probability version of Guy T's Conveyor Belt Snippet.
// This means that numbers are as likely to occur as they are written. The
// former system made earlier numbers more likely to occur, forcing skewed
// percentages, which became confusing.
turf
var
allowsDrift = 0
atom/movable
var/conveyable = 0
mob/conveyable = 1 //If you don't want a certain mob to be conveyed, set this to 0
obj/conveyable = 0 //By default, objects won't be conveyed.
area/conveyor
proc
Convey(atom/movable/M, list/conveyProbs, list/conveyDirs)
//Requires declaration of /turf/var/allowsDrift. This will prevent things from
//washing up on shore in inappropriate places. Make sure to set allowsDrift = 1
//for your water/conveyor belt/escalator/windy/whatever turfs!
if(!M.conveyable) return
var
i
turf
proposedStep
var/running_total
var/probability = rand(1,100)
// /* Jtgibson's New Code
for(i = 1; i <= conveyProbs.len; i++)
running_total += conveyProbs[i] //Add current probability to running total
if(probability <= running_total) //If the probability roll falls within these bounds
proposedStep = get_step(M, conveyDirs[i]) //this is our stop!
if(proposedStep && proposedStep.allowsDrift) //make sure that it can actually go
var/direction = M.dir //preserve the object's former direction
if(M.Move(proposedStep)) //move the object there
if(!rotate) //if the object wasn't supposed to rotate,
M.dir = direction //turn it back to its normal facing
break
// */
/* Guy T's Old Code:
for(i = 1; i <= conveyProbs.len; i++)
if(probability < conveyProbs[i])
proposedStep = get_step(M, conveyDirs[i])
if(proposedStep.allowsDrift)
if(M.Move(proposedStep))
break
*/
var
sleepTime = 5
list
conveyProbs
conveyDirs
rotate = 0 //toggle: if 1, objects will turn to face the direction of motion
New()
..()
spawn(rand(1,sleepTime)) PerpetuateConveyance()
proc
PerpetuateConveyance()
var/mob/M
for(M as mob|obj in src)
Convey(M, src.conveyProbs, src.conveyDirs)
spawn(sleepTime) PerpetuateConveyance()
/*
//Sample conveyors:
area/conveyor
water
slow_south
sleepTime = 17
New()
..()
src.conveyDirs = list(WEST,SOUTHWEST,SOUTH,SOUTHEAST,EAST)
src.conveyProbs = list(10,20,40,20,10)
medium_southeast
sleepTime = 13
New()
..()
src.conveyDirs = list(SOUTHWEST,SOUTH,SOUTHEAST,EAST,NORTHEAST)
src.conveyProbs = list(5,20,50,20,5)
rapid_east
sleepTime = 6
New()
..()
src.conveyDirs = list(SOUTHEAST,EAST,NORTHEAST)
src.conveyProbs = list(10,40,10) //probabilities don't have to add up to 100!
*/
ID:195131
Nov 21 2006, 7:35 am (Edited on Jan 4 2010, 5:28 pm)
|
|
Dec 26 2009, 1:44 pm
|
|
Out of general curiosity, is there any purpose to the floats variable?
|
In response to DivineTraveller
|
|
There was, but not actually in that snippet. I had ripped that code out of the working version in The Haven Seed, many ages ago.
Fixed. ;-) |