Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether this fleet is allowed to support this class
        /// Alerts the grid and updates tracking
        /// Returns true if it was supported
        /// </summary>
        private bool updateSupportAdded(GridEnforcer ge)
        {
            HullClass.CLASS hc = ge.Class;
            uint c = (uint)hc;
            long eID = ge.Container.Entity.EntityId;
            //log("adding " + eID + " as " + c, "updateSupportAdded");

            // if we have enough room, support it
            if (canSupportAnother(hc)) {
                log("we have enough room, supporting", "updateSupportAdded");
                m_SupportedGrids[c][eID] = ge;
                ge.markSupported(m_FactionId);
                return true;
            }

            // if we don't, see if it's bigger than one of the supported ones
            foreach (KeyValuePair<long, GridEnforcer> pair in m_SupportedGrids[c]) {
                GridEnforcer supported = pair.Value;

                // it is!
                if (ge.BlockCount > supported.BlockCount) {
                    log("it's larger than one of our supported, supporting", "updateSupportAdded");

                    // remove support from the old supported one
                    log("removing support from " + pair.Key, "updateSupportAdded");
                    m_SupportedGrids[c].Remove(pair.Key);
                    m_UnsupportedGrids[c][pair.Key] = supported;
                    supported.markUnsupported(m_FactionId);

                    // add support to the new
                    log("supporting " + eID, "updateSupportAdded");
                    m_SupportedGrids[c][eID] = ge;
                    ge.markSupported(m_FactionId);

                    return true;
                }

            }

            // if not, mark as unsupported
            log("can't support, marking grid as unsupported", "updateSupportAdded");
            m_UnsupportedGrids[c][eID] = ge;
            ge.markUnsupported(m_FactionId);
            return false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if the support has changed
        /// </summary>
        /// <remarks>
        /// We should eventually call this every so often after adding blocks,
        /// perhaps before a GE Violations check, since competition for support is
        /// dependent on block count. Right now it's not called at all.
        /// </remarks>
        /// <param name="ge"></param>
        /// <returns></returns>
        public bool updateSupport(GridEnforcer ge)
        {
            uint c = (uint)ge.Class;
            long eID = ge.Container.Entity.EntityId;
            Dictionary<long, GridEnforcer> supportedGrids = m_SupportedGrids[c];
            Dictionary<long, GridEnforcer> unsupportedGrids = m_UnsupportedGrids[c];

            // if it's a supported
            if (supportedGrids.ContainsKey(eID)) {

                // if we're out of room and there's unsupported grids
                if ((m_Counts[c] > m_Maximums[c]) && unsupportedGrids.Count > 0) {

                    // for any of the unsupported
                    foreach (long unsupportedID in unsupportedGrids.Keys) {
                        GridEnforcer unsupported = unsupportedGrids[unsupportedID];

                        // see it this is smaller
                        if (ge.BlockCount < unsupported.BlockCount) {

                            // change unsupported to supported
                            unsupportedGrids.Remove(unsupportedID);
                            supportedGrids[unsupportedID] = unsupported;
                            unsupported.markSupported(m_FactionId);

                            // change this to unsupported
                            supportedGrids.Remove(eID);
                            unsupportedGrids[eID] = ge;
                            ge.markUnsupported(m_FactionId);

                            return true;
                        }
                    }

                // if it's a unsupported
                } else if (unsupportedGrids.ContainsKey(eID)) {

                    // if we have enough room, support it
                    if (m_Counts[c] < m_Maximums[c]) {
                        unsupportedGrids.Remove(eID);
                        supportedGrids[eID] = ge;
                        ge.markSupported(m_FactionId);
                        return true;
                    }

                    // for any of the unsupported
                    foreach (long supportedID in supportedGrids.Keys) {
                        GridEnforcer supported = supportedGrids[supportedID];

                        // see if it's bigger
                        if (ge.BlockCount > supported.BlockCount) {

                            // remove support from the old
                            supportedGrids.Remove(supportedID);
                            unsupportedGrids[supportedID] = supported;
                            supported.markUnsupported(m_FactionId);

                            // add support to the existing
                            unsupportedGrids.Remove(eID);
                            supportedGrids[eID] = ge;
                            ge.markSupported(m_FactionId);

                            return true;
                        }
                    }
                }
            }

            return false;
        }