Example #1
0
 public void DrawOverlay(Vector2 offset, Player controlPlayer, Tile mouseoverTile, GameObject mouseoverGameObj)
 {
   DrawGameObjectsOverlay(offset, controlPlayer, mouseoverGameObj);
   DrawGameEffectsOverlay(offset, controlPlayer);
 }
Example #2
0
 private void DrawGameObjects(Vector2 offset, Player controlPlayer, GameObject mouseoverGameObj)
 {
   foreach (var gObj in GetAllGameObjectsEnumerable())
   {
     GameObjectHighlightMode hl = GameObjectHighlightMode.None;
     if (mouseoverGameObj == gObj)
     {
       if (gObj.Owner == controlPlayer)
         hl = GameObjectHighlightMode.FriendlyHighlight;
       else if (controlPlayer != null)
         hl = GameObjectHighlightMode.HostileHighlight;
     }
     if (UI.MakeRect(gObj.GetDrawPosition(offset), gObj.Size).Intersects(UI.Instance.ScreenRectangle))
     {
       gObj.Draw(offset, hl, controlPlayer);
     }
   }
 }
Example #3
0
 private void DrawGameObjectsOverlay(Vector2 offset, Player controlPlayer, GameObject mouseoverGameObj)
 {
   foreach (var gObj in GetAllGameObjectsEnumerable())
   {
     GameObjectHighlightMode hl = GameObjectHighlightMode.None;
     if (mouseoverGameObj == gObj)
     {
       if (gObj.Owner == controlPlayer)
         hl = GameObjectHighlightMode.FriendlyHighlight;
       else
         hl = GameObjectHighlightMode.HostileHighlight;
     }
     gObj.DrawOverlay(offset, hl, controlPlayer);
   }
 }
Example #4
0
 /// <summary>
 /// Gives unit an order with specified parameters
 /// </summary>
 /// <param id="order">New game object order</param>
 /// <param id="orderParam">Order's EntryDb parameter</param>
 /// <param id="targetTile">Tracked tile at the moment of giving order</param>
 /// <param id="targetGameObject">Tracked game object at the moment of giving order</param>
 /// <returns>Returns true if the order was successfully applied to the game object</returns>
 public virtual bool SetOrder(GameObjectOrder order, EntryDb orderParam, Tile targetTile, GameObject targetGameObject)
 {
   if (Health == 0) return false;
   CancelOrders();
   if (targetTile == null && targetGameObject == null) return false;
   if (!CanDoOrder(order)) return false;
   return true;
 }
Example #5
0
    /// <summary>
    /// Gives unit an order with specified parameters
    /// </summary>
    /// <param id="order">New game object order</param>
    /// <param id="orderParam">Order's EntryDb parameter</param>
    /// <param id="targetTile">Tracked tile at the moment of giving order</param>
    /// <param id="targetGameObject">Tracked game object at the moment of giving order</param>
    /// <returns>Returns true if the order was successfully applied to the game object</returns>
    public override bool SetOrder(GameObjectOrder order, EntryDb orderParam, Tile targetTile, GameObject targetGameObject)
    {
      if (this.game.IsServer) Debug.Fail("Server isn't supposed to call this routine");

      if (!base.SetOrder(order, orderParam, targetTile, targetGameObject))
      {
        game.SendData(Network.MakeClientMessage(MessageType.GameObjUpdate, this));
        return false;
      }

      if (!CanDoOrder(order))
      {
        GameEffect ge = new ScrollTextEffect("Unit cannot attack", Position, 50, new Vector2(0, -1f));
        ge.Initialize(game, NearestTile);
        this.game.Effects.Add(ge);

        CancelOrders(true);
        return false;
      }

      BuildingDb bldgEntry;

      switch (order)
      {
        case GameObjectOrder.Idle:
          #region
          if (targetTile == null) return false;
          OrderTarget = null;
          OrderRange = MOVEMENT_RANGE;
          OrderPosition = targetTile.MapPosition + new Vector2(MapBoard.TILE_XSPACING, MapBoard.TILE_YSPACING) / 2;
          #endregion
          break;
        case GameObjectOrder.Attack:
          #region
          if (targetGameObject == null) return false; // Hit something
          if (targetGameObject == this) return false; // Don't hit yourself
          OrderTarget = targetGameObject;
          OrderRange = entry.AttackRange;
          OrderTimeout = entry.AttackSpeed;
          #endregion
          break;
        case GameObjectOrder.Construct:
          #region
          OrderRange = entry.ConstructRange;
          OrderTimeout = entry.ConstructSpeed;

          if (targetGameObject != null && targetGameObject.GetEntityType == GameEntityType.Building)
          {
            OrderTarget = targetGameObject;
            OrderEntry = null;
          }
          else if (targetGameObject == null || targetGameObject.GetEntityType == GameEntityType.Unit)
          {
            if (orderParam == null) return false;
            bldgEntry = (BuildingDb)orderParam;
            if (bldgEntry.OnlyOneAllowed && Owner.Buildings.Any(q => q.Entry == orderParam))
            {
              ScrollUpMessage("Only one such building allowed at a time", 50, false);
              CancelOrders(true);
              return false;
            }
            if (bldgEntry.UnlockedBy != null)
            {
              Building bldg = Owner.Buildings.FirstOrDefault(q => q.Entry == bldgEntry.UnlockedBy);
              if (bldg == null || !bldg.Constructed)
              {
                ScrollUpMessage("Building unavailable", 100, true);
                CancelOrders(true);
                return false;
              }
            }

            OrderTarget = null;
            OrderEntry = (BuildingDb)orderParam;
            OrderPosition = targetTile.MapPosition + new Vector2(MapBoard.TILE_XSPACING, MapBoard.TILE_YSPACING) / 2;
          }
          #endregion
          break;
        case GameObjectOrder.Spell:
          #region

          EffectDb effect = (EffectDb)orderParam;

          if (effect.UnlockedBy != null)
          {
            Building bldg = Owner.Buildings.FirstOrDefault(q => q.Entry == effect.UnlockedBy);
            if (bldg == null || !bldg.Constructed)
            {
              ScrollUpMessage("Spell unavailable", 100, true);
              CancelOrders(true);
              return false;
            }
          }

          OrderEntry = effect;
          OrderRange = effect.CastRange;
          OrderTimeout = effect.Cooldown;
          switch (effect.Spell.Target)
          {
            case SpellEntry.TargetType.Tile:
              if (targetTile == null) return false;
              OrderRange = effect.CastRange;
              OrderPosition = targetTile.MapPosition + new Vector2(MapBoard.TILE_XSPACING, MapBoard.TILE_YSPACING) / 2;
              break;
            case SpellEntry.TargetType.GameEntity:
              if (targetGameObject == null) return false;
              OrderTarget = targetGameObject;
              break;
          }
          #endregion
          break;
        case GameObjectOrder.Gather:
          #region
          if (targetGameObject == null) return false;
          OrderTarget = targetGameObject;
          if (targetGameObject.GetEntityType == GameEntityType.Resource)
          {
            lastGatheredResource = (Resource)targetGameObject;
          }
          else if (targetTile != null && targetTile.Resource != null)
          {
            lastGatheredResource = targetTile.Resource;
          }
          else
          {
            CancelOrders(true);
            return false;
          }
          OrderRange = entry.GatherRange;
          OrderTimeout = entry.GatherSpeed;
          #endregion
          break;
        case GameObjectOrder.Train:
          #region
          if (targetGameObject == null) return false;
          if (targetGameObject.GetEntityType != GameEntityType.Building) return false;
          bldgEntry = (BuildingDb)((Building)targetGameObject).Entry;
          if (bldgEntry.Trains == null) return false;
          if (bldgEntry.Trains.All(p=>p.TrainFrom != this.Entry)) return false;

          OrderTarget = targetGameObject;
          OrderRange = MOVEMENT_RANGE;
          OrderTimeout = TRAIN_QUEUE_CHECK_TIMEOUT;
          #endregion
          break;
        default:
          break;
      }
      State = GameObjectState.MovingToOrder;
      this.Order = order;
      game.SendData(Network.MakeClientMessage(MessageType.GameObjUpdate, this));
      return true;
    }
