Exemplo n.º 1
0
        public int reserveSlot(Zombie z)
        {
            moveme decision = calculateSlotPositiion(z);

            if (decision.move)//if good value returned
            {
                subscribe(z);
                z.Notify(decision.pos + Position);
                return(decision.slot);
            }
            return(-1);
        }
        private moveme calculateSlotPositiion(Entity ent)
        {
            //finding slot positions.
            moveme decision = new moveme();

            if (Observers.Count == 0)//if first in list, give him ideal position
            {
                //give new slot at shortest distace
                decision.move = true;
                decision.pos = Vector3.Normalize(ent.Position - Position) * attackdist;

                //reset nodes
                float angle = (float)Math.Atan((ent.Position - Position).Z / (ent.Position - Position).X);

                slots[0].po = new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)) * attackdist;
                slots[1].po = new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(60)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(60))) * attackdist;
                slots[2].po = new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(120)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(120))) * attackdist;
                slots[3].po = -new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)) * attackdist;
                slots[4].po = -new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(60)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(60))) * attackdist;
                slots[5].po = -new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(120)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(120))) * attackdist;

                //set node to right state
                slots[0].occ = true;
                decision.slot = 0;
            }
            else if (Observers.Count > 6)//too many zombies, refuse
            {
                decision.move = false;
            }
            else
            {
                int start = Observers.Last().Targetslot();

                if (!slots[((start + 2)) % 6].occ)
                {
                    slots[((start + 2) % 6)].occ = true;
                    decision.slot = ((start + 2) % 6);

                    decision.move = true;
                    decision.pos = slots[((start + 2) % 6)].po;
                }
                else if (!slots[((start + 4)) % 6].occ)//first try not open go on
                {
                    slots[((start + 4) % 6)].occ = true;
                    decision.slot = ((start + 4) % 6);

                    decision.move = true;
                    decision.pos = slots[((start + 4) % 6)].po;
                }
                else if (!slots[((start + 3)) % 6].occ)
                {
                    slots[((start + 3) % 6)].occ = true;
                    decision.slot = ((start + 3) % 6);

                    decision.move = true;
                    decision.pos = slots[((start + 3) % 6)].po;
                }
                else if (!slots[((start + 5)) % 6].occ)
                {
                    slots[((start + 5) % 6)].occ = true;
                    decision.slot = ((start + 5) % 6);

                    decision.move = true;
                    decision.pos = slots[((start + 5) % 6)].po;
                }
                else if (!slots[((start + 1)) % 6].occ)
                {
                    slots[((start + 1) % 6)].occ = true;
                    decision.slot = ((start + 1) % 6);

                    decision.move = true;
                    decision.pos = slots[((start + 1) % 6)].po;
                }
                else
                {
                    //absolutely no solution get ouyt.
                    decision.move = false;
                }
            }

            return decision;
        }
Exemplo n.º 3
0
        private moveme calculateSlotPositiion(Entity ent)
        {
            //finding slot positions.
            moveme decision = new moveme();

            if (Observers.Count == 0)//if first in list, give him ideal position
            {
                //give new slot at shortest distace
                decision.move = true;
                decision.pos  = Vector3.Normalize(ent.Position - Position) * attackdist;

                //reset nodes
                float angle = (float)Math.Atan((ent.Position - Position).Z / (ent.Position - Position).X);

                slots[0].po = new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)) * attackdist;
                slots[1].po = new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(60)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(60))) * attackdist;
                slots[2].po = new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(120)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(120))) * attackdist;
                slots[3].po = -new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)) * attackdist;
                slots[4].po = -new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(60)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(60))) * attackdist;
                slots[5].po = -new Vector3((float)Math.Sin(angle + MathHelper.ToRadians(120)), 0, (float)Math.Cos(angle + MathHelper.ToRadians(120))) * attackdist;

                //set node to right state
                slots[0].occ  = true;
                decision.slot = 0;
            }
            else if (Observers.Count > 6)//too many zombies, refuse
            {
                decision.move = false;
            }
            else
            {
                int start = Observers.Last().Targetslot();

                if (!slots[((start + 2)) % 6].occ)
                {
                    slots[((start + 2) % 6)].occ = true;
                    decision.slot = ((start + 2) % 6);

                    decision.move = true;
                    decision.pos  = slots[((start + 2) % 6)].po;
                }
                else if (!slots[((start + 4)) % 6].occ)//first try not open go on
                {
                    slots[((start + 4) % 6)].occ = true;
                    decision.slot = ((start + 4) % 6);

                    decision.move = true;
                    decision.pos  = slots[((start + 4) % 6)].po;
                }
                else if (!slots[((start + 3)) % 6].occ)
                {
                    slots[((start + 3) % 6)].occ = true;
                    decision.slot = ((start + 3) % 6);

                    decision.move = true;
                    decision.pos  = slots[((start + 3) % 6)].po;
                }
                else if (!slots[((start + 5)) % 6].occ)
                {
                    slots[((start + 5) % 6)].occ = true;
                    decision.slot = ((start + 5) % 6);

                    decision.move = true;
                    decision.pos  = slots[((start + 5) % 6)].po;
                }
                else if (!slots[((start + 1)) % 6].occ)
                {
                    slots[((start + 1) % 6)].occ = true;
                    decision.slot = ((start + 1) % 6);

                    decision.move = true;
                    decision.pos  = slots[((start + 1) % 6)].po;
                }
                else
                {
                    //absolutely no solution get ouyt.
                    decision.move = false;
                }
            }

            return(decision);
        }