Exemplo n.º 1
0
 public override void Action()
 {
     time++;
     //This timer might be awfully ugly
     if (time > _transaction_duration)
     {
         AgentTicketOffice agent  = _stateMachine.Agent as AgentTicketOffice;
         Ticket            ticket = Environment.GetInstance().environment.RequestSeat((agent.askForTicket.Type as MessageAskForTicket).door);
         agent.receivedAskForTicket = false;
         if (ticket != null)
         {
             agent.SendMessage(agent.queue.Pop(), new MessageGiveTicket(ticket));
             agent.transactionFinished = true;
         }
         else
         {
             List <int> availableCategories =
                 Environment.GetInstance().environment.StillAvailableCategories((agent.queue.First() as AgentSpectator).side);
             agent.SendMessage(agent.queue.First(), new MessageNoTicketAvailable(availableCategories, (agent.askForTicket.Type as MessageAskForTicket).door));
             //No seat available, the transaction is finished
             if (availableCategories.Count == 0)
             {
                 agent.queue.Pop(); //Eliminate the first agent in the queue
                 agent.transactionFinished = true;
             }
         }
     }
 }
Exemplo n.º 2
0
        public StateTicketOfficeGiveTicket(StateMachine stateMachine, Agent agent) : base(stateMachine)
        {
            _transaction_duration = Environment.GetInstance().settings.timeToBuyTicket * 50; // 50 is the number of frames in 1 sec
            _agent = agent;
            AgentTicketOffice ato = _stateMachine.Agent as AgentTicketOffice;

            ato.transactionFinished = false;
        }
        public override State Next()
        {
            State             res   = this;
            AgentTicketOffice agent = _stateMachine.Agent as AgentTicketOffice;

            if (agent.receivedAskForTicket)
            {
                Agent firstAgentInQueue = agent.queue.First();
                res = new StateTicketOfficeGiveTicket(_stateMachine, firstAgentInQueue);
            }
            return(res);
        }
Exemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        _updateCycle        = 200;
        _updateTime         = 0;
        _ticketOfficesTimes = new Dictionary <AgentTicketOffice, float>();

        foreach (var a in Environment.GetInstance().Brain.Agents)
        {
            AgentTicketOffice ato = a.Value as AgentTicketOffice;
            if (ato != null)
            {
                _ticketOfficesTimes.Add(ato, 0);
            }
        }

        _panelSeats = GameObject.Find("RightPanel");
    }
 private void OnTriggerExit(Collider other)
 {
     if (other.tag == "Counter")
     {
         AgentTicketOffice exited = other.transform.parent.GetComponent <AgentBody>().agent as AgentTicketOffice;
         if (_ticketOfficeInLineOfVision.Contains(exited))
         {
             _ticketOfficeInLineOfVision.Remove(exited);
         }
     }
     else if (other.tag == "Security")
     {
         AgentSecurity exited = other.transform.GetComponent <AgentBody>().agent as AgentSecurity;
         if (_securityInLineOfVision.Contains(exited))
         {
             _securityInLineOfVision.Remove(exited);
         }
     }
 }
Exemplo n.º 6
0
    private void ListStats()
    {
        if (_updateTime == _updateCycle)
        {
            foreach (var a in Environment.GetInstance().Brain.Agents)
            {
                AgentTicketOffice ato = a.Value as AgentTicketOffice;
                if (ato != null)
                {
                    float avgTime = 0;
                    int   count   = 0;
                    foreach (float f in ato.times)
                    {
                        count++;
                        avgTime += f;
                    }

                    if (count > 0)
                    {
                        avgTime = avgTime / (count + 0.0f);
                    }

                    _ticketOfficesTimes[ato] = avgTime;
                }
            }

            _avgInstallationTime = 0f;
            List <float> times = Environment.GetInstance().Brain.timesToSitInStadium;
            foreach (float f in times)
            {
                _avgInstallationTime += f;
            }
            _avgInstallationTime = _avgInstallationTime / times.Count;
        }

        foreach (var a in _ticketOfficesTimes)
        {
            AddText(a.Key.Name + " : " + a.Value);
        }

        AddText("Avg time to sit in stadium : " + _avgInstallationTime);
    }
