-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcitizens.lua
More file actions
88 lines (80 loc) · 2.8 KB
/
citizens.lua
File metadata and controls
88 lines (80 loc) · 2.8 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---------------------------------------------------------------------------------------
-- Citizens --
---------------------------------------------------------------------------------------
--[[
Dependencies:
community_comforts.lua
]]--
function InitCitizens(_citizensPerPoint, _newNames)
wpcList = {}
citList = {}
citizenNameCnt = 0
local citizens = {
{ Entity = Entities.CU_AlchemistIdle },
{ Entity = Entities.CU_ChiefIdle },
{ Entity = Entities.CU_EngineerIdle },
{ Entity = Entities.CU_FarmerIdle },
{ Entity = Entities.CU_Major02Idle },
{ Entity = Entities.CU_MasterBuilder },
{ Entity = Entities.CU_Trader },
{ Entity = Entities.CU_Princess, Name = Umlaute("Bürgerin") },
{ Entity = Entities.CU_SmelterIdle }
}
local ent
repeat
ent = { Logic.GetEntities( Entities.XD_RockTidelandGreen4, 9000)};
for i=2, ent[1]+1 do
local str = GetEntityName(ent[i]);
if string.sub(str, 1, 3) == "wpc" then
local pId = tonumber(string.sub(str, 4, 4))
local thisNum = tonumber(string.sub(str, 6, 7))
wpcList[thisNum] = {
nextWP = { },
pos = GetPosition(ent[i])
}
local strPos = 8
local strLen = string.len(str)
repeat
table.insert(wpcList[thisNum].nextWP, tonumber(string.sub(str, strPos+1, strPos+2)))
strPos = strPos + 3
until strPos >= strLen
DestroyEntity(ent[i])
for i = 1, _citizensPerPoint do
local citizenType = GetRandom(1, table.getn(citizens))
local eID = CreateEntity(pId, citizens[citizenType].Entity, wpcList[thisNum].pos)
if _newNames then
local eName = GetCitizenName()
SetEntityName(eID, eName)
_newNames[eName] = citizens[citizenType].Name or Umlaute("Bürger")
end
table.insert(citList, {eId = eID, lastWP = 0, nextWP = thisNum})
end
end
end
until ent[1] ~= 16
StartSimpleJob("CitizensControlJob")
end
function GetCitizenName()
citizenNameCnt = citizenNameCnt + 1
return "citizen" .. citizenNameCnt
end
function CitizensControlJob()
for i = 1, table.getn(citList) do
if not Logic.IsEntityMoving(citList[i].eId) then
if GetRandom(1, 2) == 1 then
local nextWpId
local nextOptions = table.getn(wpcList[citList[i].nextWP].nextWP)
if nextOptions ~= 1 then
repeat
nextWpId = GetRandom(1, nextOptions)
until wpcList[citList[i].nextWP].nextWP[nextWpId] ~= citList[i].lastWP
else
nextWpId = 1
end
citList[i].lastWP = citList[i].nextWP
citList[i].nextWP = wpcList[citList[i].nextWP].nextWP[nextWpId]
Logic.MoveSettler(citList[i].eId, wpcList[citList[i].nextWP].pos.X, wpcList[citList[i].nextWP].pos.Y)
end
end
end
end