GameScript: Cleanup obsolete cruft.
[gemrb.git] / admin / make_formation.py
blob28d4686ce587b5e71ecdbc467f07ce3023fefa07
1 #!/usr/bin/python
2 # -*-python-*-
3 # GemRB - Infinity Engine Emulator
4 # Copyright (C) 2009 The GemRB Project
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # This generates a formatio.2da file for GemRB, because it was becoming
21 # far too tedious to do this by hand. The output files have pairs of
22 # coordinates in the order of the party members.
24 # Run it as 'make_formation.py bg2 > override/bg2/formatio.2da' or similar.
26 # written (badly, sorry!) by fuzzie, feb 2nd 2009
28 # TODO: older games have focus points in different positions and different
29 # spacing (ie, coordinates have different offsets)
30 # eg, pst seems to usually have the focus point always on the lead char
32 num_coords = 20
34 def generate_header():
35 print "2DA V1.0"
36 print "-10"
37 print "# generated by make_formation.py, do not edit"
39 print "",
40 for i in range(num_coords):
41 print "X" + str(i + 1),
42 print "Y" + str(i + 1),
43 print
45 # A simple spaced line formation.
46 def generate_line(name):
47 print name,
48 yloc = 0
49 for i in range(num_coords):
50 print 0,
51 print yloc,
52 yloc += 36
53 print
55 # A 'T' shape formation, with 3 actors at the front.
56 def generate_t():
57 print "T",
58 for i in range(num_coords):
59 if i == 0:
60 # centre
61 print "0 0",
62 elif i == 1:
63 # right
64 print "48 0",
65 elif i == 2:
66 # left
67 print "-48 0",
68 elif i == 3:
69 # first line member (48 deeper)
70 print "0 48",
71 else:
72 # line member (36 deeper)
73 print 0,
74 print 48 + ((i - 3) * 36),
75 print
77 # A 'gathered' formation around a centre point.
78 def generate_gather():
79 print "GATHER",
80 for i in range(num_coords):
81 if i % 3 == 0:
82 if i < 3: # front row
83 xloc = 0 # centre
84 yloc = -36 # front
85 else:
86 xloc = 48 # right
87 yloc = 24 * (i / 3)
88 elif i % 3 == 1:
89 if i < 3: # front row
90 xloc = 48 # right
91 yloc = -24
92 else:
93 xloc = -48 # left
94 yloc = 24 * (i / 3)
95 else:
96 if i < 3: # front row
97 xloc = -48 # left
98 yloc = -24
99 else:
100 xloc = 0 # back
101 yloc = 36 * (i / 3)
102 print xloc,
103 print yloc,
104 print
106 # A block formation which places 4 on a row - first two in the
107 # middle (left then right), then two on the outside (left then right).
108 # With a party size of 6 this results in 4 on the first row and 2 on the
109 # second, hence the name.
110 def generate_4and2():
111 print "4AND2",
112 for i in range(num_coords):
113 if i % 4 == 0:
114 xloc = 0
115 elif i % 4 == 1:
116 xloc = 64
117 elif i % 4 == 2:
118 xloc = -64
119 else:
120 xloc = 128
121 yloc = (i / 4) * 48
122 print xloc,
123 print yloc,
124 print
126 # A wavy-line formation.
127 def generate_s(bg2style):
128 print "S",
129 for i in range(num_coords):
130 # x coordinate: +/- 15 for bg2, 0/64 otherwise
131 if i % 2 == 0:
132 if bg2style: print 15, # on right
133 else: print 0, # on left
134 else:
135 if bg2style: print -15, # on left
136 else: print 64, # on right
138 # y coordinate: 24 each
139 print i * 24,
140 print
142 # Returns the position in a formation of party member 'actorno',
143 # if the lead character must be in position 'leadpos'.
144 def corrected_position_for_actor(actorno, leadpos):
145 if actorno == 0: # lead
146 return leadpos
147 elif actorno < leadpos + 1: # in front of lead
148 return actorno - 1
149 else: # behind lead (normal position)
150 return actorno
152 # A wavy-line formation, with the lead character in the 4th position and
153 # the other characters in order (even if this leaves spaces!).
154 def generate_wavyline():
155 print "WAVYLINE",
156 for i in range(num_coords):
157 pos = corrected_position_for_actor(i, 3)
159 # x coordinate: +/- 15
160 if pos % 2 == 0:
161 print 15, # on right
162 else:
163 print -15, # on left
165 # y coordinate: 24 each
166 print pos * 24,
167 print
169 # A formation surrounding the main character. The next character goes
170 # at the front, then one left, then one right, then the next left/right
171 # at the back, then other characters trail behind the main one (it goes
172 # completely chaotic in real BG2, apparently).
173 def generate_protect():
174 print "PROTECT",
175 for i in range(num_coords):
176 if i == 0:
177 print "0 0", # centre
178 elif i == 1:
179 print "0 -36", # front
180 elif i == 2:
181 print "-64 0", # left
182 elif i == 3:
183 print "64 0", # right
184 elif i == 4:
185 print "-32 48", # back left
186 elif i == 5:
187 print "32 48", # back right
188 else:
189 print 0,
190 print 24 * (i - 5),
191 print
193 # A simple 3-across block formation.
194 def generate_3by2():
195 print "3BY2",
196 for i in range(num_coords):
197 # x coordinate
198 if i % 3 == 0:
199 print 0,
200 elif i % 3 == 1:
201 print 64,
202 else:
203 print -64,
205 # y coordinate
206 print (i / 3) * 48,
207 print
209 # A simple 2-across block formation.
210 def generate_2by3():
211 print "2BY3",
212 # left first, then right
213 left_side = True
214 yloc = 0
215 for i in range(num_coords):
216 if left_side: # left
217 print -24,
218 print yloc,
219 else: # right
220 print 24,
221 print yloc,
222 # first step back is 48, then 36
223 if yloc == 0:
224 yloc = 48
225 else:
226 yloc += 36
227 left_side = not left_side
228 print
230 # A horizontal line formation, with each character being placed
231 # alternately on right and left of the previous characters.
232 def generate_rank():
233 print "RANK",
234 for i in range(num_coords):
235 # lead character placed at focal point -32, spacing is 64
236 if i % 2 == 0:
237 print -32 - ((i / 2) * 64),
238 else:
239 print -32 + (((i + 1) / 2) * 64),
240 print 0,
241 print
243 def generate_v():
244 print "V",
245 for i in range(num_coords):
246 if i % 2 == 0:
247 xpos = (i / 2) * -15
248 else:
249 xpos = 64 + (i / 2) * -15
250 ypos = (i / 2) * 48
251 print xpos,
252 print ypos,
253 print
255 # A triangle with the lead character at the back. Focal point is at the
256 # front. Other characters are placed row-by-row starting at the front row,
257 # middle then left then right, with the maximum width being 3.
258 def generate_triangle():
259 print "TRIANGLE",
260 for i in range(num_coords):
261 pos = corrected_position_for_actor(i, 3)
262 if pos == 0:
263 print "0 0", # front
264 elif pos == 1:
265 print "-32 36", # middle left
266 elif pos == 2:
267 print "32 36", # middle right
268 else:
269 pos = pos - 3
270 # start 72 back, then move back 36 per row
271 ypos = 72 + ((pos / 3) * 36)
273 if pos % 3 == 0: # middle
274 xpos = 0
275 elif pos % 3 == 1: # left
276 xpos = -64
277 else: # right
278 xpos = 64
280 print xpos,
281 print ypos,
282 print
284 # A wide triangle with the lead character at the front. Characters are placed
285 # row-by-row. Second row: right then left. Third row: left then right then
286 # middle. Other rows: Middle first, left, right.
287 # TODO: the older games seem to have the third row ordered the same as the other ones
288 def generate_wedge():
289 print "WEDGE",
290 for i in range(num_coords):
291 if i == 0:
292 print "0 0", # front
293 elif i == 1:
294 print "64 36", # second row: right
295 elif i == 2:
296 print "-64 36", # second row: left
297 elif i == 3:
298 print "-124 72", # third row: left
299 elif i == 4:
300 print "124 72", # third row: right
301 elif i == 5:
302 print "0 72", # third row: middle
303 else:
304 pos = i - 6
305 if pos % 3 == 0:
306 print 0, # middle
307 elif pos % 3 == 1:
308 print -124, # left
309 else:
310 print 124, # right
311 ypos = 72 + (i / 3) * 36
312 print ypos,
313 print
315 from sys import argv,exit
317 if len(argv) != 2:
318 print "pass a game name on the command line"
319 exit(1)
321 generate_header()
323 if argv[1] == "bg1" or argv[1] == "iwd" or argv[1] == "iwd2" or argv[1] == "how":
324 generate_line("FOLLOW") # TODO: should be hard-coded game logic
325 generate_t()
326 generate_gather()
327 generate_4and2()
328 generate_3by2()
329 generate_protect() # TODO: wrong formation for bg1 or others?
330 generate_2by3()
331 generate_rank()
332 generate_v()
333 generate_wedge()
334 generate_s(False)
335 generate_line("LINE")
337 if argv[1] == "pst":
338 generate_line("FOLLOW") # TODO: should be hard-coded game logic
339 generate_t()
340 generate_gather()
341 generate_4and2()
342 generate_3by2()
343 generate_protect()
344 generate_2by3()
345 generate_rank()
346 generate_v()
347 generate_wedge()
348 generate_s(False)
349 generate_line("LINE")
350 print "NONE",
351 for i in range(num_coords):
352 print "0 0",
353 print
355 if argv[1] == "bg2":
356 generate_line("FOLLOW") # TODO: should be hard-coded game logic
357 generate_t()
358 generate_gather()
359 generate_wavyline()
360 generate_3by2()
361 generate_protect()
362 generate_2by3()
363 generate_rank()
364 generate_triangle()
365 generate_wedge()
366 generate_s(True)
367 generate_line("LINE")
369 if argv[1] == "test1":
370 generate_line("LINE")
371 generate_t()
372 generate_v()