2003-02-25 00:33:42 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: Inventory
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Inventory.h"
|
|
|
|
|
#include "ThemeManager.h"
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "GameState.h"
|
2003-04-07 21:24:14 +00:00
|
|
|
#include "RageTimer.h"
|
2003-04-11 01:49:57 +00:00
|
|
|
#include "PrefsManager.h"
|
2003-04-15 05:49:46 +00:00
|
|
|
#include "song.h"
|
2003-05-13 13:35:32 +00:00
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
#include "ScreenGameplay.h"
|
2003-04-07 21:24:14 +00:00
|
|
|
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 22:07:44 +00:00
|
|
|
#define NUM_ITEM_TYPES THEME->GetMetricF("Inventory","NumItemTypes")
|
|
|
|
|
#define ITEM_DURATION_SECONDS THEME->GetMetricF("Inventory","ItemDurationSeconds")
|
|
|
|
|
#define ITEM_COMBO( i ) THEME->GetMetricI("Inventory",ssprintf("Item%dCombo",i+1))
|
|
|
|
|
#define ITEM_EFFECT( i ) THEME->GetMetric ("Inventory",ssprintf("Item%dEffect",i+1))
|
|
|
|
|
#define ITEM_LEVEL( i ) THEME->GetMetricI("Inventory",ssprintf("Item%dLevel",i+1))
|
2003-04-22 04:54:04 +00:00
|
|
|
CachedThemeMetricF ITEM_USE_RATE_SECONDS("Inventory","ItemUseRateSeconds");
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
const PlayerNumber OPPOSITE_PLAYER[NUM_PLAYERS] = { PLAYER_2, PLAYER_1 };
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-22 04:54:04 +00:00
|
|
|
#define ITEM_USE_PROBABILITY (1.f/ITEM_USE_RATE_SECONDS)
|
2003-04-07 21:24:14 +00:00
|
|
|
|
2003-04-07 05:14:27 +00:00
|
|
|
struct Item
|
|
|
|
|
{
|
2003-04-07 22:07:44 +00:00
|
|
|
AttackLevel level;
|
2003-04-07 05:14:27 +00:00
|
|
|
int iCombo;
|
|
|
|
|
CString sModifier;
|
|
|
|
|
};
|
|
|
|
|
vector<Item> g_Items;
|
|
|
|
|
|
|
|
|
|
void ReloadItems()
|
|
|
|
|
{
|
|
|
|
|
g_Items.clear();
|
|
|
|
|
for( int i=0; i<NUM_ITEM_TYPES; i++ )
|
|
|
|
|
{
|
|
|
|
|
Item item;
|
2003-04-07 22:07:44 +00:00
|
|
|
item.level = (AttackLevel)(ITEM_LEVEL(i)-1);
|
2003-04-07 05:14:27 +00:00
|
|
|
item.iCombo = ITEM_COMBO(i);
|
|
|
|
|
item.sModifier = ITEM_EFFECT(i);
|
2003-04-07 21:24:14 +00:00
|
|
|
g_Items.push_back( item );
|
2003-04-07 05:14:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-25 00:33:42 +00:00
|
|
|
|
|
|
|
|
Inventory::Inventory()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-13 13:35:32 +00:00
|
|
|
Inventory::~Inventory()
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i=0; i<m_vpSoundUseItem.size(); i++ )
|
|
|
|
|
delete m_vpSoundUseItem[i];
|
|
|
|
|
m_vpSoundUseItem.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
void Inventory::Load( PlayerNumber pn )
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-22 07:51:06 +00:00
|
|
|
ITEM_USE_RATE_SECONDS.Refresh();
|
|
|
|
|
|
2003-04-07 23:06:33 +00:00
|
|
|
ReloadItems();
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
m_PlayerNumber = pn;
|
|
|
|
|
m_iLastSeenCombo = 0;
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
// don't load battle sounds if they're not going to be used
|
2003-04-07 05:14:27 +00:00
|
|
|
if( GAMESTATE->m_PlayMode == PLAY_MODE_BATTLE )
|
2003-02-26 00:20:00 +00:00
|
|
|
{
|
2003-05-13 13:35:32 +00:00
|
|
|
m_soundAcquireItem.Load( THEME->GetPathToS("Inventory aquire item") );
|
|
|
|
|
for( unsigned i=0; i<g_Items.size(); i++ )
|
2003-02-26 00:20:00 +00:00
|
|
|
{
|
2003-05-13 13:35:32 +00:00
|
|
|
RageSound* pSound = new RageSound;
|
|
|
|
|
CString sPath = THEME->GetPathToS( ssprintf("Inventory use item %u",i+1) );
|
|
|
|
|
pSound->Load( sPath );
|
|
|
|
|
m_vpSoundUseItem.push_back( pSound );
|
2003-02-26 00:20:00 +00:00
|
|
|
}
|
2003-05-13 13:35:32 +00:00
|
|
|
m_soundItemEnding.Load( THEME->GetPathToS("Inventory item ending") );
|
2003-02-26 00:20:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
void Inventory::Update( float fDelta )
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-07 05:14:27 +00:00
|
|
|
if( GAMESTATE->m_PlayMode != PLAY_MODE_BATTLE )
|
|
|
|
|
return;
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
if( GAMESTATE->m_bActiveAttackEndedThisUpdate[m_PlayerNumber] )
|
|
|
|
|
m_soundItemEnding.Play();
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
PlayerNumber pn = m_PlayerNumber;
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
// check to see if they deserve a new item
|
|
|
|
|
if( GAMESTATE->m_CurStageStats.iCurCombo[pn] != m_iLastSeenCombo )
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
int iOldCombo = m_iLastSeenCombo;
|
|
|
|
|
m_iLastSeenCombo = GAMESTATE->m_CurStageStats.iCurCombo[pn];
|
|
|
|
|
int iNewCombo = m_iLastSeenCombo;
|
|
|
|
|
|
2003-04-07 05:14:27 +00:00
|
|
|
#define CROSSED(i) (iOldCombo<i)&&(iNewCombo>=i)
|
2003-04-11 01:49:57 +00:00
|
|
|
#define BROKE_ABOVE(i) (iNewCombo<iOldCombo)&&(iOldCombo>=i)
|
2003-04-07 03:25:44 +00:00
|
|
|
|
2003-04-07 05:14:27 +00:00
|
|
|
for( unsigned i=0; i<g_Items.size(); i++ )
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-11 01:49:57 +00:00
|
|
|
bool bEarnedThisItem = false;
|
|
|
|
|
if( PREFSMAN->m_bBreakComboToGetItem )
|
|
|
|
|
bEarnedThisItem = BROKE_ABOVE(g_Items[i].iCombo);
|
|
|
|
|
else
|
|
|
|
|
bEarnedThisItem = CROSSED(g_Items[i].iCombo);
|
|
|
|
|
|
|
|
|
|
if( bEarnedThisItem )
|
2003-04-07 05:14:27 +00:00
|
|
|
{
|
|
|
|
|
AwardItem( i );
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-02-25 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-04-07 21:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// use items if this player is CPU-controlled
|
2003-04-21 02:41:10 +00:00
|
|
|
if( GAMESTATE->m_PlayerController[m_PlayerNumber] != PC_HUMAN &&
|
2003-04-14 22:12:54 +00:00
|
|
|
GAMESTATE->m_fSongBeat < GAMESTATE->m_pCurSong->m_fLastBeat )
|
2003-04-07 21:24:14 +00:00
|
|
|
{
|
2003-04-22 04:54:04 +00:00
|
|
|
// every 1 seconds, try to use an item
|
2003-04-12 06:16:12 +00:00
|
|
|
int iLastSecond = (int)(RageTimer::GetTimeSinceStart() - fDelta);
|
2003-04-07 21:24:14 +00:00
|
|
|
int iThisSecond = (int)RageTimer::GetTimeSinceStart();
|
|
|
|
|
if( iLastSecond != iThisSecond )
|
|
|
|
|
{
|
2003-04-22 04:54:04 +00:00
|
|
|
for( int s=0; s<NUM_INVENTORY_SLOTS; s++ )
|
|
|
|
|
if( !GAMESTATE->m_Inventory[m_PlayerNumber][s].IsBlank() )
|
|
|
|
|
if( randomf(0,1) < ITEM_USE_PROBABILITY )
|
|
|
|
|
UseItem( s );
|
2003-04-07 21:24:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-02-25 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-07 05:14:27 +00:00
|
|
|
void Inventory::AwardItem( int iItemIndex )
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
// search for the first open slot
|
|
|
|
|
int iOpenSlot = -1;
|
2003-02-25 02:51:04 +00:00
|
|
|
|
2003-04-14 22:12:54 +00:00
|
|
|
GameState::Attack* asInventory = GAMESTATE->m_Inventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
|
2003-02-25 02:51:04 +00:00
|
|
|
|
2003-04-14 22:12:54 +00:00
|
|
|
if( asInventory[NUM_INVENTORY_SLOTS/2].IsBlank() )
|
2003-04-07 03:25:44 +00:00
|
|
|
iOpenSlot = NUM_INVENTORY_SLOTS/2;
|
|
|
|
|
else
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
for( int s=0; s<NUM_INVENTORY_SLOTS; s++ )
|
2003-04-14 22:12:54 +00:00
|
|
|
if( asInventory[s].IsBlank() )
|
2003-04-07 03:25:44 +00:00
|
|
|
{
|
|
|
|
|
iOpenSlot = s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-02-25 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
if( iOpenSlot != -1 )
|
2003-02-26 23:26:57 +00:00
|
|
|
{
|
2003-04-14 22:12:54 +00:00
|
|
|
GameState::Attack a;
|
|
|
|
|
a.sModifier = g_Items[iItemIndex].sModifier;
|
|
|
|
|
a.fSecsRemaining = ITEM_DURATION_SECONDS;
|
|
|
|
|
a.level = g_Items[iItemIndex].level;
|
|
|
|
|
asInventory[iOpenSlot] = a;
|
2003-04-07 03:25:44 +00:00
|
|
|
m_soundAcquireItem.Play();
|
2003-02-26 23:26:57 +00:00
|
|
|
}
|
2003-04-07 03:25:44 +00:00
|
|
|
// else not enough room to insert item
|
|
|
|
|
}
|
2003-02-26 00:20:00 +00:00
|
|
|
|
2003-04-07 05:14:27 +00:00
|
|
|
void Inventory::UseItem( int iSlot )
|
2003-04-07 03:25:44 +00:00
|
|
|
{
|
2003-04-14 22:12:54 +00:00
|
|
|
GameState::Attack* asInventory = GAMESTATE->m_Inventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-14 22:12:54 +00:00
|
|
|
if( asInventory[iSlot].IsBlank() )
|
2003-04-07 03:25:44 +00:00
|
|
|
return;
|
2003-02-25 02:51:04 +00:00
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
// PlayerNumber pnToAttack = OPPOSITE_PLAYER[m_PlayerNumber];
|
2003-04-14 22:12:54 +00:00
|
|
|
GameState::Attack a = asInventory[iSlot];
|
2003-04-07 22:07:44 +00:00
|
|
|
|
2003-05-13 13:35:32 +00:00
|
|
|
// GAMESTATE->LaunchAttack( pnToAttack, a );
|
|
|
|
|
// GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( pnToAttack );
|
|
|
|
|
|
|
|
|
|
float fPercentHealthToDrain = (a.level+1) / 10.f;
|
|
|
|
|
ASSERT( fPercentHealthToDrain > 0 );
|
|
|
|
|
GAMESTATE->m_fOpponentHealthPercent -= fPercentHealthToDrain;
|
|
|
|
|
CLAMP( GAMESTATE->m_fOpponentHealthPercent, 0.f, 1.f );
|
2003-02-26 00:20:00 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
// remove the item
|
2003-04-14 22:12:54 +00:00
|
|
|
asInventory[iSlot].MakeBlank();
|
2003-05-13 13:35:32 +00:00
|
|
|
m_vpSoundUseItem[a.level]->Play();
|
|
|
|
|
|
|
|
|
|
SCREENMAN->SendMessageToTopScreen( (ScreenMessage)(SM_BattleDamageLevel1+a.level) );
|
2003-03-06 01:12:27 +00:00
|
|
|
}
|