#!/usr/bin/perl -w

# This contains some cell templates to generate quickly churches/cathedrals

# usage: see vroom.pl

# ANNOTATIONS: see doc/notes.txt

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

# 2000-04-01 v0.0.1 - from scratch

package Cowgen::VWorld::Church;
require Exporter;
@ISA     = qw(Exporter);
@EXPORT_OK  = qw(
             crossSpikedTowerTop
             simpleTowerTop
             simpleTower
             slimTower
             
             crossChurch
             );

use Cowgen::Bunch;
use Cowgen::VWorld::Room;
use Cowgen::Dromed;
use Cowgen::Architecture::Basics;
use Cowgen::Architecture::Inside;
use strict 'vars';

my $version = 0.01;
my $count = "000";

sub simpleTower
  {
  # create a "simple" tower consisting of two parts, on straight cube
  # and one pyramid top.
  # named parameters: texture, innertexture, rooftexture, wallthick,
  # innerwallthick, skytexture, floortexture, ceilingtexture, faces (of pyramid), 
  my $p = $_[0];
  if (!defined $p)
    {
    $p = {}; print "Warning: Description hash is undefined in simpleTower().\n";
    }
  $p = { @_ } if (ref($p) ne 'HASH');
  my $name = $p->{name} || "simpleTower##num##";
  $name =~ s/##num##/ $count++; /eg;
  my $txt = $p->{texture} || -1;
  my $rtxt = $p->{rooftexture} || $txt;
  my $itxt = $p->{innertexture} || $txt;
  my $stxt = $p->{skytexture} || $txt;
  my $ftxt = $p->{floortexture} || $itxt;
  my $ctxt = $p->{ceilingtexture} || $itxt;
  my $faces = $p->{faces} || -1;
  my $aroom = { 
   gen => \&Cowgen::VWorld::RoomGen::atticRoom, innerwallthick => 0, outside => true(),
   texture => $txt, skytexture => $stxt,
   innertexture => $itxt, rooftexture => $rtxt,
   basics => [
    { type => pyramid(), 
      x => -0.5, y => -0.5, z => -0.5, w => -1, l => -1, h => -1, faces => $faces,
    },
  ]
  };
  my $room = { 
   floorthick => $p->{floorthick} || 0,
   ceilingthick => $p->{ceilingthick} || 0,
   };
  my $tower = cell ( name => $name, size => 2, div => inZ(),
    cells => [
      cell ( name => '$name_basis', size => 1, room => $room, ),
      cell ( name => '$name_top', size => 1, room => $aroom, ),
    ] );
  $tower;
  }

sub crossSpikedTower
  {
  # create a "simple" tower consisting of two parts, on straight cube
  # and one top out of a pyramid and two crossed double wedges.
  my $p = $_[0];
  if (!defined $p)
    {
    $p = {}; print "Warning: Description hash is undefined in crossSpikedTower().\n";
    }
  $p = { @_ } if (ref($p) ne 'HASH');
  my $name = $p->{name} || "simpleTower##num##";
  $name =~ s/##num##/ $count++; /eg;
  my $txt = $p->{texture} || -1;
  my $rtxt = $p->{rooftexture} || $txt;
  my $itxt = $p->{innertexture} || $txt;
  my $stxt = $p->{skytexture} || $txt;
  my $ftxt = $p->{floortexture} || $itxt;
  my $ctxt = $p->{ceilingtexture} || $itxt;
  my $faces = $p->{faces} || -1;
  my $crossspikeattic = {
    texture => $txt, innertexture => $itxt, skytexture => $stxt,
    ceilingtexture => $ctxt, floortexture => $ftxt, 
    gridsize => 0.25, gen => \&Cowgen::VWorld::RoomGen::atticRoom,
    innerwallthick => 0,
    outside => true(),
     basics => [
       { type => prisma(), z => -0.25, x => -0.5, y => -0.5, w => -0.8, l => -0.8, h => -0.5},
       { type => prisma(), z => -0.25, x => -0.5, y => -0.5, rz => 90, w => -0.8, l => -0.8, 
         h => -0.5, },
       { type => pyramid(), x => -0.5, y => -0.5, z => -0.5, w => -0.6, l => -0.6, h => -1, faces => 4,
      }, ] };
  my $crosscubeattic = {
    texture => $txt, innertexture => $itxt, skytexture => $stxt,
    ceilingtexture => $ctxt, floortexture => $ftxt, 
    gridsize => 0.25, gen => \&Cowgen::VWorld::RoomGen::atticRoom,
    innerwallthick => 0,
    outside => true(),
     basics => [
      { type => prisma(), x => -0.5, y => -0.5, z => -0.5, w => -1, l => -1, h => -1, },
      { type => prisma(), x => -0.5, y => -0.5, z => -0.5, rz => 90, w => -1, l => -1, h => -1 },
      { type => cube(), x => -0.5, y => -0.5, z => -0.5, w => -0.8, l => -0.8, h => -1, },
    ] };
  my $tower = cell ( name => $name, size => 2, div => inZ(),
    cells => [
      cell ( name => '$name_basis', size => 1, room => $crosscubeattic, ),
      cell ( name => '$name_top', size => 1, room => $crossspikeattic, ),
    ] );
  $tower;
  }

