EXPORT_C void CHarvesterEventManager::IncreaseItemCount( 
		HarvesterEventObserverType aHEObserverType, TUint aCount )
	{
	TEventStatus* eventStatus = GetEventStatus( aHEObserverType );
	WRITELOG2( "CHarvesterEventManager::IncreaseItemCount(%d) type = %d", aCount, aHEObserverType); 
	
#ifdef _DEBUG
	switch(aHEObserverType)
	    {
	    case EHEObserverTypePlaceholder:
	        {
	        WRITELOG( "CHarvesterEventManager::IncreaseItemCount() EHEObserverTypePlaceholder");
	        OstTrace0( TRACE_NORMAL, CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount EHEObserverTypePlaceholder" );	        
	        break;
	        }	        
	    case EHEObserverTypeMMC:
	        {
	        WRITELOG( "CHarvesterEventManager::IncreaseItemCount() EHEObserverTypeMMC");
	        OstTrace0( TRACE_NORMAL, DUP1_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount EHEObserverTypeMMC" );	        
	        break;
	        }
	    case EHEObserverTypeOverall:
	        {
	        WRITELOG( "CHarvesterEventManager::IncreaseItemCount() EHEObserverTypeOverall");
	        OstTrace0( TRACE_NORMAL, DUP2_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount EHEObserverTypeOverall" );	        
	        break;
	        }
	    default:
	        {
	        WRITELOG( "CHarvesterEventManager::IncreaseItemCount() Unknown type!");
	        OstTrace0( TRACE_NORMAL, DUP3_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount Unknown type!" );
	        }
	    };
#endif
	
	if( eventStatus )
		{
		WRITELOG1( "CHarvesterEventManager::IncreaseItemCount() itemsleft = %d old ", eventStatus->iItemsLeft);
		OstTrace1( TRACE_NORMAL, DUP4_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount) itemsleft = %d old", eventStatus->iItemsLeft );
		
		eventStatus->iItemsLeft += aCount;
		WRITELOG1( "CHarvesterEventManager::IncreaseItemCount() itemsleft = %d ", eventStatus->iItemsLeft);
		OstTrace1( TRACE_NORMAL, DUP5_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount itemsleft = %d", eventStatus->iItemsLeft );
		
		}
	else
		{
		TEventStatus eventStatus;
		eventStatus.iCurrentState = EHEStateStarted;
		WRITELOG1( "CHarvesterEventManager::IncreaseItemCount() itemsleft = %d old", aCount);
		OstTrace1( TRACE_NORMAL, DUP6_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount itemsleft = %d old", aCount );
		
		eventStatus.iItemsLeft = aCount;
		WRITELOG1( "CHarvesterEventManager::IncreaseItemCount() itemsleft = %d ", aCount);
		OstTrace1( TRACE_NORMAL, DUP7_CHARVESTEREVENTMANAGER_INCREASEITEMCOUNT, "CHarvesterEventManager::IncreaseItemCount itemsleft = %d", aCount );
		
		eventStatus.iObserverType = aHEObserverType;
		iEventStatuses.Append( eventStatus );
		}
	}
Esempio n. 2
0
/*
* This is used to spawn creatures
*/
void TowerDefenseInstanceScript::TowerDefenseMapInstanceScript::OnUpdate(uint32 const diff)
{
    if(GetEventStatus() < TD_EVENT_STATUS_RUNNING) // if wave is not running
        return;

    Events.Update(diff);

    Player* player = GetPlayer();
    if(!player)
        return;
    while (uint32 eventId = Events.ExecuteEvent())
    {
        switch (eventId)
        {

        case TD_EVENT_DATA_START_MUSIC_TIMER: // this is just some event music to make it feel alive.
            {
                Events.RescheduleEvent(TD_EVENT_DATA_START_MUSIC_TIMER, 240000); // repeat every 4 min, length of track
            }
            break;
        case TD_EVENT_DATA_START_WAVE_TIMER:
            {
                switch(CountDown)
                {
                case 0:
                    player->PlayDirectSound(TD_STARTWAVE_MUSIC,player);
                    SendMessageToPlayer(TD_SYSTEM_MSG_WAVE_STARTING_IN,3);
                    Events.RescheduleEvent(TD_EVENT_DATA_START_WAVE_TIMER, 1000);
                    ++CountDown;
                    break;

                case 1:
                    SendMessageToPlayer(TD_SYSTEM_MSG_WAVE_STARTING,2);
                    Events.RescheduleEvent(TD_EVENT_DATA_START_WAVE_TIMER, 1000);
                    ++CountDown;
                    break;

                case 2:
                    player->PlayDirectSound(TD_STARTWAVE_MUSIC,player);
                    SendMessageToPlayer(TD_SYSTEM_MSG_WAVE_STARTING,1);
                    Events.CancelEvent(TD_EVENT_DATA_START_WAVE_TIMER);
                    Events.ScheduleEvent(TD_EVENT_DATA_START_WAVE_MODE, 1000);
                    ++CountDown;
                    break;
                }
            }
            break;
        case TD_EVENT_DATA_START_WAVE_MODE:
            {
                CountDown = 0;
                SetEventStatus(TD_EVENT_STATUS_LOADING); // set wave status to running so the boss npc can start spawning
                SendMessageToPlayer(TD_SYSTEM_MSG_WAVE_STARTING_GO);
                Events.CancelEvent(TD_EVENT_DATA_START_WAVE_MODE);
                RecordLog("TowerDefense: Wave Id: [%u] is now running.", GetCurrentWaveId());
            }
            break;
        }
    }
}
EXPORT_C TUint CHarvesterEventManager::ItemCount( 
		HarvesterEventObserverType aHEObserverType )
	{
	TEventStatus* eventStatus = GetEventStatus( aHEObserverType );
	if( eventStatus )
		{
		return eventStatus->iItemsLeft;
		}
	
	return 0;
	}
EXPORT_C TInt CHarvesterEventManager::SendEventL( 
		HarvesterEventObserverType aHEObserverType,
		HarvesterEventState aHEState, TUint aItemsLeft )
	{
	TEventStatus* eventStatus = GetEventStatus( aHEObserverType );
	if( eventStatus )
		{
		eventStatus->iCurrentState = aHEState;
		}

	THarvesterEventNotification notification;
	notification.iObserverType = aHEObserverType;
	notification.iCurrentState = aHEState;
	notification.iItemsLeft = aItemsLeft;

	TInt err = KErrNone;
	TInt count = iRegisteredObservers.Count();
	for ( TInt i = count; --i >= 0; )
		{
		THarvesterEventObserverInfo& observer = *(iRegisteredObservers[i]);

		if( CheckObserverType( observer.iObserverType, aHEObserverType ) )
			{
			notification.iObserverId = observer.iObserverId;

			THarvesterEventQueue& eventQueue = *(observer.iQueuePtr);
			TInt sendErr = eventQueue.Send( notification );
			// Take first error
			if( err == KErrNone )
				{
				err = sendErr;
				}
			}
		}
	return err;
	}
EXPORT_C TBool CHarvesterEventManager::DecreaseItemCountL( 
		HarvesterEventObserverType aHEObserverType, TUint aCount )
	{
	TEventStatus* eventStatus = GetEventStatus( aHEObserverType );
	WRITELOG2( "CHarvesterEventManager::DecreaseItemCountL(%d) type = %d ", aCount, aHEObserverType);
	
#ifdef _DEBUG
    switch(aHEObserverType)
        {
        case EHEObserverTypePlaceholder:
            {
            WRITELOG( "CHarvesterEventManager::DecreaseItemCountL() EHEObserverTypePlaceholder");
            OstTrace0( TRACE_NORMAL, CHARVESTEREVENTMANAGER_DECREASEITEMCOUNTL, "CHarvesterEventManager::DecreaseItemCountL EHEObserverTypePlaceholder" );            
            break;
            }
        case EHEObserverTypeMMC:
            {
            WRITELOG( "CHarvesterEventManager::DecreaseItemCountL() EHEObserverTypeMMC");
            OstTrace0( TRACE_NORMAL, DUP1_CHARVESTEREVENTMANAGER_DECREASEITEMCOUNTL, "CHarvesterEventManager::DecreaseItemCountL EHEObserverTypeMMC" );            
            break;
            }
        case EHEObserverTypeOverall:
            {
            WRITELOG( "CHarvesterEventManager::DecreaseItemCountL() EHEObserverTypeOverall");
            OstTrace0( TRACE_NORMAL, DUP2_CHARVESTEREVENTMANAGER_DECREASEITEMCOUNTL, "CHarvesterEventManager::DecreaseItemCountL EHEObserverTypeOverall" );            
            break;
            }
        default:
            {
            WRITELOG( "CHarvesterEventManager::DecreaseItemCountL() Unknown type!");
            OstTrace0( TRACE_NORMAL, DUP3_CHARVESTEREVENTMANAGER_DECREASEITEMCOUNTL, "CHarvesterEventManager::DecreaseItemCountL Unknown type!" );
            }
        };
#endif
	
	if( eventStatus )
		{
		WRITELOG1( "CHarvesterEventManager::DecreaseItemCountL() iItemsLeft = %d old", eventStatus->iItemsLeft);
		OstTrace1( TRACE_NORMAL, DUP4_CHARVESTEREVENTMANAGER_DECREASEITEMCOUNTL, "CHarvesterEventManager::DecreaseItemCountL iItemsLeft = %d old", eventStatus->iItemsLeft );
		
		TUint newCount = eventStatus->iItemsLeft - aCount;

		// check for wrap
		if( newCount > eventStatus->iItemsLeft )
			{
			newCount = 0;
			}

		// event doesn't need to be sent, if count hasn't changed 
		if( newCount == eventStatus->iItemsLeft )
			{
			return EFalse;
			}

		eventStatus->iItemsLeft = newCount;
		}
	else
		{
		return EFalse;
		}

	WRITELOG1( "CHarvesterEventManager::DecreaseItemCountL() iItemsLeft = %d", eventStatus->iItemsLeft );
	OstTrace1( TRACE_NORMAL, DUP5_CHARVESTEREVENTMANAGER_DECREASEITEMCOUNTL, "CHarvesterEventManager::DecreaseItemCountL iItemsLeft = %d", eventStatus->iItemsLeft );
	
	// send finished event to all matching observers
	if ( eventStatus->iItemsLeft <= 0 )
		{
		eventStatus->iItemsLeft = 0;
		eventStatus->iCurrentState = EHEStateFinished;

		// EHEObserverTypeOverall state is handled directly in harvesterao during harvesting
        if( aHEObserverType != EHEObserverTypeOverall )
		    {
		    const TInt err = SendEventL( aHEObserverType, eventStatus->iCurrentState, eventStatus->iItemsLeft );
		    return err == KErrNone;
		    }
		}

	// still harvesting
	eventStatus->iCurrentState = EHEStateHarvesting;
	
	// send harvesting event to all matching observers
	TBool wasSent = EFalse;
	TInt count = iRegisteredObservers.Count();
	for ( TInt i = count; --i >= 0; )
		{
		THarvesterEventObserverInfo& observer = *(iRegisteredObservers[i]);

		if( CheckObserverType( observer.iObserverType, aHEObserverType ) )
			{
			observer.iDelta += aCount;

			// observers interval full
			if ( observer.iDelta >= observer.iNotificationInterval )
				{
				TInt err = SendSingleEvent( observer, aHEObserverType, 
						eventStatus->iCurrentState, eventStatus->iItemsLeft );
				if ( err == KErrNone )
					{
					wasSent = ETrue;
					}
				}
			}
		}

	return wasSent;
	}