Esempio n. 1
0
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData reciever)
        {
            Star star = target as Star;

            Message message = new Message();

            message.Audience = fleet.Owner;
            message.Text     = " You have colonised " + star.Name + ".";
            Messages.Add(message);

            star.ResourcesOnHand = fleet.Cargo.ToResource();
            star.Colonists       = fleet.Cargo.ColonistNumbers;
            star.Owner           = fleet.Owner;
            star.ThisRace        = sender.Race;

            fleet.TotalCost.Energy = 0;
            star.ResourcesOnHand  += fleet.TotalCost * 0.75;

            fleet.Composition.Clear();

            sender.OwnedStars.Add(star);
            sender.StarReports[star.Name].Update(star, ScanLevel.Owned, sender.TurnYear);

            return(true);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            if (fleet.InOrbit == null || target == null || !(target is Star))
            {
                Message message = new Message();
                message.Audience = fleet.Owner;
                message.Text     = "Fleet " + fleet.Name + " attempted to unload cargo while not in orbit.";
                Messages.Add(message);
                return(false);
            }

            Star star = target as Star;

            // Check ownership.
            if (fleet.Owner != star.Owner)
            {
                bool toReturn = false;

                InvadeTask invade = new InvadeTask();

                if (invade.IsValid(fleet, target, sender, receiver))
                {
                    toReturn = invade.Perform(fleet, target, sender, receiver);
                }

                Messages.AddRange(invade.Messages);

                return(toReturn);
            }

            return(true);
        }
Esempio n. 3
0
        /// <Summary>
        /// Set the content of the Detail control. Depending on the type of the Item
        /// selected this may either be a planet (in which case the planet Detail
        /// control is displayed) or a fleet (which will cause the fleet Detail control
        /// to be displayed).
        /// </Summary>
        /// <param name="Item">The <see cref="Item"/> to display (a <see cref="Fleet"/> or <see cref="Star"/>).</param>
        private void SetItem(Mappable item)
        {
            if (item == null)
            {
                Enabled = false;
                return;
            }

            // To avoid confusion when another race's fleet or planet is selected
            // grey out (disable) the Detail panel.
            if (item.Owner == empireState.Id)
            {
                Enabled = true;
            }
            else
            {
                Enabled = false;
                return;
            }

            // Detail panel works with owned objects, so retrieve them from their collections.
            if (item is FleetIntel || item is Fleet)
            {
                DisplayFleet(empireState.OwnedFleets[item.Key]);
            }
            else
            {
                // We should use item.Key here, but we know stars are keyed by Name and
                // we save two casts (star and starintel, which are not polymorphic)
                DisplayPlanet(empireState.OwnedStars[item.Name]);
            }
        }
Esempio n. 4
0
        internal static bool TryInvokeAsync(IMalockSocket malock, MalockMessage message, int timeout, Action <int, MalockMessage, Stream> callback, ref Exception exception)
        {
            if (malock == null)
            {
                throw new ArgumentNullException("malock");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            Mappable mapinfo = new Mappable()
            {
                State   = callback,
                Tag     = null,
                Timeout = timeout,
                Client  = malock,
            };

            if (!MalockMessage.RegisterToMap(message.Sequence, mapinfo))
            {
                exception = new InvalidOperationException("An internal error cannot add a call to a rpc-task in the map table");
                return(false);
            }
            return(TrySendMessage(malock, message, ref exception));
        }
Esempio n. 5
0
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            // See if a Minefield is already here (owned by us). We allow a
            // certaintolerance in distance because it is unlikely that the
            // waypoint has been set exactly right.

            //TODO: Implement per empire minefields.

            /*foreach (Minefield minefield in serverState.AllMinefields.Values)
             * {
             *  if (PointUtilities.IsNear(fleet.Position, minefield.Position))
             *  {
             *      if (minefield.Owner == fleet.Owner)
             *      {
             *          minefield.NumberOfMines += fleet.NumberOfMines;
             *          return true;
             *      }
             *  }
             * }
             *
             * // No Minefield found. Start a new one.
             *
             * Minefield newField = new Minefield();
             *
             * newField.Position = fleet.Position;
             * newField.Owner = fleet.Owner;
             * newField.NumberOfMines = fleet.NumberOfMines;
             *
             * serverState.AllMinefields[newField.Key] = newField;*/
            return(true);
        }
