entities.def -> entities.ent convereter script beginning
[xonotic/xonotic-maps.pk3dir.git] / scripts / entities.def2ent
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my %types;
7 my %types_override;
8
9 open my $fh, '<', '../../xonotic-data.pk3dir/qcsrc/server/qc.asm'
10         or die "must have qc.asm in server qc";
11 while(<$fh>)
12 {
13         chomp;
14         if(/^\.(\w+) (\w+);$/)
15         {
16                 if($1 eq "float")
17                 {
18                         $types{$2} = "real";
19                 }
20                 elsif($1 eq "string")
21                 {
22                         $types{$2} = "string";
23                 }
24                 elsif($1 eq "vector")
25                 {
26                         $types{$2} = "real3";
27                 }
28         }
29 }
30
31 # specialization
32 $types{angle} = "angle";
33 $types{angles} = "angles";
34 $types{_color} = "color";
35 $types{colormod} = "color";
36 $types{killtarget} = "target";
37 $types{model2} = "model";
38 $types{model} = "model";
39 $types{noise} = "sound";
40 $types{noise1} = "sound";
41 $types{noise2} = "sound";
42 $types{noise3} = "sound";
43 $types{target2} = "target";
44 $types{target3} = "target";
45 $types{target4} = "target";
46 $types{targetname} = "targetname";
47 $types{target} = "target";
48
49 # missing definition in QC, q3map2 only
50 $types{_ambient} = "real";
51 $types{_anglescale} = "real";
52 $types{author} = "string";
53 $types{_blocksize} = "integer3";
54 $types{_castshadows} = "boolean";
55 $types{_celshader} = "texture";
56 $types{_clonename} = "targetname";
57 $types{_clone} = "target";
58 $types{_description} = "string";
59 $types{_deviance} = "real";
60 $types{fade} = "real";
61 $types{_farplanedist} = "real";
62 $types{_filterradius} = "real";
63 $types{_floodlight} = "string";
64 $types{_frame} = "real";
65 $types{gridsize} = "integer3";
66 $types{_ignoreleaks} = "boolean";
67 $types{_indexmap} = "texture";
68 $types{key1} = "string";
69 $types{key2} = "string";
70 $types{_layers} = "integer";
71 $types{_lightmapscale} = "real";
72 $types{light} = "real";
73 $types{max} = "real3";
74 $types{_mingridlight} = "real";
75 $types{_minlight} = "real";
76 $types{min} = "real3";
77 $types{modelscale_vec} = "real3";
78 $types{_noshadersun} = "boolean";
79 $types{_offsets} = "string";
80 $types{_receiveshadows} = "boolean";
81 $types{_remap} = "array";
82 $types{_samples} = "integer";
83 $types{_scale} = "real";
84 $types{_shader} = "texture";
85 $types{_sun} = "boolean";
86
87 # XML types:
88 # angle           specialisation of real - Yaw angle
89 # angles          specialisation of real3 - Pitch Yaw Roll
90 # array           an array of strings - value is a semi-colon-delimited string
91 # boolean         an integer - shows as a checkbox - true = non-zero
92 # color           specialisation of real3 - RGB floating-point colour
93 # direction       specialisation of real - Yaw angle, -1 = down, -2 = up
94 # integer2        two integer values
95 # integer3        three integer values
96 # integer         an integer value
97 # model           the VFS path to a model file
98 # skin            the VFS path to a skin file
99 # sound           the VFS path to a sound file
100 # target          a string that uniquely identifies an entity or group of entities
101 # targetname      a string that uniquely identifies an entity or group of entities
102 # texture         the VFS path to a texture file or a shader name
103
104
105 print <<EOF;
106 <?xml version="1.0"?>
107 <classes>
108 EOF
109
110 my $closetag;
111 my @spawnflags;
112 my $class;
113 while(<STDIN>)
114 {
115         chomp;
116         s/&/&amp;/g;
117         s/</&lt;/g;
118         s/>/&gt;/g;
119         s/"/&quot;/g;
120         if(/^\/\*QUAKED (\S+) \((\S+ \S+ \S+)\) \((\S+ \S+ \S+)\) \((\S+ \S+ \S+)\) ?(.*)/)
121         {
122                 $class = $1;
123                 print "<point name=\"$1\" color=\"$2\" box=\"$3 $4\">\n";
124                 $closetag = "</point>";
125                 @spawnflags = split / /, $5;
126         }
127         elsif(/^\/\*QUAKED (\S+) \((\S+ \S+ \S+)\) \? ?(.*)/)
128         {
129                 $class = $1;
130                 print "<group name=\"$1\" color=\"$2\">\n";
131                 $closetag = "</group>";
132                 @spawnflags = split / /, $3;
133         }
134         elsif(/^\*\/$/)
135         {
136                 print "$closetag\n";
137         }
138         elsif(/^([0-9a-z_]*): +(.*)/)
139         {
140                 my $type = $types_override{$class}{$1} || $types{$1};
141                 warn "No type for $1"
142                         if not defined $type;
143                 print "<$type key=\"$1\" name=\"$1\">$2</$type>\n";
144         }
145         elsif(/^([0-9A-Z_]*): +(.*)/)
146         {
147                 my $bit = [grep { $spawnflags[$_] eq $1; } 0..@spawnflags-1]->[0];
148                 warn "Cannot find bit $1 in @spawnflags\n"
149                         if not defined $bit;
150                 print "<flag key=\"$1\" name=\"$1\" bit=\"$bit\">$2</flag>\n";
151         }
152         else
153         {
154                 print "$_\n";
155         }
156 }
157
158 print <<EOF;
159 </classes>
160 EOF