public void SetLocation(int index) { if (index == -1) { CurrentLocation = null; return; } if (index < 0 || index >= Locations.Count) { DebugConsole.ThrowError("Location index out of bounds"); return; } Location prevLocation = CurrentLocation; CurrentLocation = Locations[index]; CurrentLocation.Discovered = true; if (prevLocation != CurrentLocation) { var connection = CurrentLocation.Connections.Find(c => c.Locations.Contains(prevLocation)); if (connection != null) { connection.Passed = true; } } CurrentLocation.CreateStore(); OnLocationChanged?.Invoke(prevLocation, CurrentLocation); }
public void MoveToNextLocation() { if (SelectedConnection == null) { DebugConsole.ThrowError("Could not move to the next location (no connection selected).\n" + Environment.StackTrace.CleanupStackTrace()); return; } if (SelectedLocation == null) { DebugConsole.ThrowError("Could not move to the next location (no location selected).\n" + Environment.StackTrace.CleanupStackTrace()); return; } Location prevLocation = CurrentLocation; SelectedConnection.Passed = true; CurrentLocation = SelectedLocation; CurrentLocation.Discovered = true; SelectedLocation = null; CurrentLocation.CreateStore(); OnLocationChanged?.Invoke(prevLocation, CurrentLocation); if (GameMain.GameSession?.GameMode is CampaignMode campaign && campaign.CampaignMetadata is { } metadata) { metadata.SetValue("campaign.location.id", CurrentLocationIndex); metadata.SetValue("campaign.location.name", CurrentLocation.Name); } }
/// <summary> /// Generate a new campaign map from the seed /// </summary> public Map(CampaignMode campaign, string seed) : this() { Seed = seed; Rand.SetSyncedSeed(ToolBox.StringToInt(Seed)); Generate(); if (Locations.Count == 0) { throw new Exception($"Generating a campaign map failed (no locations created). Width: {Width}, height: {Height}"); } for (int i = 0; i < Locations.Count; i++) { Locations[i].Reputation ??= new Reputation(campaign.CampaignMetadata, $"location.{i}", -100, 100, Rand.Range(-10, 10, Rand.RandSync.Server)); } foreach (Location location in Locations) { if (!location.Type.Identifier.Equals("city", StringComparison.OrdinalIgnoreCase) && !location.Type.Identifier.Equals("outpost", StringComparison.OrdinalIgnoreCase)) { continue; } if (CurrentLocation == null || location.MapPosition.X < CurrentLocation.MapPosition.X) { CurrentLocation = StartLocation = furthestDiscoveredLocation = location; } } CurrentLocation.CreateStore(); CurrentLocation.Discovered = true; InitProjectSpecific(); }
public void MoveToNextLocation() { if (SelectedConnection == null) { DebugConsole.ThrowError("Could not move to the next location (no connection selected).\n" + Environment.StackTrace); return; } if (SelectedLocation == null) { DebugConsole.ThrowError("Could not move to the next location (no location selected).\n" + Environment.StackTrace); return; } Location prevLocation = CurrentLocation; SelectedConnection.Passed = true; CurrentLocation = SelectedLocation; CurrentLocation.Discovered = true; SelectedLocation = null; CurrentLocation.CreateStore(); OnLocationChanged?.Invoke(prevLocation, CurrentLocation); }
public void Update(float deltaTime, GUICustomComponent mapContainer) { Rectangle rect = mapContainer.Rect; if (CurrentDisplayLocation != null) { if (!CurrentDisplayLocation.Discovered) { RemoveFogOfWar(CurrentDisplayLocation); CurrentDisplayLocation.Discovered = true; if (CurrentDisplayLocation.MapPosition.X > furthestDiscoveredLocation.MapPosition.X) { furthestDiscoveredLocation = CurrentDisplayLocation; } } } currLocationIndicatorPos = Vector2.Lerp(currLocationIndicatorPos, CurrentDisplayLocation.MapPosition, deltaTime); #if DEBUG if (GameMain.DebugDraw) { if (editor == null) { CreateEditor(); } editor.AddToGUIUpdateList(order: 1); } #endif if (mapAnimQueue.Count > 0) { hudVisibility = Math.Max(hudVisibility - deltaTime, 0.0f); UpdateMapAnim(mapAnimQueue.Peek(), deltaTime); if (mapAnimQueue.Peek().Finished) { mapAnimQueue.Dequeue(); } return; } hudVisibility = Math.Min(hudVisibility + deltaTime, 0.75f + (float)Math.Sin(Timing.TotalTime * 3.0f) * 0.25f); Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y); Vector2 viewOffset = DrawOffset + drawOffsetNoise; float closestDist = 0.0f; HighlightedLocation = null; if (GUI.MouseOn == null || GUI.MouseOn == mapContainer) { for (int i = 0; i < Locations.Count; i++) { Location location = Locations[i]; if (IsInFogOfWar(location) && !(CurrentDisplayLocation?.Connections.Any(c => c.Locations.Contains(location)) ?? false) && !GameMain.DebugDraw) { continue; } Vector2 pos = rectCenter + (location.MapPosition + viewOffset) * zoom; if (!rect.Contains(pos)) { continue; } float iconScale = generationParams.LocationIconSize / location.Type.Sprite.size.X; if (location == CurrentDisplayLocation) { iconScale *= 1.2f; } Rectangle drawRect = location.Type.Sprite.SourceRect; drawRect.Width = (int)(drawRect.Width * iconScale * zoom * 1.4f); drawRect.Height = (int)(drawRect.Height * iconScale * zoom * 1.4f); drawRect.X = (int)pos.X - drawRect.Width / 2; drawRect.Y = (int)pos.Y - drawRect.Width / 2; if (!drawRect.Contains(PlayerInput.MousePosition)) { continue; } float dist = Vector2.Distance(PlayerInput.MousePosition, pos); if (HighlightedLocation == null || dist < closestDist) { closestDist = dist; HighlightedLocation = location; } } } if (GUI.KeyboardDispatcher.Subscriber == null) { float moveSpeed = 1000.0f; Vector2 moveAmount = Vector2.Zero; if (PlayerInput.KeyDown(InputType.Left)) { moveAmount += Vector2.UnitX; } if (PlayerInput.KeyDown(InputType.Right)) { moveAmount -= Vector2.UnitX; } if (PlayerInput.KeyDown(InputType.Up)) { moveAmount += Vector2.UnitY; } if (PlayerInput.KeyDown(InputType.Down)) { moveAmount -= Vector2.UnitY; } DrawOffset += moveAmount * moveSpeed / zoom * deltaTime; } targetZoom = MathHelper.Clamp(targetZoom, generationParams.MinZoom, generationParams.MaxZoom); zoom = MathHelper.Lerp(zoom, targetZoom, 0.1f); if (GUI.MouseOn == mapContainer) { foreach (LocationConnection connection in Connections) { if (HighlightedLocation != CurrentDisplayLocation && connection.Locations.Contains(HighlightedLocation) && connection.Locations.Contains(CurrentDisplayLocation)) { if (PlayerInput.PrimaryMouseButtonClicked() && SelectedLocation != HighlightedLocation && HighlightedLocation != null) { //clients aren't allowed to select the location without a permission if ((GameMain.GameSession?.GameMode as CampaignMode)?.AllowedToManageCampaign() ?? false) { SelectedConnection = connection; SelectedLocation = HighlightedLocation; OnLocationSelected?.Invoke(SelectedLocation, SelectedConnection); GameMain.Client?.SendCampaignState(); } } } } targetZoom += PlayerInput.ScrollWheelSpeed / 500.0f; if (PlayerInput.MidButtonHeld() || (HighlightedLocation == null && PlayerInput.PrimaryMouseButtonHeld())) { DrawOffset += PlayerInput.MouseSpeed / zoom; } if (AllowDebugTeleport) { if (PlayerInput.DoubleClicked() && HighlightedLocation != null) { var passedConnection = CurrentDisplayLocation.Connections.Find(c => c.OtherLocation(CurrentDisplayLocation) == HighlightedLocation); if (passedConnection != null) { passedConnection.Passed = true; } Location prevLocation = CurrentDisplayLocation; CurrentLocation = HighlightedLocation; Level.Loaded.DebugSetStartLocation(CurrentLocation); Level.Loaded.DebugSetEndLocation(null); CurrentLocation.Discovered = true; CurrentLocation.CreateStore(); OnLocationChanged?.Invoke(prevLocation, CurrentLocation); SelectLocation(-1); if (GameMain.Client == null) { ProgressWorld(); } else { GameMain.Client.SendCampaignState(); } } if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) && PlayerInput.PrimaryMouseButtonClicked() && HighlightedLocation != null) { int distance = DistanceToClosestLocationWithOutpost(HighlightedLocation, out Location foundLocation); DebugConsole.NewMessage($"Distance to closest outpost from {HighlightedLocation.Name} to {foundLocation?.Name} is {distance}"); } if (PlayerInput.PrimaryMouseButtonClicked() && HighlightedLocation == null) { SelectLocation(-1); } } } }