Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
    //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();
    }
Beispiel #3
0
 /// <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);
 }
Beispiel #4
0
        /// <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);

                });
        }
Beispiel #5
0
 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));
        }
Beispiel #9
0
    //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);
    }
Beispiel #10
0
    //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;
    }
Beispiel #11
0
 //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;
 }
Beispiel #12
0
 /// <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);
Beispiel #13
0
 /// <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);
Beispiel #14
0
 /// <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);
Beispiel #15
0
        /// <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;
        }
Beispiel #16
0
        /// <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));
 }
Beispiel #19
0
 public void RemoveEntity(XmasEntity xmasEntity)
 {
     entities.Remove(xmasEntity);
 }
Beispiel #20
0
        /// <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;
        }
Beispiel #21
0
 public EntityException(XmasEntity xmasEntity)
 {
     this.xmasEntity = xmasEntity;
 }
Beispiel #22
0
        /// <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;
 }
Beispiel #24
0
 public AddEntityAction(XmasEntity ent, EntitySpawnInformation info)
 {
     this.ent = ent;
     this.info = info;
 }
 public RemoveEntityAction(XmasEntity ent)
 {
     this.ent = ent;
 }
Beispiel #26
0
 public void AddEntity(XmasEntity xmasEntity)
 {
     entities.AddFirst(xmasEntity);
 }
Beispiel #27
0
 public bool IsVisionBlocking(XmasEntity xmasEntity)
 {
     return entities.Any(e => e.HasModule<VisionBlockingModule>() && e.Module<VisionBlockingModule>().IsVisionBlocking(xmasEntity));
 }
Beispiel #28
0
 /// <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);
Beispiel #29
0
        /// <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;
        }
Beispiel #30
0
 public EntityException(XmasEntity e, string msg)
     : base(msg)
 {
     xmasEntity = e;
 }
Beispiel #31
0
 public Vision(Grid<Tile> grid, XmasEntity owner)
 {
     this.grid = grid;
     this.owner = owner;
     FindVisibleTiles();
 }