Fixed regrowth not working on rocky biomes
This commit is contained in:
parent
5fa0bcf9a0
commit
3b5461ee2e
@ -6,8 +6,6 @@ local REGROWTH_TYPE =
|
||||
|
||||
local DEBUG = false
|
||||
|
||||
-- Configuration Generation
|
||||
-- I can't reference this from another file... duplicate
|
||||
-- Configuration Generation
|
||||
-- I can't reference this from another file... duplicate
|
||||
local config_table =
|
||||
|
@ -57,7 +57,7 @@ return Class(function(self, inst)
|
||||
ent:RemoveEventCallback("onremove", EntityDeathEventHandler, nil)
|
||||
|
||||
if DEBUG then
|
||||
print("[EventRegrowth] " .. ent.prefab .. " was removed at " .. GetPosStr(position))
|
||||
print("[EventRegrowth] " .. ent.prefab .. " was removed at " .. GetPosStr(position) .. " Tile: " .. TheWorld.Map:GetTileAtPoint(position.x, position.y, position.z))
|
||||
end
|
||||
end
|
||||
|
||||
@ -72,21 +72,21 @@ return Class(function(self, inst)
|
||||
local function TryRegrowth(prefab, product, position, rand_radius)
|
||||
local x,y,z = GetRandomLocation(position.x,position.y,position.z, rand_radius)
|
||||
|
||||
local orig_tile = inst.Map:GetTileAtPoint(x,y,z)
|
||||
local status = TestRegrowthByTile(x,y,z, orig_tile)
|
||||
|
||||
if status == REGROW_STATUS.CACHE then
|
||||
local orig_tile = inst.Map:GetTileAtPoint(position.x, position.y, position.z)
|
||||
local status = TestRegrowth(x,y,z, prefab, orig_tile)
|
||||
|
||||
if status == REGROW_STATUS.STRUCT then
|
||||
if DEBUG then
|
||||
print("[EventRegrowth] Cached a product " .. product .. " at ".. GetCoordStr(x,y,z) .. " for prefab " .. prefab .. " at " .. GetPosStr(position) .. " with rand radius ".. rand_radius)
|
||||
print("[EventRegrowth] Failed to spawn a product " .. product .. " at " .. GetCoordStr(x,y,z) .. " for prefab " .. prefab .. " at " .. GetPosStr(position) .. " with rand radius " .. rand_radius .. " due to " .. GetRStatusStr(status))
|
||||
end
|
||||
return REGROW_STATUS.CACHE
|
||||
return status
|
||||
end
|
||||
|
||||
if status == REGROW_STATUS.FAILED then
|
||||
if status ~= REGROW_STATUS.SUCCESS then
|
||||
if DEBUG then
|
||||
print("[EventRegrowth] Failed to spawn a product " .. product .. " at " .. GetCoordStr(x,y,z) .. " for prefab " .. prefab .. " at " .. GetPosStr(position) .. " with rand radius " .. rand_radius)
|
||||
print("[EventRegrowth] Cached a product " .. product .. " at ".. GetCoordStr(x,y,z) .. " for prefab " .. prefab .. " at " .. GetPosStr(position) .. " with rand radius ".. rand_radius .. " due to " .. GetRStatusStr(status))
|
||||
end
|
||||
return REGROW_STATUS.FAILED
|
||||
return status
|
||||
end
|
||||
|
||||
local instance = SpawnPrefab(product)
|
||||
@ -104,7 +104,7 @@ return Class(function(self, inst)
|
||||
|
||||
end
|
||||
|
||||
return REGROW_STATUS.SUCCESS
|
||||
return status
|
||||
end
|
||||
|
||||
local function HookEntities(prefab)
|
||||
@ -195,7 +195,7 @@ return Class(function(self, inst)
|
||||
data.remove = true
|
||||
end
|
||||
|
||||
if success == REGROW_STATUS.FAILED then
|
||||
if success == REGROW_STATUS.STRUCT then
|
||||
-- only increase radius when there are structures nearby
|
||||
data.retry = data.retry + 1
|
||||
end
|
||||
|
@ -38,7 +38,8 @@ return Class(function(self, inst)
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
local function TryRegrowth(x, y, z , prefab, product)
|
||||
if TestRegrowthByPrefab(x,0,z, product) == REGROW_STATUS.SUCCESS then
|
||||
local status = TestRegrowth(x,0,z, product, nil)
|
||||
if status == REGROW_STATUS.SUCCESS then
|
||||
local instance = SpawnPrefab(product)
|
||||
|
||||
if instance ~= nil then
|
||||
@ -56,7 +57,7 @@ return Class(function(self, inst)
|
||||
return true
|
||||
else
|
||||
if DEBUG then
|
||||
print("[NaturalRegrowth] Failed to spawn a product " .. product .. " at " .. GetCoordStr(x,0,z) .. " for prefab " .. prefab)
|
||||
print("[NaturalRegrowth] Failed to spawn a product " .. product .. " at " .. GetCoordStr(x,0,z) .. " for prefab " .. prefab .. " due to " .. GetRStatusStr(status))
|
||||
end
|
||||
return false
|
||||
end
|
||||
@ -260,7 +261,7 @@ return Class(function(self, inst)
|
||||
end
|
||||
|
||||
if DEBUG then
|
||||
print("[NaturalRegrowth] Loaded" .. #area_data[prefab] .. " areas for prefab " .. prefab)
|
||||
print("[NaturalRegrowth] Loaded " .. #area_data[prefab] .. " areas for prefab " .. prefab)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,8 +25,12 @@ MIN_PLAYER_DISTANCE = 40
|
||||
REGROW_STATUS =
|
||||
{
|
||||
SUCCESS = 0,
|
||||
FAILED = 1,
|
||||
CACHE = 2
|
||||
STRUCT = 1,
|
||||
CACHE = 2,
|
||||
PLAYER = 3,
|
||||
DENSITY = 4,
|
||||
TILE = 5,
|
||||
ROAD = 6
|
||||
}
|
||||
|
||||
local function TestStructures(x, y, z, radius)
|
||||
@ -42,6 +46,13 @@ local function TestStructures(x, y, z, radius)
|
||||
return true
|
||||
end
|
||||
|
||||
local function CanPlaceAtPoint(x, y, z)
|
||||
local tile = TheWorld.Map:GetTileAtPoint(x, y, z)
|
||||
return tile ~= GROUND.IMPASSABLE and
|
||||
tile ~= GROUND.INVALID and
|
||||
not GROUND_FLOORING[tile]
|
||||
end
|
||||
|
||||
local function TestPlayers(x, y, z, radius)
|
||||
return not IsAnyPlayerInRange(x,y,z, MIN_PLAYER_DISTANCE, nil)
|
||||
end
|
||||
@ -51,58 +62,31 @@ local function TestEntities(x, y, z, radius)
|
||||
return not (#ents > 0)
|
||||
end
|
||||
|
||||
function TestRegrowthByTile(x, y, z, tile)
|
||||
function TestRegrowth(x, y, z, prefab, tile)
|
||||
|
||||
if not TestPlayers(x,y,z, MIN_PLAYER_DISTANCE) then
|
||||
return REGROW_STATUS.CACHE
|
||||
return REGROW_STATUS.PLAYER
|
||||
end
|
||||
|
||||
if not TestStructures(x, y, z, BASE_RADIUS) then
|
||||
-- No regrowth around players and their bases
|
||||
return REGROW_STATUS.FAILED
|
||||
return REGROW_STATUS.STRUCT
|
||||
end
|
||||
|
||||
if not TestEntities(x,y,z, EXCLUDE_RADIUS) then
|
||||
-- Too dense
|
||||
return REGROW_STATUS.CACHE
|
||||
return REGROW_STATUS.DENSITY
|
||||
end
|
||||
|
||||
if not (TheWorld.Map:CanPlantAtPoint(x, y, z)) then
|
||||
return REGROW_STATUS.CACHE
|
||||
if (RoadManager ~= nil) and (RoadManager:IsOnRoad(x, 0, z)) then
|
||||
return REGROW_STATUS.ROAD
|
||||
end
|
||||
|
||||
if TheWorld.Map:GetTileAtPoint(x, y, z) ~= tile then
|
||||
-- keep things in their biome (more or less)
|
||||
return REGROW_STATUS.CACHE
|
||||
if (CanPlaceAtPoint(x, y, z) and TheWorld.Map:CanPlacePrefabFilteredAtPoint(x, y, z, prefab)) or ((tile ~= nil) and (TheWorld.Map:GetTileAtPoint(x, y, z) == tile)) then
|
||||
return REGROW_STATUS.SUCCESS
|
||||
end
|
||||
|
||||
return REGROW_STATUS.SUCCESS
|
||||
end
|
||||
|
||||
function TestRegrowthByPrefab(x, y, z, prefab)
|
||||
|
||||
if not TestPlayers(x,y,z, MIN_PLAYER_DISTANCE) then
|
||||
return REGROW_STATUS.CACHE
|
||||
end
|
||||
|
||||
if not TestStructures(x, y, z, BASE_RADIUS) then
|
||||
-- No regrowth around players and their bases
|
||||
return REGROW_STATUS.FAILED
|
||||
end
|
||||
|
||||
if not TestEntities(x,y,z, EXCLUDE_RADIUS) then
|
||||
-- Too dense
|
||||
return REGROW_STATUS.CACHE
|
||||
end
|
||||
|
||||
if not (TheWorld.Map:CanPlantAtPoint(x, y, z) and
|
||||
TheWorld.Map:CanPlacePrefabFilteredAtPoint(x, y, z, prefab))
|
||||
or (RoadManager ~= nil and RoadManager:IsOnRoad(x, 0, z)) then
|
||||
-- Not ground we can grow on
|
||||
return REGROW_STATUS.CACHE
|
||||
end
|
||||
|
||||
return REGROW_STATUS.SUCCESS
|
||||
return REGROW_STATUS.TILE
|
||||
end
|
||||
|
||||
function GetPosStr(pos)
|
||||
@ -111,4 +95,13 @@ end
|
||||
|
||||
function GetCoordStr(x,y,z)
|
||||
return "( " .. x .. " , " .. y .. " , ".. z .. " )"
|
||||
end
|
||||
|
||||
function GetRStatusStr(status)
|
||||
for k, v in pairs(REGROW_STATUS) do
|
||||
if v == status then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
Loading…
Reference in New Issue
Block a user