public GridOwner(GridEnforcer ge) { m_Enforcer = ge; m_Logger = new Logger(m_Enforcer.Grid.EntityId.ToString(), "GridOwner"); log("Loaded into new grid", "ctr"); // the grid will update ownership later b/c this is initialized with the grid, // and the grid doesn't have any blocks yet m_OwnerType = OWNER_TYPE.UNOWNED; m_FleetID = getFleetID(); m_Class = ge.Class; m_Fleet = getFleet(); m_Fleet.add(m_Class, ge); }
private long calcFleetID(OWNER_TYPE ownerType, long playerID, long factionID) { switch (ownerType) { case OWNER_TYPE.FACTION: return(factionID); case OWNER_TYPE.PLAYER: return(playerID); case OWNER_TYPE.UNOWNED: default: return(StateTracker.UNOWNED_FLEET_ID); } }
public static OWNER ownerFromPlayerID(long playerID) { OWNER_TYPE type = OWNER_TYPE.UNOWNED; IMyFaction faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerID); long factionID = 0; // Is the player solo? if (faction == null) { type = OWNER_TYPE.PLAYER; } else { type = OWNER_TYPE.FACTION; factionID = faction.FactionId; } return(new OWNER { OwnerType = type, PlayerID = playerID, FactionID = factionID, }); }
/// <summary> /// Figures out who owns the grid now /// </summary> /// <returns>Returns true if the owner has changed</returns> public bool reevaluateOwnership(List <long> bigOwners) { log("Reevaluating owner", "reevaluateOwnership"); bool changed = false; // = Get new ownership details OWNER_TYPE newType = OWNER_TYPE.UNOWNED; long newPlayerID = 0; long newFactionID = 0; if (bigOwners.Count == 0) { newType = OWNER_TYPE.UNOWNED; } else { if (bigOwners.Count > 1) { log("bigOwner tie! Using first owner.", "reevaluateOwnership", Logger.severity.WARNING); } newPlayerID = bigOwners[0]; IMyFaction fac = MyAPIGateway.Session.Factions.TryGetPlayerFaction(newPlayerID); // Is the player solo? if (fac == null) { newType = OWNER_TYPE.PLAYER; } else { newType = OWNER_TYPE.FACTION; newFactionID = fac.FactionId; } } long newFleetID = calcFleetID(newType, newPlayerID, newFactionID); // = Effect changes if (m_OwnerType != newType) { log(String.Format("type changed from {0} => {1}", m_OwnerType, newType), "reevaluateOwnership"); m_OwnerType = newType; changed = true; } if (m_PlayerID != newPlayerID) { log(String.Format("player changed from {0} => {1}", m_PlayerID, newPlayerID), "reevaluateOwnership"); m_PlayerID = newPlayerID; changed = true; } if (m_FactionID != newFactionID) { log(String.Format("faction changed from {0} => {1}", m_FactionID, newFactionID), "reevaluateOwnership"); m_FactionID = newFactionID; changed = true; } // If the fleet tracking ID has changed, or if we've got a temp fleet, update the fleet if ((m_FleetID != newFleetID) || (!m_StateLoaded && GridEnforcer.StateTracker != null)) { log(String.Format("Doing fleet change {0} => {1}, was temp? {2}", m_FleetID, newFleetID, !m_StateLoaded), "reevaluateOwnership"); // Remove the grid from the previous fleet if (m_Fleet == null) { log("Fleet is null", "reevaluateOwnership", Logger.severity.ERROR); } else { m_Fleet.remove(m_Class, m_Enforcer); } m_FleetID = newFleetID; m_Fleet = getFleet(); // Add the grid to the new fleet if (m_Fleet == null) { log("Failed to get new fleet for " + m_FleetID, "reevaluateOwnership", Logger.severity.ERROR); } else { m_Fleet.add(m_Class, m_Enforcer); } changed = true; } if (changed) { return(true); } else { log(String.Format("no change, owner: {0} {1}", m_OwnerType, m_FleetID), "reevaluateOwnership"); return(false); } }
private long calcFleetID(OWNER_TYPE ownerType, long playerID, long factionID) { switch (ownerType) { case OWNER_TYPE.FACTION: return factionID; case OWNER_TYPE.PLAYER: return playerID; case OWNER_TYPE.UNOWNED: default: return StateTracker.UNOWNED_FLEET_ID; } }
/// <summary> /// Figures out who owns the grid now /// </summary> /// <returns>Returns true if the owner has changed</returns> public bool reevaluateOwnership(List<long> bigOwners) { log("Reevaluating owner", "reevaluateOwnership"); bool changed = false; // = Get new ownership details OWNER_TYPE newType = OWNER_TYPE.UNOWNED; long newPlayerID = 0; long newFactionID = 0; if (bigOwners.Count == 0) { newType = OWNER_TYPE.UNOWNED; } else { if (bigOwners.Count > 1) { log("bigOwner tie! Using first owner.", "reevaluateOwnership", Logger.severity.WARNING); } newPlayerID = bigOwners[0]; IMyFaction fac = MyAPIGateway.Session.Factions.TryGetPlayerFaction(newPlayerID); // Is the player solo? if (fac == null) { newType = OWNER_TYPE.PLAYER; } else { newType = OWNER_TYPE.FACTION; newFactionID = fac.FactionId; } } long newFleetID = calcFleetID(newType, newPlayerID, newFactionID); // = Effect changes if (m_OwnerType != newType) { log(String.Format("type changed from {0} => {1}", m_OwnerType, newType), "reevaluateOwnership"); m_OwnerType = newType; changed = true; } if (m_PlayerID != newPlayerID) { log(String.Format("player changed from {0} => {1}", m_PlayerID, newPlayerID), "reevaluateOwnership"); m_PlayerID = newPlayerID; changed = true; } if (m_FactionID != newFactionID) { log(String.Format("faction changed from {0} => {1}", m_FactionID, newFactionID), "reevaluateOwnership"); m_FactionID = newFactionID; changed = true; } // If the fleet tracking ID has changed, or if we've got a temp fleet, update the fleet if ((m_FleetID != newFleetID) || (!m_StateLoaded && GridEnforcer.StateTracker != null)) { log(String.Format("Doing fleet change {0} => {1}, was temp? {2}", m_FleetID, newFleetID, !m_StateLoaded), "reevaluateOwnership"); // Remove the grid from the previous fleet if (m_Fleet == null) { log("Fleet is null", "reevaluateOwnership", Logger.severity.ERROR); } else { m_Fleet.remove(m_Class, m_Enforcer); } m_FleetID = newFleetID; m_Fleet = getFleet(); // Add the grid to the new fleet if (m_Fleet == null) { log("Failed to get new fleet for " + m_FleetID, "reevaluateOwnership", Logger.severity.ERROR); } else { m_Fleet.add(m_Class, m_Enforcer); } changed = true; } if (changed) { return true; } else { log(String.Format("no change, owner: {0} {1}", m_OwnerType, m_FleetID), "reevaluateOwnership"); return false; } }
public void SetOwnerType(OWNER_TYPE type) { m_SpecialFlag = (m_SpecialFlag & 0xffffff00) | (0xff & (uint)type); }