// Emacs style mode select   -*- C++ -*- 
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// $Log:$
//
// DESCRIPTION:
//
//-----------------------------------------------------------------------------


// We are referring to sprite numbers.

#include <string.h>

#include "info.h"
#include "dstrings.h"
#include "v_text.h"

#include "d_items.h"


//
// PSPRITE ACTIONS for waepons.
// This struct controls the weapon animations.
//
// Each entry is:
//   ammo/amunition type
//  upstate
//  downstate
// readystate
// atkstate, i.e. attack/fire/hit frame
// flashstate, muzzle flash
//
weaponinfo_t	weaponinfo[NUMWEAPONS] =
{
	{
		// fist
		am_noammo,
		S_PUNCHUP,
		S_PUNCHDOWN,
		S_PUNCH,
		S_PUNCH1,
		S_NULL,
		(mobjtype_t)0
		},	
	{
		// pistol
		am_clip,
		S_PISTOLUP,
		S_PISTOLDOWN,
		S_PISTOL,
		S_PISTOL1,
		S_PISTOLFLASH,
		MT_PISTOL	// [BC]
	},	
	{
		// shotgun
		am_shell,
		S_SGUNUP,
		S_SGUNDOWN,
		S_SGUN,
		S_SGUN1,
		S_SGUNFLASH1,
		MT_SHOTGUN
	},
	{
		// chaingun
		am_clip,
		S_CHAINUP,
		S_CHAINDOWN,
		S_CHAIN,
		S_CHAIN1,
		S_CHAINFLASH1,
		MT_CHAINGUN
	},
	{
		// missile launcher
		am_misl,
		S_MISSILEUP,
		S_MISSILEDOWN,
		S_MISSILE,
		S_MISSILE1,
		S_MISSILEFLASH1,
		MT_ROCKETLAUNCHER
	},
	{
		// plasma rifle
		am_cell,
		S_PLASMAUP,
		S_PLASMADOWN,
		S_PLASMA,
		S_PLASMA1,
		S_PLASMAFLASH1,
		MT_PLASMAGUN
	},
	{
		// bfg 9000
		am_cell,
		S_BFGUP,
		S_BFGDOWN,
		S_BFG,
		S_BFG1,
		S_BFGFLASH1,
		MT_BFG9000
	},
	{
		// chainsaw
		am_noammo,
		S_SAWUP,
		S_SAWDOWN,
		S_SAW,
		S_SAW1,
		S_NULL,
		MT_CHAINSAW
	},
	{
		// super shotgun
		am_shell,
		S_DSGUNUP,
		S_DSGUNDOWN,
		S_DSGUN,
		S_DSGUN1,
		S_DSGUNFLASH1,
		MT_SUPERSHOTGUN
	},
// [BC]
	{
		// grenade launcher
		am_misl,
		S_GLAUNCHERUP,
		S_GLAUNCHERDOWN,
		S_GLAUNCHER,
		S_GLAUNCHER1,
		S_GLAUNCHERFLASH1,
		MT_GRENADELAUNCHER
	},
	{
		// railgun
		am_cell,
		S_RAILGUNUP,
		S_RAILGUNDOWN,
		S_RAILGUN,
		S_RAILGUN1,
		S_RAILGUNFLASH,
		MT_RAILGUN
	},
	{
		// bfg10k
		am_cell,
		S_BFG10KUP,
		S_BFG10KDOWN,
		S_BFG10K,
		S_BFG10K1,
		S_BFG10KFLASH1,
		MT_BFG10000
	},
};

