예제 #1
0
    /// <summary>
    /// News the group execution.
    /// </summary>
    /// <returns>
    /// If group creation was successful.
    /// </returns>
    /// <param name='pNewGroupNumber'>
    /// The new group ID
    /// </param>
    /// <param name='pNumberOfInterceptors'>
    /// Number of interceptors in new group.
    /// </param>
    /// <param name='pNumberOfScouts'>
    /// Number of scouts in new group.
    /// </param>
    bool NewGroupExecution(ShipGroup pNewGroup, int pNumberOfInterceptors, int pNumberOfScouts)
    {
        int assignedInterceptors = 0, assignedScouts = 0;
        //loop through each hanger bay in the hanger
        foreach(HangerBay bay in m_tHanger.m_tHangerBays)
        {
            //check if the bay contains a ship
            if(bay.m_goShip != null)
            {
                Ship_Small ship = (Ship_Small)bay.m_goShip.GetComponent("Ship_Small");
                //check if ship state is ready
                if(ship.m_eSmallShipState == SMALLSHIPSTATE.DockedReady)
                {
                    //check if ship is interceptor or scout
                    if(ship is Ship_Small_Interceptor)
                    {
                        //check if the number of interceptors assigned is lower than the desired amount
                        if(assignedInterceptors < pNumberOfInterceptors)
                        {
                            //add ship to group and increment assigned interceptors
                            pNewGroup.AddShip(bay.m_goShip);
                            assignedInterceptors++;
                        }
                    }
                    else if(ship is Ship_Small_Scout)
                    {
                        //check if the number of scouts assigned is lower than the desired amount
                        if(assignedScouts < pNumberOfScouts)
                        {
                            //add ship to group and increment assigned scouts
                            pNewGroup.AddShip(bay.m_goShip);
                            assignedScouts++;
                        }
                    }
                }
            }
        }

        //check if the assigned number of interceptors and scouts is equal to the desired number
        if(assignedInterceptors != pNumberOfInterceptors ||
            assignedScouts != pNumberOfScouts)
        {
            //if one or other isn't equal then remove the group and return false
            m_liShipGroups.Remove(pNewGroup);

            return false;
        }

        return true;
    }