From 5c783f2110eaa911ffa924546127261a8cc5427b Mon Sep 17 00:00:00 2001 From: Fox-McCloud Date: Thu, 18 Aug 2016 00:09:57 -0400 Subject: [PATCH] fixup --- code/__DEFINES/misc.dm | 6 ++++ code/__HELPERS/unsorted.dm | 45 ++++++++++++++++++++----- code/modules/mining/equipment_locker.dm | 2 +- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 7a585461657..ab1357a5833 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -165,6 +165,12 @@ #define MAX_STACK_SIZE 50 +//check_target_facings() return defines +#define FACING_FAILED 0 +#define FACING_SAME_DIR 1 +#define FACING_EACHOTHER 2 +#define FACING_INIT_FACING_TARGET_TARGET_FACING_PERPENDICULAR 3 //Do I win the most informative but also most stupid define award? + //unmagic-strings for types of polls #define POLLTYPE_OPTION "OPTION" #define POLLTYPE_TEXT "TEXT" diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 6cd28a20a32..a51b593eb75 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1355,20 +1355,19 @@ Standard way to write links -Sayu return 1 -proc/check_target_facings(mob/living/initator, mob/living/target) +/proc/check_target_facings(mob/living/initator, mob/living/target) /*This can be used to add additional effects on interactions between mobs depending on how the mobs are facing each other, such as adding a crit damage to blows to the back of a guy's head. Given how click code currently works (Nov '13), the initiating mob will be facing the target mob most of the time That said, this proc should not be used if the change facing proc of the click code is overriden at the same time*/ - if(!!isliving(target) || target.lying || istype(target, /mob/living/silicon/pai)) + if(!ismob(target) || target.lying) //Make sure we are not doing this for things that can't have a logical direction to the players given that the target would be on their side - return - + return FACING_FAILED if(initator.dir == target.dir) //mobs are facing the same direction - return 1 - if(initator.dir + 4 == target.dir || initator.dir - 4 == target.dir) //mobs are facing each other - return 2 + return FACING_SAME_DIR + if(is_A_facing_B(initator, target) && is_A_facing_B(target, initator)) //mobs are facing each other + return FACING_EACHOTHER if(initator.dir + 2 == target.dir || initator.dir - 2 == target.dir || initator.dir + 6 == target.dir || initator.dir - 6 == target.dir) //Initating mob is looking at the target, while the target mob is looking in a direction perpendicular to the 1st - return 3 + return FACING_INIT_FACING_TARGET_TARGET_FACING_PERPENDICULAR atom/proc/GetTypeInAllContents(typepath) @@ -1472,6 +1471,36 @@ var/mob/dview/dview_mob = new return 1 return 0 + +//Get the dir to the RIGHT of dir if they were on a clock +//NORTH --> NORTHEAST +/proc/get_clockwise_dir(dir) + . = angle2dir(dir2angle(dir)+45) + +//Get the dir to the LEFT of dir if they were on a clock +//NORTH --> NORTHWEST +/proc/get_anticlockwise_dir(dir) + . = angle2dir(dir2angle(dir)-45) + + +//Compare A's dir, the clockwise dir of A and the anticlockwise dir of A +//To the opposite dir of the dir returned by get_dir(B,A) +//If one of them is a match, then A is facing B +/proc/is_A_facing_B(atom/A, atom/B) + if(!istype(A) || !istype(B)) + return 0 + if(isliving(A)) + var/mob/living/LA = A + if(LA.lying) + return 0 + var/goal_dir = angle2dir(dir2angle(get_dir(B,A)+180)) + var/clockwise_A_dir = get_clockwise_dir(A.dir) + var/anticlockwise_A_dir = get_anticlockwise_dir(B.dir) + + if(A.dir == goal_dir || clockwise_A_dir == goal_dir || anticlockwise_A_dir == goal_dir) + return 1 + return 0 + //This is just so you can stop an orbit. //orbit() can run without it (swap orbiting for A) //but then you can never stop it and that's just silly. diff --git a/code/modules/mining/equipment_locker.dm b/code/modules/mining/equipment_locker.dm index e4313b748b7..f73fa22c72e 100644 --- a/code/modules/mining/equipment_locker.dm +++ b/code/modules/mining/equipment_locker.dm @@ -1201,7 +1201,7 @@ marked_image = null var/backstab = check_target_facings(user, L) var/def_check = L.getarmor(type = "bomb") - if(backstab == 3 || backstab == 1) + if(backstab == FACING_INIT_FACING_TARGET_TARGET_FACING_PERPENDICULAR || backstab == FACING_SAME_DIR) L.apply_damage(80, BRUTE, blocked = def_check) playsound(user, 'sound/weapons/Kenetic_accel.ogg', 100, 1) //Seriously who spelled it wrong else