Example #1
0
//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
void CBaseAnimatingOverlay::SetLayerPriority( int iLayer, int iPriority )
{
	if (!IsValidLayer( iLayer ))
	{
		return;
	}

	if (m_AnimOverlay[iLayer].m_nPriority == iPriority)
	{
		return;
	}

	// look for an open slot and for existing layers that are lower priority
	int i;
	for (i = 0; i < m_AnimOverlay.Count(); i++)
	{
		if ( m_AnimOverlay[i].IsActive() )
		{
			if (m_AnimOverlay[i].m_nOrder > m_AnimOverlay[iLayer].m_nOrder)
			{
				m_AnimOverlay[i].m_nOrder--;
			}
		}
	}

	int iNewOrder = 0;
	for (i = 0; i < m_AnimOverlay.Count(); i++)
	{
		if ( i != iLayer && m_AnimOverlay[i].IsActive() )
		{
			if (m_AnimOverlay[i].m_nPriority <= iPriority)
			{
				iNewOrder = MAX( iNewOrder, m_AnimOverlay[i].m_nOrder + 1 );
			}
		}
	}

	for (i = 0; i < m_AnimOverlay.Count(); i++)
	{
		if ( i != iLayer && m_AnimOverlay[i].IsActive() )
		{
			if ( m_AnimOverlay[i].m_nOrder >= iNewOrder)
			{
				m_AnimOverlay[i].m_nOrder++;
			}
		}
	}

	m_AnimOverlay[iLayer].m_nOrder = iNewOrder;
	m_AnimOverlay[iLayer].m_nPriority = iPriority;
	m_AnimOverlay[iLayer].MarkActive( );

	VerifyOrder();

	return;
}
void CUnitHandler::IdleUnitUpdate(int frame) {
	list<integer2> limboremoveunits;

	for (list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++) {
		if (i->y > 0) {
			i->y--;
		}
		else {
			if (ai->cb->GetUnitDef(i->x) == NULL) {
				// ignore dead unit
			} else {
				IdleUnits[ai->ut->GetCategory(i->x)].push_back(i->x);
			}

			limboremoveunits.push_back(*i);
		}
	}

	if (limboremoveunits.size()) {
		for (list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++) {
			Limbo.remove(*i);
		}
	}

	// make sure that all the builders are in action (hack?)
	if (frame % 15 == 0) {
		for (list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++) {
			// the new test
			if ((*i)->idleStartFrame != -2) {
				// the brand new builders must be filtered still
				bool ans = VerifyOrder(*i);
				const CCommandQueue* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;

				if (mycommands->size() > 0)
					c = mycommands->front();

				// two sec delay is ok
				if (((*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < frame) {
					if (!ans) {
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);

						ClearOrder(*i, false);

						if (!mycommands->empty())
							DecodeOrder(*i, true);
						else
							IdleUnitAdd((*i)->builderID, frame);
					}
				}
			}
		}
	}
}
Example #3
0
void CBaseAnimatingOverlay::FastRemoveLayer( int iLayer )
{
	if (!IsValidLayer( iLayer ))
		return;

	// shift the other layers down in order
	for (int j = 0; j < m_AnimOverlay.Count(); j++ )
	{
		if ((m_AnimOverlay[ j ].IsActive()) && m_AnimOverlay[ j ].m_nOrder > m_AnimOverlay[ iLayer ].m_nOrder)
		{
			m_AnimOverlay[ j ].m_nOrder--;
		}
	}
	m_AnimOverlay[ iLayer ].Init( this );

	VerifyOrder();
}
Example #4
0
//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
int CBaseAnimatingOverlay::AllocateLayer( int iPriority )
{
	int i;

	// look for an open slot and for existing layers that are lower priority
	int iNewOrder = 0;
	int iOpenLayer = -1;
	int iNumOpen = 0;
	for (i = 0; i < m_AnimOverlay.Count(); i++)
	{
		if ( m_AnimOverlay[i].IsActive() )
		{
			if (m_AnimOverlay[i].m_nPriority <= iPriority)
			{
				iNewOrder = MAX( iNewOrder, m_AnimOverlay[i].m_nOrder + 1 );
			}
		}
		else if (m_AnimOverlay[ i ].IsDying())
		{
			// skip
		}
		else if (iOpenLayer == -1)
		{
			iOpenLayer = i;
		}
		else
		{
			iNumOpen++;
		}
	}

	if (iOpenLayer == -1)
	{
		if (m_AnimOverlay.Count() >= MAX_OVERLAYS)
		{
			return -1;
		}

		iOpenLayer = m_AnimOverlay.AddToTail();
		m_AnimOverlay[iOpenLayer].Init( this );
		m_AnimOverlay[iOpenLayer].NetworkStateChanged();
	}

	// make sure there's always an empty unused layer so that history slots will be available on the client when it is used
	if (iNumOpen == 0)
	{
		if (m_AnimOverlay.Count() < MAX_OVERLAYS)
		{
			i = m_AnimOverlay.AddToTail();
			m_AnimOverlay[i].Init( this );
			m_AnimOverlay[i].NetworkStateChanged();
		}
	}

	for (i = 0; i < m_AnimOverlay.Count(); i++)
	{
		if ( m_AnimOverlay[i].m_nOrder >= iNewOrder && m_AnimOverlay[i].m_nOrder < MAX_OVERLAYS)
		{
			m_AnimOverlay[i].m_nOrder++;
		}
	}

	m_AnimOverlay[iOpenLayer].m_fFlags = ANIM_LAYER_ACTIVE;
	m_AnimOverlay[iOpenLayer].m_nOrder = iNewOrder;
	m_AnimOverlay[iOpenLayer].m_nPriority = iPriority;

	m_AnimOverlay[iOpenLayer].MarkActive();
	VerifyOrder();

	return iOpenLayer;
}
Example #5
0
void CBaseAnimatingOverlay::StudioFrameAdvance ()
{
	float flAdvance = GetAnimTimeInterval();

	VerifyOrder();

	BaseClass::StudioFrameAdvance();

	for ( int i = 0; i < m_AnimOverlay.Count(); i++ )
	{
		CAnimationLayer *pLayer = &m_AnimOverlay[i];
		
		if (pLayer->IsActive())
		{
			// Assert( !m_AnimOverlay[ i ].IsAbandoned() );
			if (pLayer->IsKillMe())
			{
				if (pLayer->m_flKillDelay > 0)
				{
					pLayer->m_flKillDelay -= flAdvance;
					pLayer->m_flKillDelay = clamp( 	pLayer->m_flKillDelay, 0.0, 1.0 );
				}
				else if (pLayer->m_flWeight != 0.0f)
				{
					// give it at least one frame advance cycle to propagate 0.0 to client
					pLayer->m_flWeight -= pLayer->m_flKillRate * flAdvance;
					pLayer->m_flWeight = clamp( 	pLayer->m_flWeight.Get(), 0.0, 1.0 );
				}
				else
				{
					// shift the other layers down in order
					if (ai_sequence_debug.GetBool() == true && m_debugOverlays & OVERLAY_NPC_SELECTED_BIT)
					{
						Msg("removing %d (%d): %s : %5.3f (%.3f)\n", i, pLayer->m_nOrder.Get(), GetSequenceName( pLayer->m_nSequence ), pLayer->m_flCycle.Get(), pLayer->m_flWeight.Get() );
					}
					FastRemoveLayer( i );
					// needs at least one thing cycle dead to trigger sequence change
					pLayer->Dying();
					continue;
				}
			}

			pLayer->StudioFrameAdvance( flAdvance, this );
			if ( pLayer->m_bSequenceFinished && (pLayer->IsAutokill()) )
			{
				pLayer->m_flWeight = 0.0f;
				pLayer->KillMe();
			}
		}
		else if (pLayer->IsDying())
		{
			pLayer->Dead();	
		}
		else if (pLayer->m_flWeight > 0.0)
		{
			// Now that the server blends, it is turning off layers all the time.  Having a weight left over
			// when you're no longer marked as active is now harmless and commonplace.  Just clean up.
			pLayer->Init( this );
			pLayer->Dying();
		}
	}

	if (ai_sequence_debug.GetBool() == true && m_debugOverlays & OVERLAY_NPC_SELECTED_BIT)
	{
		for ( int i = 0; i < m_AnimOverlay.Count(); i++ )
		{
			if (m_AnimOverlay[ i ].IsActive())
			{
				/*
				if (m_AnimOverlay[ i ].IsAbandoned())
				{
					Msg(" %d abandoned %.2f (%.2f)\n", i, gpGlobals->curtime, m_AnimOverlay[ i ].m_flLastAccess );
				}
				*/
				Msg(" %d (%d): %s : %5.3f (%.3f)\n", i, m_AnimOverlay[ i ].m_nOrder.Get(), GetSequenceName( m_AnimOverlay[ i ].m_nSequence ), m_AnimOverlay[ i ].m_flCycle.Get(), m_AnimOverlay[ i ].m_flWeight.Get() );
			}
		}
	}

	VerifyOrder();
}
Example #6
0
void CUnitHandler::IdleUnitUpdate(int frame) {
	std::list<integer2> limboremoveunits;

	for (std::list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++) {
		if (i->y > 0) {
			i->y--;
		} else {
			if (ai->cb->GetUnitDef(i->x) == NULL) {
				// ignore dead unit
			} else {
				IdleUnits[ai->ut->GetCategory(i->x)].push_back(i->x);
			}

			limboremoveunits.push_back(*i);
		}
	}

	if (limboremoveunits.size()) {
		for (std::list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++) {
			Limbo.remove(*i);
		}
	}

	// make sure that all the builders are in action (hack?)
	if (frame % 15 == 0) {
		for (std::list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++) {
			if ((*i)->idleStartFrame != -2) {
				// the brand new builders must be filtered still
				bool ans = VerifyOrder(*i);
				const int builderID = (*i)->builderID;
				const CCommandQueue* myCommands = ai->cb->GetCurrentUnitCommands(builderID);
				Command c;

				if (myCommands->size() > 0) {
					c = myCommands->front();
				}

				// two sec delay is ok
				if (((*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < frame) {
					if (!ans) {
						float3 pos = ai->cb->GetUnitPos(builderID);

						std::stringstream msg;
							msg << "[CUnitHandler::IdleUnitUpdate()][frame=" << frame << "]\n";
							msg << "\tfailed to verify order for builder " << builderID;
							msg << " with " << (myCommands->size()) << " remaining commands\n";
						ai->GetLogger()->Log(msg.str());

						ClearOrder(*i, false);

						// due to the Legacy AI Wrapper inner workings,
						// the command-queue we fetched above is now invalid,
						// because it got changed in ClearOrder()
						myCommands = ai->cb->GetCurrentUnitCommands(builderID);
						if (!myCommands->empty()) {
							DecodeOrder(*i, true);
						} else {
							IdleUnitAdd(builderID, frame);
						}
					}
				}
			}
		}
	}
}
Example #7
0
main (int argc, char * argv[])
{
    FILE        * File1, * File2 ;          // the input file and output file of sorting
    long        BufferRecords    = 0;       // number of records in buffer
    long        error            = 0;       // error flag
    long        RecordNum1       = 0;       // total record number in file1
    long        RecordNum2       = 0;       // total record number in file2
    unsigned long CheckSum1      = 0;       // checksum of file1
    unsigned long CheckSum2      = 0;       // checksum of file2
    char        LastRecord[RecordSize];     // a copy of the last record in the buffer
    bool        OrderSign        = true;    // sign of whether all the records in the file have the desired order 

    /************************************************************************
    *                                                                       *
    *       Put out greeting                                                *
    *                                                                       *
    ************************************************************************/
    fprintf(stderr,"ChkSort (%s) - Verify your PennySort result with its checksum and order.", VERSION);
    fprintf(stderr,"\n    Author: Peng Liu, Tsinghua University, China.  [email protected]  12/2002\n");

    /*********************************************************************
    *                                                                    *
    *       Decode parameters                                            *
    *                                                                    *
    *********************************************************************/
    if (argc != 3)
    { usage(); error = 1; goto common_exit; }
    FileName1=argv[1];
    FileName2=argv[2];

    /************************************************************************/
    /*                                                                      */
    /*      Allocate file buffer                                            */
    /*                                                                      */
    /************************************************************************/
    Buffer = (char *)malloc( BufferSize ) ;
    if( Buffer  == NULL  )
    {
        fprintf(stderr,"\nCouldn't allocate the I/O buffer\n");
        error = 1;  goto common_exit;
    }

    /************************************************************************/
    /*                                                                      */
    /*      Calculate checksum of <filename1>                               */
    /*                                                                      */
    /************************************************************************/

    fprintf(stderr,"\nAnalysing file: %s \n", FileName1);

    // open <filename1>
    File1 = fopen( FileName1, "r+b");
    if( File1 == NULL )
    {
        fprintf(stderr,"\nError opening file %s\n", FileName1) ;
        error = 1;  goto common_exit;
    }

    // check whether the record length in <filename1> is exactly 100 bytes long
    if (CheckRecordLen(File1, FileName1)==false)
    {
        error = 1;  goto common_exit;
    }

    // count the total number of records and calculate its checksum
    RecordNum1=0;
    while ((BufferRecords=ReadToBuffer(File1)) !=0)
    {
        RecordNum1 += BufferRecords;
        CheckSum1 += GetCheckSum(BufferRecords);
    }
    fclose(File1);

    // tell the user about its record number and checksum
    fprintf(stderr, "\nRecord Number: %d  Checksum: %lX\n",RecordNum1, CheckSum1);

    /************************************************************************/
    /*                                                                      */
    /*      Calculate checksum and check order of <filename2>               */
    /*                                                                      */
    /************************************************************************/

    fprintf(stderr,"\n\nAnalysing file: %s \n", FileName2);

    // open <filename2>
    File2 = fopen( FileName2, "r+b");
    if( File2 == NULL )
    {
        fprintf(stderr,"\nError opening file %s\n", FileName2) ;
        error = 1;  goto common_exit;
    }

    // check whether the record length in <filename2> is exactly 100 bytes long
    if (CheckRecordLen(File2, FileName2)==false)
    {
        error = 1;  goto common_exit;
    }

    // count the number of records and checksum of <filename2>
    // and check the order of records in <filename2> one by one
    RecordNum2=0;
    LastRecord[0]=0;
    while ((BufferRecords=ReadToBuffer(File2)) !=0)
    {
        OrderSign=VerifyOrder(LastRecord, BufferRecords);
        // Compare the last record of previous buffer content with the first record of this one
        if (!OrderSign)
            break;
        RecordNum2 += BufferRecords;
        CheckSum2 += GetCheckSum(BufferRecords);
    }
    fclose(File2);
    if (!OrderSign)     // if the order of the records is not correct
        goto common_exit;

    // tell the user about its record number and checksum
    fprintf(stderr, "\nRecord Number: %d  Checksum: %lX\n",RecordNum2, CheckSum2);

    /************************************************************************/
    /*                                                                      */
    /*      Put out result message of comparing checksum and order          */
    /*                                                                      */
    /************************************************************************/

    if (CheckSum1==CheckSum2)
        fprintf(stderr, "\n\nCongratulations: Verification Passed!\n");
    else
        fprintf(stderr, "\n\nBad News: Verification failed due to different checksums \n(although order of records are correct)!\n");

    /************************************************************************/
    /*                                                                      */
    /*      All Done                                                        */
    /*      close output file; and exit                                     */
    /*                                                                      */
    /************************************************************************/

common_exit:
    free(Buffer);                       // free record buffer
    return(error);                      // return status code
}                                       // End of ChkSort.cpp
void CUnitHandler::IdleUnitUpdate() {
//	std::cout << "CUnitHandler::IdleUnitUpdate()" << std::endl;

	list<integer2> limboremoveunits;
	for(list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++){
		if(i->y > 0){
			i->y = i->y - 1;
		}
		else{
			//L("adding unit to idle units: " << i->x);
			if(ai->cb->GetUnitDef(i->x) == NULL)
			{
				//L(" Removeing dead unit... ");
				
			}
			else
				IdleUnits[ai->ut->GetCategory(i->x)]->push_back(i->x);
			if(ai->ut->GetCategory(i->x) == CAT_BUILDER)
			{
				//GetBuilderTracker(i->x)->idleStartFrame = -1; // Its ok now, stop the force idle  (hack)
			}
			
				
			limboremoveunits.push_back(*i);
		}
	}
	if(limboremoveunits.size()){
		for(list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++){
			Limbo.remove(*i);
		}
	}
	// Make shure that all the builders are in action:   (hack ?)
	if(ai->cb->GetCurrentFrame() % 15 == 0)
		for(list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++){
			
			// The new test:
			if((*i)->idleStartFrame != -2) // The brand new builders must be filtered still
			{
				//L("VerifyOrder");
				bool ans = VerifyOrder(*i);
				const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;
				if(mycommands->size() > 0)
					c = mycommands->front();
				
				// Two sec delay is ok
				if(( (*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < ai->cb->GetCurrentFrame())
				{
					//assert(ans);
					if(!ans)
					{
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
						
						ClearOrder(*i, false);
						if(!mycommands->empty())
							DecodeOrder(*i, true);
						else // Its idle
							IdleUnitAdd((*i)->builderID);
							
					}
				}
			}
			
			/*
			if((*i)->buildTaskId == 0 && (*i)->taskPlanId == 0 && (*i)->factoryId == 0 && (*i)->customOrderId == 0 && (*i)->idleStartFrame != -2)
			{
				// Its without tasks and not in the idle list
				if((*i)->idleStartFrame == -1)
				{
					(*i)->idleStartFrame = ai->cb->GetCurrentFrame();
				}
				else
				{
					if(((*i)->idleStartFrame + 90) < ai->cb->GetCurrentFrame())
					{
						//L("Idle unit command force: " << (*i)->builderID);
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i without tasks and not in the idle list (idle forced)", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
						IdleUnitAdd((*i)->builderID);
						(*i)->idleStartFrame =  ai->cb->GetCurrentFrame(); // Just to cut down on the spam, if its not idle
					}
				}
			} else if((*i)->idleStartFrame != -2) // This will only be ok if idleStartFrame is changed to -1 on unit UnitFinished
			{
			*/
			/*
				//L("VerifyOrder");
				bool ans = VerifyOrder(*i);
				const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;
				if(mycommands->size() > 0)
					c = mycommands->front();
				
				// Two sec delay is ok
				if(( (*i)->commandOrderPushFrame + 30 * 2) < ai->cb->GetCurrentFrame())
				{
					//assert(ans);
					if(!ans)
					{
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
					}
				}
				* /
			}
			*/
		}
}