// [BC] Medal info stuff
medalinfo_t	medalinfo[NUMMEDALS] =
{
	{
		// "Excellent!"
		"Excellent!",	// [BC] Fix me: Figure out why MD_EXCELLENT, etc doesn't work...
		"EXCLA0",
		"EXCLA0",
		S_EXCELLENT,
		CR_GRAY,
	},	
	{
		// "Incredible!"
		"Incredible!",
		"INCRA0",
		"INCRA0",
		S_INCREDIBLE,
		CR_RED,
	},	
	{
		// "Impressive!"
		"Impressive!",
		"IMPRA0",
		"IMPRA0",
		S_IMPRESSIVE,
		CR_GRAY,
	},
	{
		// "Most impressive!"
		"Most impressive!",
		"MIMPA0",
		"MIMPA0",
		S_MOST_IMPRESSIVE,
		CR_RED,
	},
	{
		// "Domination!"
		"Domination!",
		"DOMNA0",
		"DOMNA0",
		S_DOMINATION,
		CR_GRAY,
	},	
	{
		// "Total domination!"
		"Total domination!",
		"TDOMA0",
		"TDOMA0",
		S_TOTAL_DOMINATION,
		CR_RED,
	},	
	{
		// "Accuracy!"
		"Accuracy!",
		"ACCUA0",
		"ACCUA0",
		S_ACCURACY,
		CR_GRAY,
	},	
	{
		// "Precision!"
		"Precision!",
		"PRECA0",
		"PRECA0",
		S_PRECISION,
		CR_RED,
	},	
/*	{
		// "Survival!"
		"Survival!",
		"ICO1A0",
		"ICO1A0",
		S_EXCELLENT,
		CR_GOLD,
	},*/
	{
		// "Llama!"
		"Llama!",
		"LLAMA0",
		"LLAMA0",
		S_LLAMA,
		CR_GREEN,
	},	
};


int num_items;

// [RH] Guess what. These next three functions are from Quake2:
//	g_items.c

/*
===============
GetItemByIndex
===============
*/
gitem_t	*GetItemByIndex (int index)
{
	if (index == 0 || index >= num_items)
		return NULL;

	return &itemlist[index];
}


/*
===============
FindItemByClassname

===============
*/
gitem_t	*FindItemByClassname (const char *classname)
{
	int		i;
	gitem_t	*it;

	it = itemlist;
	for (i = 0; i < num_items; i++, it++)
		if (it->classname && !stricmp(it->classname, classname))
			return it;

	return NULL;
}

/*
===============
FindItem

===============
*/
gitem_t	*FindItem (const char *pickup_name)
{
	int		i;
	gitem_t	*it;

	it = itemlist;
	for (i = 0; i < num_items; i++, it++)
		if (it->pickup_name && !stricmp(it->pickup_name, pickup_name))
			return it;

	return NULL;
}


