annotate materials/parsealloys.pl @ 315:72bf6267e34f misc

Use underlines for multiword material names in plaintext format alloy list.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 30 Dec 2015 06:58:07 +0200
parents 809e2a1c64eb
children a4dff42fc40e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/perl -w
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
2 #
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
3 # BatMUD alloy data parser and converter
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
4 # Developed by Matti Hämäläinen (Ggr Pupunen) <ccr@tnsp.org>
273
2deed72277a5 Bump copyright here as well, missed it from previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents: 271
diff changeset
5 # (C) Copyright 2009-2015 Tecnic Software productions (TNSP)
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
6 #
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
7 # Old format of alloying skill output was somewhat different, but
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
8 # it has been tuned somewhere after 2005. New output format is:
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
9 #
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #You mix obsidian and crystal and create a quantity of glass
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #You mix nullium and illumium and create a quantity of dukonium
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #You mix nullium and illumium and create a quantity of dukonium
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
13 use strict;
269
08e5bfa19978 Add use warnings;
Matti Hamalainen <ccr@tnsp.org>
parents: 256
diff changeset
14 use warnings;
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
15 use materials;
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
17 my $domark = 0;
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
18 my $mode = shift or die("Usage: $0 <-php|-text>\n");
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
20 if ($mode eq "-php")
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
21 {
153
fd57384798a0 Bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
22 $domark = 1;
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
23 }
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
24 elsif ($mode eq "-text")
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
25 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
26 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
27 else
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
28 {
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
29 die("$0: Invalid operation mode '$mode'.\n");
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
30 }
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
32
315
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
33 sub ul($)
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
34 {
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
35 my $tmp = $_[0];
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
36 $tmp =~ s/ /_/g;
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
37 return $tmp;
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
38 }
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
39
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
40
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
41 ###
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
42 ### Parse data from input, ignoring fumbled alloys
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
43 ###
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 my %data = ();
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 my $fumble = 0;
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
46 my $nline = 0;
34
6be1a542ade0 Fixes, add parsing of submission datafiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
47
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
48 sub addCombo($$$)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
49 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
50 if (!$fumble)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
51 {
256
0adaafd9d6e8 Stabler sorting for text output.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
52 push(@{$data{$_[1]}{$_[2]}}, $_[0]);
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
53 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
54 else
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
55 {
306
1a6f435a1e4d Fix fumble reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
56 print STDERR "Ignoring fumbled combo $_[1] + $_[2] = $_[0]\n";
34
6be1a542ade0 Fixes, add parsing of submission datafiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
57 }
6be1a542ade0 Fixes, add parsing of submission datafiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
58 $fumble = 0;
6be1a542ade0 Fixes, add parsing of submission datafiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
59 }
6be1a542ade0 Fixes, add parsing of submission datafiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
60
315
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
61
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 while (<STDIN>) {
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 chomp;
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
64 if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+?)\.?$/)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
65 {
256
0adaafd9d6e8 Stabler sorting for text output.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
66 addCombo($3, $1, $2);
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
67 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
68 elsif (/^([a-zA-Z0-9]+)#([a-z ]+)\+([a-z ]+)=([a-z ]+)$/)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
69 {
256
0adaafd9d6e8 Stabler sorting for text output.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
70 addCombo($4, $2, $3);
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
71 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
72 elsif (/^(You slip up and fumble your attempt)/)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
73 {
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 $fumble = 1;
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
34
6be1a542ade0 Fixes, add parsing of submission datafiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
77
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
79 ###
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
80 ### Re-format the data into single "ordered" hash, using as
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
81 ### close to alphabetical order as possible.
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
82 ###
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 my %final = ();
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
84 foreach my $min1 (keys %data)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
85 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
86 foreach my $min2 (keys %{$data{$min1}})
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
87 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
88 if (!defined($final{$min1}{$min2}) && !defined($final{$min2}{$min1}))
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
89 {
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 # Get both (a, b) and (b, a) combinations results into same array
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 my @tmp = ();
274
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
92 if (defined($data{$min1}{$min2}))
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
93 {
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 push(@tmp, @{$data{$min1}{$min2}});
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 }
274
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
96 if (defined($data{$min2}{$min1}))
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
97 {
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 push(@tmp, @{$data{$min2}{$min1}});
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 # Determine if there are multiple results and which is the most likely.
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 # Some alloy combinations are inherently "unstable".
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 my %seen = ();
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
104 $seen{$_}++ foreach (@tmp);
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
105 if ($domark)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
106 {
153
fd57384798a0 Bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
107 $final{$min1}{$min2} = $final{$min2}{$min1} = \%seen;
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
108 }
274
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
109 elsif ($min1 lt $min2)
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
110 {
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
111 $final{$min1}{$min2} = \%seen;
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
112 }
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
113 else
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
114 {
274
7f4d966da5d9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
115 $final{$min2}{$min1} = \%seen;
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 }
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 ## Output the results
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
123 if ($mode eq "-php")
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
124 {
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
125 print "<?\n".
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
126 "\$alloyTable = array(\n";
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
127
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
128 foreach my $min1 (sort { $a cmp $b } keys %$Materials::matTable)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
129 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
130 print " \"$min1\" => ";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
131 if (scalar(keys %{$final{$min1}}) > 0)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
132 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
133 print "array(";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
134 foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}})
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
135 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
136 print "\"$min2\" => array(";
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
137 foreach my $res (sort { $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} } keys %{$final{$min1}{$min2}}) {
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
138 print "\"$res\" => ".$final{$min1}{$min2}{$res}.", ";
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
139 }
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
140 print "), ";
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
141 }
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
142 print "),\n";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
143 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
144 else
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
145 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
146 print "null,\n";
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
148 }
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
149
19
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
150 print ");\n\n";
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
151
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
152 # Create 'reverse' alloy table
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
153 my %restab = ();
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
154 foreach my $res (keys %$Materials::matTable)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
155 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
156 foreach my $min1 (keys %final)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
157 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
158 foreach my $min2 (keys %{$final{$min1}})
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
159 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
160 my $tmp = $final{$min1}{$min2};
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
161 if (scalar(keys %$tmp) > 1)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
162 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
163 # print STDERR "Ignoring multi $min1 + $min2 = ".join(", ", keys %$tmp)."\n";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
164 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
165 else
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
166 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
167 foreach my $key (keys %$tmp)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
168 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
169 if ($key eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1}))
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
170 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
171 $restab{$res}{$min1}{$min2} = $$tmp{$key};
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
172 }
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
173 }
19
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
174 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
175 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
176 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
177 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
178
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
179 print "\$alloyRevTable = array(\n";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
180 foreach my $res (sort { $a cmp $b } keys %restab)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
181 {
19
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
182 print " \"$res\" => array(\n";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
183 foreach my $min1 (sort { $a cmp $b } keys %{$restab{$res}})
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
184 {
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
185 if (scalar(keys %{$restab{$res}{$min1}}) > 0)
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
186 {
19
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
187 print " \"$min1\" => array(";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
188 foreach my $min2 (sort { $a cmp $b } keys %{$restab{$res}{$min1}})
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
189 {
144
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
190 print "\"$min2\" => ".$restab{$res}{$min1}{$min2}.",";
19
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
191 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
192 print "),\n";
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
193 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
194 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
195 print " ),\n";
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
196 }
3f5b8222255c Add generation of reverse alloy table.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
197
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
198 print ");\n\n".
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
199 "?>";
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
200 }
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
201 elsif ($mode eq "-text")
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
202 {
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
203 my $total = 0;
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
204 my %tdata = ();
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
205
270
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
206 foreach my $type (sort { $a cmp $b } keys %{$Materials::matByType})
f203d193963d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 269
diff changeset
207 {
137
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
208 my $subtotal = 0;
308
809e2a1c64eb Improve ascii text format alloy list output.
Matti Hamalainen <ccr@tnsp.org>
parents: 306
diff changeset
209 print "\n".$$Materials::revTransTable{99}{$type}." alloys\n".
137
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
210 "=========================================================\n";
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
211
271
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
212 foreach my $min1 (@{$$Materials::matByType{$type}})
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
213 {
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
214 foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}})
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
215 {
315
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
216 printf "%-35s = ", ul($min1)." + ".ul($min2);
137
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
217 my $n = 0;
256
0adaafd9d6e8 Stabler sorting for text output.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
218 foreach my $res (sort {
271
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
219 $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b}
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
220 ||
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
221 $a cmp $b
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
222 } keys %{$final{$min1}{$min2}})
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
223 {
315
72bf6267e34f Use underlines for multiword material names in plaintext format alloy list.
Matti Hamalainen <ccr@tnsp.org>
parents: 308
diff changeset
224 print ul($res)."[".$final{$min1}{$min2}{$res}."] ";
137
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
225 $n++;
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
226 }
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
227 if ($n > 1) { print " (unstable)"; }
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
228 print "\n";
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
229 $total++;
723216311cd1 Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
230 $subtotal++;
18
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
231 }
f9376ab3b366 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
232 }
271
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
233 print "\n".$subtotal." ".lc($$Materials::revTransTable{16}{$type})." type alloys.\n\n";
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
136
9a0e08516041 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
235
271
e5c0c407b019 Fix to work with the materials.pl changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 270
diff changeset
236 print "\n".$total." alloys total.\n";
15
79c79d865218 Add a simple Perl-script for parsing alloy combinations from logfiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 }