# !/usr/bin/perl -w

# 09/30/99 (c) Copyright by Tels 1999-2000. All Rights Reserved.
# 1999-11-04 added DromEd objetc, flavours
# 1999-12-20 objects, startingpoint, route
# 2000-01-09 finally got it to work
# 2000-01-24 more stuff for testing
# 2000-02-04 object sizes
# 2000-03-05 test for more properties

use Cowgen::Bunch;     # for a bunch of brushes
use Cowgen::Dromed;    # for some Thief constants and specifics
use Cowgen::Gamfile;   # to read Dark.gam and to contain our objects
use Cowgen::Texture;
use Cowgen::Architecture::Basics;
use Cowgen::Vbr;
use Cowgen::Route;
use Cowgen::Thief;     # for startingPoint and torch()
use Cowgen::Objsize;
use Cowgen::ObjList;

# get commandline parameter
$infile = shift || "houses.mis"; 
$outfile = shift || "objects.mis"; 

$vbr = Cowgen::Vbr->create($infile); # make object from template mission
print "'$infile' is a ",filetype2Name($vbr->fileType())," file of ",
      version2Name($vbr->version())," and uses '",$vbr->gamesysName(),"'.\n";

$gf = Cowgen::Gamfile->create($vbr->gamesysName()); # make object from gamesys file 
$txt = Cowgen::Texture->create( $vbr->getTXT() ); # make texture list

print "I know ",$gf->numProperties()," property types. ";
#$gf->decodeProperties( $ol, $vbr );

my $bunch = Cowgen::Bunch->create("Some room with objects");
$bunch->setDefTexture(1);

# show patrol routes
$ru = Cowgen::Route->create( 0,0,0, 10,0,0, 20,20,0, 20,0,0);
$bunch->merge ( $ru->asBunch() );

my $brush = $bunch->addBrush(air()+MROOM,cube(),0,0,0,48,32,24,$txt->texture("bricks"),0,0,90);
$bunch->setTexture($brush,top(),sky());
$bunch->setTexture($brush,bottom(),$txt->texture("cob"));
$bunch->debug();

my $fl = "PlayerFactory";
$fl = 'ParticleAttachement';
print "'$fl' is flavour ",$gf->flavour($fl),"\n";
print "Object 'Marker' is ",$gf->obj("Marker"),". ";
print "Archetype '-36' is '",$gf->archetypeName(-36),"'. ";
print "Object 'Garrett' is ",$gf->obj("Garrett"),".\n";
@l = objSize($gf->obj("Door12"));
print "Object 'Door12' is ",$gf->obj("Door12"),". ";
print "Size of 'Door12' is w=$l[0] l=$l[1] h=$l[2]\n";


my $bu = Cowgen::Bunch->create("Some objects");

$o = { base => $gf->obj("marker"), name => "testmarker", };
my $from = $bu->addObject( 3,2,1, 0,0,0, $o );
$o = { base => $gf->obj("marker"), name => "testmarker1", };
my $to = $bu->addObject( 10,0,0, 0,0,0, $o );

$bu->setProperty ($to, "Shape->Scale", 1, 2, 3 );
$bu->setProperty ($to, "Renderer->AnimLight", 
  # what     bright    maxbright  radius      rising?  activated?
  #               dim      minbright ofsetxyz   count
  O_SLIDE, 500, 800, 200, 0,    0,  0,0,0,  0, 0,    0  );

# test:
$bu->setProperty ($to, "EngineFeatures->StackCount", 17 );
$bu->setProperty ($to, "Renderer->LightColor", 0.5, 0.25 );
$bu->setProperty ($from, "Renderer->Light", 200, 2,3,4, 50 );

