Allows multitile to work with arbitrary list lengths (#26801)

* multitile now works with any shape of lists and the fillers are built relative to MACH_CENTER

* Iterates over each nested loop from left to right and correctly applies offsets

* Restricts list length to all be the same

* removes slashes from multiline argument in block and replaces a magic number with the appropriate define.
This commit is contained in:
Migratingcocofruit
2024-10-02 15:17:21 +00:00
committed by GitHub
parent e5320b5702
commit 54e35bcf2a
5 changed files with 46 additions and 30 deletions
+1 -1
View File
@@ -105,7 +105,7 @@
#define STAGE_SIX 11 //From supermatter shard
/// A define for the center of the coordinate map of big machinery
#define MACH_CENTER 0
#define MACH_CENTER 2
#define in_range(source, user) (get_dist(source, user) <= 1)
+42 -23
View File
@@ -16,45 +16,64 @@
*/
//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))
/datum/component/multitile/Initialize(new_filler_map)
if(!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)
var/offset_x = 0
var/offset_y = 0
var/atom/owner = parent
for(var/i in 1 to length(new_filler_map))
if(length(new_filler_map[i] != 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/j in 1 to length(new_filler_map[i]))
if(new_filler_map[i][j] == MACH_CENTER)
offset_x = j - ((length(new_filler_map[i]) + 1) / 2)
offset_y = i - ((length(new_filler_map) + 1) / 2)
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/distance_from_center_x = (max_width - 1) / 2
var/distance_from_center_y = (max_height - 1) / 2
if(owner.x - offset_x + distance_from_center_x > world.maxx || owner.x + offset_x - distance_from_center_x < 1)
var/obj/machinery/machine = parent
machine.deconstruct()
return COMPONENT_INCOMPATIBLE
if(owner.y + offset_y + distance_from_center_y > world.maxy || owner.y - offset_y - distance_from_center_y < 1)
var/obj/machinery/machine = parent
machine.deconstruct()
return COMPONENT_INCOMPATIBLE
var/current_height = 0
var/current_width = 1
var/tile_index = 1
for(var/turf/filler_turf as anything in block(
owner.x - offset_x - distance_from_center_x, owner.y + offset_y - distance_from_center_y, owner.z,
owner.x - offset_x + distance_from_center_x, owner.y + offset_y + distance_from_center_y, owner.z,
))
//Last check is for filler row lists of length 1.
if(new_filler_map[max_height - current_height][current_width] == 1) // Because the `block()` proc always works from the bottom left to the top right, we have to loop through our list in reverse
var/obj/structure/filler/new_filler = new(filler_turf)
all_fillers += new_filler
current_width += 1
if(current_width == max_width)
tile_index++
if(tile_index % max_width == 1)
current_height += 1
current_width = 0
current_width = 1
if(current_height == max_height)
break
/datum/component/multitile/Destroy(force, silent)
QDEL_LIST_CONTENTS(all_fillers)
+1 -2
View File
@@ -58,10 +58,9 @@ GLOBAL_LIST_EMPTY(gravity_generators)
/obj/machinery/gravity_generator/main/station/Initialize(mapload)
. = ..()
AddComponent(/datum/component/multitile, 1, list(
AddComponent(/datum/component/multitile, list(
list(1, 1, 1),
list(1, MACH_CENTER, 1),
list(0, 0, 0),
))
update_gen_list()
set_power()
+1 -1
View File
@@ -256,7 +256,7 @@
if(!powernet)
connect_to_network()
AddComponent(/datum/component/multitile, 1, list(
AddComponent(/datum/component/multitile, list(
list(1, 1, 1),
list(1, MACH_CENTER, 1),
list(1, 0, 1),
+1 -3
View File
@@ -170,9 +170,7 @@ GLOBAL_LIST_INIT(non_simple_animals, typecacheof(list(/mob/living/carbon/human/m
dna_max = G.human_count
break
AddComponent(/datum/component/multitile, 2, list(
list(0, 0, 0, 0, 0),
list(0, 0, 0, 0, 0),
AddComponent(/datum/component/multitile, list(
list(0, 1, MACH_CENTER, 1, 0),
list(0, 1, 0, 1, 0),
list(0, 1, 0, 1, 0)