Example #1
0
    /// <summary>
    /// Updates the cursor newText with information about current order and object under cursor
    /// </summary>
    /// <param id="c"></param>
    private void CursorUpdate(Cursor c)
    {
      string text = "";

      Building bldg;
      BuildingDb bldgEntry;

      c.UseDefault();

      if (!isObjectSelected || selectedObjects[0].GetEntityType != GameEntityType.Unit)
      {
        if (mouseoverGameObject != null)
        {
          text = mouseoverGameObject.MouseoverText;
          c.UseText(text);
        }
        return;
      }
      Unit unit = (Unit)selectedObjects[0];

      switch (inGameState)
      {
        case InGameStateEnum.Default:
        case InGameStateEnum.DefaultSelected:
        case InGameStateEnum.DragSelecting:
          c.UseDefault();
          if (mouseoverGameObject != null)
            text = mouseoverGameObject.MouseoverText;
          break;
        case InGameStateEnum.Movement:
          #region
          if (!unit.CanDoOrder(GameObjectOrder.Idle))
          {
            text = "Immovable";
            if (mouseoverGameObject != null)
              text += "\n" + mouseoverGameObject.MouseoverText;
            break;
          }
          text = "Move here";
          if (mouseoverGameObject != null)
          {
            if (mouseoverGameObject.GetEntityType == GameEntityType.Building && isObjectSelected)
            {
              bldg = (Building)mouseoverGameObject;
              bldgEntry = (BuildingDb)bldg.Entry;
              if (bldg.Constructed && bldgEntry.Trains != null)
              {
                text = GetTrainingHint(bldgEntry);
              }
            }
            text = "Move to:\n" + mouseoverGameObject.MouseoverText;
          }
          #endregion
          break;
        case InGameStateEnum.Gather:
          #region
          c.UseCursor("cursorObj");
          if (!unit.CanDoOrder(GameObjectOrder.Gather))
          {
            text = "Can't gather";
            if (mouseoverGameObject != null)
              text += "\n" + mouseoverGameObject.MouseoverText;
            break;
          }
          text = "(Gather)";
          {
            GameObject temp = null;
            if (mouseoverGameObject != null) temp = mouseoverGameObject;
            else if (mouseoverTile != null && mouseoverTile.Resource != null) temp = mouseoverTile.Resource;

            if (temp != null)
            {
              if (temp.GetEntityType == GameEntityType.Resource)
              {
                text = "Gather:\n" + temp.MouseoverText;
              }
              else
                text = "(Gather)\n" + temp.MouseoverText;
            }
          }
          #endregion
          break;
        case InGameStateEnum.Spell:
          #region
          c.UseCursor("cursorObj");
          if (!unit.CanDoOrder(GameObjectOrder.Spell))
          {
            text = "Can't cast spell";
            if (entryIdx < Db.Instance.Effects.Count && entryIdx >= 0)
              text = "\n" + Db.Instance.Effects.ElementAt(entryIdx).Value.Name;
            if (mouseoverGameObject != null)
              text += "\n" + mouseoverGameObject.MouseoverText;
            break;
          }
          text = "";
          if (entryIdx < Db.Instance.Effects.Count && entryIdx >= 0)
            text = "\n" + Db.Instance.Effects.ElementAt(entryIdx).Value.Name;

          if (mouseoverGameObject != null)
            text = (text == "" ? "(Cast)" : "Cast:" + text) + "\nat " + mouseoverGameObject.MouseoverText;
          else
            text = (text == "" ? "(Cast here)" : "Cast here:" + text);
          #endregion
          break;
        case InGameStateEnum.Attack:
          #region
          c.UseCursor("cursorObj");
          if (!unit.CanDoOrder(GameObjectOrder.Attack))
          {
            text = "Can't attack";
            if (mouseoverGameObject != null)
              text += "\n" + mouseoverGameObject.MouseoverText;
            break;
          }
          text = "(Attack)";
          if (mouseoverGameObject != null)
          {
            if (mouseoverGameObject.Owner == controllingPlayer)
              text = "Attack:\n" + mouseoverGameObject.MouseoverText + "\n(Friendly Fire)";
            else
              text = "Attack:\n" + mouseoverGameObject.MouseoverText;
          }
          #endregion
          break;
        case InGameStateEnum.Building:
          #region
          c.UseCursor("cursorObj");
          if (!unit.CanDoOrder(GameObjectOrder.Construct))
          {
            text = "Can't build";
            if (mouseoverGameObject != null)
            {
              text += "\n" + mouseoverGameObject.MouseoverText;
            }
            break;
          }

          text = "(Help building)";
          if (mouseoverGameObject != null)
          {
            if (mouseoverGameObject.GetEntityType == GameEntityType.Building &&
              !((Building)mouseoverGameObject).Constructed)
            {
              text = "Help building:\n" + mouseoverGameObject.MouseoverText;
            }
            else
            {
              text += "\n" + mouseoverGameObject.MouseoverText;
            }
          }
          #endregion
          break;
        case InGameStateEnum.BuildingPlacement:
          #region
          c.UseCursor("cursorObj");
          if (!unit.CanDoOrder(GameObjectOrder.Construct))
          {
            text = "Can't build";
            if (mouseoverGameObject != null)
            {
              text += "\n" + mouseoverGameObject.MouseoverText;
            }
            break;
          }

          if (mouseoverGameObject != null)
          {
            if (mouseoverGameObject.GetEntityType == GameEntityType.Building)
            {
              if (mouseoverGameObject.Owner == controllingPlayer &&
                !((Building)mouseoverGameObject).Constructed)
              {
                text = "Help building:\n" + mouseoverGameObject.MouseoverText;
              }
              else
              {
                text = "(Help building)\n" + mouseoverGameObject.MouseoverText;
              }
              break;
            }
          }

          if (entryIdx < Db.Instance.Buildings.Count && entryIdx >= 0)
          {
            text = "Build:\n" + Db.Instance.Buildings.OrderBy(p => p.Value.Tier).ElementAt(entryIdx).Value.Name;
            if (mouseoverTile != null)
            {
              if (controllingPlayer.Fow[mouseoverTile.X, mouseoverTile.Y] == 0)
              {
                text += "\n[unknown terrain]";
              }
              else if (Building.CanPlace(game.Map, mouseoverTile))
              {
                text += "\n[can be placed here]";
              }
              else
              {
                text += "\n[cannot be placed here]";
              }
            }
          }
          else
          {
            text = "(Build)";
          }
          #endregion
          break;
        case InGameStateEnum.Train:
          #region
          c.UseCursor("cursorObj");
          if (mouseoverGameObject != null && mouseoverGameObject.GetEntityType == GameEntityType.Building)
          {
            bldg = (Building)mouseoverGameObject;
          }
          else if (mouseoverTile != null && mouseoverTile.Building != null)
          {
            bldg = mouseoverTile.Building;
          }
          else
          {
            bldg = null;
          }

          if (!unit.CanDoOrder(GameObjectOrder.Train))
          {
            text = "Can't be trained";
            if (bldg != null)
            {
              text += "\n" + bldg.MouseoverText;
            }
            break;
          }

          text = "(Train)";
          if (bldg != null)
          {
            bldgEntry = (BuildingDb)bldg.Entry;
            if (mouseoverGameObject != null && bldgEntry.Trains != null)
            {
              if (bldg.Constructed && isObjectSelected)
              {
                text = GetTrainingHint(bldgEntry);
              }
            }

            text += "\n" + bldg.MouseoverText;
          }
          #endregion
          break;
        default:
          break;
      }
      c.UseText(text);
    }
Example #2
0
    /// <summary>
    /// Background-Updates the MapUI, updating the game
    /// </summary>
    /// <param id="c">Screen cursor</param>
    public void BackgroundUpdate(Cursor c)
    {
      // Reset cursor
      c.UseDefault();
      c.UseText("");

      // If no map is present or map is not valid, flush the information and reload the map from the game
      if (this.map == null || !this.map.Valid)
      {
        FlushMapInfo();
        // If game doesn't have valid map, return
        if (this.game.Map == null || !this.game.Map.Valid)
        {
          return;
        }

        this.map = this.game.Map;
      }

      // Don't update if there is no controlling player (we are viewing server game)
      if (controllingPlayer != null)
      {
        // Update the game
        game.Update();

        // Validate our selection (it might have died, etc)
        ValidateSelection();
      }

      lastMouseVector = UI.Instance.MouseVector;
    }