Refactor client/Move

This commit is contained in:
Aronai Sieyes
2020-04-30 15:46:51 -04:00
parent a0a3971449
commit 62e5d5a413
3 changed files with 202 additions and 214 deletions

View File

@@ -59,22 +59,11 @@
var/damage = 0.0 var/damage = 0.0
var/range = 10.0 var/range = 10.0
/obj/effect/list_container
name = "list container"
/obj/effect/list_container/mobl
name = "mobl"
var/master = null
var/list/container = list( )
/obj/effect/projection /obj/effect/projection
name = "Projection" name = "Projection"
desc = "This looks like a projection of something." desc = "This looks like a projection of something."
anchored = 1.0 anchored = 1.0
/obj/effect/shut_controller /obj/effect/shut_controller
name = "shut controller" name = "shut controller"
var/moving = null var/moving = null
@@ -114,12 +103,5 @@
user.drop_item() user.drop_item()
src.throw_at(target, throw_range, throw_speed, user) src.throw_at(target, throw_range, throw_speed, user)
/obj/effect/stop
var/victim = null
icon_state = "empty"
name = "Geas"
desc = "You can't resist."
// name = ""
/obj/effect/spawner /obj/effect/spawner
name = "object spawner" name = "object spawner"

View File

@@ -127,39 +127,27 @@
onclose(user, "mob[name]") onclose(user, "mob[name]")
return return
/mob/living/ret_grab(obj/effect/list_container/mobl/L as obj, flag) /mob/living/ret_grab(var/list/L, var/mobchain_limit = 5)
if ((!( istype(l_hand, /obj/item/weapon/grab) ) && !( istype(r_hand, /obj/item/weapon/grab) ))) // We're the first!
if (!( L )) if(!L)
return null L = list()
else
return L.container // Lefty grab!
else if (istype(l_hand, /obj/item/weapon/grab))
if (!( L )) var/obj/item/weapon/grab/G = l_hand
L = new /obj/effect/list_container/mobl( null ) L |= G.affecting
L.container += src if(mobchain_limit-- > 0)
L.master = src G.affecting?.ret_grab(L, mobchain_limit) // Recurse! They can update the list. It's the same instance as ours.
if (istype(l_hand, /obj/item/weapon/grab))
var/obj/item/weapon/grab/G = l_hand // Righty grab!
if (!( L.container.Find(G.affecting) )) if (istype(r_hand, /obj/item/weapon/grab))
L.container += G.affecting var/obj/item/weapon/grab/G = r_hand
if (G.affecting) L |= G.affecting
G.affecting.ret_grab(L, 1) if(mobchain_limit-- > 0)
if (istype(r_hand, /obj/item/weapon/grab)) G.affecting?.ret_grab(L, mobchain_limit) // Same as lefty!
var/obj/item/weapon/grab/G = r_hand
if (!( L.container.Find(G.affecting) )) // On all but the one not called by us, this will just be ignored. Oh well!
L.container += G.affecting return L
if (G.affecting)
G.affecting.ret_grab(L, 1)
if (!( flag ))
if (L.master == src)
var/list/temp = list( )
temp += L.container
//L = null
qdel(L)
return temp
else
return L.container
return
/mob/living/mode() /mob/living/mode()
set name = "Activate Held Object" set name = "Activate Held Object"

View File

