Exemple #1
0
    public void deliverTo(GameObject takeFrom, GameObject bringTo, ressourceStack stack)
    {
        print(this.name + " is delivering to: " + bringTo);

        lastTarget = null;

        if (stack.getAmount() > this.GetComponent <inventory>().maxSize)
        {
            stack.setAmount(this.GetComponent <inventory>().maxSize);
        }

        if (this.GetComponent <inventory>().maxSize - this.GetComponent <inventory>().getAmount() < stack.getAmount())
        {
            Debug.Log("mover is idle and not enough inv space to deliver, emptying now (inv:)" + this.GetComponent <inventory>());
            goToBase();
            target = null;
            return;
        }

        curState = State.ConstructionDelivering;
        this.setTarget(takeFrom);
        deliverTarget = bringTo;
        deliverFrom   = takeFrom;
        delivery      = stack;
        idleTimer     = 0;

        GetComponent <movementController>().setTarget(takeFrom.transform);
    }
Exemple #2
0
    private void orderIdle()
    {
        //Debug.Log("finding idle unit to deliver things");

        reloadOrdered();
        removeEmpty(missing);
        Debug.Log("searching idles, already ordered: " + printList(ordered) + " missing: " + printList(missing));
        if (missing.Count <= 0)
        {
            return;
        }

        foreach (GameObject elem in GameObject.FindGameObjectsWithTag("dropBase"))
        {
            foreach (ressourceStack stack in missing)
            {
                if (stack.getAmount() <= 0)
                {
                    continue;
                }

                if (elem.GetComponent <inventory>().getAmount(stack.getRessource()) > .0f)
                {
                    Transform mover = GetClosestMover(GameObject.FindGameObjectsWithTag("mover"));

                    if (mover == null)
                    {
                        return;
                    }

                    Debug.Log("found valid idle mover");
                    ressourceStack take = stack.clone();

                    float takeable = elem.GetComponent <inventory>().getAmount(stack.getRessource());
                    if (takeable > mover.gameObject.GetComponent <inventory>().maxSize)
                    {
                        takeable = mover.gameObject.GetComponent <inventory>().maxSize;
                    }

                    if (stack.getAmount() <= takeable)
                    {
                        stack.setAmount(0);
                        //ordered.Add(stack);
                    }
                    else
                    {
                        stack.addAmount(-takeable);
                        take.setAmount(takeable);
                    }

                    Debug.Log("delivering to marker: " + take);
                    mover.gameObject.GetComponent <ActionController>().deliverTo(elem, this.gameObject, take);
                }
            }
        }
    }