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

# 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;
10 use Deliantra::Map;
11
12 load_archetypes;
13
14 our $dirty;
15
16 sub fix_msg($) {
17 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 sub patch_arch($) {
48 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
54 unless (exists $ARCH{ $_[0]{_name} }) {
55 die "$_[0]{_name}\n";#d#
56 }
57 }
58
59 sub patch_inv($) {
60 my ($arch) = @_;
61
62 my $inv = $arch->{inventory} || [];
63
64 for (@$inv) {
65 patch_arch $_;
66
67 if ($_->{type} == 116 || $_->{_name} =~ /^event_/) {
68 # deliantra to old deliantra+
69 if ($_->{slaying} eq '/python/IPO/send.py') {
70 $_->{title} = 'perl';
71 $_->{slaying} = 'ipo';
72 $dirty++
73 } elsif ($_->{slaying} eq '/python/IPO/receive.py') {
74 $_->{title} = 'perl';
75 $_->{slaying} = 'ipo';
76 $dirty++;
77 } 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 $dirty++;
81 } elsif ($_->{slaying} eq '/python/IPO/say.py') {
82 $arch->{msg} = '@match *'."\n".'@eval ipo::command $who, $msg, $npc'."\n";
83 $_ = undef;
84 $dirty++;
85 } elsif ($_->{slaying} eq '/python/IPO/banksay.py') {
86 $arch->{msg} = '@match *'."\n".'@eval bank::command $who, $msg, $npc'."\n";
87 $_ = undef;
88 $dirty++;
89 }
90
91 # old deliantra+ to new plug-in system
92 if ($_ && $_->{title} eq "perl") {
93 if ($_->{slaying} eq "board") {
94 push @{$arch->{attach}}, ["board"];
95 $_ = undef;
96 $dirty++;
97 } 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 $dirty++;
105 } elsif ($_->{slaying} eq "nimbus") {
106 push @{$arch->{attach}}, ["nimbus_exit", { restore => $_->{name} eq "restore"}];
107 $_ = undef;
108 $dirty++;
109 } elsif ($_->{slaying} eq "minesweeper") {
110 push @{$arch->{attach}}, ["minesweeper", { split /(?:\s+|=)/, $_->{name} }];
111 $_ = undef;
112 $dirty++;
113 } 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 $dirty++;
122 } else {
123 warn "WARNING: unsupported perl event<$_->{slaying}>\n";#d#
124 }
125 }
126 }
127 }
128
129 $arch->{inventory} = [grep $_, @$inv];
130 }
131
132 for $path (@ARGV) {
133 eval {
134 open my $fh, "<:raw:perlio:utf8", $path
135 or die "$path: $!\n";
136
137 <$fh> =~ /^arch \S+$/
138 or die "$path: not a deliantra map file\n";
139
140 my $map = new_from_file Deliantra::Map $path
141 or die "$path: file load error\n";
142
143 $dirty = 0;
144
145 for my $a (map @$_, grep $_, map @$_, grep $_, @{ $map->{map} }) {
146 patch_arch $a;
147 patch_inv $a if $a->{inventory};
148
149 next unless $a->{msg} =~ /^\@match /;
150
151 my $old = $a->{msg};
152
153 $a->{msg} =~ s/^(\@match\s+)(.*)$/$1 . fix_msg $2/gme;
154
155 $dirty ||= $old ne $a->{msg};
156 }
157
158 $map->write_file ($path)
159 if $dirty;
160
161 1
162 } or $@ =~ /not a deliantra map/ or warn $@;
163 }
164