@@ -1,8 +1,8 @@
/mob/proc/setMoveCooldown(var/timeout) /mob/proc/setMoveCooldown(var/timeout)
move_delay = max(world.time + timeout, move_delay) next_move = max(world.time + timeout, next_move)
/mob/proc/check_move_cooldown() /mob/proc/checkMoveCooldown()
if(world.time < src.move_delay) if(world.time < next_move)
return FALSE // Need to wait more. return FALSE // Need to wait more.
return TRUE return TRUE
@@ -108,206 +108,224 @@
mob.control_object.forceMove(get_step(mob.control_object,direct)) mob.control_object.forceMove(get_step(mob.control_object,direct))
return return
// NB: This is called for 'self movement', not for being pulled or things like that, which COULD be the case for /mob/Move
// But to be honest, A LOT OF THIS CODE should be in /mob/Move
/client/Move(n, direct) /client/Move(n, direct)
//if(!mob) // Clients cannot have a null mob, as enforced by byond // Prevents a double-datum lookup each time this is referenced
// return // Moved here to avoid nullrefs below // May seem dumb, but it's faster to look up a var on my_mob than dereferencing mob on client, then dereferencing the var on that mob
// Having it in a var here means it's more available to look up things on. It won't speed up that second dereference, though.
var/mob/my_mob = mob
if(mob.control_object) Move_object(direct) // Nothing to do in nullspace
if(!my_mob.loc)
return
if(mob.incorporeal_move && isobserver(mob)) // Used many times below, faster reference.
var/atom/loc = my_mob.loc
// We're controlling an object which is SOMEHOW DIFFERENT FROM AN EYE??
if(my_mob.control_object)
Move_object(direct)
// Ghosty mob movement
if(my_mob.incorporeal_move && isobserver(my_mob))
Process_Incorpmove(direct) Process_Incorpmove(direct)
return return
if(moving) return 0 // We're in the middle of another move we've already decided to do
if(moving)
return 0
if(!mob.check_move_cooldown()) // We're still cooling down from the last move
if(!my_mob.checkMoveCooldown())
return return
if(locate(/obj/effect/stop/, mob.loc)) // If dead and we try to move in our mob, it leaves our body
for(var/obj/effect/stop/S in mob.loc) if(my_mob.stat == DEAD && isliving(my_mob) && !my_mob.forbid_seeing_deadchat)
if(S.victim == mob) my_mob.ghostize()
return
if(mob.stat==DEAD && isliving(mob) && !mob.forbid_seeing_deadchat)
mob.ghostize()
return return
// handle possible Eye movement // If we have an eyeobj, it moves instead
if(mob.eyeobj) if(my_mob.eyeobj)
return mob.EyeMove(n,direct) return my_mob.EyeMove(n,direct)
if(mob.transforming) return//This is sota the goto stop mobs from moving var // This is sota the goto stop mobs from moving var (for some reason)
if(my_mob.transforming)
return
if(isliving(mob)) if(isliving(my_mob))
var/mob/living/L = mob var/mob/living/L = my_mob
if(L.incorporeal_move)//Move though walls if(L.incorporeal_move)//Move though walls
Process_Incorpmove(direct) Process_Incorpmove(direct)
return return
if(mob.client) /* TODO observer unzoom
if(mob.client.view != world.view) // If mob moves while zoomed in with device, unzoom them. if(view != world.view) // If mob moves while zoomed in with device, unzoom them.
for(var/obj/item/item in mob.contents) for(var/obj/item/item in mob.contents)
if(item.zoom) if(item.zoom)
item.zoom() item.zoom()
break break
/* */
if(locate(/obj/item/weapon/gun/energy/sniperrifle, mob.contents)) // If mob moves while zoomed in with sniper rifle, unzoom them.
var/obj/item/weapon/gun/energy/sniperrifle/s = locate() in mob
if(s.zoom)
s.zoom()
if(locate(/obj/item/device/binoculars, mob.contents)) // If mob moves while zoomed in with binoculars, unzoom them.
var/obj/item/device/binoculars/b = locate() in mob
if(b.zoom)
b.zoom()
*/
if(Process_Grab()) return if(Process_Grab())
if(!mob.canmove)
return return
//Relaymove could handle it // Can't move
if(mob.machine) if(!my_mob.canmove)
var/result = mob.machine.relaymove(mob, direct) return
// Relaymove could handle it
if(my_mob.machine)
var/result = my_mob.machine.relaymove(my_mob, direct)
if(result) if(result)
return result return result
if(!mob.lastarea) // Can't control ourselves when drifting
mob.lastarea = get_area(mob.loc) if(isspace(loc) || my_mob.lastarea?.has_gravity == 0)
if(!my_mob.Process_Spacemove(0))
if((istype(mob.loc, /turf/space)) || (mob.lastarea.has_gravity == 0))
if(!mob.Process_Spacemove(0)) return 0
if(isobj(mob.loc) || ismob(mob.loc))//Inside an object, tell it we moved
var/atom/O = mob.loc
return O.relaymove(mob, direct)
if(isturf(mob.loc))
if(mob.restrained())//Why being pulled while cuffed prevents you from moving
for(var/mob/M in range(mob, 1))
if(M.pulling == mob)
if(!M.restrained() && M.stat == 0 && M.canmove && mob.Adjacent(M))
to_chat(src, "<font color='blue'>You're restrained! You can't move!</font>")
return 0
else
M.stop_pulling()
if(mob.pinned.len)
to_chat(src, "<font color='blue'>You're pinned to a wall by [mob.pinned[1]]!</font>")
return 0 return 0
mob.move_delay = world.time//set move delay // Inside an object, tell it we moved
if(isobj(loc) || ismob(loc))
return loc.relaymove(my_mob, direct)
switch(mob.m_intent) // Can't move unless you're in the world somewhere
if("run") if(!isturf(loc))
if(mob.drowsyness > 0) return
mob.move_delay += 6
mob.move_delay += config.run_speed
if("walk")
mob.move_delay += config.walk_speed
mob.move_delay += mob.movement_delay(n, direct)
if(istype(mob.buckled, /obj/vehicle) || istype(mob.buckled, /mob)) //VOREStation Edit: taur riding. I think. // Why being pulled while cuffed prevents you from moving
//manually set move_delay for vehicles so we don't inherit any mob movement penalties if(my_mob.restrained())
//specific vehicle move delays are set in code\modules\vehicles\vehicle.dm for(var/mob/M in range(my_mob, 1))
mob.move_delay = world.time if(M.pulling == my_mob)
//drunk driving if(!M.restrained() && M.stat == 0 && M.canmove && my_mob.Adjacent(M))
if(mob.confused && prob(20)) //vehicles tend to keep moving in the same direction to_chat(src, "<font color='blue'>You're restrained! You can't move!</font>")
direct = turn(direct, pick(90, -90)) return 0
if(istype(mob.buckled, /mob)) //VOREStation Edit to prevent mob riding speed exploit.
var/mob/M = mob.buckled
if(M.move_delay > mob.move_delay - 10)
return
return mob.buckled.relaymove(mob,direct)
if(mob.pulledby || mob.buckled) // Wheelchair driving!
if(istype(mob.loc, /turf/space))
return // No wheelchair driving in space
if(istype(mob.pulledby, /obj/structure/bed/chair/wheelchair))
return mob.pulledby.relaymove(mob, direct)
else if(istype(mob.buckled, /obj/structure/bed/chair/wheelchair))
if(ishuman(mob))
var/mob/living/carbon/human/driver = mob
var/obj/item/organ/external/l_hand = driver.get_organ("l_hand")
var/obj/item/organ/external/r_hand = driver.get_organ("r_hand")
if((!l_hand || l_hand.is_stump()) && (!r_hand || r_hand.is_stump()))
return // No hands to drive your chair? Tough luck!
//drunk wheelchair driving
else if(mob.confused)
switch(mob.m_intent)
if("run")
if(prob(50)) direct = turn(direct, pick(90, -90))
if("walk")
if(prob(25)) direct = turn(direct, pick(90, -90))
mob.move_delay += 2
return mob.buckled.relaymove(mob,direct)
//We are now going to move
moving = 1
//Something with pulling things
if(locate(/obj/item/weapon/grab, mob))
mob.move_delay = max(mob.move_delay, world.time + 7)
var/list/L = mob.ret_grab()
if(istype(L, /list))
if(L.len == 2)
L -= mob
var/mob/M = L[1]
if(M)
if ((get_dist(mob, M) <= 1 || M.loc == mob.loc))
var/turf/T = mob.loc
. = ..()
if (isturf(M.loc))
var/diag = get_dir(mob, M)
if ((diag - 1) & diag)
else
diag = null
if ((get_dist(mob, M) > 1 || diag))
step(M, get_dir(M.loc, T))
else else
for(var/mob/M in L) M.stop_pulling()
M.other_mobs = 1
if(mob != M)
M.animate_movement = 3
for(var/mob/M in L)
spawn( 0 )
step(M, direct)
return
spawn( 1 )
M.other_mobs = null
M.animate_movement = 2
return
else if(my_mob.pinned.len)
if(mob.confused) to_chat(src, "<font color='blue'>You're pinned to a wall by [my_mob.pinned[1]]!</font>")
switch(mob.m_intent) return 0
if(istype(my_mob.buckled, /obj/vehicle) || ismob(my_mob.buckled))
//manually set move_delay for vehicles so we don't inherit any mob movement penalties
//specific vehicle move delays are set in code\modules\vehicles\vehicle.dm
my_mob.next_move = world.time
//drunk driving
if(my_mob.confused && prob(20)) //vehicles tend to keep moving in the same direction
direct = turn(direct, pick(90, -90))
if(ismob(my_mob.buckled))
var/mob/M = my_mob.buckled
if(M.next_move > my_mob.next_move) // Don't let piggyback riders move their mob IN ADDITION TO the mob moving
return
return my_mob.buckled.relaymove(my_mob,direct)
if(my_mob.pulledby || my_mob.buckled) // Wheelchair driving!
if(isspace(loc))
return // No wheelchair driving in space
if(istype(my_mob.pulledby, /obj/structure/bed/chair/wheelchair))
return my_mob.pulledby.relaymove(my_mob, direct)
else if(istype(my_mob.buckled, /obj/structure/bed/chair/wheelchair))
if(ishuman(my_mob))
var/mob/living/carbon/human/driver = my_mob
var/obj/item/organ/external/l_hand = driver.get_organ("l_hand")
var/obj/item/organ/external/r_hand = driver.get_organ("r_hand")
if((!l_hand || l_hand.is_stump()) && (!r_hand || r_hand.is_stump()))
return // No hands to drive your chair? Tough luck!
//drunk wheelchair driving
else if(my_mob.confused)
switch(my_mob.m_intent)
if("run") if("run")
if(prob(75)) if(prob(50))
direct = turn(direct, pick(90, -90)) direct = turn(direct, pick(90, -90))
n = get_step(mob, direct)
if("walk") if("walk")
if(prob(25)) if(prob(25))
direct = turn(direct, pick(90, -90)) direct = turn(direct, pick(90, -90))
n = get_step(mob, direct) my_mob.setMoveCooldown(2)
. = mob.SelfMove(n, direct) return my_mob.buckled.relaymove(my_mob,direct)
for (var/obj/item/weapon/grab/G in mob) // We are now going to move
if (G.state == GRAB_NECK) moving = 1
mob.set_dir(reverse_dir[direct]) var/total_delay = 0
G.adjust_position() var/pre_move_loc = loc
for (var/obj/item/weapon/grab/G in mob.grabbed_by)
G.adjust_position()
moving = 0 // Start tally'ing when we can next move
// Grabs slow you down
if(locate(/obj/item/weapon/grab) in my_mob)
total_delay += 7
// Movespeed delay based on movement mode
switch(my_mob.m_intent)
if("run")
if(my_mob.drowsyness > 0)
total_delay += 6
total_delay += config.run_speed
if("walk")
total_delay += config.walk_speed
// A billion other things can slow you down, ask the mob
total_delay += my_mob.movement_delay(n, direct)
return . // Confused direction randomization
if(my_mob.confused)
switch(my_mob.m_intent)
if("run")
if(prob(75))
direct = turn(direct, pick(90, -90))
n = get_step(my_mob, direct)
if("walk")
if(prob(25))
direct = turn(direct, pick(90, -90))
n = get_step(my_mob, direct)
total_delay = TICKS2DS(-round(-(DS2TICKS(total_delay)))) //Rounded to the next tick in equivalent ds
var/glide_size = WORLD_ICON_SIZE/DS2TICKS(total_delay) //Down to whatever decimal
my_mob.setMoveCooldown(max(total_delay, 1))
. = my_mob.SelfMove(n, direct, glide_size)
return // If we have a grab
var/list/grablist = my_mob.ret_grab()
if(grablist.len)
grablist -= my_mob // Just in case we're in a circular grab chain
// It's just us and another person
if(grablist.len == 1)
var/mob/M = grablist[1]
if(!my_mob.Adjacent(M)) //Oh no, we moved away
M.glide_size = glide_size
step(M, get_dir(M, pre_move_loc)) //Have them step towards where we were
// It's a grab chain
else
for(var/mob/M in grablist)
my_mob.other_mobs = 1
M.other_mobs = 1 //Has something to do with people being able or unable to pass a chain of mobs
M.animate_movement = 3
//Ugly!
spawn(0) //Step
M.glide_size = glide_size
step(M, direct)
spawn(1) //Unstep
M.other_mobs = null
M.animate_movement = 2
spawn(1) //Unset
my_mob.other_mobs = null
/mob/proc/SelfMove(turf/n, direct) // Update all the grabs!
for (var/obj/item/weapon/grab/G in my_mob)
if (G.state == GRAB_NECK)
mob.set_dir(reverse_dir[direct])
G.adjust_position()
for (var/obj/item/weapon/grab/G in my_mob.grabbed_by)
G.adjust_position()
// We're not in the middle of a move anymore
moving = 0
/mob/proc/SelfMove(turf/n, direct, glide_size = 8)
src.glide_size = glide_size
return Move(n, direct) return Move(n, direct)
///Process_Incorpmove ///Process_Incorpmove
///Called by client/Move() ///Called by client/Move()
///Allows mobs to run though walls ///Allows mobs to run though walls