Esempio n. 6
0
        static MalockMessage()
        {
            timeoutmaintaining = EventWaitHandle.Run(() =>
            {
                while (true)
                {
                    foreach (KeyValuePair <int, Mappable> kv in msgmap)
                    {
                        Mappable map = kv.Value;
                        if (map == null || map.Timeout == -1)
                        {
                            continue;
                        }
                        Stopwatch sw = map.Stopwatch;
                        if (sw.ElapsedMilliseconds > map.Timeout)
                        {
                            sw.Stop();

                            Mappable value;
                            msgmap.TryRemove(kv.Key, out value);

                            var state = map.State;
                            if (state != null)
                            {
                                state(Mappable.ERROR_TIMEOUT, null, null);
                            }
                        }
                    }
                    Thread.Sleep(100);
                }
            });
        }
Esempio n. 7
0
 internal static void Abort(IMalockSocket malock)
 {
     if (malock == null)
     {
         throw new ArgumentNullException("malock");
     }
     lock (msgmap)
     {
         foreach (KeyValuePair <int, Mappable> kv in msgmap)
         {
             Mappable map = kv.Value;
             if (map == null && map.Client != malock)
             {
                 continue;
             }
             else
             {
                 Mappable mv;
                 msgmap.TryRemove(kv.Key, out mv);
             }
             var state = map.State;
             if (state != null)
             {
                 state(Mappable.ERROR_ABORTED, null, null);
             }
         }
     }
 }
Esempio n. 8
0
        /// <Summary>
        /// Set the content of the Summary control. Depending on the type of the Item
        /// selected this may either be a planet (in which case the planet Summary
        /// control is displayed) or a fleet (which will cause the fleet Summary control
        /// to be displayed).
        /// </Summary>
        /// <param name="Item">The <see cref="Item"/> to display (a <see cref="Fleet"/> or <see cref="Star"/>).</param>
        private void SetItem(Mappable item)
        {
            if (item == null)
            {
                this.summaryFrame.Text = "Nothing Selected";
                FleetSummary.Hide();
                PlanetSummary.Hide();
                Invalidate();
                return;
            }

            if (item is FleetIntel || item is Fleet)
            {
                FleetIntel report = null;
                empireState.FleetReports.TryGetValue(item.Key, out report);
                if (report != null)
                {
                    DisplayFleet(report);
                }
                else
                {
                    SetItem(null);
                }
            }
            else
            {
                DisplayPlanet(empireState.StarReports[item.Name]);
            }
        }
Esempio n. 9
0
        /// <Summary>
        /// Display a planet Summary
        /// </Summary>
        /// <param name="Item"></param>
        private void DisplayPlanet(StarIntel report)
        {
            if (empireState.StarReports[report.Name].Year == Global.Unset)
            {
                this.summaryFrame.Text = report.Name + " is unexplored";
                summaryItem            = null;
                PlanetSummary.Hide();
                FleetSummary.Hide();
                Invalidate();
                return;
            }

            // If we are displaying a fleet clear it out and add the planet
            // Summary display.

            if (summaryItem is FleetIntel || summaryItem == null)
            {
                PlanetSummary.Show();
                FleetSummary.Hide();
                Invalidate();
            }

            summaryItem = report;

            this.summaryFrame.Text = "Summary of " + report.Name;
            PlanetSummary.Location = new Point(5, 15);
            PlanetSummary.Value    = report;
        }
