1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-26 03:20:07 +02:00

finish changes

This commit is contained in:
Aaron Veden 2018-09-25 22:14:13 -07:00
parent 723e7c20c0
commit cf16ce9e62
10 changed files with 121 additions and 52 deletions

View File

@ -1,3 +1,14 @@
---------------------------------------------------------------------------------------------------
Version: 0.16.33
Date: 9. 25. 2018
Improvements:
- Reworked how death pheromone sticks to terrain and how long it is active for
Optimizations:
- Reduced in memory map footprint increasing save speed
Bugfixes:
- Fix for unit groups getting stuck in random locations
- Fix for unit retreats causing excessive retreats due to inverted comparison
---------------------------------------------------------------------------------------------------
Version: 0.16.32
Date: 8. 1. 2018

View File

@ -404,7 +404,6 @@ script.on_nth_tick(INTERVAL_SQUAD,
squadsBeginAttack(natives, gameRef.players)
squadsDispatch(map, gameRef.surfaces[natives.activeSurface], natives)
end)
local function onBuild(event)
@ -486,7 +485,7 @@ local function onDeath(event)
if (event.force ~= nil) and (event.force.name == "enemy") then
creditNatives = true
if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then
victoryScent(chunk, entity.type)
victoryScent(map, chunk, entity.type)
end
end
if creditNatives and natives.safeBuildings and (natives.safeEntities[entity.type] or natives.safeEntityName[entity.name]) then

View File

@ -4,8 +4,7 @@ local constants = require("Constants")
-- imported functions
local DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GENERATOR_AMOUNT
local DEATH_PHEROMONE_DECAY_AMOUNT = constants.DEATH_PHEROMONE_DECAY_AMOUNT
local MOVEMENT_GENERATOR_PERSISTANCE = constants.MOVEMENT_GENERATOR_PERSISTANCE
local CHUNK_ALL_DIRECTIONS = constants.CHUNK_ALL_DIRECTIONS
-- module code
@ -134,20 +133,21 @@ function chunkPropertyUtils.setPathRating(map, chunk, value)
end
end
function chunkPropertyUtils.addDeathGenerator(map, chunk)
map.chunkToDeathGenerator[chunk] = (map.chunkToDeathGenerator[chunk] or 0) + DEATH_PHEROMONE_GENERATOR_AMOUNT
function chunkPropertyUtils.addDeathGenerator(map, chunk, value)
map.chunkToDeathGenerator[chunk] = (map.chunkToDeathGenerator[chunk] or 0) + value
end
function chunkPropertyUtils.decayDeathGenerator(map, chunk)
local gen = map.chunkToDeathGenerator[chunk]
if gen and (gen > 0) then
gen = gen - DEATH_PHEROMONE_DECAY_AMOUNT
end
if (gen == 0) then
map.chunkToDeathGenerator[chunk] = nil
else
map.chunkToDeathGenerator[chunk] = gen
end
gen = gen * MOVEMENT_GENERATOR_PERSISTANCE
if (gen >= -2) and (gen <= 2) then
map.chunkToDeathGenerator[chunk] = nil
else
map.chunkToDeathGenerator[chunk] = gen
end
end
end
function chunkPropertyUtils.getPlayerBaseGenerator(map, chunk)

View File

