local lg = love.graphics local AI = require 'ai' local Cities = require 'cities' local Lines = require 'lines' local Nodes = require 'travelNodes' local Camera = require 'camera' local Territory = require 'territory' local map = { loaded = false, coastlines = false, coastlinesLow = false, international = false, territory = { africa = false, europe = false, northamerica = false, russia = false, southamerica = false, southasia = false }, travelnodes = false, sailable = false, ainodes = false, cities = false } function map.load( path ) 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" ) for k, v in pairs(map.territory) do map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k ) end map.loaded = true map.path = path end function map.draw() lg.clear( 0, 0, 0, 1 ) if not map.loaded then return end do --territory lg.setColor( 1,1,1,1) lg.setLineJoin( "none" ) lg.replaceTransform( Camera.tfTerritory ) lg.setBlendMode( "add" ) for k, v in pairs(map.territory) do if v.visible then v:draw() lg.setLineWidth( 1 / Camera.zoom ) v:drawBorder( "land" ) lg.setLineWidth( 3 / Camera.zoom ) v:drawBorder( "sea" ) end end if map.sailable.visible then map.sailable:draw() lg.setLineJoin( "none" ) lg.setLineWidth( 1 / Camera.zoom ) lg.setColor( 1, 1, 1, 0.5) map.sailable:drawBorder( "sailable" ) lg.setLineWidth( 3 / Camera.zoom ) map.sailable:drawBorder( "placeable" ) end lg.setBlendMode( "alpha" ) lg.setColor( 1, 1, 1, 1 ) end do --all this stuff is drawn in world coordinates, ( -180, 180 ) x ( -100, 100 ) lg.replaceTransform( Camera.tf ) if map.selected then lg.setColor( 1.0, 0.5, 0.5, 0.9 ) lg.setLineJoin( "miter" ) lg.setLineWidth( 1.0 / Camera.zoom ) lg.circle( "line", map.selected.x, map.selected.y, 0.2 + 1.0 / Camera.zoom ) end if map.cities.visible then --points lg.setColor( 1, 0, 0, 0.5 ) lg.setPointSize( 5.0 ) map.cities.draw() lg.setColor( 1, 1, 0.0, 0.5 ) map.cities.drawCapitals() end if map.ainodes.visible then lg.setPointSize( 5.0 ) map.ainodes:draw() end do --line stuff lg.setColor(1, 1, 1, 0.2 ) lg.setLineJoin( "miter" ) lg.setLineWidth( 0.2 / Camera.zoom ) map.international:draw() lg.setColor(1, 1, 1, 0.5 ) map.coastlines:draw() map.coastlinesLow:draw() --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 ) end do --travel nodes lg.replaceTransform( Camera.tfNodes ) if map.travelnodes.visible then map.travelnodes:draw() end end end end local function write( filename, string ) os.rename( filename, filename..".bak" ) --just in case :^) local file = assert( io.open( filename, "w+" ) ) assert( file:write( string ) ) file:close() end function map.save() write( map.path.."/data/earth/cities.dat", 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 end function map.hover(x, y) end return map