Esempio n. 10
0
    /// <summary>
    /// Synchronizes with the server, then calls run().
    /// </summary>
    /// <returns>
    /// Return true to end turn, false to resynchronize with the
    /// server and run again.
    /// </returns>
    public bool startTurn()
    {
        int count = 0;

        iteration++;

        count   = Client.getPlayerCount(connection);
        players = new Player[count];
        for (int i = 0; i < count; i++)
        {
            players[i] = new Player(Client.getPlayer(connection, i));
        }

        count     = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for (int i = 0; i < count; i++)
        {
            mappables[i] = new Mappable(Client.getMappable(connection, i));
        }

        count        = Client.getPumpStationCount(connection);
        pumpStations = new PumpStation[count];
        for (int i = 0; i < count; i++)
        {
            pumpStations[i] = new PumpStation(Client.getPumpStation(connection, i));
        }

        count = Client.getUnitCount(connection);
        units = new Unit[count];
        for (int i = 0; i < count; i++)
        {
            units[i] = new Unit(Client.getUnit(connection, i));
        }

        count = Client.getTileCount(connection);
        tiles = new Tile[count];
        for (int i = 0; i < count; i++)
        {
            tiles[i] = new Tile(Client.getTile(connection, i));
        }

        count     = Client.getUnitTypeCount(connection);
        unitTypes = new UnitType[count];
        for (int i = 0; i < count; i++)
        {
            unitTypes[i] = new UnitType(Client.getUnitType(connection, i));
        }

        if (!initialized)
        {
            initialized = true;
            init();
        }

        return(run());
    }
Esempio n. 11
0
        /// <inheritdoc />
        public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            // fleet is the original fleet to split, or the recipient of a merge.
            // target (as Fleet) is the new fleet in a split, or the fleet to be merged into FirstFleet.

            // TODO (priority 5) - Validate SplitMergeTask:
            // fleet & target valid vs sender versions
            // FirstFleet cargo + SecondFleet cargo = original cargo from either fleet + target or senders's fleets.
            return(true);
        }
 public void unregister(Mappable m, int x, int y)
 {
     if (m == grid[x, y])
     {
         grid[x, y] = null;
     }
     else
     {
         throw new System.Exception("Trying to unregister wrong mappable");
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Scrap a fleet (fleets include starbases).
        /// </summary>
        /// <param name="fleet"></param>
        /// <param name="star"></param>
        /// <remarks>
        /// The minerals depositied are:
        ///
        /// Colonisation                        - 75% (Handled in ColoniseWorkerTask)
        /// Scrap at a starbase                 - 80%
        /// Scrap at a planet without a stabase - 33%
        /// Scrap in space                      - 0%
        ///
        /// If the secondary trait Ulitmate Recycling has been selected when you scrap a
        /// fleet at a starbase, you recover 90% of the minerals and 70% of the
        /// resources used to produce the fleet. The resources are available or use the
        /// next year. Scrapping at a planet gives you 45% of the minerals and 35% of
        /// the resources.These resources are not strictly additive.
        /// </remarks>
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver = null)
        {
            Message message = new Message();

            Messages.Add(message);
            message.Audience = fleet.Owner;
            message.Text     = fleet.Name + " has been scrapped";

            double amount    = 0;
            double resources = 0;

            if (fleet.InOrbit == null || target == null || !(target is Star))
            {
                // TODO (priority 4) - create a scrap packet in space
                return(false);
            }
            else
            {
                Star star = (Star)target;

                if (sender.Race.HasTrait("UR"))
                {
                    if (star.Starbase != null)
                    {
                        amount    = 90;
                        resources = 70;
                    }
                    else
                    {
                        amount = 45;
                    }
                }
                else
                {
                    if (star.Starbase != null)
                    {
                        amount = 80;
                    }
                    else
                    {
                        amount = 33;
                    }
                }

                double    totalResources = fleet.TotalCost.Energy * resources / 100;
                Resources returned       = fleet.TotalCost;
                returned *= amount / 100;
                fleet.TotalCost.Energy = (int)totalResources;
                star.ResourcesOnHand  += fleet.TotalCost;
            }

            fleet.Composition.Clear(); // disapear the ships. The (now empty) fleet will be cleaned up latter.
            return(true);
        }
Esempio n. 14
0
        /// <inheritdoc />
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            switch (Mode)
            {
            case CargoMode.Load:
                return(Load(fleet, target, sender, receiver));

            case CargoMode.Unload:
                return(Unload(fleet, target, sender, receiver));
            }

            return(false);
        }
