1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-14 10:23:17 +02:00

Buddy check wasn't implemented...

This commit is contained in:
Oarcinae 2020-02-16 19:57:10 -05:00
parent 96f762c623
commit 20b0a04d93

View File

@ -7,8 +7,8 @@
-- them based on player activity. -- them based on player activity.
-- Basic logic: -- Basic logic:
-- on_unit_group_finished_gathering we check what command is given. -- on_unit_group_finished_gathering we check what command is given.
-- find destination position -- find destination position
-- check for closest "player" using find_nearest_enemy function -- check for closest "player" using find_nearest_enemy function
-- if a player is found, check if player is part of a shared spawn -- if a player is found, check if player is part of a shared spawn
-- Remove the enemy group if no player in the shared spawn is online. -- Remove the enemy group if no player in the shared spawn is online.
@ -22,57 +22,57 @@ require("lib/oarc_utils")
function OarcModifyEnemyGroup(group) function OarcModifyEnemyGroup(group)
-- Check validity -- Check validity
if ((group == nil) or (group.command == nil) or (group.force.name ~= "enemy")) then if ((group == nil) or (group.command == nil) or (group.force.name ~= "enemy")) then
log("OarcModifyEnemyGroup ignoring INVALID group/command") log("OarcModifyEnemyGroup ignoring INVALID group/command")
return return
end end
-- Make sure the attack is of a TYPE that we care about. -- Make sure the attack is of a TYPE that we care about.
if ((group.command.type == defines.command.attack) or if ((group.command.type == defines.command.attack) or
(group.command.type == defines.command.attack_area) or (group.command.type == defines.command.attack_area) or
(group.command.type == defines.command.build_base)) then (group.command.type == defines.command.build_base)) then
log("OarcModifyEnemyGroup MODIFYING command TYPE=" .. group.command.type) log("OarcModifyEnemyGroup MODIFYING command TYPE=" .. group.command.type)
else else
log("OarcModifyEnemyGroup ignoring command TYPE=" .. group.command.type) log("OarcModifyEnemyGroup ignoring command TYPE=" .. group.command.type)
return return
end end
-- defines.command.attack --> target --> target.position -- defines.command.attack --> target --> target.position
if (group.command.type == defines.command.attack) then if (group.command.type == defines.command.attack) then
log("OarcModifyEnemyGroup defines.command.attack NOT IMPLEMENTED YET!") log("OarcModifyEnemyGroup defines.command.attack NOT IMPLEMENTED YET!")
return return
-- defines.command.attack_area --> destination --> closest enemy (within 3 chunk radius?) -- defines.command.attack_area --> destination --> closest enemy (within 3 chunk radius?)
-- defines.command.build_base --> destination --> closest enemy (expansion chunk distance?) -- defines.command.build_base --> destination --> closest enemy (expansion chunk distance?)
else else
local destination = group.command.destination local destination = group.command.destination
local distance = CHUNK_SIZE*3 local distance = CHUNK_SIZE*3
if (group.command.type == defines.command.build_base) then if (group.command.type == defines.command.build_base) then
distance = CHUNK_SIZE*7 --game.map_settings.enemy_expansion.max_expansion_distance distance = CHUNK_SIZE*7 --game.map_settings.enemy_expansion.max_expansion_distance
end end
local target_entity = group.surface.find_nearest_enemy{position=destination, local target_entity = group.surface.find_nearest_enemy{position=destination,
max_distance=distance, max_distance=distance,
force="enemy"} force="enemy"}
-- No enemies nearby? -- No enemies nearby?
if (target_entity == nil) then if (target_entity == nil) then
if (group.command.type == defines.command.attack_area) then if (group.command.type == defines.command.attack_area) then
if (global.enable_oe_debug) then if (global.enable_oe_debug) then
SendBroadcastMsg("OarcModifyEnemyGroup find_nearest_enemy attack_area FAILED!?!?") SendBroadcastMsg("OarcModifyEnemyGroup find_nearest_enemy attack_area FAILED!?!?")
end end
log("OarcModifyEnemyGroup UNEXPECTED find_nearest_enemy did not find anything!") log("OarcModifyEnemyGroup UNEXPECTED find_nearest_enemy did not find anything!")
else else
log("OarcModifyEnemyGroup find_nearest_enemy did not find anything!") log("OarcModifyEnemyGroup find_nearest_enemy did not find anything!")
end end
return return
end end
-- Probably don't need this I hope? -- Probably don't need this I hope?
if (target_entity.force == "neutral") then if (target_entity.force == "neutral") then
log("OarcModifyEnemyGroup UNEXPECTED find_nearest_enemy found neutral target?") log("OarcModifyEnemyGroup UNEXPECTED find_nearest_enemy found neutral target?")
return return
end end
-- Most common target will be a built entity with a "last_user" -- Most common target will be a built entity with a "last_user"
@ -80,58 +80,61 @@ function OarcModifyEnemyGroup(group)
-- Target could also be a player character (more rare) -- Target could also be a player character (more rare)
if (target_player == nil) and (target_entity.type == "character") then if (target_player == nil) and (target_entity.type == "character") then
target_player = target_entity.player target_player = target_entity.player
end end
-- I don't think this should happen... -- I don't think this should happen...
if ((target_player == nil) or (not target_player.valid)) then if ((target_player == nil) or (not target_player.valid)) then
if (global.enable_oe_debug) then if (global.enable_oe_debug) then
SendBroadcastMsg("ERROR?? target_player nil/invalid " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position)) SendBroadcastMsg("ERROR?? target_player nil/invalid " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position))
end end
log("OarcModifyEnemyGroup ERROR?? target_player nil/invalid") log("OarcModifyEnemyGroup ERROR?? target_player nil/invalid")
return return
end end
-- Is the target player online? Then the attack can go through. -- Is the target player online? Then the attack can go through.
if (target_player.connected) then if (target_player.connected) then
if (global.enable_oe_debug) then if (global.enable_oe_debug) then
SendBroadcastMsg("Enemy group released: " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name) SendBroadcastMsg("Enemy group released (player): " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name)
end end
log("OarcModifyEnemyGroup RELEASING enemy group since player is ONLINE") log("OarcModifyEnemyGroup RELEASING enemy group since player is ONLINE")
return return
end end
-- Find the shared spawn that the player is part of. -- Find the shared spawn that the player is part of.
-- This could be the own player's spawn (quite likely) -- This could be the own player's spawn (quite likely)
local sharedSpawnOwner = FindPlayerSharedSpawn(target_player.name) local sharedSpawnOwnerName = FindPlayerSharedSpawn(target_player.name)
-- Is someone in the shared spawn online? -- Is someone in the shared spawn online?
if (sharedSpawnOwner ~= nil) then if (sharedSpawnOwnerName ~= nil) then
if (GetOnlinePlayersAtSharedSpawn(sharedSpawnOwner) > 0) then if (GetOnlinePlayersAtSharedSpawn(sharedSpawnOwnerName) > 0) then
if (global.enable_oe_debug) then if (global.enable_oe_debug) then
SendBroadcastMsg("Enemy group released: " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name) SendBroadcastMsg("Enemy group released (shared): " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name)
end end
log("OarcModifyEnemyGroup RELEASING enemy group since someone in the group is ONLINE") log("OarcModifyEnemyGroup RELEASING enemy group since someone in the group is ONLINE")
return return
end end
end end
-- Is there a buddy spawn and is the buddy online? -- Is there a buddy spawn and is the buddy online?
if (global.buddyPairs[target_player.name] ~= nil) then local buddyName = global.buddyPairs[sharedSpawnOwnerName]
if (global.enable_oe_debug) then if (buddyName ~= nil) and (game.players[buddyName] ~= nil) then
SendBroadcastMsg("Enemy group released: " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name) if (game.players[buddyName].connected or (GetOnlinePlayersAtSharedSpawn(buddyName) > 0)) then
end if (global.enable_oe_debug) then
log("OarcModifyEnemyGroup RELEASING enemy group since someone in the BUDDY PAIR is ONLINE") SendBroadcastMsg("Enemy group released (buddy): " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name)
return end
log("OarcModifyEnemyGroup RELEASING enemy group since someone in the BUDDY PAIR is ONLINE")
return
end
end end
-- Otherwise, we delete the group. -- Otherwise, we delete the group.
if (global.enable_oe_debug) then if (global.enable_oe_debug) then
SendBroadcastMsg("Enemy group deleted: " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name) SendBroadcastMsg("Enemy group deleted: " .. GetGPStext(group.members[1].position) .. " Target: " .. GetGPStext(target_entity.position) .. " " .. target_player.name)
end end
for _,member in pairs(group.members) do for _,member in pairs(group.members) do
member.destroy() member.destroy()
end end
log("OarcModifyEnemyGroup REMOVED enemy group since nobody was online?") log("OarcModifyEnemyGroup REMOVED enemy group since nobody was online?")
end end
end end