@ -29,9 +29,8 @@ constants.WATER_TILE_NAMES = { "water", "deepwater", "water-green", "deepwater-g
constants.MAGIC_MAXIMUM_NUMBER = 1e99 -- used in loops trying to find the lowest/highest score
constants.MAGIC_MAXIMUM_BASE_NUMBER = 100000000
constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL_MIN = 12500
constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL_MAX = 900000
constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL_MIN = 1500
constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL_MAX = 20000
constants.PROCESS_QUEUE_SIZE = 400
constants.SCAN_QUEUE_SIZE = 5
@ -245,14 +244,15 @@ constants.NO_RETREAT_SQUAD_SIZE_BONUS_MAX = 0.40
-- pheromone amounts
constants.MOVEMENT_PHEROMONE_GENERATOR_AMOUNT = 500
constants.DEATH_PHEROMONE_GENERATOR_AMOUNT = 300
constants.DEATH_PHEROMONE_GENERATOR_AMOUNT = 75
constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT = 300
constants.IMPASSABLE_TERRAIN_GENERATOR_AMOUNT = -0.1
-- pheromone diffusion amounts
constants.MOVEMENT_PHEROMONE_PERSISTANCE = 0.999
constants.MOVEMENT_GENERATOR_PERSISTANCE = 0.875
constants.MOVEMENT_PHEROMONE_PERSISTANCE = 0.99
constants.BASE_PHEROMONE_PERSISTANCE = 0.99
constants.PLAYER_PHEROMONE_PERSISTANCE = 0.98
constants.RESOURCE_PHEROMONE_PERSISTANCE = 0.99
@ -401,8 +401,6 @@ local unitTiers = settings.startup["rampant-newEnemyUnitTiers"].value
constants.SPAWNER_EGG_TIMEOUT = constants.TICKS_A_SECOND * 5
constants.DEATH_PHEROMONE_DECAY_AMOUNT = (constants.DEATH_PHEROMONE_GENERATOR_AMOUNT * (constants.INTERVAL_SCAN / constants.TICKS_A_SECOND)) / 15
constants.NEUTRAL_NEST_TIERS = nestTiers
constants.NEUTRAL_NEST_VARIATIONS = nestVariations
constants.NEUTRAL_WORM_TIERS = wormTiers

View File

@ -22,9 +22,12 @@ local BASE_PHEROMONE_PERSISTANCE = constants.BASE_PHEROMONE_PERSISTANCE
local PLAYER_PHEROMONE_PERSISTANCE = constants.PLAYER_PHEROMONE_PERSISTANCE
local RESOURCE_PHEROMONE_PERSISTANCE = constants.RESOURCE_PHEROMONE_PERSISTANCE
local DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GENERATOR_AMOUNT
-- imported functions
local getCardinalChunks = mapUtils.getCardinalChunks
local getNeighborChunks = mapUtils.getNeighborChunks
local getEnemyStructureCount = chunkPropertyUtils.getEnemyStructureCount
local getPathRating = chunkPropertyUtils.getPathRating
@ -40,25 +43,29 @@ local linearInterpolation = mathUtils.linearInterpolation
-- module code
function pheromoneUtils.scents(map, chunk)
chunk[BASE_PHEROMONE] = chunk[BASE_PHEROMONE] + getPlayerBaseGenerator(map, chunk)
chunk[BASE_PHEROMONE] = chunk[BASE_PHEROMONE] + (getPlayerBaseGenerator(map, chunk))
local resourceGenerator = getResourceGenerator(map, chunk)
local enemyCount = getEnemyStructureCount(map, chunk)
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] - getDeathGenerator(map, chunk)
decayDeathGenerator(map, chunk)
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] - (getDeathGenerator(map, chunk))
if (resourceGenerator > 0) and (enemyCount == 0) then
chunk[RESOURCE_PHEROMONE] = chunk[RESOURCE_PHEROMONE] + linearInterpolation(resourceGenerator, 9000, 10000)
chunk[RESOURCE_PHEROMONE] = chunk[RESOURCE_PHEROMONE] + (linearInterpolation(resourceGenerator, 9000, 10000))
end
end
function pheromoneUtils.victoryScent(chunk, entityType)
function pheromoneUtils.victoryScent(map, chunk, entityType)
local value = BUILDING_PHEROMONES[entityType]
if value then
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] + (value * 1000)
-- chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] + (value * 1000)
addDeathGenerator(map, chunk, -value)
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] + (value)
end
end
function pheromoneUtils.deathScent(map, chunk)
addDeathGenerator(map, chunk)
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] - (DEATH_PHEROMONE_GENERATOR_AMOUNT * 2)
addDeathGenerator(map, chunk, DEATH_PHEROMONE_GENERATOR_AMOUNT)
-- chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] - DEATH_PHEROMONE_GENERATOR_AMOUNT
end
function pheromoneUtils.playerScent(playerChunk)
@ -82,6 +89,8 @@ function pheromoneUtils.processPheromone(map, chunk)
local playerTotal = 0
local resourceTotal = 0
decayDeathGenerator(map, chunk)
local neighbor = tempNeighbors[1]
if not neighbor.name then
movementTotal = movementTotal + (neighbor[MOVEMENT_PHEROMONE] - chunkMovement)
@ -114,7 +123,7 @@ function pheromoneUtils.processPheromone(map, chunk)
resourceTotal = resourceTotal + (neighbor[RESOURCE_PHEROMONE] - chunkResource)
end
chunk[MOVEMENT_PHEROMONE] = (chunkMovement + (0.35 * movementTotal)) * MOVEMENT_PHEROMONE_PERSISTANCE * chunkPathRating
chunk[MOVEMENT_PHEROMONE] = (chunkMovement + (0.125 * movementTotal)) * MOVEMENT_PHEROMONE_PERSISTANCE * chunkPathRating
chunk[BASE_PHEROMONE] = (chunkBase + (0.35 * baseTotal)) * BASE_PHEROMONE_PERSISTANCE * chunkPathRating
chunk[PLAYER_PHEROMONE] = (chunkPlayer + (0.25 * playerTotal)) * PLAYER_PHEROMONE_PERSISTANCE * chunkPathRating
if clear then

