Skip to content

Commit

Permalink
Merge pull request #2508 from Superlagg/what-do-you-feel-when-you-sho…
Browse files Browse the repository at this point in the history
…ot-a-raider--runtimes

Reworks recoil into something I can understand
  • Loading branch information
Superlagg authored Jun 25, 2023
2 parents 553d351 + 2595a27 commit d3787a1
Show file tree
Hide file tree
Showing 66 changed files with 3,103 additions and 1,749 deletions.
238 changes: 133 additions & 105 deletions code/__DEFINES/combat.dm

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
///When a thing is adminspawned, signal
#define COMSIG_ATOM_POST_ADMIN_SPAWN "atom_post_admin_spawn"

///When a gun/mag thing is told to admin reload, signal
#define COMSIG_GUN_MAG_ADMIN_RELOAD "gun_mag_admin_reload"

#define COMSIG_ATOM_SCREWDRIVER_ACT "atom_screwdriver_act" //from base of atom/screwdriver_act(): (mob/living/user, obj/item/I)
#define COMSIG_ATOM_INTERCEPT_TELEPORT "intercept_teleport" //called when teleporting into a protected turf: (channel, turf/origin, turf/destination)
#define COMPONENT_BLOCK_TELEPORT 1
Expand Down Expand Up @@ -415,6 +418,7 @@
#define COMPONENT_BLOCK_SHARPEN_MAXED 8
#define COMSIG_UPGRADE_APPVAL "apply_values" //from /atom/refresh_upgrades(): (/src) Called to upgrade specific values
#define COMSIG_UPGRADE_ADDVAL "add_values" //from /atom/refresh_upgrades(): (/src) Called to add specific things to the /src, called before COMSIG_APPVAL
#define COMSIG_GET_UPGRADES "get_upgrades" //from /atom/refresh_upgrades(): (/src) Called to get the upgrades of the /src

#define COMSIG_UPGRADE_REMOVE "uninstall"
#define COMSIG_ITEM_MICROWAVE_ACT "microwave_act" //called on item when microwaved (): (obj/machinery/microwave/M)
Expand Down
3 changes: 2 additions & 1 deletion code/__DEFINES/items_upgrades.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
#define GUN_UPGRADE_RICO_MULT "ricochet_mult"
#define GUN_UPGRADE_FIRE_DELAY_MULT "fire_delay_mult"
#define GUN_UPGRADE_MOVE_DELAY_MULT "move_delay_mult"
#define GUN_UPGRADE_RECOIL "recoil_mult"
#define GUN_UPGRADE_RECOIL_1H "recoil_mult_1h"
#define GUN_UPGRADE_RECOIL_2H "recoil_mult_2h"
#define GUN_UPGRADE_MUZZLEFLASH "muzzleflash_mult"
#define GUN_UPGRADE_PROJ_SPEED_MULT "projspeed_mult"
#define GUN_UPGRADE_CHARGECOST "chargecost_mult"
Expand Down
26 changes: 26 additions & 0 deletions code/__DEFINES/maths.dm
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,29 @@
/// Gives the number of pixels in an orthogonal line of tiles.
#define TILES_TO_PIXELS(tiles) (tiles * PIXELS)
// )

/proc/shorten_number(number, decimals = 2)
var/unit = ""
var/thousands = 0
while(number > 1000)
number *= 0.001
thousands++
switch(thousands)
if(-INFINITY to 0)
return "[number]"
if(1)
unit = "K"
if(2)
unit = "M"
if(3)
unit = "G"
if(4)
unit = "T"
if(5)
unit = "Q"
if(6)
unit = "QQ"
else
unit = "QQQ"
var/roundie = 1 * (0.1**decimals)
return "[round(number, roundie)][unit]"
1 change: 1 addition & 0 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LAZYACCESS(L, I) (L ? (isnum(I) ? (I > 0 && I <= length(L) ? L[I] : null) : L[I]) : null)
#define LAZYSET(L, K, V) if(!L) { L = list(); } L[K] = V;
#define LAZYLEN(L) length(L)
#define LAZYLENGTHEN(L, I) if(!L) { L = list(); } L.len = (L.len < I ? I : L.len); // Thats a hose lengthener -- you need one!
//Sets a list to null
#define LAZYNULL(L) L = null
#define LAZYCLEARLIST(L) if(L) L.Cut()
Expand Down
24 changes: 24 additions & 0 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,30 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)
if(haystack.loc)
return recursive_loc_search(haystack.loc, needle, max_depth - 1)

