2023-08-26 21:05:48 +00:00
|
|
|
--Manage the AI nodes used by DEFCON.
|
|
|
|
local bmp = require 'bmp'
|
|
|
|
local lg = assert( love.graphics )
|
2024-04-25 01:06:41 +00:00
|
|
|
local locationQuery = require 'locationQuery'
|
|
|
|
|
|
|
|
local t = setmetatable( {}, {__index = locationQuery } )
|
2023-08-28 23:12:43 +00:00
|
|
|
local print = print
|
2023-08-26 21:05:48 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
local aiNode = {}
|
|
|
|
local mtAiNode = { __index = aiNode }
|
|
|
|
|
|
|
|
function aiNode:formatDisplayInfo()
|
|
|
|
return ([[AI NODE: %d
|
|
|
|
LONGITUDE: %3.2f
|
|
|
|
LATITUDE: %3.2f
|
|
|
|
ATTACKING: %s
|
|
|
|
]]):format( self.idx, self.x, self.y, tostring(self.attacking) )
|
|
|
|
end
|
|
|
|
|
2023-08-26 21:05:48 +00:00
|
|
|
function t.load( filename )
|
|
|
|
local img, imgd = bmp.load( filename )
|
|
|
|
local nodes = {
|
2024-04-29 01:21:32 +00:00
|
|
|
filename = filename,
|
2023-08-26 21:05:48 +00:00
|
|
|
visible = true,
|
2024-04-25 01:06:41 +00:00
|
|
|
all = {},
|
2023-08-26 21:05:48 +00:00
|
|
|
att = {},
|
2023-08-28 23:12:43 +00:00
|
|
|
ptsAtt = {},
|
2023-08-26 21:05:48 +00:00
|
|
|
def = {},
|
2023-08-28 23:12:43 +00:00
|
|
|
ptsDef = {},
|
2023-08-26 21:05:48 +00:00
|
|
|
img = img,
|
|
|
|
imgd = imgd }
|
2023-08-28 23:12:43 +00:00
|
|
|
|
|
|
|
print( "=== Loading AI Markers: ===" )
|
2024-04-25 01:06:41 +00:00
|
|
|
local idx = 1
|
2023-08-28 23:12:43 +00:00
|
|
|
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
|
2024-04-25 01:06:41 +00:00
|
|
|
local attacking = (r > 0.5)
|
|
|
|
local set = attacking and nodes.att or nodes.def
|
|
|
|
local node = setmetatable( {x = long, y = lat, attacking = attacking, idx = idx}, mtAiNode )
|
|
|
|
nodes.all[ idx ] = node
|
|
|
|
set[#set + 1] = node
|
|
|
|
idx = idx + 1
|
2023-08-28 23:12:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2024-04-25 01:06:41 +00:00
|
|
|
|
|
|
|
nodes.all = locationQuery.New( nodes.all )
|
|
|
|
setmetatable( nodes, {__index = t } )
|
|
|
|
return nodes
|
|
|
|
end
|
2023-08-28 23:12:43 +00:00
|
|
|
|
2024-04-25 01:06:41 +00:00
|
|
|
function t.selectNearest( nodes, x, y )
|
|
|
|
return (nodes.all):getClosestPoint( x, y )
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function t.draw( nodes )
|
2023-08-28 23:12:43 +00:00
|
|
|
lg.setColor( 1, 0, 0, 0.5 )
|
|
|
|
lg.points( nodes.ptsAtt )
|
|
|
|
lg.setColor( 0, 1, 0, 0.5 )
|
|
|
|
lg.points( nodes.ptsDef )
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
|
|
|
|
2024-04-29 01:21:32 +00:00
|
|
|
function t.save( nodes )
|
2024-07-13 02:37:50 +00:00
|
|
|
return bmp.ai( nodes.all )
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return t
|