Ejemplo n.º 1
0
    void Update()
    {
        if (locatedResource == null || !locatedResource.CanStore(resourceType))
        {
            locatedResource = FindClosestResource();
        }
        if (locatedStorage == null)
        {
            locatedStorage = FindClosestStorage();
        }

        if (state == State.IDLE)
        {
            DetermineState();
        }

        switch (state)
        {
        case State.COMMANDED:
            CommandedActions();
            break;

        case State.TRAVELLING:
            MoveTowardsTarget();
            break;

        case State.HARVESTING:
            HarvestResource();
            break;

        case State.DELIVERING:
            DeliverResource();
            break;
        }
    }
Ejemplo n.º 2
0
    public int AddResourceFrom(Resource.Type type, int value, ref ResourceStorage other)
    {
        if (other.CanStore(type))
        {
            stores[StoreIndexOf(type)].currAmount += value;
            return(-value);
        }

        return(0);
    }
Ejemplo n.º 3
0
    void DetermineState()
    {
        if (!deliveryComplete)
        {
            state = State.DELIVERING;
            return;
        }

        // If gather cannot store resource
        if (!inventory.CanStore(resourceType))
        {
            if (locatedStorage == null)
            {
                state = State.SEARCHING_DELIVERY;
            }
            else
            {
                if (moveable.InRangeOf(locatedStorage.gameObject))
                {
                    // If we are in range of the storage place
                    state            = State.DELIVERING;
                    deliveryComplete = false;
                }
                else
                {
                    state          = State.TRAVELLING;
                    locatedStorage = FindClosestStorage();
                    moveable.SetTarget(locatedStorage.transform.position);
                }
            }
        }
        else
        {
            // If we have space to store resources
            if (locatedResource == null)
            {
                state = State.SEARCHING_RESOURCE;
            }
            else
            {
                if (moveable.InRangeOf(locatedResource.gameObject))
                {
                    // If we are in range of the resource we want
                    state = State.HARVESTING;
                }
                else
                {
                    // Otherwise, set the target to the resource
                    state = State.TRAVELLING;
                    moveable.SetTarget(locatedResource.transform.position);
                }
            }
        }
    }