Ejemplo n.º 1
0
void ResizeAnimationLayerCallback( void *pStruct, int offsetToUtlVector, int len )
{
	C_BaseAnimatingOverlay *pEnt = (C_BaseAnimatingOverlay*)pStruct;
	CUtlVector < CAnimationLayer > *pVec = &pEnt->m_AnimOverlay;
	CUtlVector< CInterpolatedVar< CAnimationLayer > > *pVecIV = &pEnt->m_iv_AnimOverlay;
	
	Assert( (char*)pVec - (char*)pEnt == offsetToUtlVector );
	Assert( pVec->Count() == pVecIV->Count() );
	Assert( pVec->Count() <= C_BaseAnimatingOverlay::MAX_OVERLAYS );
	
	int diff = len - pVec->Count();
	if ( diff != 0 )
	{
		// remove all entries
		for ( int i=0; i < pVec->Count(); i++ )
		{
			pEnt->RemoveVar( &pVec->Element( i ) );
		}

		pEnt->InvalidatePhysicsRecursive( BOUNDS_CHANGED );

		// adjust vector sizes
		if ( diff > 0 )
		{
			for ( int i = 0; i < diff; ++i )
			{
				int j = pVec->AddToTail( );
				(*pVec)[j].SetOwner( pEnt );
			}
			pVecIV->AddMultipleToTail( diff );
		}
		else
		{
			pVec->RemoveMultiple( len, -diff );
			pVecIV->RemoveMultiple( len, -diff );
		}

		// Rebind all the variables in the ent's list.
		for ( int i=0; i < len; i++ )
		{
			IInterpolatedVar *pWatcher = &pVecIV->Element( i );
			pWatcher->SetDebugName( s_m_iv_AnimOverlayNames[i] );
			pEnt->AddVar( &pVec->Element( i ), pWatcher, LATCH_ANIMATION_VAR, true );
		}
	}

	// FIXME: need to set historical values of nOrder in pVecIV to MAX_OVERLAY

	// Ensure capacity
	pVec->EnsureCapacity( len );

	int nNumAllocated = pVec->NumAllocated();

	// This is important to do because EnsureCapacity doesn't actually call the constructors
	// on the elements, but we need them to be initialized, otherwise it'll have out-of-range
	// values which will piss off the datatable encoder.
	UtlVector_InitializeAllocatedElements( pVec->Base() + pVec->Count(), nNumAllocated - pVec->Count() );
}
Ejemplo n.º 2
0
void CTilegenAction_ChooseCandidate::Execute( CLayoutSystem *pLayoutSystem )
{
	CUtlVector< CRoomCandidate > *pRoomCandidateList = pLayoutSystem->GetRoomCandidateList();
	if ( pRoomCandidateList->Count() == 0 )
	{
		Log_Msg( LOG_TilegenLayoutSystem, "No more room candidates to choose from.\n" );
		pLayoutSystem->GetFreeVariables()->SetOrCreateFreeVariable( "ChoseCandidate", ( void * )0 );
		return;
	}

	int i;
	float flChance = 0.0f;
	for ( i = 0; i < pRoomCandidateList->Count(); ++ i )
	{
		flChance += pRoomCandidateList->Element( i ).m_flCandidateChance;
	}

	float flRandom = pLayoutSystem->GetRandomFloat( 0.0f, 1.0f ) * flChance;

	for ( i = 0; i < pRoomCandidateList->Count(); ++ i )
	{
		flRandom -= pRoomCandidateList->Element( i ).m_flCandidateChance;
		if ( flRandom <= 0.0f )
		{
			break;
		}
	}
	
	if ( i == pRoomCandidateList->Count() ) 
	{
		i = pRoomCandidateList->Count() - 1;
	}
	
	const CRoomCandidate *pCandidate = &pRoomCandidateList->Element( i );

	// This should always succeed since it's in the candidate list to begin with
	bool bSuccess = pLayoutSystem->TryPlaceRoom( pCandidate );
	Assert( bSuccess );
	bSuccess;
	Log_Msg( LOG_TilegenLayoutSystem, "Chose room candidate %s at position (%d, %d).\n", pCandidate->m_pRoomTemplate->GetFullName(), pCandidate->m_iXPos, pCandidate->m_iYPos );
	
	// Empty the room candidate list for future actions
	pRoomCandidateList->RemoveAll();

	if ( m_bStopProcessingActionsOnSuccess )
	{
		pLayoutSystem->StopProcessingActions();
	}

	pLayoutSystem->GetFreeVariables()->SetOrCreateFreeVariable( "ChoseCandidate", ( void * )1 );
}
Ejemplo n.º 3
0
bool SetupNetworkTablesRelease()
{
	if( g_SetupNetworkTablesOnHold == false )
		return false;
	g_SetupNetworkTablesOnHold = false;

	// Setup all tables and update all clients
	PyServerClass *p = g_pPyServerClassHead;
	while( p )
	{
		if( p->m_pNetworkedClass )
			p->m_pNetworkedClass->SetupServerClass();
		p = p->m_pPyNext;
	}

	// Release on hold
	for( int i=0; i<g_SetupNetworkTablesOnHoldList.Count(); i++ )
	{
		EntityInfoOnHold info = (g_SetupNetworkTablesOnHoldList.Element(i));
		info.ent->NetworkProp()->AttachEdict( info.edict );
		info.ent->edict()->m_pNetworkable = info.ent->NetworkProp();
		info.ent->SetTransmitState(FL_FULL_EDICT_CHANGED|FL_EDICT_DIRTY_PVS_INFORMATION);
		info.ent->DispatchUpdateTransmitState();
	}
	g_SetupNetworkTablesOnHoldList.RemoveAll();
	return true;
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void OverlayTransition_EmitOverlayFaces( void )
{
	int nMapOverlayCount = g_aMapWaterOverlays.Count();
	for( int iMapOverlay = 0; iMapOverlay < nMapOverlayCount; ++iMapOverlay )
	{
		OverlayTransition_EmitOverlayFace( &g_aMapWaterOverlays.Element( iMapOverlay ) );
	}
}
void ResizeAnimationLayerCallback( void *pStruct, int offsetToUtlVector, int len )
{
	C_BaseAnimatingOverlay *pEnt = (C_BaseAnimatingOverlay*)pStruct;
	CUtlVector < C_AnimationLayer > *pVec = &pEnt->m_AnimOverlay;
	CUtlVector< CInterpolatedVar< C_AnimationLayer > > *pVecIV = &pEnt->m_iv_AnimOverlay;
	
	Assert( (char*)pVec - (char*)pEnt == offsetToUtlVector );
	Assert( pVec->Count() == pVecIV->Count() );
	Assert( pVec->Count() <= C_BaseAnimatingOverlay::MAX_OVERLAYS );
	
	int diff = len - pVec->Count();

	

	if ( diff == 0 )
		return;

	// remove all entries
	for ( int i=0; i < pVec->Count(); i++ )
	{
		pEnt->RemoveVar( &pVec->Element( i ) );
	}

	// adjust vector sizes
	if ( diff > 0 )
	{
		pVec->AddMultipleToTail( diff );
		pVecIV->AddMultipleToTail( diff );
	}
	else
	{
		pVec->RemoveMultiple( len, -diff );
		pVecIV->RemoveMultiple( len, -diff );
	}

	// Rebind all the variables in the ent's list.
	for ( int i=0; i < len; i++ )
	{
		IInterpolatedVar *pWatcher = &pVecIV->Element( i );
		pWatcher->SetDebugName( s_m_iv_AnimOverlayNames[i] );
		pEnt->AddVar( &pVec->Element( i ), pWatcher, LATCH_ANIMATION_VAR, true );
	}
	// FIXME: need to set historical values of nOrder in pVecIV to MAX_OVERLAY
	
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// Purpose: Zeros out all active screen shakes.
//-----------------------------------------------------------------------------
void CViewEffects::ClearAllShakes()
{
	int nShakeCount = m_ShakeList.Count();
	for ( int i = 0; i < nShakeCount; i++ )
	{
		delete m_ShakeList.Element( i );
	}

	m_ShakeList.Purge();
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// Purpose: Frees all the template data. Called on level shutdown.
//-----------------------------------------------------------------------------
void Templates_RemoveAll(void)
{
	int nCount = g_Templates.Count();
	for (int i = 0; i < nCount; i++)
	{
		TemplateEntityData_t *pTemplate = g_Templates.Element(i);
		Templates_FreeTemplate( pTemplate );
	}

	g_Templates.RemoveAll();
}
void CParticleSystemQuery::TraceAgainstRayTraceEnv( int envnumber, const FourRays &rays, fltx4 TMin, fltx4 TMax,
													  RayTracingResult *rslt_out, int32 skip_id ) const
{
#if defined( CLIENT_DLL )
	if ( g_RayTraceEnvironments.IsValidIndex( envnumber ) )
	{
		RayTracingEnvironment *RtEnv = g_RayTraceEnvironments.Element( envnumber );
		RtEnv->Trace4Rays( rays, TMin, TMax, rslt_out, skip_id );
	}
#endif
}
Ejemplo n.º 9
0
void CTilegenAction_FilterCandidatesByDirection::Execute( CLayoutSystem *pLayoutSystem )
{
	CUtlVector< CRoomCandidate > *pRoomCandidateList = pLayoutSystem->GetRoomCandidateList();
	if ( pRoomCandidateList->Count() == 0 )
	{
		return;
	}

	const char *pDirection = m_pDirectionExpression->Evaluate( pLayoutSystem->GetFreeVariables() );
	int nThreshold = m_pThresholdExpression->Evaluate( pLayoutSystem->GetFreeVariables() );
	nThreshold = MAX( 0, nThreshold );
	ExitDirection_t direction = GetDirectionFromString( pDirection );
	if ( direction < EXITDIR_BEGIN || direction >= EXITDIR_END )
	{
		Log_Warning( LOG_TilegenLayoutSystem, "Invalid direction specified: %s.\n", pDirection );
		return;
	}

	// First go through and figure out the highest score
	int nHighScore = INT_MIN;
	for ( int i = 0; i < pRoomCandidateList->Count(); ++ i )
	{
		const CRoomCandidate *pCandidate = &pRoomCandidateList->Element( i );
		int nScore = ComputeScore( direction, pCandidate->m_iXPos, pCandidate->m_iYPos );
		if ( nScore > nHighScore )
		{
			nHighScore = nScore;
		}
	}

	// Now go through and set the chance of each candidate to 1.0f for any with that score or 0.0f for those with a lower score
	// @TODO: allow for specifying a numerical range in which candidates are chosen
	for ( int i = pRoomCandidateList->Count() - 1; i >= 0; -- i )
	{
		const CRoomCandidate *pCandidate = &pRoomCandidateList->Element( i );
		if ( ComputeScore( direction, pCandidate->m_iXPos, pCandidate->m_iYPos ) < ( nHighScore - nThreshold ) )
		{
			pRoomCandidateList->FastRemove( i );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Looks up a template entity by name, returning the map data blob as
//			a null-terminated string containing key/value pairs.
//			NOTE: This can't handle multiple templates with the same targetname.
//-----------------------------------------------------------------------------
string_t Templates_FindByTargetName(const char *pszName)
{
	int nCount = g_Templates.Count();
	for (int i = 0; i < nCount; i++)
	{
		TemplateEntityData_t *pTemplate = g_Templates.Element(i);
		if ( !stricmp(pTemplate->pszName, pszName) )
			return Templates_FindByIndex( i );
	}

	return NULL_STRING;
}
CEffectScriptElement *CEnvEffectsScript::GetScriptElementByName( const char *pName )
{
	for ( int i = 0; i < m_ScriptElements.Count(); i++ )
	{
		CEffectScriptElement *pCurrent = &m_ScriptElements.Element( i );

		if ( pCurrent && !Q_stricmp( pCurrent->m_szEffectName, pName ) ) 
		{
			return pCurrent;
		}
	}

	return NULL;
}
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void OverlayTransition_AddFaceToLists( int iFace, side_t *pSide )
{
	int nOverlayIdCount = pSide->aWaterOverlayIds.Count();
	for( int iOverlayId = 0; iOverlayId < nOverlayIdCount; ++iOverlayId )
	{
		mapoverlay_t *pMapOverlay = &g_aMapWaterOverlays.Element( pSide->aWaterOverlayIds[iOverlayId] - ( MAX_MAP_OVERLAYS + 1 ) );
		if ( pMapOverlay )
		{
			if( pMapOverlay->aFaceList.Find( iFace ) == -1 )
			{
				pMapOverlay->aFaceList.AddToTail( iFace );
			}
		}
	}
}
Ejemplo n.º 13
0
void CTilegenAction_FilterCandidatesForLinearGrowth::Execute( CLayoutSystem *pLayoutSystem )
{
	CUtlVector< CRoomCandidate > *pRoomCandidateList = pLayoutSystem->GetRoomCandidateList();
	if ( pRoomCandidateList->Count() == 0 )
	{
		return;
	}

	int nThreshold = m_pThresholdExpression->Evaluate( pLayoutSystem->GetFreeVariables() );
	if ( nThreshold < 0 ) nThreshold = INT_MAX;
	
	// First go through and find the most recently placed source room.
	int nHighestPlacementIndex = -1;
	for ( int i = 0; i < pRoomCandidateList->Count(); ++ i )
	{
		const CRoomCandidate *pCandidate = &pRoomCandidateList->Element( i );
		const CRoom *pSourceRoom = pCandidate->m_pExit->pSourceRoom;
		if ( pSourceRoom->m_nPlacementIndex > nHighestPlacementIndex )
		{
			nHighestPlacementIndex = pSourceRoom->m_nPlacementIndex;
		}
	}

	CMapLayout *pMapLayout = pLayoutSystem->GetMapLayout();
	int nMinimumPlacementIndex = pMapLayout->m_PlacedRooms.Count() - 1 - nThreshold;

	// Now go through and remove any candidates not within the threshold of the most recently placed source room.
	for ( int i = pRoomCandidateList->Count() - 1; i >= 0; -- i )
	{
		const CRoomCandidate *pCandidate = &pRoomCandidateList->Element( i );
		if ( pCandidate->m_pExit->pSourceRoom->m_nPlacementIndex < nHighestPlacementIndex || pCandidate->m_pExit->pSourceRoom->m_nPlacementIndex < nMinimumPlacementIndex )
		{
			pRoomCandidateList->FastRemove( i );
		}
	}
}
Ejemplo n.º 14
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Overlay_AddFaceToLists( int iFace, side_t *pSide )
{
	int nOverlayIdCount = pSide->aOverlayIds.Count();
	for( int iOverlayId = 0; iOverlayId < nOverlayIdCount; ++iOverlayId )
	{
		mapoverlay_t *pMapOverlay = &g_aMapOverlays.Element( pSide->aOverlayIds[iOverlayId] );
		if ( pMapOverlay )
		{
			if( pMapOverlay->aFaceList.Find( iFace ) == -1 )
			{
				pMapOverlay->aFaceList.AddToTail( iFace );
			}
		}
	}
}
Ejemplo n.º 15
0
//-----------------------------------------------------------------------------
// Purpose: Returns the shake with the longest duration. This is the shake we
//			use anytime we get an amplitude or frequency command, because the
//			most likely case is that we're modifying a shake with a long
//			duration rather than a brief shake caused by an explosion, etc.
//-----------------------------------------------------------------------------
screenshake_t *CViewEffects::FindLongestShake()
{
	screenshake_t *pLongestShake = NULL;

	int nShakeCount = m_ShakeList.Count();
	for ( int i = 0; i < nShakeCount; i++ )
	{
		screenshake_t *pShake = m_ShakeList.Element( i );
		if ( pShake && ( !pLongestShake || ( pShake->duration > pLongestShake->duration ) ) )
		{
			pLongestShake = pShake;
		}
	}

	return pLongestShake;
}
static void ThreadComputeLeafAmbient( int iThread, void *pUserData )
{
	CUtlVector<ambientsample_t> list;
	while (1)
	{
		int leafID = GetThreadWork ();
		if (leafID == -1)
			break;
		list.RemoveAll();
		ComputeAmbientForLeaf(iThread, leafID, list);
		// copy to the output array
		g_LeafAmbientSamples[leafID].SetCount( list.Count() );
		for ( int i = 0; i < list.Count(); i++ )
		{
			g_LeafAmbientSamples[leafID].Element(i) = list.Element(i);
		}
	}
}
Ejemplo n.º 17
0
    bool SaveItem(specialitemload_t const &item)
    {
        unsigned long long profileid = item.steamid.ConvertToUint64();

        item.itemmutex->Lock();
        unsigned int index = item.itemlist->Find(profileid);
        if(item.itemlist->IsValidIndex(index))
        {
            char query[1024];
            char petname[512];

            CUtlVector<CSpecialItem *> *items = item.itemlist->Element(index);
            item.itemmutex->Unlock();

            //Msg("[ITEMDBG] Saving/deleting old item list.\n");
            for(int i = 0; i < items->Count(); i++)
            {
                //Msg("[ITEMDBG]  - Saving/deleting item %i\n", i);
                item.itemmutex->Lock();
                CSpecialItem *olditem = items->Element(i);

                m_SQL->EscapeString(petname, olditem->m_szPetName, strlen(olditem->m_szPetName));
                
                V_snprintf(query, sizeof(query), "UPDATE `specialitems` SET `petname` = '%s', `equipped` = %i WHERE `id` = %i LIMIT 1", petname, olditem->m_bEquipped, olditem->m_iIndex);
                item.itemmutex->Unlock();
                //Msg("[ITEMDBG] %s\n", query);
                m_SQL->Query(query);
                
                delete olditem->m_pItem;
                delete olditem;
            }

            item.itemmutex->Lock();
            item.itemlist->RemoveAt(index);
            item.itemmutex->Unlock();
            delete items;
        }
        else
        {
            item.itemmutex->Unlock();
        }

        return true;
    }
//-----------------------------------------------------------------------------
// Purpose: Frees all the template data. Called on level shutdown.
//-----------------------------------------------------------------------------
void Templates_RemoveAll(void)
{
	int nCount = g_Templates.Count();
	for (int i = 0; i < nCount; i++)
	{
		TemplateEntityData_t *pTemplate = g_Templates.Element(i);

		free((void *)pTemplate->pszName);
		free(pTemplate->pszMapData);
		if ( pTemplate->pszFixedMapData )
		{
			free(pTemplate->pszFixedMapData);
		}

		free(pTemplate);
	}

	g_Templates.RemoveAll();
}
Ejemplo n.º 19
0
void VMPI_ReceiveDetailPropWU( int iWorkUnit, MessageBuffer *pBuf, int iWorker )
{
	CUtlVector<DetailPropLightstylesLump_t> *pDetailPropLump = s_pDetailPropLightStyleLump;

	DetailObjectLump_t& prop = g_pMPIDetailProps[iWorkUnit];

	pBuf->read( &prop.m_Lighting, sizeof( prop.m_Lighting ) );
	pBuf->read( &prop.m_LightStyleCount, sizeof( prop.m_LightStyleCount ) );
	pBuf->read( &prop.m_LightStyles, sizeof( prop.m_LightStyles ) );
	
	pDetailPropLump->EnsureCount( prop.m_LightStyles + prop.m_LightStyleCount );
	
	for ( int i=0; i < prop.m_LightStyleCount; i++ )
	{
		DetailPropLightstylesLump_t *l = &pDetailPropLump->Element( i + prop.m_LightStyles );
		pBuf->read( &l->m_Lighting, sizeof( l->m_Lighting ) );
		pBuf->read( &l->m_Style, sizeof( l->m_Style ) );
	}
}
Ejemplo n.º 20
0
void VMPI_ProcessDetailPropWU( int iThread, int iWorkUnit, MessageBuffer *pBuf )
{
	CUtlVector<DetailPropLightstylesLump_t> *pDetailPropLump = s_pDetailPropLightStyleLump;

	DetailObjectLump_t& prop = g_pMPIDetailProps[iWorkUnit];
	ComputeLighting( prop, iThread );

	// Send the results back...	
	pBuf->write( &prop.m_Lighting, sizeof( prop.m_Lighting ) );
	pBuf->write( &prop.m_LightStyleCount, sizeof( prop.m_LightStyleCount ) );
	pBuf->write( &prop.m_LightStyles, sizeof( prop.m_LightStyles ) );
	
	for ( int i=0; i < prop.m_LightStyleCount; i++ )
	{
		DetailPropLightstylesLump_t *l = &pDetailPropLump->Element( i + prop.m_LightStyles );
		pBuf->write( &l->m_Lighting, sizeof( l->m_Lighting ) );
		pBuf->write( &l->m_Style, sizeof( l->m_Style ) );
	}
}
Ejemplo n.º 21
0
void CSpecialItemLoader::Shutdown()
{
    if(!GAME_HAS_ITEMS())
    {
        return;
    }

    m_pLoadThread->JoinQueue();
    m_pLoadThread->SaveQueue();

    FOR_EACH_MAP_FAST(m_allItems, list)
    {
        CUtlVector<CSpecialItem *> *itemlist = m_allItems[list];
        for(int i = 0; i < itemlist->Count(); i++)
        {
            CSpecialItem *curitem = itemlist->Element(i);
            delete curitem->m_pItem;
            delete curitem;
        }
        delete itemlist;
    }
Ejemplo n.º 22
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Overlay_UpdateSideLists( void )
{
	int nMapOverlayCount = g_aMapOverlays.Count();
	for( int iMapOverlay = 0; iMapOverlay < nMapOverlayCount; ++iMapOverlay )
	{
		mapoverlay_t *pMapOverlay = &g_aMapOverlays.Element( iMapOverlay );
		if ( pMapOverlay )
		{
			int nSideCount = pMapOverlay->aSideList.Count();
			for( int iSide = 0; iSide < nSideCount; ++iSide )
			{
				side_t *pSide = GetSide( pMapOverlay->aSideList[iSide] );
				if ( pSide )
				{
					if ( pSide->aOverlayIds.Find( pMapOverlay->nId ) == -1 )
					{
						pSide->aOverlayIds.AddToTail( pMapOverlay->nId );
					}
				}
			}
		}
	}
}
Ejemplo n.º 23
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void OverlayTransition_UpdateSideLists( void )
{
	int nOverlayCount = g_aMapWaterOverlays.Count();
	for( int iOverlay = 0; iOverlay < nOverlayCount; ++iOverlay )
	{
		mapoverlay_t *pOverlay = &g_aMapWaterOverlays.Element( iOverlay );
		if ( pOverlay )
		{
			int nSideCount = pOverlay->aSideList.Count();
			for( int iSide = 0; iSide < nSideCount; ++iSide )
			{
				side_t *pSide = GetSide( pOverlay->aSideList[iSide] );
				if ( pSide )
				{
					if ( pSide->aWaterOverlayIds.Find( pOverlay->nId ) == -1 )
					{
						pSide->aWaterOverlayIds.AddToTail( pOverlay->nId );
					}
				}
			}
		}
	}
}
//------------------------------------------------------------------------------
// Purpose: general purpose routine to collect conditions used both during active
//			and non-active states of the behavior.
//------------------------------------------------------------------------------
void CAI_ASW_HealOtherBehavior::GatherCommonConditions( )
{
	BaseClass::GatherCommonConditions();

//	ClearCondition( COND_HEAL_OTHER_HAS_TARGET );
	SetCondition( COND_HEAL_OTHER_NOT_HAS_TARGET );
	ClearCondition( COND_HEAL_OTHER_TARGET_CHANGED );
	ClearCondition( COND_HEAL_OTHER_TARGET_IN_RANGE );
	ClearCondition( COND_HEAL_OTHER_NOT_TARGET_IN_RANGE );

	CBaseEntity					*pBestObject = NULL;
	int							nPotentialHealthBenefit = 0;

	for( int i = 0; i < GetOuter()->GetNumFactions(); i++ )
	{
		if ( GetOuter()->GetFactionRelationshipDisposition( i ) == D_LIKE )
		{
			CUtlVector< EHANDLE >	*pEntityList = GetOuter()->GetEntitiesInFaction( i );
			for( int j = 0; j < pEntityList->Count(); j++ )
			{
				CBaseEntity	*pEntity = pEntityList->Element( j );
				if ( pEntity->GetHealth() <= 0 )
					continue;
				
				Class_T entClass = pEntity->Classify();
 				if ( entClass == CLASS_ASW_SHAMAN || entClass == CLASS_ASW_BOOMER || entClass == CLASS_ASW_BOOMERMINI
						|| entClass == CLASS_ASW_PARASITE || entClass == CLASS_ASW_BLOB || entClass == CLASS_ASW_BUZZER
						|| entClass == CLASS_ASW_RUNNER )
 				{
 					continue;
 				}

				if ( GetOuter() != pEntity )
				{
					Vector	vDiff = pEntity->GetAbsOrigin() - GetAbsOrigin();
					float	flLengthSquared = vDiff.LengthSqr();

					if ( flLengthSquared <= m_flHealConsiderationDistanceSquared )
						//&& ( !asw_shaman_only_heal_hurt_pEntity->m_iHealth < pEntity->m_iMaxHealth )
					{
						if ( nPotentialHealthBenefit == 0 || ( pEntity->m_iMaxHealth - pEntity->m_iHealth ) > nPotentialHealthBenefit )
						{
							nPotentialHealthBenefit = ( pEntity->m_iMaxHealth - pEntity->m_iHealth );
							pBestObject = pEntity;
						}	
					}
				}
			}
		}
	}

	if ( pBestObject )
	{
		if ( m_hHealTargetEnt != NULL && m_hHealTargetEnt != pBestObject )
		{
			SetCondition( COND_HEAL_OTHER_TARGET_CHANGED );
		}
//		SetCondition( COND_HEAL_OTHER_HAS_TARGET );
		ClearCondition( COND_HEAL_OTHER_NOT_HAS_TARGET );

		m_hHealTargetEnt = pBestObject;
		
		if ( m_hHealTargetEnt.Get() )
		{
			Vector vPredictedPos = m_hHealTargetEnt->GetAbsOrigin() + m_hHealTargetEnt->GetAbsVelocity() * asw_shaman_aim_ahead_time.GetFloat();
			Vector	vDiff = vPredictedPos - GetAbsOrigin();
			if ( vDiff.Length() < m_flHealDistance )
			{
				SetCondition( COND_HEAL_OTHER_TARGET_IN_RANGE );
			}
			else
			{
				SetCondition( COND_HEAL_OTHER_NOT_TARGET_IN_RANGE );
			}
		}
	}
	else
	{
		if ( m_hHealTargetEnt != NULL && m_hHealTargetEnt != pBestObject )
		{
			SetCondition( COND_HEAL_OTHER_TARGET_CHANGED );
		}

		m_hHealTargetEnt = NULL;
	}
}
Ejemplo n.º 25
0
    bool LoadItem(specialitemload_t const &item)
    {
        unsigned long long profileid = item.steamid.ConvertToUint64();
        char query[1024];

        V_snprintf(query, sizeof(query), "SELECT `id`, `itemdef`, `petname`, `equipped`, `level`, `quality` FROM `specialitems` WHERE `owner` = %llu AND `active` = 'Y' ORDER BY `id` ASC", profileid);
        //Msg("[ITEMDBG] %s\n", query);
        m_SQL->Query(query);

        item.itemmutex->Lock();

        unsigned int index = item.itemlist->Find(profileid);
        if(item.itemlist->IsValidIndex(index))
        {
            // this should be checked first in NetworkIDValidated
            // but this could still happen if two NetworkIDValidated occur for the same ID
            // while items still loading
            Msg("[ITEMDBG] Item list already exists for %s.\n", item.steamid.Render());
            item.itemmutex->Unlock();
            return true;
        }

        item.itemmutex->Unlock();

        CUtlVector<CSpecialItem *> *items = new CUtlVector<CSpecialItem *>;

        CSOPMySQLRow row = m_SQL->NextRow();
        while(!row.IsNull())
        {
            CSpecialItem *newspecialitem = new CSpecialItem;
            newspecialitem->m_iIndex = atoi(row.Column(0));
            V_strncpy(newspecialitem->m_szPetName, row.Column(2), sizeof(newspecialitem->m_szPetName));
            newspecialitem->m_bEquipped = atoi(row.Column(3)) != 0;
            CEconItemView *newitem = new CEconItemView;
            //Msg("[ITEMDBG] Test: %i %i\n", sizeof(CEconItemView), sizeof(CEconItemAttribute));
            newspecialitem->m_pItem = newitem;
            newitem->m_bInitialized = false;
            newitem->m_iEntityLevel = atoi(row.Column(4));
            newitem->m_iEntityQuality = atoi(row.Column(5));
            newitem->m_iGlobalIndex = 0;
            newitem->m_iGlobalIndexHigh = 0;
            newitem->m_iGlobalIndexLow = 0;
            newitem->m_iAccountID = item.steamid.GetAccountID();
            newitem->m_iItemDefinitionIndex = atoi(row.Column(1));
            newitem->m_iPosition = 0;
            newitem->m_pUnk = NULL;
            newitem->m_attributes.m_Attributes.EnsureCapacity(16);

            //Msg("[ITEMDBG] Adding item %i  type %i level %i quality %i\n", newitem->m_iGlobalIndex, newitem->m_iItemDefinitionIndex, newitem->m_iEntityLevel, newitem->m_iEntityQuality);
            items->AddToTail(newspecialitem);

            row = m_SQL->NextRow();
        }

        m_SQL->FreeResult();

        // now go and get all the attributes
        for(int i = 0; i < items->Count(); i++)
        {
            CSpecialItem *curspecialitem = items->Element(i);
            CEconItemView *curitem = curspecialitem->m_pItem;

            V_snprintf(query, sizeof(query), "SELECT `attribdef`, `value` FROM `specialitems_attributes` WHERE `itemid` = %i", (int)curspecialitem->m_iIndex);
            //Msg("[ITEMDBG] %s\n", query);
            m_SQL->Query(query);

            CSOPMySQLRow row = m_SQL->NextRow();
            while(!row.IsNull())
            {
                CEconItemAttribute newAttrib;
                newAttrib.m_iAttribDef = atoi(row.Column(0));
                newAttrib.m_flVal = atof(row.Column(1));
                newAttrib.m_flInitialValue = newAttrib.m_flVal;
                newAttrib.m_nRefundableCurrency = 0;
                newAttrib.m_bSetBonus = false;

                //Msg("[ITEMDBG] Adding attribute to item %i  def %i  val %f\n", (int)curitem->m_iGlobalIndex, newAttrib.m_iAttribDef, newAttrib.m_flVal);
                curitem->m_attributes.m_Attributes.AddToTail(newAttrib);

                row = m_SQL->NextRow();
            }

            m_SQL->FreeResult();
        }

        item.itemmutex->Lock();
        index = item.itemlist->Find(profileid);
        if(item.itemlist->IsValidIndex(index))
        {
            // this should be checked first in NetworkIDValidated
            // but this could still happen if two NetworkIDValidated occur for the same ID
            // while items still loading
            Msg("[ITEMDBG] Item list already exists when inserting for %s.\n", item.steamid.Render());

            // free list
            for(int i = 0; i < items->Count(); i++)
            {
                delete items->Element(i)->m_pItem;
                delete items->Element(i);
            }
            delete items;
        }
        else
        {
            item.itemlist->Insert(profileid, items);
        }
        item.itemmutex->Unlock();
        
        return true;
    }
Ejemplo n.º 26
0
void CTilegenAction_AddConnectorRoomCandidates::Execute( CLayoutSystem *pLayoutSystem )
{
	CUtlVector< const CRoomTemplate * > roomTemplateList;
	if ( m_pTargetRoomTemplate != NULL )
	{
		Assert( m_pTargetRoomTemplateFilter == NULL && m_pTargetThemeNameExpression == NULL );
		roomTemplateList.AddToTail( m_pTargetRoomTemplate );
	}
	else
	{
		Assert( m_pTargetRoomTemplateFilter != NULL	&& m_pTargetThemeNameExpression != NULL );

		if ( m_pLevelTheme == NULL )
		{
			const char *pThemeName = m_pTargetThemeNameExpression->Evaluate( pLayoutSystem->GetFreeVariables() );
			m_pLevelTheme = CLevelTheme::FindTheme( pThemeName );
			if ( m_pLevelTheme == NULL )
			{
				Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", pThemeName );
				pLayoutSystem->OnError();
				return;
			}
		}

		BuildRoomTemplateList( pLayoutSystem, m_pLevelTheme, m_pTargetRoomTemplateFilter, true, &roomTemplateList );
	}

	// Build a list of exit types we're looking for
	CUtlVector< CExit > desiredMatchingExits;
	for ( int i = 0; i < roomTemplateList.Count(); ++ i )
	{
		const CRoomTemplate *pTemplate = roomTemplateList[i];
		for ( int j = 0; j < pTemplate->m_Exits.Count(); ++ j )
		{
			desiredMatchingExits.AddToTail( CExit( 
				0, 0, CRoomTemplateExit::GetOppositeDirection( pTemplate->m_Exits[j]->m_ExitDirection ), 
				pTemplate->m_Exits[j]->m_szExitTag, NULL, false ) );
		}
	}

	// Build up a room of connector candidates
	pLayoutSystem->ExecuteAction( m_pAddConnectorCandidates, NULL );

	// Filter the set down by eliminating candidates which don't connect to the desired direction.
	CUtlVector< CRoomCandidate > *pRoomCandidateList = pLayoutSystem->GetRoomCandidateList();
	CUtlVector< CExit > newOpenExits;
	for ( int i = pRoomCandidateList->Count() - 1; i >= 0; -- i )
	{
		bool bMatch = false;
		newOpenExits.RemoveAll();

		// Figure out which new exits would be open as a result of placing this room candidate.
		BuildOpenExitList( pRoomCandidateList->Element( i ), pLayoutSystem->GetMapLayout(), &newOpenExits );

		// For every new open exit potentially created by this candidate,
		// see if one of them could connect to one of our desired exits.
		for ( int j = 0; j < newOpenExits.Count(); ++ j )
		{
			const CExit *pNewOpenExit = &newOpenExits[j];
			for ( int k = 0; k < desiredMatchingExits.Count(); ++ k )
			{
				const CExit *pDesiredMatchingExit = &desiredMatchingExits[k];
				if ( pNewOpenExit->ExitDirection == pDesiredMatchingExit->ExitDirection && 
					 Q_stricmp( pNewOpenExit->m_szExitTag, pDesiredMatchingExit->m_szExitTag ) == 0 )
				{
					// Found a match!
					bMatch = true;
					break;
				}
			}
			if ( bMatch ) break;
		}

		if ( !bMatch )
		{
			pRoomCandidateList->FastRemove( i );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFFreezePanel::UpdateCallout( void )
{
	CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
	if ( !pPlayer )
		return;

	// Abort early if we have no gibs or ragdoll
	CUtlVector<EHANDLE>	*pGibList = pPlayer->GetSpawnedGibs();
	IRagdoll *pRagdoll = pPlayer->GetRepresentativeRagdoll();
	if ( (!pGibList || pGibList->Count() == 0) && !pRagdoll )
		return;

	if ( m_pFreezePanelBG == NULL )
		return;

	// Precalc the vectors of the freezepanel & statpanel
	int iX, iY;
	m_pFreezePanelBG->GetPos( iX, iY );
	Vector vecFreezeTL( iX, iY, 0 );
	Vector vecFreezeBR( iX + m_pFreezePanelBG->GetWide(), iY + m_pFreezePanelBG->GetTall(), 1 );

	CUtlVector<Vector> vecCalloutsTL;
	CUtlVector<Vector> vecCalloutsBR;

	Vector vecStatTL(0,0,0);
	Vector vecStatBR(0,0,1);
	CTFStatPanel *pStatPanel = GET_HUDELEMENT( CTFStatPanel );
	if ( pStatPanel && pStatPanel->IsVisible() )
	{
		pStatPanel->GetPos( iX, iY );
		vecStatTL.x = iX;
		vecStatTL.y = iY;
		vecStatBR.x = vecStatTL.x + pStatPanel->GetWide();
		vecStatBR.y = vecStatTL.y + pStatPanel->GetTall();
	}

	Vector vMins, vMaxs;

	// Check gibs
	if ( pGibList && pGibList->Count() )
	{
		int iCount = 0;
		for ( int i = 0; i < pGibList->Count(); i++ )
		{
			CBaseEntity *pGib = pGibList->Element(i);
			if ( pGib )
			{
				Vector origin = pGib->GetRenderOrigin();
				IPhysicsObject *pPhysicsObject = pGib->VPhysicsGetObject();
				if( pPhysicsObject )
				{
					Vector vecMassCenter = pPhysicsObject->GetMassCenterLocalSpace();
					pGib->CollisionProp()->CollisionToWorldSpace( vecMassCenter, &origin );
				}
				pGib->GetRenderBounds( vMins, vMaxs );

				// Try and add the callout
				CTFFreezePanelCallout *pCallout = TestAndAddCallout( origin, vMins, vMaxs, &vecCalloutsTL, &vecCalloutsBR, 
					vecFreezeTL, vecFreezeBR, vecStatTL, vecStatBR, &iX, &iY );
				if ( pCallout )
				{
					pCallout->UpdateForGib( i, iCount );
					iCount++;
				}
			}
		}
	}
	else if ( pRagdoll )
	{
		Vector origin = pRagdoll->GetRagdollOrigin();
		pRagdoll->GetRagdollBounds( vMins, vMaxs );

		// Try and add the callout
		CTFFreezePanelCallout *pCallout = TestAndAddCallout( origin, vMins, vMaxs, &vecCalloutsTL, &vecCalloutsBR, 
															 vecFreezeTL, vecFreezeBR, vecStatTL, vecStatBR, &iX, &iY );
		if ( pCallout )
		{
			pCallout->UpdateForRagdoll();
		}

		// even if the callout failed, check that our ragdoll is onscreen and our killer is taunting us (for an achievement)
		if ( GetVectorInScreenSpace( origin, iX, iY ) )
		{
			C_TFPlayer *pKiller = ToTFPlayer( UTIL_PlayerByIndex( GetSpectatorTarget() ) );
			if ( pKiller && pKiller->m_Shared.InCond( TF_COND_TAUNTING ) )
			{
				// tell the server our ragdoll just got taunted during our freezecam
				char cmd[256];
				int iPlayerID = pPlayer->GetUserID();
				unsigned short mask = UTIL_GetAchievementEventMask();

				Q_snprintf( cmd, sizeof( cmd ), "freezecam_taunt %d %d", GetSpectatorTarget() ^ mask, ( iPlayerID ^ GetSpectatorTarget() ) ^ mask );
				engine->ClientCmd_Unrestricted( cmd );
			}
		}
	}
}
Ejemplo n.º 28
0
//-----------------------------------------------------------------------------
// Purpose: Apply noise to the eye position.
// UNDONE: Feedback a bit of this into the view model position.  It shakes too much
//-----------------------------------------------------------------------------
void CViewEffects::CalcShake( void )
{
	float	fraction, freq;

	// We'll accumulate the aggregate shake for this frame into these data members.
	m_vecShakeAppliedOffset.Init(0, 0, 0);
	m_flShakeAppliedAngle = 0;
	float flRumbleAngle = 0;

	bool bShow = shake_show.GetBool();

	int nShakeCount = m_ShakeList.Count();

	for ( int nShake = nShakeCount - 1; nShake >= 0; nShake-- )
	{
		screenshake_t *pShake = m_ShakeList.Element( nShake );

		if ( pShake->endtime == 0 )
		{
			// Shouldn't be any such shakes in the list.
			Assert( false );
			continue;
		}

		if ( ( gpGlobals->curtime > pShake->endtime ) || 
			pShake->duration <= 0 || 
			pShake->amplitude <= 0 || 
			pShake->frequency <= 0 )
		{
			// Retire this shake.
			delete m_ShakeList.Element( nShake );
			m_ShakeList.FastRemove( nShake );
			continue;
		}

		if ( bShow )
		{
			con_nprint_t np;
			np.time_to_live = 2.0f;
			np.fixed_width_font = true;
			np.color[0] = 1.0;
			np.color[1] = 0.8;
			np.color[2] = 0.1;
			np.index = nShake + 2;

			engine->Con_NXPrintf( &np, "%02d: dur(%8.2f) amp(%8.2f) freq(%8.2f)", nShake + 1, (double)pShake->duration, (double)pShake->amplitude, (double)pShake->frequency );
		}

		if ( gpGlobals->curtime > pShake->nextShake )
		{
			// Higher frequency means we recalc the extents more often and perturb the display again
			pShake->nextShake = gpGlobals->curtime + (1.0f / pShake->frequency);

			// Compute random shake extents (the shake will settle down from this)
			for (int i = 0; i < 3; i++ )
			{
				pShake->offset[i] = random->RandomFloat( -pShake->amplitude, pShake->amplitude );
			}

			pShake->angle = random->RandomFloat( -pShake->amplitude*0.25, pShake->amplitude*0.25 );
		}

		// Ramp down amplitude over duration (fraction goes from 1 to 0 linearly with slope 1/duration)
		fraction = ( pShake->endtime - gpGlobals->curtime ) / pShake->duration;

		// Ramp up frequency over duration
		if ( fraction )
		{
			freq = (pShake->frequency / fraction);
		}
		else
		{
			freq = 0;
		}

		// square fraction to approach zero more quickly
		fraction *= fraction;

		// Sine wave that slowly settles to zero
		float angle = gpGlobals->curtime * freq;
		if ( angle > 1e8 )
		{
			angle = 1e8;
		}
		fraction = fraction * sin( angle );
		
		if( pShake->command != SHAKE_START_NORUMBLE )
		{
			// As long as this isn't a NO RUMBLE effect, then accumulate rumble
			flRumbleAngle += pShake->angle * fraction;
		}

		if( pShake->command != SHAKE_START_RUMBLEONLY )
		{
			// As long as this isn't a RUMBLE ONLY effect, then accumulate screen shake
			
			// Add to view origin
			m_vecShakeAppliedOffset += pShake->offset * fraction;

			// Add to roll
			m_flShakeAppliedAngle += pShake->angle * fraction;
		}

		// Drop amplitude a bit, less for higher frequency shakes
		pShake->amplitude -= pShake->amplitude * ( gpGlobals->frametime / (pShake->duration * pShake->frequency) );
	}

	// Feed this to the rumble system!
	UpdateScreenShakeRumble( flRumbleAngle );
}