Add test files;

This commit is contained in:
wan-may 2023-04-28 14:35:52 -03:00
commit 7fa3e83a22
24 changed files with 33402 additions and 0 deletions

0
ai.lua Normal file
View File

5
bmp.lua Normal file
View File

@ -0,0 +1,5 @@
--Load and save the bmp formats used by DEFCON.
local bmp = {}
return bmp

61
cities.lua Normal file
View File

@ -0,0 +1,61 @@
--Load and save the fixed width plaintext data used by DEFCON.
local t = {}
local io = io
local table = table
local tonumber = tonumber
local lfs = love.filesystem
local lg = love.graphics
local cities
local points = {}
local caps = {}
function t.draw()
lg.points( points )
end
function t.drawCapitals()
lg.points( caps )
end
function t.load( filename )
cities = {}
local n = 0
local idxPts = 1
local idxCaps = 1
for line in assert( io.lines( filename ), "Error: could not open cities.dat" ) do
n = n + 1
local _, _, x, y, pop, capital = line:sub( 83 ):find( "(%g+)%s+(%g+)%s+(%g+)%s+(%g+)" )
x, y, pop, capital = tonumber( x ), tonumber( y ), tonumber( pop ), ( tonumber( capital ) > 0)
local city = {
name = line:sub( 1, 39 ):gsub("%s+$",""),
country = line:sub( 42, 82 ):gsub("%s+$",""),
x = x, y = y, pop = pop, capital = capital
}
cities[n] = city
points[idxPts], points[idxPts + 1] = x, y
idxPts = idxPts + 2
if capital then
caps[idxCaps], caps[idxCaps + 1] = x, y
idxCaps = idxCaps + 2
end
end
print( "LOADED", filename, n )
return setmetatable( cities, {__index = t } )
end
function t.save( cities, filename )
local str = {}
for n, city in ipairs( cities ) do
str[n] = ("%-40s%-40s%f %f %d %d"):format( city.name, city.country, city.x, city.y, city.pop, city.capital and 1 or 0 )
end
assert( lfs.write( filename, table.concat( str, "\n" ) ) )
print( "Saved", filename )
end
return t

BIN
data/earth/africa.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

BIN
data/earth/ai_markers.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

2745
data/earth/cities.dat Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

BIN
data/earth/coastlines.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

15206
data/earth/coastlines.dat Normal file

File diff suppressed because it is too large Load Diff

BIN
data/earth/europe.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

8325
data/earth/international.dat Normal file

File diff suppressed because it is too large Load Diff

BIN
data/earth/northamerica.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

BIN
data/earth/russia.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

BIN
data/earth/sailable.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
data/earth/southamerica.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

BIN
data/earth/southasia.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

BIN
data/earth/travel_nodes.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

BIN
data/graphics/map.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 KiB

BIN
data/graphics/water.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

40
lines.lua Normal file
View File

@ -0,0 +1,40 @@
--Load and save plaintext line mesh format for DEFCON coastlines etc.
local t = {}
local lfs = love.filesystem
local lg = love.graphics
function t.load( filename )
local polys = {}
local poly = {}
local n = 0
local k = 1
for line in assert( lfs.lines( filename ) ) do
if line == "b" then
k = 1
n = n + 1
poly = {}
polys[n] = poly
else
local _, _, x, y = line:find( "(%g+)%s+(%g+)" )
x, y = assert( tonumber( x ) ), assert( tonumber( y ) )
poly[k], poly[ k + 1 ] = x, y
k = k + 2
end
end
print( "LOADED", filename, n )
return setmetatable( polys, {__index = t } )
end
function t.save( lines, filename )
end
function t.draw( lines )
for _, poly in ipairs( lines ) do
lg.line( poly )
end
end
return t

29
main.lua Normal file
View File

@ -0,0 +1,29 @@
local love = assert( love, "This tool requires LOVE: love2d.org" )
local map = require 'map'
local SAVEDIRECTORY = "out/"
function love.load()
local lfs = assert( love.filesystem )
lfs.setIdentity( "dcearth", false )
assert( lfs.createDirectory( SAVEDIRECTORY.."data/earth" ))
assert( lfs.createDirectory( SAVEDIRECTORY.."data/graphics" ))
map.load()
end
local canvas = love.graphics.newCanvas()
function love.update( dt )
love.graphics.setCanvas( canvas )
map.draw()
love.graphics.setCanvas()
end
function love.draw()
love.graphics.draw( canvas )
end
function love.keypressed(key)
if key == "s" then
-- To open a file or folder, "file://" must be prepended to the path.
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
end
end

76
map.lua Normal file
View File

@ -0,0 +1,76 @@
local lg = love.graphics
local Cities = require 'cities'
local Lines = require 'lines'
local Bitmap = require 'bmp'
local map = {
coastlines = false,
coastlinesLow = false,
international = false,
territory = {
af = false,
eu = false,
na = false,
ru = false,
sa = false,
as = false
},
travelnodes = false,
sailable = false,
aimarkers = false,
cities = false
}
function map.load()
map.cities = Cities.load( "data/earth/cities.dat" )
map.coastlines = Lines.load( "data/earth/coastlines.dat" )
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
map.international = Lines.load( "data/earth/international.dat" )
end
function map.draw()
lg.clear( 0, 0, 0, 1 )
do --all this stuff is drawn in world coordinates, ( -180, 180 ) x ( -100, 100 )
lg.push( "transform" )
lg.scale( lg.getCanvas():getDimensions() )
lg.scale( 1 / 360, - 1 / 200 )
lg.translate( 180, -100 )
do --points
lg.setColor( 1, 0, 0, 0.5 )
lg.setPointSize( 2 )
map.cities:draw()
lg.setColor( 1, 0, 0, 1.0 )
lg.setPointSize( 4 )
map.cities:drawCapitals()
end
do --line stuff
lg.setColor(1, 1, 1, 0.2 )
lg.setLineWidth( 0.2 )
map.international:draw()
lg.setColor(1, 1, 1, 1 )
lg.setLineWidth( 0.3 )
map.coastlines:draw()
map.coastlinesLow:draw()
end
lg.pop( )
end
end
function map.save()
end
function map.setVisible()
end
return map

7
nodes.lua Normal file
View File

@ -0,0 +1,7 @@
--Manage the pathfinding nodes used by DEFCON.
--This is important for a mapping tool because the DEFCON client will not load a map unless
--the pathfinding nodes form a connected graph.
local nodes = {}
return nodes