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 03:25:44 +00:00
|
|
|
CachedThemeMetricF ATTACK_DURATION_SECONDS ("Inventory","AttackDurationSeconds");
|
|
|
|
|
CachedThemeMetricI COMBO_PER_ATTACK_LEVEL ("Inventory","ComboPerAttackLevel");
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
Inventory::Inventory()
|
|
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
ATTACK_DURATION_SECONDS.Refresh();
|
|
|
|
|
COMBO_PER_ATTACK_LEVEL.Refresh();
|
2003-02-25 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
void Inventory::Load( PlayerNumber pn )
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
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
|
|
|
|
|
switch( GAMESTATE->m_PlayMode )
|
2003-02-26 00:20:00 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
case PLAY_MODE_BATTLE:
|
2003-02-26 00:20:00 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
2003-02-26 00:20:00 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
m_soundAcquireItem.Load( THEME->GetPathTo("Sounds",ssprintf("Inventory aquire p%d",p+1)) );
|
|
|
|
|
m_soundUseItem.Load( THEME->GetPathTo("Sounds",ssprintf("Inventory use p%d",p+1)) );
|
|
|
|
|
m_soundItemEnding.Load( THEME->GetPathTo("Sounds",ssprintf("Inventory finished p%d",p+1)) );
|
2003-02-26 00:20:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-04-07 03:25:44 +00:00
|
|
|
break;
|
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 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;
|
|
|
|
|
|
|
|
|
|
int iLevelOfOldCombo = (iOldCombo/COMBO_PER_ATTACK_LEVEL) - 1;
|
|
|
|
|
int iLevelOfNewCombo = (iNewCombo/COMBO_PER_ATTACK_LEVEL) - 1;
|
|
|
|
|
|
|
|
|
|
if( iLevelOfOldCombo < iLevelOfNewCombo && // combo increasing
|
|
|
|
|
iLevelOfNewCombo >= ATTACK_LEVEL_1 ) // attack level not negative
|
2003-02-25 00:33:42 +00:00
|
|
|
{
|
2003-04-07 03:25:44 +00:00
|
|
|
// they deserve a new item
|
|
|
|
|
CLAMP( iLevelOfNewCombo, 0, GAMESTATE->m_MaxAttackLevel[pn] );
|
|
|
|
|
AttackLevel al = (AttackLevel)iLevelOfNewCombo;
|
|
|
|
|
AwardItem( al );
|
2003-02-25 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
void Inventory::AwardItem( AttackLevel al )
|
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-07 03:25:44 +00:00
|
|
|
CString* asInventory = GAMESTATE->m_sInventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
|
|
|
|
|
CString* asAttacks = GAMESTATE->m_sAttacks[m_PlayerNumber][al]; //[NUM_ATTACKS_PER_LEVEL]
|
2003-02-25 02:51:04 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
if( asInventory[NUM_INVENTORY_SLOTS/2] == "" )
|
|
|
|
|
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++ )
|
|
|
|
|
if( asInventory[s] == "" )
|
|
|
|
|
{
|
|
|
|
|
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-07 03:25:44 +00:00
|
|
|
CString sAttackToGive = asAttacks[ rand()%NUM_ATTACKS_PER_LEVEL ];
|
|
|
|
|
asInventory[iOpenSlot] = sAttackToGive;
|
|
|
|
|
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 03:25:44 +00:00
|
|
|
void Inventory::UseAttack( int iSlot )
|
|
|
|
|
{
|
|
|
|
|
CString* asInventory = GAMESTATE->m_sInventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
if( asInventory[iSlot] == "" )
|
|
|
|
|
return;
|
2003-02-25 02:51:04 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
PlayerNumber pnToAttack = OPPOSITE_PLAYER[m_PlayerNumber];
|
2003-02-25 00:33:42 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
GameState::ActiveAttack aa;
|
|
|
|
|
aa.fSecsRemaining = ATTACK_DURATION_SECONDS;
|
|
|
|
|
aa.sModifier = asInventory[iSlot];
|
2003-02-26 00:20:00 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
GAMESTATE->ActivateAttack( pnToAttack, aa );
|
|
|
|
|
GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( pnToAttack );
|
2003-02-26 00:20:00 +00:00
|
|
|
|
2003-04-07 03:25:44 +00:00
|
|
|
// remove the item
|
|
|
|
|
asInventory[iSlot] = "";
|
|
|
|
|
m_soundUseItem.Play();
|
2003-03-06 01:12:27 +00:00
|
|
|
}
|