/// Recursively searches through everything in a turf for atoms. Will recursively search through all those atoms for atoms, and so on.
/proc/get_all_in_turf(turf/search_me, include_turf = FALSE, max_depth = 5)
if(!isturf(search_me))
if(!isatom(search_me))
return list()
else
search_me = get_turf(search_me)
var/list/atoms_in_turf = search_me.contents?.Copy()
if(!LAZYLEN(atoms_in_turf))
return list()
var/list/atoms_found = list()
var/iterations_left = 1000
while(LAZYLEN(atoms_in_turf) && iterations_left--)
var/atom/atom = LAZYACCESS(atoms_in_turf, LAZYLEN(atoms_in_turf))
atoms_in_turf.len--
if(!isatom(atom))
continue
if(LAZYLEN(atom.contents))
atoms_in_turf |= atom.contents
atoms_found += atom
if(include_turf)
atoms_found += search_me
return atoms_found

/// Goes through the common places a client can be held, and returns the first one it finds
/proc/get_client(thing_w_client)
if(isclient(thing_w_client))
Expand Down
63 changes: 60 additions & 3 deletions code/controllers/subsystem/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define BAD_INIT_SLEPT 4
#define BAD_INIT_NO_HINT 8

#define PRINT_ATOM_STATS 1

SUBSYSTEM_DEF(atoms)
name = "Atoms"
init_order = INIT_ORDER_ATOMS
Expand All @@ -16,10 +18,10 @@ SUBSYSTEM_DEF(atoms)

/datum/controller/subsystem/atoms/Initialize(timeofday)
GLOB.fire_overlay.appearance_flags = RESET_COLOR
to_chat(world, span_boldannounce("Initializing genetics..."))
to_chat(world, span_boldannounce("Initializing Genetics..."))
setupGenetics()
initialized = INITIALIZATION_INNEW_MAPLOAD
to_chat(world, span_boldannounce("Initializing atoms..."))
to_chat(world, span_boldannounce("Initializing Atoms..."))
InitializeAtoms()
return ..()

Expand All @@ -42,12 +44,67 @@ SUBSYSTEM_DEF(atoms)
CHECK_TICK
else
count = 0
#ifdef PRINT_ATOM_STATS
var/all_atoms = LAZYLEN(world.contents)
var/portion = 1
var/portion_amount = 0.1
var/next_milestone = round(all_atoms * (portion * portion_amount))
var/batch_start = REALTIMEOFDAY
var/start_timery = REALTIMEOFDAY
var/this_batch = 0
var/atoms_did = 0
var/list/rates = list()
var/list/num_of_kinds = list(
/obj = 0,
/obj/structure = 0,
/obj/item = 0,
/mob = 0,
/turf = 0,
/area = 0,
)
#endif
for(var/atom/A in world)
#ifdef PRINT_ATOM_STATS
atoms_did++
#endif
if(!(A.flags_1 & INITIALIZED_1))
InitAtom(A, mapload_arg)
++count
#ifdef PRINT_ATOM_STATS
this_batch++
for(var/kind in num_of_kinds)
if(istype(A, kind))
num_of_kinds[kind]++
if(atoms_did % next_milestone == 0)
all_atoms = LAZYLEN(world.contents)
var/batch_end = REALTIMEOFDAY
var/batch_time = ((batch_end - batch_start) * 0.1)
var/batch_rate = (this_batch / batch_time)
var/batch_percent = (atoms_did / all_atoms) * 100
var/batch_time_left = ((all_atoms - atoms_did) / batch_rate)
portion++
next_milestone = round(all_atoms * (portion * portion_amount))
rates += batch_rate
batch_start = REALTIMEOFDAY
this_batch = 0
to_chat(world, span_boldannounce("Init'd [shorten_number(atoms_did, 2)]/[shorten_number(all_atoms, 2)] ([round(batch_percent)]%) atoms in [DisplayTimeText(REALTIMEOFDAY - start_timery)]. \nProjected time left at [shorten_number(batch_rate, 1)]/sec: [DisplayTimeText(batch_time_left)]!"))
#endif
CHECK_TICK

