#!/usr/bin/perl -w

# (c) Copyright by Tels 1999-2000. All Rights Reserved.
# 2000-03-28 v0.0.1 - from scratch

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::VWorld::Room;    # virtual world based on cells
use Cowgen::VWorld::RoomGen; # virtual world based on cells
use Cowgen::VWorld::House;   # virtual houses
use Cowgen::VWorld::Church;  # churches and towers
use Cowgen::Objsize;         # for size of objects
use Cowgen::Architecture::Basics;
use Cowgen::Thief;

print "Shows how to use atticRoom\n\n";

# create a vbr object from template mission
$vbr = Cowgen::Vbr->create("houses.mis");
$txt = Cowgen::Texture->create($vbr->getTXT()); 
$gf = Cowgen::Gamfile->create( $vbr->gamesysName() );

# get commandline parameter
$outfile = shift || "vattic.mis"; 
print "Need .mis as outfile!\n" if ($outfile !~ /\.mis$/);
$outfile = "data/$outfile" if ($outfile !~ /^data\//);

# first define some basic templates

$room = { texture => $txt->texture("odstone"), wallthick => 0.5,
          ceilingtexture => { t=> sky(), s=> 24, },
          floortexture => $txt->texture("cobl2"), 
          rooftexture => $txt->texture("roof"), skytexture => sky(),
          gridsize => 0.25, gen => \&Cowgen::VWorld::RoomGen::basicRoom,
          ceilingthick => 0, floorthick => 0,
        };

$sroom = copyHash($room);
$sroom->{sidetexture} = $sroom{texture};
$sroom->{texture} = sky();
$sroom->{ceilingthick} = 0;

$skyroom = { 
  texture => sky(), wallthick => 0, 
  gen => \&basicRoom, nowall => NOWALL()+NOEDGE() };


# a normal two wedged attic
$normalatticroom = {
  texture => $txt->texture("odstone"), wallthick => 1,
  innertexture => $txt->texture("wdplnk2"),
  rooftexture => $txt->texture("roof"),
  skytexture => sky(),
  innerwallthick => 0,
  ceilingtexture => $txt->texture("wdplnk2"),
  floortexture => $txt->texture("wdplnk2"), 
  gridsize => 0.25, gen => \&Cowgen::VWorld::RoomGen::atticRoom,
  ceilingthick => 2, floorthick => 1,
  outside => true(),
  basics => [
    { type => prisma(), x => -0.5, y => -0.5, z => -0.5, w => -1, l => -1, h => -1},
  ]
  };

# blockthick and blocktexture are ignored for fake things,
# so we can set them here
# door/window type (lit/open/unlit etc) is defined later on
$mydoor = { floortexture => $txt->texture("rooftile"), 
        texture => $txt->texture("wdplanko"), 
        innertexture => $txt->texture("wdplanko"), framethick => 0.25,
        blocktexture => $txt->texture("wood"), blockthick => 0.5,
        height => 8.5, width => 4.5, name => "doorframe##num##",
        };

# a door that can be placed at an east or west wall (not relying on openDoor() 
# to set some defaults). We could make mydoor the same, and use only this, but
# this is an example, so I make some things longer to show you what you can do

# in X we place it at wall, with at least one offset of 1 feet (sx)

$myfdoor = { floortexture => $txt->texture("rooftile"), 
        texture => $txt->texture("wdplanko"), 
        innertexture => $txt->texture("wdplanko"), framethick => 0.25,
        blocktexture => $txt->texture("wood"), height => 8, width => 4, 
        ax => atWall(), ay => atCell(), az => atThing(), sx => 1, 
        };

# actually, flooding an open window will prevent you from seeing the sky texture
# this seems to be a dromed bug, flood always uses default texture and does not
# honour the face textures !?

# place the window not at center, but a bit higher

$mywindow = { texture => $txt->texture("stucco"), framethick => 0.25,
              blocktexture => $txt->texture("win325s"), 
              blockthick => 0.5, height => 4.5, width => 4.5, 
              z => 0.15,
              sidetexture => { t => sky(), s => 24 },
            };

$mystart = { name => "startingPoint", 
            gen => \&Cowgen::Thief::startingPoint,
            width => 0, height => 0, length => 0, gamfile => $gf,
            };

# start a world description.

$house1  = cell ( name => "house1", size => 16, div => inZ(), max => 24,
  cells => [ 
   emptyCell( 1 ), 
   cell ( size => 1, name => 'attic', room => $normalatticroom, ),
   cell ( size => 1, name => 'sky##num##', room => $skyroom, ),
   ] );
$street1 = cell ( name => "street", size => 16, min => 16, max => 16, nowall => NOWALL+NOEDGE,
 clobberwall => aEast(), div => inZ(),
 cells => [
  cell ( size => 1, name => 'street_lower',  ),
  cell ( size => 2, name => 'sky##num##', room => $sroom, ),
  ] );

$p = { 
  texture => $txt->texture("odstone"), wallthick => 1,
  innertexture => $txt->texture("wdplnk2"),
  rooftexture => $txt->texture("roof"),
  skytexture => sky(),
  ceilingtexture => $txt->texture("wdplnk2"),
  floortexture => $txt->texture("wdplnk2"), 
  gridsize => 0.25, 
  ceilingthick => 1, floorthick => 1, 
  towertype => 'crossspiked', };

$church  = Cowgen::VWorld::Church::crossChurch ( $p );

$street1->{things} = [ 
  objThing( 0.4, 0,-0.2,aWest(),$mystart),
  ];

# now define the 2 parts, left with house, street1, church, right only street

$left = cell ( { div => inX(), size => 48, 
  cells => [ $house1, $street1, $church
   ] } );

$right = cell ( { size => 14, nowall => NOWALL, } );

$world = cell ( { name => "city##num##", div => inY(), room => $room,
  cells => [ $left, $right ] } );

$world->{debug} = 1;

$world->{gamfile} = $gf;
$bunch = worldAsBunch (0, 64, 0, 80, 96, 48, $world);
$bunch->debug();

# optimize and generate rooms and flows, then write out
#$bunch->optimize();
$bunch->autoRoom(0,3); $bunch->autoFlow(); optimizeSky($bunch);
$vbr->missionEAX ( eax => eax_stoneRoom() );
$vbr->renderParams ( ambient => 20 ); # always use this!
$vbr->missionDescription ( number => 20, path => "vattic", ); # for save/load to work
$vbr->scriptModules ( "convict" );
$vbr->skyMode ( O_SKY_STARS ); # or O_SKY_TEXTURE
$vbr->saveMission($gf,$bunch,$outfile);
print "Done, enjoy $outfile!\n";

# EOF
1;

