Ejemplo n.º 1
0
    public static void deliverTo(GameObject to, bool important, ressources kind)
    {
        print("got deliver request: to=" + to + " important=" + important + " kind=" + kind);

        //get closest worker
        GameObject[] movers = GameObject.FindGameObjectsWithTag("mover");
        Transform    mover  = harvestableRessource.GetClosestMover(movers, !important, to.transform);

        //stop if no worker has been found
        if (mover == null)
        {
            print("no mover found!");
            return;
        }

        //find container with the ressource kind
        var results = GameObject.FindGameObjectsWithTag("dropBase");

        foreach (var obj in results)
        {
            //check if res has kind, if true then order worker to deliver it and stop
            if (obj.GetComponent <inventory>().getAmount(kind) > 1)
            {
                var stack = new ressourceStack(obj.GetComponent <inventory>().getAmount(kind), kind);
                mover.GetComponent <ActionController>().deliverTo(obj, to, stack);
                print("handled delivery request successfully");
                return;
            }
        }

        print("unable to handle request!");
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Start is called on the frame when a script is enabled just before
    /// any of the Update methods is called the first time.
    /// </summary>
    public override void Start()
    {
        base.Start();
        var patches = GameObject.FindObjectsOfType <deepRessource>();

        print("starting deepDrill script, #patches: " + patches.Length);

        GameObject res  = null;
        var        dist = float.MaxValue;

        foreach (var elem in patches)
        {
            var d = Vector3.Distance(elem.gameObject.transform.position, this.gameObject.transform.position);
            if (d < dist)
            {
                dist = d;
                res  = elem.gameObject;
            }
        }

        ingot = res.GetComponent <HPHandler>().type;
        if (res.GetComponent <deepRessource>().activeDrill != null)
        {
            return;
        }
        mineralPatch = res;
        res.GetComponent <deepRessource>().activeDrill = this.gameObject;
    }
Ejemplo n.º 3
0
    public void handleDeserialization(SaveLoad.SerializationInfo info)
    {
        serializationData data = (serializationData)info;

        print("deserilazing HP handler..., HP=" + data.HP);
        this.HP        = data.HP;
        this.initialHP = data.initialHP;
        this.type      = data.type;
    }
Ejemplo n.º 4
0
        public bool isSame(GameObject origin, GameObject target, ressources type)
        {
            if (origin == this.origin && target == this.target && type == this.type)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
    public static void addRoute(GameObject origin, GameObject target, ressources type)
    {
        if (routeExists(origin, target))
        {
            return;
        }

        routes.Add(new routeSolotype(origin, target, type));
        Debug.Log("created new route from " + origin.name + " to" + target.name + " with kind " + type);
    }
Ejemplo n.º 6
0
    public void transferSafe(inventory target, ressources item)
    {
        var amount = newContent[item];

        if (amount > target.getFreeSpace())
        {
            amount = target.getFreeSpace();
        }

        target.newContent[item] += amount;
        this.newContent[item]   -= amount;
    }
Ejemplo n.º 7
0
    public static float getAmoumt(ressources res)
    {
        int i = 0;

        foreach (ressources cur in System.Enum.GetValues(typeof(ressources)))
        {
            if (res.Equals(cur))
            {
                return(getInstance().totalRessources[i]);
            }
            i++;
        }
        return(0);
    }
Ejemplo n.º 8
0
    public static bool deleteRoute(GameObject origin, GameObject target, ressources type)
    {
        Debug.Log("deleting route...");
        foreach (routeSolotype route in routes)
        {
            if (route.isSame(origin, target, type))
            {
                routes.Remove(route);
                Debug.Log("succesfully deleted route");
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 9
0
 public void add(ressources type, float amount)
 {
     this.newContent[type] += amount;
 }
Ejemplo n.º 10
0
 public void transfer(inventory target, ressources type, float amount)
 {
     target.newContent[type] += amount;
     this.newContent[type]   -= amount;
 }
Ejemplo n.º 11
0
 public serializationData(float HP, ressources type, float initialHP)
 {
     this.HP        = HP;
     this.type      = type;
     this.initialHP = initialHP;
 }
Ejemplo n.º 12
0
 public void takeAmount(ressources kind, float amount)
 {
     newContent[kind] -= amount;
 }
Ejemplo n.º 13
0
 public float getAmount(ressources kind)
 {
     return(newContent[kind]);
 }
Ejemplo n.º 14
0
 public float getFillPercent(ressources kind)
 {
     return(this.getAmount(kind) / this.maxSize);
 }
Ejemplo n.º 15
0
 public bool canTake(ressources kind, float amount)
 {
     return(newContent[kind] >= amount);
 }
Ejemplo n.º 16
0
 public void setIngot(ressources ingot, GameObject patch)
 {
     print("set ingot type: " + ingot + " on " + this.name);
     this.ingot        = ingot;
     this.mineralPatch = patch;
 }
Ejemplo n.º 17
0
 public routeSolotype(GameObject origin, GameObject target, ressources type)
 {
     this.origin = origin;
     this.target = target;
     this.type   = type;
 }
Ejemplo n.º 18
0
 public ressourceStack(float amount, ressources type)
 {
     this.amount = amount;
     this.type   = type;
 }