Exemplo n.º 1
0
 public ResourceChunk GetBestChunk()
 {
     if (bestChunk != null && bestChunk.GetAmount() <= 0)
     {
         bestChunk = null;
     }
     return bestChunk;
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 4
0
        public void TakeResources(ResourceChunk chunk)
        {
            if (ResourcesFull())
            {
                return;
            }

            while (!chunk.IsDepleted() && currentResources < resourceCapacity)
            {
                currentResources += chunk.TakeChunk();
            }
        }
Exemplo n.º 5
0
        public void SetBestChunk(ResourceChunk c)
        {
            if (c == null)
            {
                return;
            }

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

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