// Item info
// Used mainly by the give command. Hopefully will
// become more general-purpose later.
// (Yes, this was inspired by Quake 2)
gitem_t itemlist[] = {
	{
		NULL
	},	// leave index 0 alone

	{
		"item_armor_basic",
		NULL,
		NULL,
		IT_ARMOR,
		1,
		0,
		"Basic Armor"
	},

	{
		"item_armor_mega",
		NULL,
		NULL,
		IT_ARMOR,
		2,
		0,
		"Mega Armor"
	},
// [BC]
	{
		"item_armor_red",
		NULL,
		NULL,
		IT_ARMOR,
		3,
		0,
		"Red Armor"
	},

	{
		"item_armor_bonus",
		NULL,
		NULL,
		IT_ARMOR,
		1,
		0,
		"Armor Bonus"
	},
// [BC]
	{
		"item_max_armor_bonus",
		NULL,
		NULL,
		IT_ARMOR,
		1,
		0,
		"Max. Armor Bonus"
	},

	{
		"weapon_fist",
		NULL,
		NULL,
		IT_WEAPON,
		wp_fist,
		0,
		"Fist"
	},

	{
		"weapon_chainsaw",
		NULL,
		NULL,
		IT_WEAPON,
		wp_chainsaw,
		0,
		"Chainsaw"
	},

	{
		"weapon_pistol",
		NULL,
		NULL,
		IT_WEAPON,
		wp_pistol,
		0,
		"Pistol"
	},
	
	{
		"weapon_shotgun",
		NULL,
		NULL,
		IT_WEAPON,
		wp_shotgun,
		0,
		"Shotgun"
	},

	{
		"weapon_supershotgun",
		NULL,
		NULL,
		IT_WEAPON,
		wp_supershotgun,
		0,
		"Super Shotgun"
	},

	{
		"weapon_chaingun",
		NULL,
		NULL,
		IT_WEAPON,
		wp_chaingun,
		0,
		"Chaingun"
	},

	{
		"weapon_rocketlauncher",
		NULL,
		NULL,
		IT_WEAPON,
		wp_missile,
		0,
		"Rocket Launcher"
	},
// [BC]
	{
		"weapon_grenadelauncher",
		NULL,
		NULL,
		IT_WEAPON,
		wp_grenlauncher,
		0,
		"Grenade launcher"
	},

	{
		"weapon_plasmagun",
		NULL,
		NULL,
		IT_WEAPON,
		wp_plasma,
		0,
		"Plasma Gun"
	},
// [BC]
	{
		"weapon_railgun",
		NULL,
		NULL,
		IT_WEAPON,
		wp_railgun,
		0,
		"Railgun"
	},

	{
		"weapon_bfg",
		NULL,
		NULL,
		IT_WEAPON,
		wp_bfg,
		0,
		"BFG9000"
	},

	{
		"weapon_bfg10k",
		NULL,
		NULL,
		IT_WEAPON,
		wp_bfg10k,
		0,
		"BFG10000"
	},

	{
		"ammo_bullets",
		NULL,
		NULL,
		IT_AMMO,
		am_clip,
		1,
		"Bullets"
	},

	{
		"ammo_shells",
		NULL,
		NULL,
		IT_AMMO,
		am_shell,
		1,
		"Shells"
	},

	{
		"ammo_cells",
		NULL,
		NULL,
		IT_AMMO,
		am_cell,
		1,
		"Cells"
	},

	{
		"ammo_rocket",
		NULL,
		NULL,
		IT_AMMO,
		am_misl,
		1,
		"Rockets"
	},

	//
	// POWERUP ITEMS
	//
	{
		"item_invulnerability",
		NULL,
		NULL,
		IT_POWERUP,
		pw_invulnerability,
		0,
		"Invulnerability"
	},

	{
		"item_berserk",
		NULL,
		NULL,
		IT_POWERUP,
		pw_strength,
		0,
		"Berserk"
	},

	{
		"item_invisibility",
		NULL,
		NULL,
		IT_POWERUP,
		pw_invisibility,
		0,
		"Partial Invisibility"
	},

	{
		"item_ironfeet",
		NULL,
		NULL,
		IT_POWERUP,
		pw_ironfeet,
		0,
		"Radiation Suit"
	},

	{
		"item_allmap",
		NULL,
		NULL,
		IT_POWERUP,
		pw_allmap,
		0,
		"Computer Map"
	},

	{
		"item_visor",
		NULL,
		NULL,
		IT_POWERUP,
		pw_infrared,
		0,
		"Light Amplification Visor"
	},
// [BC]
	{
		"item_turbosphere",
		NULL,
		NULL,
		IT_POWERUP,
		pw_turbosphere,
		0,
		"Turbosphere"
	},

	{
		"item_floatingfeet",
		NULL,
		NULL,
		IT_POWERUP,
		pw_floatingfeet,
		0,
		"Anti-gravity Belt"
	},

	{
		"item_freezer",
		NULL,
		NULL,
		IT_POWERUP,
		pw_freezer,
		0,
		"Time Freezer"
	},

	{
		"item_infragoggles",
		NULL,
		NULL,
		IT_POWERUP,
		pw_infragoggles,
		0,
		"Infrared Goggles"
	},

	{
		"item_tracker",
		NULL,
		NULL,
		IT_POWERUP,
		pw_infratracker,
		0,
		"Infrared Tracker"
	},


	{
		"item_translucency",
		NULL,
		NULL,
		IT_POWERUP,
		pw_translucency,
		0,
		"Invisibility"
	},

	{
		"item_doomsphere",
		NULL,
		NULL,
		IT_POWERUP,
		pw_doomsphere,
		0,
		"Doomsphere"
	},

	//
	// KEYS
	//

	{
		"key_blue_card",
		NULL,
		NULL,
		IT_KEY,
		it_bluecard,
		0,
		"Blue Keycard"
	},

	{
		"key_yellow_card",
		NULL,
		NULL,
		IT_KEY,
		it_yellowcard,
		0,
		"Yellow Keycard"
	},

	{
		"key_red_card",
		NULL,
		NULL,
		IT_KEY,
		it_redcard,
		0,
		"Red Keycard"
	},

	{
		"key_blue_skull",
		NULL,
		NULL,
		IT_KEY,
		it_blueskull,
		0,
		"Blue Skull Key"
	},

	{
		"key_yellow_skull",
		NULL,
		NULL,
		IT_KEY,
		it_yellowskull,
		0,
		"Yellow Skull Key"
	},

	{
		"key_red_skull",
		NULL,
		NULL,
		IT_KEY,
		it_redskull,
		0,
		"Red Skull Key"
	},
// [BC]
	{
		"key_black_skull",
		NULL,
		NULL,
		IT_KEY,
		it_blackskull,
		0,
		"Black Skull Key"
	},

	{
		"key_silver_skull",
		NULL,
		NULL,
		IT_KEY,
		it_silverskull,
		0,
		"Silver Skull Key"
	},

	{
		"key_gold_skull",
		NULL,
		NULL,
		IT_KEY,
		it_goldskull,
		0,
		"Gold Skull Key"
	},

	{
		"key_black_card",
		NULL,
		NULL,
		IT_KEY,
		it_blackcard,
		0,
		"Black Keycard"
	},

	{
		"key_silver_card",
		NULL,
		NULL,
		IT_KEY,
		it_silvercard,
		0,
		"Silver Keycard"
	},

	{
		"key_gold_card",
		NULL,
		NULL,
		IT_KEY,
		it_goldcard,
		0,
		"Gold Keycard"
	},


	{
		"key_master_card",
		NULL,
		NULL,
		IT_KEY,
		it_mastercard,
		0,
		"Mastercard"
	},

	{
		"key_master_skull",
		NULL,
		NULL,
		IT_KEY,
		it_masterskull,
		0,
		"Master Skull Key"
	},

	//
	// [BC] Rune items
	//
	{
		"item_strength",
		NULL,
		NULL,
		IT_RUNE,
		ru_strength,
		0,
		"Strength"
	},

	{
		"item_drain",
		NULL,
		NULL,
		IT_RUNE,
		ru_drain,
		0,
		"Drain"
	},

	{
		"item_doublefiringspeed",
		NULL,
		NULL,
		IT_RUNE,
		ru_rage,
		0,
		"Rage"
	},

	{
		"item_spread",
		NULL,
		NULL,
		IT_RUNE,
		ru_spread,
		0,
		"Spread"
	},

	{
		"item_resistance",
		NULL,
		NULL,
		IT_RUNE,
		ru_resistance,
		0,
		"Resistance"
	},

	{
		"item_regeneration",
		NULL,
		NULL,
		IT_RUNE,
		ru_regeneration,
		0,
		"Regeneration"
	},

	{
		"item_prosperity",
		NULL,
		NULL,
		IT_RUNE,
		ru_prosperity,
		0,
		"Prosperity"
	},

	{
		"item_reflection",
		NULL,
		NULL,
		IT_RUNE,
		ru_reflection,
		0,
		"Reflection"
	},

	{
		"item_highjump",
		NULL,
		NULL,
		IT_RUNE,
		ru_highjump,
		0,
		"High jump"
	},

	{
		"item_haste",
		NULL,
		NULL,
		IT_RUNE,
		ru_haste,
		0,
		"Haste"
	},

	// end of list marker
	{NULL}
};

void InitItems (void)
{
	num_items = sizeof(itemlist)/sizeof(itemlist[0]) - 1;
}