Example #1
0
    void inAttackState()
    {
        if (target == null)
        {
            scanInstance now = targetScan(transform.position);
            if (now.hasTarget)
            {
                target = now.nearest;
            }
            else
            {
                _Logic_2 = _Logic_1;
                _state   = State.Idle;
                _Logic_1 = _state;
            }
            return;
        }


        if (!checkDistance())
        {
            _Logic_1 = _state;
            _state   = State.Move;
            return;
        }

        engageTarget();
    }
Example #2
0
    void buildState()
    {
        if (target != null)
        {
            if (target.tag != "betaStructure")
            {
                scanInstance now = targetScan(transform.position);
                if (now.hasTarget)
                {
                    target = now.nearest;
                    eventManager.RequestPosition(this.gameObject, target, (attackRange * 0.69f), playerID);
                }
                else
                {
                    _Logic_2 = _Logic_1;
                    _state   = State.Idle;
                    _Logic_1 = _state;
                }
                return;
            }

            f_rate -= Time.deltaTime;

            if (!checkDistance())
            {
                _Logic_1 = _state;
                _state   = State.Move;
                return;
            }

            if (f_rate <= 0)
            {
                eventManager.Construction(damage, this.gameObject, target);
                f_rate = fireRate;
            }

            turn();
        }
        else
        {
            scanInstance now = targetScan(transform.position);
            if (now.hasTarget)
            {
                target = now.nearest;
                eventManager.RequestPosition(this.gameObject, target, (attackRange * 0.69f), playerID);
                return;
            }
            else
            {
                _Logic_2 = _Logic_1;
                _state   = State.Idle;
                _Logic_1 = _state;
            }
        }
    }
Example #3
0
    void stateMine()
    {
        if (cargo >= rCapacity)
        {
            _mineState = mineState.Seek;
        }

        if (target == null)
        {
            scanInstance now = targetScan(transform.position);
            if (now.hasTarget)
            {
                target = now.nearest;
                eventManager.RequestPosition(this.gameObject, target, (attackRange * (0.69f)), playerID);
            }
            else
            {
                if (cargo > 0)
                {
                    _mineState = mineState.Seek;
                }
                else
                {
                    _Logic_2 = _Logic_1;
                    _state   = State.Idle;
                    _Logic_1 = _state;
                }
            }
            return;
        }

        if (checkDistance() == false)
        {
            if (debugActive)
            {
                Debug.Log("Target Too Far");
            }

            _Logic_1 = _state;
            _state   = State.Move;
            return;
        }

        f_rate -= Time.deltaTime;

        if (f_rate <= 0)
        {
            eventManager.Damage(damage, this.gameObject, target);
            cargo += damage;
            f_rate = fireRate;
        }


        turn();
    }
Example #4
0
    scanInstance targetScan(Vector3 position)
    {
        bool       hasTarget;
        GameObject nearestTarget;
        int        targetCount;
        int        friendlyCount;

recache:
        List <GameObject> enemies       = gManager.GetComponent <unitIndex> ().hostiles [playerID];
        List <GameObject> friendlies    = gManager.GetComponent <unitIndex> ().units [playerID];
        List <GameObject> betaStructs   = gManager.GetComponent <unitIndex> ().betaStructs [playerID];
        List <GameObject> resourceUnits = gManager.GetComponent <unitIndex> ().resources;

        float distance = Mathf.Infinity;

        targetCount   = enemies.Count;
        friendlyCount = friendlies.Count;
        nearestTarget = this.gameObject;


        if (_type == Type.mGun | _type == Type.missile)
        {
            GameObject closest = null;
            //	Vector3 position = transform.position;
            foreach (GameObject go in enemies)
            {
                if (go != null)
                {
                    Vector3 diff        = go.transform.position - position;
                    float   curDistance = diff.sqrMagnitude;
                    if (curDistance < distance)
                    {
                        closest       = go;
                        distance      = curDistance;
                        nearestTarget = closest;
                    }
                }
            }
        }
        if (_type == Type.miner)
        {
            GameObject closest     = null;
            bool       currClosest = true;
            float      currLeader  = Mathf.Infinity;
            foreach (GameObject go in gManager.GetComponent <unitIndex>().resources)
            {
                if (go != null)
                {
                    float curDistance = Vector3.Distance(position, go.transform.position);
                    if (curDistance < currLeader)
                    {
                        closest       = go;
                        distance      = curDistance;
                        currLeader    = curDistance;
                        nearestTarget = closest;
                    }
                }
            }
        }
        if (_type == Type.utility)
        {
            GameObject closest     = null;
            bool       currClosest = true;
            //	Vector3 position = transform.position;
            float currLeader = Mathf.Infinity;
            foreach (GameObject go in betaStructs)
            {
                float curDistance = Vector3.Distance(position, go.transform.position);
                if (curDistance < currLeader)
                {
                    closest       = go;
                    distance      = curDistance;
                    currLeader    = curDistance;
                    nearestTarget = closest;
                }
            }
        }
        if (distance <= reTargetRange && nearestTarget != this.gameObject)
        {
            hasTarget = true;
        }
        else
        {
            hasTarget = false;
        }
        scanInstance scanReturn = new scanInstance(hasTarget, nearestTarget, friendlyCount, targetCount);

        return(scanReturn);
    }