| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: SalvageCrateCollide.cpp ///////////////////////////////////////////////////////////////////////
- // Author: Graham Smallwood, March 2002
- // Desc: The Savlage system can give a Weaponset bonus, a level, or money. Salvagers create them
- // by killing marked units, and only WeaponSalvagers can get the WeaponSet bonus
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "GameLogic/Module/SalvageCrateCollide.h"
- #include "Common/AudioEventRTS.h"
- #include "Common/MiscAudio.h"
- #include "Common/Kindof.h"
- #include "Common/RandomValue.h"
- #include "Common/Player.h"
- #include "Common/ThingTemplate.h"
- #include "Common/Xfer.h"
- #include "GameClient/GameText.h"
- #include "GameClient/InGameUI.h"
- #include "GameLogic/ExperienceTracker.h"
- #include "GameLogic/Object.h"
- //-------------------------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------------------------
- SalvageCrateCollide::SalvageCrateCollide( Thing *thing, const ModuleData* moduleData ) : CrateCollide( thing, moduleData )
- {
- }
- //-------------------------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------------------------
- SalvageCrateCollide::~SalvageCrateCollide( void )
- {
- }
- //-------------------------------------------------------------------------------------------------
- Bool SalvageCrateCollide::isValidToExecute( const Object *other ) const
- {
- if( ! CrateCollide::isValidToExecute( other ) )
- return FALSE;
- // Only salvage units can pick up a Salvage crate
- if( ! other->getTemplate()->isKindOf( KINDOF_SALVAGER ) )
- return FALSE;
- return TRUE;
- }
- //-------------------------------------------------------------------------------------------------
- Bool SalvageCrateCollide::executeCrateBehavior( Object *other )
- {
- if( eligibleForWeaponSet( other ) && testWeaponChance() )
- {
- doWeaponSet( other );
- //Play the salvage installation crate pickup sound.
- AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_crateSalvage;
- soundToPlay.setObjectID( other->getID() );
- TheAudio->addAudioEvent( &soundToPlay );
-
- //Play the unit voice acknowledgement for upgrading weapons.
- //Already handled by the "move order"
- //const AudioEventRTS *soundToPlayPtr = other->getTemplate()->getPerUnitSound( "VoiceSalvage" );
- //soundToPlay = *soundToPlayPtr;
- //soundToPlay.setObjectID( other->getID() );
- //TheAudio->addAudioEvent( &soundToPlay );
- }
- else if( eligibleForLevel( other ) && testLevelChance() )
- {
- doLevelGain( other );
-
- //Sound will play in
- //soundToPlay = TheAudio->getMiscAudio()->m_unitPromoted;
- }
- else // just assume the testMoneyChance
- {
- doMoney( other );
- AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_crateMoney;
- soundToPlay.setObjectID( other->getID() );
- TheAudio->addAudioEvent(&soundToPlay);
- }
- return TRUE;
- }
- // ------------------------------------------------------------------------------------------------
- Bool SalvageCrateCollide::eligibleForWeaponSet( Object *other )
- {
- if( other == NULL )
- return FALSE;
- // A kindof marks eligibility, and you must not be fully upgraded
- if( !other->isKindOf(KINDOF_WEAPON_SALVAGER) )
- return FALSE;
- if( other->testWeaponSetFlag(WEAPONSET_CRATEUPGRADE_TWO) )
- return FALSE;
- return TRUE;
- }
- // ------------------------------------------------------------------------------------------------
- Bool SalvageCrateCollide::eligibleForLevel( Object *other )
- {
- if( other == NULL )
- return FALSE;
- // Sorry, you are max level
- if( other->getExperienceTracker()->getVeterancyLevel() == LEVEL_HEROIC )
- return FALSE;
-
- // Sorry, you can't gain levels
- if( !other->getExperienceTracker()->isTrainable() )
- return FALSE;
- return TRUE;
- }
- // ------------------------------------------------------------------------------------------------
- Bool SalvageCrateCollide::testWeaponChance()
- {
- const SalvageCrateCollideModuleData *md = getSalvageCrateCollideModuleData();
- if( md->m_weaponChance == 1.0f )
- return TRUE; // don't waste a random number for a 100%
- Real randomNumber = GameLogicRandomValueReal( 0, 1 );
- if( randomNumber < md->m_weaponChance )
- return TRUE;
- return FALSE;
- }
- Bool SalvageCrateCollide::testLevelChance()
- {
- const SalvageCrateCollideModuleData *md = getSalvageCrateCollideModuleData();
- if( md->m_levelChance == 1.0f )
- return TRUE; // don't waste a random number for a 100%
- Real randomNumber = GameLogicRandomValueReal( 0, 1 );
- if( randomNumber < md->m_levelChance )
- return TRUE;
- return FALSE;
- }
- void SalvageCrateCollide::doWeaponSet( Object *other )
- {
- if( other->testWeaponSetFlag( WEAPONSET_CRATEUPGRADE_ONE ) )
- {
- other->clearWeaponSetFlag( WEAPONSET_CRATEUPGRADE_ONE );
- other->setWeaponSetFlag( WEAPONSET_CRATEUPGRADE_TWO );
- }
- else
- {
- other->setWeaponSetFlag( WEAPONSET_CRATEUPGRADE_ONE );
- }
- }
- void SalvageCrateCollide::doLevelGain( Object *other )
- {
- other->getExperienceTracker()->gainExpForLevel( 1 );
- }
- void SalvageCrateCollide::doMoney( Object *other )
- {
- const SalvageCrateCollideModuleData *md = getSalvageCrateCollideModuleData();
- Int money;
- if( md->m_minimumMoney != md->m_maximumMoney )// Random value doesn't like to get a constant range
- money = GameLogicRandomValue( md->m_minimumMoney, md->m_maximumMoney );
- else
- money = md->m_minimumMoney;
- if( money > 0 )
- {
- other->getControllingPlayer()->getMoney()->deposit( money );
- other->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( money );
-
- //Display cash income floating over the crate. Position is me, everything else is them.
- UnicodeString moneyString;
- moneyString.format( TheGameText->fetch( "GUI:AddCash" ), money );
- Coord3D pos;
- pos.set( getObject()->getPosition() );
- pos.z += 10.0f; //add a little z to make it show up above the unit.
- Color color = other->getControllingPlayer()->getPlayerColor() | GameMakeColor( 0, 0, 0, 230 );
- TheInGameUI->addFloatingText( moneyString, &pos, color );
- }
- }
- // ------------------------------------------------------------------------------------------------
- /** CRC */
- // ------------------------------------------------------------------------------------------------
- void SalvageCrateCollide::crc( Xfer *xfer )
- {
- // extend base class
- CrateCollide::crc( xfer );
- } // end crc
- // ------------------------------------------------------------------------------------------------
- /** Xfer method
- * Version Info:
- * 1: Initial version */
- // ------------------------------------------------------------------------------------------------
- void SalvageCrateCollide::xfer( Xfer *xfer )
- {
- // version
- XferVersion currentVersion = 1;
- XferVersion version = currentVersion;
- xfer->xferVersion( &version, currentVersion );
- // extend base class
- CrateCollide::xfer( xfer );
- } // end xfer
- // ------------------------------------------------------------------------------------------------
- /** Load post process */
- // ------------------------------------------------------------------------------------------------
- void SalvageCrateCollide::loadPostProcess( void )
- {
- // extend base class
- CrateCollide::loadPostProcess();
- } // end loadPostProcess
|