bool CAOPEntity::KeyValue( const char *szKeyName, const char *szValue ) { // loop through the data description, and try and place the keys in for ( datamap_t *dmap = GetDataDescMap(); dmap != NULL; dmap = dmap->baseMap ) { if ( ::ParseKeyvalue(this, dmap->dataDesc, dmap->dataNumFields, szKeyName, szValue) ) return true; } keyvalue_t keyval; strncpy(keyval.key, szKeyName, sizeof(keyval.key)); keyval.key[sizeof(keyval.key)-1] = '\0'; strncpy(keyval.val, szValue, sizeof(keyval.key)); keyval.val[sizeof(keyval.val)-1] = '\0'; // don't store the same key twice for(unsigned short i = keyValuePairs->Head(); i != keyValuePairs->InvalidIndex(); i = keyValuePairs->Next(i)) { keyvalue_t *storedkv = &keyValuePairs->Element(i); if(!strcmp(storedkv->key, keyval.key)) { keyValuePairs->Remove(i); break; } } keyValuePairs->AddToTail(keyval); RETURN_META_VALUE(MRES_HANDLED, 0); }
int GetOffsetForDatamapVar( const CBaseEntity *pEntity, const char *szVarName ) { if (pEntity) { datamap_t *pDatamap = GetDataDescMap( pEntity ); return GetDatamapVarOffset( pDatamap, szVarName ); } return 0; }
void CAOPEntity::InputCopyDatadesc( inputdata_t &inputdata ) { int srcent = inputdata.value.Int(); if(pAdminOP.myEntList.IsValidIndex(srcent) && pAdminOP.myEntList[srcent] != NULL) { CAOPEntity *src = pAdminOP.myEntList[srcent]; datamap_t *datamapdest = GetDataDescMap(); datamap_t *datamapsrc = src->GetDataDescMap(); if(datamapdest && datamapsrc) { pAdminOP.CopyDataMap(this, src, datamapdest, datamapsrc); } } }
int CAI_BehaviorBase::Restore( IRestore &restore ) { return restore.ReadAll( this, GetDataDescMap() ); }
int CAI_BehaviorBase::Save( ISave &save ) { return save.WriteAll( this, GetDataDescMap() ); }
//--------------------------------------------------------- //--------------------------------------------------------- void CBounceBomb::Spawn() { Precache(); Wake( false ); SetModel("models/props_combine/combine_mine01.mdl"); SetSolid( SOLID_VPHYSICS ); m_hSprite.Set( NULL ); m_takedamage = DAMAGE_EVENTS_ONLY; // Find my feet! m_iHookN = LookupPoseParameter( "blendnorth" ); m_iHookE = LookupPoseParameter( "blendeast" ); m_iHookS = LookupPoseParameter( "blendsouth" ); m_iAllHooks = LookupPoseParameter( "blendstates" ); m_flHookPositions = 0; SetHealth( 100 ); m_bBounce = true; SetSequence( SelectWeightedSequence( ACT_IDLE ) ); OpenHooks( true ); m_bHeldByPhysgun = false; m_iFlipAttempts = 0; if( !GetParent() ) { // Create vphysics now if I'm not being carried. CreateVPhysics(); } m_flTimeGrabbed = FLT_MAX; if( m_bDisarmed ) { SetMineState( MINE_STATE_DORMANT ); } else { SetMineState( MINE_STATE_DEPLOY ); } // default to a different skin for cavern turrets (unless explicitly overridden) if ( m_iModification == MINE_MODIFICATION_CAVERN ) { // look for this value in the first datamap // loop through the data description list, restoring each data desc block datamap_t *dmap = GetDataDescMap(); bool bFoundSkin = false; // search through all the readable fields in the data description, looking for a match for ( int i = 0; i < dmap->dataNumFields; ++i ) { if ( dmap->dataDesc[i].flags & (FTYPEDESC_OUTPUT | FTYPEDESC_KEY) ) { if ( !Q_stricmp(dmap->dataDesc[i].externalName, "Skin") ) { bFoundSkin = true; break; } } } if (!bFoundSkin) { // select a random skin for the mine. Actually, we'll cycle through the available skins // using a static variable to provide better distribution. The static isn't saved but // really it's only cosmetic. static unsigned int nextSkin = MINE_CITIZEN_SKIN_MIN; m_nSkin = nextSkin; // increment the skin for next time nextSkin = (nextSkin >= MINE_CITIZEN_SKIN_MAX) ? MINE_CITIZEN_SKIN_MIN : nextSkin + 1; } // pretend like the player set me down. m_bPlacedByPlayer = true; } }
bool CAOPEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID ) { CBaseEntity *pEnt = GetBase(); // loop through the data description list, restoring each data desc block for ( datamap_t *dmap = GetDataDescMap(); dmap != NULL; dmap = dmap->baseMap ) { // search through all the actions in the data description, looking for a match for ( int i = 0; i < dmap->dataNumFields; i++ ) { if ( dmap->dataDesc[i].flags & FTYPEDESC_INPUT ) { if ( !Q_stricmp(dmap->dataDesc[i].externalName, szInputName) ) { // found a match /*char szBuffer[256]; // mapper debug message if (pCaller != NULL) { Q_snprintf( szBuffer, sizeof(szBuffer), "(%0.2f) input %s: %s.%s(%s)\n", gpGlobals->curtime, STRING(pCaller->m_iName), GetDebugName(), szInputName, Value.String() ); } else { Q_snprintf( szBuffer, sizeof(szBuffer), "(%0.2f) input <NULL>: %s.%s(%s)\n", gpGlobals->curtime, GetDebugName(), szInputName, Value.String() ); } DevMsg( 2, szBuffer ); ADD_DEBUG_HISTORY( HISTORY_ENTITY_IO, szBuffer ); if (m_debugOverlays & OVERLAY_MESSAGE_BIT) { DrawInputOverlay(szInputName,pCaller,Value); }*/ // convert the value if necessary if ( Value.FieldType() != dmap->dataDesc[i].fieldType ) { if ( !(Value.FieldType() == FIELD_VOID && dmap->dataDesc[i].fieldType == FIELD_STRING) ) // allow empty strings { if ( !Value.Convert( (fieldtype_t)dmap->dataDesc[i].fieldType ) ) { // bad conversion Warning( "!! ERROR: bad input/output link:\n!! %s(%s,%s) doesn't match type from %s(%s)\n", VFuncs::GetClassname(pEnt), VFuncs::GetClassname(pEnt), szInputName, ( pCaller != NULL ) ? VFuncs::GetClassname(pCaller) : "<null>", ( pCaller != NULL ) ? /*STRING(pCaller->m_iName)*/"targetname" : "<null>" ); //return false; RETURN_META_VALUE(MRES_SUPERCEDE, false); } } } // call the input handler, or if there is none just set the value sopinputfunc_t pfnInput = (sopinputfunc_t)dmap->dataDesc[i].inputFunc; if ( pfnInput ) { // Package the data into a struct for passing to the input handler. inputdata_t data; data.pActivator = pActivator; data.pCaller = pCaller; data.value = Value; data.nOutputID = outputID; (this->*pfnInput)( data ); } else if ( dmap->dataDesc[i].flags & FTYPEDESC_KEY ) { // set the value directly Value.SetOther( ((char*)this) + dmap->dataDesc[i].fieldOffset[ TD_OFFSET_NORMAL ]); // TODO: if this becomes evil and causes too many full entity updates, then we should make // a macro like this: // // define MAKE_INPUTVAR(x) void Note##x##Modified() { x.GetForModify(); } // // Then the datadesc points at that function and we call it here. The only pain is to add // that function for all the DEFINE_INPUT calls. //NetworkStateChanged(); } //return true; RETURN_META_VALUE(MRES_SUPERCEDE, true); } } } } //DevMsg( 2, "unhandled input: (%s) -> (%s,%s)\n", szInputName, STRING(m_iClassname), GetDebugName()/*,", from (%s,%s)" STRING(pCaller->m_iClassname), STRING(pCaller->m_iName)*/ ); RETURN_META_VALUE(MRES_HANDLED, 0); }