From a69cbee6e9d9678756ee6f1a0988b8bd754a366f Mon Sep 17 00:00:00 2001 From: Chinsky Date: Thu, 19 Nov 2015 05:08:31 +0300 Subject: [PATCH] Refactored slipping code a little. Moved human Check_Shoegrip() override to human_movement. Parent is in mob_movement, makes sense to keep them in line imo. Renamed Process_Spaceslipping to slip_chance because it doesn't do any kind of processing. And I hate naming of these procs. Refactored human slip_chance override to use parent proc instead of doing same checks all over again. Removed update_gravity (and its only call in life()) and mob_has_gravity(). First one was called precisely once and did /nothing/. Mob-level proc just returns and it is never overriden anywhere. Second one is just a call for has_gravity, meaningless and used only once in that removed line. Refactored Check_Dense_Object (god I hate these names) to be less, for lack fo better word, retarded. Instead of weird var for keeping number of dense objects (that is never used, check only used as binary true/false), it now just returns value when it finds a suitabl object. Used trange and orange instead of oview to avoid fuckery in non-lit places. --- code/modules/mob/living/carbon/human/human.dm | 4 -- .../mob/living/carbon/human/human_movement.dm | 25 +++---- code/modules/mob/living/life.dm | 2 - .../mob/living/silicon/robot/drone/drone.dm | 2 +- .../living/silicon/robot/robot_movement.dm | 2 +- code/modules/mob/mob_movement.dm | 70 +++++++------------ 6 files changed, 37 insertions(+), 68 deletions(-) diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 11ae1407778..220c144b135 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -1365,10 +1365,6 @@ if(update_hud) handle_regular_hud_updates() -/mob/living/carbon/human/Check_Shoegrip() - if(shoes && (shoes.item_flags & NOSLIP) && istype(shoes, /obj/item/clothing/shoes/magboots)) //magboots + dense_object = no floating - return 1 - return 0 /mob/living/carbon/human/can_stand_overridden() if(wearing_rig && wearing_rig.ai_can_move_suit(check_for_ai = 1)) diff --git a/code/modules/mob/living/carbon/human/human_movement.dm b/code/modules/mob/living/carbon/human/human_movement.dm index 29eff929dce..50e88fc7859 100644 --- a/code/modules/mob/living/carbon/human/human_movement.dm +++ b/code/modules/mob/living/carbon/human/human_movement.dm @@ -87,18 +87,9 @@ return 0 -/mob/living/carbon/human/Process_Spaceslipping(var/prob_slip = 5) - //If knocked out we might just hit it and stop. This makes it possible to get dead bodies and such. - - if(species.flags & NO_SLIP) - return - - if(stat) - prob_slip = 0 // Changing this to zero to make it line up with the comment, and also, make more sense. - - //Do we have magboots or such on if so no slip - if(istype(shoes, /obj/item/clothing/shoes/magboots) && (shoes.item_flags & NOSLIP)) - prob_slip = 0 +/mob/living/carbon/human/slip_chance(var/prob_slip = 5) + if(!..()) + return 0 //Check hands and mod slip if(!l_hand) prob_slip -= 2 @@ -106,5 +97,11 @@ if (!r_hand) prob_slip -= 2 else if(r_hand.w_class <= 2) prob_slip -= 1 - prob_slip = round(prob_slip) - return(prob_slip) + return prob_slip + +/mob/living/carbon/human/Check_Shoegrip() + if(species.flags & NO_SLIP) + return 1 + if(shoes && (shoes.item_flags & NOSLIP) && istype(shoes, /obj/item/clothing/shoes/magboots)) //magboots + dense_object = no floating + return 1 + return 0 \ No newline at end of file diff --git a/code/modules/mob/living/life.dm b/code/modules/mob/living/life.dm index fd9dd7b4bfa..a848eda692c 100644 --- a/code/modules/mob/living/life.dm +++ b/code/modules/mob/living/life.dm @@ -38,8 +38,6 @@ //stuff in the stomach handle_stomach() - update_gravity(mob_has_gravity()) - update_pulling() for(var/obj/item/weapon/grab/G in src) diff --git a/code/modules/mob/living/silicon/robot/drone/drone.dm b/code/modules/mob/living/silicon/robot/drone/drone.dm index 56d608fd658..5b0c8a70c47 100644 --- a/code/modules/mob/living/silicon/robot/drone/drone.dm +++ b/code/modules/mob/living/silicon/robot/drone/drone.dm @@ -248,7 +248,7 @@ var/list/mob_hat_cache = list() ..() //DRONE MOVEMENT. -/mob/living/silicon/robot/drone/Process_Spaceslipping(var/prob_slip) +/mob/living/silicon/robot/drone/slip_chance(var/prob_slip) return 0 //CONSOLE PROCS diff --git a/code/modules/mob/living/silicon/robot/robot_movement.dm b/code/modules/mob/living/silicon/robot/robot_movement.dm index 5ea383aaa6c..faf15aa7da1 100644 --- a/code/modules/mob/living/silicon/robot/robot_movement.dm +++ b/code/modules/mob/living/silicon/robot/robot_movement.dm @@ -1,4 +1,4 @@ -/mob/living/silicon/robot/Process_Spaceslipping(var/prob_slip) +/mob/living/silicon/robot/slip_chance(var/prob_slip) if(module && module.no_slip) return 0 ..(prob_slip) diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm index d8b8778f420..aac1c91fc2e 100644 --- a/code/modules/mob/mob_movement.dm +++ b/code/modules/mob/mob_movement.dm @@ -11,7 +11,7 @@ return /mob/proc/setMoveCooldown(var/timeout) - if(client) + if(client) client.move_delay = max(world.time + timeout, client.move_delay) /client/North() @@ -450,15 +450,15 @@ if(!Check_Dense_Object()) //Nothing to push off of so end here update_floating(0) return 0 - - update_floating(1) + + update_floating(1) if(restrained()) //Check to see if we can do things return 0 //Check to see if we slipped - if(prob(Process_Spaceslipping(5)) && !buckled) - src << "\blue You slipped!" + if(prob(slip_chance(5)) && !buckled) + src << "You slipped!" src.inertia_dir = src.last_move step(src, src.inertia_dir) return 0 @@ -468,52 +468,30 @@ /mob/proc/Check_Dense_Object() //checks for anything to push off in the vicinity. also handles magboots on gravity-less floors tiles - var/dense_object = 0 - var/shoegrip + var/shoegrip = Check_Shoegrip() - for(var/turf/turf in oview(1,src)) - if(istype(turf,/turf/space)) - continue + for(var/turf/simulated/T in trange(1,src)) //we only care for non-space turfs + if(T.density) //walls work + return 1 + else + var/area/A = T.loc + if(A.has_gravity || shoegrip) + return 1 - if(istype(turf,/turf/simulated/floor)) // Floors don't count if they don't have gravity - var/area/A = turf.loc - if(istype(A) && A.has_gravity == 0) - if(shoegrip == null) - shoegrip = Check_Shoegrip() //Shoegrip is only ever checked when a zero-gravity floor is encountered to reduce load - if(!shoegrip) - continue + for(var/obj/O in orange(1, src)) + if(istype(O, /obj/structure/lattice)) + return 1 + if(O && O.density && O.anchored) + return 1 - dense_object++ - break - - if(!dense_object && (locate(/obj/structure/lattice) in oview(1, src))) - dense_object++ - - //Lastly attempt to locate any dense objects we could push off of - //TODO: If we implement objects drifing in space this needs to really push them - //Due to a few issues only anchored and dense objects will now work. - if(!dense_object) - for(var/obj/O in oview(1, src)) - if((O) && (O.density) && (O.anchored)) - dense_object++ - break - - return dense_object + return 0 /mob/proc/Check_Shoegrip() return 0 -/mob/proc/Process_Spaceslipping(var/prob_slip = 5) - //Setup slipage - //If knocked out we might just hit it and stop. This makes it possible to get dead bodies and such. +/mob/proc/slip_chance(var/prob_slip = 5) if(stat) - prob_slip = 0 // Changing this to zero to make it line up with the comment. - - prob_slip = round(prob_slip) - return(prob_slip) - -/mob/proc/mob_has_gravity(turf/T) - return has_gravity(src, T) - -/mob/proc/update_gravity() - return + return 0 + if(Check_Shoegrip()) + return 0 + return prob_slip \ No newline at end of file