mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-15 04:01:41 +00:00
## About The Pull Request All usages of world.icon_size in code have been replaced with new `ICONSIZE_X`, `ICONSIZE_Y` and `ICONSIZE_ALL` defines depending on context Replaces some "32" magic numbers with the defines A few bits of code have been modified to split up x/y math as well ## Why It's Good For The Game Magic number bad, code more readable, code more flexible and I'm told there's an access cost to doing world.icon_size so minor performance gains ## Changelog 🆑 tonty code: made some code relating to the world's icon size more readable /🆑 --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
43 lines
1.6 KiB
Plaintext
43 lines
1.6 KiB
Plaintext
/proc/getviewsize(view)
|
|
if(!view) // Just to avoid any runtimes that could otherwise cause constant disconnect loops.
|
|
stack_trace("Missing value for 'view' in getviewsize(), defaulting to world.view!")
|
|
view = world.view
|
|
|
|
if(isnum(view))
|
|
var/totalviewrange = (view < 0 ? -1 : 1) + 2 * view
|
|
return list(totalviewrange, totalviewrange)
|
|
else
|
|
var/list/viewrangelist = splittext(view, "x")
|
|
return list(text2num(viewrangelist[1]), text2num(viewrangelist[2]))
|
|
|
|
|
|
/// Takes a string or num view, and converts it to pixel width/height in a list(pixel_width, pixel_height)
|
|
/proc/view_to_pixels(view)
|
|
if(!view)
|
|
return list(0, 0)
|
|
var/list/view_info = getviewsize(view)
|
|
view_info[1] *= ICON_SIZE_X
|
|
view_info[2] *= ICON_SIZE_Y
|
|
return view_info
|
|
|
|
/**
|
|
* Frustrated with bugs in can_see(), this instead uses viewers for a much more effective approach.
|
|
* ### Things to note:
|
|
* - Src/source must be a mob. `viewers()` returns mobs.
|
|
* - Adjacent objects are always considered visible.
|
|
*/
|
|
|
|
/// The default tile-distance between two atoms for one to consider the other as visible.
|
|
#define DEFAULT_SIGHT_DISTANCE 7
|
|
|
|
/// Basic check to see if the src object can see the target object.
|
|
#define CAN_I_SEE(target) ((src in viewers(DEFAULT_SIGHT_DISTANCE, target)) || in_range(target, src))
|
|
|
|
|
|
/// Checks the visibility between two other objects.
|
|
#define CAN_THEY_SEE(target, source) ((source in viewers(DEFAULT_SIGHT_DISTANCE, target)) || in_range(target, source))
|
|
|
|
|
|
/// Further checks distance between source and target.
|
|
#define CAN_SEE_RANGED(target, source, dist) ((source in viewers(dist, target)) || in_range(target, source))
|