#!/usr/bin/perl -w

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

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;   # balcony, rooms etc
use Cowgen::Architecture::Building; # stairs
use Cowgen::Thief;

print "Advanced Thief Training\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 || "vtut.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 => $txt->texture('wdplanks'),
          bandheight => 3, bandtexture => $txt->texture("stone2s2"),
          bandthick => 0.25, 
          floortexture => $txt->texture("granwall"), 
          gridsize => 0.25, gen => \&basicRoom,
        };

$sroom = { texture => $txt->texture("odstone"), wallthick => 0.5,
          ceilingtexture => { t => $txt->texture("out2"), s => 15, u => 80 },
          floortexture => $txt->texture("granwall"), 
          gridsize => 0.25, gen => \&basicRoom,
        };

$eroom = { texture => $txt->texture("odstone"), wallthick => 0.5,
          ceilingtexture => { t => $txt->texture("clnbrik1"), r => 90, },
          gridsize => 0.25, gen => \&basicRoom,
        };

$jroom = { texture => $txt->texture('rufgry'), wallthick => 0.5,
          ceilingtexture => $txt->texture("wdplnk2"),
          floortexture => $txt->texture("ftile5"), 
          gridsize => 0.25, gen => \&basicRoom,
          floorthick => 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"), name => 'doorframe##num##',
        innertexture => $txt->texture("wdplanko"), framethick => 0.25,
        height => 8.5, width => 4.5, ax => atCell(), ay => atCell(),
        };

$mydooro = { base => $gf->obj('Door13'), gamfile => $gf, name => 'doorobject##num##',
       gen => \&makeObject, adjust => \&Cowgen::Thief::makeRotDoor, 
       relativeto => 'doorframe', rz => 90, dx => 0, dy => 0, dz => 0, 
       prop => { rotating => "0,270,1,2,O_CLOSED,0,1,60,25,1", }
       };

# a door that can be placed at an east or west wall (not relying on openDoor() 
# to set some defaults). 

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

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

$mystair = { texture => $txt->texture("wdplnkg"), name => "stair##num##",
             height => 10, width => -1, length => -0.75, sz => 6, az => atThing(),
             steps => 10, sheight => 0.5, gen => \&stairs,
            };
$mystair2 = { texture => $txt->texture("wdplnkg"), name => "stair##num##",
             height => 8, width => 6, length => 16, 
             steps => 8, gen => \&stairs, sz => 0.25,
            };

$mylantern = { name => 'ElecWallLight##num##', 
            base => $gf->obj('ElecWallLight'), 
            prop => { light => 160, collisiontype => o_bounce(), }, 
            gen => \&makeObject, rz => 180, gamfile => $gf,
            };

# sz => -1 means wallspacing = -1 foot, so embed it in the wall (ceiling in this case)

$mylamp = { name => 'lamp##num##', base => $gf->obj('HangElecLight'), 
            prop => { light => 180, }, gen => \&makeObject, sz => -1, 
            inherit => true(), gamfile => $gf,
            };

$mylamp3 = { name => 'lamp##num##', base => $gf->obj('HangingLamp'), 
            prop => { light => 120, }, gen => \&makeObject,  
            inherit => true(), gamfile => $gf,
            };

$mylamp2 = { name => 'lamp##num##', base => $gf->obj('HangingSpot'), 
            prop => { light => 120, }, gen => \&makeObject, sz => -0.25, 
            inherit => true(), gamfile => $gf,
            };

$mytable = { name => 'table##num##', base => $gf->obj('Table'), 
            prop => { }, gen => \&makeObject, gamfile => $gf, 
            adjust => \&Cowgen::Thief::makePhysical,
            sy => 0.25, sx => 0.25,
            inherit => true(), az => atThing(), ax => atThing(), ay => atThing(),
            };

$mychair = { name => 'chair1##num##', base => $gf->obj('Wooden Chair'), 
            prop => { }, gen => \&makeObject, gamfile => $gf,
            inherit => true(), az => atThing(), ax => atThing(), ay => atThing(), 
            relativeto => 'table', rz => 15,
            adjust => \&Cowgen::Thief::makePhysical,
            };

$mygem = { name => "gem##num##", base => $gf->obj('GemStone'), 
            prop => { loot => "200,0,0,0", },
            gen => \&makeObject, adjust => \&Cowgen::Thief::makeLoot, gamfile => $gf,
            inherit => false(), az => atThing(), ax => atThing(), ay => atThing(),
            sx => 1, relativeto => 'table', dx => 0, dy => 0, dz => 1,
            };

$mybalcony = { name => "balcony##num##", 
            gen => \&balcony, 
            texture => $txt->texture("rufgry"), 
            innertexture => $txt->texture("rufgry"), framethick => 1.5,
            width => -0.75, height => 4, length => 6, 
            };

$mycolumn = { name => "column##num##", 
            gen => \&brush,  brtype => cube(), brkind => solid(),
            texture => $txt->texture("rufgry"), 
            width => 4, height => -1, length => 2, 
            };

$mybar = { name => "bar##num##", 
            gen => \&brush,  brtype => cube(), brkind => solid(),
            texture => $txt->texture('ironwood'), 
            width => 3, height => 3, length => -1.1, 
            };

