//-----------------------------------------------------------------------------
//
//  $Logfile:: /game/glowstick.cpp                                            $
// $Revision:: 2                                                              $
//   $Author:: Burgermac                                                      $
//     $Date:: 12/27/00 7:20 PM                                               $
//
// Copyright (C) 1998 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// DESCRIPTION:
// Glowstick for a lightsource

#include "inventoryitem.h"

class GlowStick : public InventoryItem
{
public:
	CLASS_PROTOTYPE( GlowStick );
	GlowStick();
	void        Use( Event* ev );
};

CLASS_DECLARATION( InventoryItem, GlowStick, "powerups_glowstick" )

ResponseDef GlowStick::Responses[] =
{
	{ &EV_InventoryItem_Use, ( Response )& GlowStick::Use },
	{ NULL, NULL }
};

GlowStick::GlowStick()
{
#ifdef SIN_DEMO
	PostEvent( EV_Remove, 0 );
	return;
#endif
	setModel( "glowstick.def" );
	Set( 1 );
}

void GlowStick::Use( Event* ev )
{
	Entity*   glowstick;
	Vector dir;

	assert( owner );

	// Make sure there is a glowstick to
	assert( amount );

	amount--;

	if( amount <= 0 )
	{
		owner->RemoveItem( this );
	}

	dir = owner->orientation[ 0 ];

	glowstick = new Entity;

	glowstick->angles = dir.toAngles();
	glowstick->setAngles( glowstick->angles );
	glowstick->setMoveType( MOVETYPE_BOUNCE );
	glowstick->setSolidType( SOLID_NOT );
	glowstick->setModel( "glowstick.def" );
	glowstick->edict->s.renderfx |= RF_DLIGHT;
	glowstick->avelocity.setXYZ( 500, 0, 0 );
	glowstick->velocity = dir * 500;
	glowstick->edict->s.color_r = 0.4;
	glowstick->edict->s.color_g = 1.0;
	glowstick->edict->s.color_b = 0.1;
	glowstick->edict->s.radius  = 200;
	glowstick->setOrigin( owner->worldorigin + Vector( 0, 0, owner->viewheight ) );
	glowstick->PostEvent( EV_Remove, 60 );
}

