Example #1
0
    public void install(int i)
    {
        print("Install " + component_type + " at slot " + i);
        if (selected_ship.parts_list[i] != null)
        {
            print("To Replace " + selected_ship.parts_list[i].getType());
        }
        bool tmp = true;

        switch (component_type)                                                                     //FInd component to be installed, install, and reduce inv
        {
        case 0:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Thruster_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 1:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Armour_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 2:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Beam_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 3:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Shield_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 4:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Missile_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 5:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Colonization_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 6:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <AntiMissile_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;

        case 7:
            if (inRange[component_type] > 0)
            {
                toInstall = selected_ship.gameObject.AddComponent <Repair_Class>();
                //Decrement space dock array, currently only decrements self
                inRange[component_type]--;
                //current.component_storage[component_type]--;
            }
            else
            {
                tmp = false;
            }
            break;
        }

        if (selected_ship.parts_list[i] != null)                                                 //If part is already in slot, refund type to inv
        {
            int temp = -1;
            //Debug.Break();
            selected_ship.parts_list[i].getType();
            switch (selected_ship.parts_list[i].getType())
            {
            case "Thruster":
                temp = 0;
                break;

            case "Armour":
                temp = 1;
                break;

            case "Beam":
                temp = 2;
                break;

            case "Shield":
                temp = 3;
                break;

            case "Missile":
                temp = 4;
                break;

            case "Colonization":
                temp = 5;
                break;

            case "Anti Missile":
                temp = 6;
                break;

            case "Repair":
                temp = 7;
                break;
            }
            //Increment and replace, does not reference shipyard yet
            if (temp != -1)
            {
                print("Replacing part " + temp + " from " + i);
                Destroy(selected_ship.parts_list[i]);
                selected_ship.removeComponent(i);
                inRange[temp]++;
                //current.component_storage[temp]++;
            }
        }

        if (tmp)
        {
            selected_ship.installComponent(toInstall, i);                                    //Update ship w/ component
        }
    }