$o = { base => $gf->obj("marker"), name => "testmarker##num##", };
my $test = $bu->addObject( 1,2,3, 0,0,0, $o );
my $test = $bu->addObject( 1,2,4, 0,0,0, $o );
my $test = $bu->addObject( 1,2,5, 0,0,0, $o );
my $test = $bu->addObject( 1,2,6, 0,0,0, $o );
#$bu->setProperty ($test, "Renderer->RenderType", O_NOT_RENDERED );
#$bu->setProperty ($test, "Renderer->SelfLit", 50 );
#$bu->setProperty ($test, "Renderer->Transparency", 0.5 );
#$bu->setProperty ($test, "Renderer->ExtraLight", 0.5, 1 ); 
#$bu->setProperty ($test, "Renderer->SelfIllumination", 8 ); 
#$bu->setProperty ($test, "Physics->Misc->CollisionType", o_bounce()+o_no_result() ); 
#$bu->setProperty ($test, "Physics->Projectile->FacesVelocity", TRUE, ); 
#$bu->setProperty ($test, "Physics->Projectile->ExplodeMe", 3 ); 
#$bu->setProperty ($test, "Physics->Misc->MovingTerrain", TRUE, TRUE ); 
#$bu->setProperty ($test, "Shape->Modelname", "waypt" ); 
#$bu->setProperty ($test, "Inventory->ObjectName", "Test Name" ); 
#$bu->setProperty ($test, "Inventory->CantDropThis", TRUE ); 
#$bu->setProperty ($test, "Inventory->LongDescription", "A long description" ); 
#$bu->setProperty ($test, "Inventory->MaxPickDistance", 1.5 ); 
#$bu->setProperty ($test, "Inventory->PickBias", 0.5 ); 
#$bu->setProperty ($test, "Inventory->ToolReach", 0.5 ); 
#$bu->setProperty ($test, "Inventory->Store", TRUE ); 
#$bu->setProperty ($test, "Inventory->Type", O_JUNK ); 
#$bu->setProperty ($test, "Inventory->PurchasePrice", 25 ); 
#$bu->setProperty ($test, "Game->Bashfactor", 2.5 ); 
#$bu->setProperty ($test, "Game->BashParams", 0.5, 1.5 ); 

#$bu->setProperty ($test, "Game->DamageModel->Culpable", TRUE ); 
#$bu->setProperty ($test, "Game->DamageModel->HitPoints", 23 ); 
#$bu->setProperty ($test, "Game->DamageModel->MaxHitPoints", 34 ); 
#$bu->setProperty ($test, "Game->DamageModel->DeathStage", 3 ); 
#$bu->setProperty ($test, "Game->DamageModel->SlayResult", O_TERMINATE ); 
#$bu->setProperty ($test, "Game->DamageModel->WeaponType", 1 ); 
#$bu->setProperty ($test, "Game->DamageModel->WeaponDamage", 2 ); 
#$bu->setProperty ($test, "Game->Dark->BloodCause", TRUE ); 
#$bu->setProperty ($test, "Game->Dark->BloodMaxDamage", 2 ); 

#$bu->setProperty ($test, "Object System->Immobile", TRUE ); 
#$bu->setProperty ($test, "ObjectSystem->Transient", ON ); 
#$bu->setProperty ($test, "Weapon->weaponbasedamage", 1 ); 
#$bu->setProperty ($test, "Weapon->Exposure", 1); 
#$bu->setProperty ($test, "Weapon->SwingExposure", 1 ); 

#$bu->setProperty ($test, "AI->Utiliy->Path Avoid", O_REPEL+O_BLOCK_PATHFIND );
#$bu->setProperty ($test, "AI->State->Current Mode", O_NORMAL_MODE );
#$bu->setProperty ($test, "AI->Attributes->Aggression", O_BELOW_AVERAGE );
#$bu->setProperty ($test, "AI->Attributes->Aptitude", O_BELOW_AVERAGE );
#$bu->setProperty ($test, "AI->Attributes->Defensive", O_BELOW_AVERAGE );
#$bu->setProperty ($test, "AI->Attributes->Dodginess", O_BELOW_AVERAGE );
#$bu->setProperty ($test, "AI->Attributes->Hearing", O_BELOW_AVERAGE );
#$bu->setProperty ($test, "AI->Attributes->Verbosity", O_AVERAGE );
#$bu->setProperty ($test, "AI->Attributes->Vision", O_ABOVE_AVERAGE );

# does not work since dromed needs classpointer !?
#$bu->setProperty ($test, "Creature->CreatureType", O_BURRICK ); 

#$bu->setProperty ($from, "Prox->Blood", TRUE );
#$bu->setProperty ($from, "Prox->Fungus", TRUE );
#$bu->setProperty ($from, "Dark Gamesys->Loot", 100, 50, 10, 0 );

