Skip to content

Commit

Permalink
Adds support for machinery to be bigger than 1x1 (#26531)
Browse files Browse the repository at this point in the history
* Adds big machinery

* Remove debug stuff

* Even less debug stuff

* Contra review

* Complete refactor + BSH

* Reverts `/big`

* Adds missing *

* initial

* Removes unneeded shit

* Adds edge of world edgecases

* Whoops

* Fix

* Lewc review

* Make the grav gen better

* Render passes fix

* Extra comment in the toml

* Extra deconstruct just in case

* One less loop

---------

Co-authored-by: BeagleGaming1 <[email protected]>
  • Loading branch information
DGamerL and BeagleGaming1 authored Sep 10, 2024
1 parent 33b2dc3 commit 35740a2
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 82 deletions.
2 changes: 2 additions & 0 deletions SpacemanDMM.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ hide_invisible = [

[map_renderer.render_passes]
smart-cables = false
# With the multitile component and the removal of the gravity gen parts, the gravity generator will fail the render passes
gravity-gen = false
2 changes: 1 addition & 1 deletion _maps/map_files/stations/boxstation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -68595,7 +68595,6 @@
/turf/simulated/floor/plating,
/area/station/maintenance/disposal)
"lSr" = (
/obj/machinery/gravity_generator/main/station,
/obj/effect/turf_decal/stripes/line{
dir = 10
},
Expand Down Expand Up @@ -91302,6 +91301,7 @@
/area/station/command/office/rd)
"xjh" = (
/obj/effect/turf_decal/stripes/line,
/obj/machinery/gravity_generator/main/station,
/turf/simulated/floor/plasteel{
dir = 8;
icon_state = "vault"
Expand Down
4 changes: 2 additions & 2 deletions _maps/map_files/stations/cerestation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -144582,7 +144582,7 @@ aXn
gzv
tHv
tHv
bII
tHv
xpg
kBo
vPy
Expand Down Expand Up @@ -144839,7 +144839,7 @@ aXn
gzv
tHv
tHv
tHv
bII
pnV
aWx
sJs
Expand Down
6 changes: 3 additions & 3 deletions _maps/map_files/stations/deltastation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -28050,7 +28050,7 @@
"bEG" = (
/obj/machinery/gravity_generator/main/station,
/turf/simulated/floor/plasteel{
dir = 1;
dir = 8;
icon_state = "vault"
},
/area/station/engineering/gravitygenerator)
Expand Down Expand Up @@ -119468,7 +119468,7 @@ bwN
bzE
bBi
bBj
bEG
bBi
bGB
bwN
abj
Expand Down Expand Up @@ -119725,7 +119725,7 @@ bwN
bzE
bBj
bDc
bBj
bEG
bzE
bwN
abj
Expand Down
6 changes: 3 additions & 3 deletions _maps/map_files/stations/metastation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@
"aqh" = (
/obj/machinery/gravity_generator/main/station,
/turf/simulated/floor/plasteel{
dir = 4;
dir = 8;
icon_state = "vault"
},
/area/station/engineering/gravitygenerator)
Expand Down Expand Up @@ -134896,7 +134896,7 @@ abq
amk
anl
aoJ
aqh
ann
aGt
nHi
avR
Expand Down Expand Up @@ -135153,7 +135153,7 @@ abq
amk
apJ
ank
aoJ
aqh
ccM
asQ
avV
Expand Down
3 changes: 3 additions & 0 deletions code/__DEFINES/misc_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
#define STAGE_FIVE 9
#define STAGE_SIX 11 //From supermatter shard

/// A define for the center of the coordinate map of big machinery
#define MACH_CENTER 0

#define in_range(source, user) (get_dist(source, user) <= 1)

#define RANGE_TURFS(RADIUS, CENTER) \
Expand Down
61 changes: 61 additions & 0 deletions code/datums/components/multitile.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
///Lets multitile objects have dense walls around them based on the coordinate map
/datum/component/multitile
///Reference to all fillers
var/list/all_fillers = list()

/*
* These should all be done in this style. It represents a coordinate map of the grid around `src`.
* The src itself should always have no density, as the density should be set on the atom and not with a filler
* list(
list(0, 0, 0, 0, 0),
list(0, 0, 0, 0, 0),
list(0, 0, MACH_CENTER, 0, 0),
list(0, 0, 0, 0, 0),
list(0, 0, 0, 0, 0)
)
*/

//distance_from_center does not include src itself
/datum/component/multitile/Initialize(distance_from_center, new_filler_map)
if(!distance_from_center || !length(new_filler_map))
return COMPONENT_INCOMPATIBLE

if(!isatom(parent))
return COMPONENT_INCOMPATIBLE

var/atom/owner = parent
if(owner.x + distance_from_center > world.maxx || owner.x - distance_from_center < 1)
var/obj/machinery/machine = parent
machine.deconstruct()
return COMPONENT_INCOMPATIBLE

if(owner.y + distance_from_center > world.maxy || owner.y - distance_from_center < 1)
var/obj/machinery/machine = parent
machine.deconstruct()
return COMPONENT_INCOMPATIBLE

var/max_height = length(new_filler_map)
var/max_width = length(new_filler_map[1]) //it should have the same length on every row
for(var/i in 2 to length(new_filler_map))
var/length = length(new_filler_map[i])
if(length != max_width)
stack_trace("A multitile component was passed a list wich did not have the same length every row. Atom parent is: [parent]")
var/obj/machinery/machine = parent
machine.deconstruct()
return COMPONENT_INCOMPATIBLE

var/current_height = 0
var/current_width = 0

for(var/turf/filler_turf as anything in RANGE_TURFS(distance_from_center, owner))
if(new_filler_map[max_height - current_height][max_width - current_width]) // Because the `block()` proc always works from the bottom left to the top right, we have to loop through our nested lists in reverse
var/obj/structure/filler/new_filler = new(filler_turf)
all_fillers += new_filler
current_width += 1
if(current_width == max_width)
current_height += 1
current_width = 0

/datum/component/multitile/Destroy(force, silent)
QDEL_LIST_CONTENTS(all_fillers)
return ..()
34 changes: 7 additions & 27 deletions code/modules/power/gravitygenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GLOBAL_LIST_EMPTY(gravity_generators)
name = "gravitational generator"
desc = "A device which produces a graviton field when set up."
icon = 'icons/obj/machines/gravity_generator.dmi'
pixel_x = -32
anchored = TRUE
density = TRUE
power_state = NO_POWER_USE
Expand Down Expand Up @@ -51,26 +52,23 @@ GLOBAL_LIST_EMPTY(gravity_generators)
/obj/machinery/gravity_generator/proc/set_fix()
stat &= ~BROKEN

//
// Part generator which is mostly there for collision
//

/obj/machinery/gravity_generator/part
invisibility = INVISIBILITY_ABSTRACT

//
// Generator which spawns with the station.
//

/obj/machinery/gravity_generator/main/station/Initialize(mapload)
. = ..()
setup_parts()
AddComponent(/datum/component/multitile, 1, list(
list(1, 1, 1),
list(1, MACH_CENTER, 1),
list(0, 0, 0),
))
update_gen_list()
set_power()

//
// Main Generator with the main code
//
// With the multitile component it's dubious to still have this and not merge it with the `/obj/machinery/gravity_generator` itself

/obj/machinery/gravity_generator/main
icon_state = "generator_body"
Expand All @@ -82,8 +80,6 @@ GLOBAL_LIST_EMPTY(gravity_generators)
var/on = TRUE
/// Is the breaker switch turned on
var/breaker_on = TRUE
/// Generator parts on adjacent tiles
var/list/parts = list()
/// Charging state (Idle, Charging, Discharging)
var/charging_state = GRAV_POWER_IDLE
/// Charge percentage
Expand Down Expand Up @@ -111,29 +107,13 @@ GLOBAL_LIST_EMPTY(gravity_generators)
investigate_log("was destroyed!", "gravity")
on = FALSE
update_gen_list()
for(var/obj/machinery/gravity_generator/part/O in parts)
qdel(O)
for(var/area/A in world)
if(!is_station_level(A.z))
continue
A.gravitychange(FALSE, A)
shake_everyone()
return ..()

/obj/machinery/gravity_generator/main/proc/setup_parts()
var/turf/our_turf = get_turf(src)
// 9x9 block obtained from the bottom left of the block
var/list/spawn_turfs = block(our_turf.x + 2, our_turf.y + 2, our_turf.z, our_turf.x, our_turf.y, our_turf.z)
var/count = 10
for(var/turf/T in spawn_turfs)
count--
if(T == our_turf) // Main body, skip it
continue
var/obj/machinery/gravity_generator/part/part = new(T)
if(count <= 3) // That section is the top part of the generator
part.density = FALSE
parts += part

/obj/machinery/gravity_generator/main/set_broken()
..()
charging_state = GRAV_POWER_IDLE
Expand Down
32 changes: 10 additions & 22 deletions code/modules/station_goals/bluespace_tap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
max_integrity = 300
pixel_x = -32 //shamelessly stolen from dna vault
pixel_y = -32
/// For faking having a big machine, dummy 'machines' that are hidden inside the large sprite and make certain tiles dense. See new and destroy.
var/list/obj/structure/fillers = list()
power_state = NO_POWER_USE // power usage is handelled manually
density = TRUE
interact_offline = TRUE
Expand Down Expand Up @@ -227,7 +225,6 @@
/// How much power the machine needs per processing tick at the current level.
var/actual_power_usage = 0


// Tweak these and active_power_consumption to balance power generation

/// Max power input level, I don't expect this to be ever reached. It has been reached.
Expand All @@ -251,24 +248,20 @@

/obj/machinery/power/bluespace_tap/Initialize(mapload)
. = ..()
//more code stolen from dna vault, inculding comment below. Taking bets on that datum being made ever.
//TODO: Replace this,bsa and gravgen with some big machinery datum
var/list/occupied = list()
for(var/direct in list(NORTH, NORTHEAST, NORTHWEST, EAST, WEST, SOUTHEAST, SOUTHWEST))
occupied += get_step(src, direct)

for(var/T in occupied)
var/obj/structure/filler/F = new(T)
F.parent = src
fillers += F
component_parts = list()
component_parts += new /obj/item/circuitboard/machine/bluespace_tap(null)
for(var/i = 1 to 5) //five of each
component_parts += new /obj/item/stock_parts/capacitor/quadratic(null)
component_parts += new /obj/item/stack/ore/bluespace_crystal(null)
component_parts += new /obj/item/circuitboard/machine/bluespace_tap()
for(var/i in 1 to 5) //five of each
component_parts += new /obj/item/stock_parts/capacitor/quadratic()
component_parts += new /obj/item/stack/ore/bluespace_crystal()
if(!powernet)
connect_to_network()

AddComponent(/datum/component/multitile, 1, list(
list(1, 1, 1),
list(1, MACH_CENTER, 1),
list(1, 0, 1),
))

/obj/machinery/power/bluespace_tap/update_icon_state()
. = ..()

Expand Down Expand Up @@ -302,7 +295,6 @@
if(light)
underlays += emissive_appearance(icon, "light_mask")


/obj/machinery/power/bluespace_tap/proc/get_icon_state_number()
switch(input_level)
if(0)
Expand Down Expand Up @@ -338,10 +330,6 @@
if(.)
update_icon()

/obj/machinery/power/bluespace_tap/Destroy()
QDEL_LIST_CONTENTS(fillers)
return ..()

/**
* Increases the desired mining level
*
Expand Down
31 changes: 7 additions & 24 deletions code/modules/station_goals/dna_vault.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ GLOBAL_LIST_INIT(non_simple_animals, typecacheof(list(/mob/living/carbon/human/m
density = TRUE
anchored = TRUE
invisibility = 101
var/obj/machinery/parent

/obj/structure/filler/Destroy()
parent = null
return ..()

/obj/structure/filler/ex_act()
return
Expand Down Expand Up @@ -166,29 +161,22 @@ GLOBAL_LIST_INIT(non_simple_animals, typecacheof(list(/mob/living/carbon/human/m
var/completed = FALSE
var/static/list/power_lottery = list()

var/list/obj/structure/fillers = list()

/obj/machinery/dna_vault/Initialize(mapload)
. = ..()
//TODO: Replace this,bsa and gravgen with some big machinery datum
var/list/occupied = list()
for(var/direct in list(EAST,WEST,SOUTHEAST,SOUTHWEST))
occupied += get_step(src,direct)
occupied += locate(x+1,y-2,z)
occupied += locate(x-1,y-2,z)

for(var/T in occupied)
var/obj/structure/filler/F = new(T)
F.parent = src
fillers += F

if(SSticker.mode)
for(var/datum/station_goal/dna_vault/G in SSticker.mode.station_goals)
animals_max = G.animal_count
plants_max = G.plant_count
dna_max = G.human_count
break

AddComponent(/datum/component/multitile, 2, list(
list(0, 0, 0, 0, 0),
list(0, 0, 0, 0, 0),
list(0, 1, MACH_CENTER, 1, 0),
list(0, 1, 0, 1, 0),
list(0, 1, 0, 1, 0)
))
/obj/machinery/dna_vault/update_icon_state()
if(stat & NOPOWER)
icon_state = "vaultoff"
Expand All @@ -200,11 +188,6 @@ GLOBAL_LIST_INIT(non_simple_animals, typecacheof(list(/mob/living/carbon/human/m
return
update_icon(UPDATE_ICON_STATE)


/obj/machinery/dna_vault/Destroy()
QDEL_LIST_CONTENTS(fillers)
return ..()

/obj/machinery/dna_vault/attack_ghost(mob/user)
if(stat & (BROKEN|MAINT))
return
Expand Down
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
#include "code\datums\components\label.dm"
#include "code\datums\components\largeobjecttransparency.dm"
#include "code\datums\components\material_container.dm"
#include "code\datums\components\multitile.dm"
#include "code\datums\components\orbiter.dm"
#include "code\datums\components\paintable.dm"
#include "code\datums\components\parry.dm"
Expand Down

0 comments on commit 35740a2

Please sign in to comment.