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