/// <summary> /// Adds an Entity to be part of the engine and the world /// </summary> /// <param name="xmasEntity">The entity added to world</param> /// <param name="info">Information regarding where and how to add the entity</param> /// <returns>whether or not the adding of the entity was successful</returns> public bool AddEntity(XmasEntity xmasEntity, EntitySpawnInformation info) { xmasEntity.Load(); if (xmasEntity is Agent) { Agent agent = xmasEntity as Agent; Agent otheragent; if(string.IsNullOrEmpty(agent.Name)) throw new AgentHasNoNameException(agent); else if (agentLookup.TryGetValue(agent.Name, out otheragent)) { throw new AgentAlreadyExistsException(agent, otheragent); } else { agentLookup.Add(agent.Name,agent); } } bool entityadded = OnAddEntity(xmasEntity, info); if (entityadded) { xmasEntity.Id = nextId; this.entityLookup.Add(xmasEntity.Id,xmasEntity); nextId++; EventManager.Raise(new EntityAddedEvent(xmasEntity,info.Position)); this.evtman.AddEntity(xmasEntity); xmasEntity.OnEnterWorld(); } return entityadded; }
//Override this to get all entities on the world at a specific location public override ICollection<XmasEntity> GetEntities(XmasPosition pos) { var vpos = (VacuumPosition)pos; //check if the vacuum cleaner is located at the position //then return the entity, if not give an empty collection XmasEntity[] vacuum; if (this.vacuumTiles[vpos.PosID] != null) vacuum = new XmasEntity[] { this.vacuumTiles[vpos.PosID] }; else vacuum = new XmasEntity[0]; //Check if dirt is located on the given position XmasEntity[] dirt; if (this.dirtTiles[vpos.PosID] != null) dirt = new XmasEntity[] { this.dirtTiles[vpos.PosID] }; else dirt = new XmasEntity[0]; //Concatenate the two collections of dirt and vacuum cleaner //and make them into an array for the data to be immutable return vacuum.Concat(dirt).ToArray(); }
/// <summary> /// Constructs a new EntityView /// </summary> /// <param name="model">The entity that view is meant to show</param> /// <param name="position">The position of the entity</param> /// <param name="tman">The ThreadSafeEventManager that is controlled the XmasView</param> public EntityView(XmasEntity model, XmasPosition position, ThreadSafeEventManager tman) { this.model = model; this.Position = position; eventqueue = model.ConstructEventQueue(); tman.AddEventQueue(eventqueue); }
/// <summary> /// Add an Entity action to the sequence /// </summary> /// <param name="ent">Entity the action is executed on</param> /// <param name="action">Action to be executed in the sequence</param> public void AddAction(XmasEntity ent, EntityXmasAction action) { actionQueue.Enqueue(() => { this.SetupAction(action); ent.QueueAction(action); }); }
public bool CanContain(XmasEntity xmasEntity) { foreach (XmasEntity xent in entities) { if (xent.HasModule<MovementBlockingModule>() && xent.Module<MovementBlockingModule>().IsMovementBlocking(xmasEntity)) return false; } return true; }
public MovePathAction(XmasEntity ent, Path <TileWorld, TilePosition> path, int durPerMove) { this.Path = path; foreach (TilePosition pos in path.Road) { this.AddAction(ent, new MoveAction(pos.Point, durPerMove)); } this.SingleActionCompleted += new UnaryValueHandler <XmasAction>(MovePathAction_SingleActionCompleted); this.AddRaiseActionEvent(ent); }
public MovePathAction(XmasEntity ent, Path<TileWorld, TilePosition> path, int durPerMove) { this.Path = path; foreach (TilePosition pos in path.Road) { this.AddAction(ent, new MoveAction(pos.Point, durPerMove)); } this.SingleActionCompleted += new UnaryValueHandler<XmasAction>(MovePathAction_SingleActionCompleted); this.AddRaiseActionEvent(ent); }
public LoggerEntityView(XmasEntity model , XmasPosition position , ThreadSafeEventManager evtman , Logger logstream ) : base(model, position, evtman) { this.logstream = logstream; eventqueue.Register (new Trigger<UnitMovePostEvent> (entity_UnitMovePostEvent)); eventqueue.Register (new Trigger<UnitMovePreEvent> (entity_UnitMovePreEvent)); eventqueue.Register (new Trigger<PackageGrabbedEvent> (entity_PackageGrabbedEvent)); }
//override this for the world to provide the location of the vacuum cleaner public override XmasPosition GetEntityPosition(XmasEntity xmasEntity) { //Go through each tile to see if the agent is contained within if not return the posion of -1 if (vacuumTiles[0] == xmasEntity) return new VacuumPosition(0); else if (vacuumTiles[1] == xmasEntity) return new VacuumPosition(1); //same is done for dirt else if (dirtTiles[0] == xmasEntity) return new VacuumPosition(0); else if (dirtTiles[1] == xmasEntity) return new VacuumPosition(1); else return new VacuumPosition(-1); }
//Override this to provide a way to insert the agent protected override bool OnAddEntity(XmasEntity xmasEntity, EntitySpawnInformation info) { var spawn = (VacuumSpawnInformation)info; var spawnloc = (VacuumPosition)spawn.Position; if (xmasEntity is VacuumCleanerAgent) { vacuumTiles[spawnloc.PosID] = xmasEntity as VacuumCleanerAgent; return true; } else if (xmasEntity is DirtEntity) { dirtTiles[spawnloc.PosID] = xmasEntity as DirtEntity; return true; } return false; }
//Override this to provide the ability for the world to change position of the entity public override bool SetEntityPosition(XmasEntity xmasEntity, XmasPosition tilePosition) { //This can be implemented by removing the entity from its last location and re-add it to the tile of its new position var pos = (VacuumPosition) tilePosition; var lastpos = (VacuumPosition)this.GetEntityPosition(xmasEntity); if (xmasEntity is VacuumCleanerAgent) { this.vacuumTiles[lastpos.PosID] = null; this.vacuumTiles[pos.PosID] = xmasEntity as VacuumCleanerAgent; return true; } else if (xmasEntity is DirtEntity) { this.dirtTiles[lastpos.PosID] = null; this.dirtTiles[pos.PosID] = xmasEntity as DirtEntity; return true; } return false; }
/// <summary> /// Override this method to intercept when a entity is being removed /// </summary> /// <param name="entity">The entity that is being removed</param> protected abstract void OnRemoveEntity(XmasEntity entity);
/// <summary> /// Sets the position of an entity /// </summary> /// <param name="xmasEntity">The entity which position is being set</param> /// <param name="tilePosition">The position where the entity is set</param> /// <returns>Whether or not it could be succesfully set at that position</returns> public abstract bool SetEntityPosition(XmasEntity xmasEntity, XmasPosition tilePosition);
/// <summary> /// Override this method to intercept when a entity is added /// </summary> /// <param name="xmasEntity">The entity to be added</param> /// <param name="info">information of the entity</param> /// <returns>Whether the entity could be added</returns> protected abstract bool OnAddEntity(XmasEntity xmasEntity, EntitySpawnInformation info);
/// <summary> /// Removes the entity from the EventManager /// </summary> /// <param name="xmasEntity">The entity to be removed</param> public void RemoveEntity(XmasEntity xmasEntity) { trackedEntities.Remove(xmasEntity); xmasEntity.TriggerRaised -= entity_TriggerRaised; }
/// <summary> /// Removes an entity from the engine /// </summary> /// <param name="entity">the entity to be removed</param> public void RemoveEntity(XmasEntity entity) { if (entity is Agent) { Agent agent = entity as Agent; agentLookup.Remove(agent.Name); } entityLookup.Remove (entity.Id); OnRemoveEntity(entity); EventManager.Raise(new EntityRemovedEvent(entity)); this.evtman.RemoveEntity(entity); entity.OnLeaveWorld(); }
public abstract bool IsVisionBlocking(XmasEntity entity);
/// <summary> /// Stores information on how an entity should be added when the world is being built /// </summary> /// <param name="ent">The entity to be added</param> /// <param name="info">Information on how to add the entity</param> public void AddEntity(XmasEntity ent, EntitySpawnInformation info) { buildactions.Add(new AddEntityAction(ent, info)); }
public void RemoveEntity(XmasEntity xmasEntity) { entities.Remove(xmasEntity); }
/// <summary> /// Attaches the module to an entity /// </summary> /// <param name="entityHost">The entity host the module is attached to</param> /// <param name="replacedModule">The module that the new module replaces, is null if no module was replaced</param> protected internal virtual void AttachToEntity(XmasEntity entityHost, EntityModule replacedModule) { this.entityHost = entityHost; if (replacedModule != null && replacedModule.ModuleType == this.ModuleType) this.replacedModule = replacedModule; }
public EntityException(XmasEntity xmasEntity) { this.xmasEntity = xmasEntity; }
/// <summary> /// Removes an entity from the engine /// </summary> /// <param name="entity">the entity to be removed</param> public void RemoveEntity(XmasEntity entity) { if (entity is Agent) { Agent agent = entity as Agent; agentLookup.Remove(agent.Name); } if (this.EntityRemoved != null) this.EntityRemoved(this, new UnaryValueEvent<XmasEntity>(entity)); OnRemoveEntity(entity); EventManager.Raise(new EntityRemovedEvent(entity)); this.evtman.RemoveEntity(entity); entity.OnLeaveWorld(); }
public EntityRemovedEvent(XmasEntity removedXmasEntity) { RemovedXmasEntity = removedXmasEntity; }
public AddEntityAction(XmasEntity ent, EntitySpawnInformation info) { this.ent = ent; this.info = info; }
public RemoveEntityAction(XmasEntity ent) { this.ent = ent; }
public void AddEntity(XmasEntity xmasEntity) { entities.AddFirst(xmasEntity); }
public bool IsVisionBlocking(XmasEntity xmasEntity) { return entities.Any(e => e.HasModule<VisionBlockingModule>() && e.Module<VisionBlockingModule>().IsVisionBlocking(xmasEntity)); }
/// <summary> /// Gets the position that a entity is currently at /// </summary> /// <param name="xmasEntity">The entity which position is located</param> /// <returns>The position of the entity</returns> public abstract XmasPosition GetEntityPosition(XmasEntity xmasEntity);
/// <summary> /// Adds an entity to be part of the EventManager, so all events raised on that entity is also raised on the eventmanager /// </summary> /// <param name="xmasEntity">The entity added to the eventmanager</param> public void AddEntity(XmasEntity xmasEntity) { trackedEntities.Add(xmasEntity); xmasEntity.TriggerRaised += entity_TriggerRaised; }
public EntityException(XmasEntity e, string msg) : base(msg) { xmasEntity = e; }
public Vision(Grid<Tile> grid, XmasEntity owner) { this.grid = grid; this.owner = owner; FindVisibleTiles(); }