Exemple #1
0
        public void RemoveUnit(GameData.Wreckage wreck)
        {
            List <WreckageView> views = new List <WreckageView>(m_ResourceContainer.GetComponentsInChildren <WreckageView>());
            WreckageView        view  = views.Find((v) => v.wreck == wreck);

            Destroy(view.gameObject);
        }
Exemple #2
0
        public UnitView AddUnit(GameData.Wreckage wreck, Color tint)
        {
            GameObject   goUnit = CreateUnit("Wreckage", m_ResourceContainer, wreck.id, new Vector2Int(wreck.position.x, wreck.position.y));
            WreckageView view   = goUnit.GetComponent <WreckageView>();

            view.Initialize(wreck, tint);
            return(view);
        }
Exemple #3
0
        public void Initialize(GameData.Wreckage wreck, Color tint)
        {
            this.wreck = wreck;

            GetComponent <SpriteRenderer>().color = tint;

            // Add to minimap
            m_UnitMinimap.AddUnit(this, GetMapCoordinates(new Vector2Int(wreck.position.x, wreck.position.y)), 1);

            RefreshOverlay();
        }
Exemple #4
0
        private GameData.Wreckage GetWreckageData()
        {
            int id;

            int.TryParse(m_InputID.text, out id);

            // Create wreckage data
            GameData.Wreckage wreck = new GameData.Wreckage();
            wreck.id        = id;
            wreck.techID    = m_WreckageTypes[m_DropdownWreckageTypes.value];
            wreck.isVisible = m_IsVisible.isOn;
            wreck.position  = new DataLocation(new LOCATION(1, 1));

            return(wreck);
        }
Exemple #5
0
        protected override void OnEraseTile(Vector2Int tileXY)
        {
            // Add game coordinates
            tileXY += Vector2Int.one;

            // Find wreckage on tile
            int index = UserData.current.selectedTethysGame.wreckage.FindIndex((w) => w.position.x == tileXY.x && w.position.y == tileXY.y);

            if (index < 0)
            {
                return;
            }

            GameData.Wreckage wreckToRemove = UserData.current.selectedTethysGame.wreckage[index];

            // Remove wreckage from tile
            UserData.current.selectedTethysGame.wreckage.RemoveAt(index);
            UserData.current.SetUnsaved();

            m_UnitRenderer.RemoveUnit(wreckToRemove);
        }
