view time/gentime.pl @ 285:c30ea380329a misc

Cleanups, HTML5-zation.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2015 05:45:34 +0200
parents dde1b2712132
children
line wrap: on
line source

#!/usr/bin/perl -w
use strict;

my %data = ();
my %data_mis = ();
my %months = ();
my %continents = ();
my $month = "";
my $day;
my $mname;
my $cont;


# Parse input logs
while (<STDIN>) {
  chomp;
  if (/^Today is the (\d+)[^ ]+ day of the (\d+)[^ ]+ month \((\w+)\)/) {
    $day = $1;
    $month = $2;
    $mname = $3;

    if (defined($months{$month}) && $months{$month} ne $mname) {
      die("Inconsistent input: $mname != $months{$month}\n");
    }
    $months{$month} = $mname;
  } elsif (/^It's (winter|summer|spring|autumn) in (\w+)\./) {
    my $season = $1;
    $cont = $2;
    if (defined($data{$month}{$day}{$cont})) {
      my $tmp = $data{$month}{$day}{$cont};
      #die("Inconsistent input: $tmp != $season ($mname ($month) / $day / $cont)\n") unless ($tmp eq $season);
      if ($tmp ne $season) {
        $data_mis{$month}{$day}{$cont} = $tmp;
      }
    }
    if ($month ne "") {
      $data{$month}{$day}{$cont} = $season;
      $continents{$cont}++;
    }
    $month = "";
  }
}

# Set unset days
for ($month = 1; $month <= 10; $month++) {
  for ($day = 1; $day <= 28; $day++) {
    if (!defined($data{$month}{$day}{"Laenor"})) {
      $data{$month}{$day}{"Laenor"}="";
    }
  }
}

# Output
print qq|<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
  <title>Time in BatMUD</title>
  <style type="text/css">
    <!--
    body { background: black; color: white; font-family: Arial, Verdana, sans-serif; font-size: 10pt; }
    th { background: gray; }
    th.mname { color: #ddd; }

    tr.row1 td { background: #444; }
    tr.row2 td { background: #555; }

    table.days { width: 95%; }
    table.conversion { width: 50%; }
    td, th { text-align: center; } 
    td.mc        { color: black; }
    td.mcspring  { color: #0f7; }
    td.mcsummer  { color: #0f0; }
    td.mcautumn  { color: #ff0; }
    td.mcwinter  { color: #77f; }

    h1,h2,h3,h4  { color: #f00; border-bottom: 1px solid #c00; }
    -->
  </style>
</head>
<body>
<h1>Time in BatMUD</h1>
<p>
This document is a short summary of how time works in BatMUD. If you notice
any mistakes or omissions, please report to <b>Ggr</b> via tells or mudmail.
</p>

<h2>General</h2>
<p>
Time in BatMUD is most likely measured in ticks of some kind, probably there
is a global "world heartbeat". This theory is supported by the following
facts: <i>1) gametime does not progress during gamelag</i> and
<i>2) gametime does not progress during reboot</i>.
</p>
<ul>
  <li>BatMUD day is 24 hours long, and one hour in BatMUD lasts 5 minutes real world time.</li>
  <li>Thus the time in BatMUD advances approximately
  (1day * 24h * 60min) / (5min * 24h) = <i>12 BatMUD days per one boot</i>.
  However, this is not entirely accurate (because of the downtime during reboot
  and other non-scheduled downtimes).
  </li>
</ul>

<table class="conversion">
  <tr>
    <th>Real World</th>
    <th>equals</th>
    <th>BatMUD</th>
  </tr>
 
  <tr class="row2">
    <td>5 minutes</td>
    <td>==</td>
    <td>1 hour</td>
  </tr>

  <tr class="row1">
    <td>1 hour</td>
    <td>==</td>
    <td>12 hours</td>
  </tr>

  <tr class="row2">
    <td>2 hours</td>
    <td>==</td>
    <td>1 day</td>
  </tr>

  <tr class="row1">
    <td>1 day</td>
    <td>==</td>
    <td>12 days</td>
  </tr>
</table>

<h2>Year and months</h2>
<ul>
  <li>There are <b>10 months per BatYear</b>: Arienle, Teliminus, Lorien, Ysaril, Karmina, Ingot, Alystos, Gettrellyn, Rozgayn and Blayhrr.
  </li>
  <li>Each month has <b>28 days</b> and lasts approximately (28d * 24h * 5min/h) / (24h * 60min) = <b>2 days, 8 hours</b> of real world time.</li>
  <li>Year is thus <b>280 days</b> aka <b>23 days, 8 hours</b> of real world time.</li>
</ul>

<h2>Seasons</h2>
<p>
Each continent has its own cycle of seasons, and the durations of each season
(winter, spring, summer, autumn) differ between continents. <b>Furnachia,
Laenor and Desolathya</b> have similar seasons, while <b>Rothikgen</b> has
longest winter and <b>Lucentium</b> has longest summer.
</p>
<p>
Additionally, the change of season always happens during <b>reboot</b>, thus
there is some variation (of few days) in when the season actually changes
(marked with red background in table below).
</p>

<h2>Seasons per continent</h2>
<table class="days">
|;

sub printContHeader() {
  print qq|<tr><th class="mday">Day</th><th class="mmonth">Month</th>|;
  foreach $cont (keys %continents) {
    print qq|<th class="mname">$cont</th>|;
  }
  print qq|</tr>\n|;
}

my $n = 0;
my %hdata = ();  
my @sdata = sort { $a <=> $b } keys %data;
foreach $month (@sdata) {
  my @kdata = sort { $a <=> $b } keys %{$data{$month}};
  printContHeader();
  foreach $day (@kdata) {
    my $p = ($n % 2) + 1; $n++;
    printf qq| <tr class="row%d"><td class="mday">%02d</td><td class="mmonth">%s</td>|, $p, $day, $months{$month};
    foreach $cont (keys %continents) {
      my $s = defined($data{$month}{$day}{$cont}) ? $data{$month}{$day}{$cont} : "";
      my $t = ""; my $q = "";
      if (defined($data_mis{$month}{$day}{$cont})) {
        $t = " style=\"background: #800;\"";
        $q = "<br />(".$data_mis{$month}{$day}{$cont}.")";
      }
      print "<td class=\"mc$s\"$t>$s$q</td>";
      $hdata{$cont}{$s}++;
    }
    print "</tr>\n";
  }
}

printContHeader();

print "<tr><td></td><td></td>";

foreach $cont (keys %continents) {
  my @kdata = sort { $a cmp $b } keys %{$hdata{$cont}};
  print "<td>";
  foreach my $key (@kdata) {
    if ($key ne "") {
      print "[".$key.": <b>".$hdata{$cont}{$key}."</b>]<br />";
    }
  }
  print "</td>";
}
print "</tr>\n";


print qq|</table>
</body>
</html>
|;