#!/usr/bin/perl -w

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

# 2000-03-21 added changeTexture test
# 2000-04-30 virtual brushes
# 2000-05-27 virtual brushes rotated/textured

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

print "Demo script: Shows you possible brushes as well as the alignments.\n";
print "             Shows you also how to use brushes that are not supported as\n";
print "             native brushes in DromEd, but work in CoW.\n\n";
print "Usage: perl brushes.pl outfile.vbr outputversion (0 = thief, 2 = thief2)\n\n";

# get commandline parameter
$outfile = shift || "brushes.vbr";
$version = shift || 0;

$v[0] = "Thief/Thief Gold"; $v[2] = "Thief II";

print "Using $version ($v[$version]) for output\n\n";
$template = "thief.vbr"; $template = "thief2.vbr" if ($version == 2);
$gamfile = "thief.gam"; $gamfile = "thief2.gam" if ($version == 2);

$vbr = Cowgen::Vbr->create($template);
$gf = Cowgen::Gamfile->create($gamfile);

# create an empty bag
my $bunch = Cowgen::Bunch->create("All brush types");
$bunch->debug(); # be talkative

# add some brushes
$bunch->addBrush(air(),cube(),0,-20,12,82,96,48,3);
$bunch->addBrush(solid(),cube(),-42,-42,-8,4,4,8,1);
$bunch->addBrush(water(),cube(),-36,-42,-8,4,4,8,1);

$bunch->addBrush(solid(),wedge(),-42,-36,-8,4,4,8,1);
$bunch->addBrush(water(),wedge(),-36,-36,-8,4,4,8,1);

$bunch->addBrush(solid(),prisma(),-42,-28,-8,4,4,8,1);
$bunch->addBrush(water(),prisma(),-36,-28,-8,4,4,8,1);

$bunch->setFaces(3);
$bunch->addBrush(solid(),cylinder(),-42,-20,-8,8,8,8,1);
$bunch->setFaces(4);
$bunch->addBrush(solid(),cylinder(),-32,-20,-8,8,8,8,1);
$bunch->setFaces(5);
$bunch->addBrush(solid(),cylinder(),-22,-20,-8,8,8,8,1);
$bunch->setFaces(6);
$bunch->addBrush(solid(),cylinder()+sixsided(),-12,-20,-8,8,8,8,1);
$bunch->addBrush(solid(),cylinder()+sevensided(),-2,-20,-8,8,8,8,1);
$bunch->addBrush(solid(),cylinder()+eightsided(),12,-20,-8,8,8,8,1);
$bunch->addBrush(solid(),cylinder()+ninesided(),24,-20,-8,8,8,8,1);
$bunch->addBrush(solid(),cylinder()+tensided(),34,-20,-8,8,8,8,1);

$bunch->setFaces(3);
$bunch->addBrush(solid(),pyramid(),-42,-10,-8,8,8,8,1);
$bunch->setFaces(4);
$bunch->addBrush(solid(),pyramid(),-32,-10,-8,8,8,8,1);
$bunch->setFaces(5);
$bunch->addBrush(solid(),pyramid(),-22,-10,-8,8,8,8,1);
$bunch->setFaces(6);
$bunch->addBrush(solid(),pyramid()+sixsided(),-12,-10,-8,8,8,8,1);
$bunch->addBrush(solid(),pyramid()+sevensided(),-2,-10,-8,8,8,8,1);
$bunch->addBrush(solid(),pyramid()+eightsided(),12,-10,-8,8,8,8,1);
$bunch->addBrush(solid(),pyramid()+ninesided(),24,-10,-8,8,8,8,1);
$bunch->addBrush(solid(),pyramid()+tensided(),34,-10,-8,8,8,8,1);

$bunch->setFaces(3);
$bunch->addBrush(solid(),apexpyramid(),-42,0,-8,8,8,8,1);
$bunch->setFaces(4);
$bunch->addBrush(solid(),apexpyramid(),-32,0,-8,8,8,8,1);
$bunch->setFaces(5);
$bunch->addBrush(solid(),apexpyramid(),-22,0,-8,8,8,8,1);
$bunch->setFaces(6);
$bunch->addBrush(solid(),apexpyramid()+sixsided(),-12,0,-8,8,8,8,1);
$bunch->addBrush(solid(),apexpyramid()+sevensided(),-2,0,-8,8,8,8,1);
$bunch->addBrush(solid(),apexpyramid()+eightsided(),12,0,-8,8,8,8,1);
$bunch->addBrush(solid(),apexpyramid()+ninesided(),24,0,-8,8,8,8,1);
$bunch->addBrush(solid(),apexpyramid()+tensided(),34,0,-8,8,8,8,1);

