# !/usr/bin/perl -w

# This is the package Tempel. It contains some interesting structures that
# look best if made from metals and or wood and are common used in temples.

# (c) Copyright by Tels 1999-2000. All Rights Reserved. Do NOT distribute.
# Updates and support on bloodgate.com/thief

# 2000-01-05 v0.0.1 - from scratch (gratedLight/gratedpyramid)

package Cowgen::Architecture::Tempel;
require Exporter;
@ISA    = qw(Exporter);
@EXPORT = qw( 
            gratedPyramid gratedLight
          
            );
#@EXPORT_OK = qw();

use Cowgen::Bunch;
use Cowgen::Dromed;

sub gratedPyramid
  {
  # create a grated pyramid
  # make sure that height is at least 6 times thick
  # named parameters:  texture, facing, thick (bar thickess), sides (nr of sides
  # in outer circle, 6 looks quite good), light (light brightness value or
  # light hash; ommit for
  # disabling)
  my ($x,$y,$z,$w,$l,$h,$p) = @_;
  my $t = $p->{texture} || -1;
  my $thick = $p->{thick} || 0.25;
  my $sides = $p->{sides} || 6;
  my $facing = $p->{facing} || aSouth();
  my $b = Cowgen::Bunch->create("gratedPyramid##num##");
  my $h2 = ($h-$thick*3); my $w2 = ($w-$thick)/2; my $l2 = ($l-$thick)/2;
  my $h4 = ($h-$thick*3)/2; my $w4 = ($w-$thick)/4; my $l4 = ($l-$thick)/4;
  my $t2 = $thick/2; $h3 = $h2-$thick;
  $b->addBrush (solid(),wedge(),$x,$y+$w4+$t2,$z+$h4+$t2,$w2,$thick,$h2,$t,0,0,0);
  $b->addBrush (solid(),wedge(),$x,$y-$w4-$t2,$z+$h4+$t2,$w2,$thick,$h2,$t,0,0,180);
  $b->addBrush (solid(),wedge(),$x+$l4+$t2,$y,$z+$h4+$t2,$l2,$thick,$h2,$t,0,0,270);
  $b->addBrush (solid(),wedge(),$x-$l4-$t2,$y,$z+$h4+$t2,$l2,$thick,$h2,$t,0,0,90);
  my $ty = air()+mnoroom();
  $b->addBrush ($ty,wedge(),$x,$y+$w4,$z+$h4,$w2-$thick,$thick,$h3,$t,0,0,0);
  $b->addBrush ($ty,wedge(),$x,$y-$w4,$z+$h4,$w2-$thick,$thick,$h3,$t,0,0,180);
  $b->addBrush ($ty,wedge(),$x+$l4,$y,$z+$h4,$l2-$thick,$thick,$h3,$t,0,0,270);
  $b->addBrush ($ty,wedge(),$x-$l4,$y,$z+$h4,$l2-$thick,$thick,$h3,$t,0,0,90);
  # top
  $b->setFaces(4); 
  $b->addBrush (solid()+align_by_sides(),pyramid(),
    $x,$y,$z+$h/2-$thick,$thick,$thick,$thick*2,$t,0,0,0);

  $b->rotateByFacing($x,$y,$z,$facing);
  return $b; # light
  }

sub gratedLight
  {
  # create a grated light holder from two gratedPyramid (casts even more
  # interesting shadows...)
  # make sure that height is at least 6 times thick
  # named parameters:  texture, facing, thick (bar thickess), sides (nr of sides
  # in outer circle, 6 looks quite good), light (light brightness value or
  # light hash; ommit for
  # disabling)
  my ($x,$y,$z,$w,$l,$h,$p) = @_;
  my $t = $p->{texture} || -1;
  my $thick = $p->{thick} || 0.25;
  my $sides = $p->{sides} || 6;
  my $facing = $p->{facing} || aSouth();
  my $b = Cowgen::Bunch->create("gratedLight##num##");
  # ring
  $b->setFaces($sides);
  $b->addBrush (solid(),cylinder(),$x,$y,$z,$w,$l+$thick*2,$thick,$t);
  $b->addBrush (air()+mnoroom(),cylinder(),$x,$y,$z,$w-$thick*2,$l,$thick,$t);
  my $e = { texture => $t, thick => $thick, facing => $facing };
  $b->merge ( gratedPyramid ( $x,$y,$z+$h/4, $w,$l, $h/2, $e));
  my $b2 = gratedPyramid ( $x,$y,$z-$h/4, $w,$l, $h/2, $e);
  $b2->rotate(180,0,180,$x,$y,$z-$h/4);
  $b->merge ($b2);
  $b; # grated light
  }

1;

