working on Disney Rave "Magic Dance" battle mode
This commit is contained in:
+70
-124
@@ -15,167 +15,113 @@
|
||||
#include "RageUtil.h"
|
||||
#include "GameState.h"
|
||||
|
||||
CachedThemeMetricF ATTACK_DURATION_SECONDS ("Inventory","AttackDurationSeconds");
|
||||
CachedThemeMetricI COMBO_PER_ATTACK_LEVEL ("Inventory","ComboPerAttackLevel");
|
||||
|
||||
#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))
|
||||
const PlayerNumber OPPOSITE_PLAYER[NUM_PLAYERS] = { PLAYER_2, PLAYER_1 };
|
||||
|
||||
|
||||
Inventory::Inventory()
|
||||
{
|
||||
RefreshPossibleItems();
|
||||
|
||||
ATTACK_DURATION_SECONDS.Refresh();
|
||||
COMBO_PER_ATTACK_LEVEL.Refresh();
|
||||
}
|
||||
|
||||
void Inventory::Load( PlayerNumber pn )
|
||||
{
|
||||
m_PlayerNumber = pn;
|
||||
m_iLastSeenCombo = 0;
|
||||
|
||||
// don't load battle sounds if they're not going to be used
|
||||
switch( GAMESTATE->m_PlayMode )
|
||||
{
|
||||
case PLAY_MODE_BATTLE:
|
||||
m_soundAcquireItem.Load( THEME->GetPathTo("Sounds","gameplay battle aquire item") );
|
||||
m_soundUseItem.Load( THEME->GetPathTo("Sounds","gameplay battle use item") );
|
||||
m_soundItemEnding.Load( THEME->GetPathTo("Sounds","gameplay battle item ending") );
|
||||
{
|
||||
for( int p=0; p<NUM_PLAYERS; p++ )
|
||||
{
|
||||
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)) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Inventory::RefreshPossibleItems()
|
||||
{
|
||||
m_ItemDefs.clear();
|
||||
|
||||
for( int i=0; i<NUM_ITEM_TYPES; i++ )
|
||||
{
|
||||
ItemDef def;
|
||||
def.comboLevel = ITEM_COMBO(i);
|
||||
def.effect = ITEM_EFFECT(i);
|
||||
m_ItemDefs.push_back( def );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Inventory::Update( float fDelta )
|
||||
{
|
||||
for( int p=0; p<NUM_PLAYERS; p++ )
|
||||
{
|
||||
bool bActiveItemsChanged = false;
|
||||
for( int i=m_ActiveItems[p].size()-1; i>=0; i-- )
|
||||
{
|
||||
ActiveItem& active_item = m_ActiveItems[p][i];
|
||||
active_item.fSecondsLeft -= fDelta;
|
||||
if( active_item.fSecondsLeft < 0 )
|
||||
{
|
||||
m_ActiveItems[p].erase( m_ActiveItems[p].begin()+i );
|
||||
bActiveItemsChanged = true;
|
||||
}
|
||||
}
|
||||
if( GAMESTATE->m_bActiveAttackEndedThisUpdate[m_PlayerNumber] )
|
||||
m_soundItemEnding.Play();
|
||||
|
||||
if( bActiveItemsChanged )
|
||||
PlayerNumber pn = m_PlayerNumber;
|
||||
|
||||
// check to see if they deserve a new item
|
||||
if( GAMESTATE->m_CurStageStats.iCurCombo[pn] != m_iLastSeenCombo )
|
||||
{
|
||||
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
|
||||
{
|
||||
RebuildPlayerOptions( (PlayerNumber)p );
|
||||
m_soundItemEnding.Play();
|
||||
// they deserve a new item
|
||||
CLAMP( iLevelOfNewCombo, 0, GAMESTATE->m_MaxAttackLevel[pn] );
|
||||
AttackLevel al = (AttackLevel)iLevelOfNewCombo;
|
||||
AwardItem( al );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Inventory::OnComboBroken( PlayerNumber pn, int iCombo )
|
||||
void Inventory::AwardItem( AttackLevel al )
|
||||
{
|
||||
int* iItems = GAMESTATE->m_iItems[pn];
|
||||
// search for the first open slot
|
||||
int iOpenSlot = -1;
|
||||
|
||||
// search for the item acquired
|
||||
int item;
|
||||
for( item=0; item<(int)m_ItemDefs.size(); item++ )
|
||||
if( m_ItemDefs[item].comboLevel > iCombo )
|
||||
break;
|
||||
CString* asInventory = GAMESTATE->m_sInventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
|
||||
CString* asAttacks = GAMESTATE->m_sAttacks[m_PlayerNumber][al]; //[NUM_ATTACKS_PER_LEVEL]
|
||||
|
||||
item--; // back up because we went one too far
|
||||
|
||||
if( item == -1 ) // no item acquired
|
||||
return false;
|
||||
if( asInventory[NUM_INVENTORY_SLOTS/2] == "" )
|
||||
iOpenSlot = NUM_INVENTORY_SLOTS/2;
|
||||
else
|
||||
{
|
||||
// give them an item
|
||||
|
||||
// search for the first open slot
|
||||
int iOpenSlot = -1;
|
||||
|
||||
if( iItems[NUM_ITEM_SLOTS/2] == ITEM_NONE )
|
||||
iOpenSlot = NUM_ITEM_SLOTS/2;
|
||||
else
|
||||
{
|
||||
for( int s=0; s<NUM_ITEM_SLOTS; s++ )
|
||||
if( iItems[s] == ITEM_NONE )
|
||||
{
|
||||
iOpenSlot = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( iOpenSlot != -1 )
|
||||
{
|
||||
iItems[iOpenSlot] = item;
|
||||
m_soundAcquireItem.Play();
|
||||
}
|
||||
// else not enough room to insert item
|
||||
for( int s=0; s<NUM_INVENTORY_SLOTS; s++ )
|
||||
if( asInventory[s] == "" )
|
||||
{
|
||||
iOpenSlot = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
if( iOpenSlot != -1 )
|
||||
{
|
||||
CString sAttackToGive = asAttacks[ rand()%NUM_ATTACKS_PER_LEVEL ];
|
||||
asInventory[iOpenSlot] = sAttackToGive;
|
||||
m_soundAcquireItem.Play();
|
||||
}
|
||||
// else not enough room to insert item
|
||||
}
|
||||
|
||||
void Inventory::UseItem( PlayerNumber pn, int iSlot )
|
||||
void Inventory::UseAttack( int iSlot )
|
||||
{
|
||||
int* iItems = GAMESTATE->m_iItems[pn];
|
||||
CString* asInventory = GAMESTATE->m_sInventory[m_PlayerNumber]; //[NUM_INVENTORY_SLOTS]
|
||||
|
||||
if( iItems[iSlot] == ITEM_NONE )
|
||||
if( asInventory[iSlot] == "" )
|
||||
return;
|
||||
|
||||
int iItemIndex = iItems[iSlot];
|
||||
PlayerNumber pnToAttack = OPPOSITE_PLAYER[m_PlayerNumber];
|
||||
|
||||
PlayerNumber pnToAttack;
|
||||
switch( pn )
|
||||
{
|
||||
case PLAYER_1: pnToAttack = PLAYER_2; break;
|
||||
case PLAYER_2: pnToAttack = PLAYER_1; break;
|
||||
default: ASSERT(0); pnToAttack = PLAYER_1; break;
|
||||
}
|
||||
GameState::ActiveAttack aa;
|
||||
aa.fSecsRemaining = ATTACK_DURATION_SECONDS;
|
||||
aa.sModifier = asInventory[iSlot];
|
||||
|
||||
// see if there is already an active instance of this item index
|
||||
bool bAddedToExisting = false;
|
||||
for( unsigned i=0; i<m_ActiveItems[pnToAttack].size(); i++ )
|
||||
{
|
||||
if( m_ActiveItems[pnToAttack][i].iItemDefIndex == iItemIndex )
|
||||
{
|
||||
m_ActiveItems[pnToAttack][i].fSecondsLeft += ITEM_DURATION_SECONDS;
|
||||
bAddedToExisting = true;
|
||||
}
|
||||
}
|
||||
if( !bAddedToExisting )
|
||||
{
|
||||
ActiveItem ai = { ITEM_DURATION_SECONDS, iItemIndex };
|
||||
m_ActiveItems[pnToAttack].push_back( ai );
|
||||
}
|
||||
|
||||
RebuildPlayerOptions( pnToAttack );
|
||||
GAMESTATE->ActivateAttack( pnToAttack, aa );
|
||||
GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( pnToAttack );
|
||||
|
||||
// remove the item
|
||||
iItems[iSlot] = ITEM_NONE;
|
||||
|
||||
asInventory[iSlot] = "";
|
||||
m_soundUseItem.Play();
|
||||
}
|
||||
|
||||
void Inventory::RebuildPlayerOptions( PlayerNumber pn )
|
||||
{
|
||||
// rebuild player options
|
||||
PlayerOptions po = GAMESTATE->m_StoredPlayerOptions[pn];
|
||||
for( int i=0; i<(int)m_ActiveItems[pn].size(); i++ )
|
||||
{
|
||||
int iItemDefIndex = m_ActiveItems[pn][i].iItemDefIndex;
|
||||
po.FromString( m_ItemDefs[iItemDefIndex].effect );
|
||||
}
|
||||
GAMESTATE->m_PlayerOptions[pn] = po;
|
||||
}
|
||||
|
||||
|
||||
void Inventory::RemoveAllActiveItems()
|
||||
{
|
||||
for( int p=0; p<NUM_PLAYERS; p++ )
|
||||
m_ActiveItems[p].clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user