Skip to content

Commit

Permalink
Dragging storage bags now drops items around the mouse pointer (#27790)
Browse files Browse the repository at this point in the history
* Standardize attom scatter and make bag drops offset it based on mouse position

* Init sanity

* Update code/game/atoms_movable.dm

Signed-off-by: DGamerL <[email protected]>

---------

Signed-off-by: DGamerL <[email protected]>
Co-authored-by: DGamerL <[email protected]>
  • Loading branch information
FunnyMan3595 and DGamerL authored Jan 6, 2025
1 parent c195c48 commit 41c236a
Show file tree
Hide file tree
Showing 39 changed files with 94 additions and 94 deletions.
6 changes: 2 additions & 4 deletions code/controllers/subsystem/non_firing/SSmapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,15 @@ SUBSYSTEM_DEF(mapping)
var/obj/structure/closet/C = pick_n_take(seeded_salvage_closets)
var/salvage_item_type = pick(small_salvage_items)
var/obj/salvage_item = new salvage_item_type(C)
salvage_item.pixel_x = rand(-5, 5)
salvage_item.pixel_y = rand(-5, 5)
salvage_item.scatter_atom()
max_salvage_attempts -= 1

max_salvage_attempts = rand(10, 15)
while(max_salvage_attempts > 0 && length(seeded_salvage_surfaces) > 0)
var/obj/T = pick_n_take(seeded_salvage_surfaces)
var/salvage_item_type = pick(small_salvage_items)
var/obj/salvage_item = new salvage_item_type(T.loc)
salvage_item.pixel_x = rand(-5, 5)
salvage_item.pixel_y = rand(-5, 5)
salvage_item.scatter_atom()
max_salvage_attempts -= 1

log_startup_progress("Successfully seeded space salvage in [stop_watch(space_salvage_timer)]s.")
Expand Down
3 changes: 1 addition & 2 deletions code/datums/elements/shatters_when_thrown.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@

for(var/iteration in 1 to number_of_shards)
var/obj/item/shard = new shard_type(scatter_turf)
shard.pixel_x = rand(-6, 6)
shard.pixel_y = rand(-6, 6)
shard.scatter_atom()
playsound(scatter_turf, shattering_sound, 60, TRUE)
if(isobj(source))
var/obj/obj_source = source
Expand Down
8 changes: 8 additions & 0 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
/// Used for icon smoothing. Won't smooth if it ain't anchored and can be unanchored. Only set to true on windows
var/can_be_unanchored = FALSE

/// How far (in pixels) should this atom scatter when created/dropped/etc. Does not apply to mapped-in items.
var/scatter_distance = 0

/atom/movable/attempt_init(loc, ...)
var/turf/T = get_turf(src)
if(T && SSatoms.initialized != INITIALIZATION_INSSATOMS && GLOB.space_manager.is_zlevel_dirty(T.z))
Expand Down Expand Up @@ -1062,3 +1065,8 @@
/// useful callback for things that want special behavior on crush
/atom/movable/proc/on_crush_thing(atom/thing)
return

/// Used to scatter atoms so that multiple copies aren't all at the exact same spot.
/atom/movable/proc/scatter_atom(x_offset = 0, y_offset = 0)
pixel_x = x_offset + rand(-scatter_distance, scatter_distance)
pixel_y = y_offset + rand(-scatter_distance, scatter_distance)
3 changes: 1 addition & 2 deletions code/game/machinery/autolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@
var/obj/item/new_item = new D.build_path(BuildTurf)
new_item.materials[MAT_METAL] /= coeff
new_item.materials[MAT_GLASS] /= coeff
new_item.pixel_y = rand(-5, 5)
new_item.pixel_x = rand(-5, 5)
new_item.scatter_atom()
if(is_station_level(z))
SSblackbox.record_feedback("tally", "station_autolathe_production", 1, "[D.type]")
SStgui.update_uis(src)
Expand Down
3 changes: 1 addition & 2 deletions code/game/machinery/pipe/pipe_construction.dm
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
connect_types = list(CONNECT_TYPE_NORMAL, CONNECT_TYPE_SUPPLY, CONNECT_TYPE_SCRUBBER)

update(make_from)
pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)
scatter_atom()

//update the name and icon of the pipe item depending on the type

Expand Down
3 changes: 1 addition & 2 deletions code/game/machinery/vendors/vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,7 @@
if(put_on_turf)
var/turf/T = get_turf(src)
vended.forceMove(T)
vended.pixel_x = rand(-5, 5)
vended.pixel_y = rand(-5, 5)
vended.scatter_atom()
return TRUE
return FALSE