$bu->setProperty ($from, "Tweq->ModelState", O_ON+O_REVERSE, 0, 1, 2 );
$bu->setProperty ($from, "Tweq->LockState", O_ON+O_REVERSE, 0, 2.4, 2 );
$bu->setProperty ($from, "Tweq->RotateState", O_ON+O_REVERSE, 0, O_REVERSE, O_GO_EDGE, O_LAP_ONE );
$bu->setProperty ($from, "Tweq->FlickerState", O_ON+O_REVERSE, 0, 1, 2 );
$bu->setProperty ($from, "Tweq->EmitterState", O_ON+O_REVERSE, 0, 1, 2 );
$bu->setProperty ($from, "Tweq->DeleteState", O_ON+O_REVERSE, 0, 1, 2 );

#$bu->setProperty ($from, "EngineFeatures->FrobInfo", O_WORLD, O_SCRIPT, O_DESELECT );

#$bu->setProperty ($from, "Tweq->Models", O_REMOVE_PROP, O_NO_LIMIT+O_SIM, 
# O_ANCHOR+O_SCRIPTS, O_JITER_LOW+O_JITTER_HIGH, 4, "Model1", "Model2",);

#$bu->setProperty ($from, "Physics->Misc->Attributes", 10, 20, 30, 40, 50, 4.5, 5.5, 6.5, 0x1, 0x2);
#$bu->setProperty ($from, "Physics->Misc->AICollidesWith", TRUE );

#$bu->setProperty ($from, "MetaProperty", $gf->obj("FrobInert"), -1706 ); 

# next oe will crash dromed !?
#$bu->setProperty ($test, "Creature->CurrentPose", O_MOTION, "testmotion", 0.2, 1.2, TRUE ); 

# crashes dromed !?
#$bu->setProperty ($test, "AI->Core->Soundtype", O_COMBAT_HIGH, "testname" ); 

#$bu->setProperty ($test, "Motions->SwordActionType", O_GENERAL_BLOCK ); 
#$bu->setProperty ($test, "Inventory->InvRenderType", O_ALTERNATE_MODEL, "test12" ); 

#$bu->setProperty ($test, "Difficulty->Script", O_QUEST_VAR_1 ); 
#$bu->setProperty ($test, "Difficulty->TurnOnOFf", O_QUEST_VAR_2 ); 
#$bu->setProperty ($test, "Difficulty->CloseOpenDoor", O_QUEST_VAR_3 ); 
#$bu->setProperty ($test, "Difficulty->Destroy", O_QUEST_VAR_4 ); 

#$bu->setProperty ($test, "Difficulty->LockUnlock", O_QUEST_VAR_5 ); 

$bu->setProperty ($test, "Sfx->HeatDisks", 1,2,3,4,5,6,7,8,9,10,11,12,13 ); 

$bu->setProperty ($test, "AI_AbilitySettngs->NonHostile", O_ALWAYS ); 

$bu->setProperty ($test, "Sfx->Particle Launch Info", 
  O_BOUNDING_BOX,1,2,3,4,5,6,7,8,TRUE,10,11,12,13,14,15,TRUE,17,18 ); 

$bu->setProperty ($test, "AI->Responses->AlertResponse", 
  O_LOW, O_PRIORITY_HIGH, 
  O_BECOME_HOSTILE, '123', '1234', '12345', 
  O_DEST_SCRIPT_MESSAGE, '23', '234', '2345'
  ); 
$bu->setProperty ($test, "AI->Responses->BodyResponse", 
  O_PRIORITY_HIGH,
  O_BECOME_HOSTILE, '123', '1234', '12345', 
  O_DEST_SCRIPT_MESSAGE, '23', '234', '2345'
  ); 
$bu->setProperty ($test, "AI->Responses->SignalResponse", 
  'Signal',O_PRIORITY_HIGH,
  O_BECOME_HOSTILE, '123', '1234', '12345', 
  O_DEST_SCRIPT_MESSAGE, '23', '234', '2345'
  ); 
$bu->setProperty ($test, "AI->Responses->ThreatResponse", 
  O_DAMAGE, O_PRIORITY_HIGH,
  O_BECOME_HOSTILE, '123', '1234', '12345', 
  O_DEST_SCRIPT_MESSAGE, '23', '234', '2345'
  ); 
$bu->setProperty ($test, "AI->Responses->SenseCOmbatResponse", 
  O_BECOME_HOSTILE, '123', '1234', '12345', 
  O_DEST_SCRIPT_MESSAGE, '23', '234', '2345'
  ); 
$bu->setProperty ($test, "AI->Core->EfficiencySettings", 
  TRUE, 1,2,3,4,5,6,7,8,
  ); 