Esempio n. 15
0
        /// <summary>
        /// Performs concrete loading.
        /// </summary>
        private bool Load(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            Star star = target as Star;

            Message message = new Message();

            message.Text = "Fleet " + fleet.Name + " has loaded cargo from " + star.Name + ".";
            Messages.Add(message);

            fleet.Cargo.Add(Amount);
            star.Remove(Amount);

            return(true);
        }
Esempio n. 16
0
        /// <Summary>
        /// Display a fleet Summary
        /// </Summary>
        /// <param name="Item">The <see cref="Item"/> to display (a <see cref="Fleet"/> or <see cref="Star"/>).</param>
        private void DisplayFleet(FleetIntel report)
        {
            if (summaryItem is StarIntel || summaryItem == null)
            {
                FleetSummary.Show();
                PlanetSummary.Hide();
                Invalidate();
            }

            summaryItem            = report;
            this.summaryFrame.Text = "Summary of " + report.Name;
            FleetSummary.Location  = new Point(5, 15);
            FleetSummary.Value     = report;
        }
Esempio n. 17
0
    /// <summary>
    /// Synchronizes with the server, then calls run().
    /// </summary>
    /// <returns>
    /// Return true to end turn, false to resynchronize with the
    /// server and run again.
    /// </returns>
    public bool startTurn()
    {
        int count = 0;

        iteration++;

        count   = Client.getPlayerCount(connection);
        players = new Player[count];
        for (int i = 0; i < count; i++)
        {
            players[i] = new Player(Client.getPlayer(connection, i));
        }

        count     = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for (int i = 0; i < count; i++)
        {
            mappables[i] = new Mappable(Client.getMappable(connection, i));
        }

        count  = Client.getDroidCount(connection);
        droids = new Droid[count];
        for (int i = 0; i < count; i++)
        {
            droids[i] = new Droid(Client.getDroid(connection, i));
        }

        count = Client.getTileCount(connection);
        tiles = new Tile[count];
        for (int i = 0; i < count; i++)
        {
            tiles[i] = new Tile(Client.getTile(connection, i));
        }

        count         = Client.getModelVariantCount(connection);
        modelVariants = new ModelVariant[count];
        for (int i = 0; i < count; i++)
        {
            modelVariants[i] = new ModelVariant(Client.getModelVariant(connection, i));
        }

        if (!initialized)
        {
            initialized = true;
            init();
        }

        return(run());
    }
Esempio n. 18
0
        internal static Mappable GetByMap(int msgid)
        {
            Mappable map = null;

            lock (msgmap)
            {
                if (msgmap.TryGetValue(msgid, out map))
                {
                    Stopwatch sw = map.Stopwatch;
                    sw.Stop();
                    Mappable value;
                    msgmap.TryRemove(msgid, out value);
                }
            }
            return(map);
        }
Esempio n. 19
0
        public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            Message message = new Message();

            Messages.Add(message);
            message.Audience = fleet.Owner;


            if (fleet.NumberOfMines == 0)
            {
                message.Text = fleet.Name + " attempted to lay mines. The order has been canceled because no ship in the fleet has a mine laying pod.";
                return(false);
            }

            Messages.Clear();
            return(true);
        }
Esempio n. 20
0
    public bool startTurn()
    {
        iteration++;
        int count = 0;

        count     = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for (int i = 0; i < count; i++)
        {
            mappables[i] = new Mappable(Client.getMappable(connection, i));
        }
        count = Client.getTileCount(connection);
        tiles = new Tile[count];
        for (int i = 0; i < count; i++)
        {
            tiles[i] = new Tile(Client.getTile(connection, i));
        }
        count       = Client.getSpeciesCount(connection);
        speciesList = new Species[count];
        for (int i = 0; i < count; i++)
        {
            speciesList[i] = new Species(Client.getSpecies(connection, i));
        }
        count  = Client.getFishCount(connection);
        fishes = new Fish[count];
        for (int i = 0; i < count; i++)
        {
            fishes[i] = new Fish(Client.getFish(connection, i));
        }
        count   = Client.getPlayerCount(connection);
        players = new Player[count];
        for (int i = 0; i < count; i++)
        {
            players[i] = new Player(Client.getPlayer(connection, i));
        }

        if (!initialized)
        {
            initialized = true;
            init();
        }
        return(run());
    }
