ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/bin/cfmap-plushify
Revision: 1.2
Committed: Wed Aug 9 13:41:53 2006 UTC (17 years, 9 months ago) by elmex
Branch: MAIN
Changes since 1.1: +6 -3 lines
Log Message:
fixed it :)

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/bin/perl
2    
3     # this script checks, fixes and simplifies @match expressions in a map
4    
5     use Crossfire::Map;
6    
7     sub fix($) {
8     my ($msg) = @_;
9    
10     local $_ = $msg;
11    
12     # fx pretty common error of having "* First line of response"
13     my $response = s/^\* (.*)/*/ ? "\n$1" : "";
14    
15     warn "$path ($_) unexpected characters in match \n" if !/^[a-zA-Z\[\]\|\*\!\' 0-9\-\?]+$/;
16    
17     s/\[(.)(.)\]/(lc $1) eq (lc $2) ? lc $1 : "[$1$2]"/ge;
18    
19     my %alt;
20    
21     for my $kw (split /\|/) {
22     $kw =~ s/^\s+//;
23     $kw =~ s/\s+$//;
24    
25     $alt{lc $kw} = $kw;
26     }
27    
28     $_ = join "|", sort keys %alt;
29    
30     $_ .= $response;
31    
32     warn "$path <$msg><$_>\n" if $_ ne $msg;
33     warn "$path ($_) unexpected characters in match\n" if /[\[\]]/;
34    
35     $_
36     }
37    
38     sub patch_ipo {
39     my ($arch) = @_;
40     my $patched = 0;
41    
42     my @appendinv;
43    
44     for (@{$arch->{inventory} || []}) {
45     if ($_->{slaying} eq '/python/IPO/send.py') {
46     $_->{title} = 'perl';
47     $_->{slaying} = 'ipo';
48     $patched++
49     } elsif ($_->{slaying} eq '/python/IPO/receive.py') {
50     $_->{title} = 'perl';
51     $_->{slaying} = 'ipo';
52     $patched++
53     } elsif ($_->{slaying} eq '/python/IPO/board.py') {
54     push @appendinv, { _name => 'event_apply', title => 'perl', slaying => 'board' };
55     $arch->{msg} = '@match *'."\n".'@eval board::command $who, $msg, $npc'."\n";
56     $patched++
57     } elsif ($_->{slaying} eq '/python/IPO/say.py') {
58     $arch->{msg} = '@match *'."\n".'@eval ipo::command $who, $msg, $npc'."\n";
59     $patched++
60     }
61     }
62 elmex 1.2
63 elmex 1.1 if ($arch->{inventory}) {
64 elmex 1.2 my @oinv =
65 elmex 1.1 grep {
66     $_->{slaying} ne '/python/IPO/board.py'
67     and $_->{slaying} ne '/python/IPO/say.py'
68     } @{$arch->{inventory}};
69 elmex 1.2 $patched++ if @oinv < @{$arch->{inventory}};
70     @{$arch->{inventory}} = @oinv;
71 elmex 1.1 }
72    
73     if (@appendinv) {
74     $arch->{inventory} = [@{$arch->{inventory} || []}, @appendinv];
75 elmex 1.2 $patched++
76 elmex 1.1 }
77    
78     $patched
79     }
80    
81     for $path (@ARGV) {
82     eval {
83     open my $fh, "<:raw:perlio:utf8", $path
84     or die "$path: $!\n";
85    
86     <$fh> =~ /^arch map$/
87     or die "$path: not a crossfire map file\n";
88    
89     my $map = new_from_file Crossfire::Map $path
90     or die "$path: file load error\n";
91    
92     my $dirty;
93    
94     for my $a (map @$_, grep $_, map @$_, grep $_, @{ $map->{map} }) {
95 elmex 1.2 if ($a->{inventory} and patch_ipo ($a)) {
96 elmex 1.1 $dirty = 1;
97     next;
98     }
99    
100     next unless $a->{msg} =~ /^\@match /;
101    
102     my $old = $a->{msg};
103    
104     $a->{msg} =~ s/^(\@match\s+)(.*)$/$1 . fix $2/gme;
105    
106     $dirty ||= $old ne $a->{msg};
107     }
108    
109     $map->write_file ($path)
110     if $dirty;
111    
112     1
113     } or $@ =~ /not a crossfire map/ or warn $@;
114     }
115