/*
 * Hamlet
 *
 * Special code
 *
 */

GAME_NAME = 'Hamlet'
GAME_ID = 'HAM'
MAX_SCORE = 31;

INV_CAP = 24; // number of items in inventory. max out to number in game.

HIGHLIGHT_COLOUR = '#880000';
INPUT_COLOUR = '#888888';

// words of more than three letters to ignore
WORDS_TO_IGNORE = 'about.with.around.under.over.go.do';
function anywhere_do()
{
}
PARDON = 'Pardon?'

function initialiseGame()
{
}

INTRO = "<font color=\"" + HIGHLIGHT_COLOUR + "\"><b>Hamlet - The Text Adventure</b>\n\
&copy; 2003-08 Robin Johnson. Some rights reserved.</font>\n\
\n\
It's so unfair! You're in trouble again, \
just because you called your uncle - or rather, your new stepfather, Claudius - \
a usurping git. It's true, though. Your real dad was SO much better than that guy. \
Too bad he was found mysteriously dead in the orchard a couple of weeks back. Anyway, \
your mother (who was, incidentally, looking quite something today in a sparse \
leather number, er...) sent you to your room, and here you are.\n\
\n";

MANNER_FREQ = 5;

rating = new Object;
rating[0] = 'a most lamentable tragedy';
rating[1] = 'a comedy of errors';
rating[10] = 'a new-hatched unfledg\'d comrade';
rating[20] = 'a dull and muddy-mettled rascal';
rating[30] = 'a rogue and peasant slave';
rating[40] = 'a saucy merchant';
rating[50] = 'a virtuous and well-governed youth';
rating[60] = 'a noble kinsman';
rating[70] = 'a fellow of infinite jest';
rating[80] = 'a very flower';
rating[90] = 'the very ecstasy of love';

function score_rating()
{
	var txt = '\nHoratio rates you as ';
	for(var i=sc_percent();i>=0;--i)
		if(rating[i])
		{
			txt += (rating[i]);
			break;
		}
	txt += '.'
	return(txt);
}

START_LOC = bedroom;

// flags which are initially zero needn't be set here
function set_gameflags()
{
}

function game_help()
{
	window.open('hamhelp.html','help',
	  'width=600,height=400,scrollbars=yes,menubar=no,resizable=yes,status=no,toolbar=no');
}

function game_hints()
{
	window.open('hamhint.html','help',
	  'width=600,height=400,scrollbars=yes,menubar=no,resizable=yes,status=no,toolbar=no');
}

function anywhere_append()
{
	var txt = '';
	
	if(gs('horse')==1)
	{
		// this function can also be used to do tweaks like this
		// remember list_persons() has already been called, so you will not
		// have 'a horse is here' already displayed, UNLESS neither the
		// player nor the horse have just moved

		if(personloc(horse)!=heroloc())
		{
			set_personloc(horse,heroloc());
			txt += '\nThere is a horse following you.';
		}
	}
	else if(personloc(horse)==heroloc() && in_inv(carrot))
	{
		txt += '\nThe horse neighs and nuzzles its head against you. \
It seems to have decided to follow you.';
		sgs('horse',1);
		if(!gs('hrspnt')==1)
		{
			inc_score();
			sgs('hrspnt',1);
		}
	}

	if(gs('horse') && personloc(richard)==heroloc())
	{
		inc_score();
		sgs('horse',0);
		set_personloc(horse,nowhere);
		set_personloc(richard,nowhere);
		set_thingloc(crown,bosworth);
		txt += ('\nRichard looks up and sees the horse.\n\
\"Brilliant!\" he says, climbing up onto its back. \"Here, you can be \
King then...\" He takes his crown off and throws it in mour general direction, \
and rides off into the sunset.');
	}

	if(gs('ancfnrl')==1)
	{
		txt += '\nFar away, a town crier yells: \
\"Ophelia\'s funeral will be held at Elsinore Cemetery!\"';
		set_personloc(laertes,graveyard);
		sgs('ancfnrl',0);
	}

	return(txt);
}

var anywhere_sights = '';

function anywhere_sight(sight,description)
{
	anywhere_sights += '/' + sight + '::' + description;
}
anywhere_sight('self','You are a typical angsty teenager, \
clad all in black, with a look of disdain in your eyes, a \
foreboding frown on your lips, and a snotty nose. Of course, \
you think you\'re rather attractive.');

