Skip to content

Commit b791ab4

Browse files
authored
Add files via upload
1 parent d2eb65b commit b791ab4

100 files changed

Lines changed: 16950 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ai/AIJobTypeManager.lua

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
---This class handles all npcs
13+
local AIJobTypeManager_mt = Class(AIJobTypeManager)
14+
15+
16+
---Creating manager
17+
-- @return table instance instance of object
18+
function AIJobTypeManager.new(isServer, customMt)
19+
local self = setmetatable({}, customMt or AIJobTypeManager_mt)
20+
21+
self.isServer = isServer
22+
23+
return self
24+
end
25+
26+
27+
---Load data on map load
28+
-- @return boolean true if loading was successful else false
29+
function AIJobTypeManager:loadMapData(xmlFile, missionInfo, baseDirectory)
30+
self.jobTypes = {}
31+
self.nameToIndex = {}
32+
self.classObjectToIndex = {}
33+
AIJobType = self.nameToIndex
34+
35+
self:registerJobType("GOTO", "$l10n_ai_jobTitleGoto", AIJobGoTo)
36+
self:registerJobType("FIELDWORK", "$l10n_ai_jobTitleFieldWork", AIJobFieldWork)
37+
self:registerJobType("CONVEYOR", "$l10n_ai_jobTitleConveyor", AIJobConveyor)
38+
self:registerJobType("DELIVER", "$l10n_ai_jobTitleDeliver", AIJobDeliver)
39+
self:registerJobType("LOAD_AND_DELIVER", "$l10n_ai_jobTitleLoadAndDeliver", AIJobLoadAndDeliver)
40+
end
41+
42+
43+
---
44+
function AIJobTypeManager:delete()
45+
self.jobTypes = {}
46+
self.nameToIndex = {}
47+
self.classObjectToIndex = {}
48+
AIJobType = self.nameToIndex
49+
end
50+
51+
52+
---
53+
function AIJobTypeManager:registerJobType(name, title, classObject)
54+
if not ClassUtil.getIsValidIndexName(name) then
55+
Logging.warning("'%s' is not a valid name for a ai job type!", tostring(name))
56+
return nil
57+
end
58+
59+
name = name:upper()
60+
61+
if self.nameToIndex[name] ~= nil then
62+
Logging.warning("AI job type '%s' already exists!", tostring(name))
63+
return nil
64+
end
65+
66+
local jobType = {}
67+
jobType.name = name
68+
jobType.title = g_i18n:convertText(title)
69+
jobType.classObject = classObject
70+
jobType.index = #self.jobTypes + 1
71+
72+
table.insert(self.jobTypes, jobType)
73+
self.nameToIndex[name] = jobType.index
74+
self.classObjectToIndex[classObject] = jobType.index
75+
76+
return jobType
77+
end
78+
79+
80+
---
81+
function AIJobTypeManager:getJobTypeIndex(job)
82+
local classObject = ClassUtil.getClassObjectByObject(job)
83+
if classObject == nil then
84+
return nil
85+
end
86+
87+
return self.classObjectToIndex[classObject]
88+
end
89+
90+
91+
---
92+
function AIJobTypeManager:createJob(typeIndex)
93+
if typeIndex == nil then
94+
return nil
95+
end
96+
97+
local jobType = self.jobTypes[typeIndex]
98+
if jobType == nil then
99+
return nil
100+
end
101+
102+
local job = jobType.classObject.new(self.isServer)
103+
job.jobTypeIndex = typeIndex
104+
105+
return job
106+
end
107+
108+
109+
---
110+
function AIJobTypeManager:getJobTypeByIndex(index)
111+
return self.jobTypes[index]
112+
end
113+
114+
115+
---
116+
function AIJobTypeManager:getJobTypeIndexByName(name)
117+
if name == nil then
118+
return nil
119+
end
120+
121+
name = name:upper()
122+
123+
return self.nameToIndex[name]
124+
end

0 commit comments

Comments
 (0)