sub crossChurch
  {
  # create a church with the form of a simple cross
  # named parameters: texture, innertexture, rooftexture, wallthick,
  # innerwallthick, skytexture, faces (for tower top), towertype (simple, 
  # crossspiked), 
  my $p = $_[0];
  if (!defined $p)
    {
    $p = {}; print "Warning: Description hash is undefined in crossChurch().\n";
    }
  $p = { @_ } if (ref($p) ne 'HASH');
  my $name = $p->{name} || "crossChurch##num##";
  $name =~ s/##num##/ $count++; /eg;
  my $room = copyHash($p);
  $room->{ceilingthick} = 0;
  $room->{floorthick} = 0;
  # a normal two wedged attic
  my $churchatticroom = {
    innerwallthick => 0,
    gridsize => 0.25, gen => \&Cowgen::VWorld::RoomGen::atticRoom,
    outside => true(),
    basics => [
      { type => prisma(), x => -0.5, y => -0.5, z => -0.5, w => -1, l => -1, h => -1,},
    ] };
  my $churchshipatticroom = {
    innerwallthick => 0,
    gridsize => 0.25, gen => \&Cowgen::VWorld::RoomGen::atticRoom,
    outside => true(),
    basics => [
      { type => prisma(), x => -0.5, y => -0.5, z => -0.5, w => -1, l => -1, h => -1, rz => 90},
    ] };
  my $skyroom = { 
    texture => sky(), wallthick => 0, 
    gen => \&Cowgen::VWorld::RoomGen::basicRoom, nowall => NOWALL()+NOEDGE() 
    };
 my $tt = $p->{towertype} || 'simple';
 my $tower;
 if ($tt eq 'crossspiked')
   {
   $tower = crossSpikedTower($p);
   }
 else
   {
   $tower = simpleTower($p);
   }
 my $church  = cell ( name => $name, size => 16, div => inY(), room => $room,
   cells => [
    cell ( size => 2, name => 'shipend', div => inZ(),
      cells => [
       cell ( size => 2, name => 'lowershipend', div => inX(),
         cells => [
          cell ( size => 1, name => 'shipnorth', nowall => NOWALL()+NOEDGE() ),
          cell ( size => 20, min => 20, max => 20, name => 'ship', div => inZ(), 
           cells => [
            emptyCell (1),  
            cell ( size => 1, name => 'attic##num##', room => $churchshipatticroom, ),
          ] ), 
          cell ( size => 1, name => 'shipsouth', nowall => NOWALL()+NOEDGE()),
         ] ), 
       cell ( size => 1, name => 'shipendsky', room => $skyroom, ),
      ] ),
    cell ( size => 1, min => 20, max => 20, name => 'towerend', div => inX(), 
      cells => [
       cell ( size => 1, name => 'towernorth', div => inZ(),
        cells => [ 
         emptyCell (1),  
         cell ( size => 1, name => 'attic##num##', room => $churchatticroom, ),
         cell ( size => 1, name => 'sky##num##', room => $skyroom, ),
       ] ), 
       cell ( size => 1, min => 20, max => 20, name => 'tower', div => inZ(),
       cells => [
         emptyCell (1),  
         $tower,
       ] ), 
       cell ( size => 1, name => 'towersouth', div => inZ(),
        cells => [ 
         emptyCell (1),  
         cell ( size => 1, name => 'attic##num##', room => $churchatticroom, ),
         cell ( size => 1, name => 'sky##num##', room => $skyroom, ),
       ] ), 
      ] ),
  ] );
  $church;
  }

1;
