Skip to content

Commit

Permalink
Ports cogbars from TG (#11120)
Browse files Browse the repository at this point in the history
* cpr

* flags

* qustinnus do_after refactor

* centre'd

* coggers

* move layers define

* mass fixes

* fix buckling

* misplace

* guh
  • Loading branch information
Tsar-Salat authored Sep 28, 2024
1 parent 279f861 commit ee0c7cc
Show file tree
Hide file tree
Showing 70 changed files with 378 additions and 226 deletions.
4 changes: 3 additions & 1 deletion beestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "code\__DEFINES\directional.dm"
#include "code\__DEFINES\diseases.dm"
#include "code\__DEFINES\DNA.dm"
#include "code\__DEFINES\do_afters.dm"
#include "code\__DEFINES\dye_keys.dm"
#include "code\__DEFINES\dynamic.dm"
#include "code\__DEFINES\economy.dm"
Expand Down Expand Up @@ -182,7 +183,6 @@
#include "code\__DEFINES\tgs.dm"
#include "code\__DEFINES\tgui.dm"
#include "code\__DEFINES\time.dm"
#include "code\__DEFINES\timed_action.dm"
#include "code\__DEFINES\tools.dm"
#include "code\__DEFINES\toys.dm"
#include "code\__DEFINES\traitor.dm"
Expand Down Expand Up @@ -335,6 +335,7 @@
#include "code\_globalvars\lists\ambience.dm"
#include "code\_globalvars\lists\client.dm"
#include "code\_globalvars\lists\flavor_misc.dm"
#include "code\_globalvars\lists\icons.dm"
#include "code\_globalvars\lists\maintenance_loot.dm"
#include "code\_globalvars\lists\mapping.dm"
#include "code\_globalvars\lists\mobs.dm"
Expand Down Expand Up @@ -538,6 +539,7 @@
#include "code\datums\chat_payload.dm"
#include "code\datums\chatmessage.dm"
#include "code\datums\cinematic.dm"
#include "code\datums\cogbar.dm"
#include "code\datums\dash_weapon.dm"
#include "code\datums\datacore.dm"
#include "code\datums\datum.dm"
Expand Down
4 changes: 4 additions & 0 deletions code/__DEFINES/do_afters.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define DOAFTER_SOURCE_SURGERY "doafter_surgery"
#define DOAFTER_SOURCE_MECHADRILL "doafter_mechadrill"
#define DOAFTER_SOURCE_SURVIVALPEN "doafter_survivalpen"
#define DOAFTER_SOURCE_GETTING_UP "doafter_gettingup"
18 changes: 14 additions & 4 deletions code/__DEFINES/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
else if(!HAS_TRAIT(x, TRAIT_KEEP_TOGETHER))\
x.appearance_flags &= ~KEEP_TOGETHER

//religious_tool flags
#define RELIGION_TOOL_INVOKE (1<<0)
#define RELIGION_TOOL_SACRIFICE (1<<1)
#define RELIGION_TOOL_SECTSELECT (1<<2)

//dir macros
///Returns true if the dir is diagonal, false otherwise
#define ISDIAGONALDIR(d) (d&(d-1))
Expand All @@ -217,7 +222,12 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
///Turns the dir by 180 degrees
#define DIRFLIP(d) turn(d, 180)

//religious_tool flags
#define RELIGION_TOOL_INVOKE (1<<0)
#define RELIGION_TOOL_SACRIFICE (1<<1)
#define RELIGION_TOOL_SECTSELECT (1<<2)
// timed_action_flags parameter for `/proc/do_after`
/// Can do the action even if mob moves location
#define IGNORE_USER_LOC_CHANGE (1<<0)
/// Can do the action even if the target moves location
#define IGNORE_TARGET_LOC_CHANGE (1<<1)
/// Can do the action even if the item is no longer being held
#define IGNORE_HELD_ITEM (1<<2)
/// Can do the action even if the mob is incapacitated (ex. handcuffed)
#define IGNORE_INCAPACITATED (1<<3)
6 changes: 5 additions & 1 deletion code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@
///AI Camera Static
#define CAMERA_STATIC_PLANE 200

///Anything that wants to be part of the game plane, but also wants to draw above literally everything else
#define HIGH_GAME_PLANE 499

#define FULLSCREEN_PLANE 500

///Popup Chat Messages
#define RUNECHAT_PLANE 650
/// Plane for balloon text (text that fades up)
#define BALLOON_CHAT_PLANE 651

///--------------- FULLSCREEN IMAGES ------------
#define FULLSCREEN_PLANE 500
#define FLASH_LAYER 1
#define FULLSCREEN_LAYER 2
#define UI_DAMAGE_LAYER 3
Expand Down
6 changes: 5 additions & 1 deletion code/__DEFINES/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ GLOBAL_LIST_INIT(available_random_trauma_list, list(
#define HUMAN_CARRY_SLOWDOWN 0.35

#define SLEEP_CHECK_DEATH(X) sleep(X); if(QDELETED(src) || stat == DEAD) return;
#define INTERACTING_WITH(X, Y) (Y in X.do_afters)

#define DOING_INTERACTION(user, interaction_key) (LAZYACCESS(user.do_afters, interaction_key))
#define DOING_INTERACTION_LIMIT(user, interaction_key, max_interaction_count) ((LAZYACCESS(user.do_afters, interaction_key) || 0) >= max_interaction_count)
#define DOING_INTERACTION_WITH_TARGET(user, target) (LAZYACCESS(user.do_afters, target))
#define DOING_INTERACTION_WITH_TARGET_LIMIT(user, target, max_interaction_count) ((LAZYACCESS(user.do_afters, target) || 0) >= max_interaction_count)

#define SILENCE_RANGED_MESSAGE (1<<0)

Expand Down
22 changes: 13 additions & 9 deletions code/__DEFINES/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ When using time2text(), please use "DDD" to find the weekday. Refrain from using
*/

#define MONDAY "Mon"
#define TUESDAY "Tue"
#define WEDNESDAY "Wed"
#define THURSDAY "Thu"
#define FRIDAY "Fri"
#define SATURDAY "Sat"
#define SUNDAY "Sun"
#define MONDAY "Mon"
#define TUESDAY "Tue"
#define WEDNESDAY "Wed"
#define THURSDAY "Thu"
#define FRIDAY "Fri"
#define SATURDAY "Sat"
#define SUNDAY "Sun"

#define INFINITE -1 // -1 is commonly used to indicate an infinite time duration

#define MILLISECONDS *0.01

#define DECISECONDS *1 //the base unit all of these defines are scaled by, because byond uses that as a unit of measurement for some fucking reason

#define SECONDS *10

Expand All @@ -49,8 +55,6 @@ When using time2text(), please use "DDD" to find the weekday. Refrain from using

#define TICKS *world.tick_lag

#define MILLISECONDS * 0.01

#define DS2TICKS(DS) ((DS)/world.tick_lag)

#define TICKS2DS(T) ((T) TICKS)
Expand Down
12 changes: 0 additions & 12 deletions code/__DEFINES/timed_action.dm

This file was deleted.

12 changes: 12 additions & 0 deletions code/__HELPERS/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,15 @@
return get_step(ref, base_dir)
*/

/// Returns an x and y value require to reverse the transformations made to center an oversized icon
/atom/proc/get_oversized_icon_offsets()
if (pixel_x == 0 && pixel_y == 0)
return list("x" = 0, "y" = 0)
var/list/icon_dimensions = get_icon_dimensions(icon)
var/icon_width = icon_dimensions["width"]
var/icon_height = icon_dimensions["height"]
return list(
"x" = icon_width > world.icon_size && pixel_x != 0 ? (icon_width - world.icon_size) * 0.5 : 0,
"y" = icon_height > world.icon_size && pixel_y != 0 ? (icon_height - world.icon_size) * 0.5 : 0,
)
7 changes: 7 additions & 0 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1459,3 +1459,10 @@ GLOBAL_LIST_EMPTY(friendly_animal_types)
animate(src, pixel_x = pixel_x + shiftx, pixel_y = pixel_y + shifty, time = 0.2, loop = duration)
pixel_x = initialpixelx
pixel_y = initialpixely

/// Returns a list containing the width and height of an icon file
/proc/get_icon_dimensions(icon_path)
if (isnull(GLOB.icon_dimensions[icon_path]))
var/icon/my_icon = icon(icon_path)
GLOB.icon_dimensions[icon_path] = list("width" = my_icon.Width(), "height" = my_icon.Height())
return GLOB.icon_dimensions[icon_path]
69 changes: 32 additions & 37 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,19 @@ GLOBAL_LIST_EMPTY(species_list)
* * progress - if TRUE, a progress bar is displayed.
* * extra_checks - a callback that can be used to add extra checks to the do_after. Returning false in this callback will cancel the do_after.
*/
/proc/do_after(mob/user, delay = 3 SECONDS, atom/target, timed_action_flags = NONE, progress = TRUE, datum/callback/extra_checks)
/proc/do_after(mob/user, delay, atom/target, timed_action_flags = NONE, progress = TRUE, datum/callback/extra_checks, interaction_key, max_interact_count = 1, hidden = FALSE)
if(!user)
return FALSE

if(target)
LAZYADD(user.do_afters, target)
LAZYADD(target.targeted_by, user)
if(!isnum(delay))
CRASH("do_after was passed a non-number delay: [delay || "null"].")

if(!interaction_key && target)
interaction_key = target //Use the direct ref to the target
if(interaction_key) //Do we have a interaction_key now?
var/current_interaction_count = LAZYACCESS(user.do_afters, interaction_key) || 0
if(current_interaction_count >= max_interact_count) //We are at our peak
return
LAZYSET(user.do_afters, interaction_key, current_interaction_count + 1)

var/atom/user_loc = user.loc
var/atom/target_loc = target?.loc
Expand All @@ -305,60 +311,49 @@ GLOBAL_LIST_EMPTY(species_list)
delay *= user.cached_multiplicative_actions_slowdown

var/datum/progressbar/progbar
var/datum/cogbar/cog

if(progress)
if(target) // the progress bar needs a target, so if we don't have one just pass it the user.
progbar = new(user, delay, target)
else
progbar = new(user, delay, user)
if(user.client)
progbar = new(user, delay, target || user)

if(!hidden && delay >= 1 SECONDS)
cog = new(user)

var/endtime = world.time + delay
var/starttime = world.time
. = TRUE
while(world.time < endtime)
stoplag(1)

if(QDELETED(user))
. = FALSE
break

if(progress)
if(!QDELETED(progbar))
progbar.update(world.time - starttime)

if(drifting && SSmove_manager.processing_on(user, SSspacedrift))
drifting = FALSE
user_loc = user.loc

// Check flags
if(!(timed_action_flags & IGNORE_USER_LOC_CHANGE) && !drifting && user.loc != user_loc)
. = FALSE

if(!(timed_action_flags & IGNORE_HELD_ITEM) && user.get_active_held_item() != holding)
if(QDELETED(user) \
|| (!(timed_action_flags & IGNORE_USER_LOC_CHANGE) && !drifting && user.loc != user_loc) \
|| (!(timed_action_flags & IGNORE_HELD_ITEM) && user.get_active_held_item() != holding) \
|| (!(timed_action_flags & IGNORE_INCAPACITATED) && HAS_TRAIT(user, TRAIT_INCAPACITATED)) \
|| (extra_checks && !extra_checks.Invoke()))
. = FALSE
break

if(!(timed_action_flags & IGNORE_INCAPACITATED) && user.incapacitated(ignore_restraints = (timed_action_flags & IGNORE_RESTRAINED)))
. = FALSE


if(extra_checks && !extra_checks.Invoke())
. = FALSE

// If we have a target, we check for them moving here. We don't care about it if we're drifting or we ignore target loc change
if(!(timed_action_flags & IGNORE_TARGET_LOC_CHANGE) && !drifting)
if(target_loc && user != target && (QDELETED(target) || target_loc != target.loc))
. = FALSE

if(target && !(timed_action_flags & IGNORE_TARGET_IN_DOAFTERS) && !(target in user.do_afters))
if(target && (user != target) && \
(QDELETED(target) \
|| (!(timed_action_flags & IGNORE_TARGET_LOC_CHANGE) && target.loc != target_loc)))
. = FALSE

if(!.)
break

if(!QDELETED(progbar))
progbar.end_progress()

if(!QDELETED(target))
LAZYREMOVE(user.do_afters, target)
LAZYREMOVE(target.targeted_by, user)
cog?.remove()

if(interaction_key)
LAZYREMOVE(user.do_afters, interaction_key)

/proc/is_species(A, species_datum)
. = FALSE
Expand Down
6 changes: 3 additions & 3 deletions code/__HELPERS/turfs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ Turf and target are separate in case you want to teleport some distance from a t
var/pixel_y_offset = checked_atom.pixel_y + atom_matrix.get_y_shift()

//Irregular objects
var/icon/checked_atom_icon = icon(checked_atom.icon, checked_atom.icon_state)
var/checked_atom_icon_height = checked_atom_icon.Height()
var/checked_atom_icon_width = checked_atom_icon.Width()
var/list/icon_dimensions = get_icon_dimensions(checked_atom.icon)
var/checked_atom_icon_height = icon_dimensions["width"]
var/checked_atom_icon_width = icon_dimensions["height"]
if(checked_atom_icon_height != world.icon_size || checked_atom_icon_width != world.icon_size)
pixel_x_offset += ((checked_atom_icon_width / world.icon_size) - 1) * (world.icon_size * 0.5)
pixel_y_offset += ((checked_atom_icon_height / world.icon_size) - 1) * (world.icon_size * 0.5)
Expand Down
2 changes: 2 additions & 0 deletions code/_globalvars/lists/icons.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Cache of the width and height of icon files, to avoid repeating the same expensive operation
GLOBAL_LIST_EMPTY(icon_dimensions)
2 changes: 1 addition & 1 deletion code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ CREATION_TEST_IGNORE_SUBTYPES(/atom/movable/screen/storage)
screen_loc = ui_mood

/atom/movable/screen/splash
icon = 'icons/blank_title.png'
icon = 'icons/blanks/blank_title.png'
icon_state = ""
screen_loc = "1,1"
plane = SPLASHSCREEN_PLANE
Expand Down
2 changes: 1 addition & 1 deletion code/datums/brain_damage/special.dm
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
var/slip_out_message = pick("silently fades in", "leaps out of thin air","appears", "walks out of an invisible doorway",\
"slides out of a fold in spacetime")
to_chat(user, "<span class='notice'>You try to align with the bluespace stream...</span>")
if(do_after(user, 20, target = src))
if(do_after(user, delay = 2 SECONDS, target = src))
new /obj/effect/temp_visual/bluespace_fissure(get_turf(src))
new /obj/effect/temp_visual/bluespace_fissure(get_turf(linked_to))
if(do_teleport(user, get_turf(linked_to), no_effects = TRUE))
Expand Down
Loading

0 comments on commit ee0c7cc

Please sign in to comment.