Files
itgmania212121/stepmania/src/Inventory.cpp
T

144 lines
3.4 KiB
C++
Raw Normal View History

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 05:14:27 +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))
2003-02-25 00:33:42 +00:00
const PlayerNumber OPPOSITE_PLAYER[NUM_PLAYERS] = { PLAYER_2, PLAYER_1 };
2003-02-25 00:33:42 +00:00
2003-04-07 05:14:27 +00:00
struct Item
{
int iCombo;
CString sModifier;
};
vector<Item> g_Items;
void ReloadItems()
{
g_Items.clear();
for( int i=0; i<NUM_ITEM_TYPES; i++ )
{
Item item;
item.iCombo = ITEM_COMBO(i);
item.sModifier = ITEM_EFFECT(i);
}
}
2003-02-25 00:33:42 +00:00
Inventory::Inventory()
{
2003-04-07 05:14:27 +00:00
ReloadItems();
2003-02-25 00:33:42 +00:00
}
void Inventory::Load( PlayerNumber pn )
2003-02-25 00:33:42 +00:00
{
m_PlayerNumber = pn;
m_iLastSeenCombo = 0;
2003-02-25 00:33:42 +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-04-07 05:14:27 +00:00
for( int p=0; p<NUM_PLAYERS; p++ )
{
2003-04-07 05:14:27 +00:00
m_soundAcquireItem.Load( THEME->GetPathTo("Sounds",ssprintf("Inventory aquire item p%d",p+1)) );
m_soundUseItem.Load( THEME->GetPathTo("Sounds",ssprintf("Inventory use item p%d",p+1)) );
m_soundItemEnding.Load( THEME->GetPathTo("Sounds",ssprintf("Inventory item ending p%d",p+1)) );
}
}
}
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;
if( GAMESTATE->m_bActiveAttackEndedThisUpdate[m_PlayerNumber] )
m_soundItemEnding.Play();
2003-02-25 00:33:42 +00:00
PlayerNumber pn = m_PlayerNumber;
2003-02-25 00:33:42 +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
{
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-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-07 05:14:27 +00:00
if( CROSSED(g_Items[i].iCombo) )
{
AwardItem( i );
break;
}
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
{
// search for the first open slot
int iOpenSlot = -1;
2003-02-25 02:51:04 +00:00
CString* asInventory = GAMESTATE->m_sInventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
2003-02-25 02:51:04 +00:00
if( asInventory[NUM_INVENTORY_SLOTS/2] == "" )
iOpenSlot = NUM_INVENTORY_SLOTS/2;
else
2003-02-25 00:33:42 +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
}
if( iOpenSlot != -1 )
{
2003-04-07 05:14:27 +00:00
CString sAttackToGive = g_Items[iItemIndex].sModifier;
asInventory[iOpenSlot] = sAttackToGive;
m_soundAcquireItem.Play();
}
// else not enough room to insert item
}
2003-04-07 05:14:27 +00:00
void Inventory::UseItem( int iSlot )
{
CString* asInventory = GAMESTATE->m_sInventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
2003-02-25 00:33:42 +00:00
if( asInventory[iSlot] == "" )
return;
2003-02-25 02:51:04 +00:00
PlayerNumber pnToAttack = OPPOSITE_PLAYER[m_PlayerNumber];
2003-02-25 00:33:42 +00:00
GameState::ActiveAttack aa;
2003-04-07 05:14:27 +00:00
aa.fSecsRemaining = ITEM_DURATION_SECONDS;
aa.sModifier = asInventory[iSlot];
2003-04-07 05:14:27 +00:00
GAMESTATE->LaunchAttack( pnToAttack, aa );
GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( pnToAttack );
// remove the item
asInventory[iSlot] = "";
m_soundUseItem.Play();
}