void OnTownSelected(MapTown a_Town, int a_Index) { m_SelectedTown = a_Town; m_SelectedHero = null; int _TownCount = m_LocalOwnership.GetTownCount(); // High res if (a_Index >= m_TownUIIndex + 7 || a_Index < m_TownUIIndex) { m_TownUIIndex = a_Index; if (m_TownUIIndex > _TownCount - 7) { m_TownUIIndex = _TownCount - 7; } } // Low res if (a_Index >= m_TownUIIndexLowRes + 5 || a_Index < m_TownUIIndexLowRes) { m_TownUIIndexLowRes = a_Index; if (m_TownUIIndexLowRes > _TownCount - 5) { m_TownUIIndexLowRes = _TownCount - 5; } } UpdateTownDisplay(); }
public void SelectHero(MapHero a_Hero) { if (!m_Heroes.Contains(a_Hero)) { Debug.LogError("Selected hero that isn't owned by local player"); return; } if (SelectedHero != null) { SelectedHero.OnDeselected(); OnHeroDeselected?.Invoke(SelectedHero); } else if (SelectedTown != null) { OnTownDeselected?.Invoke(SelectedTown); } SelectedHero = a_Hero; SelectedTown = null; OnHeroSelected?.Invoke(a_Hero, m_Heroes.IndexOf(a_Hero)); a_Hero.OnSelected(); }
void OnTownSelected(MapTown a_Town, int a_Index) { m_Map.ShowUnderground(a_Town.IsUnderground); transform.position = new Vector3 ( a_Town.transform.position.x - 2.5f, a_Town.transform.position.y + 0.5f, transform.position.z ); }
public void AddTown(MapTown a_Town) { if (m_Towns.Contains(a_Town)) { Debug.LogError("Attempted to add town that's already owned"); return; } m_Towns.Add(a_Town); OnTownAdded?.Invoke(a_Town); }
void OnTownSelected(MapTown a_Town, int a_Index) { m_TownCard.SetActive(true); m_InfoCard.SetActive(false); if (a_Town.Buildings.Fort) { m_TownImage.sprite = a_Town.Faction.TownSpriteLarge; } else { m_TownImage.sprite = a_Town.Faction.TownNoFortSpriteLarge; } }
public void RemoveTown(MapTown a_Town) { if (!m_Towns.Contains(a_Town)) { Debug.LogError("Attempted to remove town that isn't owned"); return; } m_Towns.Remove(a_Town); if (SelectedTown == a_Town) { OnTownDeselected?.Invoke(a_Town); SelectedTown = null; } OnTownRemoved?.Invoke(a_Town); }
void OnHeroSelected(MapHero a_Hero, int a_Index) { m_SelectedHero = a_Hero; m_SelectedTown = null; m_SelectedBorder.SetActive(true); m_SelectedBorder.transform.position = m_HeroImages[a_Index].transform.position; if (a_Index >= m_HeroUIIndexLowRes + 5) { m_HeroUIIndexLowRes = 3; } else if (a_Index < m_HeroUIIndexLowRes) { m_HeroUIIndexLowRes = a_Index; } UpdateHeroDisplayLowRes(); }
public void OpenTown(MapTown a_Town) { m_Root.SetActive(true); ShowTown(a_Town); List<MapTown> _Towns = m_LocalOwnership.GetTowns(); m_TownListIndex = _Towns.IndexOf(a_Town) - 1; if (m_TownListIndex > _Towns.Count - 3) { m_TownListIndex = _Towns.Count - 3; } if (m_TownListIndex < 0) { m_TownListIndex = 0; } UpdateTownDisplay(); }
void ShowTown(MapTown a_Town) { m_CurrentTown = a_Town; m_CurrentTownIndex = m_LocalOwnership.GetTowns().IndexOf(a_Town); int _FactionIndex = m_Factions.Factions.IndexOf(m_CurrentTown.Faction); m_TownBuildings[m_CurrentFactionIndex].gameObject.SetActive(false); m_TownBuildings[_FactionIndex].gameObject.SetActive(true); m_TownBuildings[_FactionIndex].SetBuildings(a_Town.Buildings, m_CurrentTown.CanBuildShipyard); m_CurrentFactionIndex = _FactionIndex; if (m_CurrentTown.Buildings.Fort) { m_Portrait.sprite = m_CurrentTown.Faction.TownSpriteLarge; } else { m_Portrait.sprite = m_CurrentTown.Faction.TownNoFortSpriteLarge; } }
public void SelectTown(MapTown a_Town) { if (!m_Towns.Contains(a_Town)) { Debug.LogError("Selected town that isn't owned by local player"); return; } if (SelectedHero != null) { SelectedHero.OnDeselected(); OnHeroDeselected?.Invoke(SelectedHero); } else if (SelectedTown != null) { OnTownDeselected?.Invoke(SelectedTown); } SelectedTown = a_Town; SelectedHero = null; OnTownSelected?.Invoke(a_Town, m_Towns.IndexOf(a_Town)); }
void Update() { // If mouse is in the actual map area if (Input.mousePosition.x >= GameScreenScaler.VIEWPORT_PADDING_LEFT && Input.mousePosition.y >= GameScreenScaler.VIEWPORT_PADDING_BOTTOM && Input.mousePosition.x <= Screen.width - GameScreenScaler.VIEWPORT_PADDING_RIGHT && Input.mousePosition.y <= Screen.height - GameScreenScaler.VIEWPORT_PADDING_TOP && !m_TownScreen.Enabled) { Vector3 _WorldMousePos = m_Camera.ScreenToWorldPoint(Input.mousePosition - new Vector3(0, 8, 0)); Vector2Int _WorldMouseCoords = new Vector2Int ( (int)(_WorldMousePos.x + 0.5f), (int)(-_WorldMousePos.y + 0.5f) ); // If mouse has moved onto a different tile in the world if (m_PreviousWorldMouseCoords != _WorldMouseCoords || m_UpdateCursor) { // If mouse coords are within the bounds of the map if (_WorldMouseCoords.x >= 0 && _WorldMouseCoords.y >= 0 && _WorldMouseCoords.x < m_GameSettings.Scenario.Size && _WorldMouseCoords.y < m_GameSettings.Scenario.Size) { m_HoveredTown = null; m_HoveredHero = null; MapHero _SelectedHero = m_LocalOwnership.SelectedHero; m_PreviousWorldMouseCoords = _WorldMouseCoords; m_UpdateCursor = false; Pathfinding.Node _Node = m_Pathfinding.GetNode(_WorldMouseCoords, false); List <MapObjectBase> _Objects = new List <MapObjectBase>(_Node.BlockingObjects.Count + _Node.InteractionObjects.Count); for (int i = 0; i < _Node.BlockingObjects.Count; i++) { _Objects.Add(_Node.BlockingObjects[i]); } for (int i = 0; i < _Node.InteractionObjects.Count; i++) { _Objects.Add(_Node.InteractionObjects[i]); } // Flag used to break out of logic if an earlier bit of logic has already determined what the cursor should be bool _CursorSelected = false; int _TurnCost = 0; if (_SelectedHero != null) { _TurnCost = _SelectedHero.GetPathingTurnCost(_WorldMouseCoords.x, _WorldMouseCoords.y); } // Check if any of the objects are heroes for (int i = 0; i < _Objects.Count; i++) { MapHero _Hero = _Objects[i] as MapHero; if (_Hero != null) { m_HoveredObject = _Hero; if (_SelectedHero != null) { if (_SelectedHero == _Hero) { CursorManager.SetCursor(m_HeroCursor, new Vector2(-12, 10)); } else if (_Hero.IsPrison) { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break; case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break; case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break; default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break; } } else if (_Hero.PlayerIndex == m_GameSettings.LocalPlayerIndex) { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_TradeCursor, new Vector2(-8, 9)); break; case 2: CursorManager.SetCursor(m_TradeCursor2, new Vector2(-8, 9)); break; case 3: CursorManager.SetCursor(m_TradeCursor3, new Vector2(-8, 9)); break; default: CursorManager.SetCursor(m_TradeCursor4, new Vector2(-8, 9)); break; } } else { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_AttackCursor, new Vector2(-13, 13)); break; case 2: CursorManager.SetCursor(m_AttackCursor2, new Vector2(-13, 13)); break; case 3: CursorManager.SetCursor(m_AttackCursor3, new Vector2(-13, 13)); break; default: CursorManager.SetCursor(m_AttackCursor4, new Vector2(-13, 13)); break; } } _CursorSelected = true; } else if (!_Hero.IsPrison && _Hero.PlayerIndex == m_GameSettings.LocalPlayerIndex) { CursorManager.SetCursor(m_HeroCursor, new Vector2(-12, 10)); m_HoveredHero = _Hero; _CursorSelected = true; } break; } } // Check if any of the objects are towns if (!_CursorSelected) { for (int i = 0; i < _Objects.Count; i++) { MapTown _Town = _Objects[i] as MapTown; if (_Town != null) { m_HoveredObject = _Objects[i]; int _XIndex = 8 - Mathf.Clamp(Mathf.CeilToInt(_Objects[i].transform.position.x - _WorldMousePos.x), 0, 7); int _YIndex = 6 - Mathf.Clamp(Mathf.CeilToInt(_WorldMousePos.y - _Objects[i].transform.position.y), 0, 5); // If the cursor is specifically on the castle's entrance, horse rear cursor if (_SelectedHero != null && _XIndex == 5 && _YIndex == 5) { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break; case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break; case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break; default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break; } } else if (_Town.PlayerIndex == m_GameSettings.LocalPlayerIndex) { CursorManager.SetCursor(m_CastleCursor, new Vector2(-12, 12)); m_HoveredTown = _Town; } else { CursorManager.ResetCursor(); } _CursorSelected = true; break; } } } // If a hero is currently selected, set movement cursor if (_SelectedHero != null) { if (!_CursorSelected) { // If the mouse is on an interaction tile, horse rear cursor if (_Objects.Count > 0) { int _XIndex = 8 - Mathf.Clamp(Mathf.CeilToInt(_Objects[0].transform.position.x - _WorldMousePos.x), 0, 7); int _YIndex = 6 - Mathf.Clamp(Mathf.CeilToInt(_WorldMousePos.y - _Objects[0].transform.position.y), 0, 5); if ((_Objects[0].InteractionCollision[_YIndex] & 1 << _XIndex) != 0) { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break; case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break; case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break; default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break; } _CursorSelected = true; } } } if (!_CursorSelected) { // If the mouse is on the end point of the current selected destination, horse rear cursor if (_SelectedHero.GetTargetDestination() == _WorldMouseCoords) { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_InteractCursor, new Vector2(-14, 15)); break; case 2: CursorManager.SetCursor(m_InteractCursor2, new Vector2(-14, 15)); break; case 3: CursorManager.SetCursor(m_InteractCursor3, new Vector2(-14, 15)); break; default: CursorManager.SetCursor(m_InteractCursor4, new Vector2(-14, 15)); break; } } else { switch (_TurnCost) { case 0: CursorManager.ResetCursor(); break; case 1: CursorManager.SetCursor(m_MoveCursor, new Vector2(-15, 13)); break; case 2: CursorManager.SetCursor(m_MoveCursor2, new Vector2(-15, 13)); break; case 3: CursorManager.SetCursor(m_MoveCursor3, new Vector2(-15, 13)); break; default: CursorManager.SetCursor(m_MoveCursor4, new Vector2(-15, 13)); break; } } _CursorSelected = true; } } if (!_CursorSelected) { CursorManager.ResetCursor(); } } else { CursorManager.ResetCursor(); } } if (Input.GetMouseButtonDown(0)) { if (m_HoveredTown != null) { if (m_HoveredTown != m_LocalOwnership.SelectedTown) { m_LocalOwnership.SelectTown(m_HoveredTown); } else { m_TownScreen.OpenTown(m_HoveredTown); } } else if (m_LocalOwnership.SelectedHero != null) { if (m_LocalOwnership.SelectedHero.IsMoving) { m_LocalOwnership.SelectedHero.CancelMovement(); } else { m_LocalOwnership.SelectedHero.OnLeftClick(_WorldMouseCoords.x, _WorldMouseCoords.y, m_HoveredObject); } } else if (m_HoveredHero != null) { m_LocalOwnership.SelectHero(m_HoveredHero); } m_UpdateCursor = true; } } else { if (Input.GetMouseButtonDown(0)) { if (m_LocalOwnership.SelectedHero != null) { if (m_LocalOwnership.SelectedHero.IsMoving) { m_LocalOwnership.SelectedHero.CancelMovement(); } } } m_UpdateCursor = true; CursorManager.ResetCursor(); } if (!m_TownScreen.Enabled) { if (Input.mousePosition.x <= 2) { if (Input.mousePosition.y <= 2) { CursorManager.SetCursor(m_BottomLeftCursor, new Vector2(0, 18)); } else if (Input.mousePosition.y >= Screen.height - 3) { CursorManager.SetCursor(m_TopLeftCursor, new Vector2(0, 1)); } else { CursorManager.SetCursor(m_LeftCursor, new Vector2(0, 5)); } } else if (Input.mousePosition.x >= Screen.width - 3) { if (Input.mousePosition.y <= 2) { CursorManager.SetCursor(m_BottomRightCursor, new Vector2(-18, 18)); } else if (Input.mousePosition.y >= Screen.height - 3) { CursorManager.SetCursor(m_TopRightCursor, new Vector2(-18, 1)); } else { CursorManager.SetCursor(m_RightCursor, new Vector2(-23, 6)); } } else { if (Input.mousePosition.y <= 2) { CursorManager.SetCursor(m_BottomCursor, new Vector2(-6, 23)); } else if (Input.mousePosition.y >= Screen.height - 3) { CursorManager.SetCursor(m_TopCursor, new Vector2(-6, 0)); } } } }
IEnumerator Move() { if (m_Path.Count == 0) { yield break; } IsAsleep = false; m_StopMovement = false; IsMoving = true; m_FlagRenderer.enabled = false; HeroFlagVisualData _FlagData = m_PlayerColors.Flags[PlayerIndex]; m_DynamicObstacle.ClearNodes(); Pathfinding.PrecomputedNode _Node = m_Path[0]; Destroy(m_PathNodes[0]); Destroy(m_PathNodeShadows[0]); m_PathNodes.RemoveAt(0); m_PathNodeShadows.RemoveAt(0); int _AnimationIndex = 0; int _Frame = 0; m_GameReferences.InputBlocker.SetActive(true); Vector3 _MovementDirection; void SetDirection() { _MovementDirection = new Vector3 ( m_Path[0].PosX - m_PathfindingPos.x, -(m_Path[0].PosY - m_PathfindingPos.y), 0 ) / 4; if (_MovementDirection.x > 0) { if (_MovementDirection.y > 0) { m_Direction = DIRECTION_NE; } else if (_MovementDirection.y < 0) { m_Direction = DIRECTION_SE; } else { m_Direction = DIRECTION_E; } } else if (_MovementDirection.x < 0) { if (_MovementDirection.y > 0) { m_Direction = DIRECTION_NW; } else if (_MovementDirection.y < 0) { m_Direction = DIRECTION_SW; } else { m_Direction = DIRECTION_W; } } else if (_MovementDirection.y > 0) { m_Direction = DIRECTION_N; } else { m_Direction = DIRECTION_S; } } SetDirection(); OnStartMovement?.Invoke(); // We don't check IsMoving here, because when cancelled, we still want to finish walking to the next tile while (true) { if (_Frame == 4) { _Frame = 0; m_PathfindingPos = new Vector2Int(_Node.PosX, _Node.PosY); m_Path.RemoveAt(0); if (m_Path.Count == 0 || m_StopMovement) { break; } Destroy(m_PathNodes[0]); Destroy(m_PathNodeShadows[0]); m_PathNodes.RemoveAt(0); m_PathNodeShadows.RemoveAt(0); _Node = m_Path[0]; SetDirection(); } m_HeroRenderer.sprite = Hero.HeroVisualData.MovingSprites[m_Direction].Array[_AnimationIndex]; m_HeroShadowRenderer.sprite = Hero.HeroVisualData.ShadowMovingSprites[m_Direction].Array[_AnimationIndex]; m_FlagSpriteRenderer.sprite = _FlagData.MovingSprites[m_Direction].Array[_AnimationIndex]; m_HeroRenderer.flipX = HeroVisualData.SPRITES_FLIPPED[m_Direction]; m_HeroShadowRenderer.flipX = HeroVisualData.SPRITES_FLIPPED[m_Direction]; m_FlagSpriteRenderer.flipX = HeroVisualData.SPRITES_FLIPPED[m_Direction]; if (m_HeroRenderer.flipX) { m_HeroRenderer.transform.localPosition = new Vector3(-3, 0, 0); m_HeroShadowRenderer.transform.localPosition = new Vector3(-3, 0, 0); m_FlagSpriteRenderer.transform.localPosition = new Vector2(-3, 0) + Hero.HeroVisualData.MovingFlagOffsets[m_Direction]; } else { m_HeroRenderer.transform.localPosition = Vector3.zero; m_HeroShadowRenderer.transform.localPosition = Vector3.zero; m_FlagSpriteRenderer.transform.localPosition = Hero.HeroVisualData.MovingFlagOffsets[m_Direction]; } transform.position += _MovementDirection; yield return(new WaitForSeconds(0.05f)); _AnimationIndex++; _Frame++; if (_AnimationIndex == 8) { _AnimationIndex = 0; } } m_GameReferences.InputBlocker.SetActive(false); m_FlagRenderer.enabled = true; m_HeroRenderer.sprite = Hero.HeroVisualData.IdleSprites[m_Direction]; m_HeroShadowRenderer.sprite = Hero.HeroVisualData.ShadowIdleSprites[m_Direction]; m_HeroRenderer.flipX = HeroVisualData.SPRITES_FLIPPED[m_Direction]; m_HeroShadowRenderer.flipX = HeroVisualData.SPRITES_FLIPPED[m_Direction]; m_FlagSpriteRenderer.flipX = HeroVisualData.SPRITES_FLIPPED[m_Direction]; if (m_HeroRenderer.flipX) { m_HeroRenderer.transform.localPosition = new Vector3(-3, 0, 0); m_HeroShadowRenderer.transform.localPosition = new Vector3(-3, 0, 0); m_FlagSpriteRenderer.transform.localPosition = new Vector2(-3, 0) + Hero.HeroVisualData.IdleFlagOffsets[m_Direction]; } else { m_HeroRenderer.transform.localPosition = Vector3.zero; m_HeroShadowRenderer.transform.localPosition = Vector3.zero; m_FlagSpriteRenderer.transform.localPosition = Hero.HeroVisualData.IdleFlagOffsets[m_Direction]; } Pathfinding.Node _FinalNode = m_GameReferences.Pathfinding.GetNode(m_PathfindingPos, IsUnderground); m_DynamicObstacle.AddInteractedNode(_FinalNode); for (int i = 0; i < _FinalNode.InteractionObjects.Count; i++) { MapTown _Town = _FinalNode.InteractionObjects[i] as MapTown; if (_Town != null) { m_GameReferences.TownScreen.OpenTown(_Town); } } m_PathableArea = m_GameReferences.Pathfinding.GetPathableArea(m_PathfindingPos, IsUnderground); if (m_Path.Count == 0) { m_TargetNodeIndex = -1; HasPath = false; OnPathRemoved?.Invoke(); } IsMoving = false; }
void OnTownRemoved(MapTown a_Town) { UpdateTownDisplay(); }
void OnTownAdded(MapTown a_Town) { UpdateTownDisplay(); }
void Start() { m_TerrainSprites = new List <List <Sprite> >(); m_TerrainSprites.Add(m_DirtSprites); m_TerrainSprites.Add(m_SandSprites); m_TerrainSprites.Add(m_GrassSprites); m_TerrainSprites.Add(m_SnowSprites); m_TerrainSprites.Add(m_SwampSprites); m_TerrainSprites.Add(m_RoughSprites); m_TerrainSprites.Add(m_SubterraneanSprites); m_TerrainSprites.Add(m_LavaSprites); m_TerrainSprites.Add(new List <Sprite>()); m_TerrainSprites.Add(m_RockSprites); m_RiverSprites = new List <List <Sprite> >(); m_RiverSprites.Add(new List <Sprite>()); m_RiverSprites.Add(m_IcyRiverSprites); m_RiverSprites.Add(m_MuddyRiverSprites); m_RiverSprites.Add(new List <Sprite>()); m_RoadSprites = new List <List <Sprite> >(); m_RoadSprites.Add(m_DirtRoadSprites); m_RoadSprites.Add(m_GravelRoadSprites); m_RoadSprites.Add(m_CobbleRoadSprites); if (m_GameSettings.Scenario.Version != Scenario.SHADOW_OF_DEATH) { Debug.Log($"This map isn't SoD, not supported yet"); return; } int _Size = m_GameSettings.Scenario.Size; m_TerrainFrame.size = new Vector2(_Size + 2, _Size + 2); m_TerrainFrame.transform.localPosition = new Vector3(_Size / 2 - 0.5f, -_Size / 2 + 0.5f, 0); m_TerrainMask.localScale = new Vector3(_Size, _Size, 1); m_TerrainMask.transform.localPosition = new Vector3(_Size / 2 - 0.5f, -_Size / 2 + 0.5f, 0); // <><><><><> Above Ground Terrain List <TerrainTile> _Terrain = m_GameSettings.Scenario.Terrain; m_TerrainTileObjects = new List <TerrainTileObject>(_Terrain.Capacity); m_RiverTileObjects = new List <TerrainTileObject>(); m_RoadTileObjects = new List <TerrainTileObject>(); for (int x = 0; x < _Size; x++) { for (int y = 0; y < _Size; y++) { int _Index = x + y * _Size; // <><><><><> Terrain Tile TerrainTileObject _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity); _TileObject.Renderer.sortingOrder = -32768; if (_Terrain[_Index].TerrainType < m_TerrainSprites.Count) { if (_Terrain[_Index].TerrainType == WATER_TILE_INDEX) { _TileObject.AnimationRenderer.SetSprites(m_WaterAnimations[_Terrain[_Index].TerrainSpriteID].Array); } else if (_Terrain[_Index].TerrainSpriteID < m_TerrainSprites[_Terrain[_Index].TerrainType].Count) { _TileObject.Renderer.sprite = m_TerrainSprites[_Terrain[_Index].TerrainType][_Terrain[_Index].TerrainSpriteID]; } else { Debug.Log($"Failed ID {_Terrain[_Index].TerrainSpriteID}"); } } else { Debug.Log($"Failed Type {_Terrain[_Index].TerrainType}"); } _TileObject.Renderer.sortingLayerName = "Terrain"; _TileObject.Renderer.flipX = (_Terrain[_Index].Mirrored & 1) == 1; _TileObject.Renderer.flipY = (_Terrain[_Index].Mirrored & 2) == 2; _TileObject.name = $"{_TileObject.Renderer.sprite.name} Pos {_Index} ID {_Terrain[_Index].TerrainSpriteID}"; _TileObject.transform.parent = m_TerrainTileObjectParent; m_TerrainTileObjects.Add(_TileObject); // <><><><><> River Tile if (_Terrain[_Index].RiverType != 0) { _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity); if (_Terrain[_Index].RiverType - 1 < m_RiverSprites.Count) { if (_Terrain[_Index].RiverType == CLEAR_RIVER_INDEX) { _TileObject.AnimationRenderer.SetSprites(m_ClearRiverAnimations[_Terrain[_Index].RiverSpriteID].Array); } else if (_Terrain[_Index].RiverType == LAVA_RIVER_INDEX) { _TileObject.AnimationRenderer.SetSprites(m_LavaRiverAnimations[_Terrain[_Index].RiverSpriteID].Array); } else if (_Terrain[_Index].RiverSpriteID < m_RiverSprites[_Terrain[_Index].RiverType - 1].Count) { _TileObject.Renderer.sprite = m_RiverSprites[_Terrain[_Index].RiverType - 1][_Terrain[_Index].RiverSpriteID]; } else { Debug.Log($"River Failed ID {_Terrain[_Index].RiverSpriteID}"); } } else { Debug.Log($"River Failed Type {_Terrain[_Index].RiverSpriteID}"); } _TileObject.Renderer.sortingOrder = 1; _TileObject.Renderer.sortingLayerName = "Terrain"; _TileObject.Renderer.flipX = (_Terrain[_Index].Mirrored & 4) == 4; _TileObject.Renderer.flipY = (_Terrain[_Index].Mirrored & 8) == 8; _TileObject.name = $"{_TileObject.Renderer.sprite.name} Pos {_Index} ID {_Terrain[_Index].RiverSpriteID}"; _TileObject.transform.parent = m_RiverTileObjectParent; m_RiverTileObjects.Add(_TileObject); } // <><><><><> Road Tile if (_Terrain[_Index].RoadType != 0) { _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y - 0.5f), Quaternion.identity); if (_Terrain[_Index].RoadType - 1 < m_RoadSprites.Count) { if (_Terrain[_Index].RoadSpriteID < m_RoadSprites[_Terrain[_Index].RoadType - 1].Count) { _TileObject.Renderer.sprite = m_RoadSprites[_Terrain[_Index].RoadType - 1][_Terrain[_Index].RoadSpriteID]; } else { Debug.Log($"Road Failed ID {_Terrain[_Index].RoadSpriteID}"); } } else { Debug.Log($"Road Failed Type {_Terrain[_Index].RoadSpriteID}"); } _TileObject.Renderer.sortingOrder = 2; _TileObject.Renderer.sortingLayerName = "Terrain"; _TileObject.Renderer.flipX = (_Terrain[_Index].Mirrored & 16) == 16; _TileObject.Renderer.flipY = (_Terrain[_Index].Mirrored & 32) == 32; _TileObject.name = $"{_TileObject.Renderer.sprite.name} Pos {_Index} ID {_Terrain[_Index].RoadSpriteID}"; _TileObject.transform.parent = m_RoadTileObjectParent; m_RoadTileObjects.Add(_TileObject); } } } if (m_GameSettings.Scenario.HasUnderground) { // <><><><><> Underground Terrain List <TerrainTile> _UndergroundTerrain = m_GameSettings.Scenario.UndergroundTerrain; m_UndergroundTerrainTileObjects = new List <TerrainTileObject>(_Terrain.Capacity); m_UndergroundRiverTileObjects = new List <TerrainTileObject>(); m_UndergroundRoadTileObjects = new List <TerrainTileObject>(); for (int x = 0; x < _Size; x++) { for (int y = 0; y < _Size; y++) { int _Index = x + y * _Size; // <><><><><> Terrain Tile TerrainTileObject _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity); _TileObject.Renderer.sortingOrder = -32768; if (_UndergroundTerrain[_Index].TerrainType < m_TerrainSprites.Count) { if (_UndergroundTerrain[_Index].TerrainType == WATER_TILE_INDEX) { if (m_WaterAnimations[_UndergroundTerrain[_Index].TerrainSpriteID] != null) { _TileObject.AnimationRenderer.SetSprites(m_WaterAnimations[_UndergroundTerrain[_Index].TerrainSpriteID].Array); } } else if (_UndergroundTerrain[_Index].TerrainSpriteID < m_TerrainSprites[_UndergroundTerrain[_Index].TerrainType].Count) { _TileObject.Renderer.sprite = m_TerrainSprites[_UndergroundTerrain[_Index].TerrainType][_UndergroundTerrain[_Index].TerrainSpriteID]; } else { Debug.Log($"Failed ID {_UndergroundTerrain[_Index].TerrainSpriteID}"); } } else { Debug.Log($"Failed Type {_UndergroundTerrain[_Index].TerrainType}"); } _TileObject.Renderer.sortingLayerName = "Terrain"; _TileObject.Renderer.flipX = (_UndergroundTerrain[_Index].Mirrored & 1) == 1; _TileObject.Renderer.flipY = (_UndergroundTerrain[_Index].Mirrored & 2) == 2; _TileObject.name = $"{_TileObject.Renderer.sprite.name} Pos {_Index} ID {_UndergroundTerrain[_Index].TerrainSpriteID}"; _TileObject.transform.parent = m_UndergroundTerrainTileObjectParent; m_UndergroundTerrainTileObjects.Add(_TileObject); // <><><><><> River Tile if (_UndergroundTerrain[_Index].RiverType != 0) { _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity); if (_UndergroundTerrain[_Index].RiverType == CLEAR_RIVER_INDEX) { _TileObject.AnimationRenderer.SetSprites(m_ClearRiverAnimations[_UndergroundTerrain[_Index].RiverSpriteID].Array); } else if (_UndergroundTerrain[_Index].RiverType == LAVA_RIVER_INDEX) { _TileObject.AnimationRenderer.SetSprites(m_LavaRiverAnimations[_UndergroundTerrain[_Index].RiverSpriteID].Array); } else if (_UndergroundTerrain[_Index].RiverSpriteID < m_RiverSprites[_UndergroundTerrain[_Index].RiverType - 1].Count) { _TileObject.Renderer.sprite = m_RiverSprites[_UndergroundTerrain[_Index].RiverType - 1][_UndergroundTerrain[_Index].RiverSpriteID]; } else { Debug.Log($"River Failed ID {_UndergroundTerrain[_Index].RiverSpriteID}"); } _TileObject.Renderer.sortingOrder = 1; _TileObject.Renderer.sortingLayerName = "Terrain"; _TileObject.Renderer.flipX = (_UndergroundTerrain[_Index].Mirrored & 4) == 4; _TileObject.Renderer.flipY = (_UndergroundTerrain[_Index].Mirrored & 8) == 8; _TileObject.name = $"{_TileObject.Renderer.sprite.name} Pos {_Index} ID {_UndergroundTerrain[_Index].RiverSpriteID}"; _TileObject.transform.parent = m_UndergroundRiverTileObjectParent; m_UndergroundRiverTileObjects.Add(_TileObject); } // <><><><><> Road Tile if (_UndergroundTerrain[_Index].RoadType != 0) { _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y - 0.5f), Quaternion.identity); if (_UndergroundTerrain[_Index].RoadType - 1 < m_RoadSprites.Count) { if (_UndergroundTerrain[_Index].RoadSpriteID < m_RoadSprites[_UndergroundTerrain[_Index].RoadType - 1].Count) { _TileObject.Renderer.sprite = m_RoadSprites[_UndergroundTerrain[_Index].RoadType - 1][_UndergroundTerrain[_Index].RoadSpriteID]; } else { Debug.Log($"Road Failed ID {_UndergroundTerrain[_Index].RoadSpriteID}"); } } else { Debug.Log($"Road Failed Type {_UndergroundTerrain[_Index].RoadSpriteID}"); } _TileObject.Renderer.sortingOrder = 2; _TileObject.Renderer.sortingLayerName = "Terrain"; _TileObject.Renderer.flipX = (_UndergroundTerrain[_Index].Mirrored & 16) == 16; _TileObject.Renderer.flipY = (_UndergroundTerrain[_Index].Mirrored & 32) == 32; _TileObject.name = $"{_TileObject.Renderer.sprite.name} Pos {_Index} ID {_UndergroundTerrain[_Index].RoadSpriteID}"; _TileObject.transform.parent = m_UndergroundRoadTileObjectParent; m_UndergroundRoadTileObjects.Add(_TileObject); } } } } // <><><><><> Objects m_OverworldObjects = new List <GameObject>(); m_UndergroundObjects = new List <GameObject>(); List <ScenarioObject> _Objects = m_GameSettings.Scenario.Objects; List <MapObjectBase> _MapObjects = new List <MapObjectBase>(_Objects.Count); Dictionary <ScenarioObject, DynamicMapObstacle> _DynamicObstacles = new Dictionary <ScenarioObject, DynamicMapObstacle>(); // Load map objects for (int i = 0; i < _Objects.Count; i++) { ScenarioObject _Object = _Objects[i]; MapObjectBase _MapObject; switch (_Object.Template.Type) { case ScenarioObjectType.Hero: MapHero _Hero = Instantiate(m_MapHeroPrefab, m_MapObjectParent); _Hero.Initialize(_Object, m_GameReferences); _MapObject = _Hero; _DynamicObstacles.Add(_Object, _Hero.DynamicObstacle); break; case ScenarioObjectType.Resource: MapResource _Resource = Instantiate(m_MapResourcePrefab, m_MapObjectParent); _Resource.Initialize(_Object, m_GameReferences); _MapObject = _Resource; _DynamicObstacles.Add(_Object, _Resource.DynamicObstacle); break; case ScenarioObjectType.Dwelling: case ScenarioObjectType.Mine: // Temporary case ScenarioObjectType.AbandonedMine: // Temporary MapDwelling _Dwelling = Instantiate(m_MapDwellingPrefab, m_MapObjectParent); _Dwelling.Initialize(_Object, m_GameReferences); _MapObject = _Dwelling; break; case ScenarioObjectType.Town: MapTown _Town = Instantiate(m_MapTownPrefab, m_MapObjectParent); // Determine if this town can build a shipyard, and where the ship will spawn Vector2Int _ShipyardSpot = Vector2Int.zero; Vector2Int _ShipyardSpot1 = new Vector2Int(_Object.PosX - 3, _Object.PosY + 2); Vector2Int _ShipyardSpot2 = new Vector2Int(_Object.PosX - 1, _Object.PosY + 2); int _ShipyardIndex1 = _ShipyardSpot1.x + _ShipyardSpot1.y * _Size; int _ShipyardIndex2 = _ShipyardSpot2.x + _ShipyardSpot2.y * _Size; if (_ShipyardIndex1 < _Size * _Size) { if (_Terrain[_ShipyardIndex1].TerrainType == WATER_TILE_INDEX) { _ShipyardSpot = _ShipyardSpot1; } else if (_ShipyardIndex2 < _Size * _Size && _Terrain[_ShipyardIndex2].TerrainType == WATER_TILE_INDEX) { _ShipyardSpot = _ShipyardSpot2; } } // If _ShipyardSpot is still Vector2Int.zero, there's no shipyard _Town.Initialize(_Object, m_GameReferences, _ShipyardSpot); _MapObject = _Town; break; case ScenarioObjectType.Monster: MapMonster _Monster = Instantiate(m_MapMonsterPrefab, m_MapObjectParent); _Monster.Initialize(_Object, m_GameReferences); _MapObject = _Monster; _DynamicObstacles.Add(_Object, _Monster.DynamicObstacle); break; case ScenarioObjectType.Garrison: MapGarrison _Garrison = Instantiate(m_MapGarrisonPrefab, m_MapObjectParent); _Garrison.Initialize(_Object, m_GameReferences); _MapObject = _Garrison; break; default: MapObject _Obj = Instantiate(m_MapObjectPrefab, m_MapObjectParent); _Obj.Initialize(_Object, m_GameReferences); _MapObject = _Obj; break; } _MapObject.transform.position = new Vector3(_Object.PosX + 0.5f, -_Object.PosY - 0.5f, 0); _MapObject.MouseCollision = new byte[6]; _MapObject.MouseCollision[0] = (byte)(~_Object.Template.Passability[0] | _Object.Template.Interactability[0]); _MapObject.MouseCollision[1] = (byte)(~_Object.Template.Passability[1] | _Object.Template.Interactability[1]); _MapObject.MouseCollision[2] = (byte)(~_Object.Template.Passability[2] | _Object.Template.Interactability[2]); _MapObject.MouseCollision[3] = (byte)(~_Object.Template.Passability[3] | _Object.Template.Interactability[3]); _MapObject.MouseCollision[4] = (byte)(~_Object.Template.Passability[4] | _Object.Template.Interactability[4]); _MapObject.MouseCollision[5] = (byte)(~_Object.Template.Passability[5] | _Object.Template.Interactability[5]); _MapObject.InteractionCollision = _Object.Template.Interactability; if (_Object.IsUnderground) { m_UndergroundObjects.Add(_MapObject.gameObject); _MapObject.transform.parent = m_UndergroundMapObjectParent; } else { m_OverworldObjects.Add(_MapObject.gameObject); } _MapObjects.Add(_MapObject); } m_Pathfinding.Generate(m_GameSettings.Scenario, _MapObjects, _DynamicObstacles); // Spawn starting heroes for (int i = 0; i < m_GameSettings.Players.Count; i++) { PlayerInfo _PlayerInfo = m_GameSettings.Scenario.PlayerInfo[i]; if (_PlayerInfo.GenerateHeroAtMainTown) { MapHero _MapHero = Instantiate(m_MapHeroPrefab, m_MapObjectParent); // Spawn map object at main town coordinates if (_PlayerInfo.IsMainTownUnderground) { _MapHero.transform.parent = m_UndergroundMapObjectParent; } Hero _Hero; if (_PlayerInfo.IsMainHeroRandom) { _Hero = HeroPool.GetRandomHero(m_GameSettings.Players[i].Index, m_GameSettings.Players[i].Faction, true); HeroPool.ClaimHero(_Hero); } else { _Hero = m_GameSettings.Players[i].Hero; } _MapHero.Initialize ( _Hero, m_GameSettings.Players[i].Index, m_GameSettings.Scenario.PlayerInfo[i].MainTownXCoord + 1, m_GameSettings.Scenario.PlayerInfo[i].MainTownYCoord, m_GameSettings.Scenario.PlayerInfo[i].IsMainTownUnderground, m_GameReferences ); } } List <MapHero> _LocalOwnership = m_LocalOwnership.GetHeroes(); if (_LocalOwnership.Count > 0) { m_LocalOwnership.SelectHero(_LocalOwnership[0]); } }
void OnTownDeselected(MapTown a_Town) { m_TownCard.SetActive(false); // Day X thing }