#ifdef PRINT_ATOM_STATS
var/avrate = 0
for(var/r in rates)
avrate += r
avrate /= rates.len
var/list/output_kinds = list()
output_kinds += "[shorten_number(num_of_kinds[/obj], 1)] objects"
output_kinds += "[shorten_number(num_of_kinds[/obj/item], 1)] items"
output_kinds += "[shorten_number(num_of_kinds[/obj/structure], 1)] structures"
output_kinds += "[shorten_number(num_of_kinds[/mob], 1)] mobs"
output_kinds += "[shorten_number(num_of_kinds[/turf], 1)] turfs"
output_kinds += "[shorten_number(num_of_kinds[/area], 1)] areas"
to_chat(world, span_boldannounce("~Initialized [shorten_number(count, 2)] atoms ([shorten_number(atoms_did - count, 2)] didn't need it)! Average rate: [shorten_number(avrate, 1)]/sec.~"))
to_chat(world, span_notice("Of these atoms, [english_list(output_kinds)] initialized."))
#endif
testing("Initialized [count] atoms")
pass(count)

Expand Down
105 changes: 105 additions & 0 deletions code/controllers/subsystem/gunreticle.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// A subsystem? For reticle? In MY BYOND? It's more likely than you think.
// Also includes a dynamic cursor, simulating accuracy. If you want to resprite this, go ahead.
SUBSYSTEM_DEF(reticle)
name = "Reticle"
flags = SS_BACKGROUND|SS_NO_FIRE
var/list/reticle_icons = list()

/datum/controller/subsystem/reticle/Initialize(start_timeofday)
build_reticle_icons()
. = ..()

/datum/controller/subsystem/reticle/proc/build_reticle_icons()
for(var/offset in 0 to SSrecoil.recoil_max_spread*2)
var/true_offset = offset - SSrecoil.recoil_max_spread // -SSrecoil.recoil_max_spread to SSrecoil.recoil_max_spread
var/apparent_offset = max(true_offset, 0) // The negatives just get color differences
var/icon/base = icon('modular_coyote/eris/icons/96x96.dmi')
var/icon/scaled = icon('modular_coyote/eris/icons/standard_grayscale.dmi') //Default cursor, cut into pieces according to their direction
base.Blend(scaled, ICON_OVERLAY, x = 32, y = 32)
for(var/dir in list(NORTHEAST,NORTHWEST,SOUTHEAST,SOUTHWEST))
var/icon/overlay = icon('modular_coyote/eris/icons/standard_grayscale.dmi', "[dir]")
var/pixel_y
var/pixel_x
if(dir & NORTH)
pixel_y = CLAMP(apparent_offset, -MAX_RETICLE_SIZE, MAX_RETICLE_SIZE)
if(dir & SOUTH)
pixel_y = CLAMP(-apparent_offset, -MAX_RETICLE_SIZE, MAX_RETICLE_SIZE)
if(dir & EAST)
pixel_x = CLAMP(apparent_offset, -MAX_RETICLE_SIZE, MAX_RETICLE_SIZE)
if(dir & WEST)
pixel_x = CLAMP(-apparent_offset, -MAX_RETICLE_SIZE, MAX_RETICLE_SIZE)
base.Blend(overlay, ICON_OVERLAY, x=32+pixel_x, y=32+pixel_y)
var/spread_color = gradient("#00FF00", "#0000FF", "#FFFF00", (offset/(SSrecoil.recoil_max_spread*2)))
base.Blend(spread_color, ICON_MULTIPLY)
reticle_icons["reticle-[round(true_offset)]"] = base
SSassets.transport.register_asset("reticle-[offset]", base)

/datum/controller/subsystem/reticle/proc/find_cursor_icon(offset)
var/my_cursor = LAZYACCESS(reticle_icons, "reticle-[offset]")
if(!my_cursor)
return LAZYACCESS(reticle_icons, "reticle-0")
return LAZYACCESS(reticle_icons, "reticle-[offset]")

