Пример #1
0
 public ResourceChunk GetBestChunk()
 {
     if (bestChunk != null && bestChunk.GetAmount() <= 0)
     {
         bestChunk = null;
     }
     return bestChunk;
 }
Пример #2
0
        public bool ShouldTakeControl()
        {
            for (int i = 0; i < unit.GetVisibleObjects().GetCount(); i++)
            {
                GameObject g = unit.GetVisibleObjects()[i];
                ResourceChunk c = g as ResourceChunk;
                if (c != null)
                {
                    if (GameMath.TestCircleCircle(unit.GetBounds(), c.GetBounds()) && !c.IsDepleted() && !unit.ResourcesFull())
                    {
                        desiredChunk = c;
                        return true;
                    }
                }
            }

            return false;
        }
Пример #3
0
        public bool ShouldTakeControl()
        {
            if (unit.ResourcesFull())
            {
                return false;
            }

            //If we can see a resource chunk, go to it
            for (int i = 0; i < unit.GetVisibleObjects().GetCount(); i++)
            {
                GameObject g = unit.GetVisibleObjects()[i];
                ResourceChunk c = g as ResourceChunk;
                if (c != null)
                {
                    if (GameMath.TestCircleCircle(unit.GetViewCircle(), c.GetBounds()))
                    {
                        desiredChunk = c;
                        //We'll send out a message that we've found resources
                        unit.AddMessage(new FoundResourceMessage(unit, desiredChunk));
                        return true;
                    }
                }
            }

            //Else, if we've received info from a teammate that there are resources around...
            Buffer<Message> inbox = unit.GetInbox();
            for (int i = 0; i < inbox.GetCount(); i++)
            {
                FoundResourceMessage frm = inbox[i] as FoundResourceMessage;
                if (frm != null)
                {
                    desiredChunk = frm.GetChunk();
                    unit.SetBestChunk(desiredChunk);
                    return true;
                }
            }

            return false;
        }
Пример #4
0
        public void TakeResources(ResourceChunk chunk)
        {
            if (ResourcesFull())
            {
                return;
            }

            while (!chunk.IsDepleted() && currentResources < resourceCapacity)
            {
                currentResources += chunk.TakeChunk();
            }
        }
Пример #5
0
        public void SetBestChunk(ResourceChunk c)
        {
            if (c == null)
            {
                return;
            }

            if (bestChunk == null)
            {
                bestChunk = c;
                return;
            }

            if (c.GetAmount() > bestChunk.GetAmount())
            {
                bestChunk = c;
            }
        }