#Input variables
#max_speed
#walk_speed
#run_speed
#slope
#species
#underwater
#carry_mass
#elapsed_time
#energy

#Output variables
#max_speed
#energy

#original_max = max_speed
#max_speed = -1 means slide backwards downhill, speed proportional to slope


# THIS SECTION MAKES THEM STOP AT WATER BOUNDARIES
if (underwater and slope <= 0)
 max_speed = 0
endif

# THIS SECTION MAKES SOME SLOPES UNCLIMBABLE
 if (slope > (0.6+0.12*climb))
  max_speed = -2.0*slope
  else 


# CT: I think this maybe makes it so that they'll quickly scooch out of a too-steep situation
  if (slope > 0.3 and max_speed <= 0)
   max_speed = -2.0*slope


#THIS SECTION MAKES SPEED FASTER DOWNHILL
   else
    if (slope < -0.3)
     max_speed = max_speed 
#- (2 * max_speed * slope)


#THIS SECTION MAKES SPEED SLOWER UP STEEP SLOPES
    else
     if (slope > 0.5)
     max_speed = max_speed 
#- (0.5 * max_speed * slope) + (0.2*climb*max_speed)


#THIS SECTION MAKES SPEED NORMAL ON MOST SLOPES
    else
     max_speed = max_speed

    endif
   endif
  endif
 endif

#THIS SECTION MAKES THE CREATURE GO SLOWER WHEN CARRYING STUFF
if (max_speed > 0)
 max_speed = max_speed/(1+carry_mass)
endif

#THIS SECTION MAKES THE CREATURE GO WALK SPEED WHEN OUT OF ENERGY
if (energy <= 0 and max_speed > walk_speed)
 max_speed = walk_speed
endif