Beispiel #1
0
        public int[] infectionSourceAgentIds; // Agents trying to infect someone

        #endregion Fields

        #region Constructors

        public GoToContainerMessage(Guid senderId, AddAgentMessage[] agents, Enums.ContainerType[] containerIds, int[] infectionSourceAgentIds, int agentCount)
            : base(senderId, MessageType.GoTo)
        {
            this.agents = agents;
            this.containerTypes = containerIds;
            this.infectionSourceAgentIds = infectionSourceAgentIds;
            this.agentCount = agentCount;
        }
Beispiel #2
0
        //private void infectOtherAgent(int sourceAgentId)
        //{
        //    if (this.agents.Count < 2)
        //    {
        //        Trace.TraceInformation("Warning: too litle agents");
        //        return;
        //    }
        //    // Random:
        //    // int idx = random.Next(0, this.agents.Count - 1);

        //    ContainersCore currentContainer = this.agentLocations[sourceAgentId];
        //    if (currentContainer == null)
        //    {
        //        Trace.TraceInformation("Warning: no current container for {0}", sourceAgentId);
        //        return;
        //    }

        //    if (currentContainer is Home)
        //    {
        //        // Trace.TraceInformation("Current container for {0} is Home", sourceAgentId);
        //        return;
        //    }

        //    if (currentContainer.AgentCount < 2)
        //    {
        //        Trace.TraceInformation("Warning: noone in container for {0}", sourceAgentId);
        //        return;
        //    }

        //    int destAgentId = sourceAgentId;
        //    while (destAgentId == sourceAgentId)
        //    {
        //        destAgentId = currentContainer.GetRandomAgent();
        //    }

        //    Guid clientId = this.agents[destAgentId];
        //    var msg0 = new Message(MessageTransportSystem.Instance.Id, MessageType.Infect);
        //    msg0.data = destAgentId.ToString();
        //    //Trace.TraceInformation("Infecting: {0} -> {1}", sourceAgentId, destAgentId);
        //    MessageTransportSystem.Instance.SendMessage(msg0, clientId);
        //}

        private void gotoContainer(AddAgentMessage amsg, Enums.ContainerType containerType)
        {
            //if (agentId == 2)
            //    Trace.TraceInformation("Go: {0} to {1} ; Time: {2}", agentId, containerId, GlobalTime.realTime);

            List<ContainersCore> containersWithType = Containers.Instance.Values.Where((c) => c.ContainerType == containerType).ToList();
            if (containersWithType.Count == 0)
            {
                Trace.TraceWarning("Warning: Container with type {0} not found", containerType);
                return;
            }

            int idx = GlobalAgentDescriptorTable.random.Next(0, containersWithType.Count - 1);
            ContainersCore container = containersWithType[idx];
            ContainersCore oldContainer = this.agentLocations[amsg.agentId];

            amsg.containerId = container.Id;

            Guid workerId = this.containers2workers[container.Id];
            // MessageTransportSystem.Instance.SendMessage(amsg, workerId);
            this.addAgentMessages[workerId].Add(amsg);

            agentLocations[amsg.agentId] = container;
        }
Beispiel #3
0
 public TickMessage(Guid senderId, AddAgentMessage[] agents)
     : base(senderId, MessageType.Tick)
 {
     this.agents = agents;
 }