View File

@ -118,6 +118,7 @@ function unitGroupUtils.createSquad(position, surface, natives, group)
originPosition = {x = 0,
y = 0},
chunk = nil
}
natives.squads[#natives.squads+1] = squad
return squad

View File

@ -78,6 +78,12 @@
(copyDirectory "sounds" modFolder)
(copyDirectory "graphics" modFolder)
(copyDirectory "prototypes" modFolder)))
(define (copy)
(copyFiles modFolder))
(define (zipIt)
(makeZip modFolder))
(define (run)
(copyFiles modFolder)

View File

@ -4,7 +4,7 @@
(struct AiState (chunks
chunksLookup
minMaxes)
#:transparent)
#:transparent)
(struct MinMax (min max)
#:transparent)
@ -23,10 +23,17 @@
rally
retreat
resourceGen
playerGen)
playerGen
deathGen
attackScore
settleScore
seigeScore)
#:transparent)
(struct Chunk (x
(struct Chunk (seigeScore
settleScore
attackScore
x
y
movement
base
@ -40,7 +47,8 @@
rally
retreat
resourceGen
playerGen)
playerGen
deathGen)
#:transparent)
(require threading)
@ -51,10 +59,21 @@
(port->string port))))
(define (stringToChunk str)
(match-let (((list movement base player resource passable tick rating x y nest worms rally retreat resourceGen playerGen) (string-split str ",")))
(match-let (((list movement base player resource passable tick rating x y nest
worms rally retreat resourceGen playerGen deathGen) (string-split str ",")))
(apply Chunk
(map string->number
(list x y movement base player resource passable tick rating nest worms rally retreat resourceGen playerGen)))))
(cons (+ (* 2 (string->number movement))
(string->number resource)
(string->number base)
(* (string->number player) 500))
(cons (+ (* 2 (string->number movement))
(string->number resource))
(cons (+ (* 2 (string->number movement))
(string->number base)
(* (string->number player) 500))
(map string->number
(list x y movement base player resource passable tick rating nest
worms rally retreat resourceGen playerGen deathGen))))))))
(define (chunk->string chunk)
(string-append "x: " (~v (Chunk-x chunk)) "\n"
@ -70,9 +89,15 @@
"wo: " (~v (Chunk-worms chunk)) "\n"
"rall: " (~v (Chunk-rally chunk)) "\n"
"retr: " (~v (Chunk-retreat chunk)) "\n"
"rGen: " (~v (Chunk-resourceGen chunk)) "\n"
"pGen: " (~v (Chunk-playerGen chunk)) "\n"))
"rGen: " (~v (Chunk-resourceGen chunk)) "\n"))
(define (chunk->string2 chunk)
(string-append "pGen: " (~v (Chunk-playerGen chunk)) "\n"
"dGen: " (~v (Chunk-deathGen chunk)) "\n"
"aSco: " (~v (Chunk-attackScore chunk)) "\n"
"sSco: " (~v (Chunk-settleScore chunk)) "\n"
"sSei: " (~v (Chunk-seigeScore chunk)) "\n"))
(define (findChunkPropertiesMinMax chunks)
(let ((xs (map Chunk-x chunks))
(ys (map Chunk-y chunks))
@ -88,7 +113,11 @@
(rallys (map Chunk-rally chunks))
(retreats (map Chunk-retreat chunks))
(rGens (map Chunk-resourceGen chunks))
(pGens (map Chunk-playerGen chunks)))
(pGens (map Chunk-playerGen chunks))
(dGens (map Chunk-deathGen chunks))
(aSco (map Chunk-attackScore chunks))
(sSco (map Chunk-settleScore chunks))
(sSei (map Chunk-seigeScore chunks)))
(ChunkRange (MinMax (apply min xs) (apply max xs))
(MinMax (apply min ys) (apply max ys))
(MinMax (apply min movements) (apply max movements))
@ -103,8 +132,12 @@
(MinMax (apply min rallys) (apply max rallys))
(MinMax (apply min retreats) (apply max retreats))
(MinMax (apply min rGens) (apply max rGens))
(MinMax (apply min pGens) (apply max pGens)))))
(MinMax (apply min pGens) (apply max pGens))
(MinMax (apply min dGens) (apply max dGens))
(MinMax (apply min aSco) (apply max aSco))
(MinMax (apply min sSco) (apply max sSco))
(MinMax (apply min sSei) (apply max sSei)))))
(define (readState filePath)
(let* ((replayChunks (getFile filePath))
(chunks (map stringToChunk (string-split replayChunks "\n")))

View File

@ -377,9 +377,9 @@ function tests.exportAiState()
chunk[constants.BASE_PHEROMONE],
chunk[constants.PLAYER_PHEROMONE],
chunk[constants.RESOURCE_PHEROMONE],
-- chunk[constants.PASSABLE],
chunkPropertyUtils.getPassable(global.map, chunk),
chunk[constants.CHUNK_TICK],
-- chunk[constants.PATH_RATING],
chunkPropertyUtils.getPathRating(global.map, chunk),
chunk.x,
chunk.y,
chunkPropertyUtils.getNestCount(global.map, chunk),
@ -387,7 +387,8 @@ function tests.exportAiState()
chunkPropertyUtils.getRallyTick(global.map, chunk),
chunkPropertyUtils.getRetreatTick(global.map, chunk),
chunkPropertyUtils.getResourceGenerator(global.map, chunk),
chunkPropertyUtils.getPlayerBaseGenerator(global.map, chunk)}, ",") .. "\n"
chunkPropertyUtils.getPlayerBaseGenerator(global.map, chunk),
chunkPropertyUtils.getDeathGenerator(global.map, chunk)}, ",") .. "\n"
end
game.write_file("rampantState.txt", s, false)
end

