… | |
… | |
2 | |
2 | |
3 | # this script checks, fixes and simplifies @match expressions in a map |
3 | # this script checks, fixes and simplifies @match expressions in a map |
4 | |
4 | |
5 | use Crossfire::Map; |
5 | use Crossfire::Map; |
6 | |
6 | |
7 | sub fix($) { |
7 | sub fix_msg($) { |
8 | my ($msg) = @_; |
8 | my ($msg) = @_; |
9 | |
9 | |
10 | local $_ = $msg; |
10 | local $_ = $msg; |
11 | |
11 | |
12 | # fx pretty common error of having "* First line of response" |
12 | # fx pretty common error of having "* First line of response" |
… | |
… | |
35 | $_ |
35 | $_ |
36 | } |
36 | } |
37 | |
37 | |
38 | sub patch_perl { |
38 | sub patch_perl { |
39 | my ($arch) = @_; |
39 | my ($arch) = @_; |
40 | my $patched = 0; |
|
|
41 | |
40 | |
42 | my @appendinv; |
41 | my $patched; |
43 | |
42 | |
44 | for (@{$arch->{inventory} || []}) { |
43 | my $inv = $arch->{inventory} || []; |
|
|
44 | |
|
|
45 | for (@$inv) { |
|
|
46 | if ($_->{type} == 116 || $_->{_name} =~ /^event_/) { |
|
|
47 | # crossfire to old crossfire+ |
45 | if ($_->{slaying} eq '/python/IPO/send.py') { |
48 | if ($_->{slaying} eq '/python/IPO/send.py') { |
46 | $_->{title} = 'perl'; |
49 | $_->{title} = 'perl'; |
47 | $_->{slaying} = 'ipo'; |
50 | $_->{slaying} = 'ipo'; |
48 | $patched++ |
51 | $patched++ |
49 | } elsif ($_->{slaying} eq '/python/IPO/receive.py') { |
52 | } elsif ($_->{slaying} eq '/python/IPO/receive.py') { |
50 | $_->{title} = 'perl'; |
53 | $_->{title} = 'perl'; |
51 | $_->{slaying} = 'ipo'; |
54 | $_->{slaying} = 'ipo'; |
52 | $patched++ |
55 | $patched++; |
53 | } elsif ($_->{slaying} eq '/python/IPO/board.py') { |
56 | } elsif ($_->{slaying} eq '/python/IPO/board.py') { |
54 | push @appendinv, { _name => 'event_apply', title => 'perl', slaying => 'board' }; |
57 | $_ = { _name => 'event_apply', title => 'perl', slaying => 'board' }; |
55 | $arch->{msg} = '@match *'."\n".'@eval board::command $who, $msg, $npc'."\n"; |
58 | $arch->{msg} = '@match *'."\n".'@eval board::command $who, $msg, $npc'."\n"; |
56 | $patched++ |
59 | $patched++; |
57 | } elsif ($_->{slaying} eq '/python/IPO/say.py') { |
60 | } elsif ($_->{slaying} eq '/python/IPO/say.py') { |
58 | $arch->{msg} = '@match *'."\n".'@eval ipo::command $who, $msg, $npc'."\n"; |
61 | $arch->{msg} = '@match *'."\n".'@eval ipo::command $who, $msg, $npc'."\n"; |
|
|
62 | $_ = undef; |
59 | $patched++ |
63 | $patched++; |
60 | } elsif ($_->{slaying} eq '/python/IPO/banksay.py') { |
64 | } elsif ($_->{slaying} eq '/python/IPO/banksay.py') { |
61 | $arch->{msg} = '@match *'."\n".'@eval bank::command $who, $msg, $npc'."\n"; |
65 | $arch->{msg} = '@match *'."\n".'@eval bank::command $who, $msg, $npc'."\n"; |
|
|
66 | $_ = undef; |
62 | $patched++ |
67 | $patched++; |
|
|
68 | } |
|
|
69 | |
|
|
70 | # old crossfire+ to new plug-in system |
|
|
71 | if ($_ && $_->{title} eq "perl") { |
|
|
72 | if ($_->{slaying} eq "board") { |
|
|
73 | push @{$arch->{attach}}, ["board"]; |
|
|
74 | $_ = undef; |
|
|
75 | $patched++; |
|
|
76 | } elsif ($_->{slaying} eq "ipo") { |
|
|
77 | if ($_->{_name} eq "event_close") { |
|
|
78 | push @{$arch->{attach}}, ["ipo_mailbox"]; |
|
|
79 | } elsif ($_->{_name} eq "event_apply") { |
|
|
80 | # |
|
|
81 | } |
|
|
82 | $_ = undef; |
|
|
83 | $patched++; |
|
|
84 | } elsif ($_->{slaying} eq "nimbus") { |
|
|
85 | push @{$arch->{attach}}, ["nimbus_exit", { restore => $_->{name} eq "restore"}]; |
|
|
86 | $_ = undef; |
|
|
87 | $patched++; |
|
|
88 | } elsif ($_->{slaying} eq "minesweeper") { |
|
|
89 | push @{$arch->{attach}}, ["minesweeper", { split /(?:\s+|=)/, $_->{name} }]; |
|
|
90 | $_ = undef; |
|
|
91 | $patched++; |
|
|
92 | } elsif ($_->{slaying} eq "reseller") { |
|
|
93 | if ($_->{_name} eq "event_drop_on") { |
|
|
94 | push @{$arch->{attach}}, ["reseller_floor"]; |
|
|
95 | } elsif ($_->{_name} eq "event_trigger") { |
|
|
96 | my ($a, $b, $c) = split /,/, $_->{name}; |
|
|
97 | push @{$arch->{attach}}, ["reseller_shopmat", {npc_name => $a, npc_x => $b, npc_y => $c}]; |
|
|
98 | } |
|
|
99 | $_ = undef; |
|
|
100 | $patched++; |
|
|
101 | } else { |
|
|
102 | warn "WARNING: unsupported perl event<$_->{slaying}>\n";#d# |
|
|
103 | } |
|
|
104 | } |
63 | } |
105 | } |
64 | } |
106 | } |
65 | |
107 | |
66 | if ($arch->{inventory}) { |
108 | $arch->{inventory} = [grep $_, @$inv]; |
67 | my @oinv = |
|
|
68 | grep { |
|
|
69 | my $o = $_; |
|
|
70 | not grep { $o->{slaying} eq $_ } |
|
|
71 | ('/python/IPO/board.py', '/python/IPO/say.py', '/python/IPO/banksay.py') |
|
|
72 | } @{$arch->{inventory}}; |
|
|
73 | $patched++ if @oinv < @{$arch->{inventory}}; |
|
|
74 | @{$arch->{inventory}} = @oinv; |
|
|
75 | } |
|
|
76 | |
|
|
77 | if (@appendinv) { |
|
|
78 | $arch->{inventory} = [@{$arch->{inventory} || []}, @appendinv]; |
|
|
79 | $patched++ |
|
|
80 | } |
|
|
81 | |
109 | |
82 | $patched |
110 | $patched |
83 | } |
111 | } |
84 | |
112 | |
85 | for $path (@ARGV) { |
113 | for $path (@ARGV) { |
… | |
… | |
103 | |
131 | |
104 | next unless $a->{msg} =~ /^\@match /; |
132 | next unless $a->{msg} =~ /^\@match /; |
105 | |
133 | |
106 | my $old = $a->{msg}; |
134 | my $old = $a->{msg}; |
107 | |
135 | |
108 | $a->{msg} =~ s/^(\@match\s+)(.*)$/$1 . fix $2/gme; |
136 | $a->{msg} =~ s/^(\@match\s+)(.*)$/$1 . fix_msg $2/gme; |
109 | |
137 | |
110 | $dirty ||= $old ne $a->{msg}; |
138 | $dirty ||= $old ne $a->{msg}; |
111 | } |
139 | } |
112 | |
140 | |
113 | $map->write_file ($path) |
141 | $map->write_file ($path) |