$mycarpet = { name => "carpet##num##", 
            gen => \&brush,  brtype => cube(), brkind => solid(),
            texture => $txt->texture("r03"), 
            width => -0.5, height => 0.5, length => -0.25, sz => -0.25,
            };

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

$myrope = { name => "ropeArrow##num##", base => $gf->obj("RopeArrow"),
            gen => \&makeObject,
            prop => { 
              "Projectile->Faces Velocity" => true(),  
              "Projectile->Initial Velocity" => '60,0,0',
              stackcount => '2',
            }, 
            relativeto => "table", dx => 0, dy => 0, dz => 1,
            rz => 105, 
            width => 0, height => 0, length => 0, gamfile => $gf,
            };

# start tutorial splitting

$end = cell ( name => "end", size => 2, room => $eroom, div => inZ(),
   cells => [
     cell ( name => "endlower", size => 1, div => inY(),
      cells => [ 
       emptyCell( 1 ), 
       cell (size => 1, name => "endroom",  
        things => [
         objThing(-0.5,0,-0.5,aWest(),$mytable),
         thing(0.5,0,-0.5,aSouth(),$mydoor),
         objThing(0,0,0,aSouth(),$mydooro),
         objThing(0,0,0,aWest(),$mygem), 
         objThing(0,0,+0.5,aWest(),$mylamp3), 
        ] ),  
       emptyCell( 1 ),
       ] ),
     emptyCell (1),
    ] );
$arch = cell ( { name => "archroom##num##", size => 0.5, room => $room, 
   div => inZ(), cells => [
     cell ( size => 24, name => "arch##num##", nowall => aSouth()+aNorth(), 
     things => [
       thing ( 0,-0.5,0,aSouth(),$mycolumn),
       thing ( 0, 0.5,0,aSouth(),$mycolumn),
     ] ),
     emptyCell( 8 ),
   ] } );

$archery = cell ( { name => "archery", size => 3, room => $room, nowall => aSouth(), 
  things => [ 
    objThing(0,0.5,-0.1,aWest(),$mylantern)
  ] } );
$jumper = cell ( name => "room with balcony", size => 6, room => $jroom,
  nowall => aSouth()+aNorth(), 
  things => [
    thing (0,-0.5,0,aEast(),$mybalcony),
    objThing(0,-0.4,0.5,aWest(),$mylamp),
    thing ( -0.3,0,-0.5,aSouth(),$mycarpet),
    thing (  0.3,0,-0.5,aSouth(),$mycarpet),
    thing ( 0,-0.3,0.5,aSouth(),$mybar),
    thing ( 0, 0.3,0.5,aSouth(),$mybar),
  ] );
$begin = cell ( { name => "begin", size => 3, room => $room, nowall => aNorth(), 
  things => [ 
    thing(0.5,-0.5,-0.5,aWest(),$myfdoor),
    thing (+0.5,-0.5,-0.5,aWest(),$mystair2),
  ] } );
$hallway = cell ( name => "hallway_part", size => 1, div => inZ(),
  cells => [ cell ( name => "hallway_lower", size => 1, div => inY(),
    cells => [
      emptyCell(3),
      cell ( name => "hallway", size => 2, nowall => aSouth()+aNorth(), 
        clobberwall => aSouth()+aNorth(), ),
      emptyCell(1),
    ], ),
    emptyCell(1), 
  ] );
$start = cell ( name => "start", size => 2, room => $sroom, 
  things => [ 
    objThing(0,0.5,-0.2,aWest(),$mylantern),
    objThing(0,0.5,-0.5,aSouth(),$mytable),
    objThing(0,-0.3,-0.4,aEast(),$mystart),
    objThing(0,0,0,aEast(),$myrope),
  ] );

$balcony = cell ( name => "balcony", size => 12, nowall => aEast(), clobberwall => aEast(), 
   things => [ 
    openDoor(aSouth(),$mydoor),
 ] );

$left = cell ( name => "left", size => 2, div => inX(), room => $room,
   cells => [
    emptyCell ( 7 ),
    cell ( name => "balcony_part", size => 2, div => inZ(),
       cells => [
        emptyCell(12),
        $balcony,
        emptyCell(2),
       ] ),
    cell ( name => "stair_part", size => 5, div => inZ(),
      cells => [
      cell ( name => "stairs", size => 26, things => [
        objThing(0,0,0.5,aWest(),$mylamp2),
        thing (-0.5,0,-0.5,aNorth(),$mystair),
       ] ),
      emptyCell(2),
    ] ),
    emptyCell ( 3 ),
  ] );

$right = cell ( name => "right", size => 8, div => inX(), room => $room,
  cells => [ $end, $archery, $arch, $jumper, $arch, $begin, $hallway, $start ],
  );

$world = cell ( name => "Tutorial", size => 1, div => inY(), room => $room,
  cells => [ $left, $right ],
  );

$world->{gamfile} = $gf;
$world->{debug} = 1;

$bunch = worldAsBunch (0, 64, 0, 10*4, 19*4, 28, $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 => "vtut", ); # for save/load to work
$vbr->scriptModules ( "convict" );
$vbr->saveMission($gf,$bunch,$outfile);
print "Done, enjoy $outfile!\n";

# EOF
1;

