#!/usr/bin/perl -w

# BoT - ye ole Bag o' Tricks

# (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::Gamfile;

print "Demo script: Shows you the basic usage of Bunch.pm\n\n";
print "It shows you also the scope of Bunches.\n\n";

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

# create an empty bag
my $bunch = Cowgen::Bunch->create("some loony bunch of brushes");
$bunch->debug(); # be talkative

# add a brush to it
# the kind can be either set as string (like "solid") or as number, (whereas
# 0 = solid) or as (prefered method) number you get from calling the appr. 
# function like solid()
# the texture must be a number, names like "jorge" or jorge() will be 
# supported later on

# parameters that  are left out on the right side are replaced by defaults
# you can only leave them out from right to left, you cannot skip something
# in the middle. addBrush() is also possible and generates a solid cube
# at 0,0,0 with 16,16,16 as size, zero rotation and jorge (0) texture

#
#                               x y z width (x)
#                                        length (y)
#                                           height (z)  
#                                              texture
#                                                rotation x
#                                                   rotation y
#                                                     rotation z
#                                                       texture face0
#                                                         texture face1 aso
#$brush = $bunch->addBrush(air(),cube(),
 #                               0,0,0,16,16,16,0,0,0,0,);
#$brush = $bunch->addBrush(solid(),wedge(),
 #                               4,0,-4,4,4,4,);

# set face 2 to texture 4 of brush $brush in our bunch
$bunch->setTexture($brush,2,4);

my $bu = Cowgen::Bunch->create("another bunch"); # create another
$bu->debug();

scope_demo();

print "\n\$bu in main is still: '",$bu->name(),"'\n";

$bu = Cowgen::Bunch->create("one more"); 
print "\$bu is overwritten, 'another bunch' is automatically freed.\n";

print "\n\$bu in main is now: '",$bu->name(),"'\n";

$bu->addBrush (air(),wedge(),0,0,0,20,20,20,1);

$bunch->merge($bu);

$bunch->autoRoom();
my $vbr => Cowgen::Vbr->create(); # create one using dummy.vbr
my $gf = Cowgen::Gamfile->create(); # use dark.gam
$vbr->saveMission($gf,$bunch,$outfile);

# This frees the bunch (haha!) of it, but is normally not needed.
undef $bunch;

print "Done.\n";

# EOF

sub scope_demo
  {
  print "\n Entering sub routine scope_demo\n";
  my $bu = Cowgen::Bunch->create("inside sub");
  print "\n \$bu in scope_demo is: '",$bu->name(),"'\n";
  $bu->debug();
  print " Leaving sub scope_demo, \$bu goes out of scope and bunch 'inside sub'\n";
  print " is automatically destroyed here.\n";
  }
