ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/bin/cfmap-plushify
Revision: 1.10
Committed: Tue Jul 29 09:28:43 2008 UTC (15 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-1_222, rel-1_221, rel-1_24, rel-1_25, rel-1_22, rel-1_23
Changes since 1.9: +4 -4 lines
Log Message:
*** empty log message ***

File Contents

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