Quantcast
Channel: forum.freeciv.org
Viewing all articles
Browse latest Browse all 394

Contribution • Re: Simple continent map generators for Freeciv

$
0
0
Well how about just simple rectangles and the whole set of other layers (empty) for at least Freeciv 2.6.4 through 2.6.11 ?

Image
^ Generates all the layers: t, blank startpos section (works well with the blocks of land), e00 through e03, and res.

Code:

#!/usr/bin/env bash# This generates blocks of land on ocean# and output is the terrain layer, startpos (blank),# and the other layers needed for Freeciv 2.6.4 through 2.6.11 scenarios# Ouput a blank lineecho# Declare variablesdeclare    zeroPad="0000" tile layerPrefix lineOfSpacesdeclare -a terrain_layerdeclare -i x y r breaks# The map size is determined by the xsize and ysize variables on the next line# and those can be set from the command line when invoking the script by adding 80 60, for exampledeclare -i xsize="${1:-92}" ysize="${2:-46}"if [ ${xsize} -lt 30 ] || [ ${ysize} -lt 30 ] ; thenecho "Too small, try x and y sizes greater or equal to 30"echoexit 1fiprintf -v lineOfSpaces '%*s ' $(( ${xsize} - 1 ))# Ouput a blank lineechofor (( y=0 ; y<${ysize} ; y++ )) ; dofor (( x=0 ; x<${xsize} ; x++ )) ; dor=$(( 1 + RANDOM % 19 ))# No lake tiles, add them laterif [ ${r} -ge 1 ] && [ ${r} -le 5 ] ; then tile="g" ; fiif [ ${r} -ge 6 ] && [ ${r} -le 9 ] ; then tile="p" ; fiif [ ${r} -ge 10 ] && [ ${r} -le 12 ] ; then tile="h" ; fiif [ ${r} -ge 13 ] && [ ${r} -le 15 ] ; then tile="f" ; fiif [ ${r} -eq 16 ] ; then tile="m" ; fiif [ ${r} -eq 17 ] ; then tile="d" ; fiif [ ${r} -eq 18 ] ; then tile="j" ; fiif [ ${r} -eq 19 ] ; then tile="s" ; fibreaks=$(( ( ( "${xsize}" / 6 ) + ( "${ysize}" / 6 ) ) / 2 ))if [ "${x}" -ge 0 -a $(( "${x}" % "${breaks}" )) -ge 0 -a $(( "${x}" % "${breaks}" )) -lt 4 ] ; thentile=" "fiif [ "${y}" -ge 0 -a $(( "${y}" % "${breaks}" )) -ge 0 -a $(( "${y}" % "${breaks}" )) -lt 4 ] ; thentile=" "fiterrain_layer[${y}]="${terrain_layer[${y}]}${tile}"donedone# Output the map sections formatted for at least, Freeiv 2.6.4 through 2.6.11for (( y=0 ; y<${ysize} ; y++ )) ; doecho "t${zeroPad:${#y}}${y}=\"${terrain_layer[${y}]}\""done# Output the startpos info (blocks of land do well with startpos defaults so no specific values needed)echo -e 'startpos_count=0\nstartpos={"x","y","exclude","nations"\n}'# Output the other layersfor layerPrefix in e00_ e01_ e02_ e03_ res ; dofor (( y=0 ; y<${ysize} ; y++ )) ; doecho -n "${layerPrefix}${zeroPad:${#y}}${y}="if [ "${layerPrefix}" = "res" ] ; thenecho "\"${lineOfSpaces}\""elseecho "\"${lineOfSpaces// /0}\""fidonedone# Ouput a blank lineechoexit 0

Or a Lua script for stand-alone Lua

Code:

-- Written and tested in Lua 5.3.0 for Mac OS-- http://www.lua.org/ftp/lua-5.3.0.tar.gz-- Set map size herexsize = 92ysize = 46-- Set # of breaks ( lines of ocean vs land)breaks = math.floor( ( ( xsize / 6 ) + ( ysize / 6 ) ) / 2 )terrain_layer = {}zeroPad = "0000"math.randomseed( ( '' .. os.time() ):reverse() )for y = 0, ysize - 1, 1 doterrain_layer[ y ] = ""for x = 0, xsize - 1, 1 dolocal terrain = ""local z = math.random( 1, 74 )if     z >=  1 and z<= 30 then terrain = "g"elseif z >= 31 and z<= 61 then terrain = "p"elseif z >= 62 and z<= 65 then terrain = "f"elseif z >= 66 and z<= 70 then terrain = "h"elseif z == 71 then terrain = "j"elseif z == 72 then terrain = "s"elseif z == 73 then terrain = "d"elseif z == 74 then terrain = "m"endif x >= 0 and x % breaks >= 0 and x % breaks < 4 thenterrain=" "endif y >= 0 and y % breaks >= 0 and y % breaks < 4 thenterrain=" "endterrain_layer[ y ] = terrain_layer[ y ] .. terrainendprint( "t" .. string.sub( zeroPad, 1, string.len( zeroPad ) - string.len( y ) ).. y .. "=\"" .. terrain_layer[ y ] .. "\"" )end-- output blank startpos infoprint( 'startpos_count=0\nstartpos={"x","y","exclude","nations"\n}' )-- output the "e" layerslayers = { "e01_", "e02_", "e03_" }for i = 1, #layers, 1 dofor y = 0, ysize - 1, 1 doprint( layers[ i ] .. string.sub( zeroPad, 1, string.len( zeroPad ) - string.len( y ) ).. y .. "=\"" .. string.rep( "0", xsize ) .. "\"" )endend-- output the "res" layerfor y = 0, ysize - 1, 1 doprint( "res" .. string.sub( zeroPad, 1, string.len( zeroPad ) - string.len( y ) ).. y .. "=\"" .. string.rep( " ", xsize ) .. "\"" )end
Oops, I left e00 out of v1.0 of the Lua script, it's back in v1.1.
map generator Continent squares Lua script v1.1.lua.txt.zip

map generator Continent squares Bash script v1.0.sh.txt.zip

Statistics: Posted by Molo_Parko — Fri Nov 29, 2024 10:02 pm



Viewing all articles
Browse latest Browse all 394

Trending Articles