ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/bin/cfmap-plushify
Revision: 1.11
Committed: Wed Oct 28 08:51:27 2009 UTC (14 years, 7 months ago) by root
Branch: MAIN
Changes since 1.10: +27 -21 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/bin/perl
2    
3 root 1.8 #TODO: dwall3_3 => dwall_3_3
4     #TODO: fix dialogue
5     #TODO: update file format version
6    
7 elmex 1.1 # this script checks, fixes and simplifies @match expressions in a map
8    
9 root 1.9 use Deliantra::Map;
10 elmex 1.1
11 root 1.11 our $dirty;
12    
13 root 1.6 sub fix_msg($) {
14 elmex 1.1 my ($msg) = @_;
15    
16     local $_ = $msg;
17    
18     # fx pretty common error of having "* First line of response"
19     my $response = s/^\* (.*)/*/ ? "\n$1" : "";
20    
21     warn "$path ($_) unexpected characters in match \n" if !/^[a-zA-Z\[\]\|\*\!\' 0-9\-\?]+$/;
22    
23     s/\[(.)(.)\]/(lc $1) eq (lc $2) ? lc $1 : "[$1$2]"/ge;
24    
25     my %alt;
26    
27     for my $kw (split /\|/) {
28     $kw =~ s/^\s+//;
29     $kw =~ s/\s+$//;
30    
31     $alt{lc $kw} = $kw;
32     }
33    
34     $_ = join "|", sort keys %alt;
35    
36     $_ .= $response;
37    
38     warn "$path <$msg><$_>\n" if $_ ne $msg;
39     warn "$path ($_) unexpected characters in match\n" if /[\[\]]/;
40    
41     $_
42     }
43    
44 root 1.11 sub patch_face($) {
45     if ($_[0]{face} =~ /\.[1-9]\d\d$/) {
46     $_[0]{face} =~ s/\.([2-9])\1\1$/.x1$1/; # 222, 333, 444
47     $_[0]{face} =~ s/\.1(\d\d)$/.x$1/; # 1AB xAB
48     $dirty++;
49     }
50     }
51    
52     sub patch_inv($) {
53 elmex 1.1 my ($arch) = @_;
54    
55 root 1.6 my $inv = $arch->{inventory} || [];
56    
57     for (@$inv) {
58 root 1.11 patch_face $_;
59    
60 root 1.6 if ($_->{type} == 116 || $_->{_name} =~ /^event_/) {
61 root 1.10 # deliantra to old deliantra+
62 root 1.6 if ($_->{slaying} eq '/python/IPO/send.py') {
63     $_->{title} = 'perl';
64     $_->{slaying} = 'ipo';
65 root 1.11 $dirty++
66 root 1.6 } elsif ($_->{slaying} eq '/python/IPO/receive.py') {
67     $_->{title} = 'perl';
68     $_->{slaying} = 'ipo';
69 root 1.11 $dirty++;
70 root 1.6 } elsif ($_->{slaying} eq '/python/IPO/board.py') {
71     $_ = { _name => 'event_apply', title => 'perl', slaying => 'board' };
72     $arch->{msg} = '@match *'."\n".'@eval board::command $who, $msg, $npc'."\n";
73 root 1.11 $dirty++;
74 root 1.6 } elsif ($_->{slaying} eq '/python/IPO/say.py') {
75     $arch->{msg} = '@match *'."\n".'@eval ipo::command $who, $msg, $npc'."\n";
76     $_ = undef;
77 root 1.11 $dirty++;
78 root 1.6 } elsif ($_->{slaying} eq '/python/IPO/banksay.py') {
79     $arch->{msg} = '@match *'."\n".'@eval bank::command $who, $msg, $npc'."\n";
80     $_ = undef;
81 root 1.11 $dirty++;
82 root 1.6 }
83    
84 root 1.10 # old deliantra+ to new plug-in system
85 root 1.6 if ($_ && $_->{title} eq "perl") {
86     if ($_->{slaying} eq "board") {
87     push @{$arch->{attach}}, ["board"];
88     $_ = undef;
89 root 1.11 $dirty++;
90 root 1.6 } elsif ($_->{slaying} eq "ipo") {
91     if ($_->{_name} eq "event_close") {
92     push @{$arch->{attach}}, ["ipo_mailbox"];
93     } elsif ($_->{_name} eq "event_apply") {
94     #
95     }
96     $_ = undef;
97 root 1.11 $dirty++;
98 root 1.6 } elsif ($_->{slaying} eq "nimbus") {
99     push @{$arch->{attach}}, ["nimbus_exit", { restore => $_->{name} eq "restore"}];
100     $_ = undef;
101 root 1.11 $dirty++;
102 root 1.6 } elsif ($_->{slaying} eq "minesweeper") {
103     push @{$arch->{attach}}, ["minesweeper", { split /(?:\s+|=)/, $_->{name} }];
104     $_ = undef;
105 root 1.11 $dirty++;
106 root 1.6 } elsif ($_->{slaying} eq "reseller") {
107     if ($_->{_name} eq "event_drop_on") {
108     push @{$arch->{attach}}, ["reseller_floor"];
109     } elsif ($_->{_name} eq "event_trigger") {
110     my ($a, $b, $c) = split /,/, $_->{name};
111     push @{$arch->{attach}}, ["reseller_shopmat", {npc_name => $a, npc_x => $b, npc_y => $c}];
112     }
113     $_ = undef;
114 root 1.11 $dirty++;
115 root 1.6 } else {
116     warn "WARNING: unsupported perl event<$_->{slaying}>\n";#d#
117     }
118     }
119 elmex 1.1 }
120     }
121 elmex 1.2
122 root 1.6 $arch->{inventory} = [grep $_, @$inv];
123 elmex 1.1 }
124    
125     for $path (@ARGV) {
126     eval {
127     open my $fh, "<:raw:perlio:utf8", $path
128     or die "$path: $!\n";
129    
130 root 1.7 <$fh> =~ /^arch \S+$/
131 root 1.10 or die "$path: not a deliantra map file\n";
132 elmex 1.1
133 root 1.9 my $map = new_from_file Deliantra::Map $path
134 elmex 1.1 or die "$path: file load error\n";
135    
136 root 1.11 $dirty = 0;
137 elmex 1.1
138     for my $a (map @$_, grep $_, map @$_, grep $_, @{ $map->{map} }) {
139 root 1.11 patch_face $a;
140    
141     patch_inv $a if $a->{inventory};
142 elmex 1.1
143     next unless $a->{msg} =~ /^\@match /;
144    
145     my $old = $a->{msg};
146    
147 root 1.6 $a->{msg} =~ s/^(\@match\s+)(.*)$/$1 . fix_msg $2/gme;
148 elmex 1.1
149     $dirty ||= $old ne $a->{msg};
150     }
151    
152     $map->write_file ($path)
153     if $dirty;
154    
155     1
156 root 1.10 } or $@ =~ /not a deliantra map/ or warn $@;
157 elmex 1.1 }
158