#!/usr/bin/perl -w

# (c) Copyright by Tels 1999. All Rights Reserved.
# 1999-10-23 v0.0.2 - rewritten completely
# 1999-11-12 v0.0.3 - moved report to checknfix

use Cowgen::Bunch;  # for a bunch of brushes
use Cowgen::Dromed; # for some Thief constants and specifics
use Cowgen::Texture;
use Cowgen::Vbr;

my $ver = "v0.0.3";

print "GenMap $ver List contents of mission/VBR file\n\n";
print "Usage: perl genmap [file.mis|file.vbr]\n\n";

$file = shift || "dummy.vbr";
$file .= ".mis" if ($file !~ /\.(mis|vbr|gam)$/);

# get difference for object/brush checking
$e = shift || 0.05;

$vbr = Cowgen::Vbr->create($file,1); # read container

print "Using file ",$vbr->template(),"\n";
$file =~ s/\.(mis|vbr|gam)$//g;

print "Dumping inventory of $file to $file.inv\n";
%inv = $vbr->getINV();

open (FILE, ">data/$file.inv") or die ("Cant write to data/$file.inv: $!");
print FILE "Inventory listing from $file\n\n";
foreach (sort keys %inv)
  {
  @f = split (",",$inv{$_});
  $n = $_; $n .= " " while (length($n) < 18);
  $f[0] .= " " while (length($f[0]) < 10);
  print FILE "$n ofs: $f[0]\tlen: $f[1]\n";
  }
close(FILE);

$time = time;

if (!$vbr->isDefined("OBJMAP"))
  {
  print "Cant dump object map of $file, there is no one present!\n";
  }
else
  {
  print "Dumping object map of $file to $file.lst\n";
  %obj = $vbr->getOBJ();

  open (FILE, ">data/$file.lst") or die ("Cant write to data/$file.lst: $!");
  print FILE "# Object mapping from $file\n\n";
  foreach (sort keys %obj)
    {
    @f = split (",",$obj{$_});
    $n = $_; $n .= " " while (length($n) < 24);
    $f[0] .= " " while (length($f[0]) < 10);
    print FILE "$n id: $f[0] val: $f[1]\n";
    }
  close(FILE);
  }

if (!$vbr->isDefined("TXLIST"))
  {
  print "Cant dump texture list of $file, there is no one present!\n";
  }
else
  {
  print "Dumping texture list of $file to $file.map\n";
  $txt = Cowgen::Texture->create($vbr->getTXT()); 
  open (FILE, ">data/$file.map") or die ("Cant write to data/$file.map: $!");
  print FILE "# Texture mapping from $file, generated at $time by genMap $ver\n";
  print FILE "# genVBR and genMap are (c) Copyright by Tels 1999. All Rights Reserved.\n\n";
  print FILE $txt->asText();
  close (FILE); 
  }

print "Done.\n";

# EOF

