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