Refactors poi rotation to use degrees instead of dir

This commit is contained in:
Neerti
2019-01-12 04:26:23 -05:00
committed by Novacat
parent 42df71908b
commit ee18328ce0
5 changed files with 83 additions and 40 deletions

View File

@@ -24,7 +24,10 @@
if(rename)
name = rename
<<<<<<< HEAD
/datum/map_template/proc/preload_size(path, orientation = SOUTH)
=======
/datum/map_template/proc/preload_size(path, orientation = 0)
var/bounds = SSmapping.maploader.load_map(file(path), 1, 1, 1, cropMap=FALSE, measureOnly=TRUE, orientation=orientation)
if(bounds)
width = bounds[MAP_MAXX] // Assumes all templates are rectangular, have a single Z level, and begin at 1,1,1
@@ -69,7 +72,7 @@
admin_notice("<span class='danger'>Submap initializations finished.</span>", R_DEBUG)
/datum/map_template/proc/load_new_z(var/centered = FALSE, var/orientation = SOUTH)
/datum/map_template/proc/load_new_z(var/centered = FALSE, var/orientation = 0)
var/x = 1
var/y = 1
@@ -89,10 +92,10 @@
on_map_loaded(world.maxz) //VOREStation Edit
return TRUE
/datum/map_template/proc/load(turf/T, centered = FALSE, orientation = SOUTH)
/datum/map_template/proc/load(turf/T, centered = FALSE, orientation = 0)
var/old_T = T
if(centered)
T = locate(T.x - round(((orientation & NORTH|SOUTH) ? width : height)/2) , T.y - round(((orientation & NORTH|SOUTH) ? height : width)/2) , T.z)
T = locate(T.x - round(((orientation%180) ? height : width)/2) , T.y - round(((orientation%180) ? width : height)/2) , T.z) // %180 catches East/West (90,270) rotations on true, North/South (0,180) rotations on false
if(!T)
return
if(T.x+width > world.maxx)
@@ -117,15 +120,15 @@
loaded++
return TRUE
/datum/map_template/proc/get_affected_turfs(turf/T, centered = FALSE, orientation = SOUTH)
/datum/map_template/proc/get_affected_turfs(turf/T, centered = FALSE, orientation = 0)
var/turf/placement = T
if(centered)
var/turf/corner = locate(placement.x - round(((orientation & NORTH|SOUTH) ? width : height)/2), placement.y - round(((orientation & NORTH|SOUTH) ? height : width)/2), placement.z)
var/turf/corner = locate(placement.x - round(((orientation%180) ? height : width)/2), placement.y - round(((orientation%180) ? width : height)/2), placement.z) // %180 catches East/West (90,270) rotations on true, North/South (0,180) rotations on false
if(corner)
placement = corner
return block(placement, locate(placement.x+((orientation & NORTH|SOUTH) ? width : height)-1, placement.y+((orientation & NORTH|SOUTH) ? height : width)-1, placement.z))
return block(placement, locate(placement.x+((orientation%180) ? height : width)-1, placement.y+((orientation%180) ? width : height)-1, placement.z))
/datum/map_template/proc/annihilate_bounds(turf/origin, centered = FALSE, orientation = SOUTH)
/datum/map_template/proc/annihilate_bounds(turf/origin, centered = FALSE, orientation = 0)
var/deleted_atoms = 0
admin_notice("<span class='danger'>Annihilating objects in submap loading locatation.</span>", R_DEBUG)
var/list/turfs_to_clean = get_affected_turfs(origin, centered, orientation)
@@ -139,7 +142,7 @@
//for your ever biggening badminnery kevinz000
//❤ - Cyberboss
/proc/load_new_z_level(var/file, var/name, var/orientation = SOUTH)
/proc/load_new_z_level(var/file, var/name, var/orientation = 0)
var/datum/map_template/template = new(file, name)
template.load_new_z(orientation)
@@ -216,13 +219,13 @@
var/orientation
if(chosen_template.fixed_orientation || !config.random_submap_orientation)
orientation = SOUTH
orientation = 0
else
orientation = pick(cardinal)
orientation = pick(list(0, 90, 180, 270))
chosen_template.preload_size(chosen_template.mappath, orientation)
var/width_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(((orientation & NORTH|SOUTH) ? chosen_template.width : chosen_template.height) / 2)
var/height_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(((orientation & NORTH|SOUTH) ? chosen_template.height : chosen_template.width) / 2)
var/width_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(((orientation%180) ? chosen_template.height : chosen_template.width) / 2) // %180 catches East/West (90,270) rotations on true, North/South (0,180) rotations on false
var/height_border = TRANSITIONEDGE + SUBMAP_MAP_EDGE_PAD + round(((orientation%180) ? chosen_template.width : chosen_template.height) / 2)
var/z_level = pick(z_levels)
var/turf/T = locate(rand(width_border, world.maxx - width_border), rand(height_border, world.maxy - height_border), z_level)
var/valid = TRUE
@@ -281,4 +284,4 @@
admin_notice("Submap loader gave up with [budget] left to spend.", R_DEBUG)
else
admin_notice("Submaps loaded.", R_DEBUG)
admin_notice("Loaded: [english_list(pretty_submap_list)]", R_DEBUG)
admin_notice("Loaded: [english_list(pretty_submap_list)]", R_DEBUG)

