public override void Update(GameBoard board) { //compute path if (m_counter == 0) { GameCamp camp = board.Camps[0]; m_agent_position = board.Grid.GetCellCenter(Position); m_path = board.GetPath(this.Position, camp.Position); } if (m_counter % m_launch_delay == 0) { GameAgent agent = m_agent.Clone() as GameAgent; agent.Position = m_agent_position; agent.Path = m_path; board.Agents.Add(agent); } m_counter++; }
public StaticLauncher(GridPosition position, GameAgent agent, int launch_delay) : base(position) { m_agent = agent; m_launch_delay = launch_delay; m_counter = 0; }
public override void Update(GameBoard board) { double range2 = GameUtils.Sqr(m_range * board.Grid.Size); Position tower_position = board.Grid.GetCellCenter(this.Position); bool shots_fired = false; LinkedList <GameAgent> dead_targets = new LinkedList <GameAgent>(); //check existing targets foreach (GameAgent target in m_targets) { if (target.isAlive) { double temp = (target.Position - tower_position).Length2; if (temp < range2) { target.DoDamage(m_damage, enDamageType.Physical); shots_fired = true; break; } } else { dead_targets.AddLast(target); } } foreach (GameAgent t in dead_targets) { m_targets.Remove(t); } //find closest target and shot it if (shots_fired == false) { int closest_agent = -1; double closest_agent_dist = Double.PositiveInfinity; for (int i = 0; i < board.Agents.Count; i++) { if (board.Agents[i].isAlive) { double temp = (board.Agents[i].Position - tower_position).Length2; if (temp < range2 && temp < closest_agent_dist) { closest_agent_dist = temp; closest_agent = i; } } } if (closest_agent >= 0) { GameAgent agent = board.Agents[closest_agent]; agent.DoDamage(m_damage, enDamageType.Physical); // board.Agents[closest_agent] m_targets.AddLast(agent); } } }