1#!/usr/local/bin/perl 2# 3# Copyright (C) 2003 by Marc Olzheim 4# 5# alias decay "show sh c >! tmp/.decay.sshc; show sh b >! tmp/.decay.sshb; sdump * type mil civ fir eff x y >! tmp/.decay.sdump; @./decay.pl" 6# 7my %shipavail; 8my %shipdec; 9my %shipciv; 10my %shipmil; 11my $tmp; 12my $amt; 13my $firsttmp; 14 15open(CONF, ".config") or die "Run genconfig first."; 16while (<CONF>) 17{ 18 s/^/\$/; 19 eval; 20} 21close CONF; 22 23chdir "tmp" || die "No tmp/ directory"; 24 25open SPB, "<.decay.sshb" || die "Argh .decay.sshb"; 26while (<SPB>) 27{ 28 if (/^(\S+)\s+(\S+ )+\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\$(\d+)/) { 29 $shipavail{$1} = $5; 30 } 31} 32close SSB; 33 34open SSC, "<.decay.sshc" || die "Argh .decay.sshc"; 35while (<SSC>) 36{ 37 if (/^(\S+)\s+(\S+ )+\s+(\d+\S)\s+(\d+\S)\s+(\d+\S)/) { 38 $tmp = $3; 39 $firsttmp = chop($tmp); 40 if ($firsttmp eq "c") 41 { 42 $shipciv{$1} = $tmp; 43 $tmp = $4; 44 $firsttmp = chop($tmp); 45 } 46 if ($firsttmp eq "m") 47 { 48 $shipmil{$1} = $tmp; 49 } 50 } 51} 52close SSC; 53 54open SPD, "<.decay.sdump" || die "Argh .decay.sdump"; 55while (<SPD>) 56{ 57# id type mil civ fir eff x y 58 if (/^(\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(-?\d+)\s+(-?\d+)$/) 59 { 60 if ($5 > 0) 61 { 62# mil ship 63 $shipdec{$1} = - (($ETU * $3 / 6) 64 - ($ETU * (100 - (($3 * 100) / $shipmil{$2}))) 65 / 7); 66 if (0 < int($shipdec{$1})) 67 { 68 print STDOUT $1 . " " . $2 . " : shipdec = " . $shipdec{$1} / $shipavail{$2} . "% (if not in harbor)\n"; 69 } 70 } 71 else 72 { 73# civ ship 74 $tmp = 0; 75 76 if ($shipciv{$2} > 0) 77 { 78 $tmp = $shipciv{$2}; 79 $amt = $4; 80 } elsif ($shipmil{$2} > 0) 81 { 82 $tmp = $shipmil{$2}; 83 $amt = $3; 84 } 85 86 $shipdec{$1} = 87 (($ETU * (100 - (($amt * 100) / $tmp))) / 7) 88 - (($ETU * (($4 / 2) + ($3 / 5))) / 3); 89 90 if (0 < int($shipdec{$1})) 91 { 92 print STDOUT $1 . " " . $2 . " : shipdec = " . $shipdec{$1} / $shipavail{$2} . "% (if not in harbor)\n"; 93 } 94 } 95 } 96} 97close SPD; 98