/datum/controller/subsystem/reticle/proc/send_all_cursor_icons(client/C)
for(var/reticle in reticle_icons)
C << LAZYACCESS(reticle_icons, reticle)

/mob/living/proc/update_cursor(obj/item/gun/G)
if(!client)
return
if(!istype(G))
remove_cursor()
return
if(!CHECK_BITFIELD(client.prefs.cb_toggles, AIM_CURSOR_ON))
remove_cursor()
return
if(get_active_held_item() != G)
remove_cursor()
return
//client.mouse_pointer_icon = initial(client.mouse_pointer_icon)
var/recoil = SSrecoil.get_offset(src, FALSE, TRUE)
var/offset = clamp(round(recoil, 1), -MAX_ACCURACY_OFFSET, MAX_ACCURACY_OFFSET)
var/icon/base = SSreticle.find_cursor_icon(offset)
ASSERT(isicon(base))
client.mouse_pointer_icon = base

/mob/living/proc/remove_cursor()
if(!client)
return
client.mouse_pointer_icon = initial(client.mouse_pointer_icon)

//Allows for a dynamic cursor, simulating accuracy. If you want to resprite this, go ahead.

/obj/item/gun/equipped(mob/living/H)
. = ..()
if(H.client && !CHECK_BITFIELD(H.client.prefs.cb_toggles, AIM_CURSOR_ON))
H.remove_cursor()
return
if(H.get_active_held_item() == src && !safety)
H.update_cursor(src)
else
H.remove_cursor()

/obj/item/gun/afterattack(obj/target, mob/living/user, flag)
. = ..()
if(user.get_active_held_item() != src)
user.remove_cursor()

/obj/item/gun/dropped(mob/living/user)
user.remove_cursor()
. = ..()

/obj/item/gun/afterattack(atom/A, mob/living/user, adjacent, params)
check_safety_cursor(user)
. = ..()

/obj/item/gun/Destroy()
if(ismob(loc))
var/mob/living/L = loc
L.remove_cursor()
. = ..()





11 changes: 11 additions & 0 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ SUBSYSTEM_DEF(mapping)
var/total_z = 0
var/list/parsed_maps = list()
for (var/file in files)
var/start_part_time = world.time
var/full_path = "_maps/[path]/[file]"
var/datum/parsed_map/pm = new(file(full_path))
var/bounds = pm?.bounds
Expand All @@ -236,6 +237,9 @@ SUBSYSTEM_DEF(mapping)
continue
parsed_maps[pm] = total_z // save the start Z of this file
total_z += bounds[MAP_MAXZ] - bounds[MAP_MINZ] + 1
var/time_taken = world.time - start_part_time
if (!silent)
INIT_ANNOUNCE("Parsed [file] in [time_taken * 0.1] seconds.")

if (!length(traits)) // null or empty - default
for (var/i in 1 to total_z)
Expand All @@ -256,9 +260,16 @@ SUBSYSTEM_DEF(mapping)

// load the maps
for (var/P in parsed_maps)
var/start_part_time = world.time
var/datum/parsed_map/pm = P
if (!pm.load(1, 1, start_z + parsed_maps[P], no_changeturf = TRUE, orientation = orientation))
errorList |= pm.original_path
if(!silent)
var/time_taken = world.time - start_part_time
var/list/fullfile = splittext(pm.original_path, "/")
var/filename = fullfile[LAZYLEN(fullfile)]
INIT_ANNOUNCE("Loaded [filename] in [(time_taken)/10]s!")

if(!silent)
INIT_ANNOUNCE("Loaded [name] in [(REALTIMEOFDAY - start_time)/10]s!")
return parsed_maps
Expand Down
3 changes: 1 addition & 2 deletions code/controllers/subsystem/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ SUBSYSTEM_DEF(misc)
GLOBAL_LIST_INIT(cursor_icons, list()) //list of icon files, which point to lists of offsets, which point to icons

/proc/initialize_cursors()
for(var/i = 0 to MAX_ACCURACY_OFFSET)
make_cursor_icon('modular_coyote/eris/icons/standard.dmi', i)

Loading

0 comments on commit d3787a1

Please sign in to comment.