Exemple #1
0
    //todo: currently the player and AI ships have the weapon firing code duplicated. Maybe move to its own
    //place if the firing proves to be similar

    public void fireWeapons(SwarmFireDetails details)
    {
        if (ship.weapons != null && ship.weapons.Length > 0)
        {
            int[] weaponIndexes = details.fireWeapons;
            foreach (int weaponIndex in weaponIndexes)
            {
                foreach (FireStream fs in ship.weapons[weaponIndex].fireStreams)
                {
                    // NO cooldowns for enemy weapons so we can script whatever we want
                    //if (fs.currentCooldown <= 0f) {
                    IEnumerator coroutine = FireProjectile(fs, details.targetType, details.firings);
                    StartCoroutine(coroutine);

                    //FireProjectile (fs, details.targetType);
                    //fs.currentCooldown = fs.fireRate;
                    //}
                }
            }
        }
    }
Exemple #2
0
 public SwarmPathAction(SwarmFireDetails _fireDetails)
 {
     this.actionType  = swarmActionType.fire;
     this.fireDetails = _fireDetails;
     this.moveDetails = null;
 }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (ship.currentHealth <= 0)
        {
            destroyShip();
        }

        if (!ship.isComponent)
        {
            if (currentAction == null)
            {
                currentAction         = swarmActions [0];
                currentActionPosition = 0;
                computeInitialMoveTargetAndTime();
                ComputeNextMoveTargetAndTime();
                InitiateCurrentMove();
            }
            //execute the current swarm action
            if (currentAction.actionType == swarmActionType.move)
            {
                if (transform.localPosition == currentMoveTarget)
                {
                    //we're at the move destination - move to next action, or start over
                    GoToNextAction();

                    //if the new action is a move, start moving. If firing, start firing!
                    if (currentAction.actionType == swarmActionType.move)
                    {
                        currentMoveTarget = nextMoveTarget;
                        currentMoveTime   = nextMoveTime;
                        if (currentAction.moveDetails.bezier)
                        {
                            currentAction.moveDetails.bezierVectors [currentAction.moveDetails.bezierVectors.Length - 1] = nextMoveTarget;
                        }
                        InitiateCurrentMove();
                    }

                    //find the next move action and compute now so we're ready

                    ComputeNextMoveTargetAndTime();
                }
            }
            else if (currentAction.actionType == swarmActionType.fire)
            {
                if (shipType != shipType.dummy)
                {
                    fireWeapons(currentAction.fireDetails);
                }

                GoToNextAction();

                if (currentAction.actionType == swarmActionType.move)
                {
                    currentMoveTarget = nextMoveTarget;
                    currentMoveTime   = nextMoveTime;
                    if (currentAction.moveDetails.bezier)
                    {
                        currentAction.moveDetails.bezierVectors [currentAction.moveDetails.bezierVectors.Length - 1] = nextMoveTarget;
                    }
                    InitiateCurrentMove();
                }

                ComputeNextMoveTargetAndTime();
            }
        }
        else
        {
            //component update code
            //make components fire once every X seconds. Ensure there is at least Y seconds before firings

            timeSinceLastFiring += Time.deltaTime;

            if (Random.Range(minTimeBetweenFiring, maxTimeBetweenFiring) <= timeSinceLastFiring)
            {
                //fire

                SwarmFireDetails fireDetails = null;

                switch (this.componentType)
                {
                case componentType.missile:
                    fireDetails = new SwarmFireDetails(swarmTargetType.straightAhead, new int[1]  {
                        0
                    }, 3);
                    break;

                case componentType.rail:
                    fireDetails = new SwarmFireDetails(swarmTargetType.straightAhead, new int[1]  {
                        0
                    }, 10);
                    break;
                }

                if (fireDetails != null)
                {
                    fireWeapons(fireDetails);
                }

                timeSinceLastFiring = 0;
            }
        }
    }