| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- using UnityEngine;
- /// <summary>
- /// Simplified MapMaker2 - Basic map generation with team placement on towns/villages
- /// No exploration or expansion systems - just a clean, working map
- /// </summary>
- public class SimpleMapMaker2 : MonoBehaviour
- {
- [Header("Basic Map Settings")]
- public int mapSize = 100;
- public int seed = 12345;
- [Header("Team Placement")]
- public GameObject teamMarkerPrefab;
- [Header("Visualization")]
- public MapVisualizer mapVisualizer;
- // Core components
- private MapData mapData;
- private Transform teamMarker;
- void Start()
- {
- GenerateSimpleMap();
- }
- /// <summary>
- /// Generate a simple map and place team marker on a town/village
- /// </summary>
- public void GenerateSimpleMap()
- {
- Debug.Log("🗺️ SimpleMapMaker2: Generating basic map...");
- // Generate basic map data
- CreateBasicMapData();
- // Visualize the map
- if (mapVisualizer != null)
- {
- mapVisualizer.VisualizeMap(mapData);
- Debug.Log("✅ Map visualization complete");
- }
- else
- {
- Debug.LogWarning("⚠️ MapVisualizer not assigned - creating simple cubes for visualization");
- CreateSimpleCubeVisualization();
- }
- // Place team marker on a town/village
- PlaceTeamMarkerOnTown();
- Debug.Log($"🎯 SimpleMapMaker2: Map generation complete - Size: {mapSize}x{mapSize}");
- }
- /// <summary>
- /// Create basic map data with terrain and settlements
- /// </summary>
- private void CreateBasicMapData()
- {
- Random.InitState(seed);
- mapData = new MapData(mapSize, mapSize);
- // Generate basic terrain
- for (int x = 0; x < mapSize; x++)
- {
- for (int y = 0; y < mapSize; y++)
- {
- // Simple terrain generation
- float noise = Mathf.PerlinNoise(x * 0.1f, y * 0.1f);
- MapTile tile = mapData.GetTile(x, y);
- if (tile != null)
- {
- if (noise < 0.3f)
- {
- tile.terrainType = TerrainType.Plains;
- }
- else if (noise < 0.6f)
- {
- tile.terrainType = TerrainType.Forest;
- }
- else if (noise < 0.8f)
- {
- tile.terrainType = TerrainType.Plains; // Use plains for hills
- tile.height = 1f; // Use height for elevation
- }
- else
- {
- tile.terrainType = TerrainType.Mountain;
- }
- }
- }
- }
- // Add some roads
- AddBasicRoads();
- // Add settlements (towns and villages)
- AddSettlements();
- Debug.Log($"📊 Basic map data created: {mapSize}x{mapSize}");
- }
- /// <summary>
- /// Add basic road network
- /// </summary>
- private void AddBasicRoads()
- {
- // Horizontal road across the middle
- int midY = mapSize / 2;
- for (int x = 0; x < mapSize; x++)
- {
- MapTile tile = mapData.GetTile(x, midY);
- if (tile != null && tile.terrainType != TerrainType.Mountain)
- {
- tile.featureType = FeatureType.Road;
- }
- }
- // Vertical road across the middle
- int midX = mapSize / 2;
- for (int y = 0; y < mapSize; y++)
- {
- MapTile tile = mapData.GetTile(midX, y);
- if (tile != null && tile.terrainType != TerrainType.Mountain)
- {
- tile.featureType = FeatureType.Road;
- }
- }
- Debug.Log("🛤️ Basic roads added");
- }
- /// <summary>
- /// Add towns and villages to the map
- /// </summary>
- private void AddSettlements()
- {
- // Add a few towns and villages
- Vector2Int[] settlementPositions = {
- new Vector2Int(25, 25),
- new Vector2Int(75, 25),
- new Vector2Int(25, 75),
- new Vector2Int(75, 75),
- new Vector2Int(50, 50), // Center town
- new Vector2Int(30, 60),
- new Vector2Int(70, 40)
- };
- for (int i = 0; i < settlementPositions.Length; i++)
- {
- Vector2Int pos = settlementPositions[i];
- // Make sure position is valid
- if (pos.x >= 0 && pos.x < mapSize && pos.y >= 0 && pos.y < mapSize)
- {
- MapTile tile = mapData.GetTile(pos.x, pos.y);
- if (tile != null)
- {
- // First three are towns, rest are villages
- FeatureType settlementType = i < 3 ? FeatureType.Town : FeatureType.Village;
- tile.featureType = settlementType;
- // Give settlements names
- if (settlementType == FeatureType.Town)
- {
- tile.name = $"Town_{i + 1}";
- }
- else
- {
- tile.name = $"Village_{i + 1}";
- }
- Debug.Log($"🏘️ Placed {settlementType} at ({pos.x}, {pos.y})");
- }
- }
- }
- }
- /// <summary>
- /// Place team marker on a town or village
- /// </summary>
- private void PlaceTeamMarkerOnTown()
- {
- // Find a suitable town or village
- Vector2Int? townPosition = FindTownOrVillage();
- if (townPosition.HasValue)
- {
- PlaceTeamMarkerAt(townPosition.Value);
- }
- else
- {
- // Fallback to center if no town found
- Debug.LogWarning("⚠️ No town/village found, placing team marker at center");
- PlaceTeamMarkerAt(new Vector2Int(mapSize / 2, mapSize / 2));
- }
- }
- /// <summary>
- /// Find the first town or village on the map
- /// </summary>
- private Vector2Int? FindTownOrVillage()
- {
- for (int x = 0; x < mapSize; x++)
- {
- for (int y = 0; y < mapSize; y++)
- {
- MapTile tile = mapData.GetTile(x, y);
- if (tile != null && (tile.featureType == FeatureType.Town || tile.featureType == FeatureType.Village))
- {
- return new Vector2Int(x, y);
- }
- }
- }
- return null;
- }
- /// <summary>
- /// Place team marker at specific map coordinates
- /// </summary>
- private void PlaceTeamMarkerAt(Vector2Int mapPos)
- {
- // Find existing team marker or create one
- GameObject teamMarkerObj = GameObject.Find("TeamMarker");
- if (teamMarkerObj == null)
- {
- // Create a simple team marker if none exists
- if (teamMarkerPrefab != null)
- {
- teamMarkerObj = Instantiate(teamMarkerPrefab);
- teamMarkerObj.name = "TeamMarkerSimpleMapMaker2";
- Debug.Log("🎯 Created new TeamMarker from prefab");
- }
- else
- {
- // Create a simple sphere as team marker
- teamMarkerObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- teamMarkerObj.name = "TeamMarkerSimplMapMaker2";
- teamMarkerObj.transform.localScale = new Vector3(2f, 2f, 2f);
- // Make it green and easily visible
- Renderer renderer = teamMarkerObj.GetComponent<Renderer>();
- if (renderer != null)
- {
- renderer.material.color = Color.green;
- }
- Debug.Log("🎯 Created simple sphere TeamMarker");
- }
- }
- if (teamMarkerObj != null)
- {
- // Convert map coordinates to world position
- Vector3 worldPos = new Vector3(mapPos.x, 1f, mapPos.y); // Y=1 to be above ground
- teamMarkerObj.transform.position = worldPos;
- teamMarker = teamMarkerObj.transform;
- Debug.Log($"📍 Team marker placed at map position ({mapPos.x}, {mapPos.y}) = world position {worldPos}");
- // Log what type of settlement we're on
- MapTile tile = mapData.GetTile(mapPos.x, mapPos.y);
- if (tile != null)
- {
- Debug.Log($"🏘️ Team marker placed on: Terrain={tile.terrainType}, Feature={tile.featureType}");
- if (!string.IsNullOrEmpty(tile.name))
- {
- Debug.Log($"🏘️ Settlement name: {tile.name}");
- }
- }
- }
- else
- {
- Debug.LogError("❌ Could not create TeamMarker!");
- }
- }
- /// <summary>
- /// Context menu helper to regenerate map
- /// </summary>
- [ContextMenu("Generate New Map")]
- public void RegenerateMap()
- {
- seed = Random.Range(1, 99999);
- GenerateSimpleMap();
- }
- /// <summary>
- /// Context menu helper to disable conflicting systems
- /// </summary>
- [ContextMenu("Setup Simple System (Disable Conflicts)")]
- public void SetupSimpleSystem()
- {
- Debug.Log("🔧 Setting up simple system by disabling conflicting components...");
- // Disable SimpleTeamPlacement if present
- SimpleTeamPlacement teamPlacement = FindFirstObjectByType<SimpleTeamPlacement>();
- if (teamPlacement != null)
- {
- teamPlacement.enabled = false;
- Debug.Log("🚫 Disabled SimpleTeamPlacement component");
- }
- // Disable old TravelUI if present
- TravelUI oldTravelUI = FindFirstObjectByType<TravelUI>();
- if (oldTravelUI != null)
- {
- oldTravelUI.enabled = false;
- Debug.Log("🚫 Disabled old TravelUI component");
- }
- // Disable TeamTravelSystem if present
- TeamTravelSystem travelSystem = FindFirstObjectByType<TeamTravelSystem>();
- if (travelSystem != null)
- {
- travelSystem.enabled = false;
- Debug.Log("🚫 Disabled TeamTravelSystem component");
- }
- // Disable ExplorationManager if present (search by component name)
- MonoBehaviour[] allComponents = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
- foreach (var component in allComponents)
- {
- if (component.GetType().Name == "ExplorationManager")
- {
- component.enabled = false;
- Debug.Log("🚫 Disabled ExplorationManager component");
- break;
- }
- }
- Debug.Log("✅ Simple system setup complete - conflicting systems disabled");
- // Regenerate the map to ensure clean state
- GenerateSimpleMap();
- }
- /// <summary>
- /// Context menu helper to place team marker on different town
- /// </summary>
- [ContextMenu("Move Team to Random Town")]
- public void MoveTeamToRandomTown()
- {
- // Find all towns and villages
- var settlements = new System.Collections.Generic.List<Vector2Int>();
- for (int x = 0; x < mapSize; x++)
- {
- for (int y = 0; y < mapSize; y++)
- {
- MapTile tile = mapData.GetTile(x, y);
- if (tile != null && (tile.featureType == FeatureType.Town || tile.featureType == FeatureType.Village))
- {
- settlements.Add(new Vector2Int(x, y));
- }
- }
- }
- if (settlements.Count > 0)
- {
- int randomIndex = Random.Range(0, settlements.Count);
- PlaceTeamMarkerAt(settlements[randomIndex]);
- }
- else
- {
- Debug.LogWarning("⚠️ No settlements found on map");
- }
- }
- /// <summary>
- /// Create simple cube visualization when MapVisualizer is not available
- /// </summary>
- private void CreateSimpleCubeVisualization()
- {
- // Create a parent object for all tiles
- GameObject mapContainer = GameObject.Find("MapContainer");
- if (mapContainer == null)
- {
- mapContainer = new GameObject("MapContainer");
- }
- // Clear existing tiles
- for (int i = mapContainer.transform.childCount - 1; i >= 0; i--)
- {
- DestroyImmediate(mapContainer.transform.GetChild(i).gameObject);
- }
- // Create simple cubes for visualization
- for (int x = 0; x < mapSize; x++)
- {
- for (int y = 0; y < mapSize; y++)
- {
- MapTile tile = mapData.GetTile(x, y);
- if (tile != null)
- {
- CreateTileVisualization(x, y, tile, mapContainer.transform);
- }
- }
- }
- Debug.Log($"✅ Created simple cube visualization with {mapSize * mapSize} tiles");
- }
- /// <summary>
- /// Create a simple cube to represent a tile
- /// </summary>
- private void CreateTileVisualization(int x, int y, MapTile tile, Transform parent)
- {
- // Create a cube for the tile
- GameObject tileObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
- tileObj.name = $"Tile_{x}_{y}";
- tileObj.transform.parent = parent;
- tileObj.transform.position = new Vector3(x, 0, y);
- tileObj.transform.localScale = new Vector3(0.9f, 0.1f, 0.9f); // Flat tiles
- // Get the renderer to change colors
- Renderer renderer = tileObj.GetComponent<Renderer>();
- if (renderer != null)
- {
- // Color based on terrain type
- Color terrainColor = GetTerrainColor(tile.terrainType);
- renderer.material.color = terrainColor;
- }
- // Add feature visualization on top if needed
- if (tile.featureType != FeatureType.None)
- {
- CreateFeatureVisualization(x, y, tile, tileObj.transform);
- }
- }
- /// <summary>
- /// Create feature visualization (towns, villages, roads)
- /// </summary>
- private void CreateFeatureVisualization(int x, int y, MapTile tile, Transform tileParent)
- {
- GameObject featureObj = null;
- switch (tile.featureType)
- {
- case FeatureType.Town:
- featureObj = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
- featureObj.name = $"Town_{x}_{y}";
- featureObj.transform.localScale = new Vector3(0.6f, 0.5f, 0.6f);
- featureObj.GetComponent<Renderer>().material.color = Color.blue;
- break;
- case FeatureType.Village:
- featureObj = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
- featureObj.name = $"Village_{x}_{y}";
- featureObj.transform.localScale = new Vector3(0.4f, 0.3f, 0.4f);
- featureObj.GetComponent<Renderer>().material.color = Color.cyan;
- break;
- case FeatureType.Road:
- featureObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
- featureObj.name = $"Road_{x}_{y}";
- featureObj.transform.localScale = new Vector3(0.8f, 0.05f, 0.8f);
- featureObj.GetComponent<Renderer>().material.color = Color.yellow;
- break;
- }
- if (featureObj != null)
- {
- featureObj.transform.parent = tileParent;
- featureObj.transform.localPosition = new Vector3(0, 0.6f, 0); // On top of tile
- }
- }
- /// <summary>
- /// Get color for terrain type
- /// </summary>
- private Color GetTerrainColor(TerrainType terrainType)
- {
- return terrainType switch
- {
- TerrainType.Plains => Color.green,
- TerrainType.Forest => new Color(0f, 0.5f, 0f), // Dark green
- TerrainType.Mountain => Color.gray,
- TerrainType.Ocean => Color.blue,
- TerrainType.Lake => new Color(0f, 0.5f, 1f), // Light blue
- TerrainType.River => Color.cyan,
- _ => Color.white
- };
- }
- /// <summary>
- /// Get the current map data
- /// </summary>
- public MapData GetMapData()
- {
- return mapData;
- }
- /// <summary>
- /// Get the team marker transform
- /// </summary>
- public Transform GetTeamMarker()
- {
- return teamMarker;
- }
- }
|