private void OpenRequest(bool open, long identityId) { AdminSettingsEnum enum2; MyPlayer playerFromCharacter; MyRelationsBetweenPlayerAndBlock userRelationToOwner = base.GetUserRelationToOwner(identityId); MyIdentity identity = MySession.Static.Players.TryGetIdentity(identityId); if ((identity == null) || (identity.Character == null)) { playerFromCharacter = null; } else { playerFromCharacter = MyPlayer.GetPlayerFromCharacter(identity.Character); } MyPlayer player = playerFromCharacter; bool flag = false; if (((player != null) && !userRelationToOwner.IsFriendly()) && MySession.Static.RemoteAdminSettings.TryGetValue(player.Client.SteamUserId, out enum2)) { flag = enum2.HasFlag(AdminSettingsEnum.UseTerminals); } if (userRelationToOwner.IsFriendly() | flag) { this.Open = open; } }
static void UseSuccessCallback(MySyncControllableEntity sync, ref UseObject_UseMsg msg, MyNetworkClient sender) { MyEntity controlledEntity; if (MyEntities.TryGetEntityById <MyEntity>(msg.UsedByEntityId, out controlledEntity)) { var controllableEntity = controlledEntity as IMyControllableEntity; Debug.Assert(controllableEntity != null, "Controllable entity needs to get control from another controllable entity"); if (controllableEntity != null) { MyRelationsBetweenPlayerAndBlock relation = MyRelationsBetweenPlayerAndBlock.FactionShare; var cubeBlock = sync.Entity as MyCubeBlock; if (cubeBlock != null && controllableEntity.ControllerInfo.Controller != null) { relation = cubeBlock.GetUserRelationToOwner(controllableEntity.ControllerInfo.Controller.Player.Identity.IdentityId); } if (relation == MyRelationsBetweenPlayerAndBlock.FactionShare || relation == MyRelationsBetweenPlayerAndBlock.Owner) { sync.RaiseUseSuccess(msg.UseAction, controllableEntity); } else { sync.RaiseUseFailure(msg.UseAction, msg.UseResult, controllableEntity); } } } }
private bool IsValidCubeBlock(IMyCubeBlock block) { if (block != null) { if (block.CubeGrid.GridSizeEnum == MyCubeSize.Large) { if (!TargetLargeShips || (block.CubeGrid.IsStatic && !TargetStations)) { return(false); } } else { if (!TargetSmallShips) { return(false); } } MyRelationsBetweenPlayerAndBlock relation = block.GetUserRelationToOwner(CubeBlock.OwnerId); if (!(relation == MyRelationsBetweenPlayerAndBlock.Enemies || TargetNeutrals && (relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership))) { return(false); } return(true); } return(false); }
public bool ShouldDetectRelation(MyRelationsBetweenPlayerAndBlock relation) { switch (relation) { case MyRelationsBetweenPlayerAndBlock.Owner: return(DetectOwner); break; case MyRelationsBetweenPlayerAndBlock.NoOwnership: case MyRelationsBetweenPlayerAndBlock.FactionShare: return(DetectFriendly); break; case MyRelationsBetweenPlayerAndBlock.Neutral: return(DetectNeutral); break; case MyRelationsBetweenPlayerAndBlock.Enemies: return(DetectEnemy); break; default: throw new InvalidBranchException(); break; } return(false); }
public static string GetIconForRelationship(MyRelationsBetweenPlayerAndBlock relationship) { string str = string.Empty; switch (relationship) { case MyRelationsBetweenPlayerAndBlock.NoOwnership: case MyRelationsBetweenPlayerAndBlock.Neutral: str = "Textures\\HUD\\marker_neutral.dds"; break; case MyRelationsBetweenPlayerAndBlock.Owner: str = "Textures\\HUD\\marker_self.dds"; break; case MyRelationsBetweenPlayerAndBlock.FactionShare: case MyRelationsBetweenPlayerAndBlock.Friends: str = "Textures\\HUD\\marker_friendly.dds"; break; case MyRelationsBetweenPlayerAndBlock.Enemies: str = "Textures\\HUD\\marker_enemy.dds"; break; } return(str); }
private bool IsValidCharacter(IMyCharacter character) { if (character != null) { if (!TargetCharacters || character.IsDead) // dont target if not set or dead { return(false); } IMyPlayer player = MyAPIGateway.Players.GetPlayerControllingEntity(character); if (player == null) { return(false); } MyRelationsBetweenPlayerAndBlock relation = player.GetRelationTo(CubeBlock.OwnerId); if (!(relation == MyRelationsBetweenPlayerAndBlock.Enemies || TargetNeutrals && (relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership))) { return(false); } return(true); } return(false); }
public void GetColorAndFontForRelationship(MyRelationsBetweenPlayerAndBlock relationship, out Color color, out Color fontColor, out string font) { color = Color.White; fontColor = Color.White; font = "White"; switch (relationship) { case MyRelationsBetweenPlayerAndBlock.Owner: color = new Color(117, 201, 241); fontColor = new Color(117, 201, 241); font = "Blue"; break; case MyRelationsBetweenPlayerAndBlock.FactionShare: case MyRelationsBetweenPlayerAndBlock.Friends: color = new Color(101, 178, 90); font = "Green"; break; case MyRelationsBetweenPlayerAndBlock.Enemies: color = new Color(227, 62, 63); font = "Red"; break; } }
private MyRelationsBetweenPlayerAndBlock GetGroupRelation() { if (this.m_group == null || this.m_group.Count == 0) { return(MyRelationsBetweenPlayerAndBlock.NoOwnership); } MyRelationsBetweenPlayerAndBlock betweenPlayerAndBlock = this.m_group[0].Relationship; for (int index = 1; index < this.m_group.Count; ++index) { if (this.m_group[index].Relationship != betweenPlayerAndBlock) { if (betweenPlayerAndBlock == MyRelationsBetweenPlayerAndBlock.Owner && this.m_group[index].Relationship == MyRelationsBetweenPlayerAndBlock.FactionShare) { betweenPlayerAndBlock = MyRelationsBetweenPlayerAndBlock.FactionShare; } else { if (betweenPlayerAndBlock != MyRelationsBetweenPlayerAndBlock.FactionShare || this.m_group[index].Relationship != MyRelationsBetweenPlayerAndBlock.Owner) { return(MyRelationsBetweenPlayerAndBlock.NoOwnership); } betweenPlayerAndBlock = MyRelationsBetweenPlayerAndBlock.FactionShare; } } } return(betweenPlayerAndBlock == MyRelationsBetweenPlayerAndBlock.NoOwnership ? MyRelationsBetweenPlayerAndBlock.Neutral : betweenPlayerAndBlock); }
public static bool ColorGridOrBlockRequestValidationPatch(MyCubeGrid __instance, ref bool __result, long player) { if (player == 0L || !Sandbox.Game.Multiplayer.Sync.IsServer || __instance.BigOwners.Count == 0) { __result = true; } else { foreach (long bigOwner in __instance.BigOwners) { MyRelationsBetweenPlayerAndBlock relationPlayerBlock = MyIDModule.GetRelationPlayerBlock(bigOwner, player, MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare); if (relationPlayerBlock == MyRelationsBetweenPlayerAndBlock.Owner || relationPlayerBlock == MyRelationsBetweenPlayerAndBlock.FactionShare || relationPlayerBlock == MyRelationsBetweenPlayerAndBlock.NoOwnership) { __result = true; break; } } } // Stop the original method from running return(false); }
static void Postfix(long playerId1, long playerId2, ref MyRelationsBetweenPlayerAndBlock __result) { if (playerId1 == playerId2) { return; } IMyFaction playerFaction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId1); IMyFaction playerFaction2 = MySession.Static.Factions.TryGetPlayerFaction(playerId2); if (playerFaction1 != null && playerFaction2 != null) { if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) != null && AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction) != null) { if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) == AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction)) { // AlliancePlugin.Log.Info("Same alliance?"); __result = MyRelationsBetweenPlayerAndBlock.Friends; return; } } if (MySession.Static.Factions.AreFactionsFriends(playerFaction1.FactionId, playerFaction2.FactionId)) { __result = MyRelationsBetweenPlayerAndBlock.Friends; return; } } return; // make sure you only skip if really necessary }
private static List <IMyInventory> GetInventories(IMyCubeBlock cube) { List <IMyCubeGrid> grids = new List <IMyCubeGrid>(); MyAPIGateway.GridGroups.GetGroup(cube.CubeGrid, GridLinkTypeEnum.Logical, grids); List <IMyInventory> inventories = new List <IMyInventory>(); long owner = cube.OwnerId; foreach (IMyCubeGrid g in grids) { MyCubeGrid grid = (MyCubeGrid)g; foreach (var block in grid.GetFatBlocks()) { if (owner != 0) { MyRelationsBetweenPlayerAndBlock relation = block.GetUserRelationToOwner(owner); if (relation == MyRelationsBetweenPlayerAndBlock.Enemies) { continue; } } for (int i = 0; i < block.InventoryCount; i++) { IMyInventory inv = ((IMyCubeBlock)block).GetInventory(i); inventories.Add(inv); } } } return(inventories); }
private Dictionary <MyRelationsBetweenPlayerAndBlock, List <EnergySignature> > GetSignificantGroupPOIs() { Dictionary <MyRelationsBetweenPlayerAndBlock, List <EnergySignature> > dictionary = new Dictionary <MyRelationsBetweenPlayerAndBlock, List <EnergySignature> >(); if (this.m_group == null || this.m_group.Count == 0) { return(dictionary); } bool flag = true; MyRelationsBetweenPlayerAndBlock relationship = this.m_group[0].Relationship; for (int index = 1; index < this.m_group.Count; ++index) { if (this.m_group[index].Relationship != relationship) { flag = false; break; } } if (flag) { this.m_group.Sort(new Comparison <EnergySignature>(this.ComparePointOfInterest)); dictionary[relationship] = new List <EnergySignature>(); for (int index = this.m_group.Count - 1; index >= 0; --index) { dictionary[relationship].Add(this.m_group[index]); if (dictionary[relationship].Count >= 4) { break; } } } else { for (int index = 0; index < this.m_group.Count; ++index) { EnergySignature poiA = this.m_group[index]; MyRelationsBetweenPlayerAndBlock key = poiA.Relationship; if (key == MyRelationsBetweenPlayerAndBlock.NoOwnership) { key = MyRelationsBetweenPlayerAndBlock.Neutral; } if (dictionary.ContainsKey(key)) { if (this.ComparePointOfInterest(poiA, dictionary[key][0]) > 0) { dictionary[key].Clear(); dictionary[key].Add(poiA); } } else { dictionary[key] = new List <EnergySignature>(); dictionary[key].Add(poiA); } } } return(dictionary); }
public MyHudEntityParams(StringBuilder text, MyRelationsBetweenPlayerAndBlock targetMode, float maxDistance, MyHudIndicatorFlagsEnum flagsEnum) : this() { this.Text = text; this.FlagsEnum = flagsEnum; this.MaxDistance = maxDistance; this.TargetMode = targetMode; }
private bool IsRelationHostile(MyRelationsBetweenPlayerAndBlock relationshipA, MyRelationsBetweenPlayerAndBlock relationshipB) { if (relationshipA == MyRelationsBetweenPlayerAndBlock.Owner || relationshipA == MyRelationsBetweenPlayerAndBlock.FactionShare) { return(relationshipB == MyRelationsBetweenPlayerAndBlock.Enemies); } return((relationshipB == MyRelationsBetweenPlayerAndBlock.Owner || relationshipB == MyRelationsBetweenPlayerAndBlock.FactionShare) && relationshipA == MyRelationsBetweenPlayerAndBlock.Enemies); }
public void SetState(Vector3D position, EnergySignatureType type, MyRelationsBetweenPlayerAndBlock relationship) { this.WorldPosition = position; this.POIType = type; this.Relationship = relationship; this.Distance = (position - this.GetDistanceMeasuringMatrix().Translation).Length(); this.DistanceToCam = (this.WorldPosition - MyAPIGateway.Session.Camera.WorldMatrix.Translation).Length(); }
private bool AddPotentialBlock(IMySlimBlock block, bool remote = false, NaniteAreaBeacon beacon = null) { if (TargetList.Contains(block)) { return(false); } if (!remote && block.FatBlock != null && block.FatBlock is IMyTerminalBlock && block.FatBlock.OwnerId != 0) { IMyTerminalBlock terminal = (IMyTerminalBlock)block.FatBlock; MyRelationsBetweenPlayerAndBlock relation = terminal.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId); if (relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.Enemies) { return(false); } } else if (remote) { //if (block.CubeGrid.BigOwners.Count < 1) // return false; foreach (var item in block.CubeGrid.BigOwners) { MyRelationsBetweenPlayerAndBlock relation = m_constructionBlock.ConstructionBlock.GetUserRelationToOwner(item); if (relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.Enemies) { return(false); } } } if (!block.IsFullIntegrity || block.HasDeformation) { using (Lock.AcquireExclusiveUsing()) { if (beacon != null) { if (!m_areaTargetBlocks.ContainsKey(block)) { m_areaTargetBlocks.Add(block, beacon); } else { m_areaTargetBlocks[block] = beacon; } } PotentialTargetList.Add(block); return(true); } } return(false); }
public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <IMySlimBlock> blocks) { using (Lock.AcquireExclusiveUsing()) { PotentialTargetList.Clear(); } var remoteList = new HashSet <IMySlimBlock>(); if (!IsEnabled()) { return; } foreach (var block in blocks) { AddPotentialBlock(block); } foreach (var beaconBlock in NaniteConstructionManager.BeaconList.Where(x => x is NaniteBeaconConstruct && Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), x.BeaconBlock.GetPosition()) < m_maxDistance * m_maxDistance)) { IMyCubeBlock item = (IMyCubeBlock)beaconBlock.BeaconBlock; if (!((IMyFunctionalBlock)item).Enabled || !((IMyFunctionalBlock)item).IsFunctional) { continue; } MyRelationsBetweenPlayerAndBlock relation = item.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId); if (!(relation == MyRelationsBetweenPlayerAndBlock.Owner || relation == MyRelationsBetweenPlayerAndBlock.FactionShare || (MyAPIGateway.Session.CreativeMode && relation == MyRelationsBetweenPlayerAndBlock.NoOwnership))) { continue; } List <IMyCubeGrid> beaconGridList = GridHelper.GetGridGroup((IMyCubeGrid)item.CubeGrid); List <IMySlimBlock> beaconBlocks = new List <IMySlimBlock>(); foreach (var grid in beaconGridList) { grid.GetBlocks(beaconBlocks); } foreach (var block in beaconBlocks) { if (AddPotentialBlock(block, true)) { remoteList.Add(block); } } } CheckAreaBeacons(); using (m_remoteLock.AcquireExclusiveUsing()) { m_remoteTargets = remoteList; } }
public void UpdateHud(bool showMyself = false) { if (MySandboxGame.IsDedicated) { return; } Clear(); foreach (var broadcaster in m_relayedBroadcasters) { MyEntity entity = null; if (MyEntities.TryGetEntityById(broadcaster.EntityId, out entity)) { if (!showMyself && entity == Parent) { continue; //do not show myself } bool friendly = true; if (broadcaster.Parent is IMyComponentOwner <MyIDModule> ) { MyIDModule broadcasterId; if ((broadcaster.Parent as IMyComponentOwner <MyIDModule>).GetComponent(out broadcasterId)) { MyRelationsBetweenPlayerAndBlock relation = broadcasterId.GetUserRelationToOwner(MySession.LocalPlayerId); if (relation == MyRelationsBetweenPlayerAndBlock.Enemies || relation == MyRelationsBetweenPlayerAndBlock.Neutral) { friendly = false; } } } MyLaserAntenna la = broadcaster.Parent as MyLaserAntenna; if (la != null && la.ShowOnHUD == false) { continue; } foreach (var hudParams in entity.GetHudParams(friendly)) { if (!m_entitiesOnHud.Contains(hudParams.Entity)) { m_entitiesOnHud.Add(hudParams.Entity); if (hudParams.BlinkingTime > 0) { MyHud.HackingMarkers.RegisterMarker(hudParams.Entity, hudParams); } else if (!MyHud.HackingMarkers.MarkerEntities.ContainsKey(hudParams.Entity)) { MyHud.LocationMarkers.RegisterMarker(hudParams.Entity, hudParams); } } } } } }
public static void ShowJumpSelector(MyJumpDrive block) { MyRelationsBetweenPlayerAndBlock userRelationToOwner = block.GetUserRelationToOwner(MySession.Static.LocalPlayerId); if (userRelationToOwner == MyRelationsBetweenPlayerAndBlock.FactionShare || userRelationToOwner == MyRelationsBetweenPlayerAndBlock.Owner) { MyGuiSandbox.AddScreen(new JumpSelectorGui()); } }
public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <BlockTarget> gridBlocks) { List <IMyPlayer> players = new List <IMyPlayer>(); try { MyAPIGateway.Players.GetPlayers(players); } catch { Logging.Instance.WriteLine("NaniteLifeSupportTargets.ParallelUpdate: Error getting players, skipping"); return; } foreach (IMyPlayer item in players) { var functional = m_constructionBlock.ConstructionBlock as IMyFunctionalBlock; MyRelationsBetweenPlayerAndBlock relations = functional.GetUserRelationToOwner(item.IdentityId); if (relations != MyRelationsBetweenPlayerAndBlock.Owner && relations != MyRelationsBetweenPlayerAndBlock.FactionShare) { continue; } if (!DoesTargetNeedLifeSupport(item)) { continue; } if (PotentialTargetList.Contains(item) || TargetList.Contains(item)) { continue; } if (IsInRange(item.GetPosition(), m_maxDistance)) { PotentialTargetList.Add(item); } } List <IMyGasTank> removalList = new List <IMyGasTank>(); foreach (IMyGasTank tank in connectedGasTanks) { if (!GridHelper.IsValidGasConnection(m_constructionBlock.ConstructionCubeBlock, tank)) { removalList.Add(tank); } } foreach (IMyGasTank tank in removalList) { connectedGasTanks.Remove(tank); } CheckTanks(ref m_hasOxygen, ref m_hasHydrogen); }
public Entry(double X, double Y, double Z) { this.TimeNum = -42044469; this.TSB = 0; this.Id = -1; this.Location = new Vector3D(X, Y, Z); this.Velocity = new Vector3D(0, 0, 0); this.Type = MyDetectedEntityType.LargeGrid; this.Relation = MyRelationsBetweenPlayerAndBlock.Enemies; }
public Entry(MyDetectedEntityInfo entity) { this.TimeNum = 0; this.TSB = 0; this.Id = entity.EntityId; this.Location = entity.Position; this.Velocity = entity.Velocity; this.Type = entity.Type; this.Relation = entity.Relationship; }
static public Boolean CheckOwnership(IMyCubeBlock entity, long playerId) { MyRelationsBetweenPlayerAndBlock relation = entity.GetUserRelationToOwner(playerId); if (relation == MyRelationsBetweenPlayerAndBlock.FactionShare || relation == MyRelationsBetweenPlayerAndBlock.Owner) { return(true); } return(false); }
void DestroyHandler(object target, MyDamageInformation damage) { if (damage.Type == MyDamageType.Grind) { MyDefinitionId blockId = new MyDefinitionId(); MyRelationsBetweenPlayerAndBlock relation = new MyRelationsBetweenPlayerAndBlock(); string faction = "none"; IMyFaction plFaction; List <long> owners = new List <long>(); long ownerID = -1; IMyEntity ent; MyAPIGateway.Entities.TryGetEntityById(damage.AttackerId, out ent); var hand = ent as IMyHandheldGunObject <MyToolBase>; IMyPlayer pl; if (hand != null && hand.DefinitionId.TypeId == typeof(MyObjectBuilder_AngleGrinder)) { var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); pl = players.FirstOrDefault(p => p.IdentityId.Equals(hand.OwnerIdentityId)); plFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(pl.IdentityId); } else { //If nothing was returned from Entity return; } if (target is IMySlimBlock) { IMySlimBlock slim = target as IMySlimBlock; blockId = slim.BlockDefinition.Id; relation = slim.FatBlock.GetUserRelationToOwner(pl.IdentityId); faction = slim.FatBlock.GetOwnerFactionTag(); owners = slim.CubeGrid.SmallOwners; ownerID = slim.OwnerId; } else if (target is IMyCubeBlock) //just in cause { var fat = target as IMyCubeBlock; blockId = fat.BlockDefinition; relation = fat.GetUserRelationToOwner(pl.IdentityId); faction = fat.GetOwnerFactionTag(); owners = fat.CubeGrid.SmallOwners; ownerID = fat.OwnerId;//fat.OwnerBlock.BuiltBy; } MyLog.Default.WriteLine($"OwnerID {ownerID} Owner {relation.ToString()} - Player {pl.IdentityId} Faction {faction} - Player Faction {plFaction.Tag} Built By {owners.Count}"); if (owners.Count > 0 && faction != plFaction.Tag && !owners.Contains(pl.IdentityId)) { CalculatePlayers(blockId, ent, pl); } } }
public MyDetectedEntityInfo(long entityId, string name, MyDetectedEntityType type, Vector3D?hitPosition, MatrixD orientation, Vector3 velocity, MyRelationsBetweenPlayerAndBlock relationship, BoundingBoxD boundingBox, long timeStamp) { this.EntityId = entityId; this.Name = name; this.Type = type; this.HitPosition = hitPosition; this.Orientation = orientation; this.Velocity = velocity; this.Relationship = relationship; this.BoundingBox = boundingBox; this.TimeStamp = timeStamp; }
public static bool CanBeUsedByPlayer(long playerId, IMyEntity Entity) { MyIDModule module; IMyComponentOwner <MyIDModule> owner = Entity as IMyComponentOwner <MyIDModule>; if ((owner == null) || !owner.GetComponent(out module)) { return(true); } MyRelationsBetweenPlayerAndBlock userRelationToOwner = module.GetUserRelationToOwner(playerId); return((userRelationToOwner != MyRelationsBetweenPlayerAndBlock.NoOwnership) && ((userRelationToOwner - 3) > MyRelationsBetweenPlayerAndBlock.Owner)); }
public virtual bool HasPlayerAccess(long playerId) { if (!MyFakes.SHOW_FACTIONS_GUI) { return(true); } MyRelationsBetweenPlayerAndBlock relation = GetUserRelationToOwner(playerId); bool accessAllowed = relation.IsFriendly(); return(accessAllowed); }
/// <summary> /// Is the given player allowed get information or use commands on the grid? /// Player is able to interact with the grid if the player is part of a specific /// block's faction OR the player owns the block /// The block is dependent on the CommandsRequireClassifier setting /// </summary> /// <param name="playerID"></param> /// <param name="grid"></param> /// <returns></returns> public static bool canInteractWith(this IMyCubeGrid grid, long playerID, HullClassifier bestClassifier = null) { IMyCubeBlock blockToCheck; // Get the type of block to check based on settings if (Core.ConquestSettings.getInstance().SimpleOwnership) { if (bestClassifier != null) { blockToCheck = bestClassifier.FatBlock; } else { blockToCheck = grid.getFirstClassifierBlock(); } } else { blockToCheck = grid.getMainCockpit(); } if (blockToCheck != null) { MyRelationsBetweenPlayerAndBlock relationship = blockToCheck.GetUserRelationToOwner(playerID); if (relationship == MyRelationsBetweenPlayerAndBlock.NoOwnership || relationship == MyRelationsBetweenPlayerAndBlock.Enemies) { return(false); } else if (relationship == MyRelationsBetweenPlayerAndBlock.FactionShare || relationship == MyRelationsBetweenPlayerAndBlock.Owner) { return(true); } // Being in a faction doesn't necessarily mean FactionShare, so need to check for faction status else { IMyFactionCollection factions = MyAPIGateway.Session.Factions; IMyFaction blocksFaction = factions.TryGetPlayerFaction(blockToCheck.OwnerId); // Block is either owned by friendly faction or user's faction if (blocksFaction != null) { long owningFactionID = blocksFaction.FactionId; if (owningFactionID == factions.TryGetPlayerFaction(playerID).FactionId) { return(true); } } } } return(false); }
public static bool GridHasHostileOwners(IMyCubeGrid grid) { var gridOwners = grid.BigOwners; foreach (var pid in gridOwners) { MyRelationsBetweenPlayerAndBlock relation = MyAPIGateway.Session.Player.GetRelationTo(pid); if (relation == MyRelationsBetweenPlayerAndBlock.Enemies) { return(true); } } return(false); }
public static string RelationToLetter(MyRelationsBetweenPlayerAndBlock relation) { switch (relation) { case MyRelationsBetweenPlayerAndBlock.Enemies: return("H"); case MyRelationsBetweenPlayerAndBlock.FactionShare: case MyRelationsBetweenPlayerAndBlock.Friends: case MyRelationsBetweenPlayerAndBlock.Owner: return("F"); default: return("N"); } }
private static Relations GetRelations(MyRelationsBetweenPlayerAndBlock relations) { switch (relations) { case MyRelationsBetweenPlayerAndBlock.Enemies: return Relations.Enemy; case MyRelationsBetweenPlayerAndBlock.FactionShare: return Relations.Faction; case MyRelationsBetweenPlayerAndBlock.Neutral: return Relations.Neutral; case MyRelationsBetweenPlayerAndBlock.Owner: return Relations.Owner; case MyRelationsBetweenPlayerAndBlock.NoOwnership: default: return Relations.None; } }
private bool IsRelationHostile(MyRelationsBetweenPlayerAndBlock relationshipA, MyRelationsBetweenPlayerAndBlock relationshipB) { if (relationshipA == MyRelationsBetweenPlayerAndBlock.Owner || relationshipA == MyRelationsBetweenPlayerAndBlock.FactionShare) { return (relationshipB == MyRelationsBetweenPlayerAndBlock.Enemies); } if (relationshipB == MyRelationsBetweenPlayerAndBlock.Owner || relationshipB == MyRelationsBetweenPlayerAndBlock.FactionShare) { return (relationshipA == MyRelationsBetweenPlayerAndBlock.Enemies); } return false; }
/// <summary> /// Draws an icon for the POI /// </summary> private static void DrawIcon(MyHudMarkerRender renderer, PointOfInterestType poiType, MyRelationsBetweenPlayerAndBlock relationship, Vector2 screenPosition, Color markerColor, float sizeScale = 1) { MyHudTexturesEnum centerIcon = MyHudTexturesEnum.corner; string centerIconSprite = string.Empty; Vector2 iconSize = new Vector2(12, 12); switch (poiType) { default: // Groups don't have an icon case PointOfInterestType.Group: return; case PointOfInterestType.Hack: centerIcon = MyHudTexturesEnum.hit_confirmation; break; case PointOfInterestType.Target: centerIcon = MyHudTexturesEnum.TargetTurret; break; case PointOfInterestType.Ore: centerIcon = MyHudTexturesEnum.HudOre; break; case PointOfInterestType.Character: case PointOfInterestType.SmallEntity: case PointOfInterestType.LargeEntity: case PointOfInterestType.StaticEntity: case PointOfInterestType.Unknown: case PointOfInterestType.UnknownEntity: { string icon = GetIconForRelationship(relationship); DrawIcon(renderer, icon, screenPosition, markerColor); return; } case PointOfInterestType.GPS: { string icon = "Textures\\HUD\\marker_gps.dds"; DrawIcon(renderer, icon, screenPosition, markerColor); return; } } // Draw icon if (!string.IsNullOrWhiteSpace(centerIconSprite)) { iconSize *= sizeScale; renderer.AddTexturedQuad(centerIconSprite, screenPosition, -Vector2.UnitY, markerColor, iconSize.X, iconSize.Y); } else { float indicatorSize = MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f * sizeScale; renderer.AddTexturedQuad(centerIcon, screenPosition, -Vector2.UnitY, markerColor, indicatorSize, indicatorSize); } }
/// <summary> /// Returns the icon path for the marker images for each relationship. /// </summary> public static string GetIconForRelationship(MyRelationsBetweenPlayerAndBlock relationship) { string centerIconSprite = string.Empty; switch (relationship) { case MyRelationsBetweenPlayerAndBlock.Owner: centerIconSprite = "Textures\\HUD\\marker_self.dds"; break; case MyRelationsBetweenPlayerAndBlock.FactionShare: centerIconSprite = "Textures\\HUD\\marker_friendly.dds"; break; case MyRelationsBetweenPlayerAndBlock.NoOwnership: case MyRelationsBetweenPlayerAndBlock.Neutral: centerIconSprite = "Textures\\HUD\\marker_neutral.dds"; break; case MyRelationsBetweenPlayerAndBlock.Enemies: centerIconSprite = "Textures\\HUD\\marker_enemy.dds"; break; } return centerIconSprite; }
/// <summary> /// Adds a generic POI, styled like a GPS coordinate. /// Currently only used to draw a center-of-the-world marker. /// </summary> public void AddPOI(Vector3D worldPosition, StringBuilder name, MyRelationsBetweenPlayerAndBlock relationship) { // Don't add poi if we're not displaying them if (SignalDisplayMode == SignalMode.Off) return; PointOfInterest poi = m_pointOfInterestPool.Allocate(); m_pointsOfInterest.Add(poi); poi.Reset(); poi.SetState(worldPosition, PointOfInterest.PointOfInterestType.GPS, relationship); poi.SetText(name); }
public void AddEntity(MyEntity entity, MyRelationsBetweenPlayerAndBlock relationship, StringBuilder entityName) { // Don't add poi if we're not displaying them if (SignalDisplayMode == SignalMode.Off) return; if (entity == null) return; Vector3D worldPosition = entity.PositionComp.GetPosition(); PointOfInterest.PointOfInterestType poiType = PointOfInterest.PointOfInterestType.UnknownEntity; if (entity is Sandbox.Game.Entities.Character.MyCharacter) { // Don't add marker for own character if (entity == MySession.Static.LocalCharacter) return; poiType = PointOfInterest.PointOfInterestType.Character; worldPosition += entity.WorldMatrix.Up * 1.3f; } else { MyCubeBlock cubeBlock = entity as MyCubeBlock; if (cubeBlock != null && cubeBlock.CubeGrid != null) { if (cubeBlock.CubeGrid.GridSizeEnum == MyCubeSize.Small) { poiType = PointOfInterest.PointOfInterestType.SmallEntity; } else { poiType = cubeBlock.CubeGrid.IsStatic ? PointOfInterest.PointOfInterestType.StaticEntity : PointOfInterest.PointOfInterestType.LargeEntity; } } } PointOfInterest poi = m_pointOfInterestPool.Allocate(); m_pointsOfInterest.Add(poi); poi.Reset(); poi.SetState(worldPosition, poiType, relationship); poi.SetEntity(entity); poi.SetText(entityName); }
/// <summary> /// Sets the POI state /// </summary> /// <param name="position">World position of the POI.</param> /// <param name="type">POI Type, grid, ore, gps, etc.</param> /// <param name="relationship">Relationship of the local player to this POI</param> public void SetState(Vector3D position, PointOfInterestType type, MyRelationsBetweenPlayerAndBlock relationship) { WorldPosition = position; POIType = type; Relationship = relationship; Vector3D viewDirection = position - MyHudMarkerRender.ActiveWorldMatrix.Translation; Distance = viewDirection.Length(); }
public bool ShouldDetectRelation(MyRelationsBetweenPlayerAndBlock relation) { switch (relation) { case MyRelationsBetweenPlayerAndBlock.Owner: return DetectOwner; break; case MyRelationsBetweenPlayerAndBlock.FactionShare: return DetectFriendly; break; case MyRelationsBetweenPlayerAndBlock.Neutral: return DetectNeutral; break; case MyRelationsBetweenPlayerAndBlock.Enemies: return DetectEnemy; break; default: throw new InvalidBranchException(); break; } return false; }
/// <summary> /// Retrieves font and colouring information for a relationship. /// </summary> /// <param name="relationship"></param> /// <param name="color"></param> /// <param name="fontColor"></param> /// <param name="font"></param> public void GetColorAndFontForRelationship(MyRelationsBetweenPlayerAndBlock relationship, out Color color, out Color fontColor, out MyFontEnum font) { color = Color.White; fontColor = Color.White; font = MyFontEnum.White; switch (relationship) { case MyRelationsBetweenPlayerAndBlock.Owner: color = new Color(117, 201, 241); fontColor = new Color(117, 201, 241); font = MyFontEnum.Blue; break; case MyRelationsBetweenPlayerAndBlock.FactionShare: color = new Color(101, 178, 90); font = MyFontEnum.Green; break; // Neutral and unowned are the same colour case MyRelationsBetweenPlayerAndBlock.Neutral: case MyRelationsBetweenPlayerAndBlock.NoOwnership: break; case MyRelationsBetweenPlayerAndBlock.Enemies: color = new Color(227, 62, 63); font = MyFontEnum.Red; break; } }