Esempio n. 21
0
        /// <Summary>
        /// Process event thrown by a ToolStripMenuItem from the waypoint context menu.
        /// </Summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="ToolStripItemClickedEventArgs"/> that contains the event data.</param>
        private void ContextMenuWaypointTargets_SelectedIndexChanged(Object sender, ToolStripItemClickedEventArgs e)
        {
            String name = e.ClickedItem.AccessibilityObject.Name;

            int      index    = wayPoints.SelectedIndices[0];
            Waypoint waypoint = new Waypoint(selectedFleet.Waypoints[index]);

            NovaPoint position = waypoint.Position;

            List <Mappable> nearObjects = FindNearObjects(position);

            if (nearObjects.Count == 0)
            {
                return;
            }

            Mappable target = null;

            foreach (Mappable report in nearObjects)
            {
                if (report.Name == name)
                {
                    target = report;
                    break;
                }
            }
            if (target == null)
            {
                return;
            }

            if (wayPoints.SelectedItems.Count > 0)
            {
                index = wayPoints.SelectedIndices[0];
                selectedFleet.Waypoints[index].Destination = target.Name;
                selectedFleet.Waypoints[index].Position    = target.Position;
            }

            (e.ClickedItem as ToolStripMenuItem).Checked = true;
            UpdateWaypointList(this, new EventArgs());
            Invalidate();
        }
Esempio n. 22
0
    /// <summary>
    /// Synchronizes with the server, then calls run().
    /// </summary>
    /// <returns>
    /// Return true to end turn, false to resynchronize with the
    /// server and run again.
    /// </returns>
    public bool startTurn()
    {
        int count = 0;

        iteration++;

        count   = Client.getPlayerCount(connection);
        players = new Player[count];
        for (int i = 0; i < count; i++)
        {
            players[i] = new Player(Client.getPlayer(connection, i));
        }

        count     = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for (int i = 0; i < count; i++)
        {
            mappables[i] = new Mappable(Client.getMappable(connection, i));
        }

        count  = Client.getPlantCount(connection);
        plants = new Plant[count];
        for (int i = 0; i < count; i++)
        {
            plants[i] = new Plant(Client.getPlant(connection, i));
        }

        count     = Client.getMutationCount(connection);
        mutations = new Mutation[count];
        for (int i = 0; i < count; i++)
        {
            mutations[i] = new Mutation(Client.getMutation(connection, i));
        }

        if (!initialized)
        {
            initialized = true;
            init();
        }

        return(run());
    }
Esempio n. 23
0
        private void ContextSelect(object sender, EventArgs e)
        {
            ToolStripItem menuItem = sender as ToolStripItem;

            if (menuItem == null)
            {
                return;
            }

            Mappable item = menuItem.Tag as Mappable;

            if (item == null)
            {
                return;
            }

            SetCursor(item.Position);

            OnSelectionChanged(new SelectionArgs(item));
        }
Esempio n. 24
0
 internal static bool RegisterToMap(int msgid, Mappable map)
 {
     if (map == null)
     {
         throw new ArgumentNullException("map");
     }
     lock (msgmap)
     {
         if (!msgmap.TryAdd(msgid, map))
         {
             return(false);
         }
         else
         {
             Stopwatch sw = map.Stopwatch;
             sw.Reset();
             sw.Start();
         }
         return(true);
     }
 }
