Exemplo n.º 1
0
        public FactionFleet(long facId, GridOwner.OWNER_TYPE ownerType)
        {
            //if (s_Settings == null) {
            //    s_Settings = ConquestSettings.getInstance();
            //}
            if (s_Rules == null) {
                s_Rules = ConquestSettings.getInstance().HullRules;
            }
            if (s_Logger == null) {
                s_Logger = new Logger("Static", "FactionFleet");
            }
            log("start", "ctr", Logger.severity.TRACE);

            m_FactionId = facId;
            m_OwnerType = ownerType;

            // = init count holders
            m_TotalCount = 0;

            int classCount = Enum.GetValues(typeof(HullClass.CLASS)).Length;
            m_Counts = new uint[classCount];

            m_SupportedGrids = new Dictionary<long, GridEnforcer>[classCount];
            for (int i = 0; i < classCount; i++) {
                m_SupportedGrids[i] = new Dictionary<long, GridEnforcer>();
            }

            m_UnsupportedGrids = new Dictionary<long, GridEnforcer>[classCount];
            for (int i = 0; i < classCount; i++) {
                m_UnsupportedGrids[i] = new Dictionary<long, GridEnforcer>();
            }

            m_Maximums = new uint[classCount];
            if (ownerType == GridOwner.OWNER_TYPE.FACTION) {
                for (int i = 0; i < classCount; i++) {
                    m_Maximums[i] = (uint)s_Rules[i].MaxPerFaction;
                }
            } else if (ownerType == GridOwner.OWNER_TYPE.PLAYER) {
                for (int i = 0; i < classCount; i++) {
                    m_Maximums[i] = (uint)s_Rules[i].MaxPerSoloPlayer;
                }
            } else {
                for (int i = 0; i < classCount; i++) {
                    m_Maximums[i] = 0;
                }
            }
        }
Exemplo n.º 2
0
        private string buildFleetInfoBody(GridOwner.OWNER_TYPE ownerType)
        {
            log("Building Fleet Info Body", "buildFleetInfoBody");
            string fleetInfoBody = "";
            List<GridEnforcer.GridData> gdList;
            for (int i = 0; i < m_Counts.Length; ++i) {
                if (m_Counts[i] > 0) {
                    fleetInfoBody += (HullClass.CLASS)i + ": " + m_Counts[i] + " / ";
                    if (ownerType == GridOwner.OWNER_TYPE.FACTION) {
                        fleetInfoBody += ServerSettings.HullRules[i].MaxPerFaction + "\n";
                    }
                    else if (ownerType == GridOwner.OWNER_TYPE.PLAYER) {
                        fleetInfoBody += ServerSettings.HullRules[i].MaxPerSoloPlayer + "\n";
                    }
                    else {
                        fleetInfoBody += "0\n";
                    }

                    if (m_SupportedGrids.ContainsKey(i)) {
                        gdList = m_SupportedGrids[i];
                        for (int j = 0; j < gdList.Count; ++j) {
                            fleetInfoBody += "  " + (j + 1) + ". " + gdList[j].shipName + " - " + gdList[j].blockCount + " blocks\n";
                            if (gdList[j].displayPos) {
                                fleetInfoBody += "      GPS: " + gdList[j].shipPosition.X + ", " + gdList[j].shipPosition.Y + ", " + gdList[j].shipPosition.Z + "\n";
                            }
                            else {
                                fleetInfoBody += "      GPS: Unavailable - Must own the Main Cockpit\n";
                            }
                        }
                    }
                    if (m_UnsupportedGrids.ContainsKey(i)) {
                        gdList = m_UnsupportedGrids[i];
                        int offset = (m_SupportedGrids.ContainsKey(i) ? m_SupportedGrids[i].Count : 0);
                        fleetInfoBody += "\n  Unsupported:\n";
                        for (int j = 0; j < gdList.Count; ++j) {
                            //Some code logic to continue the numbering of entries where m_SupportedGrid leaves off
                            fleetInfoBody += "     " + (j + offset + 1) + ". " + gdList[j].shipName + " - " + gdList[j].blockCount + " blocks\n";
                            if (gdList[j].displayPos) {
                                fleetInfoBody += "         GPS: " + gdList[j].shipPosition.X + ", " + gdList[j].shipPosition.Y + ", " + gdList[j].shipPosition.Z + "\n";
                            }
                            else {
                                fleetInfoBody += "         GPS: Unavailable - Must own the Main Cockpit\n";
                            }
                        }
                    }

                    fleetInfoBody += "\n";
                }
            }
            return fleetInfoBody;
        }
Exemplo n.º 3
0
 private string buildFleetInfoTitle(GridOwner.OWNER_TYPE ownerType)
 {
     string fleetInfoTitle = "";
     switch (ownerType) {
         case GridOwner.OWNER_TYPE.FACTION:
             fleetInfoTitle = "Your Faction's Fleet:";
             break;
         case GridOwner.OWNER_TYPE.PLAYER:
             fleetInfoTitle = "Your Fleet:";
             break;
     }
     return fleetInfoTitle;
 }
