Exemple #1
0
 public void directMessage(uint receiverId, string text)
 {
     Comm.directMessage(Comm.SATELLITE, receiverId, text);
 }
Exemple #2
0
 public void broadcastMessage(string text)
 {
     Comm.broadcastMessage(Comm.SATELLITE, text);
 }
Exemple #3
0
        public static void update(float frameTime)
        {
            Comm    comm = Instance();
            Vector3 robotPosition;

            lock (comm.listMutex)
            {
                // Update direct message travel distances
                CommMessage msg;
                GameObject  msgIndicator;
                foreach (KeyValuePair <uint, CommMessage> p in comm.activeMsgs)
                {
                    if (p.Value.receiverId != RECEIVER_ALL)
                    {
                        msg = p.Value;
                        msg.distanceTraveled += frameTime * msg.propagationSpeed;

                        if (msg.receiverId == SATELLITE)
                        {
                            if (comm.mainScript.getSatellitePosition(out robotPosition) &&
                                Vector3.Distance(msg.origin, robotPosition) <= msg.distanceTraveled)
                            {
                                comm.msgsToBeDelivered.Add(new KeyValuePair <uint, uint>(msg.id, msg.receiverId));
                                comm.msgsToBeDeleted.Add(msg.id);
                            }
                        }
                        else
                        {
                            if (comm.mainScript.getRobotPosition(msg.receiverId, out robotPosition) &&
                                Vector3.Distance(msg.origin, robotPosition) <= msg.distanceTraveled)
                            {
                                comm.msgsToBeDelivered.Add(new KeyValuePair <uint, uint>(msg.id, msg.receiverId));
                                comm.msgsToBeDeleted.Add(msg.id);
                            }
                        }

                        if (comm.activeMsgIndicators.TryGetValue(msg.id, out msgIndicator))
                        {
                            Vector3 msgScale = new Vector3();
                            msgScale.x = msg.distanceTraveled * 2.0f;
                            msgScale.y = msg.distanceTraveled * 2.0f;
                            msgScale.z = msg.distanceTraveled * 2.0f;
                            msgIndicator.transform.localScale = msgScale;
                        }
                    }
                }

                // Deliver messages that have reached (one of) their receiver(s)
                foreach (KeyValuePair <uint, uint> p in comm.msgsToBeDelivered) // TODO specify what the key and value is
                {
                    comm.deliverMessage(p.Key, p.Value);
                }

                comm.msgsToBeDelivered.Clear();

                // Delete direct messages that have been delivered to all recipients, or any message
                // that has exceeded its travel distance
                GameObject g;
                foreach (uint id in comm.msgsToBeDeleted)
                {
                    comm.activeMsgs.Remove(id);
                    if (comm.activeMsgIndicators.TryGetValue(id, out g))
                    {
                        comm.activeMsgIndicators.Remove(id);
                        Object.Destroy(g);
                    }
                }
            }
        }