Esempio n. 25
0
        public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData reciever)
        {
            Message message = new Message();

            Messages.Add(message);

            message.Audience = fleet.Owner;
            message.Text     = fleet.Name + " attempted to colonise ";

            if (fleet.InOrbit == null || target == null || !(target is Star))
            {
                message.Text += "something that is not a star.";
                return(false);
            }

            Star star = (Star)target;

            message.Text += target.Name;

            if (star.Colonists != 0)
            {
                message.Text += " but it is already occupied.";
                return(false);
            }

            if (fleet.Cargo.ColonistsInKilotons == 0)
            {
                message.Text += " but no colonists were on board.";
                return(false);
            }

            if (fleet.CanColonize == false)
            {
                message.Text += " but no ships with colonization module were present.";
                return(false);
            }

            Messages.Clear();
            return(true);
        }
Esempio n. 26
0
        /// <Summary>
        /// Left mouse button: select objects.
        /// </Summary>
        /// <param name="e"></param>
        private void LeftMouse(MouseEventArgs e)
        {
            NovaPoint position = new NovaPoint();
            NovaPoint click    = new NovaPoint(e.X, e.Y);

            position = DeviceToLogical(click);

            List <Mappable> nearObjects = FindNearObjects(position);

            if (nearObjects.Count == 0)
            {
                return;
            }

            // If the mouse hasn't moved since the last selection cycle through
            // the list of near objects. If it has, start at the beginning of the
            // list.

            if ((Math.Abs(lastClick.X - click.X) > 10) ||
                (Math.Abs(lastClick.Y - click.Y) > 10))
            {
                selection = 0;
            }
            else
            {
                selection++;
                if (selection >= nearObjects.Count)
                {
                    selection = 0;
                }
            }

            lastClick = click;
            Mappable item = nearObjects[selection];

            SetCursor(item.Position);

            OnSelectionChanged(new SelectionArgs(item));
        }
Esempio n. 27
0
  /// <summary>
  /// Synchronizes with the server, then calls run().
  /// </summary>
  /// <returns>
  /// Return true to end turn, false to resynchronize with the 
  /// server and run again.
  /// </returns>
  public bool startTurn()
  {
    int count = 0;
    iteration++;

    count = Client.getPlayerCount(connection);
    players = new Player[count];
    for(int i = 0; i < count; i++)
      players[i] = new Player(Client.getPlayer(connection, i));

    count = Client.getMappableCount(connection);
    mappables = new Mappable[count];
    for(int i = 0; i < count; i++)
      mappables[i] = new Mappable(Client.getMappable(connection, i));

    count = Client.getDroidCount(connection);
    droids = new Droid[count];
    for(int i = 0; i < count; i++)
      droids[i] = new Droid(Client.getDroid(connection, i));

    count = Client.getTileCount(connection);
    tiles = new Tile[count];
    for(int i = 0; i < count; i++)
      tiles[i] = new Tile(Client.getTile(connection, i));

    count = Client.getModelVariantCount(connection);
    modelVariants = new ModelVariant[count];
    for(int i = 0; i < count; i++)
      modelVariants[i] = new ModelVariant(Client.getModelVariant(connection, i));

    if(!initialized)
    {
      initialized = true;
      init();
    }

    return run();
  }
Esempio n. 28
0
        /// <inheritdoc />
        public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
        {
            Fleet secondFleet = null;

            // Look for an appropiate fleet for a merge.
            if (OtherFleetKey != 0)
            {
                // This allows to merge with other empires if desired at some point.
                if (receiver != null && receiver.OwnedFleets.ContainsKey(OtherFleetKey))
                {
                    secondFleet = receiver.OwnedFleets[OtherFleetKey];
                }
                else if (sender.OwnedFleets.ContainsKey(OtherFleetKey))
                {
                    // The other fleet is also ours: OtherFleetKey belongs to the same Race/Player as the fleet with the SplitMergeTask waypoint order.
                    secondFleet = sender.OwnedFleets[OtherFleetKey];
                }
            }

            // Found fleet => Merge
            if (secondFleet != null)
            {
                MergeFleets(fleet, secondFleet);
            }
            else
            {
                // Else it's a split. Need a new fleet so clone original
                // and change stuff.
                secondFleet = sender.MakeNewFleet(fleet);

                ReassignShips(fleet, secondFleet);

                // Now send new Fleets to limbo pending inclusion.
                sender.TemporaryFleets.Add(secondFleet);
            }

            return(true);
        }
