Render travel node adjacency; render markers as points; turn off texture filtering
This commit is contained in:
parent
ee7a32af21
commit
f30f27bfb1
40
ai.lua
40
ai.lua
|
@ -2,25 +2,55 @@
|
|||
local t = {}
|
||||
local bmp = require 'bmp'
|
||||
local lg = assert( love.graphics )
|
||||
local print = print
|
||||
|
||||
function t.load( filename )
|
||||
local img, imgd = bmp.load( filename )
|
||||
local nodes = {
|
||||
visible = true,
|
||||
att = {},
|
||||
ptsAtt = {},
|
||||
def = {},
|
||||
ptsDef = {},
|
||||
img = img,
|
||||
imgd = imgd }
|
||||
|
||||
print( "PIXEL: ", imgd:getPixel( 1, 1 ) )
|
||||
print( "=== Loading AI Markers: ===" )
|
||||
for x = 0, 511 do
|
||||
for y = 0, 284 do
|
||||
local r, g = imgd:getPixel( x, 284 - y )
|
||||
if r > 0.5 or g > 0.5 then
|
||||
local long = x * (360 / imgd:getWidth()) - 180
|
||||
local lat = y * (200 / img:getHeight()) - 100
|
||||
local set = (r > 0.5) and nodes.att or nodes.def
|
||||
set[#set + 1] = {x = long, y = lat}
|
||||
print( #set, long, lat )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable( nodes, {__index = t } )
|
||||
do
|
||||
local k = 1
|
||||
for i, point in ipairs( nodes.att ) do
|
||||
nodes.ptsAtt[k], nodes.ptsAtt[k + 1] = point.x, point.y
|
||||
k = k + 2
|
||||
end
|
||||
|
||||
k = 1
|
||||
for j, point in ipairs( nodes.def ) do
|
||||
nodes.ptsDef[k], nodes.ptsDef[k + 1] = point.x, point.y
|
||||
k = k + 2
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable( nodes, {__index = t } )
|
||||
end
|
||||
|
||||
function t.draw( nodes )
|
||||
lg.points( nodes.att )
|
||||
lg.points( nodes.def )
|
||||
lg.draw( nodes.img )
|
||||
lg.setColor( 1, 0, 0, 0.5 )
|
||||
lg.points( nodes.ptsAtt )
|
||||
lg.setColor( 0, 1, 0, 0.5 )
|
||||
lg.points( nodes.ptsDef )
|
||||
end
|
||||
|
||||
function t.save( nodes, filename )
|
||||
|
|
4
bmp.lua
4
bmp.lua
|
@ -10,7 +10,9 @@ local bit = require 'bit'
|
|||
function t.load( filename )
|
||||
local imgd = love.image.newImageData( filename )
|
||||
print( "LOADING BITMAP: ", filename, imgd:getSize(), imgd:getFormat(), imgd:getDimensions() )
|
||||
return love.graphics.newImage( imgd ), imgd
|
||||
local img = love.graphics.newImage( imgd )
|
||||
img:setFilter( "nearest", "nearest" )
|
||||
return img, imgd
|
||||
end
|
||||
|
||||
function t.save( data, format )
|
||||
|
|
|
@ -48,7 +48,7 @@ function t.Edit( points, point, x, y )
|
|||
|
||||
end
|
||||
|
||||
function t.Add( points )
|
||||
function t.Add( points, x, y )
|
||||
|
||||
end
|
||||
|
||||
|
|
13
map.lua
13
map.lua
|
@ -30,24 +30,17 @@ function map.load()
|
|||
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.travelnodes = Nodes.load( "data/earth/travel_nodes.bmp" )
|
||||
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" )
|
||||
for k, v in pairs(map.territory) do
|
||||
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
|
||||
end
|
||||
map.sailable = Territory.load( "data/earth/sailable.bmp", "sailable" )
|
||||
end
|
||||
|
||||
function map.draw()
|
||||
lg.clear( 0, 0, 0, 1 )
|
||||
|
||||
|
||||
do -- ai nodes
|
||||
lg.replaceTransform( Camera.tfTerritory )
|
||||
map.ainodes:draw()
|
||||
end
|
||||
|
||||
|
||||
do --territory
|
||||
lg.replaceTransform( Camera.tfTerritory )
|
||||
lg.setBlendMode( "add" )
|
||||
|
@ -75,6 +68,8 @@ function map.draw()
|
|||
|
||||
lg.setColor( 1, 0, 1, 0.5 )
|
||||
map.cities.drawSelected( 22.0 / Camera.zoom )
|
||||
|
||||
map.ainodes:draw()
|
||||
end
|
||||
|
||||
do --line stuff
|
||||
|
|
52
nodes.lua
52
nodes.lua
|
@ -5,25 +5,58 @@ local t = {}
|
|||
local bmp = require 'bmp'
|
||||
local lg = assert( love.graphics )
|
||||
|
||||
function t.load( filename )
|
||||
local isSailable
|
||||
|
||||
local function isConnected( startNode, endNode )
|
||||
local ix, iy, fx, fy = startNode.x, startNode.y, endNode.x, endNode.y
|
||||
if fx < -180 then fx = fx + 180 end
|
||||
if fx > 180 then fx = fx - 180 end
|
||||
|
||||
local dx, dy = fx - ix, fy - iy
|
||||
local mag = math.sqrt( dx * dx + dy * dy )
|
||||
local n = 2 * math.floor( mag )
|
||||
dx, dy = 0.5 * dx / mag, 0.5 * dy / mag
|
||||
|
||||
for i = 1, n do
|
||||
ix, iy = ix + dx, iy + dy
|
||||
if not( isSailable( ix, iy ) ) then return nil end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function t.load( filename, sailable )
|
||||
|
||||
isSailable = sailable
|
||||
local img, imgd = bmp.load( filename )
|
||||
local nodes = { visible = true, points = {}, connections = {}, img = img }
|
||||
local nodes = { visible = true, nodes = {}, points = {}, connections = {}, img = img }
|
||||
|
||||
print( "=== Loading Nodes: ===" )
|
||||
local n = 1
|
||||
for x = 0, 799 do
|
||||
for y = 0, 399 do
|
||||
if imgd:getPixel( x, 399 - y ) > 0 then
|
||||
local long = 360 * ( x - 800 ) / 800 - 360 / 2 + 360
|
||||
local lat = 360 * ( 600 / 800 ) * ( 600 - y ) / 600 - 180
|
||||
local n = #nodes.points
|
||||
nodes.points[n + 1] = long
|
||||
nodes.points[n + 2] = lat
|
||||
print( long, lat )
|
||||
nodes.nodes[n] = {x = long, y = lat}
|
||||
nodes.points[ 2 * n - 1 ] = long
|
||||
nodes.points[ 2 * n ] = lat
|
||||
print( n, long, lat )
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for i, srcNode in ipairs( nodes.nodes ) do
|
||||
local adjacent = {}
|
||||
|
||||
for j, destNode in ipairs( nodes.nodes ) do
|
||||
adjacent[j] = isConnected( srcNode, destNode )
|
||||
end
|
||||
|
||||
nodes.connections[i] = adjacent
|
||||
end
|
||||
|
||||
print( "=== Nodes Loaded ===" )
|
||||
return setmetatable( nodes, {__index = t } )
|
||||
end
|
||||
|
@ -36,6 +69,13 @@ function t.draw( nodes )
|
|||
lg.setPointSize( 10 )
|
||||
lg.setColor( 1, 1, 1, 0.5 )
|
||||
lg.points( nodes.points )
|
||||
|
||||
for i, connection in pairs( nodes.connections ) do
|
||||
for j in pairs( connection ) do
|
||||
local ix, iy, fx, fy = nodes.nodes[i].x, nodes.nodes[i].y, nodes.nodes[j].x, nodes.nodes[j].y
|
||||
lg.line( ix, iy, fx, fy )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t.drawConnections( nodes )
|
||||
|
|
|
@ -21,6 +21,8 @@ function t.load( filename, name )
|
|||
img = img,
|
||||
imgd = imgd
|
||||
}
|
||||
|
||||
if name == "sailable" then t.sailable = territory end
|
||||
return setmetatable( territory, {__index = t } )
|
||||
end
|
||||
|
||||
|
@ -31,7 +33,9 @@ end
|
|||
|
||||
function t.getPixel( territory, x, y )
|
||||
--ZERO INDEXED
|
||||
return territory.img[math.floor( 512 * ( x + 180 ) / 360 ) ][ math.floor( 285 * ( y + 100 ) / 200 ) ]
|
||||
local imgx, imgy = math.floor( 512 * ( x + 180 ) / 360 ), math.floor( 285 * ( y + 100 ) / 200 )
|
||||
--print( territory.name, imgx, imgy )
|
||||
return territory.imgd:getPixel( imgx, imgy )
|
||||
end
|
||||
|
||||
function t.toggleVisibility( territory )
|
||||
|
@ -39,15 +43,28 @@ function t.toggleVisibility( territory )
|
|||
end
|
||||
|
||||
--[[
|
||||
0
|
||||
20 -- once sailable.bmp is brighter than this, the area is traversable by ships
|
||||
60 -- once sailable.bmp and territory.bmp are brighter than this, ships can be placed here
|
||||
130 -- if territory.bmp is brighter than this and sailable is darker than 60, structures are placeable.
|
||||
0
|
||||
20 -- once sailable.bmp is brighter than this, the area is traversable by ships
|
||||
60 -- once sailable.bmp and territory.bmp are brighter than this, ships can be placed here
|
||||
130 -- if territory.bmp is brighter than this and sailable is darker than 60, structures are placeable.
|
||||
|
||||
SO:
|
||||
SAILABLE: 0 (not), 21 (traverse not place), 61 ( traverse and place )
|
||||
TERRITORY: 131 ( place land if sailable <= 60 ), 61 ( place sea ), 0
|
||||
SO:
|
||||
SAILABLE: 0 (not), 21 (traverse not place), 61 ( traverse and place )
|
||||
TERRITORY: 131 ( place land if sailable <= 60 ), 61 ( place sea ), 0
|
||||
]]
|
||||
function t.isSailable( x, y )
|
||||
local water = assert( t.sailable )
|
||||
if water:getPixel( x, y ) > 20 / 255 then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
function t.canPlaceShip( territory, x, y )
|
||||
|
||||
end
|
||||
|
||||
function t.canPlaceLand( territory, x, y )
|
||||
|
||||
end
|
||||
|
||||
function t.draw( territory )
|
||||
lg.setColor( territory.colour )
|
||||
|
|
Loading…
Reference in New Issue