Exemple #6
0
        protected override void OnPaintTile(Vector2Int tileXY)
        {
            // Add game coordinates
            tileXY += Vector2Int.one;

            // If tile already contains wreckage, cancel
            if (UserData.current.GetCombinedTethysGame().wreckage.Find((w) => w.position.x == tileXY.x && w.position.y == tileXY.y) != null)
            {
                return;
            }

            // Create wreckage data
            GameData.Wreckage wreck = GetWreckageData();
            wreck.position = new LOCATION(tileXY.x, tileXY.y);

            // Add wreckage to tile
            UserData.current.selectedTethysGame.wreckage.Add(wreck);
            UserData.current.SetUnsaved();

            m_UnitRenderer.AddUnit(wreck);
        }
        private void Update()
        {
            m_txtHeaders.text = "";
            m_txtInfo.text    = "";

            // If mouse is over UI, we should not get unit info
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            // Get the tile that we are over
            Vector2    worldMousePt = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3Int cell         = m_Tilemap.WorldToCell(worldMousePt);

            // Don't do anything out of bounds
            if (cell.x < 0 || cell.y < 0 || cell.x >= m_Tilemap.size.x || cell.y >= m_Tilemap.size.y)
            {
                return;
            }

            // Invert Y to match data storage instead of render value
            cell.y = m_Tilemap.size.y - (cell.y + 1);

            // Add game coordinates
            cell += Vector3Int.one;

            // Get unit on tile
            UnitData unitOnTile = GetUnitOnTile(cell.x, cell.y);

            if (unitOnTile != null)
            {
                // Display info for unit on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                string type = unitOnTile.typeID.ToString();

                // Add weapon to type
                if (unitOnTile.typeID == map_id.GuardPost || unitOnTile.typeID == map_id.Lynx || unitOnTile.typeID == map_id.Panther || unitOnTile.typeID == map_id.Tiger)
                {
                    type += " " + ((map_id)unitOnTile.cargoType).ToString();
                }

                headers.AppendLine("ID:");              info.AppendLine(unitOnTile.id.ToString());
                headers.AppendLine("Type:");    info.AppendLine(type);
                if (IsVehicle(unitOnTile.typeID) || IsStructure(unitOnTile.typeID))
                {
                    headers.AppendLine("Health:");        info.AppendLine((unitOnTile.health * 100).ToString("N2") + "%");
                }
                if (IsVehicle(unitOnTile.typeID))
                {
                    headers.AppendLine("Direction:");     info.AppendLine(unitOnTile.direction.ToString());
                }
                if (IsVehicle(unitOnTile.typeID))
                {
                    headers.AppendLine("Lights:");        info.AppendLine(unitOnTile.lights ? "On" : "Off");
                }
                if (IsMine(unitOnTile.typeID) || Isbeacon(unitOnTile.typeID))
                {
                    headers.AppendLine("Yield:");         info.AppendLine(unitOnTile.barYield.ToString());
                }
                if (IsMine(unitOnTile.typeID) || Isbeacon(unitOnTile.typeID))
                {
                    headers.AppendLine("Variant:");       info.AppendLine(unitOnTile.barVariant.ToString());
                }
                string cargoText = GetCargoText(unitOnTile);
                if (cargoText != null)
                {
                    string[] typeAmount = cargoText.Split(':');

                    headers.AppendLine("Cargo:");           info.AppendLine(typeAmount[0]);
                    if (typeAmount.Length >= 2)
                    {
                        headers.AppendLine("Amount:");          info.AppendLine(typeAmount[1]);
                    }
                }
                headers.AppendLine("Position:");        info.AppendLine(unitOnTile.position.x.ToString() + ", " + unitOnTile.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get beacon on tile
            GameData.Beacon beacon = UserData.current.selectedVariant.tethysGame.beacons.Find((b) => b.position.x == cell.x && b.position.y == cell.y);
            if (beacon != null)
            {
                // Display info for beacon on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                headers.AppendLine("ID:");                      info.AppendLine(beacon.id.ToString());
                headers.AppendLine("Type:");            info.AppendLine(beacon.mapID.ToString());
                if (beacon.mapID == map_id.MiningBeacon)
                {
                    headers.AppendLine("Ore Type:");        info.AppendLine(beacon.oreType.ToString());
                    headers.AppendLine("Yield:");           info.AppendLine(beacon.barYield.ToString());
                    headers.AppendLine("Variant:");         info.AppendLine(beacon.barVariant.ToString());
                }
                headers.AppendLine("Position:");        info.AppendLine(beacon.position.x.ToString() + ", " + beacon.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get marker on tile
            GameData.Marker marker = UserData.current.selectedVariant.tethysGame.markers.Find((m) => m.position.x == cell.x && m.position.y == cell.y);
            if (marker != null)
            {
                // Display info for marker on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                headers.AppendLine("ID:");                      info.AppendLine(marker.id.ToString());
                headers.AppendLine("Type:");            info.AppendLine(marker.markerType.ToString());
                headers.AppendLine("Position:");        info.AppendLine(marker.position.x.ToString() + ", " + marker.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get wreckage on tile
            GameData.Wreckage wreckage = UserData.current.selectedVariant.tethysGame.wreckage.Find((w) => w.position.x == cell.x && w.position.y == cell.y);
            if (wreckage != null)
            {
                // Display info for wreckage on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                headers.AppendLine("ID:");                      info.AppendLine(wreckage.id.ToString());
                headers.AppendLine("Type:");            info.AppendLine(wreckage.techID.ToString());
                headers.AppendLine("Visible:");         info.AppendLine(wreckage.isVisible ? "Yes" : "No");
                headers.AppendLine("Position:");        info.AppendLine(wreckage.position.x.ToString() + ", " + wreckage.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get start location on tile
            foreach (PlayerData player in UserData.current.selectedVariant.players)
            {
                PlayerData.ResourceData resData = UserData.current.GetPlayerResourceData(player);

                if (resData.centerView.x == cell.x && resData.centerView.y == cell.y)
                {
                    // Display info for start location
                    System.Text.StringBuilder headers = new System.Text.StringBuilder();
                    System.Text.StringBuilder info    = new System.Text.StringBuilder();

                    headers.AppendLine("Player:");          info.AppendLine(player.id.ToString());
                    headers.AppendLine("Type:");            info.AppendLine("Start Location");
                    headers.AppendLine("Position:");        info.AppendLine(resData.centerView.x.ToString() + ", " + resData.centerView.y.ToString());

                    m_txtHeaders.text = headers.ToString();
                    m_txtInfo.text    = info.ToString();
                    return;
                }
            }
        }
Exemple #8
0
 public UnitView AddUnit(GameData.Wreckage wreck)
 {
     return(AddUnit(wreck, Color.white));
 }