-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbionomics.lua
More file actions
57 lines (54 loc) · 2.05 KB
/
bionomics.lua
File metadata and controls
57 lines (54 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---------------------------------------------------------------------------------------
-- Bionomics --
---------------------------------------------------------------------------------------
--[[
Dependencies:
none
]]--
function SetupRecoverableTreeStumps(_ressAmount)
gvTreeStumps = {
stumps = {},
ressourceAmount = _ressAmount
}
Trigger.RequestTrigger(Events.LOGIC_EVENT_ENTITY_DESTROYED, "", "TreeStumpCreation", 1)
end
function TreeStumpCreation()
local eId = Event.GetEntityID()
local eType = Logic.GetEntityType(eId)
if (eType == Entities.XD_ResourceTree) and (not gvTreeStumps.stumps[eId]) then
gvTreeStumps.JobID = gvTreeStumps.JobID or StartSimpleJob("ControlTreeStumps")
local pos = GetPosition(eId)
local stumps, treeStump = Logic.GetEntitiesInArea(Entities.XD_TreeStump1, pos.X, pos.Y, 5, 1)
if not treeStump then
return
end
local ressourceEntity = Logic.CreateEntity(Entities.XD_ResourceTree, pos.X, pos.Y)
Logic.SetResourceDoodadGoodAmount(ressourceEntity, 50 + gvTreeStumps.ressourceAmount)
Logic.SetModelAndAnimSet(ressourceEntity, Models.XD_Plant4)
gvTreeStumps.stumps[ressourceEntity] = treeStump
end
end
function ControlTreeStumps()
local stumpCnt = 0
for ressourceEntity, treeStump in pairs(gvTreeStumps.stumps) do
if IsExisting(treeStump) then
if Logic.GetResourceDoodadGoodAmount(ressourceEntity) <= 50 then
local pos = GetPosition(ressourceEntity)
DestroyEntity(ressourceEntity)
DestroyEntity(treeStump)
Logic.CreateEffect(GGL_Effects.FXBuildingSmoke, pos.X, pos.Y, 0)
gvTreeStumps.stumps[ressourceEntity] = nil
else
stumpCnt = stumpCnt + 1
end
else
DestroyEntity(ressourceEntity)
gvTreeStumps.stumps[ressourceEntity] = nil
end
end
if stumpCnt == 0 then
gvTreeStumps.JobID = nil
return true
end
end
-------------------------------------------------------------