/// <summary> /// Searches the entities that are in a rectangular area around the owner entity with the given radius. /// </summary> /// <param name="searchAreaRadius">The radius of the search area given in quadratic tiles.</param> /// <returns>The entities that are in the search area.</returns> public RCSet <Entity> SearchNearbyEntities(int searchAreaRadius) { RCSet <Entity> nearbyEntities = this.owner.Read().Scenario.GetElementsOnMap <Entity>(this.owner.Read().MotionControl.PositionVector.Read(), searchAreaRadius, MapObjectLayerEnum.GroundObjects, MapObjectLayerEnum.AirObjects); nearbyEntities.Remove(this.owner.Read()); return(nearbyEntities); }
/// <summary> /// Internal implementation of ComputeFieldOffsets. /// </summary> /// <param name="types">The list of the types.</param> /// <param name="triedTypeIDs">Used to avoid infinite loop.</param> private void ComputeFieldOffsetsInternal(List <HeapType> types, ref RCSet <short> triedTypeIDs) { if (this.fieldIndices == null) { return; } if (!triedTypeIDs.Add(this.id)) { throw new HeapException(string.Format("Infinite cycle found in the layout of element '{0}'!", this.name)); } int allocationSize = 0; for (int fieldIdx = 0; fieldIdx < this.fieldTypeIDs.Count; fieldIdx++) { this.fieldOffsets[fieldIdx] = allocationSize; short fieldTypeID = this.fieldTypeIDs[fieldIdx]; HeapType fieldType = types[fieldTypeID]; if (fieldType.AllocationSize == -1) { /// Compute the allocation size of the field type first. fieldType.ComputeFieldOffsetsInternal(types, ref triedTypeIDs); } allocationSize += fieldType.AllocationSize; } this.allocationSize = allocationSize; triedTypeIDs.Remove(this.id); }
/// <summary> /// Locates the entities that are in the sight-range of the owner entity. /// </summary> /// <returns>The entities that are in the sight-range of the owner entity.</returns> public RCSet <Entity> LocateEntities() { /// Collect the entities in sight-range. RCSet <Entity> retList = new RCSet <Entity>(); RCSet <Entity> entitiesToCheck = this.owner.Read().Scenario.GetElementsOnMap <Entity>(this.owner.Read().MotionControl.PositionVector.Read(), this.GetSightRangeOfOwner(), MapObjectLayerEnum.GroundObjects, MapObjectLayerEnum.AirObjects); entitiesToCheck.Remove(this.owner.Read()); RCSet <RCIntVector> visibleQuadCoords = this.VisibleQuadCoords; foreach (Entity entity in entitiesToCheck) { bool breakFlag = false; for (int row = entity.MapObject.QuadraticPosition.Top; !breakFlag && row < entity.MapObject.QuadraticPosition.Bottom; row++) { for (int col = entity.MapObject.QuadraticPosition.Left; !breakFlag && col < entity.MapObject.QuadraticPosition.Right; col++) { if (visibleQuadCoords.Contains(new RCIntVector(col, row))) { retList.Add(entity); breakFlag = true; } } } } return(retList); }