1
0
mirror of https://github.com/veden/Rampant.git synced 2025-09-16 09:16:43 +02:00

added code for scouting, but commented out due to computer ai doing thing automatically

This commit is contained in:
veden
2016-08-08 19:54:41 -07:00
parent c4e45563d8
commit a1401d5285
3 changed files with 50 additions and 17 deletions

View File

@@ -30,7 +30,7 @@ function onInit()
pendingChunks = global.pendingChunks pendingChunks = global.pendingChunks
natives = global.natives natives = global.natives
natives.squads = {} natives.squads = {}
natives.bases = {} natives.scouts = {}
-- game.map_settings.enemy_expansion.enabled = false -- game.map_settings.enemy_expansion.enabled = false
@@ -83,6 +83,7 @@ function onTick(event)
unitGroupUtils.regroupSquads(natives) unitGroupUtils.regroupSquads(natives)
-- ai.scouting(regionMap, surface, natives)
ai.squadAttackPlayer(regionMap, surface, natives, game.players) ai.squadAttackPlayer(regionMap, surface, natives, game.players)
if (mapRoutine ~= nil) and (coroutine.status(mapRoutine) ~= "dead") then if (mapRoutine ~= nil) and (coroutine.status(mapRoutine) ~= "dead") then
@@ -99,17 +100,24 @@ end
function onDeath(event) function onDeath(event)
local entity = event.entity local entity = event.entity
if (entity.force.name == "enemy") and (entity.type == "unit") then if (entity.force.name == "enemy") then
if (entity.type == "unit") then
local entityPosition = entity.position local entityPosition = entity.position
-- drop death pheromone where unit died -- drop death pheromone where unit died
pheromoneUtils.deathScent(regionMap, pheromoneUtils.deathScent(regionMap,
entityPosition.x, entityPosition.x,
entityPosition.y, entityPosition.y,
200) 200)
local squad = unitGroupUtils.convertUnitGroupToSquad(natives, entity.unit_group) local squad = unitGroupUtils.convertUnitGroupToSquad(natives, entity.unit_group)
ai.retreatUnits(entityPosition, squad, regionMap, surface, natives) ai.retreatUnits(entityPosition, squad, regionMap, surface, natives)
-- ai.removeScout(regionMap, surface, entity, natives)
elseif (entity.type == "unit-spawner") then
local entityPosition = entity.position
mapUtils.removeUnitSpawner(regionMap, entityPosition.x, entityPosition.y)
end
end end
end end
@@ -139,7 +147,7 @@ function onInitialTick(event)
-- add processing handler into chunk map processing -- add processing handler into chunk map processing
mapProcessor.install(pheromoneUtils.enemyBaseScent) mapProcessor.install(pheromoneUtils.enemyBaseScent)
-- mapProcessor.install(ai.sendScouts) mapProcessor.install(ai.sendScouts)
mapProcessor.install(pheromoneUtils.processPheromone) mapProcessor.install(pheromoneUtils.processPheromone)
-- used for debugging -- used for debugging

View File

@@ -33,7 +33,7 @@ function ai.squadAttackPlayer(regionMap, surface, natives, players)
end end
if (closestDistance < 60) then if (closestDistance < 60) then
local squadType = SQUAD_ATTACKING local squadType = SQUAD_ATTACKING
if (math.random() < 0.10) then -- TODO add sliding scale based on number of members if (math.random() < 0.10) then -- TODO add sliding scale based on number of members and evolution
squadType = SQUAD_SUICIDE squadType = SQUAD_SUICIDE
end end
unitGroupUtils.setSquadCommand(squad, unitGroupUtils.setSquadCommand(squad,
@@ -120,9 +120,29 @@ function ai.retreatUnits(position, squad, regionMap, surface, natives)
end end
end end
function ai.sendScouts(regionMap, surface, natives, chunk, neighbors, validNeighbors) --[[ not used due to being unable to stop unit group formation by the computer ai
function ai.removeScout(regionMap, surface, entity, natives)
return validNeighbors for i=#natives.scouts, 1, -1 do
local scout = natives.scouts[i]
if (scout == entity) then
table.remove(natives.scouts, i)
end
end
end end
function ai.sendScouts(regionMap, surface, natives, chunk, neighbors, validNeighbors)
if (#natives.scouts < 5) then -- TODO scaled with evolution factor
local enemy = surface.find_nearest_enemy({position={x=chunk.pX + constants.HALF_CHUNK_SIZE,
y=chunk.pY + constants.HALF_CHUNK_SIZE},
max_distance=16})
if (enemy ~= nil) and (enemy.type == "unit") then
natives.scouts[#natives.scouts+1] = enemy
enemy.set_command({type=defines.command.attack,
target=game.players[1].character})
-- print("scounting")
end
end
return validNeighbors
end
]]--
return ai return ai

View File

@@ -14,7 +14,12 @@ function mapUtils.getChunkByPosition(regionMap, x, y)
return nil return nil
end end
function mapUtils.removeUnitSpawner(regionMap, x, y)
local bases = mapUtils.getChunkByPosition(regionMap, x, y)
if (bases ~= nil) then
bases.bG = mMax(0, bases.bG - 1)
end
end
--[[ --[[
1 2 3 1 2 3