Example #1
0
/**
 * \brief Returns the layer and index of an entity given its name.
 * \param name Name of the entity to get.
 * \return The layer and index of this entity.
 * Returns an invalid index if there is no such entity.
 */
EntityIndex MapData::get_entity_index(const std::string& name) const {

  const auto& it = named_entities.find(name);

  if (it == named_entities.end()) {
    return EntityIndex();
  }

  return it->second;
}
Example #2
0
/**
 * \brief Adds an entity to the map.
 *
 * The entity will be added in front of other ones that are on the same layer.
 * Use insert_entity() if you want to insert it at a specific index.
 *
 * If the new entity has a name, it should be unique on the map.
 *
 * \param entity The information of an entity.
 * \return The index of this entity on the map.
 * Returns an invalid index in case of failure, that is,
 * if the name was already in use or if the entity type is illegal.
 */
EntityIndex MapData::add_entity(const EntityData& entity) {

  // Compute the appropriate index.
  Layer layer = entity.get_layer();
  int bound = entity.is_dynamic() ? get_num_entities(layer) : get_num_tiles(layer);
  EntityIndex index = { layer, bound };

  // Insert the entity there.
  if (!insert_entity(entity, index)) {
    // Failure.
    return EntityIndex();
  }
  return index;
}
Example #3
0
void touchEntities(entity *ent)
{

  int i;
  int done;
  BBox box1, box2;

  done=0;

  if(ent->touch != NULL)
  {
    for(i=0;i < MAXENTITIES;i++) 
    {
      if(done >= numents+10) break;
      if(EntityIndex(i)->used != 0)
      {
        done++;
        if(EntityIndex(i)->solid != 0)
        {		
          if(EntityIndex(i) != ent && (ent->targetType == EntityIndex(i)->type || ent->targetType2 == EntityIndex(i)->type))
          {
            box1.w = ent->box.w;
            box1.h = ent->box.h;
            box2.w = EntityIndex(i)->box.w;
            box2.h = EntityIndex(i)->box.h;
            box1.x = ent->s.x-ent->box.x;
            box1.y = ent->s.y-ent->box.y;
            box2.x = EntityIndex(i)->s.x-EntityIndex(i)->box.x;
            box2.y = EntityIndex(i)->s.y-EntityIndex(i)->box.y;
            if(BoxCollide2(box1,box2))
            {
              if(ent->touch != NULL) ent->touch(ent->self,EntityIndex(i),box2);
            }
          }
        }
      }
    }
  }

}
int	CSaveRestoreBuffer::EntityIndex( EOFFSET eoLookup )
{
	return EntityIndex( ENT( eoLookup ) );
}
int	CSaveRestoreBuffer::EntityIndex( entvars_t *pevLookup )
{
	if( pevLookup == NULL )
		return -1;
	return EntityIndex( ENT( pevLookup ) );
}
int	CSaveRestoreBuffer::EntityIndex( CBaseEntity *pEntity )
{
	if( pEntity == NULL )
		return -1;
	return EntityIndex( pEntity->pev );
}
Example #7
0
bool CSave::WriteFields( const char *pname, void *pBaseData, const DataMap_t& dataMap, const TYPEDESCRIPTION *pFields, int fieldCount )
{
	int				i, j;
	const TYPEDESCRIPTION	*pTest;
	int				entityArray[ MAX_ENTITYARRAY ];

	// Precalculate the number of empty fields
	int actualCount = 0;
	for( i = 0; i < fieldCount; i++ )
	{
		pTest = &pFields[ i ];
		void *pOutputData;
		pOutputData = ( ( char * ) pBaseData + pTest->fieldOffset );
		if( ( pTest->flags & TypeDescFlag::SAVE ) && !DataEmpty( ( const char * ) pOutputData, pTest->fieldSize * g_SaveRestoreSizes[ pTest->fieldType ] ) )
			++actualCount;
	}

	// Empty fields will not be written, write out the actual number of fields to be written
	WriteInt( pname, &actualCount, 1 );

	for( i = 0; i < fieldCount; i++ )
	{
		void *pOutputData;
		pTest = &pFields[ i ];
		pOutputData = ( ( char * ) pBaseData + pTest->fieldOffset );

		// UNDONE: Must we do this twice?
		//TODO: update CSaveRestoreBuffer to allow seeking to write to earlier locations. - Solokiller
		if( !( pTest->flags & TypeDescFlag::SAVE ) || DataEmpty( ( const char * ) pOutputData, pTest->fieldSize * g_SaveRestoreSizes[ pTest->fieldType ] ) )
			continue;

		switch( pTest->fieldType )
		{
		case FIELD_FLOAT:
			WriteFloat( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize );
			break;
		case FIELD_TIME:
			WriteTime( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize );
			break;
		case FIELD_MODELNAME:
		case FIELD_SOUNDNAME:
		case FIELD_STRING:
			WriteString( pTest->fieldName, ( int * ) pOutputData, pTest->fieldSize );
			break;
		case FIELD_CLASSPTR:
		case FIELD_EVARS:
		case FIELD_EDICT:
		case FIELD_ENTITY:
		case FIELD_EHANDLE:
			if( pTest->fieldSize > MAX_ENTITYARRAY )
				ALERT( at_error, "Can't save more than %d entities in an array!!!\n", MAX_ENTITYARRAY );
			for( j = 0; j < pTest->fieldSize; j++ )
			{
				switch( pTest->fieldType )
				{
				case FIELD_EVARS:
					entityArray[ j ] = EntityIndex( ( ( entvars_t ** ) pOutputData )[ j ] );
					break;
				case FIELD_CLASSPTR:
					entityArray[ j ] = EntityIndex( ( ( CBaseEntity ** ) pOutputData )[ j ] );
					break;
				case FIELD_EDICT:
					entityArray[ j ] = EntityIndex( ( ( edict_t ** ) pOutputData )[ j ] );
					break;
				case FIELD_ENTITY:
					entityArray[ j ] = EntityIndex( ( ( EOFFSET * ) pOutputData )[ j ] );
					break;
				case FIELD_EHANDLE:
					entityArray[ j ] = EntityIndex( ( CBaseEntity * ) ( ( ( EHANDLE * ) pOutputData )[ j ] ) );
					break;
				}
			}
			WriteInt( pTest->fieldName, entityArray, pTest->fieldSize );
			break;
		case FIELD_POSITION_VECTOR:
			WritePositionVector( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize );
			break;
		case FIELD_VECTOR:
			WriteVector( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize );
			break;

		case FIELD_BOOLEAN:
			//TODO: should be written as a bit perhaps? - Solokiller
			WriteBoolean( pTest->fieldName, ( bool* ) pOutputData, pTest->fieldSize );
			break;

		case FIELD_INTEGER:
			WriteInt( pTest->fieldName, ( int * ) pOutputData, pTest->fieldSize );
			break;

		case FIELD_SHORT:
			WriteData( pTest->fieldName, 2 * pTest->fieldSize, ( ( char * ) pOutputData ) );
			break;

		case FIELD_CHARACTER:
			WriteData( pTest->fieldName, pTest->fieldSize, ( ( char * ) pOutputData ) );
			break;

		case FIELD_FUNCPTR:
			WriteFunction( pTest->fieldName, ( void ** ) pOutputData, pTest->fieldSize, dataMap, *pTest );
			break;
		default:
			ALERT( at_error, "Bad field type\n" );
		}
	}

	return true;
}