Merge pull request #4150 from Tastyfish/away-reorder

Updates maploader code to be in line with tg's, startup improvements
This commit is contained in:
Fox McCloud
2016-04-11 19:41:22 -04:00
21 changed files with 373 additions and 313 deletions
+3 -1
View File
@@ -151,7 +151,9 @@ var/list/admin_verbs_debug = list(
/client/proc/test_movable_UI,
/client/proc/test_snap_UI,
/client/proc/cinematic,
/proc/machine_upgrade
/proc/machine_upgrade,
/client/proc/map_template_load,
/client/proc/map_template_upload
)
var/list/admin_verbs_possess = list(
/proc/possess,
@@ -0,0 +1,45 @@
/client/proc/map_template_load()
set category = "Debug"
set name = "Map Template - Place"
if(!holder)
return
var/datum/map_template/template
var/map = input(usr, "Choose a Map Template to place at your CURRENT LOCATION","Place Map Template") as null|anything in map_templates
if(!map)
return
template = map_templates[map]
var/turf/T = get_turf(mob)
if(!T)
return
var/list/preview = list()
for(var/S in template.get_affected_turfs(T,centered = TRUE))
preview += image('icons/turf/overlays.dmi',S,"greenOverlay")
usr.client.images += preview
if(alert(usr,"Confirm location.","Template Confirm","Yes","No") == "Yes")
template.load(T, centered = TRUE)
message_admins("[key_name_admin(usr)] has placed a map template ([template.name]) at <A HREF='?_src_=holder;adminplayerobservecoodjump=1;X=[T.x];Y=[T.y];Z=[T.z]'>(JMP)</A>")
usr.client.images -= preview
/client/proc/map_template_upload()
set category = "Debug"
set name = "Map Template - Upload"
if(!holder)
return
var/map = input(usr, "Choose a Map Template to upload to template storage","Upload Map Template") as null|file
if(!map)
return
if(copytext("[map]",-4) != ".dmm")
usr << "Bad map file: [map]"
return
var/datum/map_template/M = new(map=map, rename="[map]")
M.preload_size(map)
map_templates[M.name] = M
message_admins("[key_name_admin(usr)] has uploaded a map template ([map])")
@@ -53,7 +53,7 @@ dmm_suite{
*/
verb/load_map(var/dmm_file as file, var/z_offset as num){
verb/load_map(var/dmm_file as file, var/x_offset as num, var/y_offset as num, var/z_offset as num, do_sleep as num){
// dmm_file: A .dmm file to load (Required).
// z_offset: A number representing the z-level on which to start loading the map (Optional).
}
+78 -51
View File
@@ -3,7 +3,8 @@
//////////////////////////////////////////////////////////////
//global datum that will preload variables on atoms instanciation
var/global/dmm_suite/preloader/_preloader = null
var/global/use_preloader = FALSE
var/global/dmm_suite/preloader/_preloader = new
/**
@@ -16,9 +17,9 @@ var/global/dmm_suite/preloader/_preloader = null
* 2) Read the map line by line, parsing the result (using parse_grid)
*
*/
/dmm_suite/load_map(var/dmm_file as file, var/z_offset as num)
/dmm_suite/load_map(dmm_file as file, x_offset = 0 as num, y_offset = 0 as num, z_offset as num, do_sleep = 1 as num)
if(!z_offset)//what z_level we are creating the map on
z_offset = world.maxz+1
z_offset = world.maxz + 1
var/quote = ascii2text(34)
var/tfile = file2text(dmm_file)//the map file we're creating
@@ -39,7 +40,8 @@ var/global/dmm_suite/preloader/_preloader = null
var/model_key = copytext(tline,2,2+key_len)
var/model_contents = copytext(tline,findtext(tfile,"=")+3,length(tline))
grid_models[model_key] = model_contents
sleep(-1)
if(do_sleep)
sleep(-1)
///////////////////////////////////////////////////////////////////////////////////////
//now let's fill the map with turf and objects using the constructed model map
@@ -47,8 +49,8 @@ var/global/dmm_suite/preloader/_preloader = null
//position of the currently processed square
var/zcrd=-1
var/ycrd=0
var/xcrd=0
var/ycrd=y_offset
var/xcrd=x_offset
for(var/zpos=findtext(tfile,"\n(1,1,",lpos,0);zpos!=0;zpos=findtext(tfile,"\n(1,1,",zpos+1,0)) //in case there's several maps to load
@@ -60,8 +62,9 @@ var/global/dmm_suite/preloader/_preloader = null
//if exceeding the world max x or y, increase it
var/x_depth = length(copytext(zgrid,1,findtext(zgrid,"\n",2,0)))
if(world.maxx<x_depth)
world.maxx=x_depth
var/x_tilecount = x_depth/key_len
if(world.maxx<x_tilecount)
world.maxx=x_tilecount
var/y_depth = z_depth / (x_depth+1)//x_depth + 1 because we're counting the '\n' characters in z_depth
if(world.maxy<y_depth)
@@ -75,23 +78,25 @@ var/global/dmm_suite/preloader/_preloader = null
//fill the current square using the model map
xcrd=0
for(var/mpos=1;mpos<=x_depth;mpos+=key_len)
for(var/mpos in 1 to x_depth step key_len)
xcrd++
var/model_key = copytext(grid_line,mpos,mpos+key_len)
parse_grid(grid_models[model_key],xcrd,ycrd,zcrd+z_offset)
parse_grid(grid_models[model_key], xcrd + x_offset, ycrd + y_offset, zcrd + z_offset, do_sleep)
//reached end of current map
if(gpos+x_depth+1>z_depth)
break
ycrd--
sleep(-1)
if(do_sleep)
sleep(-1)
//reached End Of File
if(findtext(tfile,quote+"}",zpos,0)+2==tfile_len)
break
sleep(-1)
if(do_sleep)
sleep(-1)
/**
* Fill a given tile with its area/turf/objects/mobs
@@ -110,7 +115,7 @@ var/global/dmm_suite/preloader/_preloader = null
* 4) Instanciates the atom with its variables
*
*/
/dmm_suite/proc/parse_grid(var/model as text,var/xcrd as num,var/ycrd as num,var/zcrd as num)
/dmm_suite/proc/parse_grid(model as text, xcrd as num, ycrd as num, zcrd as num, do_sleep = 1)
/*Method parse_grid()
- Accepts a text string containing a comma separated list of type paths of the
same construction as those contained in a .dmm file, and instantiates them.
@@ -143,13 +148,14 @@ var/global/dmm_suite/preloader/_preloader = null
var/variables_start = findtext(full_def,"{")
if(variables_start)//if there's any variable
full_def = copytext(full_def,variables_start+1,length(full_def))//removing the last '}'
fields = dmm_splittext(full_def,";")
fields = readlist(full_def, ";")
//then fill the members_attributes list with the corresponding variables
members_attributes.len++
members_attributes[index++] = fields
sleep(-1)
if(do_sleep)
sleep(-1)
while(dpos != 0)
@@ -165,15 +171,17 @@ var/global/dmm_suite/preloader/_preloader = null
//first instance the /area and remove it from the members list
index = members.len
var/atom/instance
_preloader = new(members_attributes[index])//preloader for assigning set variables on atom creation
if(members[index] != /area/template_noop)
var/atom/instance
_preloader.setup(members_attributes[index])//preloader for assigning set variables on atom creation
instance = locate(members[index])
instance.contents.Add(locate(xcrd,ycrd,zcrd))
if(_preloader && instance)
_preloader.load(instance)
instance = locate(members[index])
var/turf/crds = locate(xcrd,ycrd,zcrd)
if(crds)
instance.contents.Add(crds)
if(use_preloader && instance)
_preloader.load(instance)
members.Remove(members[index])
//then instance the /turf and, if multiple tiles are presents, simulates the DMM underlays piling effect
@@ -183,40 +191,47 @@ var/global/dmm_suite/preloader/_preloader = null
first_turf_index++
//instanciate the first /turf
var/turf/T = instance_atom(members[first_turf_index],members_attributes[first_turf_index],xcrd,ycrd,zcrd)
var/turf/T
if(members[first_turf_index] != /turf/template_noop)
T = instance_atom(members[first_turf_index],members_attributes[first_turf_index],xcrd,ycrd,zcrd)
//if others /turf are presents, simulates the underlays piling effect
index = first_turf_index + 1
while(index <= members.len)
turfs_underlays.Insert(1,image(T.icon,null,T.icon_state,T.layer,T.dir))//add the current turf image to the underlays list
var/turf/UT = instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd)//instance new turf
add_underlying_turf(UT,T,turfs_underlays)//simulates the DMM piling effect
T = UT
index++
if(T)
//if others /turf are presents, simulates the underlays piling effect
index = first_turf_index + 1
while(index <= members.len)
turfs_underlays.Insert(1,image(T.icon,null,T.icon_state,T.layer,T.dir))//add the current turf image to the underlays list
var/turf/UT = instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd)//instance new turf
add_underlying_turf(UT,T,turfs_underlays)//simulates the DMM piling effect
T = UT
index++
//finally instance all remainings objects/mobs
for(index=1,index < first_turf_index,index++)
for(index in 1 to first_turf_index - 1)
instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd)
if(do_sleep)
sleep(-1)
////////////////
//Helpers procs
////////////////
//Instance an atom at (x,y,z) and gives it the variables in attributes
/dmm_suite/proc/instance_atom(var/path,var/list/attributes, var/x, var/y, var/z)
/dmm_suite/proc/instance_atom(path,list/attributes, x, y, z)
var/atom/instance
_preloader = new(attributes, path)
_preloader.setup(attributes, path)
instance = new path (locate(x,y,z))//first preloader pass
var/turf/T = locate(x,y,z)
if(T)
instance = new path (T)//first preloader pass
if(_preloader && instance)//second preloader pass, for those atoms that don't ..() in New()
if(use_preloader && instance)//second preloader pass, for those atoms that don't ..() in New()
_preloader.load(instance)
return instance
//text trimming (both directions) helper proc
//optionally removes quotes before and after the text (for variable name)
/dmm_suite/proc/trim_text(var/what as text,var/trim_quotes=0)
/dmm_suite/proc/trim_text(what as text,trim_quotes=0)
while(length(what) && (findtext(what," ",1,2)))
what=copytext(what,2,0)
while(length(what) && (findtext(what," ",length(what),0)))
@@ -230,7 +245,7 @@ var/global/dmm_suite/preloader/_preloader = null
//find the position of the next delimiter,skipping whatever is comprised between opening_escape and closing_escape
//returns 0 if reached the last delimiter
/dmm_suite/proc/find_next_delimiter_position(var/text as text,var/initial_position as num, var/delimiter=",",var/opening_escape=quote,var/closing_escape=quote)
/dmm_suite/proc/find_next_delimiter_position(text as text,initial_position as num, delimiter=",",opening_escape=quote,closing_escape=quote)
var/position = initial_position
var/next_delimiter = findtext(text,delimiter,position,0)
var/next_opening = findtext(text,opening_escape,position,0)
@@ -245,7 +260,7 @@ var/global/dmm_suite/preloader/_preloader = null
//build a list from variables in text form (e.g {var1="derp"; var2; var3=7} => list(var1="derp", var2, var3=7))
//return the filled list
/dmm_suite/proc/dmm_splittext(var/text as text,var/delimiter=",")
/dmm_suite/proc/readlist(text as text, delimiter=",")
var/list/to_return = list()
@@ -279,12 +294,16 @@ var/global/dmm_suite/preloader/_preloader = null
//Check for list
else if(copytext(trim_right,1,5) == "list")
trim_right = dmm_splittext(copytext(trim_right,6,length(trim_right)))
trim_right = readlist(copytext(trim_right,6,length(trim_right)))
//Check for file
else if(copytext(trim_right,1,2) == "'")
trim_right = file(copytext(trim_right,2,length(trim_right)))
//Check for path
else if(ispath(text2path(trim_right)))
trim_right = text2path(trim_right)
to_return[trim_left] = trim_right
else//simple var
@@ -295,7 +314,7 @@ var/global/dmm_suite/preloader/_preloader = null
return to_return
//simulates the DM multiple turfs on one tile underlaying
/dmm_suite/proc/add_underlying_turf(var/turf/placed,var/turf/underturf, var/list/turfs_underlays)
/dmm_suite/proc/add_underlying_turf(turf/placed,turf/underturf, list/turfs_underlays)
if(underturf.density)
placed.density = 1
if(underturf.opacity)
@@ -304,11 +323,15 @@ var/global/dmm_suite/preloader/_preloader = null
//atom creation method that preloads variables at creation
/atom/New()
if(_preloader && (src.type == _preloader.target_path))//in case the instanciated atom is creating other atoms in New()
if(use_preloader && (src.type == _preloader.target_path))//in case the instanciated atom is creating other atoms in New()
_preloader.load(src)
. = ..()
/dmm_suite/Destroy()
..()
return QDEL_HINT_HARDDEL_NOW
//////////////////
//Preloader datum
//////////////////
@@ -318,15 +341,19 @@ var/global/dmm_suite/preloader/_preloader = null
var/list/attributes
var/target_path
/dmm_suite/preloader/New(var/list/the_attributes, var/path)
.=..()
if(!the_attributes.len)
del(src)
return
attributes = the_attributes
target_path = path
/dmm_suite/preloader/proc/setup(list/the_attributes, path)
if(the_attributes.len)
use_preloader = TRUE
attributes = the_attributes
target_path = path
/dmm_suite/preloader/proc/load(atom/what)
for(var/attribute in attributes)
what.vars[attribute] = attributes[attribute]
del(src)
use_preloader = FALSE
/area/template_noop
name = "Area Passthrough"
/turf/template_noop
name = "Turf Passthrough"
+20 -19
View File
@@ -156,14 +156,14 @@ swapmap
if(z2>swapmaps_compiled_maxz ||\
y2>swapmaps_compiled_maxy ||\
x2>swapmaps_compiled_maxx)
del(src)
qdel(src)
return
x2=x?(x):world.maxx
y2=y?(y):world.maxy
z2=z?(z):1
AllocateSwapMap()
Del()
Destroy()
// a temporary datum for a chunk can be deleted outright
// for others, some cleanup is necessary
if(!ischunk)
@@ -179,13 +179,14 @@ swapmap
if(!M.key) qdel(M)
else M.loc=null
areas[A.loc]=null
del(A)
qdel(A)
// delete areas that belong only to this map
for(var/area/a in areas)
if(a && !a.contents.len) del(a)
if(a && !a.contents.len) qdel(a)
if(x2>=world.maxx || y2>=world.maxy || z2>=world.maxz) CutXYZ()
del(areas)
qdel(areas)
..()
return QDEL_HINT_HARDDEL_NOW
/*
Savefile format:
@@ -226,11 +227,11 @@ swapmap
S["areas"] << areas
for(n in 1 to areas.len) areas[areas[n]]=n
var/oldcd=S.cd
for(z=z1,z<=z2,++z)
for(z in z1 to z2)
S.cd="[z-z1+1]"
for(y=y1,y<=y2,++y)
for(y in y1 to y2)
S.cd="[y-y1+1]"
for(x=x1,x<=x2,++x)
for(x in x1 to x2)
S.cd="[x-x1+1]"
var/turf/T=locate(x,y,z)
S["type"] << T.type
@@ -241,7 +242,7 @@ swapmap
sleep()
S.cd=oldcd
locked=0
del(areas)
qdel(areas)
Read(savefile/S,_id,turf/locorner)
var/x
@@ -269,11 +270,11 @@ swapmap
locked=1
AllocateSwapMap() // adjust x1,y1,z1 - x2,y2,z2 coords
var/oldcd=S.cd
for(z=z1,z<=z2,++z)
for(z in z1 to z2)
S.cd="[z-z1+1]"
for(y=y1,y<=y2,++y)
for(y in y1 to y2)
S.cd="[y-y1+1]"
for(x=x1,x<=x2,++x)
for(x in x1 to x2)
S.cd="[x-x1+1]"
var/tp
S["type"]>>tp
@@ -297,7 +298,7 @@ swapmap
sleep()
S.cd=oldcd
locked=0
del(areas)
qdel(areas)
/*
Find an empty block on the world map in which to load this map.
@@ -321,7 +322,7 @@ swapmap
x1=l[1]
y1=l[2]
z1=l[3]
del(l)
qdel(l)
x2+=x1-1
y2+=y1-1
z2+=z1-1
@@ -377,7 +378,7 @@ swapmap
// save and delete
proc/Unload()
Save()
del(src)
qdel(src)
proc/Save()
if(id==src) return 0
@@ -472,7 +473,7 @@ atom
l=l.Copy()
for(M in src) if(M.key) l-=M
if(l.len) S["contents"]<<l
if(l!=contents) del(l)
if(l!=contents) qdel(l)
Read(savefile/S)
var/list/l
if(contents.len) l=contents
@@ -485,7 +486,7 @@ atom
if(istext(ic)) icon=swapmaps_iconcache[ic]
if(l && contents!=l)
contents+=l
del(l)
qdel(l)
// set this up (at runtime) as follows:
@@ -625,7 +626,7 @@ proc/SwapMaps_LoadChunk(chunk_id,turf/locorner)
S.cd="//.0"
M.Read(S,M,locorner)
while(M.locked) sleep(1)
del(M)
qdel(M)
return 1
proc/SwapMaps_SaveChunk(chunk_id,turf/corner1,turf/corner2)
@@ -646,7 +647,7 @@ proc/SwapMaps_SaveChunk(chunk_id,turf/corner1,turf/corner2)
M.mode=swapmaps_mode
M.Save()
while(M.locked) sleep(1)
del(M)
qdel(M)
return 1
proc/SwapMaps_GetSize(id)
@@ -36,7 +36,7 @@ dmm_suite{
fdel("[map_name].dmm")
}
var/saved_map = file("[map_name].dmm")
to_chat(saved_map, file_text)
saved_map << file_text
return saved_map
}
write_map(var/turf/t1 as turf, var/turf/t2 as turf, var/flags as num){
@@ -49,9 +49,9 @@ dmm_suite{
var/list/templates[0]
var/template_buffer = {""}
var/dmm_text = {""}
for(var/pos_z=nw.z;pos_z<=se.z;pos_z++){
for(var/pos_y=nw.y;pos_y>=se.y;pos_y--){
for(var/pos_x=nw.x;pos_x<=se.x;pos_x++){
for(var/pos_z in nw.z to se.z){
for(var/pos_y in nw.y to se.y){
for(var/pos_x in nw.x to se.x){
var/turf/test_turf = locate(pos_x,pos_y,pos_z)
var/test_template = make_template(test_turf, flags)
var/template_number = templates.Find(test_template)
@@ -67,7 +67,7 @@ dmm_suite{
}
var/key_length = round/*floor*/(log(letter_digits.len,templates.len-1)+1)
var/list/keys[templates.len]
for(var/key_pos=1;key_pos<=templates.len;key_pos++){
for(var/key_pos in 1 to templates.len){
keys[key_pos] = get_model_key(key_pos,key_length)
dmm_text += {""[keys[key_pos]]" = ([templates[key_pos]])\n"}
}
@@ -163,7 +163,7 @@ dmm_suite{
get_model_key(var/which as num, var/key_length as num){
var/key = ""
var/working_digit = which-1
for(var/digit_pos=key_length;digit_pos>=1;digit_pos--){
for(var/digit_pos in key_length to 1 step -1){
var/place_value = round/*floor*/(working_digit/(letter_digits.len**(digit_pos-1)))
working_digit-=place_value*(letter_digits.len**(digit_pos-1))
key = "[key][letter_digits[place_value+1]]"
+29 -14
View File
@@ -1,10 +1,33 @@
proc/createRandomZlevel()
/proc/late_setup_level(turfs, smoothTurfs)
if(!smoothTurfs)
smoothTurfs = turfs
if(air_master)
air_master.setup_allturfs(turfs)
for(var/turf/T in turfs)
if(T.dynamic_lighting)
T.lighting_build_overlays()
for(var/obj/structure/cable/PC in T)
makepowernet_for(PC)
for(var/turf/T in smoothTurfs)
if(T.smooth)
smooth_icon(T)
for(var/R in T)
var/atom/A = R
if(A.smooth)
smooth_icon(A)
/proc/createRandomZlevel()
if(awaydestinations.len) //crude, but it saves another var!
return
var/list/potentialRandomZlevels = list()
log_startup_progress("Searching for away missions...")
var/list/Lines = file2list("_maps/map_files/RandomZLevels/fileList.txt")
var/list/Lines
if(fexists("config/away_mission_config.txt"))
Lines = file2list("config/away_mission_config.txt")
else
Lines = file2list("config/example/away_mission_config.txt")
if(!Lines.len) return
for (var/t in Lines)
@@ -35,22 +58,14 @@ proc/createRandomZlevel()
if(potentialRandomZlevels.len)
var/watch = start_watch()
log_startup_progress(" Loading away mission...")
log_startup_progress("Loading away mission...")
var/map = pick(potentialRandomZlevels)
var/file = file(map)
if(isfile(file))
maploader.load_map(file)
var/turfs = block(locate(1, 1, world.maxz), locate(world.maxx, world.maxy, world.maxz))
if(air_master)
air_master.setup_allturfs(turfs)
for(var/turf/T in turfs)
if(T.dynamic_lighting)
T.lighting_build_overlays()
for(var/obj/structure/cable/PC in T)
makepowernet_for(PC)
smooth_zlevel(world.maxz)
log_to_dd("Away mission loaded: [map]")
maploader.load_map(file, do_sleep = 0)
late_setup_level(block(locate(1, 1, world.maxz), locate(world.maxx, world.maxy, world.maxz)))
log_to_dd(" Away mission loaded: [map]")
for(var/obj/effect/landmark/L in landmarks_list)
if (L.name != "awaystart")