diff --git a/Upgrade.lua b/Upgrade.lua index 71c2525..7db31de 100755 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -12,6 +12,8 @@ local BASE_AI_STATE_DORMANT = constants.BASE_AI_STATE_DORMANT local INTERVAL_LOGIC = constants.INTERVAL_LOGIC local CHUNK_SIZE = constants.CHUNK_SIZE +local ATTACK_SCORE = constants.ATTACK_SCORE + local SQUAD_GUARDING = constants.SQUAD_GUARDING -- imported functions @@ -242,16 +244,14 @@ function upgrade.attempt(natives) game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.37") global.version = constants.VERSION_72 end - if (global.version < constants.VERSION_74) then + if (global.version < constants.VERSION_75) then for _,squad in pairs(natives.squads) do - squad.status = SQUAD_GUARDING - squad.cycles = 0 - squad.attackScoreFunction = nil + squad.attackScoreFunction = ATTACK_SCORE end - game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.39") - global.version = constants.VERSION_74 + game.surfaces[natives.activeSurface].print("Rampant - Version 0.16.40") + global.version = constants.VERSION_75 end return starting ~= global.version, natives diff --git a/changelog.txt b/changelog.txt index 511476b..41c8479 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,9 @@ +--------------------------------------------------------------------------------------------------- +Version: 0.16.40 +Date: 2. 16. 2019 + Bugfixes: + - Switched to numeric value to represent scoring functions + --------------------------------------------------------------------------------------------------- Version: 0.16.39 Date: 2. 15. 2019 diff --git a/info.json b/info.json index e5e3b78..d497864 100755 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "name" : "Rampant", "factorio_version" : "0.16", - "version" : "0.16.39", + "version" : "0.16.40", "title" : "Rampant", "author" : "Veden", "homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445", diff --git a/libs/AIAttackWave.lua b/libs/AIAttackWave.lua index 6696f6e..a6d69be 100755 --- a/libs/AIAttackWave.lua +++ b/libs/AIAttackWave.lua @@ -194,9 +194,8 @@ function aiAttackWave.formSettlers(map, surface, natives, chunk, cost, tick) CHUNK_SIZE, 4) if squadPosition then - local squad = createSquad(squadPosition, surface, natives) + local squad = createSquad(squadPosition, surface, natives, nil, true) - squad.settlers = true squad.maxDistance = gaussianRandomRange(natives.expansionMaxDistance, natives.expansionMaxDistanceDerivation, CHUNK_SIZE * 1, diff --git a/libs/Constants.lua b/libs/Constants.lua index ff6db28..9db2569 100755 --- a/libs/Constants.lua +++ b/libs/Constants.lua @@ -26,7 +26,7 @@ constants.VERSION_51 = 51 constants.VERSION_57 = 57 constants.VERSION_72 = 72 constants.VERSION_73 = 73 -constants.VERSION_74 = 74 +constants.VERSION_75 = 75 -- misc @@ -400,6 +400,9 @@ constants.SQUAD_BUILDING = 6 -- Squad Related +constants.ATTACK_SCORE = 1 +constants.ATTACK_SCORE_KAMIKAZE = 2 + constants.RETREAT_GRAB_RADIUS = 24 constants.RETREAT_SPAWNER_GRAB_RADIUS = 75 diff --git a/libs/SquadAttack.lua b/libs/SquadAttack.lua index cfc72f0..6e4359c 100755 --- a/libs/SquadAttack.lua +++ b/libs/SquadAttack.lua @@ -20,6 +20,9 @@ local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE local BASE_PHEROMONE = constants.BASE_PHEROMONE local RESOURCE_PHEROMONE = constants.RESOURCE_PHEROMONE +local ATTACK_SCORE = constants.ATTACK_SCORE +local ATTACK_SCORE_KAMIKAZE = constants.ATTACK_SCORE_KAMIKAZE + local SQUAD_BUILDING = constants.SQUAD_BUILDING local SQUAD_RAIDING = constants.SQUAD_RAIDING @@ -163,11 +166,15 @@ local function attackMove(map, attackPosition, attackCmd, squad, group, natives, local groupPosition = group.position local x, y = positionToChunkXY(groupPosition) local chunk = getChunkByXY(map, x, y) + local attackScorer = scoreAttackLocation + if (squad.attackScoreFunction == ATTACK_SCORE_KAMIKAZE) then + attackScorer = scoreAttackKamikazeLocation + end local attackChunk, attackDirection = scoreNeighborsForAttack(map, natives, chunk, getNeighborChunks(map, x, y), - squad.attackScoreFunction or scoreAttackLocation, + attackScorer, squad) if (chunk ~= SENTINEL_IMPASSABLE_CHUNK) then addSquadToChunk(map, chunk, squad) @@ -258,9 +265,7 @@ function squadAttack.squadsBeginAttack(natives, players) end if squad.kamikaze and (mRandom() < (kamikazeThreshold * 0.75)) then - squad.attackScoreFunction = scoreAttackKamikazeLocation - else - squad.attackScoreFunction = scoreAttackLocation + squad.attackScoreFunction = ATTACK_SCORE_KAMIKAZE end squad.status = SQUAD_RAIDING end diff --git a/libs/UnitGroupUtils.lua b/libs/UnitGroupUtils.lua index f64d3e3..e12a346 100755 --- a/libs/UnitGroupUtils.lua +++ b/libs/UnitGroupUtils.lua @@ -103,25 +103,25 @@ function unitGroupUtils.findNearbySquad(map, chunk, position) return nil end -function unitGroupUtils.createSquad(position, surface, natives, group) +function unitGroupUtils.createSquad(position, surface, natives, group, settlers) local unitGroup = group or surface.create_unit_group({position=position}) local squad = { group = unitGroup, status = SQUAD_GUARDING, penalties = {}, - settlers = false, rabid = false, frenzy = false, + settlers = settlers or false, kamikaze = false, frenzyPosition = {x = 0, y = 0}, cycles = 0, maxDistance = 0, + attackScoreFunction = 1, originPosition = {x = 0, y = 0}, chunk = nil - } natives.squads[#natives.squads+1] = squad return squad