Exemple #1
0
        //Remove references from other sentients
        //Possible places there might be a reference are:
        // A sentient's target
        // A sentient's attacker
        public static void removeReference(Sentient s)
        {
            if (s == null)
            {
                return;
            }

            LinkedListNode <Sentient> sn = Sentients.First;

            while (sn != null)
            {
                Sentient snv = sn.Value;
                if (!snv.Equals(s))
                {
                    if (snv.target != null && snv.target.Equals(s))
                    {
                        snv.target = null;
                    }
                    if (snv.attackers.Contains(s))
                    {
                        if (snv.attackers.Contains(s))
                        {
                            int      c = snv.attackers.Count;
                            Sentient x;
                            for (int i = 0; i < c; i++)
                            {
                                x = snv.attackers.Dequeue();
                                if (!x.Equals(s))
                                {
                                    snv.attackers.Enqueue(x);
                                }
                            }
                        }
                    }
                }
                sn = sn.Next;
            }

            /*
             * try
             * {
             *  if (target.Equals(s))
             *  {
             *      target = null;
             *      Fighting = false;
             *  }
             *  else
             *  {
             *      //loop through attackers, dequeuing everyone, and requeuing everyone but
             *      //the one being removed
             *      if (attackers.Contains(s))
             *      {
             *          int c = attackers.Count;
             *          Sentient x;
             *          for (int i = 0; i < c; i++)
             *          {
             *              x = attackers.Dequeue();
             *              if (x != s)
             *                  attackers.Enqueue(x);
             *          }
             *      }
             *  }
             * }
             * catch (Exception ex)
             * {
             *  //I'm sorry
             *  string m = ex.Message;
             * }
             */
        }