# !/usr/bin/perl -w

# (c) Copyright by Tels 1999-2000. All Rights Reserved.
# 1999-11-12 v0.0.1 - from scratch
# 2000-01-07 v0.0.2 - adapted to use new VHouse stuff
#                     added new splitCube example

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::House;        # virtual houses
use Cowgen::Architecture::Basics;

print "Shows how to use VWorld::Room.pm and VWorld::House.pm\n\n";

$vbr = Cowgen::Vbr->create("houses.mis");
$txt = Cowgen::Texture->create($vbr->getTXT()); 

# get commandline parameter
$outfile = shift || "vroom.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("rufgry"), wallthick => 0.5,
          ceilingtexture => $txt->texture("wdplnk2"),
          bandheight => 3, bandtexture => $txt->texture("stone2s2"),
          floortexture => $txt->texture("mosaic"), bandthick => 0.25, 
          gridsize => 0.25, 
        };

my $clist = $txt->weightedList( { r02 => 1, r03 => 1, r04 => 1, r05 => 1, r06 => 1,
              r07 => 1, r08 => 1, r11 => 1, } );

my $carpet = { texture => randTexture($clist), sx => 1, sy => 1, };

print "Today using ",$txt->textureName($carpet->{texture}->{t})," as carpet.\n";

# blockthick and blocktexture are ignored for fake things
# door/window type is defined later on
my $mydoor = { floortexture => $txt->texture("tile"), texture => $txt->texture("wdplanko"), 
        innertexture => $txt->texture("wdplanko"), framethick => 0.25,
        blocktexture => $txt->texture("wood"), blockthick => 0.5,
        height => 8, width => 4
        };

# 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 !?

$mywindow = { texture => $txt->texture("stucco"), framethick => 0.5,
              blocktexture => $txt->texture("win325s"), 
              blocklittexture => $txt->texture("win32l"),
              blockthick => 0.5, height => 5, width => 5,
              sidetexture => { t => sky(), s => 24 },
            };

# for outer windows to save some brushes
$mywindow_o = copyHash($mywindow);
$mywindow_o->{onesided} = true();

# start a house floor description.
# create a cell divider from template (using our room, door, window stuff)

# you can now leave of the {}} in the cell call!

$left = cell( 
   name => "leftside", div => inX(), size => 0.4,
   cells =>
   [ cell ( name => "kitchen", div => none(), size => 0.5,
            things => [ openDoor(aEast(), $mydoor), unlitWindow(aNorth(), $mywindow),
            litWindow(aNorth(), $mywindow),
            ] ),
     cell ( name => "sleeps", div => none(), size => 0.5,  
            things => [ unlitWindow(aWest(), $mywindow_o), openDoor(aNorth(), $mydoor), 
                        unlitWindow(aSouth(), $mywindow_o) ], 
           ),
   ] ); 

$sroom = { texture => $txt->texture("clnbrik1"), floortexture => $txt->texture("cob"),
           floorthick => 1, ceilingthick => 4
          }; 

my $sitt  = cell ( name => "sitting", div => none(), size => 0.8, gen => \&basicRoom,
              room => $sroom,
              things => [ unlitWindow(aSouth(), $mywindow_o), openDoor(aWest(), $mydoor),
               omniLight(0,0,0, { light => 64, } ),
              ] );

addCarpet ($sitt,$carpet);

$right = cell( 
   name => "rightside", div => inX(), size => 0.4,
   cells =>
   [ cell ( name => "stairs", div => none(), size => 0.2, min => 6, max => 10, 
              nowall => aBottom()+aTop(),
              things => [ openDoor(aWest(), $mydoor) ], ),
     $sitt,
   ] ); 

$house_1 = cell( 
   { name => "small house", div => inY(), size => 16, min => 16, max => 16,
     room => $room,
   cells =>
   [ $left, 
     cell ( { name => "hallway", div => none(), size => 0.2, min => 6, max => 10, 
              room => hallwayRoom($room,$carpet), 
              things => [ openDoor(aNorth(), $mydoor), fakeDoor ( aSouth(), $mydoor) 
              ] } ),
     $right,
   ]
 } ); 

$house1 = cell( 
    { name => "house", div => inZ(), size => 20, min => 20, max => 24, room => $room,
      cells => [ $house_1, emptyCell() ] } );

# show access to cells by name
$h = cellByName($house1,"hallway");
print "Cell 'hallway' has size ", $h->{size},"\n";

# now make another from some ready-made template
$house2 = smallHouse("myHouse", 2, 1 , $room, $mydoor, $mywindow);
$house2->{size} = 0.6;

# world is two houses plus street, water level at -10 

$below = emptyCell ( 13,13,13 );
$street = cell (  name => "street", div => none(), size => 24, min => 24, max => 28,
                   room => $sroom,  ),

$leftside = cell ( { name => "left", div => inZ(), cells => [ $below, 
             cell ( { div => inX(), size => 1, cells => [ $street, $house1 ] } ), ]
                 } ); 

$world = cell( 
   { name => "world", div => inX(), size => 1, 
     room => { texture => $txt->texture("rufgry"), ceilingtexture => sky()}, flood => "+32",
   cells => [ $house2, $leftside ],
 } ); 

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

$bunch->autoRoom(1); $bunch->autoFlow(); optimizeSky($bunch);
$list = { $txt->texture("win325s") => 1, $txt->texture("win32l") => 1, };
$bunch->alignTextures();
$vbr->missionEAX ( eax => eax_stoneRoom() );
$vbr->renderParams ( ambient => 20 ); # always use this!
$vbr->saveMission($gf,$bunch,$outfile);

print "Done, enjoy $outfile!\n";

# EOF
1;

