changeset 77:ece6f3a45ee1 misc

Improvements, cleanups, better error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 15 Apr 2010 22:14:21 +0000
parents 0ca7343edec0
children f00429745a00
files magestats.pl
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/magestats.pl	Fri Apr 09 20:50:10 2010 +0000
+++ b/magestats.pl	Thu Apr 15 22:14:21 2010 +0000
@@ -46,7 +46,7 @@
 ### Print out help if no arguments given
 ###
 my $opt_mode = shift or die(
-"Magestats v0.4 - BatMUD Mage guild statistics generator
+"Magestats v0.5 - BatMUD Mage guild statistics generator
 Developed by Matti Hamalainen (Ggr \@ bat), <ccr\@tnsp.org>
 (C) Copyright 2010 Tecnic Software productions (TNSP)
 
@@ -104,7 +104,8 @@
   $spells->{$type}{"essence"}{"increase"} = 0;
   $spells->{$type}{"essence"}{"blasts"}{"single"} = [];
   $spells->{$type}{"essence"}{"blasts"}{"area"} = [];
-
+ 
+  $spells->{$type}{"blasts"} = 0;
   $spells->{$type}{"reagents"} = 0;
 
   $spells->{$type}{"single"} = $src->[0];
@@ -128,6 +129,19 @@
   return $spells->{$spell}{"type"};
 }
 
+### Trap warnings to inform the user that the cache might be stale
+my $has_warned = 0;
+$SIG{__WARN__} = sub {
+  warn("* ", @_);
+  if (!$has_warned) {
+    if (defined($opt_cachefile)) {
+      mlog(-1, "!! The given cache file '$opt_cachefile' is probably stale / incompatible !!");
+    } else {
+      mlog(-1, "!! There seems to be a bug. Report to Ggr !!");
+    }
+  }
+  $has_warned = 1;
+};
 
 ###
 ### Read cache
@@ -154,7 +168,7 @@
 my $crit_type;
 my $last_spell = "";
 
-#print STDERR "$match\n";
+mlog(2, "Matching regexp '$match'\n");
 
 if ($opt_noinput) {
   mlog(1, "Skipping input parsing.");
@@ -167,6 +181,7 @@
 
       $spells->{$last_spell}{"blasts"}++;
       $spells->{"total"}{"blasts"}++;
+      $spells->{$type}{"blasts"}++;
 
       # If essence was gained, get the type etc ..
       if ($essence_flag) {
@@ -187,7 +202,8 @@
         $spells->{$type}{"crits"}{$crit_type}++;
       }
     } elsif ($s =~ /^Your knowledge in elemental powers helps you to save the reagent for further use\./) {
-      $spells->{get_spell_type($last_spell)}{"reagents"}++;
+      my $type = get_spell_type($last_spell);
+      $spells->{$type}{"reagents"}++;
       $spells->{"total"}{"reagents"}++;
     } elsif ($s =~ /^You feel your skills in handling elemental forces improve\./) {
       $essence_flag = 1;
@@ -247,6 +263,8 @@
 
 my $major_blasts = 0;
 foreach my $type (sort { $a cmp $b } keys %spell_data) {
+  if ($spells->{$type}{"blasts"} > 0) {
+
   my $s_s = $spells->{$type}{"single"};
   my $s_a = $spells->{$type}{"area"};
 
@@ -279,6 +297,7 @@
   print OUT "
   </td>
   </tr>\n";
+  }
 }
 
 print OUT "</table>