1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-30 21:19:46 +02:00
Rampant/libs/BaseUtils.lua

611 lines
20 KiB
Lua
Raw Normal View History

2019-02-16 06:17:30 +02:00
if baseUtilsG then
return baseUtilsG
end
2017-05-08 08:56:11 +02:00
local baseUtils = {}
-- imports
local mathUtils = require("MathUtils")
2017-05-08 08:56:11 +02:00
local constants = require("Constants")
local chunkPropertyUtils = require("ChunkPropertyUtils")
2019-11-30 02:49:22 +02:00
local mapUtils = require("MapUtils")
2017-06-08 02:57:24 +02:00
2017-05-08 08:56:11 +02:00
-- constants
2019-12-18 03:09:08 +02:00
local FACTION_MUTATION_MAPPING = constants.FACTION_MUTATION_MAPPING
2018-08-02 05:18:52 +02:00
local MAGIC_MAXIMUM_NUMBER = constants.MAGIC_MAXIMUM_NUMBER
2019-02-12 08:30:13 +02:00
local BASE_AI_STATE_DORMANT = constants.BASE_AI_STATE_DORMANT
local BASE_AI_STATE_ACTIVE = constants.BASE_AI_STATE_ACTIVE
local BASE_AI_STATE_WORMS = constants.BASE_AI_STATE_WORMS
local BASE_AI_STATE_NESTS = constants.BASE_AI_STATE_NESTS
local BASE_AI_STATE_OVERDRIVE = constants.BASE_AI_STATE_OVERDRIVE
local BASE_AI_STATE_MUTATE = constants.BASE_AI_STATE_MUTATE
2019-11-30 02:49:22 +02:00
local FACTION_SET = constants.FACTION_SET
2019-11-30 02:49:22 +02:00
local BASE_DEADZONE_TTL = constants.BASE_DEADZONE_TTL
2019-02-12 08:30:13 +02:00
local BASE_AI_MIN_STATE_DURATION = constants.BASE_AI_MIN_STATE_DURATION
local BASE_AI_MIN_TEMPERAMENT_DURATION = constants.BASE_AI_MIN_TEMPERAMENT_DURATION
local BASE_AI_MAX_STATE_DURATION = constants.BASE_AI_MAX_STATE_DURATION
local BASE_AI_MAX_TEMPERAMENT_DURATION = constants.BASE_AI_MAX_TEMPERAMENT_DURATION
2018-02-05 02:07:25 +02:00
local BASE_UPGRADE = constants.BASE_UPGRADE
2019-11-30 02:49:22 +02:00
local HIVE_BUILDINGS_COST = constants.HIVE_BUILDINGS_COST
local BASE_DISTANCE_THRESHOLD = constants.BASE_DISTANCE_THRESHOLD
local BASE_DISTANCE_LEVEL_BONUS = constants.BASE_DISTANCE_LEVEL_BONUS
local BASE_DISTANCE_TO_EVO_INDEX = constants.BASE_DISTANCE_TO_EVO_INDEX
2017-05-08 08:56:11 +02:00
2018-01-26 07:48:12 +02:00
local BASE_COLLECTION_THRESHOLD = constants.BASE_COLLECTION_THRESHOLD
local CHUNK_SIZE = constants.CHUNK_SIZE
2017-05-08 08:56:11 +02:00
-- imported functions
2019-02-12 08:30:13 +02:00
local randomTickEvent = mathUtils.randomTickEvent
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
2017-05-08 08:56:11 +02:00
2019-11-30 02:49:22 +02:00
local getChunkByPosition = mapUtils.getChunkByPosition
local gaussianRandomRange = mathUtils.gaussianRandomRange
2019-11-30 02:49:22 +02:00
local linearInterpolation = mathUtils.linearInterpolation
2017-06-01 03:46:53 +02:00
local mFloor = math.floor
local mMin = math.min
local mMax = math.max
2019-11-30 02:49:22 +02:00
local distort = mathUtils.distort
local getChunkBase = chunkPropertyUtils.getChunkBase
local setChunkBase = chunkPropertyUtils.setChunkBase
2017-06-01 03:46:53 +02:00
2019-11-30 02:49:22 +02:00
local getResourceGenerator = chunkPropertyUtils.getResourceGenerator
2020-05-20 04:37:16 +02:00
local next = next
local mRandom = math.random
2017-05-19 09:47:24 +02:00
-- module code
2017-05-08 08:56:11 +02:00
2021-02-20 07:41:30 +02:00
local function evoToTier(native, evolutionFactor)
2019-11-30 02:49:22 +02:00
local v
2019-12-16 03:16:56 +02:00
for i=10,1,-1 do
2021-02-20 07:41:30 +02:00
if native.evoToTierMapping[i] <= evolutionFactor then
2019-11-30 02:49:22 +02:00
v = i
if mRandom() <= 0.65 then
break
2019-03-12 08:03:26 +02:00
end
2019-10-19 21:13:48 +02:00
end
2019-03-12 08:03:26 +02:00
end
2019-11-30 02:49:22 +02:00
return v
2018-08-02 05:18:52 +02:00
end
2019-11-30 02:49:22 +02:00
function baseUtils.findNearbyBase(map, chunk)
local x = chunk.x
local y = chunk.y
local foundBase = getChunkBase(map, chunk)
if foundBase then
2019-10-19 21:13:48 +02:00
return foundBase
end
2021-02-20 07:41:30 +02:00
local bases = map.native.bases
2020-08-08 22:38:15 +02:00
local closest = MAGIC_MAXIMUM_NUMBER
2020-05-20 04:37:16 +02:00
for _, base in pairs(bases) do
2019-10-19 21:13:48 +02:00
local distance = euclideanDistancePoints(base.x, base.y, x, y)
2020-08-08 22:38:15 +02:00
if (distance <= base.distanceThreshold) and (distance < closest) then
closest = distance
2019-10-19 21:13:48 +02:00
foundBase = base
end
2017-05-08 08:56:11 +02:00
end
2019-02-03 08:01:28 +02:00
2017-05-28 06:50:37 +02:00
return foundBase
2017-05-19 09:47:24 +02:00
end
2021-02-20 07:41:30 +02:00
local function findBaseMutation(native, targetEvolution)
local tier = evoToTier(native, targetEvolution or native.evolutionLevel)
local alignments = native.evolutionTableAlignment[tier]
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
local roll = mRandom()
for i=1,#alignments do
local alignment = alignments[i]
2019-11-30 02:49:22 +02:00
roll = roll - alignment[1]
2019-11-04 08:19:22 +02:00
2019-11-30 02:49:22 +02:00
if (roll <= 0) then
return alignment[2]
end
end
2019-11-30 02:49:22 +02:00
return alignments[#alignments]
end
2019-02-03 08:01:28 +02:00
2021-02-20 07:41:30 +02:00
local function initialEntityUpgrade(baseAlignment, tier, maxTier, native, useHiveType)
local evolutionTable = native.buildingEvolveLookup
2019-11-30 02:49:22 +02:00
local entity
2019-12-16 03:16:56 +02:00
local useTier
local tierRoll = mRandom()
if (tierRoll < 0.4) then
useTier = maxTier
elseif (tierRoll < 0.7) then
useTier = mMax(maxTier - 1, tier)
elseif (tierRoll < 0.9) then
useTier = mMax(maxTier - 2, tier)
else
useTier = mMax(maxTier - 3, tier)
end
local upgrades = evolutionTable[baseAlignment][useTier]
if upgrades then
if useHiveType then
for ui=1,#upgrades do
local upgrade = upgrades[ui]
if upgrade[3] == useHiveType then
entity = upgrade[2][mRandom(#upgrade[2])]
break
2019-03-12 08:03:26 +02:00
end
2019-12-16 03:16:56 +02:00
end
2020-05-24 05:47:14 +02:00
end
if not entity then
2019-12-16 03:16:56 +02:00
local roll = mRandom()
2019-11-30 02:49:22 +02:00
2019-12-16 03:16:56 +02:00
for ui=1,#upgrades do
local upgrade = upgrades[ui]
2019-11-30 02:49:22 +02:00
2019-12-16 03:16:56 +02:00
roll = roll - upgrade[1]
2019-11-30 02:49:22 +02:00
2019-12-16 03:16:56 +02:00
if (roll <= 0) then
entity = upgrade[2][mRandom(#upgrade[2])]
break
2019-03-12 08:03:26 +02:00
end
end
2019-11-04 08:19:22 +02:00
end
2019-11-30 02:49:22 +02:00
end
2019-12-16 03:16:56 +02:00
2019-11-30 02:49:22 +02:00
return entity
end
2021-02-20 07:41:30 +02:00
local function entityUpgrade(baseAlignment, tier, maxTier, originalEntity, native)
local buildingHiveTypeLookup = native.buildingHiveTypeLookup
local evolutionTable = native.upgradeLookup
2019-11-30 02:49:22 +02:00
local entity
2019-12-18 03:09:08 +02:00
local hiveType = buildingHiveTypeLookup[originalEntity.name]
2019-11-30 02:49:22 +02:00
2019-12-18 03:09:08 +02:00
for t=maxTier,tier,-1 do
local factionLookup = evolutionTable[baseAlignment][t]
local upgrades = factionLookup[hiveType]
if not upgrades then
local mapTypes = FACTION_MUTATION_MAPPING[hiveType]
for i=1, #mapTypes do
local upgrade = factionLookup[mapTypes[i]]
if upgrade and (#upgrade > 0) then
entity = upgrade[mRandom(#upgrade)]
if mRandom() < 0.55 then
return entity
end
end
end
elseif (#upgrades > 0) then
2019-11-30 02:49:22 +02:00
entity = upgrades[mRandom(#upgrades)]
2019-12-16 03:16:56 +02:00
if mRandom() < 0.55 then
2020-05-24 05:47:14 +02:00
return entity
2019-03-12 08:03:26 +02:00
end
2019-11-04 08:19:22 +02:00
end
end
return entity
end
2021-02-20 07:41:30 +02:00
local function findEntityUpgrade(baseAlignment, currentEvo, evoIndex, originalEntity, native, evolve)
2019-11-30 02:49:22 +02:00
local adjCurrentEvo = mMax(
2021-02-20 07:41:30 +02:00
((baseAlignment ~= native.enemyAlignmentLookup[originalEntity.name]) and 0) or currentEvo,
2019-11-30 02:49:22 +02:00
0
)
2021-02-20 07:41:30 +02:00
local tier = evoToTier(native, adjCurrentEvo)
local maxTier = evoToTier(native, evoIndex)
2019-11-30 02:49:22 +02:00
if (tier > maxTier) then
return nil
end
2019-12-16 03:16:56 +02:00
2019-11-30 02:49:22 +02:00
if evolve then
2021-02-20 07:41:30 +02:00
local chunk = getChunkByPosition(native.map, originalEntity.position)
local makeHive = (chunk ~= -1) and (getResourceGenerator(native.map, chunk) > 0) and (mRandom() < 0.2)
return initialEntityUpgrade(baseAlignment, tier, maxTier, native, (makeHive and "hive"))
2019-11-30 02:49:22 +02:00
else
2021-02-20 07:41:30 +02:00
return entityUpgrade(baseAlignment, tier, maxTier, originalEntity, native)
2019-12-16 03:16:56 +02:00
end
2019-11-30 02:49:22 +02:00
end
2021-02-20 07:41:30 +02:00
local function findBaseInitialAlignment(native, evoIndex)
2020-05-20 04:37:16 +02:00
local dev = evoIndex * 0.3
local evoTop = gaussianRandomRange(evoIndex - dev, dev, 0, evoIndex)
2019-11-30 02:49:22 +02:00
local result
if mRandom() < 0.05 then
2021-02-20 07:41:30 +02:00
result = {findBaseMutation(native, evoTop), findBaseMutation(native, evoTop)}
2019-11-30 02:49:22 +02:00
else
2021-02-20 07:41:30 +02:00
result = {findBaseMutation(native, evoTop)}
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
return result
end
2021-02-20 07:41:30 +02:00
function baseUtils.recycleBases(native, tick)
local bases = native.bases
local id, base = next(bases, native.map.recycleBaseIterator)
-- for _=1,2 do
if not id then
native.map.recycleBaseIterator = nil
return
else
if ((tick - base.tick) > BASE_COLLECTION_THRESHOLD) then
local nextId
nextId = next(bases, id)
bases[id] = nil
id = nextId
2020-05-20 04:37:16 +02:00
else
2021-02-20 07:41:30 +02:00
id = next(bases, id)
2019-02-03 08:01:28 +02:00
end
2018-01-26 07:48:12 +02:00
end
2021-02-20 07:41:30 +02:00
-- end
native.map.recycleBaseIterator = id
2018-01-26 07:48:12 +02:00
end
2021-02-20 07:41:30 +02:00
function baseUtils.upgradeEntity(entity, baseAlignment, native, disPos, evolve)
local surface = native.surface
local position = entity.position
2019-11-04 08:19:22 +02:00
local currentEvo = entity.prototype.build_base_evolution_requirement or 0
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
if not baseAlignment[1] then
2019-03-12 08:03:26 +02:00
entity.destroy()
2019-02-03 08:01:28 +02:00
return nil
2019-11-04 08:19:22 +02:00
end
2019-03-12 08:03:26 +02:00
local distance = mMin(1, euclideanDistancePoints(position.x, position.y, 0, 0) * BASE_DISTANCE_TO_EVO_INDEX)
2021-02-20 07:41:30 +02:00
local evoIndex = mMax(distance, native.evolutionLevel)
2019-11-30 02:49:22 +02:00
local spawnerName = findEntityUpgrade(baseAlignment[mRandom(#baseAlignment)],
currentEvo,
evoIndex,
entity,
2021-02-20 07:41:30 +02:00
native,
2019-12-16 03:16:56 +02:00
evolve)
if spawnerName then
2019-03-12 08:03:26 +02:00
entity.destroy()
2021-02-20 07:41:30 +02:00
local name = native.buildingSpaceLookup[spawnerName] or spawnerName
local query = native.map.upgradeEntityQuery
2019-11-30 02:49:22 +02:00
query.name = name
query.position = disPos or position
if not surface.can_place_entity(query) then
local newPosition = surface.find_non_colliding_position(
name,
disPos or position,
CHUNK_SIZE,
1,
true
)
query.position = newPosition or disPos or position
2019-02-03 08:01:28 +02:00
end
2018-01-14 09:07:29 +02:00
2019-11-30 02:49:22 +02:00
query.name = spawnerName
2020-11-28 02:29:25 +02:00
if remote.interfaces["kr-creep"] then
remote.call("kr-creep", "spawn_creep_at_position", surface, query.position)
end
2019-11-30 02:49:22 +02:00
return surface.create_entity(query)
2019-02-13 03:12:32 +02:00
end
2020-05-24 05:47:14 +02:00
return entity
2019-02-12 08:30:13 +02:00
end
2021-02-20 07:41:30 +02:00
local function upgradeBase(native, base)
2019-11-30 02:49:22 +02:00
local baseAlignment = base.alignment
2019-02-12 08:30:13 +02:00
local roll = mRandom()
2019-11-30 02:49:22 +02:00
if baseAlignment[2] then
2019-02-12 08:30:13 +02:00
if (roll < 0.05) then
2019-11-30 02:49:22 +02:00
baseAlignment[2] = nil
2021-02-20 07:41:30 +02:00
baseAlignment[1] = findBaseMutation(native)
2019-11-30 02:49:22 +02:00
elseif (roll < 0.25) then
2021-02-20 07:41:30 +02:00
baseAlignment[1] = findBaseMutation(native)
2019-02-12 08:30:13 +02:00
else
2021-02-20 07:41:30 +02:00
baseAlignment[2] = findBaseMutation(native)
2019-02-12 08:30:13 +02:00
end
return true
2019-11-30 02:49:22 +02:00
else
2019-02-12 08:30:13 +02:00
if (roll < 0.85) then
2021-02-20 07:41:30 +02:00
base.alignment[1] = findBaseMutation(native)
2019-02-12 08:30:13 +02:00
else
2021-02-20 07:41:30 +02:00
base.alignment[2] = findBaseMutation(native)
2019-02-12 08:30:13 +02:00
end
2019-02-03 08:01:28 +02:00
return true
end
end
2021-02-20 07:41:30 +02:00
function baseUtils.processBase(chunk, native, tick, base)
2019-11-30 02:49:22 +02:00
if not base.alignment[1] then
base.state = BASE_AI_STATE_DORMANT
return
end
2019-11-04 08:19:22 +02:00
2021-02-20 07:41:30 +02:00
local surface = native.surface
local map = native.map
2019-11-30 02:49:22 +02:00
local point = map.position
2019-11-30 02:49:22 +02:00
point.x = chunk.x + (CHUNK_SIZE * mRandom())
point.y = chunk.y + (CHUNK_SIZE * mRandom())
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
if (base.state == BASE_AI_STATE_ACTIVE) then
local entity = surface.find_entities_filtered(map.filteredEntitiesPointQueryLimited)
2021-02-20 07:41:30 +02:00
local cost = (native.costLookup[entity.name] or MAGIC_MAXIMUM_NUMBER)
2019-11-30 02:49:22 +02:00
if entity and (base.points >= cost) then
local newEntity = baseUtils.upgradeEntity(entity,
surface,
base.alignment,
2021-02-20 07:41:30 +02:00
native)
2019-11-30 02:49:22 +02:00
if newEntity then
base.points = base.points - cost
end
2019-02-03 08:01:28 +02:00
end
2019-02-12 08:30:13 +02:00
elseif (base.state == BASE_AI_STATE_MUTATE) then
2019-02-03 08:01:28 +02:00
if (base.points >= BASE_UPGRADE) then
2021-02-20 07:41:30 +02:00
if upgradeBase(native, base) then
2019-02-03 08:01:28 +02:00
base.points = base.points - BASE_UPGRADE
end
end
end
2019-02-12 08:30:13 +02:00
if (base.state == BASE_AI_STATE_OVERDRIVE) then
2021-02-20 07:41:30 +02:00
base.points = base.points + (native.baseIncrement * 5)
2019-02-12 08:30:13 +02:00
elseif (base.state ~= BASE_AI_STATE_DORMANT) then
2021-02-20 07:41:30 +02:00
base.points = base.points + native.baseIncrement
2019-02-12 08:30:13 +02:00
end
if (base.temperamentTick <= tick) then
2019-10-19 21:13:48 +02:00
base.temperament = mRandom()
2019-11-30 02:49:22 +02:00
base.temperamentTick = randomTickEvent(tick,
BASE_AI_MIN_TEMPERAMENT_DURATION,
BASE_AI_MAX_TEMPERAMENT_DURATION)
2019-02-12 08:30:13 +02:00
end
if (base.stateTick <= tick) then
2021-02-20 07:41:30 +02:00
local roll = mRandom() * mMax(1 - native.evolutionLevel, 0.15)
if (roll > native.temperament) then
2019-10-19 21:13:48 +02:00
base.state = BASE_AI_STATE_DORMANT
else
roll = mRandom()
if (roll < 0.70) then
base.state = BASE_AI_STATE_ACTIVE
elseif (roll < 0.80) then
base.state = BASE_AI_STATE_NESTS
2019-02-12 08:30:13 +02:00
elseif (roll < 0.90) then
2019-10-19 21:13:48 +02:00
base.state = BASE_AI_STATE_WORMS
2019-02-12 08:30:13 +02:00
elseif (roll < 0.975) then
2019-10-19 21:13:48 +02:00
base.state = BASE_AI_STATE_OVERDRIVE
2019-02-12 08:30:13 +02:00
else
2019-10-19 21:13:48 +02:00
base.state = BASE_AI_STATE_MUTATE
end
end
2019-11-30 02:49:22 +02:00
base.stateTick = randomTickEvent(tick,
BASE_AI_MIN_STATE_DURATION,
BASE_AI_MAX_STATE_DURATION)
2019-02-12 08:30:13 +02:00
end
2019-11-04 08:19:22 +02:00
base.tick = tick
end
2021-02-20 07:41:30 +02:00
function baseUtils.createBase(native, chunk, tick, rebuilding)
local x = chunk.x
local y = chunk.y
local distance = euclideanDistancePoints(x, y, 0, 0)
2019-11-30 02:49:22 +02:00
local meanLevel = mFloor(distance * 0.005)
2019-02-03 08:01:28 +02:00
local distanceIndex = mMin(1, distance * BASE_DISTANCE_TO_EVO_INDEX)
2021-02-20 07:41:30 +02:00
local evoIndex = mMax(distanceIndex, native.evolutionLevel)
2019-11-30 02:49:22 +02:00
local baseTick = tick
2019-11-04 08:19:22 +02:00
local alignment
2021-02-20 07:41:30 +02:00
if (not rebuilding) and (mRandom() < native.deadZoneFrequency) then
2019-11-30 02:49:22 +02:00
alignment = {}
baseTick = BASE_DEADZONE_TTL
else
2021-02-20 07:41:30 +02:00
alignment = findBaseInitialAlignment(native, evoIndex) or {"neutral"}
end
2019-02-03 08:01:28 +02:00
local baseLevel = gaussianRandomRange(meanLevel, meanLevel * 0.3, meanLevel * 0.50, meanLevel * 1.50)
2019-11-30 02:49:22 +02:00
local baseDistanceThreshold = gaussianRandomRange(BASE_DISTANCE_THRESHOLD,
BASE_DISTANCE_THRESHOLD * 0.2,
BASE_DISTANCE_THRESHOLD * 0.75,
BASE_DISTANCE_THRESHOLD * 1.50)
local distanceThreshold = (baseLevel * BASE_DISTANCE_LEVEL_BONUS) + baseDistanceThreshold
2017-05-12 06:50:06 +02:00
local base = {
2019-02-03 08:01:28 +02:00
x = x,
y = y,
distanceThreshold = distanceThreshold,
2019-11-30 02:49:22 +02:00
tick = baseTick,
alignment = alignment,
2019-02-12 08:30:13 +02:00
state = BASE_AI_STATE_DORMANT,
stateTick = 0,
temperamentTick = 0,
createdTick = tick,
2019-02-12 08:30:13 +02:00
temperament = 0,
2020-05-20 04:37:16 +02:00
points = 0,
2021-02-20 07:41:30 +02:00
id = native.baseId
2017-05-12 06:50:06 +02:00
}
2021-02-20 07:41:30 +02:00
native.baseId = native.baseId + 1
2021-02-20 07:41:30 +02:00
setChunkBase(native.map, chunk, base)
2021-02-20 07:41:30 +02:00
native.bases[base.id] = base
2019-02-03 08:01:28 +02:00
2017-05-12 06:50:06 +02:00
return base
2017-05-08 08:56:11 +02:00
end
2021-02-20 07:41:30 +02:00
function baseUtils.rebuildNativeTables(native, rg)
2019-11-30 02:49:22 +02:00
local alignmentSet = {}
2021-02-20 07:41:30 +02:00
native.evolutionTableAlignment = alignmentSet
2019-11-30 02:49:22 +02:00
local buildingSpaceLookup = {}
2021-02-20 07:41:30 +02:00
native.buildingSpaceLookup = buildingSpaceLookup
2019-11-30 02:49:22 +02:00
local enemyAlignmentLookup = {}
2021-02-20 07:41:30 +02:00
native.enemyAlignmentLookup = enemyAlignmentLookup
2019-11-30 02:49:22 +02:00
local evoToTierMapping = {}
2021-02-20 07:41:30 +02:00
native.evoToTierMapping = evoToTierMapping
2019-11-30 02:49:22 +02:00
local upgradeLookup = {}
2021-02-20 07:41:30 +02:00
native.upgradeLookup = upgradeLookup
2019-11-30 02:49:22 +02:00
local buildingEvolveLookup = {}
2021-02-20 07:41:30 +02:00
native.buildingEvolveLookup = buildingEvolveLookup
2019-11-30 02:49:22 +02:00
local costLookup = {}
2021-02-20 07:41:30 +02:00
native.costLookup = costLookup
2019-11-30 02:49:22 +02:00
local buildingHiveTypeLookup = {}
2021-02-20 07:41:30 +02:00
native.buildingHiveTypeLookup = buildingHiveTypeLookup
2019-11-30 02:49:22 +02:00
for i=1,10 do
2021-02-14 06:49:54 +02:00
evoToTierMapping[#evoToTierMapping+1] = (((i - 1) * 0.1) ^ 0.5) - 0.05
2019-11-30 02:49:22 +02:00
end
for i=1,#FACTION_SET do
local faction = FACTION_SET[i]
local factionUpgradeLookup = {}
upgradeLookup[faction.type] = factionUpgradeLookup
local factionBuildingPicker = {}
buildingEvolveLookup[faction.type] = factionBuildingPicker
for t=1,10 do
local alignments = alignmentSet[t]
if not alignments then
alignments = {}
alignmentSet[t] = alignments
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
--[[
alignments table is a table that is used for selecting what factions are available
to pick given an evolution level.
evolutionTable is a table that given a faction allows the selection of a building
2019-12-16 03:16:56 +02:00
type based on the propabilities given. Once the the building type is selected given
2019-11-30 02:49:22 +02:00
a faction, then the evolution decides what level of building to select
--]]
local factionAcceptRate = faction.acceptRate
local low = factionAcceptRate[1]
local high = factionAcceptRate[2]
if (low <= t) and (t <= high) then
alignments[#alignments+1] = {
distort(rg,
linearInterpolation((t - low) / (high - low), factionAcceptRate[3], factionAcceptRate[4])),
faction.type
}
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
local tieredUpgradeBuildingSet = factionUpgradeLookup[t]
if not tieredUpgradeBuildingSet then
tieredUpgradeBuildingSet = {}
factionUpgradeLookup[t] = tieredUpgradeBuildingSet
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
local tieredBuildingPickerSet = factionBuildingPicker[t]
if not tieredBuildingPickerSet then
tieredBuildingPickerSet = {}
factionBuildingPicker[t] = tieredBuildingPickerSet
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
for b=1,#faction.buildings do
local building = faction.buildings[b]
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
local buildingSet = tieredUpgradeBuildingSet[building.type]
if not buildingSet then
buildingSet = {}
tieredUpgradeBuildingSet[building.type] = buildingSet
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
local variationSet = {}
2021-02-20 07:41:30 +02:00
for v=1,native.ENEMY_VARIATIONS do
2019-11-30 02:49:22 +02:00
local entry = faction.type .. "-" .. building.name .. "-v" .. v .. "-t" .. t .. "-rampant"
enemyAlignmentLookup[entry] = faction.type
local proxyEntity = "entity-proxy-" .. building.type .. "-t" .. t .. "-rampant"
buildingSpaceLookup[entry] = proxyEntity
costLookup[entry] = HIVE_BUILDINGS_COST[building.type]
buildingHiveTypeLookup[entry] = building.type
if not buildingHiveTypeLookup[proxyEntity] then
buildingHiveTypeLookup[proxyEntity] = building.type
end
variationSet[#variationSet+1] = entry
end
2019-11-30 02:49:22 +02:00
local buildingAcceptRate = building.acceptRate
2019-02-03 08:01:28 +02:00
2021-02-14 06:49:54 +02:00
local buildingLow = buildingAcceptRate[1]
local buildingHigh = buildingAcceptRate[2]
if (buildingLow <= t) and (t <= buildingHigh) then
2019-11-30 02:49:22 +02:00
for vi=1,#variationSet do
local variation = variationSet[vi]
buildingSet[#buildingSet+1] = variation
end
tieredBuildingPickerSet[#tieredBuildingPickerSet+1] = {
distort(rg,
2021-02-14 06:49:54 +02:00
linearInterpolation((t - buildingLow) / (buildingHigh - buildingLow),
buildingAcceptRate[3],
buildingAcceptRate[4])),
2019-11-30 02:49:22 +02:00
variationSet,
building.type
}
end
2019-02-03 08:01:28 +02:00
2019-11-30 02:49:22 +02:00
end
end
2019-02-03 08:01:28 +02:00
end
2018-02-05 05:24:28 +02:00
2019-11-30 02:49:22 +02:00
for t=1,10 do
local alignments = alignmentSet[t]
local totalAlignment = 0
for i=1,#alignments do
totalAlignment = totalAlignment + alignments[i][1]
end
for i=1,#alignments do
alignments[i][1] = alignments[i][1] / totalAlignment
end
2019-02-14 07:53:31 +02:00
2019-11-30 02:49:22 +02:00
for fi=1,#FACTION_SET do
local faction = FACTION_SET[fi]
local factionBuildingSet = buildingEvolveLookup[faction.type][t]
local totalBuildingSet = 0
for i=1,#factionBuildingSet do
totalBuildingSet = totalBuildingSet + factionBuildingSet[i][1]
end
for i=1,#factionBuildingSet do
factionBuildingSet[i][1] = factionBuildingSet[i][1] / totalBuildingSet
end
end
2019-02-13 07:50:25 +02:00
end
2019-12-16 03:16:56 +02:00
2021-02-20 07:41:30 +02:00
local evoIndex = evoToTier(native, native.evolutionLevel)
2020-02-02 03:55:58 +02:00
2021-02-20 07:41:30 +02:00
for _,base in pairs(native.bases) do
2020-02-02 03:55:58 +02:00
for x=1,#base.alignment do
2020-02-02 04:12:14 +02:00
local alignment = base.alignment[x]
2021-02-20 07:41:30 +02:00
if not native.buildingEvolveLookup[alignment] then
base.alignment = findBaseInitialAlignment(native, evoIndex)
2020-02-02 03:55:58 +02:00
break
end
end
end
end
2019-02-16 06:17:30 +02:00
baseUtilsG = baseUtils
2017-05-08 08:56:11 +02:00
return baseUtils