Exemplo n.º 7
0
        public override State Next()
        {
            AgentTicketOffice agent = _stateMachine.Agent as AgentTicketOffice;
            State             res   = this;

            if (time > _transaction_duration && agent.transactionFinished)
            {
                //Envoyer la nouvelle position à tout le monde
                foreach (Agent a in agent.queue.agents)
                {
                    agent.SendMessage(a, new MessageSendQueuePosition(agent.queue.GetPositionForAgent(a), agent.queue.GetNumberInQueueForAgent(a)));
                }
                res = new StateTicketOfficeWaiting(_stateMachine);
            }
            else if (time > _transaction_duration)
            {
                time = 0;
            }
            return(res);
        }
        public StateGoToTicketOffice(StateMachine stateMachine) : base(stateMachine)
        {
            List <AgentTicketOffice> ticketOfficesAgent =
                (_stateMachine.Agent.Body as AgentSpectatorBody).ticketOfficeInLineOfVision;

            int minAgents = -1;
            AgentTicketOffice selectedTicketOffice = null;

            foreach (AgentTicketOffice ato in ticketOfficesAgent)
            {
                int agents = ato.queue.agents.Count;
                if (agents < minAgents || minAgents == -1)
                {
                    selectedTicketOffice = ato;
                    minAgents            = agents;
                }
            }

            _target = selectedTicketOffice;
            _stateMachine.Agent.SendMessage(_target, new MessageAskForQueue());
        }
Exemplo n.º 9
0
        /// <summary>
        /// Main cycle of brain execution
        /// </summary>
        public void Loop()
        {
            //Kill agents
            foreach (Agent a in _askedForASuicide)
            {
                Guid agent;
                foreach (KeyValuePair <Guid, Agent> kvp in _agents)
                {
                    if (kvp.Value == a)
                    {
                        agent = kvp.Key;
                    }
                }

                _agents.Remove(agent);
            }
            _askedForASuicide.Clear();

            //Deactivate agents
            foreach (Agent a in _askedForDeactivation)
            {
                Guid agent;
                foreach (KeyValuePair <Guid, Agent> kvp in _agents)
                {
                    if (kvp.Value == a)
                    {
                        agent = kvp.Key;
                    }
                }
                Agent agentToRemove = _agents[agent];
                _deactivatedAgents.Add(agent, agentToRemove);
                _agents.Remove(agent);
            }
            _askedForDeactivation.Clear();

            //Reactivate agent
            foreach (Agent a in _askedForReactivation)
            {
                Guid agent;
                foreach (KeyValuePair <Guid, Agent> kvp in _deactivatedAgents)
                {
                    if (kvp.Value == a)
                    {
                        agent = kvp.Key;
                    }
                }

                _agents.Add(agent, _deactivatedAgents[agent]);
                _deactivatedAgents.Remove(agent);
            }
            _askedForReactivation.Clear();

            foreach (KeyValuePair <Guid, Agent> a in _agents)
            {
                a.Value.StateMachine.Action();
            }

            //Every ten seconds
            if (Time.frameCount % 500 == 0)
            {
                foreach (KeyValuePair <Guid, Agent> a in _agents)
                {
                    AgentTicketOffice ato = a.Value as AgentTicketOffice;
                    if (ato != null)
                    {
                        ato.queue.peoplesInQueue.Add(ato.queue.agents.Count);
                    }
                    AgentSecurity sec = a.Value as AgentSecurity;
                    if (sec != null)
                    {
                        sec.queue.peoplesInQueue.Add(sec.queue.agents.Count);
                    }
                }
            }
        }
 public TicketOfficeStateMachine(AgentTicketOffice agent) : base(agent)
 {
     _current = new StateTicketOfficeWaiting(this);
 }
 public StateSpectatorFollowQueue(StateMachine stateMachine, AgentTicketOffice ticketOffice) : base(stateMachine)
 {
     (_stateMachine.Agent as AgentSpectator).timeEnterTicketOfficeQueue = Time.time;
     _askedForTicket = false;
     _ticketOffice   = ticketOffice;
 }