#!/usr/bin/perl -w

# Texture - to show usage of Texture.pm

# (c) Copyright by Tels 1999. All Rights Reserved.

use Cowgen::Bunch;   # for a bunch of brushes
use Cowgen::Dromed;  # for some Thief constants and specifics
use Cowgen::Texture; # to get texture mappings
use Cowgen::Vbr;     # to load a mission

print "Texture demo script (run again to see random effect):\n\n";

$core = Cowgen::Texture->create(); $core->loadMapping("core.map");

print "Looking for texture wdplnk:\n ";
$t1 = $core->texture("wdplnk");
print "Number: $t1  Name: ", $core->textureName($t1), "  Long name: ";
print $core->textureLName ($t1),"\n";

print "Looking for texture grey brick (will use fuzzy search):\n ";
$t1 = $core->texture("grey brick");
print "Number: $t1  Name: ", $core->textureName($t1), "  Long name: ";
print $core->textureLName ($t1),"\n";

# old method, does not work if textures are loaded from mission
# so its use is depricated
#print "Getting random floortile texture:\n ";
#
#$t1 = $core->randTexture(floortile());
#print "Number: $t1  Name: ", $core->textureName($t1), "  Long name: ";
#print $core->textureLName ($t1),"\n";
#
#print "Getting another random floortile texture:\n ";
#
#$t1 = $core->randTexture(floortile());
#print "Number: $t1  Name: ", $core->textureName($t1), "  Long name: ";
#print $core->textureLName ($t1),"\n";

$vbr = Cowgen::Vbr->create("houses.mis"); # load template
$txt = Cowgen::Texture->create($vbr->getTXT()); # create texture object 

# method one, using hash
$list = $txt->weightedList ( { "roof" => 1, "wdplnk" => 1, "tile" => 1, "stucco" => 2,} );

$r = randTexture($list);
print "Random one: index: ", $r->{t}, " name: ",$txt->textureName($r->{t}), "\n";

# checking weight
for ($i = 0; $i < 10000; $i++)
  {
  $r = randTexture($list);
  $randt->{$r->{t}} ++; 
  }

print "Testing weighting:\n";
foreach (sort keys %$randt)
  {
  $all += $randt->{$_};
  }
foreach (sort keys %$randt)
  {
  print " ",$txt->textureName($_), " ($_) was selected $randt->{$_}\n";
  }

# method two, a scaled one
$list = $txt->weightedList ( { "roof" => 1, "wdplnk" => { s => 14, u => 2, w => 3 }, } );

$r = randTexture($list);
print "Random one: index: ", $r->{t}, " name: ",$txt->textureName($r->{t}), "\n";

print "Done.\n";

# EOF

1;
