#!/usr/bin/perl -w

# (c) Copyright by Tels 1999-2000. All Rights Reserved.
# 2000-03-15 v0.0.1 - from vroom1, show link usage

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::Objsize;        # for size of objects
use Cowgen::Architecture::Basics;
use Cowgen::Thief;

print "Show usage of Links and custom soundroom\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("Dark.gam");

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

# first define some basic templates

# when adding prop to a room description you force Vroom to generate
# a new concrete room object and use that instead of leaving rooms of
# to the autoroom stage. Dont forget to set Gamfile, VRoom will need
# it!

$room = { texture => $txt->texture("odstone"), wallthick => 1,
          ceilingtexture => $txt->texture("wdplnk"),
          floortexture => $txt->texture("slab"), 
          prop => { script => "TrigRoomPlayer", }, gamfile => $gf,
          gridsize => 0.25, gen => \&basicRoom,
        };

# 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, width => 4
        };

$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, 
        };

# 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 },
            };

# Most of the objects need gamefile set for the adjustments done in Thief.pm

$myoutlight = { name => 'OldElecWallLight##num##', 
            base => $gf->obj('OldElecWallLight'), 
            prop => { light => 160, collisiontype => o_bounce(), }, 
            gen => \&makeObject, rz => 180, gamfile => $gf,
            adjust => \&Cowgen::Thief::makePhysical,
            inherit => TRUE,
            };

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

# the ##path## will be replaced with the path to the cell the link is
# actually in, and room will hopefully match our custom room object
# created by the prop of room above.

$mylightlink = { name => 'link##num##', gamfile => $gf,
            from => '##path##room', to => '##path##OldElec', 
            flavour => 'controldevice', inherit => TRUE,
            };

$kitchen = cell ( { name => "kitchen", size => 16, room => $kroom } );
$dining  = cell ( { name => "hall", size => 16 } );
$stairs  = cell ( { name => "stairs", size => 16, room => $room } );

$dinette = cell ( { name => "dinette", size => 18, room => $kroom } );
$hallway = cell ( { name => "hallway", size => 12 } );
$office  = cell ( { name => "office", size => 18, room => $room } );

$living  = cell ( { name => "living", size => 18, room => $kroom } );
$entry   = cell ( { name => "entry", size => 12 } );
$library = cell ( { name => "library", size => 18, room => $room } );

# now add some things to the various rooms

$kitchen->{things} = [ openDoor(aEast(),$mydoor), openWindow(aNorth(),$mywindow), ];
$dinette->{things} = [ openDoor(aEast(),$mydoor), ];
$living->{things} = [ openDoor(aEast(),$mydoor), openWindow(aWest(),$mywindow),  ];

$entry->{things} = [ 
  openDoor(aSouth(),$mydoor), thing ( 0.4, 0.5, -0.5, aEast(), $myfdoor),
  objThing( 0.4, 0,-0.2,aNorth(),$mystart),
  ];

# to show you that it actually does not matter where to add links
$hallway->{things} = [ openDoor(aSouth(),$mydoor), openDoor(aNorth(),$mydoor),
   thing ( -0.4, 0.5, -0.5, aEast(), $myfdoor),  ];
$stairs->{things} = [ openDoor(aWest(),$mydoor) ];

$library->{things} = [ openWindow(aEast(),$mywindow), ];

# define house

$upper = cell ( { div => inY(), size => 12, 
  cells => [ $kitchen, $dining, $stairs
   ] } );

$middle = cell ( { div => inY(), size => 20,
  cells => [ $dinette, $hallway, $office
   ] } );

$lower = cell ( { div => inY(), size => 12,
  cells => [ $living, $entry, $library
   ] } );

# now we divide out "world" in three parts, from left to right

$firstfloor = cell ( { name => "firstfloor##num##", div => inX(), size => 14,
  cells => [ $upper, $middle, $lower
   ] } );

# add the light and link to it to every room
$firstfloor->{things} = [ objThing(0.5,0.1,+0.1,aNorth(),$myoutlight), objLink ( $mylightlink ), ];

# now we add the attic
$attic = cell ( { name => "attic##num##", div => inX(), size => 16, room => $room } );

$house = cell ( { name => "house##num##", div => inZ(), room => $room,
  cells => [ $firstfloor, $attic ] } );

$house->{debug} = 1;

# at 0,64,0 place the house, 48 width (in Y), 64 long (in X), 30 heigh

$house->{gamfile} = $gf;
$bunch = worldAsBunch (0, 64, 0, 64, 48, 30, $house);
$bunch->debug();

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

# EOF
1;

