Пример #1
0
        private void onAddAgentMessage(Message message, ContainersCore container = null)
        {
            AddAgentMessage aaMessage = (AddAgentMessage)message;
            List<IAgent> ags = new List<IAgent>();
            GlobalAgentDescriptorTable.GetNewId = aaMessage.agentId;
            switch (aaMessage.agentType)
            {
                case "Adolescent":
                    ags.AddRange(Adolescent.AdolescentList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                    break;
                case "Adult":
                    ags.AddRange(Adult.AdultList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                    break;
                case "Child":
                    ags.AddRange(Child.ChildList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                    break;
                case "Elder":
                    ags.AddRange(Elder.ElderList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                    break;
                case "Youngster":
                    ags.AddRange(Youngster.YoungsterList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                    break;
            }
            foreach(IAgent a in ags)
            {
                if (container == null)
                {
                    int containerId = aaMessage.containerId;
                    if (containerId > 0)
                    {
                        if (Containers.Instance.ContainsKey(containerId))
                        {
                            var foundContainer = Containers.Instance[containerId];

                            AbstractPerson ap = (AbstractPerson)a;
                            ap.currentContainerId = containerId;
                            ap.currentContainerType = foundContainer.ContainerType;
                        }
                        else
                        {
                            Trace.TraceWarning("Agent was added to moved to another node container. Moving him again");
                            CoreAMS.MessageTransportSystem.MessageTransfer.Instance.AddToGoto((AbstractPerson)a, Enums.ContainerType.Home);
                        }
                    }
                }
                else
                {
                    AbstractPerson ap = (AbstractPerson)a;
                    ap.currentContainerId = container.Id;
                    ap.currentContainerType = container.ContainerType;
                }
            }
            GlobalAgentDescriptorTable.AddAgents(ags);
            //foreach (var ag in ags) {
            //    Trace.TraceInformation("Added agent with id {0} (check: {1})", ag.GetId(), aaMessage.agentId);
            //}
        }
Пример #2
0
        public void MoveContainer(ContainersCore container)
        {
            Trace.TraceInformation("Going to move container {0} ({1})", container.Id, container.ContainerType);

            var agents = GlobalAgentDescriptorTable.PersonsInContainer(container.Id);
            Trace.TraceInformation("Going to move container agents: {0}", String.Join(", ", agents.Select(a => a.GetId())));

            AddContainerMessage msg = new AddContainerMessage(
                this.transportSystem.Id,
                container.ContainerType,
                container.Id,
                container.Area,
                container.Dencity
            );
            msg.agentData.AddRange(agents.Select(a => new AddAgentMessage(
                this.transportSystem.Id,
                a.GetType().Name,
                a.GetId(),
                a.GetHealthState(),
                1
                )));

            this.moveContainerMessage = msg;
        }