View File

@ -7,7 +7,7 @@
(define CHUNK_SIZE 32)
(define INVALID_CHUNK (Chunk -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0))
(define INVALID_CHUNK (Chunk -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
(define windowX 500)
(define windowY 0)
@ -72,6 +72,10 @@
[parent panel]
[label ""]
[vert-margin 30]))
(define siteBox2 (new message%
[parent panel]
[label ""]
[vert-margin 270]))
(new button%
[parent mainFrame]
@ -132,7 +136,11 @@
rally
retreat
resourceGen
playerGen) chunkMinMaxes))
playerGen
deathGen
attackScore
settleScore
seigeScore) chunkMinMaxes))
(set! activeChunkSet chunks)
(set! activeChunkMinMaxSet chunkMinMaxes)
@ -211,11 +219,14 @@
(hash-ref activeChunkSetLookup (list x y) INVALID_CHUNK))
(define (displayChunk x y)
(send siteBox set-label
(chunk->string (if (Chunk? activeHighlight)
activeHighlight
(findChunk (screenX->chunkX x)
(screenY->chunkY y))))))
(let ((chunk (if (Chunk? activeHighlight)
activeHighlight
(findChunk (screenX->chunkX x)
(screenY->chunkY y)))))
(send siteBox set-label
(chunk->string chunk))
(send siteBox2 set-label
(chunk->string2 chunk))))
(define (displayHighlight x y)
;; (display (list (screenX->chunkX x)
@ -253,7 +264,7 @@
(new radio-box%
[label "Show Layer"]
[choices (list "movement" "base" "player" "resource" "passable" "tick" "rating" "nests" "worms" "rally" "retreat" "resourceGen" "playerGen")]
[choices (list "movement" "base" "player" "resource" "passable" "tick" "rating" "nests" "worms" "rally" "retreat" "resourceGen" "playerGen" "deathGen" "attackScore" "settleScore" "seigeScore")]
[selection 0]
[parent mainFrame]
(callback (lambda (radioButton event)