public void Upgrade()
 {
     curLevelDat       = FarFutureTechnologySettings.GetAMFactoryLevelData(factoryLevel + 1);
     factoryLevel      = factoryLevel + 1;
     maxAntimatter     = curLevelDat.maxCapacity;
     curAntimatterRate = curLevelDat.baseRate;
 }
        public void Initialize(int loadedLevel, double loadedStorage, double deferredConsumption)
        {
            factoryLevel             = loadedLevel;
            curAntimatter            = loadedStorage;
            deferredAntimatterAmount = deferredConsumption;

            // If game mode is sandbox, set the level to max immediately and begin production
            if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
            {
                Utils.Log("Detected Sandbox, setting AM factory to max and activating");
                researched   = true;
                factoryLevel = FarFutureTechnologySettings.factoryLevels.Count - 1;
                SetProductionStatus(true);
            }
            // If science sandbox, check for the needed technology first
            else if (HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX)
            {
                Utils.Log("Detected Science Sandbox, setting AM factory to max, detecting tech");
                bool isResearched = Utils.CheckTechPresence(FarFutureTechnologySettings.antimatterFactoryUnlockTech);
                if (isResearched)
                {
                    researched   = true;
                    factoryLevel = FarFutureTechnologySettings.factoryLevels.Count - 1;
                    SetProductionStatus(true);
                }
                else
                {
                    researched = false;
                    SetProductionStatus(false);
                }
            }
            else
            {
                Utils.Log("Detected Career, setting AM factory to stored level, detecting tech");
                bool isResearched = Utils.CheckTechPresence(FarFutureTechnologySettings.antimatterFactoryUnlockTech);
                if (isResearched)
                {
                    researched   = true;
                    factoryLevel = loadedLevel;
                    SetProductionStatus(true);
                }
                else
                {
                    researched = false;
                    SetProductionStatus(false);
                }
            }

            Utils.Log("Completed data load, setting up factory for level " + factoryLevel.ToString());
            curLevelDat = FarFutureTechnologySettings.GetAMFactoryLevelData(factoryLevel);

            maxAntimatter     = curLevelDat.maxCapacity;
            curAntimatterRate = curLevelDat.baseRate;

            if (curAntimatter > maxAntimatter)
            {
                curAntimatter = maxAntimatter;
            }

            if (HighLogic.LoadedSceneIsFlight && DeferredAntimatterAmount > 0d)
            {
                ConsumeAntimatter(deferredAntimatterAmount);
                deferredAntimatterAmount = 0d;
            }
        }