$bu->setProperty ($test, "AI->Core->VisionDescription", 
  3, 
  O_PERIPHERAL+O_OMNI, 10,11,12,13,
  O_PERIPHERAL+O_BEHIND, 14,15,16,17,
  O_OMNI, 18,19,20,21,
  O_NO_ALERT_0+O_OMNI, 22,23,24,25,
  O_NO_ALERT_1+O_OMNI, 26,27,28,29,
  O_NO_ALERT_2+O_OMNI, 30,31,32,33,
  O_NO_ALERT_3+O_OMNI, 34,35,36,37,
  O_NIGHT_VISION+O_OMNI, 38,39,40,41,
  O_PERIPHERAL+O_OMNI, 42,43,44,45,
  O_PERIPHERAL+O_OMNI, 46,47,48,49,
  ); 

$bu->setProperty ($test, "AI->Utility->WatchPoint", 
  O_PLAYER_INTRUSION, 1, 2, O_LOW, O_LINE_OF_SIGHT, O_MODERATE, O_HIGH,
  O_AFTER_TRIGGER, TRUE, FALSE, 23, 24,
  O_BECOME_HOSTILE, '123', '1234', '12345', 
  O_DEST_SCRIPT_MESSAGE, '23', '234', '2345',
  O_DEST_SCRIPT_MESSAGE, '1223', '12234', '122345',
  ); 

$bu->setProperty ($test, "Tweq->TweqEmitter", 
  O_SLAY_OBJ, O_SIM, O_TWEQ_RANDOM+O_GRAV, O_JITTER_HIGH, 6,7, "testem", 1,2,3); 

$bu->setProperty ($test, "Tweq->TweqLock", 
  O_SLAY_OBJ, O_SIM, O_TWEQ_RANDOM+O_GRAV, O_JITTER_HIGH, 7, 1,2,3); 

$bu->setProperty ($test, "Tweq->TweqFlicker", 
  O_SLAY_OBJ, O_SIM, O_TWEQ_RANDOM+O_GRAV, O_JITTER_HIGH, 7, ); 
$bu->setProperty ($test, "Tweq->TweqDelete", 
  O_SLAY_OBJ, O_SIM, O_TWEQ_RANDOM+O_GRAV, O_JITTER_HIGH, 7, ); 

# show test for valid property name
print "Property PurchasePrice is ";
if ($gf->isProperty("purchasePrice")) { print "known\n"; } else { print "unknown\n"; }

# test:
#$bu->addLink ($from, $to, $gf->flavour("Contains"), l_belt());

# particle attachment dont work as expected. dromed does never write them 
#out to a mis/vbr file (saved a torch and it wasnt there.) huh?
#$bu->addLink ($from, $to, $gf->flavour("ParticleAttachement"), 1,3,0,0);
$bunch->merge ( $bu );

$o = { base => $gf->obj("lantern"), name => "testlantern", };
my $from = $bunch->addObject( 4,2,6, 0,0,0, $o );
Cowgen::Thief::makeLight($bunch,$from, { bright => 150, hue => 0.2, saturation => 0.3 } );

#$o = { gf => $gf, name => "testtorch", light => 100, minlight => 80};
#$bunch->merge ( Cowgen::Thief::torch( 4,8,6,0,0,0, $o) );

# objects are currently not working properly due to missing properties
$inv = { Blackjack => 1, BroadHead => 3, };
$p = { facing => aNorth(), inventory => $inv, gamfile => $gf};
$bunch->merge ( Cowgen::Thief::startingPoint (8,0,0, 0,0,0, $p) );

$bunch->autoRoom();
$bunch->stuff2vbr($vbr,$gf);

#$b = Cowgen::Bunch->create("test");
#$o = { base => $gf->obj("door_ham_suns"), name => "testdoor", };
#
#my $test = $b->addObject( 1,2,3, objSize($o->{base}), $o );
#$b->debug();
#Cowgen::Thief::makeDoor ($b,$test,$gf);
#$b->stuff2vbr($vbr,$gf);

$vbr->missionEAX ( eax => eax_stoneRoom() );
# miss11 is just here for testing this stuff! doubles will be removed automatically
$vbr->scriptModules ( "convict", "miss11", "convict" ); 
#$vbr->gamesysName("test"); # just for testing if it works
$vbr->writeFile("data/$outfile");

#$txt = $bunch->asText();
#open FILE, ">t.txt" or die "Cant write t.txt: $!\n";
#print FILE $txt;
#close FILE;

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

# EOF
1;