// all 'special command' attempts come this way if they are
// not caught by a specific place. Return true if a command
// is interpreted and obeyed (even if it is to no effect)
function anywhere_special()
{
	// you can create on-the-fly 'dynamic synonyms' this way -
	// it's awkward, but it will work.
	// this way 'polonius' means the dead body, but only if he's dead
	if(gs('klpln')==1 && Token_str.indexOf('polonius')!=-1)
	{
		var tkns = Token_str.split('.');
		for(var i=0;i<tkns.length;++i)
		{
			if(tkns[i]=='polonius')
				tkns[i] = 'body';
		}
		Token_str = tkns.join('.');
		
		for(var i=1;i<=MAX_TOKENS;++i)
			if(Token[i]=='polonius')
				Token[i] = 'body';
		
		// don't return
	}
	
	if(Token[1]=='dig')
	{
		if(in_inv(shovel))
			say('The ground is too hard to dig here.')
		else
			say('You haven\'t got anything to dig with.');
		return(true)
	}
	else if(Token[1]=='cut'&&Token[2]!='nail')
	{
		if(in_inv(scissors) && !Token[2])
			say('I don\'t know what you want to cut.')
		else if(in_inv(scissors))
			say('There\'s nothing worth cutting here.')
		else
			say('You haven\'t got anything to cut with.' +
			(in_inv(dagger) ? '\n(Daggers are for stabbing, not cutting.)' : '') );
		return(true);
	}
	else if(Token_str.indexOf('drop.carrot')==0 && in_inv(carrot) && gs('horse')==1)
	{
		drop(carrot);
		sgs('horse',0);
		say('Okay. You have dropped the carrot.\n\
The horse looks less interested in you now.');
		return(true);
	}
	else if(Token_str.indexOf('take.carrot')==0 && thingloc(carrot)==heroloc() &&
	  personloc(horse)==heroloc())
	{
		take(carrot);
		sgs('horse',1);
		say('Okay. You have taken the carrot.\n\
The horse neighs and nuzzles its head against you.');
		return(true);
	}
	
	else if(Token_str.indexOf('fight.self')==0)
	{
		if(!in_inv(dagger))
			say('You survive punching yourself in the face.')
		else
			die('Okay, if you insist. You stab yourself.', randomDeath());
		return(true);
	}


	// useless things
	else if(Token_str.indexOf('blow.nose')!=-1)
	{
		say('PARRRP!!!');
		return(true);
	}
	else if(Token_str.indexOf('cut.nail')!=-1)
	{
		say('Your fingernails are short enough through nervous biting.');
		return(true);
	}
	else if(Token[1]=='jump')
	{
		say('You can\'t jump very high.');
		return(true);
	}
	else if(Token[1]=='shout')
	{
		say('\"AAAARRRGGGHHH!!!\"')
		return(true);
	}
	else if(Token[1]=='sneeze')
	{
		say('You can\'t sneeze at will.');
		return(true);
	}
	else if(Token[1]=='swear'||Token[2]=='swear')
	{
		say('Please! There might be children reading this site!');
		return(true);
	}
	else if(Token[1]=='sit'||Token[1]=='sleep')
	{
		say('Lazy!');
		return(true);
	}
	else if(Token[1]=='be')
	{
		say('Okay then. You are.');
		return(true);
	}
	else if(Token_str=='not.be')
	{
		die('Okay then.', 'Not to be');
		return(true);
	}
	else if(Token[1]=='not')
	{
		say('Not done.');
		return(true);
	}
	else if(('.' + Token_str + '.').indexOf('.sonnet.')!=-1)
	{
		say("How embarrassing. You've forgotten your lines.");
		return(true);		
	}

	return(false);
}

// big array of deaths
var ShakespeareanDeaths = new Array(
'You have shuffled off this mortal coil',
'You are dead as a door-nail',
'Ask for you tomorrow, and they shall find you a grave man',
'Who now the price of your dear blood doth owe?',
'You are dead for a ducat',
'A certain convocation of politic worms are e\'en at you',
'The sight is dismal',
'No med\'cine in the world can do thee good',
'Thou art slain',
'Now cracks a noble heart',
'Not to be',
'For certain you are dead, and by strange manner',
'And wheresoe\'er thou art, you\'re surely dead',
'You are dead, forsook, cast off'
)

function randomDeath()
{
	return ShakespeareanDeaths[pick(ShakespeareanDeaths.length)];
}

