diff options
Diffstat (limited to 'game/code/cards')
-rw-r--r-- | game/code/cards/allcards.cpp | 5 | ||||
-rw-r--r-- | game/code/cards/bonuscard.cpp | 72 | ||||
-rw-r--r-- | game/code/cards/bonuscard.h | 63 | ||||
-rw-r--r-- | game/code/cards/card.cpp | 98 | ||||
-rw-r--r-- | game/code/cards/card.h | 130 | ||||
-rw-r--r-- | game/code/cards/cardgallery.cpp | 639 | ||||
-rw-r--r-- | game/code/cards/cardgallery.h | 131 | ||||
-rw-r--r-- | game/code/cards/cards.h | 124 | ||||
-rw-r--r-- | game/code/cards/cardsdb.cpp | 218 | ||||
-rw-r--r-- | game/code/cards/cardsdb.h | 71 | ||||
-rw-r--r-- | game/code/cards/collectorcard.cpp | 72 | ||||
-rw-r--r-- | game/code/cards/collectorcard.h | 63 |
12 files changed, 1686 insertions, 0 deletions
diff --git a/game/code/cards/allcards.cpp b/game/code/cards/allcards.cpp new file mode 100644 index 0000000..65d0dd9 --- /dev/null +++ b/game/code/cards/allcards.cpp @@ -0,0 +1,5 @@ +#include <cards/bonuscard.cpp> +#include <cards/card.cpp> +#include <cards/cardgallery.cpp> +#include <cards/cardsdb.cpp> +#include <cards/collectorcard.cpp> diff --git a/game/code/cards/bonuscard.cpp b/game/code/cards/bonuscard.cpp new file mode 100644 index 0000000..28e716f --- /dev/null +++ b/game/code/cards/bonuscard.cpp @@ -0,0 +1,72 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: BonusCard +// +// Description: Implementation of the BonusCard class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +//=========================================================================== +// Includes +//=========================================================================== +#include <cards/bonuscard.h> + +//=========================================================================== +// Local Constants +//=========================================================================== + +//=========================================================================== +// Public Member Functions +//=========================================================================== + +//=========================================================================== +// BonusCard::BonusCard +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +BonusCard::BonusCard +( + unsigned int ID, + unsigned int level, + unsigned int levelID, + tUID cardName, + const eQuoteID* quotes, + int numQuotes +) +: Card( ID, level, levelID, cardName, quotes, numQuotes ) +{ +} + +//=========================================================================== +// BonusCard::~BonusCard +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +BonusCard::~BonusCard() +{ +} + +//=========================================================================== +// Private Member Functions +//=========================================================================== + diff --git a/game/code/cards/bonuscard.h b/game/code/cards/bonuscard.h new file mode 100644 index 0000000..27d9af2 --- /dev/null +++ b/game/code/cards/bonuscard.h @@ -0,0 +1,63 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: BonusCard +// +// Description: Interface for the BonusCard class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +#ifndef BONUSCARD_H +#define BONUSCARD_H + +//=========================================================================== +// Nested Includes +//=========================================================================== + +#include <cards/card.h> + +//=========================================================================== +// Forward References +//=========================================================================== + +//=========================================================================== +// Interface Definitions +//=========================================================================== + +class BonusCard : public Card +{ +public: + BonusCard( unsigned int ID, + unsigned int level, + unsigned int levelID, + tUID cardName, + const eQuoteID* quotes, + int numQuotes ); + + virtual ~BonusCard(); + + virtual eCardType GetType() const { return BONUS_CARD; } + +private: + + //--------------------------------------------------------------------- + // Private Functions + //--------------------------------------------------------------------- + + // No copying or assignment. Declare but don't define. + // + BonusCard( const BonusCard& ); + BonusCard& operator= ( const BonusCard& ); + + //--------------------------------------------------------------------- + // Private Data + //--------------------------------------------------------------------- + +}; + +#endif // BONUSCARD_H diff --git a/game/code/cards/card.cpp b/game/code/cards/card.cpp new file mode 100644 index 0000000..8794ec4 --- /dev/null +++ b/game/code/cards/card.cpp @@ -0,0 +1,98 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: Card +// +// Description: Implementation of the Card class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +//=========================================================================== +// Includes +//=========================================================================== +#include <string.h> +#include <cards/card.h> + +//=========================================================================== +// Local Constants +//=========================================================================== + +//=========================================================================== +// Public Member Functions +//=========================================================================== + +//=========================================================================== +// Card::Card +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +Card::Card +( + unsigned int ID, + unsigned int level, + unsigned int levelID, + tUID cardName, + const eQuoteID* quotes, + int numQuotes +) +: m_ID( ID ), + m_level( level ), + m_levelID( levelID ), + m_cardName( cardName ), + m_numQuotes( 0 ) +{ + rAssert( quotes != NULL ); + + for( int i = 0; i < numQuotes; i++ ) + { + rAssert( quotes[ i ] < NUM_QUOTE_IDS ); + + m_quotes[ i ] = quotes[ i ]; + + if( m_quotes[ i ] != EMPTY_QUOTE ) + { + m_numQuotes++; + } + } +} + +//=========================================================================== +// Card::~Card +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +Card::~Card() +{ +} + +eQuoteID +Card::GetQuoteID( int index ) const +{ + rAssert( static_cast<unsigned int>( index ) < MAX_NUM_QUOTES ); + + return m_quotes[ index ]; +} + +//=========================================================================== +// Private Member Functions +//=========================================================================== + diff --git a/game/code/cards/card.h b/game/code/cards/card.h new file mode 100644 index 0000000..216fcb7 --- /dev/null +++ b/game/code/cards/card.h @@ -0,0 +1,130 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: Card +// +// Description: Interface for the Card class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +#ifndef CARD_H +#define CARD_H + +//=========================================================================== +// Nested Includes +//=========================================================================== + +#include <p3d/p3dtypes.hpp> + +//=========================================================================== +// Forward References +//=========================================================================== + +enum eCardType +{ + COLLECTOR_CARD, + BONUS_CARD, + + NUM_CARD_TYPES +}; + +enum eQuoteID +{ + EMPTY_QUOTE = -1, + + QUOTE_ANNOUNCER, + QUOTE_APU, + QUOTE_BART, + QUOTE_BROCKMAN, + QUOTE_BURNS, + QUOTE_CARL, + QUOTE_CHILD, + QUOTE_DR_WOLFF, + QUOTE_GIL, + QUOTE_HOMER, + QUOTE_JASPER, + QUOTE_JIMBO, + QUOTE_KANG, + QUOTE_KRUSTY, + QUOTE_LENNY, + QUOTE_LISA, + QUOTE_MAGGIE, + QUOTE_MANJULA, + QUOTE_MARGE, + QUOTE_MEYERS, + QUOTE_MILHOUSE, + QUOTE_MOTHER, + QUOTE_MR_SPARKLE, + QUOTE_OTTO, + QUOTE_PHOTOGRAPHER, + QUOTE_RALPH, + QUOTE_SKINNER, + QUOTE_SMITHERS, + QUOTE_STACY, + QUOTE_WIGGUM, + QUOTE_WILLIE, + + NUM_QUOTE_IDS +}; + +const unsigned int MAX_NUM_QUOTES = 3; // max. number of quotes per card + +//=========================================================================== +// Interface Definitions +//=========================================================================== + +class Card +{ +public: + Card( unsigned int ID, + unsigned int level, + unsigned int levelID, + tUID cardName, + const eQuoteID* quotes, + int numQuotes ); + + virtual ~Card(); + + // Accessors to card info + unsigned int GetID() const { return m_ID; } + unsigned int GetLevel() const { return m_level; } + unsigned int GetLevelID() const { return m_levelID; } + tUID GetCardName() const { return m_cardName; } + eQuoteID GetQuoteID( int index ) const; + int GetNumQuotes() const { return m_numQuotes; } + + // Pure virtual function to be implemented by derived classes + virtual eCardType GetType() const = 0; + +private: + + //--------------------------------------------------------------------- + // Private Functions + //--------------------------------------------------------------------- + + // No copying or assignment. Declare but don't define. + // + Card( const Card& ); + Card& operator= ( const Card& ); + + //--------------------------------------------------------------------- + // Private Data + //--------------------------------------------------------------------- + + unsigned int m_ID; // ID >= 0 (for card image) + unsigned int m_level; // level >= 1 + unsigned int m_levelID; // levelID >= 1 + + tUID m_cardName; // hashed ID for card name + + eQuoteID m_quotes[ MAX_NUM_QUOTES ]; + int m_numQuotes; + +}; + +#endif // CARD_H diff --git a/game/code/cards/cardgallery.cpp b/game/code/cards/cardgallery.cpp new file mode 100644 index 0000000..d82fc74 --- /dev/null +++ b/game/code/cards/cardgallery.cpp @@ -0,0 +1,639 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: CardGallery +// +// Description: Implementation of the CardGallery class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +//=========================================================================== +// Includes +//=========================================================================== +#include <cards/cardgallery.h> +#include <cards/cardsdb.h> +#include <cards/card.h> + +#include <data/gamedatamanager.h> +#include <memory/srrmemory.h> + +#include <raddebugwatch.hpp> + +// Static pointer to instance of singleton. +CardGallery* CardGallery::spInstance = NULL; + +#ifdef DEBUGWATCH + static const char* WATCHER_NAMESPACE = "Card Gallery"; + static unsigned int s_wAddCollectedCard; + static void AddCardToGallery() + { + GetCardGallery()->AddCollectedCardByID( s_wAddCollectedCard ); + } + + static void AddAllCardsToGallery() + { + GetCardGallery()->AddAllCollectedCards(); + } + + static void RemoveAllCardsFromGallery() + { + GetCardGallery()->RemoveAllCollectedCards(); + } +#endif + +//=========================================================================== +// Local Constants +//=========================================================================== + +const unsigned int NUM_BITS_PER_BYTE = 8; + +//=========================================================================== +// Public Member Functions +//=========================================================================== + +CardList::CardList() +: m_numCards( 0 ) +{ + memset( m_cards, 0, sizeof( m_cards ) ); +} + +void +CardList::Add( Card* card ) +{ + rAssert( card != NULL ); + rAssert( m_numCards < static_cast<int>( NUM_CARDS_PER_LEVEL ) ); + + unsigned int slot = card->GetLevelID() - 1; + rAssert( slot < NUM_CARDS_PER_LEVEL ); + + if( m_cards[ slot ] == NULL ) + { + m_cards[ slot ] = card; + m_numCards++; + } + else + { + rAssertMsg( 0, "WARNING: *** Card already collected!" ); + } +} + +bool +CardList::Remove( unsigned int cardID ) +{ + bool cardFound = false; + + // find card with cardID + // + for( int i = 0; i < m_numCards; i++ ) + { + rAssert( m_cards[ i ] ); + + if( m_cards[ i ]->GetID() == cardID ) + { + // found it! now remove it + m_cards[ i ] = NULL; + m_numCards--; + + cardFound = true; + break; + } + } + + return cardFound; +} + +void +CardList::Empty() +{ + memset( m_cards, 0, sizeof( m_cards ) ); + m_numCards = 0; +} + +//============================================================================== +// CardGallery::CreateInstance +//============================================================================== +// +// Description: - Creates the Card Gallery. +// +// Parameters: None. +// +// Return: Pointer to the CardGallery. +// +// Constraints: This is a singleton so only one instance is allowed. +// +//============================================================================== +CardGallery* CardGallery::CreateInstance() +{ +MEMTRACK_PUSH_GROUP( "CardGallery" ); + #ifdef RAD_GAMECUBE + HeapMgr()->PushHeap( GMA_GC_VMM ); + #else + HeapMgr()->PushHeap( GMA_PERSISTENT ); + #endif + spInstance = new(GMA_PERSISTENT) CardGallery; + rAssert( spInstance != NULL ); + + #ifdef RAD_GAMECUBE + HeapMgr()->PopHeap( GMA_GC_VMM ); + #else + HeapMgr()->PopHeap( GMA_PERSISTENT ); + #endif + MEMTRACK_POP_GROUP( "CardGallery" ); + return spInstance; +} + +//============================================================================== +// CardGallery::DestroyInstance +//============================================================================== +// +// Description: Destroy the GUI system. +// +// Parameters: None. +// +// Return: None. +// +//============================================================================== +void CardGallery::DestroyInstance() +{ + rAssert( spInstance != NULL ); + + delete spInstance; + spInstance = NULL; +} + +//============================================================================== +// CardGallery::GetInstance +//============================================================================== +// +// Description: - Access point for the CardGallery singleton. +// - Creates the CardGallery if needed. +// +// Parameters: None. +// +// Return: Pointer to the CardGallery. +// +// Constraints: This is a singleton so only one instance is allowed. +// +//============================================================================== +CardGallery* CardGallery::GetInstance() +{ + rAssert( spInstance != NULL ); + + return spInstance; +} + +//=========================================================================== +// CardGallery::CardGallery +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +CardGallery::CardGallery() +: m_cardsDB( NULL ), + m_numCollectedCards( 0 ) +{ +#ifdef RAD_GAMECUBE + HeapMgr()->PushHeap( GMA_GC_VMM ); +#else + HeapMgr()->PushHeap( GMA_PERSISTENT ); +#endif + + m_cardsDB = new CardsDB(); + rAssert( m_cardsDB ); + +#ifdef RAD_GAMECUBE + HeapMgr()->PopHeap( GMA_GC_VMM ); +#else + HeapMgr()->PopHeap( GMA_PERSISTENT ); +#endif +} + +//=========================================================================== +// CardGallery::~CardGallery +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +CardGallery::~CardGallery() +{ + GetCheatInputSystem()->UnregisterCallback( this ); + + if( m_cardsDB != NULL ) + { + delete m_cardsDB; + m_cardsDB = NULL; + } +} + +//=========================================================================== +// CardGallery::Init +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::Init() +{ + // load cards into database + // + rAssert( m_cardsDB ); + m_cardsDB->LoadCards(); + + // determine number of bytes needed for loading/saving + // + unsigned int numDataBytes = m_cardsDB->GetNumCards() / NUM_BITS_PER_BYTE; + if( m_cardsDB->GetNumCards() % NUM_BITS_PER_BYTE > 0 ) + { + numDataBytes++; // round up number of bytes + } + + // register collected cards data for loading/saving + // + GetGameDataManager()->RegisterGameData( this, numDataBytes, "Card Gallery" ); + + // register callback for "Collect All Cards" cheat + // + GetCheatInputSystem()->RegisterCallback( this ); + +#ifdef DEBUGWATCH + radDbgWatchAddUnsignedInt( &s_wAddCollectedCard, + "Add Collectible Card", + WATCHER_NAMESPACE, + (RADDEBUGWATCH_CALLBACK)AddCardToGallery, + NULL, + 0, + MAX_NUM_CARDS - 1 ); + + radDbgWatchAddFunction( "Add All Collectible Cards", + (RADDEBUGWATCH_CALLBACK)AddAllCardsToGallery, + NULL, + WATCHER_NAMESPACE ); + + radDbgWatchAddFunction( "Remove All Collectible Cards", + (RADDEBUGWATCH_CALLBACK)RemoveAllCardsFromGallery, + NULL, + WATCHER_NAMESPACE ); +#endif +} + +//=========================================================================== +// CardGallery::AddCollectedCardByID +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +Card* +CardGallery::AddCollectedCardByID( unsigned int cardID ) +{ + rAssert( m_cardsDB ); + + // get card by ID from DB, and add it to collected cards + // + Card* collectedCard = m_cardsDB->GetCardByID( cardID ); + if( collectedCard != NULL ) + { + this->AddCollectedCard( collectedCard ); + } + + return collectedCard; +} + +//=========================================================================== +// CardGallery::AddCollectedCardByName +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +Card* +CardGallery::AddCollectedCardByName( tUID cardName ) +{ + rAssert( m_cardsDB ); + + // get card by name from DB, and add it to collected cards + // + Card* collectedCard = m_cardsDB->GetCardByName( cardName ); + if( collectedCard != NULL ) + { + this->AddCollectedCard( collectedCard ); + } + else + { + rAssertMsg( false, "ERROR: *** Card not found!" ); + } + + return collectedCard; +} + +//=========================================================================== +// CardGallery::AddAllCollectedCards +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::AddAllCollectedCards() +{ + for( unsigned int i = 0; i < MAX_NUM_CARDS; i++ ) + { + rAssert( m_cardsDB != NULL ); + Card* card = m_cardsDB->GetCardByID( i ); + if( card != NULL ) + { + this->AddCollectedCard( card ); + } + } +} + +//=========================================================================== +// CardGallery::RemoveAllCollectedCards +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::RemoveAllCollectedCards() +{ + for( unsigned int i = 0; i < NUM_LEVELS; i++ ) + { + m_collectedCards[ i ].Empty(); + } + + m_numCollectedCards = 0; +} + +//=========================================================================== +// CardGallery::GetCollectedCards +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +const CardList* +CardGallery::GetCollectedCards( unsigned int level ) const +{ + rAssert( level < NUM_LEVELS ); + return( &(m_collectedCards[ level ]) ); +} + +//============================================================================= +// CardGallery::IsCardCollected +//============================================================================= +// Description: Comment +// +// Parameters: ( tUID cardName ) +// +// Return: bool +// +//============================================================================= +bool CardGallery::IsCardCollected( tUID cardName ) const +{ + bool cardCollected = false; + + rAssert( m_cardsDB ); + Card* card = m_cardsDB->GetCardByName( cardName ); + if( card != NULL ) + { + int level = card->GetLevel() - 1; + int levelID = card->GetLevelID() - 1; + if( m_collectedCards[ level ].m_cards[ levelID ] != NULL ) + { + cardCollected = true; + } + } + + return cardCollected; +} + +//============================================================================= +// CardGallery::GetNumCardDecksCompleted +//============================================================================= +// Description: Get number of card decks completed. Collecting all cards in +// a given level constitutes a complete deck. +// +// Parameters: none +// +// Return: number of card decks completed +// +//============================================================================= +int CardGallery::GetNumCardDecksCompleted() const +{ + int numDecksCompleted = 0; + + for( unsigned int i = 0; i < NUM_LEVELS; i++ ) + { + if( this->IsCardDeckComplete( i ) ) + { + numDecksCompleted++; + } + } + + return numDecksCompleted; +} + +//============================================================================= +// CardGallery::IsCardDeckComplete +//============================================================================= +// Description: Query whether or not a card deck is complete for a given level. +// +// Parameters: level index +// +// Return: true/false +// +//============================================================================= +bool CardGallery::IsCardDeckComplete( unsigned int level ) const +{ + rAssert( level < NUM_LEVELS ); + + return( m_collectedCards[ level ].m_numCards == static_cast<int>( NUM_CARDS_PER_LEVEL ) ); +} + +//=========================================================================== +// CardGallery::LoadData +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::LoadData( const GameDataByte* dataBuffer, + unsigned int numBytes ) +{ + // remove all collected cards first + // + this->RemoveAllCollectedCards(); + + // add new set of collected cards from loaded data + // + for( unsigned int i = 0; i < numBytes * NUM_BITS_PER_BYTE; i++ ) + { + unsigned int dataBufferIndex = i / NUM_BITS_PER_BYTE; + if( (dataBuffer[ dataBufferIndex ] & (1 << i % NUM_BITS_PER_BYTE)) > 0 ) + { + this->AddCollectedCardByID( i ); + } + } +} + +//=========================================================================== +// CardGallery::SaveData +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::SaveData( GameDataByte* dataBuffer, + unsigned int numBytes ) +{ + if( CommandLineOptions::Get( CLO_MEMCARD_CHEAT ) ) + { + // turn on all bits, and save + // + memset( dataBuffer, ~0, numBytes ); + } + else + { + // clear data buffer first + // + for( unsigned int byteIndex = 0; byteIndex < numBytes; byteIndex++ ) + { + dataBuffer[ byteIndex ] = 0; + } + + // save collected cards using bit-masking algorithm + // + for( unsigned int i = 0; i < NUM_LEVELS; i++ ) + { + for( unsigned int j = 0; j < NUM_CARDS_PER_LEVEL; j++ ) + { + if( m_collectedCards[ i ].m_cards[ j ] != NULL ) + { + unsigned int cardID = m_collectedCards[ i ].m_cards[ j ]->GetID(); + + unsigned int dataBufferIndex = cardID / NUM_BITS_PER_BYTE; + dataBuffer[ dataBufferIndex ] |= (1 << (cardID % NUM_BITS_PER_BYTE)); + } + } + } + } +} + +//=========================================================================== +// CardGallery::OnCheatEntered +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::OnCheatEntered( eCheatID cheatID, bool isEnabled ) +{ + if( cheatID == CHEAT_ID_UNLOCK_CARDS ) + { + // remove all cards from gallery first + // + this->RemoveAllCollectedCards(); + + // now add all collectible cards to gallery + // + this->AddAllCollectedCards(); + } +} + +//=========================================================================== +// Private Member Functions +//=========================================================================== + +//=========================================================================== +// CardGallery::AddCollectedCard +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardGallery::AddCollectedCard( Card* newCard ) +{ + rAssert( newCard != NULL ); + unsigned int level = newCard->GetLevel() - 1; + rAssert( level < NUM_LEVELS ); + m_collectedCards[ level ].Add( newCard ); + + rDebugPrintf( "Card Gallery: Collected Card %d-%d\n", + newCard->GetLevel(), newCard->GetLevelID() ); + + m_numCollectedCards++; +} + diff --git a/game/code/cards/cardgallery.h b/game/code/cards/cardgallery.h new file mode 100644 index 0000000..0cf3d52 --- /dev/null +++ b/game/code/cards/cardgallery.h @@ -0,0 +1,131 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: CardGallery +// +// Description: Interface for the CardGallery class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +#ifndef CARDGALLERY_H +#define CARDGALLERY_H + +//=========================================================================== +// Nested Includes +//=========================================================================== + +#include <cheats/cheatinputsystem.h> + +#include <data/gamedata.h> +#include <p3d/p3dtypes.hpp> + +//=========================================================================== +// Forward References +//=========================================================================== + +const unsigned int NUM_LEVELS = 7; +const unsigned int NUM_CARDS_PER_LEVEL = 7; + +class CardsDB; +class Card; + +struct CardList +{ + Card* m_cards[ NUM_CARDS_PER_LEVEL ]; + int m_numCards; + + CardList(); + + void Add( Card* card ); + bool Remove( unsigned int cardID ); + void Empty(); +}; + +//=========================================================================== +// Interface Definitions +//=========================================================================== + +class CardGallery : public GameDataHandler, + public ICheatEnteredCallback +{ +public: + // Static Methods for accessing this singleton. + static CardGallery* CreateInstance(); + static void DestroyInstance(); + static CardGallery* GetInstance(); + + CardGallery(); + virtual ~CardGallery(); + + // Initialization (involves disc I/O) + void Init(); + + // Adding collected cards (either by UID name or by card ID) + Card* AddCollectedCardByName( tUID cardName ); + Card* AddCollectedCardByID( unsigned int cardID ); + + void AddAllCollectedCards(); + void RemoveAllCollectedCards(); + + // Querying collected cards + const CardList* GetCollectedCards( unsigned int level ) const; + bool IsCardCollected( tUID cardName ) const; + + // Querying card decks + // + int GetNumCardDecksCompleted() const; + bool IsCardDeckComplete( unsigned int level ) const; + + // Querying cards DB + CardsDB* GetCardsDB() const { return m_cardsDB; } + + // Implements Game Data Handler + virtual void LoadData( const GameDataByte* dataBuffer, + unsigned int numBytes ); + virtual void SaveData( GameDataByte* dataBuffer, + unsigned int numBytes ); + virtual void ResetData(); + + virtual void OnCheatEntered( eCheatID cheatID, bool isEnabled ); + +private: + + //--------------------------------------------------------------------- + // Private Functions + //--------------------------------------------------------------------- + + // No copying or assignment. Declare but don't define. + // + CardGallery( const CardGallery& ); + CardGallery& operator= ( const CardGallery& ); + + void AddCollectedCard( Card* newCard ); + + //--------------------------------------------------------------------- + // Private Data + //--------------------------------------------------------------------- + + // Pointer to the one and only instance of this singleton. + static CardGallery* spInstance; + + CardsDB* m_cardsDB; + + CardList m_collectedCards[ NUM_LEVELS ]; + int m_numCollectedCards; + +}; + +// A little syntactic sugar for getting at this singleton. +inline CardGallery* GetCardGallery() { return( CardGallery::GetInstance() ); } + +inline void CardGallery::ResetData() +{ + this->RemoveAllCollectedCards(); +} + +#endif // CARDGALLERY_H diff --git a/game/code/cards/cards.h b/game/code/cards/cards.h new file mode 100644 index 0000000..0e2e5a4 --- /dev/null +++ b/game/code/cards/cards.h @@ -0,0 +1,124 @@ +//=========================================================================== +// Copyright (C) 2002 Radical Entertainment Ltd. All rights reserved. +// +// Component: Cards +// +// Description: Collector Cards Database +// +// Authors: Tony Chu (and Simpsons2 Designers) +// +// Revisions Date Author Revision +// 2002/08/14 TChu Created for SRR2 +// +//=========================================================================== + +#ifndef CARDS_H +#define CARDS_H + +//=========================================================================== +// Nested Includes +//=========================================================================== + +#include <cards/card.h> + +struct CardData +{ + char name[ 32 ]; + unsigned short level; + unsigned short levelID; + unsigned short imageID; + eCardType type; + eQuoteID quotes[ MAX_NUM_QUOTES ]; +}; + +//=========================================================================== +// Cards Database +//=========================================================================== + +static const CardData s_cardsDB[] = +{ + // SYNTAX: { <Card Name>, <Card Level>, <Card Level ID>, <Card Image ID>, <Card Type> }, + // + // - <Card Name> is the card name (max. 31 characters) + // - <Card Level> is the card level (1-7) + // - <Card Level ID> is the card level ID + // - <Card Image ID> is the ID reference for the associated Scrooby image + // - <Card Type> is the card type (either COLLECTOR_CARD or BONUS_CARD) + // + +/// Level 1 +// + { "card11", 1, 1, 0, COLLECTOR_CARD, { QUOTE_LENNY, QUOTE_CARL, EMPTY_QUOTE } }, + { "card12", 1, 2, 1, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card13", 1, 3, 2, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card14", 1, 4, 3, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card15", 1, 5, 4, COLLECTOR_CARD, { QUOTE_HOMER, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card16", 1, 6, 5, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card17", 1, 7, 6, COLLECTOR_CARD, { QUOTE_MR_SPARKLE, EMPTY_QUOTE, EMPTY_QUOTE } }, +// +/// Level 2 +// + { "card21", 2, 1, 8, COLLECTOR_CARD, { QUOTE_JIMBO, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card22", 2, 2, 9, COLLECTOR_CARD, { QUOTE_WIGGUM, QUOTE_JASPER, EMPTY_QUOTE } }, + { "card23", 2, 3, 10, COLLECTOR_CARD, { QUOTE_BART, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card24", 2, 4, 11, COLLECTOR_CARD, { QUOTE_SKINNER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card25", 2, 5, 12, COLLECTOR_CARD, { QUOTE_LISA, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card26", 2, 6, 13, COLLECTOR_CARD, { QUOTE_MILHOUSE, QUOTE_BART, EMPTY_QUOTE } }, + { "card27", 2, 7, 14, COLLECTOR_CARD, { QUOTE_BART, EMPTY_QUOTE, EMPTY_QUOTE } }, +// +/// Level 3 +// + { "card31", 3, 1, 16, COLLECTOR_CARD, { QUOTE_LISA, QUOTE_BROCKMAN, EMPTY_QUOTE } }, + { "card32", 3, 2, 17, COLLECTOR_CARD, { QUOTE_BART, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card33", 3, 3, 18, COLLECTOR_CARD, { QUOTE_LISA, QUOTE_STACY, EMPTY_QUOTE } }, + { "card34", 3, 4, 19, COLLECTOR_CARD, { QUOTE_RALPH, QUOTE_LISA, EMPTY_QUOTE } }, + { "card35", 3, 5, 20, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card36", 3, 6, 21, COLLECTOR_CARD, { QUOTE_DR_WOLFF, QUOTE_LISA, EMPTY_QUOTE } }, + { "card37", 3, 7, 22, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, +// +/// Level 4 +// + { "card41", 4, 1, 24, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card42", 4, 2, 25, COLLECTOR_CARD, { QUOTE_BURNS, QUOTE_MARGE, EMPTY_QUOTE } }, + { "card43", 4, 3, 26, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card44", 4, 4, 27, COLLECTOR_CARD, { QUOTE_HOMER, QUOTE_MARGE, EMPTY_QUOTE } }, + { "card45", 4, 5, 28, COLLECTOR_CARD, { QUOTE_GIL, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card46", 4, 6, 29, COLLECTOR_CARD, { QUOTE_HOMER, QUOTE_PHOTOGRAPHER, EMPTY_QUOTE } }, + { "card47", 4, 7, 30, COLLECTOR_CARD, { QUOTE_MARGE, QUOTE_HOMER, EMPTY_QUOTE } }, +// +/// Level 5 +// + { "card51", 5, 1, 32, COLLECTOR_CARD, { QUOTE_LISA, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card52", 5, 2, 33, COLLECTOR_CARD, { QUOTE_BROCKMAN, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card53", 5, 3, 34, COLLECTOR_CARD, { QUOTE_APU, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card54", 5, 4, 35, COLLECTOR_CARD, { QUOTE_MANJULA, QUOTE_HOMER, EMPTY_QUOTE } }, + { "card55", 5, 5, 36, COLLECTOR_CARD, { QUOTE_APU, QUOTE_MANJULA, EMPTY_QUOTE } }, + { "card56", 5, 6, 37, COLLECTOR_CARD, { QUOTE_BART, QUOTE_OTTO, EMPTY_QUOTE } }, + { "card57", 5, 7, 38, COLLECTOR_CARD, { QUOTE_APU, QUOTE_HOMER, EMPTY_QUOTE } }, +// +/// Level 6 +// + { "card61", 6, 1, 40, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card62", 6, 2, 41, COLLECTOR_CARD, { QUOTE_CHILD, QUOTE_MOTHER, EMPTY_QUOTE } }, + { "card63", 6, 3, 42, COLLECTOR_CARD, { QUOTE_KRUSTY, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card64", 6, 4, 43, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card65", 6, 5, 44, COLLECTOR_CARD, { QUOTE_MEYERS, QUOTE_ANNOUNCER, EMPTY_QUOTE } }, + { "card66", 6, 6, 45, COLLECTOR_CARD, { QUOTE_KRUSTY, QUOTE_ANNOUNCER, EMPTY_QUOTE } }, + { "card67", 6, 7, 46, COLLECTOR_CARD, { QUOTE_BART, EMPTY_QUOTE, EMPTY_QUOTE } }, +// +/// Level 7 +// + { "card71", 7, 1, 48, COLLECTOR_CARD, { QUOTE_BURNS, QUOTE_SMITHERS, EMPTY_QUOTE } }, + { "card72", 7, 2, 49, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card73", 7, 3, 50, COLLECTOR_CARD, { QUOTE_MARGE, QUOTE_KANG, EMPTY_QUOTE } }, + { "card74", 7, 4, 51, COLLECTOR_CARD, { QUOTE_WILLIE, QUOTE_MAGGIE, EMPTY_QUOTE } }, + { "card75", 7, 5, 52, COLLECTOR_CARD, { QUOTE_LISA, QUOTE_MARGE, EMPTY_QUOTE } }, + { "card76", 7, 6, 53, COLLECTOR_CARD, { QUOTE_HOMER, EMPTY_QUOTE, EMPTY_QUOTE } }, + { "card77", 7, 7, 54, COLLECTOR_CARD, { QUOTE_MARGE, QUOTE_HOMER, EMPTY_QUOTE } }, +// +}; + +static const unsigned int s_numCardsInDB = sizeof( s_cardsDB ) / sizeof( s_cardsDB[ 0 ] ); + + +#endif // CARDS_H diff --git a/game/code/cards/cardsdb.cpp b/game/code/cards/cardsdb.cpp new file mode 100644 index 0000000..704fa60 --- /dev/null +++ b/game/code/cards/cardsdb.cpp @@ -0,0 +1,218 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: CardsDB +// +// Description: Implementation of the CardsDB class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +//=========================================================================== +// Includes +//=========================================================================== +#include <cards/cardsdb.h> +#include <cards/collectorcard.h> +#include <cards/bonuscard.h> + +// cards database header file +#include <cards/cards.h> + +#include <memory/srrmemory.h> + +#include <p3d/entity.hpp> + +//=========================================================================== +// Local Constants +//=========================================================================== + +//=========================================================================== +// Public Member Functions +//=========================================================================== + +//=========================================================================== +// CardsDB::CardsDB +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +CardsDB::CardsDB() +: m_cards( NULL ), + m_numCards( 0 ) +{ +MEMTRACK_PUSH_GROUP( "CardsDB" ); + + #ifdef RAD_GAMECUBE + HeapMgr()->PushHeap( GMA_GC_VMM ); + #else + HeapMgr()->PushHeap( GMA_PERSISTENT ); + #endif + + m_cards = new Card*[ MAX_NUM_CARDS ]; + rAssert( m_cards ); + + for( unsigned int i = 0; i < MAX_NUM_CARDS; i++ ) + { + m_cards[ i ] = NULL; + } + + #ifdef RAD_GAMECUBE + HeapMgr()->PopHeap( GMA_GC_VMM ); + #else + HeapMgr()->PopHeap( GMA_PERSISTENT ); + #endif +MEMTRACK_POP_GROUP( "CardsDB" ); +} + +//=========================================================================== +// CardsDB::~CardsDB +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +CardsDB::~CardsDB() +{ + // Clean-up cards DB memory + // + if( m_cards != NULL ) + { + for( unsigned int i = 0; i < MAX_NUM_CARDS; i++ ) + { + if( m_cards[ i ] != NULL ) + { + delete m_cards[ i ]; + m_cards[ i ] = NULL; + } + } + + delete [] m_cards; + m_cards = NULL; + } +} + +//=========================================================================== +// CardsDB::LoadCards +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +void +CardsDB::LoadCards() +{ + // load cards from memory (static array in Cards.h header file) + // + for( unsigned int i = 0; i < s_numCardsInDB; i++ ) + { + int cardID = s_cardsDB[ i ].imageID; + + if( s_cardsDB[ i ].type == COLLECTOR_CARD ) + { + // create new collector card + // + m_cards[ cardID ] = new CollectorCard( cardID, + s_cardsDB[ i ].level, + s_cardsDB[ i ].levelID, + tEntity::MakeUID( s_cardsDB[ i ].name ), + s_cardsDB[ i ].quotes, + MAX_NUM_QUOTES ); + } + else if( s_cardsDB[ i ].type == BONUS_CARD ) + { + // create new bonus card + // + m_cards[ cardID ] = new BonusCard( cardID, + s_cardsDB[ i ].level, + s_cardsDB[ i ].levelID, + tEntity::MakeUID( s_cardsDB[ i ].name ), + s_cardsDB[ i ].quotes, + MAX_NUM_QUOTES ); + } + else + { + rAssertMsg( 0, "ERROR: *** Invalid card type in database file!\n" ); + } + + m_numCards++; + } +} + +//=========================================================================== +// CardsDB::GetCardByID +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +Card* +CardsDB::GetCardByID( unsigned int cardID ) +{ + rAssert( cardID < MAX_NUM_CARDS ); + + return m_cards[ cardID ]; +} + +//=========================================================================== +// CardsDB::GetCardByName +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +Card* +CardsDB::GetCardByName( tUID cardName ) +{ + Card* card = NULL; + + // search for card with cardName + for( unsigned int i = 0; i < MAX_NUM_CARDS; i++ ) + { + if( m_cards[ i ] != NULL ) + { + if( m_cards[ i ]->GetCardName() == cardName ) + { + // found it! + card = m_cards[ i ]; + break; + } + } + } + + return card; +} + +//=========================================================================== +// Private Member Functions +//=========================================================================== + diff --git a/game/code/cards/cardsdb.h b/game/code/cards/cardsdb.h new file mode 100644 index 0000000..5620eb9 --- /dev/null +++ b/game/code/cards/cardsdb.h @@ -0,0 +1,71 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: CardsDB +// +// Description: Interface for the CardsDB class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +#ifndef CARDSDB_H +#define CARDSDB_H + +//=========================================================================== +// Nested Includes +//=========================================================================== + +#include <p3d/p3dtypes.hpp> + +//=========================================================================== +// Forward References +//=========================================================================== + +const unsigned int MAX_NUM_CARDS = 64; + +class Card; + +//=========================================================================== +// Interface Definitions +//=========================================================================== + +class CardsDB +{ +public: + CardsDB(); + virtual ~CardsDB(); + + // Load cards from config file into DB + void LoadCards(); + + // Accessing cards DB + Card* GetCardByID( unsigned int cardID ); + Card* GetCardByName( tUID cardName ); + + int GetNumCards() const { return m_numCards; } + +private: + + //--------------------------------------------------------------------- + // Private Functions + //--------------------------------------------------------------------- + + // No copying or assignment. Declare but don't define. + // + CardsDB( const CardsDB& ); + CardsDB& operator= ( const CardsDB& ); + + //--------------------------------------------------------------------- + // Private Data + //--------------------------------------------------------------------- + + Card** m_cards; + int m_numCards; + +}; + +#endif // CARDSDB_H diff --git a/game/code/cards/collectorcard.cpp b/game/code/cards/collectorcard.cpp new file mode 100644 index 0000000..7b6ae27 --- /dev/null +++ b/game/code/cards/collectorcard.cpp @@ -0,0 +1,72 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: CollectorCard +// +// Description: Implementation of the CollectorCard class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +//=========================================================================== +// Includes +//=========================================================================== +#include <cards/collectorcard.h> + +//=========================================================================== +// Local Constants +//=========================================================================== + +//=========================================================================== +// Public Member Functions +//=========================================================================== + +//=========================================================================== +// CollectorCard::CollectorCard +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +CollectorCard::CollectorCard +( + unsigned int ID, + unsigned int level, + unsigned int levelID, + tUID cardName, + const eQuoteID* quotes, + int numQuotes +) +: Card( ID, level, levelID, cardName, quotes, numQuotes ) +{ +} + +//=========================================================================== +// CollectorCard::~CollectorCard +//=========================================================================== +// Description: +// +// Constraints: None. +// +// Parameters: None. +// +// Return: +// +//=========================================================================== +CollectorCard::~CollectorCard() +{ +} + +//=========================================================================== +// Private Member Functions +//=========================================================================== + diff --git a/game/code/cards/collectorcard.h b/game/code/cards/collectorcard.h new file mode 100644 index 0000000..e04c48c --- /dev/null +++ b/game/code/cards/collectorcard.h @@ -0,0 +1,63 @@ +//=========================================================================== +// Copyright (C) 2000 Radical Entertainment Ltd. All rights reserved. +// +// Component: CollectorCard +// +// Description: Interface for the CollectorCard class. +// +// Authors: Tony Chu +// +// Revisions Date Author Revision +// 2002/08/06 TChu Created for SRR2 +// +//=========================================================================== + +#ifndef COLLECTORCARD_H +#define COLLECTORCARD_H + +//=========================================================================== +// Nested Includes +//=========================================================================== + +#include <cards/card.h> + +//=========================================================================== +// Forward References +//=========================================================================== + +//=========================================================================== +// Interface Definitions +//=========================================================================== + +class CollectorCard : public Card +{ +public: + CollectorCard( unsigned int ID, + unsigned int level, + unsigned int levelID, + tUID cardName, + const eQuoteID* quotes, + int numQuotes ); + + virtual ~CollectorCard(); + + virtual eCardType GetType() const { return COLLECTOR_CARD; } + +private: + + //--------------------------------------------------------------------- + // Private Functions + //--------------------------------------------------------------------- + + // No copying or assignment. Declare but don't define. + // + CollectorCard( const CollectorCard& ); + CollectorCard& operator= ( const CollectorCard& ); + + //--------------------------------------------------------------------- + // Private Data + //--------------------------------------------------------------------- + +}; + +#endif // COLLECTORCARD_H |