dcearth/map.lua

143 lines
3.4 KiB
Lua
Raw Normal View History

2023-04-28 17:35:52 +00:00
local lg = love.graphics
local AI = require 'ai'
2023-04-28 17:35:52 +00:00
local Cities = require 'cities'
local Lines = require 'lines'
local Nodes = require 'nodes'
2023-04-28 17:35:52 +00:00
local Bitmap = require 'bmp'
local Camera = require 'camera'
2023-07-28 23:23:08 +00:00
local Territory = require 'territory'
2023-04-28 17:35:52 +00:00
local map = {
coastlines = false,
coastlinesLow = false,
international = false,
territory = {
2023-07-28 23:23:08 +00:00
africa = false,
europe = false,
northamerica = false,
russia = false,
southamerica = false,
southasia = false
2023-04-28 17:35:52 +00:00
},
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" )
map.sailable = Territory.load( "data/earth/sailable.bmp", "sailable" )
map.travelnodes = Nodes.load( "data/earth/travel_nodes.bmp", map.sailable.isSailable ) --travel node adjacency matrix depends on sailable bitmap
map.ainodes = AI.load( "data/earth/ai_markers.bmp" )
2023-07-28 23:23:08 +00:00
for k, v in pairs(map.territory) do
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
end
2023-04-28 17:35:52 +00:00
end
function map.draw()
lg.clear( 0, 0, 0, 1 )
2023-07-28 23:23:08 +00:00
do --territory
lg.setColor( 1,1,1,1)
lg.setLineJoin( "none" )
2023-07-28 23:23:08 +00:00
lg.replaceTransform( Camera.tfTerritory )
lg.setBlendMode( "add" )
for k, v in pairs(map.territory) do
if v.visible then
v:draw()
2024-04-21 14:10:53 +00:00
lg.setLineWidth( 1 / Camera.zoom )
v:drawBorder( "land" )
2024-04-21 14:10:53 +00:00
lg.setLineWidth( 3 / Camera.zoom )
v:drawBorder( "sea" )
end
2023-07-28 23:23:08 +00:00
end
if map.sailable.visible then map.sailable:draw() end
lg.setBlendMode( "alpha" )
2023-09-04 00:49:02 +00:00
lg.setColor( 1, 1, 1, 1 )
end
do --borders
lg.setLineJoin( "none" )
lg.setLineWidth( 1 / Camera.zoom )
lg.setColor( 1, 1, 1, 0.5)
map.sailable:drawBorder( "sailable" )
2024-04-21 14:10:53 +00:00
lg.setLineWidth( 3 / Camera.zoom )
map.sailable:drawBorder( "placeable" )
2023-07-28 23:23:08 +00:00
end
2023-04-28 17:35:52 +00:00
do --all this stuff is drawn in world coordinates, ( -180, 180 ) x ( -100, 100 )
2023-09-04 00:49:02 +00:00
lg.replaceTransform( Camera.tf )
2023-04-28 17:35:52 +00:00
do --points
2023-07-28 23:23:08 +00:00
2023-04-28 17:35:52 +00:00
lg.setColor( 1, 0, 0, 0.5 )
lg.setPointSize( 0.5 * Camera.zoom )
map.cities.draw()
2023-07-28 23:23:08 +00:00
lg.setColor( 1, 1, 1.0, 0.5 )
lg.setPointSize( 1.0 * Camera.zoom )
map.cities.drawCapitals()
2023-07-28 23:23:08 +00:00
2023-09-04 00:49:02 +00:00
lg.setColor( 1, 1, 1, 0.5 )
map.cities.drawSelected( 15.0 / Camera.zoom )
map.ainodes:draw()
2023-04-28 17:35:52 +00:00
end
do --line stuff
lg.setColor(1, 1, 1, 0.2 )
2023-07-28 23:23:08 +00:00
lg.setLineJoin( "miter" )
lg.setLineWidth( 0.2 / Camera.zoom )
2023-04-28 17:35:52 +00:00
map.international:draw()
2023-07-28 23:23:08 +00:00
lg.setColor(1, 1, 1, 0.5 )
2023-04-28 17:35:52 +00:00
map.coastlines:draw()
map.coastlinesLow:draw()
2023-07-28 23:23:08 +00:00
--International Date Line
lg.line( -180, -100, -180, 100 )
lg.line( 180, -100, 180, 100 )
lg.line( -180, 90, 180, 90 )
lg.line( -180, -90, 180, -90 )
lg.line( -180, 100, 180, 100 )
lg.line( -180, -100, 180, -100 )
2023-04-28 17:35:52 +00:00
end
do --travel nodes
lg.replaceTransform( Camera.tfNodes )
map.travelnodes:draw()
end
2023-04-28 17:35:52 +00:00
end
end
function map.save()
2024-04-21 14:10:53 +00:00
map.cities.save()
map.coastlines.save()
map.coastlinesLow.save()
map.international.save()
map.sailable.save()
map.travelnodes.save()
map.ainodes.save()
for k, v in pairs(map.territory) do
map.territory[k].save()
end
2023-04-28 17:35:52 +00:00
end
2023-07-28 05:42:16 +00:00
function map.hover(x, y)
2023-07-28 23:23:08 +00:00
2023-04-28 17:35:52 +00:00
end
return map