コード例 #1
0
ファイル: GridEnforcer.cs プロジェクト: Devlah/GardenConquest
 private void detatchClassifiers()
 {
     if (m_Classifiers != null) {
         foreach (KeyValuePair<long, HullClassifier> pair in m_Classifiers) {
             pair.Value.FatBlock.IsWorkingChanged -= classifierWorkingChanged;
         }
         m_Classifiers = null;
     }
     m_Classifier = null;
 }
コード例 #2
0
ファイル: GridEnforcer.cs プロジェクト: Devlah/GardenConquest
        /// <summary>
        /// Applies the new class if block is a Classifier and we can reserve the Class
        /// Returns true if this was a happy update,
        /// false if the block needs to be removed
        /// </summary>
        /// <param name="block"></param>
        private VIOLATION_TYPE updateClassifiersWith(IMySlimBlock block)
        {
            log("", "updateClassificationWith");
            try {
                // If it's not a classifier, we don't care about it
                if (!HullClassifier.isClassifierBlock(block)) {
                    return VIOLATION_TYPE.NONE;
                }

                // load up the classifier helper object
                HullClassifier classifier = new HullClassifier(block);
                HullClass.CLASS classID = classifier.Class;
                log("Adding a classifier for class " + classID + " - " +
                    s_Settings.HullRules[(int)classID].DisplayName,
                    "updateClassificationWith");

                addClassifier(classifier);

                // Ensure it's the right type for this grid
                if (s_Settings.HullRules[(int)classifier.Class].ShouldBeStation && !m_Grid.IsStatic) {
                    return VIOLATION_TYPE.SHOULD_BE_STATIC;
                }

                // Two classifiers not allowed
                if (m_Classifiers.Count > 1) {
                    return VIOLATION_TYPE.TOO_MANY_CLASSIFIERS;
                }

                // Too many per Player/Faction not allowed
                if (!checkClassAllowed(classID)) {
                    return VIOLATION_TYPE.TOO_MANY_OF_CLASS;
                }
            }
            catch (Exception e) {
                log("Error: " + e, "updateClassificationWith", Logger.severity.ERROR);
            }

            return VIOLATION_TYPE.NONE;
        }
コード例 #3
0
ファイル: GridEnforcer.cs プロジェクト: Devlah/GardenConquest
        // <summary>
        /// Returns true if the added classifier is used
        /// </summary>
        /// <param name="classifier"></param>
        /// <returns></returns>
        private void addClassifier(HullClassifier classifier)
        {
            if (classifier == null || classifier.FatBlock == null) {
                log("Null classifier or Fatblock",
                    "addClassifier", Logger.severity.ERROR);
                return;
            }

            log("adding classifier with ID " + classifier.FatBlock.EntityId,
                "addClassifier");

            m_Classifiers.Add(classifier.FatBlock.EntityId, classifier);
            classifier.FatBlock.IsWorkingChanged += classifierWorkingChanged;
            m_CheckClassifierNextUpdate = true;
        }
コード例 #4
0
ファイル: GridEnforcer.cs プロジェクト: Devlah/GardenConquest
        private void reevaluateClassification()
        {
            log("Reevaluate classifier", "reevaluateClassification");

            HullClassifier bestClassifier = findBestClassifier();

            if (m_Classifier != bestClassifier) {
                log("Classifier changed", "reevaluateClassification");
                m_Classifier = bestClassifier;
                setReservedToClassifier();
                setEffectiveToClassifier();
            } else {
                log("Classifier unchanged", "reevaluateClassification");
                bool workingNow = (m_Classifier == null) ? false : m_Classifier.FatBlock.IsWorking;
                if (m_ClassifierWorking != workingNow) {
                    log("Working changed", "reevaluateClassification");
                    m_ClassifierWorking = workingNow;
                    setEffectiveToClassifier();
                }
            }
        }