Example #1
0
        protected bool MoveOrRotateOrDig(ISimulationWorld isw, KeyValuePair <int, int> where)
        {// nie chce mi sie obrotu zrobic do kopania..
            Tile t = isw.GetMap().GetTile(where.Key, where.Value);

            if (t.TileType == TileType.Wall)
            {// destroy wall nie ma zabawy z regionami
                if (this.IsMoveOrRotate(where))
                {
                    isw.GetMap().DestroyWall(t);
                }
                return(false);
            }
            return(MoveOrRotate(where));
        }
Example #2
0
        protected void MoveRandomly(ISimulationWorld isw)
        {
            randomMovementCount++;

            if (randomMovementCount < currentTrail.Count)
            {
                if ((this.Position.X == currentTrail[randomMovementCount].Key) && (this.Position.Y == currentTrail[randomMovementCount].Value))
                {
                    randomMovementCount++;
                }
            }

            if ((randomMovementCount >= currentTrail.Count) || (randomDestination.X < 0))
            {
                randomMovementCount = 0;
                randomDestination   = new Position(isw.GetMap().GetRandomIndoorOrOutdoorTile().Position);
                currentTrail        = Astar.Search(new KeyValuePair <int, int>(this.Position.X, this.Position.Y),
                                                   new KeyValuePair <int, int>(randomDestination.X, randomDestination.Y),
                                                   new AstarOtherObject());
            }
            if (currentTrail == null)
            {
                randomDestination.X = -1;
                return;
            }
            if (currentTrail.Count <= 1)
            {
                randomDestination.X = -1;
                return;
            }
            if (!MoveOrRotate(currentTrail[randomMovementCount]))
            {
                randomMovementCount--;
            }
            if (randomMovementCount >= 10)
            {
                randomDestination.X = -1;
            }
        }
Example #3
0
        /*
         * private int GetPointIndex(int x, int y)
         * {
         *  LIList<PointWithIntensity>.Enumerator e = points.GetEnumerator();
         *  int i = 0;
         *  while (e.MoveNext())
         *  {
         *      Tile t = e.Current.Tile;
         *      if (t.Position.X == x && t.Position.Y == y)
         *          return i;
         *      i++;
         *  }
         *  return -1;
         * }
         */

        public override bool Maintain(ISimulationWorld isw)
        {
            LinkedListNode <PointWithIntensity> msg = points.First;
            LinkedListNode <PointWithIntensity> msgT;

            while (msg != null)
            {
                if (--msg.Value.Intensity <= 0)
                {
                    isw.GetMap().RemoveMessage(this.GetMessageType, msg.Value.Tile.Position);
                    msg.Value.Tile.messages.Remove(this);

                    msgT = msg;
                    msg  = msg.Next;
                    points.Remove(msgT);
                }
                else
                {
                    msg = msg.Next;
                }
            }
            return(true);
        }
Example #4
0
        public void Spread(ISimulationWorld isw, Position point, int intensity)
        {
            int      radius = AntHillConfig.messageRadius, radius2 = radius * radius;
            int      i2, j2;
            Map      map = isw.GetMap();
            Tile     t;
            Position p;

            for (int i = -radius; i <= radius; i++)
            {
                i2 = i * i;
                for (int j = -radius; j <= radius; j++)
                {
                    j2 = j * j;
                    if (i2 + j2 <= radius2)
                    {
                        p = new Position(i + point.X, j + point.Y);
                        if (map.IsInside(p))
                        {// czy wogole w srodku
                            t = map.GetTile(p);
                            if (t.TileType == TileType.Wall)
                            {
                                continue;
                            }
                            if (!t.messages.Contains(this))
                            {// nie ma w danym tile - wrzucamy
                                t.messages.AddLast(this);
                                this.points.AddLast(new PointWithIntensity(t, intensity));
                                //update map
                                map.AddMessage(this.GetMessageType, p);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public override bool Maintain(ISimulationWorld isw)
        {
            if (--timeToLive < 0)
            {
                isw.DeleteRain();
                return(false);
            }

            LIList <Food>    lFood    = isw.GetVisibleFood(this);
            LIList <Ant>     lAnt     = isw.GetVisibleAnts(this);
            LIList <Spider>  lSpider  = isw.GetVisibleSpiders(this);
            LIList <Message> lMessage = isw.GetVisibleMessages(this);

            while (lFood.Count > 0)
            {
                isw.DeleteFood(lFood.First.Value);
                lFood.RemoveFirst();
            }

            while (lAnt.Count > 0)
            {
                isw.DeleteAnt(lAnt.First.Value);
                lAnt.RemoveFirst();
            }
            while (lSpider.Count > 0)
            {
                isw.DeleteSpider(lSpider.First.Value);
                lSpider.RemoveFirst();
            }

            Map map = isw.GetMap();

            if (lMessage != null)
            {
                LinkedListNode <Message>            enumMsg = lMessage.First;
                LinkedListNode <PointWithIntensity> enumPwI, enumPwItemp;
                while (enumMsg != null)
                {
                    enumPwI = enumMsg.Value.Points.First;
                    while (enumPwI != null)
                    {
                        if (IsRainOver(enumPwI.Value.Position))
                        {
                            map.RemoveMessage(enumMsg.Value.GetMessageType, enumPwI.Value.Position);
                            enumPwItemp = enumPwI;
                            enumPwI     = enumPwI.Next;
                            enumMsg.Value.Points.Remove(enumPwItemp);
                        }
                        else
                        {
                            enumPwI = enumPwI.Next;
                        }
                    }
                    enumMsg = enumMsg.Next;
                }
            }

            // Rain is always on the map
            for (int i = 0; i < AntHillConfig.rainWidth; i++)     // && i+this.Position.X < map.Width; i++)
            {
                for (int j = 0; j < AntHillConfig.rainWidth; j++) // && j+this.Position.Y < map.Height; j++)
                {
                    map.GetTile(this.Position.X + i, this.Position.Y + j).messages.Clear();
                }
            }
            return(true);
        }
Example #6
0
 public void Dig(ISimulationWorld isw, Position pos)
 {
     isw.GetMap().DestroyWall(isw.GetMap().GetTile(pos));
 }