]> git.pond.sub.org Git - empserver/blob - tests/actofgod/geninput.pl
contact: Create EF_CONTACT table of struct contactstr
[empserver] / tests / actofgod / geninput.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 my $MAXNOC = 99;
7 my $xmax = 31;
8 my $ymax = 15;
9 my $STAT_GOD = 5;
10 my $INT_MAX = 0x7fffffff;
11 my $INT_MIN = -$INT_MAX - 1;
12
13 my %ef2edit = (
14     sect => 'l',
15     ship => 's',
16     plane => 'p',
17     land => 'u',
18     nuke => 'n',
19     nat => 'c',
20 );
21
22 my %edit2setres = (
23     i => 'i',
24     g => 'g',
25     c => 'o',
26     f => 'f',
27     u => 'u',
28 );
29
30 my %edit2setsect = (
31     o => 'ow',
32     O => 'ol',
33     i => 'i',
34     g => 'g',
35     c => 'oi',
36     e => 'e',
37     M => 'mi',
38     m => 'mo',
39     a => 'a',
40     w => 'w',
41     f => 'f',
42     u => 'u',
43 );
44
45 sub edit {
46     my ($ef, $id, $key, @rest) = @_;
47     my $args = join(' ', @rest);
48     print "edit $ef2edit{$ef} $id $key $args\n";
49 }
50
51 sub iedit {
52     my ($ef, $id, @rest) = @_;
53     print "edit $ef2edit{$ef} $id\n";
54     for my $inp (@rest) {
55         print "$inp\n";
56     }
57     print "\n";
58 }
59
60 sub next_id {
61     my ($ef, $id) = @_;
62     if ($ef ne 'sect') {
63         return $id + 1;
64     }
65     my ($x, $y) = split /,/, $id;
66     $x += 2;
67     return "$x,$y";
68 }
69
70 sub edit_int1 {
71     my ($ef, $id, $key, $lob, $upb) = @_;
72     edit($ef, $id, $key, $lob);
73     $id = next_id($ef, $id);
74     edit($ef, $id, $key, $lob - 1)
75         if ($lob > $INT_MIN);
76     $id = next_id($ef, $id);
77     edit($ef, $id, $key, $upb);
78     $id = next_id($ef, $id);
79     edit($ef, $id, $key, $upb + 1)
80         if ($upb < $INT_MAX);
81 }
82
83 sub edit_int {
84     my ($ef, $id, @rest) = @_;
85     for my $it (@rest) {
86         edit_int1($ef, $id, @$it);
87     }
88 }
89
90 sub setres {
91     my ($id, $key, $val) = @_;
92     print "setres $key $id $val\n";
93 }
94
95 sub setsect {
96     my ($id, $key, $val) = @_;
97     print "setsect $key $id $val\n";
98 }
99
100 sub give {
101     my ($id, $key, $val) = @_;
102     print "give $key $id $val\n";
103 }
104
105 sub swaps {
106     my ($id1, $id2) = @_;
107     print "swaps $id1 $id2\ny\n";
108 }
109
110 ## Sector
111
112 # invalid key
113 edit('sect', '0,0', '@', 0);
114 setres('0,0', '@', 0);
115 setsect('0,0', '@', 0);
116 give('0,0', '@', 0);
117
118 # own oldown che_target
119 for my $key ('o', 'O', 'X') {
120     edit('sect', '1,7', $key, 0);
121     edit('sect', '1,7', $key, -1);
122     edit('sect', '3,7', $key, $MAXNOC - 1);
123     edit('sect', '3,7', $key, $MAXNOC);
124 }
125 edit('sect', '5,7', 'o', 2);
126 for my $key ('ow', 'ol') {
127     setsect('7,7', $key, 0);
128     setsect('7,7', $key, -1);
129     setsect('9,7', $key, $MAXNOC - 1);
130     setsect('9,7', $key, $MAXNOC);
131 }
132 setsect('11,7', 'ow', 2);
133
134 # x,y (copy)
135 edit('sect', '1,7', 'L', '5,-7');
136 edit('sect', '3,-7', 'L', '3,-7', 'L', '1,0');
137
138 # effic mobil iron gmin fertil oil uran work loyalty che pstage ptime
139 # fallout avail mines road rail defense
140 sub sect_int {
141     for my $it (@_) {
142         my ($key, $lob, $upb) = @$it;
143         edit_int1('sect', '1,1', $key, $lob, $upb);
144         my $rkey = $edit2setres{$key};
145         if (defined $rkey) {
146             setres('2,2', $rkey, $lob);
147             setres('4,2', $rkey, $lob - 1);
148             setres('6,2', $rkey, $upb);
149             setres('8,2', $rkey, $upb + 1);
150         }
151         my $skey = $edit2setsect{$key};
152         if (defined $skey) {
153             setsect('1,3', $skey, $INT_MIN);
154             setsect('3:7,3', $skey, 1);
155             setsect('5,3', $skey, $INT_MAX);
156             setsect('7,3', $skey, -1);
157         }
158     }
159 }
160 sect_int(
161     ['e', 0, 100],
162     ['m', -127, 127],
163     ['i', 0, 100],
164     ['g', 0, 100],
165     ['f', 0, 100],
166     ['c', 0, 100],
167     ['u', 0, 100],
168     ['w', 0, 100],
169     ['l', 0, 127],
170     ['x', 0, 255],
171     ['p', 0, 4],
172     ['t', 0, 32767],
173     ['F', 0, 9999],
174     ['a', 0, 9999],
175     ['M', 0, 32767],
176     ['R', 0, 100],
177     ['r', 0, 100],
178     ['d', 0, 100],
179 );
180
181 # special case: unowned sector
182 edit('sect', '-1,-1', 'i', 50);
183 setres('-1,-1', 'g', 50);
184 setsect('-1,-1', 'f', 50);
185
186 # special case: mines in occupied sector
187 setsect('1:3,-3', 'ol', 1);
188 setsect('1,-3', 'mi', 1);
189 edit('sect', '3,-3', 'M', 1);
190
191 # dist
192 edit('sect', '2,4', 'D', '4,4');
193 edit('sect', '4,4', 'D', '4,4');
194
195 # des newdes
196 for my $key ('s', 'S') {
197     edit('sect', '6:8,4', $key, '+');
198     edit('sect', '6,4', $key, '+');
199     edit('sect', '8,4', $key, ',');
200 }
201
202 # multiple arguments
203 edit('sect', '1,5', 'm', 1, 'a', 1);
204
205 # interactive edit
206 iedit('sect', '3,5', 'm 2', 'a 1');
207 iedit('sect', '5,5', ' ');
208 iedit('sect', '7:9,5', 'e 1', '', 'e 2');
209
210 # give
211 give('2,6', 'l', $INT_MIN);
212 give('4:8,6', 'c', 1);
213 give('6,6', 'c', $INT_MAX);
214 give('8,6', 'c', -1);
215
216 # swapsector
217 swaps('-2,2', '2,-2');
218
219 ## Ship, plane, land unit, nuke
220
221 for my $ef ('ship', 'plane', 'land', 'nuke') {
222     # invalid key
223     edit($ef, 0, '@', 0);
224     # own
225     edit($ef, 0, 'O', 0);
226     edit($ef, 0, 'O', -1);
227     edit($ef, 1, 'O', $MAXNOC - 1);
228     edit($ef, 1, 'O', $MAXNOC);
229     edit($ef, 2, 'O', 2);
230     edit($ef, 4, 'O', 0, 'O', '3');
231     # uid (copy)
232     edit($ef, 3, 'U', 5, 'U', 3);
233     edit($ef, 0, 'U', 0, 'U', -1);
234     # x,y
235     my $key = $ef eq 'plane' ? 'l' : 'L';
236     edit($ef, 2, $key, '3,-1');
237     edit($ef, 3, $key, '1,-1');
238 }
239
240 # ship: type
241 edit('ship', 6, 't', 'lc', 'O', 1, 't', 'lc', 't', 'hc', 'g', 8, 't', 'lc');
242
243 # ship: effic mobil tech pstage ptime milit
244 edit_int('ship', 2, (
245     ['E', 0, 100],
246     ['M', -127, 127],
247     ['T', 0, 32767],
248     ['a', 0, 4],
249     ['b', 0, 32767],
250     ['m', 0, 50],
251 ));
252
253 # plane: type
254 edit('plane', 6, 'T', 'mb', 'O', 1, 'T', 'mb', 'T', 'hb', 'T', 'mb');
255 edit('plane', 7, 'r', 255, 'T', 'hb', 'T', 'mb');
256 edit('plane', 8, 'T', 'hb', 'r', 255, 'T', 'f1');
257
258 # plane: effic mobil range tech
259 edit_int('plane', 2, (
260     ['e', 0, 100],
261     ['m', -127, 127],
262     ['r', 0, 9],
263     ['t', 50, 32767],
264 ));
265
266 # land: type
267 edit('land', 6, 'T', 'art', 'O', 1, 'T', 'art', 'T', 'hat', 'g', 12,
268      'T', 'art');
269
270 # land: effic mobil tech harden retreat milit
271 edit_int('land', 2, (
272     ['e', 0, 100],
273     ['M', -127, 127],
274     ['t', 50, 32767],
275     ['F', 0, 127],
276     ['Z', 0, 100],
277     ['m', 0, 25],
278 ));
279
280 # nuke: type
281 edit('nuke', 6, 't', '15kt', 'O', 1, 't', '15kt', 't', '50kt', 't', '15kt');
282
283 # nuke: tech
284 edit_int('nuke', 2, (
285     ['T', 280, 32767],
286 ));
287
288 # fleet, wing, army
289 sub unit_group {
290     my ($ef, $key) = @_;
291     edit($ef, 2, $key, '~');
292     edit($ef, 3, $key, 'a');
293 }
294 unit_group('ship', 'F');
295 unit_group('plane', 'w');
296 unit_group('land', 'a');
297
298 # rpath, rflags
299 for my $ef ('ship', 'land') {
300     edit($ef, 2, 'R', '""');
301     edit($ef, 3, 'R', 'jj');
302     # Take care to have only valid bits set in final state
303     edit($ef, 2, 'W', 0, 'W', 1);
304     edit($ef, 3, 'W', 513, 'W', 1030, 'W', 2);
305 }
306
307 # plane: flags
308 # Take care to have only valid bits set in final state
309 edit('plane', 2, 'f', 4);
310
311 # carrier
312 sub unit_carrier {
313     my ($ef, $key1, $key2) = @_;
314     edit($ef, 2, $key1, -1, $key1, 9999);
315     edit($ef, 3, $key1, 3);
316     edit($ef, 4, $key1, 4, $key2, 4) if defined $key2;
317 }
318 unit_carrier('plane', 's', 'y');
319 unit_carrier('land', 'S', 'Y');
320 unit_carrier('nuke', 'p');
321
322 # special case: move carrier's cargo away
323 edit('plane', 4, 'l', '5,1');
324
325 # special case: load teleports to carrier
326 edit('land', 4, 'S', 2);
327
328 # interactive edit
329 iedit('ship', 0, 'M 2', 'm 1', 'f 1');
330 iedit('ship', 0, 'R n', 'R ""');
331 iedit('plane', 0, 'm 2', 'y -1');
332 iedit('land', 0, 'M 2', 'Y -1');
333 iedit('nuke', 0, 'S a', 'p -1');
334
335 ## Nation
336
337 # invalid key
338 edit('nat', 0, '@', 0);
339
340 # btus reserve timeused money
341
342 edit_int('nat', 1, (
343     ['b', 0, 640],
344     ['m', 0, 2147483647],
345     ['u', 0, 86400],
346     ['M', -2147483648, 2147483647],
347 ));
348
349 # tgms
350 # Take care to use ones that won't receive further telegrams
351 edit('nat', 6, 't', -1);
352 edit('nat', 7, 't', 65536);
353
354 # tlev rlev elev hlev
355 for my $key ('T', 'R', 'E', 'H') {
356     edit('nat', 1, $key, 3.14);
357     edit('nat', 2, $key, 100);
358     edit('nat', 3, $key, -1);
359 }
360
361 # cnam
362 edit('nat', 1, 'n', 'POGO');
363 edit('nat', 2, 'n', '2');
364 edit('nat', 3, 'n', 'drei');
365
366 # pnam
367 edit('nat', 1, 'r', 1);
368 edit('nat', 2, 'r', '012345678901234567890123456789');
369
370 # xcap,ycap xorg,yorg
371 for my $key ('c', 'o') {
372     edit('nat', 1, $key, '0,0');
373     edit('nat', 2, $key, '2,0');
374 }
375
376 # status
377 # Refs to nats with status 0 are invalid, take care to use
378 # unreferenced ones for that
379 edit('nat', 6, 's', 0);
380 edit('nat', 7, 's', -1);
381 edit('nat', 4, 's', $STAT_GOD);
382 edit('nat', 5, 's', $STAT_GOD + 1);
383
384 # interactive edit
385 iedit('nat', 5, 'b 640', 'T 1');
386
387 ## Epilog: read telegrams (they're not in xdump)
388 for my $cnum (0, 1, 2, 3, 4, 5, 98) {
389     print "read $cnum\n";
390 }