2017-05-07 23:56:11 -07:00
|
|
|
local baseUtils = {}
|
|
|
|
|
|
|
|
-- imports
|
|
|
|
|
2017-06-15 18:30:26 -07:00
|
|
|
local mathUtils = require("MathUtils")
|
2017-05-07 23:56:11 -07:00
|
|
|
local constants = require("Constants")
|
2017-06-07 17:57:24 -07:00
|
|
|
|
2017-11-20 23:27:03 -08:00
|
|
|
-- local tendrilUtils = require("TendrilUtils")
|
2017-05-07 23:56:11 -07:00
|
|
|
|
2017-08-08 01:19:51 -07:00
|
|
|
local nestUtils = require("NestUtils")
|
2017-06-12 20:16:43 -07:00
|
|
|
|
2017-05-07 23:56:11 -07:00
|
|
|
-- constants
|
|
|
|
|
|
|
|
local BASE_DISTANCE_THRESHOLD = constants.BASE_DISTANCE_THRESHOLD
|
|
|
|
|
|
|
|
local BASE_ALIGNMENT_NEUTRAL = constants.BASE_ALIGNMENT_NEUTRAL
|
|
|
|
|
|
|
|
local MAGIC_MAXIMUM_NUMBER = constants.MAGIC_MAXIMUM_NUMBER
|
2017-05-19 00:47:24 -07:00
|
|
|
local MAGIC_MAXIMUM_BASE_NUMBER = constants.MAGIC_MAXIMUM_BASE_NUMBER
|
2017-05-07 23:56:11 -07:00
|
|
|
|
|
|
|
-- imported functions
|
|
|
|
|
2017-06-15 18:30:26 -07:00
|
|
|
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
2017-05-07 23:56:11 -07:00
|
|
|
|
2017-08-08 01:19:51 -07:00
|
|
|
local buildHive = nestUtils.buildHive
|
2017-05-07 23:56:11 -07:00
|
|
|
|
2017-05-31 18:46:53 -07:00
|
|
|
local mFloor = math.floor
|
|
|
|
|
2017-11-20 23:27:03 -08:00
|
|
|
-- local buildTendril = tendrilUtils.buildTendril
|
2017-05-31 18:46:53 -07:00
|
|
|
|
2017-06-30 21:36:23 -07:00
|
|
|
local mRandom = math.random
|
|
|
|
|
2017-05-19 00:47:24 -07:00
|
|
|
-- module code
|
2017-05-07 23:56:11 -07:00
|
|
|
|
2017-05-27 21:50:37 -07:00
|
|
|
function baseUtils.findNearbyBase(natives, position)
|
2017-05-11 21:50:06 -07:00
|
|
|
local bases = natives.bases
|
2017-05-27 21:50:37 -07:00
|
|
|
local foundBase
|
2017-05-11 21:50:06 -07:00
|
|
|
local closest = MAGIC_MAXIMUM_NUMBER
|
|
|
|
for i=1,#bases do
|
|
|
|
local base = bases[i]
|
2017-05-19 00:47:24 -07:00
|
|
|
local distance = euclideanDistancePoints(base.x, base.y, position.x, position.y)
|
2017-05-31 18:46:53 -07:00
|
|
|
if (distance <= (BASE_DISTANCE_THRESHOLD + (base.level * 100))) and (distance < closest) then
|
2017-05-11 21:50:06 -07:00
|
|
|
closest = distance
|
2017-05-27 21:50:37 -07:00
|
|
|
foundBase = base
|
2017-05-07 23:56:11 -07:00
|
|
|
end
|
|
|
|
end
|
2017-05-27 21:50:37 -07:00
|
|
|
return foundBase
|
2017-05-19 00:47:24 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
function baseUtils.createBase(regionMap, natives, position, surface, tick)
|
2017-05-07 23:56:11 -07:00
|
|
|
local bases = natives.bases
|
2017-05-31 18:46:53 -07:00
|
|
|
local distance = euclideanDistancePoints(position.x, position.y, 0, 0)
|
2017-05-11 21:50:06 -07:00
|
|
|
local base = {
|
2017-05-19 00:47:24 -07:00
|
|
|
x = position.x,
|
|
|
|
y = position.y,
|
2017-05-11 21:50:06 -07:00
|
|
|
created = tick,
|
|
|
|
alignment = { BASE_ALIGNMENT_NEUTRAL },
|
2017-05-27 21:50:37 -07:00
|
|
|
hives = {},
|
2017-06-07 17:57:24 -07:00
|
|
|
tendrils = {},
|
2017-05-11 21:50:06 -07:00
|
|
|
nests = {},
|
|
|
|
worms = {},
|
2017-05-19 00:47:24 -07:00
|
|
|
eggs = {},
|
2017-05-11 21:50:06 -07:00
|
|
|
upgradePoints = 0,
|
|
|
|
growth = tick,
|
2017-06-30 21:36:23 -07:00
|
|
|
pattern = mRandom(MAGIC_MAXIMUM_BASE_NUMBER),
|
2017-05-31 18:46:53 -07:00
|
|
|
level = mFloor(distance / 200)
|
2017-05-11 21:50:06 -07:00
|
|
|
}
|
2017-06-12 20:16:43 -07:00
|
|
|
if not buildHive(regionMap, base, surface) then
|
2017-05-19 00:47:24 -07:00
|
|
|
return nil
|
2017-06-07 17:57:24 -07:00
|
|
|
end
|
2017-11-20 23:27:03 -08:00
|
|
|
-- buildTendril(regionMap, natives, base, surface, tick)
|
2017-05-07 23:56:11 -07:00
|
|
|
bases[#bases+1] = base
|
2017-05-11 21:50:06 -07:00
|
|
|
return base
|
2017-05-07 23:56:11 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
return baseUtils
|
|
|
|
|