Skip to content

Commit

Permalink
behind turf stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikafox committed Dec 30, 2024
1 parent 7398a64 commit 616b8d4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 21 deletions.
2 changes: 2 additions & 0 deletions code/__DEFINES/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
#define TRAIT_KISS_OF_DEATH "kiss_of_death"
/// We can handle 'dangerous' plants in botany safely
#define TRAIT_PLANT_SAFE "plant_safe"
///This person is aiming and should not face atoms in different directions
#define TRAIT_AIMING "aiming"
/// This mob overrides certian SSlag_switch measures with this special trait
#define TRAIT_BYPASS_MEASURES "bypass_lagswitch_measures"
//non-mob traits
Expand Down
30 changes: 18 additions & 12 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -765,19 +765,25 @@ GLOBAL_LIST_INIT(WALLITEMS_INVERSE, typecacheof(list(
else
return "white"

/proc/params2turf(scr_loc, turf/origin, client/C)
if(!scr_loc)
/proc/parse_caught_click_modifiers(list/modifiers, turf/origin, client/viewing_client)
if(!modifiers)
return null
var/tX = splittext(scr_loc, ",")
var/tY = splittext(tX[2], ":")
var/tZ = origin.z
tY = tY[1]
tX = splittext(tX[1], ":")
tX = tX[1]
var/list/actual_view = getviewsize(C ? C.view : world.view)
tX = clamp(origin.x + text2num(tX) - round(actual_view[1] / 2) - 1, 1, world.maxx)
tY = clamp(origin.y + text2num(tY) - round(actual_view[2] / 2) - 1, 1, world.maxy)
return locate(tX, tY, tZ)

var/screen_loc = splittext(LAZYACCESS(modifiers, SCREEN_LOC), ",")
var/list/actual_view = getviewsize(viewing_client ? viewing_client.view : world.view)
var/click_turf_x = splittext(screen_loc[1], ":")
var/click_turf_y = splittext(screen_loc[2], ":")
var/click_turf_z = origin.z

var/click_turf_px = text2num(click_turf_x[2])
var/click_turf_py = text2num(click_turf_y[2])
click_turf_x = origin.x + text2num(click_turf_x[1]) - round(actual_view[1] / 2) - 1
click_turf_y = origin.y + text2num(click_turf_y[1]) - round(actual_view[2] / 2) - 1

var/turf/click_turf = locate(clamp(click_turf_x, 1, world.maxx), clamp(click_turf_y, 1, world.maxy), click_turf_z)
LAZYSET(modifiers, ICON_X, "[(click_turf_px - click_turf.pixel_x) + ((click_turf_x - click_turf.x) * world.icon_size)]")
LAZYSET(modifiers, ICON_Y, "[(click_turf_py - click_turf.pixel_y) + ((click_turf_y - click_turf.y) * world.icon_size)]")
return click_turf

/proc/screen_loc2turf(text, turf/origin, client/C)
if(!text)
Expand Down
3 changes: 2 additions & 1 deletion code/_globalvars/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ GLOBAL_LIST_INIT(traits_by_type, list(
"TRAIT_SCOOPABLE" = TRAIT_SCOOPABLE,
"TRAIT_ANXIOUS" = TRAIT_ANXIOUS,
"TRAIT_KISS_OF_DEATH" = TRAIT_KISS_OF_DEATH,
"TRAIT_PLANT_SAFE" = TRAIT_PLANT_SAFE
"TRAIT_PLANT_SAFE" = TRAIT_PLANT_SAFE,
"TRAIT_AIMING" = TRAIT_AIMING
),
/obj/item/bodypart = list(
"TRAIT_PARALYSIS" = TRAIT_PARALYSIS
Expand Down
10 changes: 5 additions & 5 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@

/// Simple helper to face what you clicked on, in case it should be needed in more than one place
/mob/proc/face_atom(atom/A)
if(buckled || stat != CONSCIOUS || !A || !x || !y || !A.x || !A.y)
if(buckled || stat != CONSCIOUS || !A || !x || !y || !A.x || !A.y || HAS_TRAIT(src, TRAIT_AIMING))
return
var/dx = A.x - x
var/dy = A.y - y
Expand Down Expand Up @@ -443,10 +443,10 @@
var/mob/living/carbon/C = usr
C.swap_hand()
else
var/turf/T = params2turf(LAZYACCESS(modifiers, SCREEN_LOC), get_turf(usr.client ? usr.client.eye : usr), usr.client)
params += "&catcher=1"
if(T)
T.Click(location, control, params)
var/turf/click_turf = parse_caught_click_modifiers(modifiers, get_turf(usr.client ? usr.client.eye : usr), usr.client)
if (click_turf)
modifiers["catcher"] = TRUE
click_turf.Click(click_turf, control, list2params(modifiers))
. = 1

/// MouseWheelOn
Expand Down
6 changes: 4 additions & 2 deletions code/datums/components/fullauto.dm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
if(isnull(location)) //Clicking on a screen object.
if(_target.plane != CLICKCATCHER_PLANE) //The clickcatcher is a special case. We want the click to trigger then, under it.
return //If we click and drag on our worn backpack, for example, we want it to open instead.
_target = params2turf(modifiers["screen-loc"], get_turf(source.eye), source)
_target = parse_caught_click_modifiers(modifiers, get_turf(source.eye), source)
params = list2params(modifiers)
if(!_target)
CRASH("Failed to get the turf under clickcatcher")

Expand Down Expand Up @@ -204,7 +205,8 @@
SIGNAL_HANDLER
if(isnull(over_location)) //This happens when the mouse is over an inventory or screen object, or on entering deep darkness, for example.
var/list/modifiers = params2list(params)
var/new_target = params2turf(modifiers["screen-loc"], get_turf(source.eye), source)
var/new_target = parse_caught_click_modifiers(modifiers, get_turf(source.eye), source)
params = list2params(modifiers)
mouse_parameters = params
if(!new_target)
if(QDELETED(target)) //No new target acquired, and old one was deleted, get us out of here.
Expand Down
2 changes: 2 additions & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1052,11 +1052,13 @@

if(zoomed)
RegisterSignal(user, COMSIG_ATOM_DIR_CHANGE, PROC_REF(rotate))
ADD_TRAIT(user, TRAIT_AIMING, src)
user.client.view_size.zoomOut(zoom_out_amt, zoom_amt, direc)
min_recoil = min_recoil_aimed
user.add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/gun, multiplicative_slowdown = wield_slowdown+aimed_wield_slowdown)
else
UnregisterSignal(user, COMSIG_ATOM_DIR_CHANGE)
REMOVE_TRAIT(user, TRAIT_AIMING, src)
user.client.view_size.zoomIn()
min_recoil = initial(min_recoil)
user.add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/gun, multiplicative_slowdown = wield_slowdown)
Expand Down
14 changes: 13 additions & 1 deletion code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,19 @@
if(prob(50))
homing_offset_y = -homing_offset_y

//Spread is FORCED!
/**
* Aims the projectile at a target.
*
* Must be passed at least one of a target or a list of click parameters.
* If only passed the click modifiers the source atom must be a mob with a client.
*
* Arguments:
* - [target][/atom]: (Optional) The thing that the projectile will be aimed at.
* - [source][/atom]: The initial location of the projectile or the thing firing it.
* - [modifiers][/list]: (Optional) A list of click parameters to apply to this operation.
* - deviation: (Optional) How the trajectory should deviate from the target in degrees.
* - //Spread is FORCED!
*/
/obj/projectile/proc/preparePixelProjectile(atom/target, atom/source, list/modifiers = null, spread = 0)
if(!(isnull(modifiers) || islist(modifiers)))
stack_trace("WARNING: Projectile [type] fired with non-list modifiers, likely was passed click params.")
Expand Down

0 comments on commit 616b8d4

Please sign in to comment.