Example #6
0
    // DISPOSING

    /// <summary>
    /// Flushes all the information about the map and resets the MapUI (while keeping the Game and ControllingPlayer)
    /// </summary>
    private void FlushMapInfo()
    {
      inGameState = InGameStateEnum.Default;

      mouseoverTile = null;
      mouseoverGameObject = null;
      map = null;

      mouseoverTileTracking = false;
      gameObjectTracking = true;
      mouseSelecting = false;
    }
Example #7
0
 /// <summary>
 /// Select a game object (if is owner by controlling player
 /// </summary>
 /// <param id="gObj">Game object to select</param>
 private void SelectObject(GameObject gObj)
 {
   if (gObj != null && gObj.Owner == controllingPlayer)
   {
     selectedObjects.Add(gObj);
     ApplySelection();
   }
 }
Example #8
0
    /// <summary>
    /// Validates selected objects (de-selects dead objects, etc)
    /// </summary>
    private void ValidateSelection()
    {
      if (isObjectSelected)
      {
        foreach (var gObj in new List<GameObject>(selectedObjects))
        {
          if (gObj.Removed || gObj.Health == 0)
          {
            selectedObjects.Remove(gObj);
          }
        }
        if (selectedObjects.Count == 0) DeselectObjects();
      }

      if (mouseoverGameObject != null)
      {
        if (mouseoverGameObject.Removed || mouseoverGameObject.Health == 0)
          mouseoverGameObject = null;
      }
    }
Example #9
0
    // MOUSE SELECTION

    /// <summary>
    /// Updates the tracking of game objects and tiles
    /// </summary>
    private void UpdateTracking()
    {
      bool mouseMoved = UI.Instance.MouseVector != lastMouseVector;

      // If tile targeting is enabled, select tile under the cursor
      if ((mouseoverTileTracking || autoCursor) && mouseMoved)
      {
        mouseoverTile = game.Map.GetTile(UI.Instance.MouseVector + screenOffset);
      }
      else if (!mouseoverTileTracking && !autoCursor)
      {
        mouseoverTile = null;
      }

      // If game object targeting is enabled, select game object under the cursor
      if ((gameObjectTracking || autoCursor) && mouseMoved)
      {
        GameObject temp = GetGameObject(UI.Instance.MouseVector + screenOffset);
        // Verify visibility
        if (temp != null &&
          (temp.NearestTile == null || controllingPlayer.Fow[temp.NearestTile.X, temp.NearestTile.Y] != 2))
          temp = null;

        mouseoverGameObject = temp;
      }
      else if (!gameObjectTracking && !autoCursor)
      {
        mouseoverGameObject = null;
      }
    }
Example #10
0
 public void Unassign(GameObject gObj)
 {
   switch (gObj.GetEntityType)
   {
     case GameEntityType.Unit:
       Unassign((Unit)gObj);
       break;
     case GameEntityType.Building:
       Unassign((Building)gObj);
       break;
     case GameEntityType.Resource:
       Unassign((Resource)gObj);
       break;
     default:
       throw new Exception("Invalid instance of a game object");
   }
 }