mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
Centralize base points manipulation
- Centralized base points manipulation and chat messaging - Bases can no longer spend points that exceed the overflow limit
This commit is contained in:
parent
c0bae50774
commit
1bf1825320
@ -12,11 +12,13 @@ Version: 3.2.0
|
||||
- Fixed worm range scaler setting not adjusting prepareRange so worms could shoot without being out of the ground. (Thanks Garrotte)
|
||||
- When a faction is removed during play alignment table will default to the neutral faction to prevent alignment table being nil
|
||||
- Fixed settler groups not respecting expansion map setting for min and max time
|
||||
- Bases can no longer spend points that exceed the overflow limit
|
||||
Optimizations:
|
||||
- Moved most constants out of global
|
||||
- Removed new enemy variations setting
|
||||
- Dropped number of enemy levels see during the game from 10 to 6, new tiers will now appear at 0, 0.25, 0.5, 0.75, 0.85, 0.925
|
||||
- Moved neturalObject scan chunk to after a chunk is determined to be passable
|
||||
- Centralized base points manipulation and chat messaging
|
||||
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 3.1.2
|
||||
|
30
control.lua
30
control.lua
@ -152,6 +152,8 @@ local cleanSquads = squadAttack.cleanSquads
|
||||
local upgradeEntity = baseUtils.upgradeEntity
|
||||
local rebuildNativeTables = baseUtils.rebuildNativeTables
|
||||
|
||||
local modifyBasePoints = baseUtils.modifyBasePoints
|
||||
|
||||
local tRemove = table.remove
|
||||
|
||||
local sFind = string.find
|
||||
@ -177,11 +179,7 @@ local function onIonCannonFired(event)
|
||||
if base then
|
||||
base.ionCannonBlasts = base.ionCannonBlasts + 1
|
||||
rallyUnits(chunk, map, event.tick, base)
|
||||
base.unitPoints = base.unitPoints + 4000
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. 4000 .. ". [Ion Cannon] Total: " ..
|
||||
string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
modifyBasePoints(base, 4000, "Ion Cannon")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -467,10 +465,7 @@ local function onDeath(event)
|
||||
base.damagedBy[damageTypeName] = (base.damagedBy[damageTypeName] or 0) + 0.01
|
||||
base.deathEvents = base.deathEvents + 1
|
||||
end
|
||||
base.unitPoints = base.unitPoints - UNIT_DEATH_POINT_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. UNIT_DEATH_POINT_COST .. ". [Unit Lost] Total: " .. string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
modifyBasePoints(base, UNIT_DEATH_POINT_COST*-1.0, "Unit Lost")
|
||||
if (universe.random() < universe.rallyThreshold) and not surface.peaceful_mode then
|
||||
rallyUnits(chunk, map, tick, base)
|
||||
end
|
||||
@ -492,17 +487,9 @@ local function onDeath(event)
|
||||
then
|
||||
if base then
|
||||
if (entityType == "unit-spawner") then
|
||||
base.unitPoints = base.unitPoints + RECOVER_NEST_COST
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. RECOVER_NEST_COST ..
|
||||
". [Nest Lost] Total: " .. string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
modifyBasePoints(base, RECOVER_NEST_COST, "Nest Lost")
|
||||
elseif (entityType == "turret") then
|
||||
base.unitPoints = base.unitPoints + RECOVER_WORM_COST
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. RECOVER_WORM_COST ..
|
||||
". [Worm Lost] Total: " .. string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
modifyBasePoints(base, RECOVER_WORM_COST, "Worm Lost")
|
||||
end
|
||||
rallyUnits(chunk, map, tick, base)
|
||||
if artilleryBlast then
|
||||
@ -659,10 +646,7 @@ local function onRocketLaunch(event)
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if base then
|
||||
base.rocketLaunched = base.rocketLaunched + 1
|
||||
base.unitPoints = base.unitPoints + 5000
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. 5000 .. ". [Rocket Launch] Total: " .. string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
modifyBasePoints(base, 5000, "Rocket Launch")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -27,6 +27,7 @@ local chunkPropertyUtils = require("ChunkPropertyUtils")
|
||||
local unitGroupUtils = require("UnitGroupUtils")
|
||||
local movementUtils = require("MovementUtils")
|
||||
local mathUtils = require("MathUtils")
|
||||
local baseUtils = require("libs/BaseUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -76,6 +77,8 @@ local getDeathGeneratorRating = chunkPropertyUtils.getDeathGeneratorRating
|
||||
|
||||
local mCeil = math.ceil
|
||||
|
||||
local modifyBasePoints = baseUtils.modifyBasePoints
|
||||
|
||||
-- module code
|
||||
|
||||
local function settlerWaveScaling(universe)
|
||||
@ -256,12 +259,7 @@ function aiAttackWave.formSettlers(map, chunk, base)
|
||||
squad.kamikaze = map.random() < kamikazeThreshold
|
||||
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
base.unitPoints = base.unitPoints - AI_SETTLER_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_SETTLER_COST .. ". [Settler] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," ..
|
||||
squadPosition.y .. "]")
|
||||
end
|
||||
modifyBasePoints(base, AI_SETTLER_COST*-1.0, "Settler", squadPosition.x, squadPosition.y)
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
@ -306,11 +304,7 @@ function aiAttackWave.formVengenceSquad(map, chunk, base)
|
||||
squad.kamikaze = map.random() < calculateKamikazeSquadThreshold(foundUnits, universe)
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
base.unitPoints = base.unitPoints - AI_VENGENCE_SQUAD_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_VENGENCE_SQUAD_COST .. ". [Vengence] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
end
|
||||
modifyBasePoints(base, AI_VENGENCE_SQUAD_COST*-1.0, "Vengence", squadPosition.x, squadPosition.y)
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
@ -356,12 +350,8 @@ function aiAttackWave.formVengenceSettler(map, chunk, base)
|
||||
squad.base = base
|
||||
squad.kamikaze = map.random() < calculateKamikazeSettlerThreshold(foundUnits, universe)
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
base.unitPoints = base.unitPoints - AI_VENGENCE_SQUAD_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_VENGENCE_SQUAD_COST .. ". [Vengence Settlers] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
end
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
modifyBasePoints(base, AI_VENGENCE_SQUAD_COST*-1.0, "Vengence Settlers", squadPosition.x, squadPosition.y)
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
@ -404,17 +394,12 @@ function aiAttackWave.formSquads(map, chunk, base)
|
||||
if (foundUnits > 0) then
|
||||
squad.base = base
|
||||
squad.kamikaze = map.random() < calculateKamikazeSquadThreshold(foundUnits, universe)
|
||||
base.unitPoints = base.unitPoints - AI_SQUAD_COST
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
if (base.stateAI == BASE_AI_STATE_AGGRESSIVE) then
|
||||
base.sentAggressiveGroups = base.sentAggressiveGroups + 1
|
||||
end
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_SQUAD_COST .. ". [Squad] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," ..
|
||||
squadPosition.y .. "]")
|
||||
end
|
||||
end
|
||||
modifyBasePoints(base, AI_SQUAD_COST*-1.0, "Squad", squadPosition.x, squadPosition.y)
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
|
@ -73,6 +73,7 @@ local randomTickEvent = mathUtils.randomTickEvent
|
||||
local randomTickDuration = mathUtils.randomTickDuration
|
||||
|
||||
local upgradeBaseBasedOnDamage = baseUtils.upgradeBaseBasedOnDamage
|
||||
local modifyBasePoints = baseUtils.modifyBasePoints
|
||||
|
||||
local linearInterpolation = mathUtils.linearInterpolation
|
||||
|
||||
@ -175,9 +176,9 @@ local function processBase(universe, base, tick)
|
||||
end
|
||||
|
||||
if (currentPoints < universe.maxPoints) then
|
||||
base.unitPoints = currentPoints + points
|
||||
modifyBasePoints(base, points, "Logic Cycle")
|
||||
elseif currentPoints > universe.maxOverflowPoints then
|
||||
base.unitPoints = universe.maxOverflowPoints
|
||||
--modifyBasePoints(base, (base.unitPoints - universe.maxOverflowPoints)*-1.0, "Logic Cycle - Point Cap Reached")
|
||||
end
|
||||
|
||||
if (base.points < universe.maxPoints) then
|
||||
|
@ -546,5 +546,35 @@ function baseUtils.rebuildNativeTables(universe)
|
||||
end
|
||||
end
|
||||
|
||||
function baseUtils.modifyBasePoints(base, points, tag, x, y)
|
||||
tag = tag or ""
|
||||
x = x or nil
|
||||
y = y or nil
|
||||
|
||||
base.unitPoints = base.unitPoints + points
|
||||
|
||||
local universe = base.universe
|
||||
local overflowMessage = ""
|
||||
if base.unitPoints > universe.maxOverflowPoints then
|
||||
base.unitPoints = universe.maxOverflowPoints
|
||||
overflowMessage = " [Point cap reached]"
|
||||
end
|
||||
|
||||
local printPointChange = ""
|
||||
if points > 0 and universe.aiPointsPrintGainsToChat then
|
||||
printPointChange = "+" .. string.format("%.2f", points)
|
||||
elseif points < 0 and universe.aiPointsPrintSpendingToChat then
|
||||
printPointChange = string.format("%.2f", points)
|
||||
end
|
||||
|
||||
if printPointChange ~= "" then
|
||||
local gps = ""
|
||||
if x ~= nil then
|
||||
gps = " [gps=" .. x .. "," .. y .. "]"
|
||||
end
|
||||
game.print("[" .. base.id .. "]:" .. base.map.surface.name .. " " .. printPointChange .. " [" .. tag .. "] Total:" .. string.format("%.2f", base.unitPoints) .. overflowMessage .. gps)
|
||||
end
|
||||
end
|
||||
|
||||
baseUtilsG = baseUtils
|
||||
return baseUtils
|
||||
|
@ -98,9 +98,10 @@ local removeChunkBase = chunkPropertyUtils.removeChunkBase
|
||||
local getEnemyStructureCount = chunkPropertyUtils.getEnemyStructureCount
|
||||
|
||||
local findNearbyBase = chunkPropertyUtils.findNearbyBase
|
||||
local createBase = baseUtils.createBase
|
||||
|
||||
local createBase = baseUtils.createBase
|
||||
local upgradeEntity = baseUtils.upgradeEntity
|
||||
local modifyBasePoints = baseUtils.modifyBasePoints
|
||||
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
@ -590,17 +591,10 @@ function chunkUtils.accountPlayerEntity(entity, map, addObject, base)
|
||||
pointValue = 0
|
||||
end
|
||||
base.destroyPlayerBuildings = base.destroyPlayerBuildings + 1
|
||||
if (base.stateAI == BASE_AI_STATE_ONSLAUGHT) then
|
||||
base.unitPoints = base.unitPoints + pointValue
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. math.floor(pointValue) .. ". [Structure Kill] Total: " .. string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
else
|
||||
base.unitPoints = base.unitPoints + (pointValue * 0.12)
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. math.floor(pointValue) .. ". [Structure Kill] Total: " .. string.format("%.2f", base.unitPoints))
|
||||
end
|
||||
if (base.stateAI ~= BASE_AI_STATE_ONSLAUGHT) then
|
||||
pointValue = pointValue * 0.12
|
||||
end
|
||||
modifyBasePoints(base, pointValue, "Structure Kill")
|
||||
end
|
||||
entityValue = -entityValue
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user