Esempio n. 29
0
 public static int ManhattanDistance(Mappable u1, Mappable u2)
 {
     return Math.Abs(u2.X - u1.X) + Math.Abs(u2.Y - u1.Y);
 }
Esempio n. 30
0
 public bool Perform(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
 {
     return(true);
 }
Esempio n. 31
0
 public bool IsValid(Fleet fleet, Mappable target, EmpireData sender, EmpireData receiver)
 {
     return(true);
 }
Esempio n. 32
0
    public bool startTurn()
    {
        iteration++;
        int count = 0;
        count = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for(int i = 0; i < count; i++)
        {
          mappables[i] = new Mappable(Client.getMappable(connection, i));
        }
        count = Client.getTileCount(connection);
        tiles = new Tile[count];
        for(int i = 0; i < count; i++)
        {
          tiles[i] = new Tile(Client.getTile(connection, i));
        }
        count = Client.getSpeciesCount(connection);
        speciesList = new Species[count];
        for(int i = 0; i < count; i++)
        {
          speciesList[i] = new Species(Client.getSpecies(connection, i));
        }
        count = Client.getFishCount(connection);
        fishes = new Fish[count];
        for(int i = 0; i < count; i++)
        {
          fishes[i] = new Fish(Client.getFish(connection, i));
        }
        count = Client.getPlayerCount(connection);
        players = new Player[count];
        for(int i = 0; i < count; i++)
        {
          players[i] = new Player(Client.getPlayer(connection, i));
        }

        if(!initialized)
        {
          initialized = true;
          init();
        }
        return run();
    }
Esempio n. 33
0
        /// <Summary>
        /// Left Shift Mouse: Set Waypoints.
        /// </Summary>
        /// <param name="e"></param>
        /// <param name="snapToObject"></param>
        private void LeftShiftMouse(MouseEventArgs e, bool snapToObject)
        {
            SelectionArgs args = new SelectionArgs(null);

            OnSelectionRequested(args);

            Mappable item = args.Selection;

            if (item == null || !(item is Fleet))
            {
                return;
            }

            NovaPoint       click       = new NovaPoint(e.X, e.Y);
            Fleet           fleet       = item as Fleet;
            NovaPoint       position    = DeviceToLogical(click);
            List <Mappable> nearObjects = FindNearObjects(position);
            Waypoint        waypoint    = new Waypoint();

            waypoint.Position   = position;
            waypoint.WarpFactor = 6;
            waypoint.Task       = new NoTask();

            // If there are no items near the selected position then set the
            // waypoint to just be a position in space. Otherwise, make the target
            // of the waypoint the selected Item.
            //
            // To Do: Handle multiple items at the target location

            if (nearObjects.Count == 0 || snapToObject == false)
            {
                waypoint.Destination = "Space at " + position.ToString();
                waypoint.Position    = position;
            }
            else
            {
                Mappable selected = nearObjects[0];
                waypoint.Position    = selected.Position;
                waypoint.Destination = selected.Name;
            }

            // If the new waypoint is the same as the last one then do nothing.

            int      lastIndex    = fleet.Waypoints.Count - 1;
            Waypoint lastWaypoint = fleet.Waypoints[lastIndex];

            if (waypoint.Destination == lastWaypoint.Destination)
            {
                return;
            }

            WaypointCommand command = new WaypointCommand(CommandMode.Add, waypoint, fleet.Key);

            clientState.Commands.Push(command);

            if (command.IsValid(clientState.EmpireState))
            {
                command.ApplyToState(clientState.EmpireState);
            }

            RefreshStarMap(this, EventArgs.Empty);

            if (WaypointChanged != null)
            {
                WaypointChanged(this, new EventArgs());
            }
        }
Esempio n. 34
0
    /// <summary>
    /// Synchronizes with the server, then calls run().
    /// </summary>
    /// <returns>
    /// Return true to end turn, false to resynchronize with the 
    /// server and run again.
    /// </returns>
    public bool startTurn()
    {
        int count = 0;
        iteration++;

        count = Client.getPlayerCount(connection);
        players = new Player[count];
        for(int i = 0; i < count; i++)
          players[i] = new Player(Client.getPlayer(connection, i));

        count = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for(int i = 0; i < count; i++)
          mappables[i] = new Mappable(Client.getMappable(connection, i));

        count = Client.getPumpStationCount(connection);
        pumpStations = new PumpStation[count];
        for(int i = 0; i < count; i++)
          pumpStations[i] = new PumpStation(Client.getPumpStation(connection, i));

        count = Client.getUnitCount(connection);
        units = new Unit[count];
        for(int i = 0; i < count; i++)
          units[i] = new Unit(Client.getUnit(connection, i));

        count = Client.getTileCount(connection);
        tiles = new Tile[count];
        for(int i = 0; i < count; i++)
          tiles[i] = new Tile(Client.getTile(connection, i));

        count = Client.getUnitTypeCount(connection);
        unitTypes = new UnitType[count];
        for(int i = 0; i < count; i++)
          unitTypes[i] = new UnitType(Client.getUnitType(connection, i));

        if(!initialized)
        {
          initialized = true;
          init();
        }

        return run();
    }
 public void unregister(Mappable m, int x, int y)
 {
     if (m == grid[x,y]) grid[x, y] = null;
     else throw new System.Exception("Trying to unregister wrong mappable");
 }
 public void register(Mappable m, int x, int y)
 {
     grid[x, y] = m;
 }
    public bool startTurn()
    {
        iteration++;
        int count = 0;
        count = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for(int i = 0; i < count; i++)
        {
          mappables[i] = new Mappable(Client.getMappable(connection, i));
        }
        count = Client.getCreatureCount(connection);
        creatures = new Creature[count];
        for(int i = 0; i < count; i++)
        {
          creatures[i] = new Creature(Client.getCreature(connection, i));
        }
        count = Client.getPlantCount(connection);
        plants = new Plant[count];
        for(int i = 0; i < count; i++)
        {
          plants[i] = new Plant(Client.getPlant(connection, i));
        }
        count = Client.getPlayerCount(connection);
        players = new Player[count];
        for(int i = 0; i < count; i++)
        {
          players[i] = new Player(Client.getPlayer(connection, i));
        }

        if(!initialized)
        {
          initialized = true;
          init();
        }
        return run();
    }
Esempio n. 38
0
    /// <summary>
    /// Synchronizes with the server, then calls run().
    /// </summary>
    /// <returns>
    /// Return true to end turn, false to resynchronize with the 
    /// server and run again.
    /// </returns>
    public bool startTurn()
    {
        int count = 0;
        iteration++;

        count = Client.getPlayerCount(connection);
        players = new Player[count];
        for(int i = 0; i < count; i++)
          players[i] = new Player(Client.getPlayer(connection, i));

        count = Client.getMappableCount(connection);
        mappables = new Mappable[count];
        for(int i = 0; i < count; i++)
          mappables[i] = new Mappable(Client.getMappable(connection, i));

        count = Client.getTileCount(connection);
        tiles = new Tile[count];
        for(int i = 0; i < count; i++)
          tiles[i] = new Tile(Client.getTile(connection, i));

        count = Client.getTrapCount(connection);
        traps = new Trap[count];
        for(int i = 0; i < count; i++)
          traps[i] = new Trap(Client.getTrap(connection, i));

        count = Client.getThiefCount(connection);
        thiefs = new Thief[count];
        for(int i = 0; i < count; i++)
          thiefs[i] = new Thief(Client.getThief(connection, i));

        count = Client.getThiefTypeCount(connection);
        thiefTypes = new ThiefType[count];
        for(int i = 0; i < count; i++)
          thiefTypes[i] = new ThiefType(Client.getThiefType(connection, i));

        count = Client.getTrapTypeCount(connection);
        trapTypes = new TrapType[count];
        for(int i = 0; i < count; i++)
          trapTypes[i] = new TrapType(Client.getTrapType(connection, i));

        if(!initialized)
        {
          initialized = true;
          init();
        }

        return run();
    }