$bunch->addBrush(solid(),dodecahedron(),-30,-24,12,12,12,12,1);

$bunch->setFaces(6);
$bunch->setDefAlign(align_by_sides());
$bunch->addBrush(solid(),apexpyramid(),20,-48,-8,8,8,8,1);
$bunch->setDefAlign(align_by_vertices());
$bunch->addBrush(solid(),apexpyramid(),20,-38,-8,8,8,8,1);

$bunch->addBrush(solid()+align_by_sides(),cylinder(),10,-48,-8,8,8,8,2);
$bunch->addBrush(solid()+align_by_vertices(),cylinder(),10,-38,-8,8,8,8,1);

$bunch->setFaces(4);
# show virtual brush pyramid with a center different from the standard centered 
# position, -0.25 means 1/4 of the length from width, 3 means 3 foot from left
# center will be contrained to be inside the pyramid base face. 
# (4 apexs)
$p = { type => solid(), kind => vpyramid(), sides => 4, centerx => -0.25, centery => 0.25,
       texture => 4, texturelist => [ 5,6,7,8,9,10 ], flags => ALIGN_BY_SIDES,  };
$bunch->brush( -42,10,-8,8,8,8, $p );
# same, but center at center, but centerwidth set (will result in prisma)
# -1 = 100% width, 3 would mean 3 foot absolute
$p = { type => solid(), kind => vpyramid(), centerx => 0, centery => 0,
       centerw => -1, texture => 4, texturelist => [ 5,6,7,8,9,10 ], flags => ALIGN_BY_SIDES };
$bunch->brush( -32,10,-8,8,8,8, $p );
# cut off pyramid (4 apex 1 cube, 4 wedges)
$p = { type => solid(), kind => vpyramid(), centerx => 0, centery => 0,
       centerw => -0.5, centerl => -0.5, texture => 4, 
       texturelist => [ 5,6,7,8,9,10 ], flags => ALIGN_BY_SIDES };
$bunch->brush( -22,10,-8,8,8,8, $p );
# cut off pyramid, same as before but offcenter
# showing relative (-0.5) and absolute (3) measurement of platou
$p = { type => solid(), kind => vpyramid(), centerx => 0, centery => -0.25,
       centerw => -0.5, centerl => 3, texture => 4, flags => ALIGN_BY_SIDES,
       texturelist => [ 5,6,7,8,9,10], };
$bunch->brush( -12,10,-8,8,8,8, $p );
# only one spike, but at a corner (will result in apex)
$p = { type => solid(), kind => vpyramid(), centerx => -0.5, centery => -0.5,
       texture => 4, flags => ALIGN_BY_SIDES,    
       texturelist => [ 5,6,7,8,9,10], };
$bunch->brush( -2,10,-8,8,8,8, $p );
# only one spike, but at a side face (two apex)
$p = { type => solid(), kind => vpyramid(), centerx => -0.5, centery => 0,
       texture => 4, flags => ALIGN_BY_SIDES,
       texturelist => [ 5,6,7,8,9,10], };
$bunch->brush( 12,10,-8,8,8,8, $p );
# show rotation
$p = { type => solid(), kind => vpyramid(), sides => 4, centerx => -0.25, centery => 0.25,
       texture => 4, flags => ALIGN_BY_SIDES, rz => 45, 
       texturelist => [ 5,6,7,8,9,10], };
$bunch->brush( 24,10,-8,8,8,8, $p );

$copy = $bunch->clone();

$c = $bunch->changeTexture (  2 => 17 );
print "changed $c faces (should be 1).\n";
$c = $copy->changeTexture ( 17 => 6 ); # see wether change to 17 spread into $copy (it shouldnt)
print "changed $c faces (should be 0).\n";

$bunch->autoRoom();
$vbr->saveMission($gf,$bunch,$outfile);

print $bunch->asText();
print "Done.\n";

# EOF