Exemplo n.º 4
0
 private void detatchOwner()
 {
     if (m_Owner != null) {
         log("detatching owner", "detatchOwner");
         m_Owner.Close();
         m_Owner = null;
     }
 }
Exemplo n.º 5
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);
            m_Grid = Container.Entity as IMyCubeGrid;

            m_Logger = new Logger(m_Grid.EntityId.ToString(), "GridEnforcer");
            log("Loaded into new grid", "Init");

            // If this is not the server we don't need this class.
            // When we modify the grid on the server the changes should be
            // sent to all clients
            try {
                m_IsServer = Utility.isServer();
                log("Is server: " + m_IsServer, "Init");
                if (!m_IsServer) {
                    // No cleverness allowed :[
                    log("Disabled.  Not server.", "Init");
                    m_Logger = null;
                    m_Grid = null;
                    return;
                }
            } catch (NullReferenceException e) {
                log("Exception.  Multiplayer is not initialized.  Assuming server for time being: " + e,
                    "Init");
                // If we get an exception because Multiplayer was null (WHY KEEN???)
                // assume we are the server for a little while and check again later
                m_IsServer = true;
                m_CheckServerLater = true;
            }

            // We need to only turn on our rule checking after startup. Otherwise, if
            // a beacon is destroyed and then the server restarts, all but the first
            // 25 blocks will be deleted on startup.
            m_Grid.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_BlockCount = 0;
            m_BlockTypeCounts = new int[s_Settings.BlockTypes.Length];
            m_Owner = new GridOwner(this);
            m_Classifiers = new Dictionary<long, HullClassifier>();
            m_Projectors = new Dictionary<long, InGame.IMyProjector>();
            m_ReservedClass = DEFAULT_CLASS;
            m_ReservedRules = s_Settings.HullRules[(int)DEFAULT_CLASS];
            m_EffectiveClass = DEFAULT_CLASS;
            m_EffectiveRules = s_Settings.HullRules[(int)DEFAULT_CLASS];
            reserveEffectiveClassFromOwner();

            m_Grid.OnBlockAdded += blockAdded;
            m_Grid.OnBlockRemoved += blockRemoved;
            m_Grid.OnBlockOwnershipChanged += blockOwnerChanged;
            m_GridSubscribed = true;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Removes hooks and references
 /// </summary>
 private void unServerize()
 {
     detatchGrid();
     detatchOwner();
     detatchClassifiers();
     detatchCleanupTimer();
     m_Owner = null;
     m_Logger = null;
 }
Exemplo n.º 7
0
 public void removeFleetIfEmpty(long fleetId, GridOwner.OWNER_TYPE ownerType)
 {
     switch (ownerType) {
         case GridOwner.OWNER_TYPE.FACTION:
             if (m_Fleets.ContainsKey(fleetId)) {
                 if (m_Fleets[fleetId].TotalCount == 0) {
                     m_Fleets.Remove(fleetId);
                 }
             }
             return;
         case GridOwner.OWNER_TYPE.PLAYER:
             if (m_PlayerFleets.ContainsKey(fleetId)) {
                 if (m_PlayerFleets[fleetId].TotalCount == 0) {
                     m_PlayerFleets.Remove(fleetId);
                 }
             }
             return;
         case GridOwner.OWNER_TYPE.UNOWNED:
         default:
             if (m_PlayerFleets.ContainsKey(fleetId)) {
                 if (m_PlayerFleets[fleetId].TotalCount == 0) {
                     m_PlayerFleets.Remove(fleetId);
                 }
             }
             return;
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Returns the fleet for the fleet id.  If no fleet yet recorded creates a new one.
 /// </summary>
 /// <param name="factionId"></param>
 /// <returns></returns>
 public FactionFleet getFleet(long fleetId, GridOwner.OWNER_TYPE ownerType)
 {
     switch (ownerType) {
         case GridOwner.OWNER_TYPE.FACTION:
             if (!m_Fleets.ContainsKey(fleetId))
                 m_Fleets.Add(fleetId, new FactionFleet(fleetId, ownerType));
             return m_Fleets[fleetId];
         case GridOwner.OWNER_TYPE.PLAYER:
             if (!m_PlayerFleets.ContainsKey(fleetId))
                 m_PlayerFleets.Add(fleetId, new FactionFleet(fleetId, ownerType));
             return m_PlayerFleets[fleetId];
         case GridOwner.OWNER_TYPE.UNOWNED:
         default:
             if (!m_PlayerFleets.ContainsKey(UNOWNED_FLEET_ID))
                 m_PlayerFleets.Add(UNOWNED_FLEET_ID, new FactionFleet(fleetId, ownerType));
             return m_PlayerFleets[fleetId];
     }
 }