View File

@@ -63,9 +63,9 @@ var/global/use_preloader = FALSE
if(!z_offset)
z_offset = world.maxz + 1
// If it's not a single dir, default to north (Default orientation)
if(!orientation in cardinal)
orientation = SOUTH
// If it's not a single dir, default to 0 degrees rotation (Default orientation)
if(!(orientation in list(0, 90, 180, 270)))
orientation = 0
var/list/bounds = list(1.#INF, 1.#INF, 1.#INF, -1.#INF, -1.#INF, -1.#INF)
var/list/grid_models = list()
@@ -167,12 +167,12 @@ var/global/use_preloader = FALSE
key_list[++key_list.len] = line_keys
// Rotate the list according to orientation
if(orientation != SOUTH)
if(orientation != 0)
var/num_cols = key_list[1].len
var/num_rows = key_list.len
var/list/new_key_list = list()
// If it's rotated 180 degrees, the dimensions are the same
if(orientation == NORTH)
if(orientation == 180)
new_key_list.len = num_rows
for(var/i = 1 to new_key_list.len)
new_key_list[i] = list()
@@ -190,11 +190,11 @@ var/global/use_preloader = FALSE
for(var/i = 1 to new_key_list.len)
for(var/j = 1 to new_key_list[i].len)
switch(orientation)
if(NORTH)
if(180)
new_key_list[i][j] = key_list[num_rows - i][num_cols - j]
if(EAST)
if(270)
new_key_list[i][j] = key_list[num_rows - j][i]
if(WEST)
if(90)
new_key_list[i][j] = key_list[j][num_cols - i]
key_list = new_key_list
@@ -314,12 +314,6 @@ var/global/use_preloader = FALSE
if(istext(value))
fields[I] = apply_text_macros(value)
// Rotate dir if orientation isn't south (default)
if(fields["dir"])
fields["dir"] = turn(fields["dir"], dir2angle(orientation) + 180)
else
fields["dir"] = turn(SOUTH, dir2angle(orientation) + 180)
//then fill the members_attributes list with the corresponding variables
members_attributes.len++
members_attributes[index++] = fields
@@ -380,20 +374,20 @@ var/global/use_preloader = FALSE
//instanciate the first /turf
var/turf/T
if(members[first_turf_index] != /turf/template_noop)
T = instance_atom(members[first_turf_index],members_attributes[first_turf_index],crds,no_changeturf)
T = instance_atom(members[first_turf_index],members_attributes[first_turf_index],crds,no_changeturf,orientation)
if(T)
//if others /turf are presents, simulates the underlays piling effect
index = first_turf_index + 1
while(index <= members.len - 1) // Last item is an /area
var/underlay = T.appearance
T = instance_atom(members[index],members_attributes[index],crds,no_changeturf)//instance new turf
T = instance_atom(members[index],members_attributes[index],crds,no_changeturf,orientation)//instance new turf
T.underlays += underlay
index++
//finally instance all remainings objects/mobs
for(index in 1 to first_turf_index-1)
instance_atom(members[index],members_attributes[index],crds,no_changeturf)
instance_atom(members[index],members_attributes[index],crds,no_changeturf,orientation)
//Restore initialization to the previous value
SSatoms.map_loader_stop()
@@ -402,7 +396,7 @@ var/global/use_preloader = FALSE
////////////////
//Instance an atom at (x,y,z) and gives it the variables in attributes
/dmm_suite/proc/instance_atom(path,list/attributes, turf/crds, no_changeturf)
/dmm_suite/proc/instance_atom(path,list/attributes, turf/crds, no_changeturf, orientation=0)
_preloader.setup(attributes, path)
if(crds)
@@ -420,6 +414,11 @@ var/global/use_preloader = FALSE
stoplag()
SSatoms.map_loader_begin()
// Rotate the atom now that it exists, rather than changing its orientation beforehand through the fields["dir"]
if(orientation != 0) // 0 means no rotation
var/atom/A = .
A.set_dir(turn(A.dir, orientation))
/dmm_suite/proc/create_atom(path, crds)
set waitfor = FALSE
. = new path (crds)