forked from DevilboxGames/ReincarnationTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRPedFile.ms
More file actions
304 lines (273 loc) · 7.3 KB
/
Copy pathCRPedFile.ms
File metadata and controls
304 lines (273 loc) · 7.3 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
PedFileSpawnTypes = #(
"Point",
"Line",
"Radius",
"Rectangle",
"Material"
)
PedFileSpawnSpecAttribute = attributes PedFileSpawnSpec_Def attribID:#(0x3f78e276, 0x54cd3c7) version:1
(
parameters main rollout:PetFileSpawnSpecRollout (
SpecType type:#string default:"Radius"
)
)
struct PedFile_SpawnSpec
(
Type,
Location,
Location2,
Radius,
PedCount,
GroupOrType,
Homogenous,
InitialMode,
Direction,
MaterialName,
Density,
fn ParseSpawnSpec luaText =
(
luaStream = luaText as StringStream
lineNum = 0
while (eof luaStream) == false do
(
lineNum += 1
line = readLine luaStream
splitLine = filterstring (trimleft line) ":()"
if splitLine.count > 0 then
(
argsStream = (substituteString splitLine[3] "," ", ") as StringStream
--format "doing % with args\n" splitline[2] splitline[3]
case splitline[2] of
(
"Set_Type":
(
Type =readToken argsStream
)
"Set_Location":
(
x = readToken argsStream
y = readToken argsStream
z = readToken argsStream
x = (substring x 1 (x.count-1)) as float
y = (substring y 1 (y.count-1)) as float
z = z as float
Location = ConvertFromCRSpace [x,y,z]
)
"Set_Radius":
(
x = readToken argsStream
Radius = x as float
format "% - %\n" x radius
)
"Set_Count":
(
x = readToken argsStream
PedCount = x as integer
)
"Set_Homogenous":
(
x = readToken argsStream
if (tolower x) == "true" then Homogenous = true
else Homogenous = false
)
"Set_GroupOrType":
(
GroupOrType = readToken argsStream
)
"Set_Location_0":
(
x = readToken argsStream
y = readToken argsStream
z = readToken argsStream
x = (substring x 1 (x.count-1)) as float
y = (substring y 1 (y.count-1)) as float
z = z as float
Location = ConvertFromCRSpace [x,y,z]
)
"Set_Location_1":
(
x = readToken argsStream
y = readToken argsStream
z = readToken argsStream
x = (substring x 1 (x.count-1)) as float
y = (substring y 1 (y.count-1)) as float
z = z as float
Location2 = ConvertFromCRSpace [x,y,z]
)
"Set_InitialMode":
(
InitialMode =readToken argsStream
)
"Set_Direction":
(
x = readToken argsStream
Direction = x as integer
)
"Set_MaterialName":
(
MaterialName =readToken argsStream
)
"Set_Density":
(
x = readToken argsStream
Density = x as float
)
)
)
)
--while peekToken luaStream != undefined do format "%\n" (readToken luaStream)
),
fn CreateSpawnSpec =
(
luaText = StringStream ""
append luaText ("\tCPedSpawnSpec:Set_Type(\""+type+"\")\r\n")
append luaText ("\tCPedSpawnSpec:Set_GroupOrType(\""+GroupOrType+"\")\r\n")
if MaterialName != undefined then append luaText ("\tCPedSpawnSpec:Set_MaterialName(\""+MaterialName+"\")\r\n")
if InitialMode != undefined then append luaText ("\tCPedSpawnSpec:Set_InitialMode(\""+InitialMode+"\")\r\n")
if Location != undefined and Location2 == undefined then
(
crLoc = ConvertToCRSpace location
append luaText ("\tCPedSpawnSpec:Set_Location("+(crLoc.x as string)+","+(crLoc.y as string)+","+(crLoc.z as string)+")\r\n")
)
else if Location != undefined and Location2 != undefined then
(
crLoc = ConvertToCRSpace location
append luaText ("\tCPedSpawnSpec:Set_Location_0("+(crLoc.x as string)+","+(crLoc.y as string)+","+(crLoc.z as string)+")\r\n")
)
if Location2 != undefined then
(
crLoc2 = ConvertToCRSpace location2
append luaText ("\tCPedSpawnSpec:Set_Location_1("+(crLoc.x as string)+","+(crLoc.y as string)+","+(crLoc.z as string)+")\r\n")
)
if Homogenous != undefined and Homogenous == false then append luaText "\tCPedSpawnSpec:Set_Homogenous(false)\r\n"
if Radius != undefined then
(
append luaText ("\tCPedSpawnSpec:Set_Radius("+(radius as string)+")\r\n")
)
if PedCount != undefined then
(
append luaText ("\tCPedSpawnSpec:Set_Count("+(pedcount as string)+")\r\n")
)
if Density != undefined then
(
append luaText ("\tCPedSpawnSpec:Set_Density("+(density as string)+")\r\n")
)
if Direction != undefined then
(
append luaText ("\tCPedSpawnSpec:Set_Direction("+(direction as string)+")\r\n")
)
(luaText as string)
)
)
struct PedFile
(
PedFileName,
SpawnSpecs=#(),
fn LoadPedFile fname=
(
format "Loading Ped File %\n" fname
SpawnSpecs = #()
if (dotnetclass "system.xml.xmldocument") == undefined then
dotNet.loadAssembly "system.xml"
xmlDoc=dotNetObject "system.xml.xmlDocument"
PedFileName = fname
xmlDoc.load PedFileName
spawnSpecTags = xmlDoc.GetElementsByTagName "SPAWN_SPEC"
for i=1 to spawnSpecTags.count do
(
tag = spawnSpecTags.item (i-1)
--format "Spawn spec %\n" i
for j = 1 to tag.childnodes.count do
(
child = tag.childnodes.item (j-1)
--format "\tChild node % of type %\n" i child.nodetype
--if child.nodetype == child.nodetype.cdata then
(
luaText = child.value
--format "Node is CData: %\n" luaText
spawnSpec = PedFile_SpawnSpec()
spawnSpec.ParseSpawnSpec luaText
append SpawnSpecs spawnSpec
)
)
)
),
mapped function PlaceCube spec =
(
if spec.type=="Point" then
(
cube = Box name:("PedSpawn_" + spec.GroupOrType) pos: spec.Location length: 2 width:2 height:4
)
if spec.type == "Radius" then
(
sphereobj = Sphere name:("PedSpawn_"+spec.GroupOrType) pos: spec.Location radius:spec.Radius
)
),
function MakeSpawnSpecNode spec xmldoc =
(
specNode = xmlDoc.CreateElement "SPAWN_SPEC"
textEl = xmldoc.CreateTextNode (spec.CreateSpawnSpec())
specNode.AppendChild textEl
((xmldoc.GetElementsByTagName "PED_SPAWN").item 0).AppendChild specnode
),
fn SavePedFile fname:undefined =
(
if fname != undefined then PedFileName = fname
if (dotnetclass "system.xml.xmldocument") == undefined then
dotNet.loadAssembly "system.xml"
xmlDoc=dotNetObject "system.xml.xmlDocument"
xmlRoot = xmlDoc.CreateElement "PED_SPAWN"
xmlDoc.AppendChild xmlRoot
xmlDecl = xmlDoc.CreateXmlDeclaration "1.0" "" ""
xmlDoc.InsertBefore xmlDecl xmlRoot
for spec in spawnspecs do MakeSpawnSpecNode spec xmldoc
xmlDoc.save(PedFileName)
),
mapped function SwapPointForRadius spec =
(
spec.type = "Radius"
spec.radius = 3
spec.pedcount = 1
),
fn DebugPlaceCubes =
(
/*for spec in SpawnSpecs do
(
if spec.type=="Point" then
(
cube = Box name:("PedSpawn_" + spec.GroupOrType) pos: spec.Location length: 2 width:2 height:4
)
)*/
PlaceCube SpawnSpecs
)
)
fn TestPedFile =
(
fname = "G:\\Steam\\steamapps\\common\\Carmageddon_Reincarnation\\Data_Core\\Content\\Levels\\C1CityA\\PedFile_race1.xml"
pf = PedFile()
pf.LoadPedFile fname
pf.DebugPlaceCubes()
--pf.SwapPointForRadius pf.SpawnSpecs
pf.SavePedFile()
)
fn ExportSelectedToPedFile fname =
(
pf = PedFile()
pf.PedFileName = fname
for i=1 to $.count do (
if (substring $[i].name 1 9) == "PedSpawn_" then
(
spawnSpec = PedFile_SpawnSpec()
spawnSpec.GroupOrType = substring $[i].name 10 -1
spawnSpec.Location = $[i].pos
if(classOf $[i]) == Sphere then
(
spawnSpec.type="Radius"
spawnSpec.radius = $[i].Radius
spawnSpec.pedcount = 2
)
append pf.SpawnSpecs spawnSpec
)
)
pf.SavePedFile()
)