Mercurial > hg > batmud > misc
changeset 18:f9376ab3b366 misc
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 Apr 2009 17:05:32 +0000 |
parents | da0c7dc4952a |
children | 3f5b8222255c |
files | materials/mkmaterialinfo.sh parsealloys.pl |
diffstat | 2 files changed, 63 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/mkmaterialinfo.sh Thu Apr 16 14:27:07 2009 +0000 +++ b/materials/mkmaterialinfo.sh Thu Apr 16 17:05:32 2009 +0000 @@ -4,7 +4,8 @@ LISTLONG="$DESTDIR/materials_long.txt" LISTSHORT="$DESTDIR/materials_short.txt" LISTCSV="$DESTDIR/materials.csv" -LISTPHP="$DESTDIR/material.inc.php" +LISTPHP="$DESTDIR/materials.inc.php" +LISTMAT="$DESTDIR/materials.pm" # Create the long list echo "Generating long list..." @@ -30,3 +31,6 @@ echo "Generating PHP ..." perl -w csv2phpsql.pl -php < "$LISTCSV" > "$LISTPHP" + +echo "Generating Perl data ..." +perl -w csv2phpsql.pl -mat < "$LISTCSV" > "$LISTMAT"
--- a/parsealloys.pl Thu Apr 16 14:27:07 2009 +0000 +++ b/parsealloys.pl Thu Apr 16 17:05:32 2009 +0000 @@ -1,10 +1,12 @@ #!/usr/bin/perl -w # Superklunssi by Ggr -use strict; - +# Old format of alloying skill output was somewhat different, but +# it has been tuned somewhere after 2005. New output format is: +# #You mix obsidian and crystal and create a quantity of glass #You mix nullium and illumium and create a quantity of dukonium #You mix nullium and illumium and create a quantity of dukonium +use strict; my ($opt_php); @@ -12,25 +14,32 @@ if ($ARGV[0] eq "-php") { $opt_php = 1; } } +our %alloyNames = ("adamantium" => 0,"air" => 1,"alabaster" => 2,"alexandrite" => 3,"aluminium" => 4,"amber" => 5,"amethyst" => 6,"anipium" => 7,"aquamarine" => 8,"bamboo" => 9,"bark" => 10,"basalt" => 11,"batium" => 12,"birch" => 13,"bloodstone" => 14,"bone" => 15,"brass" => 16,"brick" => 17,"bronze" => 18,"burlap" => 19,"carnelian" => 20,"cedar" => 21,"cesium" => 22,"chalk" => 23,"charcoal" => 24,"chromium" => 25,"chrysoberyl" => 26,"clay" => 27,"cloth" => 28,"coal" => 29,"cobalt" => 30,"concrete" => 31,"copper" => 32,"coral" => 33,"cork" => 34,"cotton" => 35,"crystal" => 36,"darksteel" => 37,"diamond" => 38,"diggalite" => 39,"dragonscale" => 40,"dukonium" => 41,"duraluminium" => 42,"durandium" => 43,"earth" => 44,"ebony" => 45,"electrum" => 46,"elm" => 47,"emerald" => 48,"emulsion" => 49,"enchanted air" => 50,"feathers" => 51,"fire" => 52,"flesh" => 53,"food" => 54,"fur" => 55,"garnet" => 56,"glass" => 57,"gold" => 58,"granite" => 59,"graphite" => 60,"hematite" => 61,"hemp" => 62,"highsteel" => 63,"ice" => 64,"illumium" => 65,"indium" => 66,"iridium" => 67,"iron" => 68,"ivory" => 69,"jade" => 70,"kryptonite" => 71,"laen" => 72,"lead" => 73,"leather" => 74,"magnesium" => 75,"mahogany" => 76,"malachite" => 77,"mallorn" => 78,"maple" => 79,"marble" => 80,"marlor" => 81,"mithril" => 82,"molybdenum" => 83,"moonstone" => 84,"moss agate" => 85,"mowgles" => 86,"mowglite" => 87,"neo burlap" => 88,"nickel" => 89,"nullium" => 90,"oak" => 91,"obsidian" => 92,"olivine" => 93,"onyx" => 94,"opal" => 95,"osmium" => 96,"palladium" => 97,"paper" => 98,"pearl" => 99,"petrified wood" => 100,"pewter" => 101,"phosphorus" => 102,"platinum" => 103,"porcelain" => 104,"potassium" => 105,"pyrite" => 106,"quartz" => 107,"quicksilver" => 108,"rhodium" => 109,"rhodonite" => 110,"rubber" => 111,"ruby" => 112,"sapphire" => 113,"silicon" => 114,"silk" => 115,"silver" => 116,"slate" => 117,"starmetal" => 118,"steel" => 119,"steuben" => 120,"stone" => 121,"sulphur" => 122,"sunstone" => 123,"tadmium" => 124,"tin" => 125,"titanium" => 126,"topaz" => 127,"tormium" => 128,"tungsten" => 129,"turquoise" => 130,"uranium" => 131,"vanadium" => 132,"vegetation" => 133,"water" => 134,"wax" => 135,"weenite" => 136,"wood" => 137,"wool" => 138,"zhentorium" => 139,"zinc" => 140,"zircon" => 141,); +our @alloyNameTable = ("adamantium","air","alabaster","alexandrite","aluminium","amber","amethyst","anipium","aquamarine","bamboo","bark","basalt","batium","birch","bloodstone","bone","brass","brick","bronze","burlap","carnelian","cedar","cesium","chalk","charcoal","chromium","chrysoberyl","clay","cloth","coal","cobalt","concrete","copper","coral","cork","cotton","crystal","darksteel","diamond","diggalite","dragonscale","dukonium","duraluminium","durandium","earth","ebony","electrum","elm","emerald","emulsion","enchanted air","feathers","fire","flesh","food","fur","garnet","glass","gold","granite","graphite","hematite","hemp","highsteel","ice","illumium","indium","iridium","iron","ivory","jade","kryptonite","laen","lead","leather","magnesium","mahogany","malachite","mallorn","maple","marble","marlor","mithril","molybdenum","moonstone","moss agate","mowgles","mowglite","neo burlap","nickel","nullium","oak","obsidian","olivine","onyx","opal","osmium","palladium","paper","pearl","petrified wood","pewter","phosphorus","platinum","porcelain","potassium","pyrite","quartz","quicksilver","rhodium","rhodonite","rubber","ruby","sapphire","silicon","silk","silver","slate","starmetal","steel","steuben","stone","sulphur","sunstone","tadmium","tin","titanium","topaz","tormium","tungsten","turquoise","uranium","vanadium","vegetation","water","wax","weenite","wood","wool","zhentorium","zinc","zircon",); + ## Parse data from input, ignoring fumbled alloys my %data = (); my $fumble = 0; +my $nline = 0; +print STDERR "Processing input ..."; while (<STDIN>) { chomp; + $nline++; + if ($nline % 10000 == 1) { print STDERR "."; } if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+)$/) { my $min1 = $1; my $min2 = $2; my $res = $3; if (!$fumble) { push(@{$data{$1}{$2}}, $3); } else { - print STDERR "Ignoring fumbled combo $1 + $2 = $3\n"; + print STDERR "\nIgnoring fumbled combo $1 + $2 = $3\n"; } $fumble = 0; } elsif (/^(You slip up and fumble your attempt.)/) { $fumble = 1; } } - +print STDERR " OK\n\n"; ## Re-format the data into single "ordered" hash, using as ## close to alphabetical order as possible. @@ -51,10 +60,27 @@ # Some alloy combinations are inherently "unstable". my %seen = (); foreach my $mat (@tmp) { $seen{$mat}++; } - if ($min1 lt $min2) { - $final{$min1}{$min2} = \%seen; + if ($opt_php) { + my $n = -1; + my $res = ""; + foreach my $mat (keys %seen) { + if ($seen{$mat} > $n) { + $n = $seen{$mat}; + $res = $mat; + } + } + if ($min1 lt $min2) { + $final{$min1}{$min2} = $res; + } else { + $final{$min2}{$min1} = $res; + } + } else { - $final{$min2}{$min1} = \%seen; + if ($min1 lt $min2) { + $final{$min1}{$min2} = \%seen; + } else { + $final{$min2}{$min1} = \%seen; + } } } } @@ -62,16 +88,31 @@ ## Output the results -print -"| Mineral1 | Mineral 2 | Result(s)\n". -"+-----------------+-----------------+--------------------------------\n"; -foreach my $min1 (sort { $a cmp $b } keys %final) { - foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) { - printf "| %-15s | %-15s | ", $min1, $min2; - foreach my $res (sort { $_{$a} <=> $_{$b} } keys %{$final{$min1}{$min2}}) { - print "$res($final{$min1}{$min2}{$res}) "; +if ($opt_php) { + print "<?\n". + "\$alloyTable = array(\n"; + + foreach my $min1 (@alloyNameTable) { + print " \"$min1\" => array("; + foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) { + print "\"$min2\" => \"".$final{$min1}{$min2}."\", "; } - print "\n"; + print "),\n"; + } + + print ");\n\n". + "?>"; +} else { + print + "| Mineral1 | Mineral 2 | Result(s)\n". + "+-----------------+-----------------+--------------------------------\n"; + foreach my $min1 (sort { $a cmp $b } keys %final) { + foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) { + printf "| %-15s | %-15s | ", $min1, $min2; + foreach my $res (sort { $_{$a} <=> $_{$b} } keys %{$final{$min1}{$min2}}) { + print "$res($final{$min1}{$min2}{$res}) "; + } + print "\n"; + } } } -