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