Random map generator fixes, cleanup

This commit is contained in:
Zuhayr
2015-08-02 21:06:16 +09:30
parent 0d7b2570db
commit dd41dfa16a
4 changed files with 24 additions and 23 deletions

View File

@@ -7,7 +7,7 @@
for(var/x = 1, x <= limit_x, x++)
for(var/y = 1, y <= limit_y, y++)
var/current_cell = get_map_cell(x,y)
if(!within_bounds(current_cell))
if(!current_cell)
continue
if(x == 1 || y == 1 || x == limit_x || y == limit_y)
map[current_cell] = WALL_CHAR
@@ -19,7 +19,7 @@
for(var/x = 1, x <= limit_x, x++)
for(var/y = 1, y <= limit_y, y++)
var/current_cell = get_map_cell(x,y)
if(!within_bounds(current_cell))
if(!current_cell)
continue
if(!(x == 1 || y == 1 || x == limit_x || y == limit_y))
continue

View File

@@ -38,8 +38,8 @@
/datum/random_map/noise/ore/apply_to_turf(var/x,var/y)
var/tx = (origin_x+(x-1))*chunk_size
var/ty = (origin_y+(y-1))*chunk_size
var/tx = ((origin_x-1)+x)*chunk_size
var/ty = ((origin_y-1)+y)*chunk_size
for(var/i=0,i<chunk_size,i++)
for(var/j=0,j<chunk_size,j++)

View File

@@ -41,9 +41,7 @@ var/global/list/map_count = list()
random_maps[name] = src
// Get origins for applying the map later.
origin_x = (!isnull(tx) ? tx : 1)
origin_y = (!isnull(ty) ? ty : 1)
origin_z = (!isnull(tz) ? tz : 1)
set_origins(tx, ty, tz)
if(tlx) limit_x = tlx
if(tly) limit_y = tly
@@ -69,6 +67,8 @@ var/global/list/map_count = list()
if(!do_not_announce) admin_notice("<span class='danger'>[capitalize(name)] failed to generate ([round(0.1*(world.timeofday-start_time),0.1)] seconds): could not produce sane map.</span>", R_DEBUG)
/datum/random_map/proc/get_map_cell(var/x,var/y)
if(!islist(map))
set_map_size()
var/cell = ((y-1)*limit_x)+x
if((cell < 1) || (cell > map.len))
return null
@@ -103,16 +103,11 @@ var/global/list/map_count = list()
for(var/x = 1, x <= limit_x, x++)
for(var/y = 1, y <= limit_y, y++)
var/current_cell = get_map_cell(x,y)
if(within_bounds(current_cell))
if(current_cell)
dat += get_map_char(map[current_cell])
dat += "<br>"
user << "[dat]+------+</code>"
/datum/random_map/proc/within_bounds(var/val)
if(!islist(map))
set_map_size()
return (val>0) && (val<=map.len)
/datum/random_map/proc/set_map_size()
map = list()
map.len = limit_x * limit_y
@@ -148,21 +143,26 @@ var/global/list/map_count = list()
/datum/random_map/proc/check_map_sanity()
return 1
/datum/random_map/proc/apply_to_map(var/tx, var/ty, var/tz)
if(!tx) tx = isnull(origin_x) ? 1 : origin_x
if(!ty) ty = isnull(origin_y) ? 1 : origin_y
if(!tz) tz = isnull(origin_z) ? 1 : origin_z
/datum/random_map/proc/set_origins(var/tx, var/ty, var/tz)
origin_x = tx ? tx : 1
origin_y = ty ? ty : 1
origin_z = tz ? tz : 1
/datum/random_map/proc/apply_to_map()
if(!origin_x) origin_x = 1
if(!origin_y) origin_y = 1
if(!origin_z) origin_z = 1
for(var/x = 1, x <= limit_x, x++)
for(var/y = 1, y <= limit_y, y++)
if(!priority_process) sleep(-1)
apply_to_turf((tx-1)+x,(ty-1)+y,tz)
apply_to_turf(x,y)
/datum/random_map/proc/apply_to_turf(var/x,var/y,var/z)
/datum/random_map/proc/apply_to_turf(var/x,var/y)
var/current_cell = get_map_cell(x,y)
if(!within_bounds(current_cell))
if(!current_cell)
return 0
var/turf/T = locate(x,y,z)
var/turf/T = locate((origin_x-1)+x,(origin_y-1)+y,origin_z)
if(!T || (target_turf_type && !istype(T,target_turf_type)))
return 0
var/newpath = get_appropriate_path(map[current_cell])
@@ -193,7 +193,7 @@ var/global/list/map_count = list()
for(var/x = 1, x <= limit_x, x++)
for(var/y = 1, y <= limit_y, y++)
var/current_cell = get_map_cell(x,y)
if(!within_bounds(current_cell))
if(!current_cell)
continue
if(tx+x > target_map.limit_x)
continue

View File

@@ -75,7 +75,8 @@
tz = !isnull(tz) ? tz : T.z
message_admins("[key_name_admin(usr)] has applied [M.name] at x[tx],y[ty],z[tz].")
log_admin("[key_name(usr)] has applied [M.name] at x[tx],y[ty],z[tz].")
M.apply_to_map(tx,ty,tz)
M.set_origins(tx,ty,tz)
M.apply_to_map()
/client/proc/overlay_random_map()
set category = "Debug"