changeset 136:9a0e08516041 misc

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 20 Dec 2010 17:07:07 +0000
parents 88cf0ca0f137
children 723216311cd1
files materials/mkalloyinfo.sh materials/parsealloys.pl materials/parsematerial.pl
diffstat 3 files changed, 36 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/materials/mkalloyinfo.sh	Mon Dec 20 16:27:11 2010 +0000
+++ b/materials/mkalloyinfo.sh	Mon Dec 20 17:07:07 2010 +0000
@@ -10,7 +10,7 @@
 cat ggr_alloys.txt data-*.log > tmp
 cat $HOME/tf/logs/*.log | grep -B1 "^You mix .* and create a quantity of " >> tmp
 perl -w parsealloys.pl -php < tmp > "$ALLOYPHP"
-perl -w parsealloys.pl < tmp > "$ALLOYTXT"
+perl -w parsealloys.pl -text < tmp > "$ALLOYTXT"
 
 echo "Uploading ..."
 scp -C "$ALLOYTXT" ccr@tnsp.org:public_html/bat/ &&
--- a/materials/parsealloys.pl	Mon Dec 20 16:27:11 2010 +0000
+++ b/materials/parsealloys.pl	Mon Dec 20 17:07:07 2010 +0000
@@ -1,5 +1,9 @@
 #!/usr/bin/perl -w
-# Superklunssi by Ggr
+#
+# BatMUD alloy data parser and converter
+# Developed by Matti Hämäläinen (Ggr Pupunen) <ccr@tnsp.org>
+# (C) Copyright 2009-2010 Tecnic Software productions (TNSP)
+#
 # Old format of alloying skill output was somewhat different, but
 # it has been tuned somewhere after 2005. New output format is:
 #
@@ -7,16 +11,18 @@
 #You mix nullium and illumium and create a quantity of dukonium
 #You mix nullium and illumium and create a quantity of dukonium
 use strict;
+use materials;
 
-my ($opt_php);
+my $domark = 0;
+my $mode = shift or die("Usage: $0 <-php|-text>\n");
 
-if ($#ARGV >= 0) {
-  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",);
-
+if ($mode eq "-php") {
+  $domark = 1;
+}
+elsif ($mode eq "-text") {
+} else {
+  die("$0: Invalid operation mode '$mode'.\n");
+}
 
 ## Parse data from input, ignoring fumbled alloys
 my %data = ();
@@ -63,7 +69,7 @@
       # Some alloy combinations are inherently "unstable".
       my %seen = ();
       foreach my $mat (@tmp) { $seen{$mat}++; }
-      if ($opt_php) {
+      if ($domark) {
         my $n = -1;
         my $mult = 0;
         my $res = "";
@@ -71,7 +77,7 @@
           $res = $mat;
           $mult++;
         }
-        if ($mult > 1) { $res = "unstable"; }
+        if ($mult > 1) { $res .= " (uns)"; }
         $final{$min1}{$min2} = $res;
         $final{$min2}{$min1} = $res;
       } else {
@@ -82,17 +88,18 @@
           $final{$min2}{$min1} = \%seen;
         }
       }
+      # domark
     }
   }
 }
 
 
 ## Output the results
-if ($opt_php) {
+if ($mode eq "-php") {
   print "<?\n".
   "\$alloyTable = array(\n";
   
-  foreach my $min1 (@alloyNameTable) {
+  foreach my $min1 (sort { $a cmp $b } keys %$Materials::matTable) {
     print "  \"$min1\" => array(";
     foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
       print "\"$min2\" => \"".$final{$min1}{$min2}."\", ";
@@ -104,7 +111,7 @@
   
   # Create 'reverse' alloy table
   my %restab = ();
-  foreach my $res (@alloyNameTable) {
+  foreach my $res (keys %$Materials::matTable) {
     foreach my $min1 (keys %final) {
       foreach my $min2 (keys %{$final{$min1}}) {
         if ($final{$min1}{$min2} eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1})) {
@@ -131,10 +138,13 @@
   
   print ");\n\n".
   "?>";
-} else {
-  my $num = 0;
+} elsif ($mode eq "-text") {
+  my $total = 0;
+  my %tdata = ();
+
   foreach my $min1 (sort { $a cmp $b } keys %final) {
     foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) {
+      
       printf "%-35s = ", $min1." + ".$min2;
       my $n = 0;
       foreach my $res (sort { $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} } keys %{$final{$min1}{$min2}}) {
@@ -143,8 +153,14 @@
       }
       if ($n > 1) { print " (unstable)"; }
       print "\n";
-      $num++;
+      $total++;
+#      $subtotal++;
     }
   }
-  print "\n$num alloys total.\n";
+
+
+#    print "$type alloys\n===================\n";
+#    print "\n$subtotal $type alloys.\n";
+  
+  print "\n$total alloys total.\n";
 }
--- a/materials/parsematerial.pl	Mon Dec 20 16:27:11 2010 +0000
+++ b/materials/parsematerial.pl	Mon Dec 20 17:07:07 2010 +0000
@@ -9,6 +9,7 @@
 # processing by other tools.
 #
 use strict;
+use warnings;
 use Data::Dumper;