script, editor mode, begin # Called from the main loop once per tick if(keyval(key:tilde)) then( editor menu exit script ) variable(save) save := false variable(x, y, tile) x := mouse tile x y := mouse tile y tile := get tile at(x, y) if(tile) then( variable(tkind) tkind := -1 if(keyval(key:1) > 1) then(tkind := tile:void) if(keyval(key:2) > 1) then(tkind := tile:snow) if(keyval(key:3) > 1) then(tkind := tile:wall) if(keyval(key:4) > 1) then(tkind := tile:rock) if(tkind > -1) then( change tile(tile, tkind) save := true ) variable(unit) unit := tile unit(tile) if(not(unit)) then( if(keyval(key:tilde) > 1) then( set parent(player, tile) camera follows slice(player) save := true ) if(keyval(key:g) > 1) then(create snow goon(x, y), save := true) if(keyval(key:w) > 1) then(create werewolf(x, y), save := true) if(keyval(key:b) > 1) then(create ganderer(x, y), save := true) if(keyval(key:r) > 1) then(create rustmuncher(x, y), save := true) if(keyval(key:t) > 1) then(create random tree(x, y), save := true) )else( if(keyval(key:backspace) > 1) then( if(unit <> player) then( free unit(unit) save := true ) ) ) ) if(save) then( save leveledit ) end script, editor menu, begin wait for not a click wait for key release(key:tilde) variable(col, map move) col := load slice collection(slicol:editor menu) while(true) do( if(keyval(key:tilde)) then( break ) if(mouse click(left button)) then( map move := mapnav menu button(col, mouse pixel x, mouse pixel y) if(map move >= 0) then( save map chunk(world x, world y) world x += hex around x(map move) world y += hex around y(map move) load map chunk(world x, world y) ) ) wait(1) ) free slice(col) wait for not a click wait for key release(key:tilde) end script, mapnav menu button, sl, px, py, begin if(get slice lookup(sl) == sli:mapnav) then( if(slice collide point(sl, px, py)) then( exit returning(get slice extra(sl, 0)) ) ) variable(ch, ret) ch := first child(sl) while(ch) do( ret := mapnav menu button(ch, px, py) if(ret >= 0) then(exit returning(ret)) ch := next sibling(ch) ) exit returning(-1) end script, wait for not a click, begin while(mouse click(left button)) do(wait(1)) end script, wait for key release, k, begin while(key is pressed(k)) do(wait(1)) end #----------------------------------------------------------------------- script, get map chunk, wx, wy, begin variable(chunk, code, wh, ww) ww := slice width(world map) wh := slice height(world map) code := sli:chunk code + wy * ww + wx chunk := lookup slice(code, world map) if(not(chunk)) then( chunk := create container(0, 0) set slice lookup(chunk, code) set parent(chunk, world map) ) exit returning(chunk) end script, save map chunk, wx, wy, begin variable(chunk) chunk := get map chunk(wx, wy) write map chunk(chunk) end script, write map chunk, chunk, begin free slice children(chunk) for each tile(@do write map chunk, chunk) end script, do write map chunk, tile, chunk, begin variable(code, data) code := sli:tile code + y for tile(tile) * gridsize + x for tile(tile) data := create container(0, 0) set slice lookup(data, code) set parent(data, chunk) set slice extra(data, 0, get tile kind(tile)) for each unit(tile, @do write map chunk tile unit, data) end script, do write map chunk tile unit, unit, data, begin variable(unit data) if(get unit never saved(unit)) then(exit script) if(unit == player) then( # Player does not get saved in the map data exit script ) unit data := create container(0, 0) set parent(unit data, data) set slice extra(unit data, 0, get unit id(unit)) end script, load map chunk, wx, wy, begin variable(chunk) chunk := get map chunk(wx, wy) read map chunk(chunk) end script, read map chunk, chunk, begin for each tile(@do read map chunk, chunk) end script, do read map chunk, tile, chunk, begin variable(code, data) code := sli:tile code + y for tile(tile) * gridsize + x for tile(tile) data := lookup slice(code, chunk) if(not(data)) then( # blank tile data := create container(0, 0) set slice lookup(data, code) set parent(data, chunk) set slice extra(data, 0, tile:snow) ) change tile(tile, get slice extra(data, 0)) for each unit(tile, @free non player units) variable(unit data, unit id, unit) unit data := first child(data) while(unit data) do( unit id := get slice extra(unit data, 0) unit := create unit by id(tile, unit id) unit data := next sibling(unit data) ) end script, free non player units, unit, begin if(unit <> player) then( free slice(unit) ) end