Example #1
0
 //This code is called by an attacking sentient upon the victim sentient
 // should always be used like x.addToAttackers(this);
 public void addToAttackers(Sentient s)
 {
     if (!attackers.Contains(s))
     {
         attackers.Enqueue(s);
     }
     if (!Fighting)
     {
         target   = attackers.Dequeue();
         Fighting = true;
     }
 }
Example #2
0
 private void frmSim_Load(object sender, EventArgs e)
 {
     Buildings    = new LinkedList <Building>();
     Sentients    = new LinkedList <Sentient>();
     FormControls = new frmControls();
     rnd          = new Random();
     InitializeDrawArea();
     this.BackgroundImage = DrawArea;
     genBuildings(rnd.Next(MINBUILDINGS, MAXBUILDINGS));
     genSentients(rnd.Next(MINSENTIENTS, MAXSENTIENTS));
     Sentient.setLists(Sentients, Buildings);
     this.DoubleBuffered = true;
 }
Example #3
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;
             * }
             */
        }
Example #4
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;
            }
             */
        }
Example #5
0
 //This code is called by an attacking sentient upon the victim sentient
 // should always be used like x.addToAttackers(this);
 public void addToAttackers(Sentient s)
 {
     if(!attackers.Contains(s))
         attackers.Enqueue(s);
     if (!Fighting)
     {
         target = attackers.Dequeue();
         Fighting = true;
     }
 }