Expand Down
2 changes: 2 additions & 0 deletions code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ GLOBAL_DATUM_INIT(welding_sparks, /mutable_appearance, mutable_appearance('icons
/// In tiles, how far this weapon can reach; 1 for adjacent, which is default
var/reach = 1

scatter_distance = 5

/obj/item/New()
..()

Expand Down
7 changes: 3 additions & 4 deletions code/game/objects/items/random_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@
reagents.add_reagent(R, volume)
name = "unlabelled bottle"
icon_state = pick("alco-white","alco-green","alco-blue","alco-clear","alco-red")
pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)
scatter_atom()

/obj/item/storage/pill_bottle/random_meds
name = "unlabelled pillbottle"
desc = "The sheer recklessness of this bottle's existence astounds you."
allow_wrap = FALSE
var/labelled = FALSE
scatter_distance = 10

/obj/item/storage/pill_bottle/random_meds/Initialize(mapload)
. = ..()
pixel_x = rand(-10, 10)
pixel_y = rand(-10, 10)
scatter_atom()

/obj/item/storage/pill_bottle/random_meds/populate_contents()
var/list/possible_meds_standard = GLOB.standard_medicines.Copy()
Expand Down
7 changes: 5 additions & 2 deletions code/game/objects/items/stacks/sheets/mineral.dm
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ GLOBAL_LIST_INIT(snow_recipes, list(

/obj/item/stack/sheet/mineral/Initialize(mapload, new_amount, merge)
. = ..()
pixel_x = rand(0,4)-4
pixel_y = rand(0,4)-4
scatter_atom()

/obj/item/stack/sheet/mineral/scatter_atom(offset_x, offset_y)
pixel_x = rand(-4,0) + offset_x
pixel_y = rand(-4,0) + offset_y

/obj/item/stack/sheet/mineral/sandstone
name = "sandstone brick"
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/stacks/tiles/tile_types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
origin_tech = "materials=1"
var/turf_type = null
var/mineralType = null
scatter_distance = 3

/obj/item/stack/tile/Initialize(mapload, new_amount, merge)
. = ..()
pixel_x = rand(-3, 3)
pixel_y = rand(-3, 3) //randomize a little
scatter_atom()

/obj/item/stack/tile/welder_act(mob/user, obj/item/I)
if(get_amount() < 4)
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/trash.dm
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@
name = "arbitrary spent casing item"
desc = "If you can see this and didn't spawn it, make an issue report on GitHub."
icon_state = "gshell"
scatter_distance = 10

/obj/item/trash/spentcasing/Initialize(mapload)
. = ..()
pixel_x = rand(-10, 10)
pixel_y = rand(-10, 10)
scatter_atom()
transform = turn(transform, rand(0, 360))

/obj/item/trash/spentcasing/shotgun
Expand Down
12 changes: 5 additions & 7 deletions code/game/objects/items/weapons/cigs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ LIGHTERS ARE IN LIGHTERS.DM

/obj/item/clothing/mask/cigarette/rollie/Initialize(mapload)
. = ..()
pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)

scatter_atom()
/obj/item/clothing/mask/cigarette/rollie/custom
list_reagents = list()

Expand All @@ -346,11 +344,11 @@ LIGHTERS ARE IN LIGHTERS.DM
icon_state = "cigbutt"
w_class = WEIGHT_CLASS_TINY
throwforce = 1
scatter_distance = 10

/obj/item/cigbutt/Initialize(mapload)
. = ..()
pixel_x = rand(-10, 10)
pixel_y = rand(-10, 10)
scatter_atom()
transform = turn(transform, rand(0, 360))

/obj/item/cigbutt/decompile_act(obj/item/matter_decompiler/C, mob/user)
Expand All @@ -364,11 +362,11 @@ LIGHTERS ARE IN LIGHTERS.DM
name = "roach"
desc = "A manky old roach, or for non-stoners, a used rollup."
icon_state = "roach"
scatter_distance = 5

/obj/item/cigbutt/roach/Initialize(mapload)
. = ..()
pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)
scatter_atom()

//////////////////////////////
// MARK: ROLLING
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/gift_wrappaper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
icon_state = "gift1"
item_state = "gift1"
resistance_flags = FLAMMABLE
scatter_distance = 10

/obj/item/a_gift/New()
..()
pixel_x = rand(-10,10)
pixel_y = rand(-10,10)
scatter_atom()
if(w_class > 0 && w_class < 4)
icon_state = "gift[w_class]"
else
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/grenades/frag.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
w_class = WEIGHT_CLASS_SMALL
sharp = TRUE
hitsound = 'sound/weapons/pierce.ogg'
scatter_distance = 8

/obj/item/shrapnel/Initialize(mapload)
. = ..()
icon_state = pick("shrapnel1", "shrapnel2", "shrapnel3")
pixel_x = rand(-8, 8)
pixel_y = rand(-8, 8)
scatter_atom()

#undef DEFAULT_SHRAPNEL_RANGE
7 changes: 6 additions & 1 deletion code/game/objects/items/weapons/storage/storage_base.dm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
/obj/item/storage/proc/removal_allowed_check(mob/user)
return TRUE

/obj/item/storage/MouseDrop(obj/over_object)
/obj/item/storage/MouseDrop(obj/over_object, src_location, over_location, src_control, over_control, params)
if(!ismob(usr)) //so monkeys can take off their backpacks -- Urist
return
var/mob/M = usr
Expand Down Expand Up @@ -134,8 +134,12 @@
M.face_atom(over_object)
M.visible_message("<span class='notice'>[M] empties [src] onto [over_object].</span>",
"<span class='notice'>You empty [src] onto [over_object].</span>")
var/list/params_list = params2list(params)
var/x_offset = text2num(params_list["icon-x"]) - 16
var/y_offset = text2num(params_list["icon-y"]) - 16
for(var/obj/item/I in contents)
remove_from_storage(I, T)
I.scatter_atom(x_offset, y_offset)
update_icon() // For content-sensitive icons
return

Expand Down Expand Up @@ -608,6 +612,7 @@
hide_from(user)
for(var/obj/item/I in contents)
remove_from_storage(I, T)
I.scatter_atom()
CHECK_TICK

/**
Expand Down
3 changes: 1 addition & 2 deletions code/modules/fish/fish_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@

/obj/item/shard/shark_teeth/set_initial_icon_state()
icon_state = "teeth"
pixel_x = rand(-5,5)
pixel_y = rand(-5,5)
scatter_atom()

/obj/item/fish/catfish
name = "catfish"
Expand Down
3 changes: 1 addition & 2 deletions code/modules/food_and_drinks/food_base.dm
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@
for(var/i in 1 to (slices_num - slices_lost))
var/obj/slice = new slice_path (loc)
reagents.trans_to(slice,reagents_per_slice)
slice.pixel_x = rand(-7, 7)
slice.pixel_y = rand(-7, 7)
slice.scatter_atom()
qdel(src)
return ..()

Expand Down
4 changes: 2 additions & 2 deletions code/modules/hydroponics/beekeeping/honeycomb.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
volume = 10
list_reagents = list("honey" = 5)
var/honey_color = ""
scatter_distance = 8

/obj/item/food/honeycomb/Initialize(mapload)
. = ..()
pixel_x = rand(8,-8)
pixel_y = rand(8,-8)
scatter_atom()
update_icon(UPDATE_OVERLAYS)

/obj/item/food/honeycomb/update_overlays()
Expand Down
6 changes: 2 additions & 4 deletions code/modules/hydroponics/grown.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
else if(seed)
seed = new seed

pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)
scatter_atom()

if(dried_type == -1)
dried_type = type
Expand Down Expand Up @@ -92,8 +91,7 @@
for(var/i = 1 to (slices_num - slices_lost))
var/obj/slice = new slice_path (loc)
reagents.trans_to(slice, reagents_per_slice)
slice.pixel_x = rand(-7, 7)
slice.pixel_y = rand(-7, 7)
slice.scatter_atom()
qdel(src)
return ..()

Expand Down
3 changes: 1 addition & 2 deletions code/modules/hydroponics/grown/towercap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@
if(!has_buckled_mobs() && do_after(user, 50, target = src))
for(var/I in 1 to 5)
var/obj/item/grown/log/L = new /obj/item/grown/log(loc)
L.pixel_x += rand(1,4)
L.pixel_y += rand(1,4)
L.scatter_atom()
qdel(src)
return
..()
Expand Down
4 changes: 1 addition & 3 deletions code/modules/hydroponics/growninedible.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
else if(seed)
seed = new seed

pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)

scatter_atom()
if(seed)
for(var/datum/plant_gene/trait/T in seed.genes)
T.on_new(src)
Expand Down
3 changes: 1 addition & 2 deletions code/modules/hydroponics/hydroitemdefines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@

/obj/item/reagent_containers/glass/bottle/nutrient/killer/Initialize(mapload)
. = ..()
pixel_x = rand(-5, 5)
pixel_y = rand(-5, 5)
scatter_atom()

/obj/item/reagent_containers/glass/bottle/nutrient/killer/weedkiller
name = "jug of weed killer"
Expand Down
3 changes: 1 addition & 2 deletions code/modules/hydroponics/seeds.dm
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,7 @@
/obj/item/unsorted_seeds/New(obj/item/seeds/template, mutation_level, list/mutation_focus, seed_data_in = null)
..()
template = template.Copy()
pixel_x = rand(-6, 6)
pixel_y = rand(-6, 6)
scatter_atom()
if(seed_data_in)
seed_data = seed_data_in
else
Expand Down
3 changes: 1 addition & 2 deletions code/modules/mining/lavaland/ash_flora.dm
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@

/obj/item/food/grown/ash_flora/Initialize(mapload)
. = ..()
pixel_x = rand(-4, 4)
pixel_y = rand(-4, 4)
scatter_atom()

/// for actual crafting
/obj/item/food/grown/ash_flora/shavings
Expand Down
7 changes: 5 additions & 2 deletions code/modules/mining/ores_coins.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

/obj/item/stack/ore/Initialize(mapload, new_amount, merge = TRUE)
. = ..()
pixel_x = rand(0, 16) - 8
pixel_y = rand(0, 8) - 8
scatter_atom()

/obj/item/stack/ore/scatter_atom(x_offset, y_offset)
pixel_x = rand(-8, 8) + x_offset
pixel_y = rand(-8, 0) + y_offset

/obj/item/stack/ore/welder_act(mob/user, obj/item/I)
. = TRUE
Expand Down
Loading

0 comments on commit 41c236a

Please sign in to comment.