Skip to content

Commit

Permalink
Refactors weapon racks and armory spawners, as well as fixing every w…
Browse files Browse the repository at this point in the history
…ide gun being too far to the right on weapon racks (weapon rack resprite as a treat) (#1624)

* man why was rotating on the guns themselves

* armory spawns *shakes fist*

* fix

* should make the pixel thing actually work

* i know what's happening here

* makes it handle being picked up, too

Co-authored-by: Paxilmaniac <[email protected]>
  • Loading branch information
Steals-The-PRs and Paxilmaniac authored Jan 21, 2024
1 parent b82d01d commit 52ef800
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 68 deletions.
47 changes: 0 additions & 47 deletions modular_nova/modules/aesthetics/rack/code/rack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,3 @@
desc = "A shelf, for storing things on. Conveinent!"
icon = 'modular_nova/modules/aesthetics/rack/icons/rack.dmi'
icon_state = "shelf"

/obj/item/gun
var/on_rack = FALSE

/obj/item/gun/proc/place_on_rack()
on_rack = TRUE
var/matrix/M = matrix()
M.Turn(-90)
transform = M

/obj/item/gun/proc/remove_from_rack()
if(on_rack)
var/matrix/M = matrix()
transform = M
on_rack = FALSE

/obj/item/gun/pickup(mob/user)
. = ..()
remove_from_rack()

/obj/structure/rack/gunrack
name = "gun rack"
desc = "A gun rack for storing guns."
icon_state = "gunrack"

/obj/structure/rack/gunrack/Initialize(mapload)
. = ..()
if(mapload)
for(var/obj/item/I in loc.contents)
if(istype(I, /obj/item/gun))
var/obj/item/gun/to_place = I
to_place.place_on_rack()

/obj/structure/rack/gunrack/attackby(obj/item/W, mob/living/user, params)
var/list/modifiers = params2list(params)
if (W.tool_behaviour == TOOL_WRENCH && !(obj_flags & NO_DECONSTRUCTION) && LAZYACCESS(modifiers, RIGHT_CLICK))
W.play_tool_sound(src)
deconstruct(TRUE)
return
if(user.combat_mode)
return ..()
if(user.transferItemToLoc(W, drop_location()))
if(istype(W, /obj/item/gun))
var/obj/item/gun/our_gun = W
our_gun.place_on_rack()
our_gun.pixel_x = rand(-10, 10)
return TRUE
58 changes: 58 additions & 0 deletions modular_nova/modules/modular_weapons/code/gun_racks.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/obj/structure/rack/gunrack
name = "gun rack"
desc = "A tall rack for storing guns."
icon = 'modular_nova/modules/modular_weapons/icons/gun_rack.dmi'
icon_state = "gunrack"

/obj/structure/rack/gunrack/Initialize(mapload)
. = ..()
var/static/list/loc_connections = list(
COMSIG_ATOM_EXIT = PROC_REF(on_exit),
)
AddElement(/datum/element/connect_loc, loc_connections)
if(!mapload)
return
for(var/obj/item/found_item in loc.contents)
if(!isgun(found_item))
continue
rotate_weapon(found_item)

/obj/structure/rack/gunrack/attackby(obj/item/attacking_item, mob/living/user, params)
var/list/modifiers = params2list(params)
if(attacking_item.tool_behaviour == TOOL_WRENCH && !(obj_flags & NO_DECONSTRUCTION) && LAZYACCESS(modifiers, RIGHT_CLICK))
attacking_item.play_tool_sound(src)
deconstruct(TRUE)
return
if(user.combat_mode)
return ..()
if(user.transferItemToLoc(attacking_item, drop_location()))
if(istype(attacking_item, /obj/item/gun))
var/obj/item/gun/our_gun = attacking_item
rotate_weapon(our_gun)
our_gun.pixel_x = rand(-10, 10) + our_gun.base_pixel_x
return TRUE

/// Rotates the weapon or resets its transform based on the being_removed variable
/obj/structure/rack/gunrack/proc/rotate_weapon(obj/item/incoming_weapon, being_removed = FALSE)
var/matrix/new_matrix = matrix()
if(!being_removed)
new_matrix.Turn(-90)
incoming_weapon.transform = new_matrix
RegisterSignal(incoming_weapon, COMSIG_ITEM_EQUIPPED, PROC_REF(item_picked_up))

/// Checks when something is leaving our turf, if its a gun then make sure to reset its transform so its not permanently rotated
/obj/structure/rack/gunrack/proc/on_exit(datum/source, atom/movable/leaving, direction)
SIGNAL_HANDLER

if(!isgun(leaving))
return
var/obj/item/leaving_item = leaving
rotate_weapon(leaving_item, TRUE)

/// Handles the guns being picked up to unrotate them
/obj/structure/rack/gunrack/proc/item_picked_up(datum/source, mob/equipper, slot)
SIGNAL_HANDLER

var/obj/item/leaving_item = source
rotate_weapon(leaving_item, TRUE)
UnregisterSignal(leaving_item, COMSIG_ITEM_EQUIPPED)
Binary file not shown.
51 changes: 30 additions & 21 deletions modular_nova/modules/sec_haul/code/guns/armory_spawns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,36 @@
/obj/effect/spawner/armory_spawn/Initialize(mapload)
. = ..()

if(guns)
var/gun_count = 0
var/offset_percent = 20 / guns.len
for(var/gun in guns) // 11/20/21: Gun spawners now spawn 1 of each gun in it's list no matter what, so as to reduce the RNG of the armory stock.
var/obj/item/gun/spawned_gun = new gun(loc)

if(vertical_guns)
spawned_gun.place_on_rack()
spawned_gun.pixel_x = -10 + (offset_percent * gun_count)
else if (fan_out_items)
spawned_gun.pixel_x = spawned_gun.pixel_y = ((!(gun_count%2)*gun_count/2)*-1)+((gun_count%2)*(gun_count+1)/2*1)

gun_count++

if(istype(spawned_gun, /obj/item/gun/ballistic))
var/obj/item/gun/ballistic/spawned_ballistic_gun = spawned_gun
if(spawned_ballistic_gun.magazine && !istype(spawned_ballistic_gun.magazine, /obj/item/ammo_box/magazine/internal))
var/obj/item/storage/box/ammo_box/spawned_box = new(loc)
spawned_box.name = "ammo box - [spawned_ballistic_gun.name]"
for(var/i in 1 to mags_to_spawn)
new spawned_ballistic_gun.spawn_magazine_type (spawned_box)
if(!guns)
return

var/obj/structure/rack/gunrack/rack_on_tile
for(var/obj/structure/rack/gunrack/found_rack in loc.contents)
rack_on_tile = found_rack
break

var/gun_count = 0
var/offset_percent = 20 / guns.len
for(var/gun in guns) // 11/20/21: Gun spawners now spawn 1 of each gun in it's list no matter what, so as to reduce the RNG of the armory stock.
var/obj/item/gun/spawned_gun = new gun(loc)

if(vertical_guns && rack_on_tile)
rack_on_tile.rotate_weapon(spawned_gun)
spawned_gun.pixel_x = -10 + (offset_percent * gun_count) + spawned_gun.base_pixel_x
else if (fan_out_items)
spawned_gun.pixel_x = spawned_gun.pixel_y = ((!(gun_count%2)*gun_count/2)*-1)+((gun_count%2)*(gun_count+1)/2*1)

gun_count++

if(!istype(spawned_gun, /obj/item/gun/ballistic))
continue

var/obj/item/gun/ballistic/spawned_ballistic_gun = spawned_gun
if(spawned_ballistic_gun.magazine && !istype(spawned_ballistic_gun.magazine, /obj/item/ammo_box/magazine/internal))
var/obj/item/storage/box/ammo_box/spawned_box = new(loc)
spawned_box.name = "ammo box - [spawned_ballistic_gun.name]"
for(var/i in 1 to mags_to_spawn)
new spawned_ballistic_gun.spawn_magazine_type(spawned_box)

/obj/effect/spawner/armory_spawn/shotguns
guns = list(
Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -7691,6 +7691,7 @@
#include "modular_nova\modules\modular_weapons\code\conversion_kits.dm"
#include "modular_nova\modules\modular_weapons\code\energy.dm"
#include "modular_nova\modules\modular_weapons\code\gun_launches_little_guys_element.dm"
#include "modular_nova\modules\modular_weapons\code\gun_racks.dm"
#include "modular_nova\modules\modular_weapons\code\gunsets.dm"
#include "modular_nova\modules\modular_weapons\code\melee.dm"
#include "modular_nova\modules\modular_weapons\code\modular_projectiles.dm"
Expand Down

0 comments on commit 52ef800

Please sign in to comment.