Esempio n. 1
0
        /// <summary>
        /// Add game entity to this cell
        /// </summary>
        /// <param name="entity">The Entity to add</param>
        public void AddEntity(ModelComponent entity)
        {
            if (entitiesContainedWithin.Count == 0)
            {
                if (entity is UnitComponent || entity is MapResource || entity is Building)
                {
                    entitiesContainedWithin.Add(entity);

                    if (entity is UnitComponent)
                    {
                        UnitArgs args = new UnitArgs();
                        args.Unit = (UnitComponent)entity;
                        args.Unit.UnitAttackedEnemyHanlders += new UnitAttackedEnemyHandler(handleUnitInCellAttackingEnemy);
                        if (UnitAddedEvent != null)
                        {
                            UnitAddedEvent(this, args);
                        }
                    }
                    if (entity is Building)
                    {
                        // do nothing special?
                    }
                }
            }
        }
Esempio n. 2
0
 public void onMyUnitDestroyed(object sender, UnitArgs args)
 {
     if (args.Unit.Id == ScoutingProbe.Id)
     {
         ScoutingProbe.Alive = false;
         current_task.SetResult(false);
     }
 }
Esempio n. 3
0
 private void UnitRemovedFromCell(Object sender, UnitArgs args)
 {
     for (int i = 0; i < Controls.Count;)
     {
         if (Controls[0] != null)
         {
             Controls[0].Dispose();
         }
     }
 }
Esempio n. 4
0
 public void onEnemyShown(object sender, UnitArgs args)
 {
     Unit unit = args.Unit.theUnit;
     foreach (var location in State.BaseLocations)
     {
         if (enemy_position == null && location.getRegion().getPolygon().isInside(unit.getPosition()))
         {
             enemy_position = location.getPosition();
             bwapi.Broodwar.printf(String.Format("Enemy base spotted"));
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Adds a Component to this CellComponent.
        /// </summary>
        /// <param name="child">The Component to add</param>
        override public void AddChild(ModelComponent child)
        {
            // Ensure that we only have one tile or resource
            List <ModelComponent> toRemove = new List <ModelComponent>();

            if (child is Tile)
            {
                foreach (ModelComponent tile in GetChildren())
                {
                    if (tile is Tile)
                    {
                        toRemove.Add(tile);
                    }
                }
            }
            else if (child is MapResource)
            {
                foreach (ModelComponent resource in GetChildren())
                {
                    if (resource is MapResource)
                    {
                        toRemove.Add(resource);
                        if (entitiesContainedWithin.Count != 0)
                        {
                            UnitArgs args = new UnitArgs();
                            args.Unit = (UnitComponent)entitiesContainedWithin[0];
                            entitiesContainedWithin.Clear();
                            if (UnitRemovedEvent != null)
                            {
                                UnitRemovedEvent(this, args);
                            }
                        }
                    }
                }
                entitiesContainedWithin.Add(child);
            }
            foreach (ModelComponent component in toRemove)
            {
                RemoveChild(component);
            }
            base.AddChild(child);

            // Handle notifications
            if (child is Tile)
            {
                if (TileChangedEvent != null)
                {
                    TileChangedEvent(this, new TileChangedEventArgs((Tile)child));
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Removes an Entity from this Cell.
 /// </summary>
 /// <param name="entity">The Entity to remove</param>
 public void RemoveEntity(ModelComponent entity)
 {
     entitiesContainedWithin.Remove(entity);
     if (entity is UnitComponent)
     {
         UnitArgs args = new UnitArgs();
         args.Unit = (UnitComponent)entity;
         args.Unit.UnitAttackedEnemyHanlders -= new UnitAttackedEnemyHandler(handleUnitInCellAttackingEnemy);
         if (UnitRemovedEvent != null)
         {
             UnitRemovedEvent(this, args);
         }
     }
 }
Esempio n. 7
0
        private void UnitAddedToCell(Object sender, UnitArgs args)
        {
            for (int i = 0; i < Controls.Count;)
            {
                if (Controls[0] != null)
                {
                    Controls[0].Dispose();
                }
            }
            UnitUI unitUI = new UnitUI(controller, args.Unit);

            Controls.Add(unitUI);
            unitUI.MouseClick += TileUI_MouseDown;
        }
 private void handleUnitAddedToCell(object obj, UnitArgs e)
 {
     if (e.Unit == this)             // I'm seeing my own move event.
     {
     }
     else             // Saw another Unit added to a CellComponent.
     {
         if (unitIsAnEnemy(e.Unit) && this.AttackStance == UnitAttackStance.Aggressive && this.actionQueue.GetChildren().Count == 0)
         {
             ModelComponent temp = Parent;
             while (!(temp is Gameworld))
             {
                 temp = temp.Parent;
             }
             AttackAction attackAction = new AttackAction(this, e.Unit, (Gameworld)temp);
             actionQueue.AddChild(attackAction);
         }
     }
 }