mirror of
https://github.com/veden/Rampant.git
synced 2024-12-30 21:19:46 +02:00
fixed base mutation
This commit is contained in:
parent
cee6ac20d4
commit
791f4c3c23
@ -158,6 +158,20 @@ local mRandom = math.random
|
|||||||
|
|
||||||
-- module code
|
-- module code
|
||||||
|
|
||||||
|
local function nonRepeatingRandom(evoTable, rg)
|
||||||
|
local ordering = {}
|
||||||
|
for evo in pairs(evoTable) do
|
||||||
|
ordering[#ordering+1] = evo
|
||||||
|
end
|
||||||
|
for i=#ordering,1,-1 do
|
||||||
|
local s = rg(i)
|
||||||
|
local t = ordering[i]
|
||||||
|
ordering[i] = ordering[s]
|
||||||
|
ordering[s] = t
|
||||||
|
end
|
||||||
|
return ordering
|
||||||
|
end
|
||||||
|
|
||||||
local function normalizeProbabilities(probabilityTable)
|
local function normalizeProbabilities(probabilityTable)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
@ -246,8 +260,8 @@ local function findBaseInitialAlignment(evoIndex, natives, evolutionTable)
|
|||||||
|
|
||||||
local pickedEvo
|
local pickedEvo
|
||||||
local alignment
|
local alignment
|
||||||
for _,evo in pairs(natives.evolutionTableAlignmentOrder) do
|
for i=1,#natives.evolutionTableAlignmentOrder do
|
||||||
|
local evo = natives.evolutionTableAlignmentOrder[i]
|
||||||
local entitySet = evolutionTable[evo]
|
local entitySet = evolutionTable[evo]
|
||||||
if (evo <= evoTop) and entitySet and (#entitySet > 0) then
|
if (evo <= evoTop) and entitySet and (#entitySet > 0) then
|
||||||
if not pickedEvo then
|
if not pickedEvo then
|
||||||
@ -336,12 +350,23 @@ function baseUtils.upgradeEntity(entity, surface, baseAlignment, natives, evolut
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function findMutation(natives, evolutionFactor)
|
local function findMutation(natives, evolutionFactor)
|
||||||
natives.evolutionTableAlignmentOrder
|
local shuffled = nonRepeatingRandom(natives.evolutionTableAlignment, natives.randomGenerator)
|
||||||
|
local evoTable = natives.evolutionTableAlignment
|
||||||
|
local alignment
|
||||||
|
|
||||||
|
for i=1,#shuffled do
|
||||||
|
local evo = shuffled[i]
|
||||||
|
if (evo <= evolutionFactor) then
|
||||||
|
local alignmentSet = evoTable[evo]
|
||||||
|
alignment = alignmentSet[mRandom(#alignmentSet)]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return alignment
|
||||||
end
|
end
|
||||||
|
|
||||||
local function upgradeBase(natives, evolutionFactor, base)
|
local function upgradeBase(natives, evolutionFactor, base)
|
||||||
print("currentAlignment", serpent.dump(base.alignment))
|
|
||||||
|
|
||||||
local alignmentCount = #base.alignment
|
local alignmentCount = #base.alignment
|
||||||
|
|
||||||
local roll = mRandom()
|
local roll = mRandom()
|
||||||
@ -379,23 +404,19 @@ function baseUtils.processBase(map, chunk, surface, natives, tick, base, evoluti
|
|||||||
local entity
|
local entity
|
||||||
local cost
|
local cost
|
||||||
local choice = mRandom()
|
local choice = mRandom()
|
||||||
print(base, choice, base.points, base.state)
|
|
||||||
|
|
||||||
if (base.state == BASE_AI_STATE_NESTS) or ((base.state == BASE_AI_STATE_ACTIVE) and (choice < 0.5)) then
|
if (base.state == BASE_AI_STATE_NESTS) or ((base.state == BASE_AI_STATE_ACTIVE) and (choice < 0.5)) then
|
||||||
if (base.points >= BASE_SPAWNER_UPGRADE) then
|
if (base.points >= BASE_SPAWNER_UPGRADE) then
|
||||||
print("new nest")
|
|
||||||
entity = surface.find_entities_filtered(map.filteredEntitiesSpawnerQueryLimited)
|
entity = surface.find_entities_filtered(map.filteredEntitiesSpawnerQueryLimited)
|
||||||
cost = BASE_SPAWNER_UPGRADE
|
cost = BASE_SPAWNER_UPGRADE
|
||||||
end
|
end
|
||||||
elseif (base.state == BASE_AI_STATE_WORMS) or (base.state == BASE_AI_STATE_ACTIVE) then
|
elseif (base.state == BASE_AI_STATE_WORMS) or (base.state == BASE_AI_STATE_ACTIVE) then
|
||||||
if (base.points >= BASE_WORM_UPGRADE) then
|
if (base.points >= BASE_WORM_UPGRADE) then
|
||||||
print("new worm")
|
|
||||||
entity = surface.find_entities_filtered(map.filteredEntitiesWormQueryLimited)
|
entity = surface.find_entities_filtered(map.filteredEntitiesWormQueryLimited)
|
||||||
cost = BASE_WORM_UPGRADE
|
cost = BASE_WORM_UPGRADE
|
||||||
end
|
end
|
||||||
elseif (base.state == BASE_AI_STATE_MUTATE) then
|
elseif (base.state == BASE_AI_STATE_MUTATE) then
|
||||||
if (base.points >= BASE_UPGRADE) then
|
if (base.points >= BASE_UPGRADE) then
|
||||||
print("new mutation")
|
|
||||||
if upgradeBase(natives, evolutionFactor, base) then
|
if upgradeBase(natives, evolutionFactor, base) then
|
||||||
base.points = base.points - BASE_UPGRADE
|
base.points = base.points - BASE_UPGRADE
|
||||||
end
|
end
|
||||||
@ -403,7 +424,6 @@ function baseUtils.processBase(map, chunk, surface, natives, tick, base, evoluti
|
|||||||
end
|
end
|
||||||
|
|
||||||
if entity and (#entity > 0) then
|
if entity and (#entity > 0) then
|
||||||
print("upgrading")
|
|
||||||
baseUtils.upgradeEntity(entity[mRandom(#entity)], surface, base.alignment[mRandom(#base.alignment)], natives, evolutionFactor)
|
baseUtils.upgradeEntity(entity[mRandom(#entity)], surface, base.alignment[mRandom(#base.alignment)], natives, evolutionFactor)
|
||||||
base.points = base.points - cost
|
base.points = base.points - cost
|
||||||
end
|
end
|
||||||
@ -520,20 +540,6 @@ local function fileAlignment(baseAlignment, evolution, evolutionTable)
|
|||||||
eTable[#eTable+1] = baseAlignment
|
eTable[#eTable+1] = baseAlignment
|
||||||
end
|
end
|
||||||
|
|
||||||
local function nonRepeatingRandom(evoTable, rg)
|
|
||||||
local ordering = {}
|
|
||||||
for evo in pairs(evoTable) do
|
|
||||||
ordering[#ordering+1] = evo
|
|
||||||
end
|
|
||||||
for i=#ordering,1,-1 do
|
|
||||||
local s = rg(i)
|
|
||||||
local t = ordering[i]
|
|
||||||
ordering[i] = ordering[s]
|
|
||||||
ordering[s] = t
|
|
||||||
end
|
|
||||||
return ordering
|
|
||||||
end
|
|
||||||
|
|
||||||
local function processUnitClass(biterVariation, biterTier, spitterVariation, spitterTier, wormVariation, wormTier, surface, natives, baseAlignment, baseAlignmentString)
|
local function processUnitClass(biterVariation, biterTier, spitterVariation, spitterTier, wormVariation, wormTier, surface, natives, baseAlignment, baseAlignmentString)
|
||||||
local position = { x = 0, y = 0 }
|
local position = { x = 0, y = 0 }
|
||||||
|
|
||||||
@ -795,6 +801,19 @@ function baseUtils.rebuildNativeTables(natives, surface, rg)
|
|||||||
"spawner")
|
"spawner")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- if settings.startup["rampant-energyEnemy"].value then
|
||||||
|
-- processUnitClass(0,
|
||||||
|
-- 0,
|
||||||
|
-- SPAWNER_NEST_VARIATIONS,
|
||||||
|
-- SPAWNER_NEST_TIERS,
|
||||||
|
-- SPAWNER_WORM_VARIATIONS,
|
||||||
|
-- SPAWNER_WORM_TIERS,
|
||||||
|
-- surface,
|
||||||
|
-- natives,
|
||||||
|
-- BASE_ALIGNMENT_SPAWNER,
|
||||||
|
-- "spawner")
|
||||||
|
-- end
|
||||||
|
|
||||||
natives.evolutionTableUnitSpawner = normalizeProbabilities(natives.evolutionTableUnitSpawner)
|
natives.evolutionTableUnitSpawner = normalizeProbabilities(natives.evolutionTableUnitSpawner)
|
||||||
natives.evolutionTableWorm = normalizeProbabilities(natives.evolutionTableWorm)
|
natives.evolutionTableWorm = normalizeProbabilities(natives.evolutionTableWorm)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user