Beispiel #1
1
        public async Task <List <ShipLocationHistoryResult> > GetRawGeolocationsForShip(ShipToken ship)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            var connection = new SQLite.Net.SQLiteConnection(
                TinyIoC.TinyIoCContainer.Current.Resolve <ISQLitePlatform>(),
                TinyIoC.TinyIoCContainer.Current.Resolve <IFolderProvider>().MapDatabasePath);


            List <ShipLocationHistoryResult> mainShipLocationResults = new List <ShipLocationHistoryResult> ();

            var query = connection.Table <shipLocationDate>().Where(r => r.shipID == ship.ID && r.shiplocationdatetype == "log");           //.OrderBy (r => r.startdate);

            int locationIndex = 1;

            foreach (var shipLocation in query)
            {
                var possibleLocation = connection.Table <locationJSON> ().Where(l => l.name == shipLocation.locationname).FirstOrDefault();

                if (possibleLocation == null)
                {
                    //We purposely skip some locations when processing. May want to re-think that!
                    continue;
                }

                DateTime startDate;
                DateTime endDate;

                var hasStartDate = string.IsNullOrEmpty(shipLocation.startdate) ? false : DateTime.TryParse(shipLocation.startdate, out startDate);
                var hasEndDate   = string.IsNullOrEmpty(shipLocation.enddate) ? false : DateTime.TryParse(shipLocation.enddate, out endDate);

                mainShipLocationResults.Add(new ShipLocationHistoryResult()
                {
                    Location              = shipLocation.locationname,
                    PossibleEndDate       = hasStartDate ? startDate : default(DateTime),
                    PossibleStartDate     = hasEndDate ? endDate : default(DateTime),
                    ShipToken             = ship,
                    LocationIndex         = locationIndex++,
                    LocationGeocodeResult = possibleLocation != null ? JsonConvert.DeserializeObject <GeocodeResultMain> (possibleLocation.geocodeJSON) : null,
                    LocationGuid          = shipLocation.locationguid
                });

                /*foreach (var location in locations) {
                 *      List<GeocodeResultMain> results = new List<GeocodeResultMain> ();
                 *      var query = connection.Table<locationJSON> ().Where (l => l.name == location);
                 *      foreach (var locationJSONEntry in query) {
                 *              mainGeocodeResults.Add(JsonConvert.DeserializeObject<GeocodeResultMain>(locationJSONEntry.geocodeJSON));
                 *      }*/
            }

            sw.Stop();

            System.Diagnostics.Debug.WriteLine($"Total geolocation query time: {sw.ElapsedMilliseconds} ms");

            return(mainShipLocationResults);
        }
Beispiel #2
0
        public void Init()
        {
            fleets = new List <Fleet>();
            Fleet fleet = new Fleet(1);

            fleet.Owner = 1;
            ShipDesign shipDesign = new ShipDesign(1);
            ShipToken  shipToken  = new ShipToken(shipDesign, 1);

            fleet.Composition.Add(shipToken.Key, shipToken);
            fleets.Add(fleet);
            Waypoint      waypoint = new Waypoint();
            IWaypointTask task     = new ScrapTask();

            waypoint.Task        = task;
            waypoint.Destination = "Star1";
            fleet.Waypoints.Add(waypoint);
            serverData = new SimpleServerData();
            Star star = new Star();

            star.Name = "Star1";
            serverData.AllStars.Add(star.Key, star);
            empireData    = new SimpleEmpireData();
            empireData.Id = 1;
            empireData.OwnedFleets.Add(fleet);
            serverData.AllEmpires.Add(empireData.Id, empireData);
            Console.WriteLine(fleets.First().Composition.Count());
            Assert.AreEqual(fleets.First().Composition.Count(), 1);
        }
Beispiel #3
0
        /// <summary>
        /// Load: Read an object of this class from and XmlNode representation.
        /// </summary>
        /// <param name="node">An XmlNode containing a representation of this object.</param>
        public SplitMergeTask(XmlNode node)
        {
            if (node == null)
            {
                return;
            }

            LeftComposition  = new Dictionary <long, ShipToken>();
            RightComposition = new Dictionary <long, ShipToken>();

            XmlNode   mainNode = node.FirstChild;
            XmlNode   subNode;
            ShipToken token;

            while (mainNode != null)
            {
                try
                {
                    subNode = mainNode.FirstChild;

                    switch (mainNode.Name.ToLower())
                    {
                    case "rightkey":
                        OtherFleetKey = long.Parse(subNode.Value, System.Globalization.NumberStyles.HexNumber);
                        break;

                    case "leftcomposition":
                        while (subNode != null)
                        {
                            token = new ShipToken(subNode);
                            LeftComposition.Add(token.Key, token);
                            subNode = subNode.NextSibling;
                        }
                        break;

                    case "rightcomposition":
                        while (subNode != null)
                        {
                            token = new ShipToken(subNode);
                            RightComposition.Add(token.Key, token);
                            subNode = subNode.NextSibling;
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    Report.Error(e.Message);
                }
                mainNode = mainNode.NextSibling;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Create a new ship or starbase at the specified location. Starbases are
        /// handled just like ships except that they cannot move.
        /// </summary>
        /// <param name="design">A ShipDesign to be constructed.</param>
        /// <param name="star">The star system producing the ship.</param>
        private void CreateShips(ShipDesign design, Star star, int countToBuild)
        {
            EmpireData empire = serverState.AllEmpires[star.Owner];

            ShipToken token = new ShipToken(design, countToBuild);

            Fleet fleet = new Fleet(token, star, empire.GetNextFleetKey());

            fleet.Name          = design.Name + " #" + fleet.Id;
            fleet.FuelAvailable = fleet.TotalFuelCapacity;

            Message message = new Message();

            message.Audience = star.Owner;
            message.Text     = star.Name + " has produced " + countToBuild + " new " + design.Name;
            // message.Event = fleet; // will not be persisted unless the Type is implemented.
            // message.Type = "Fleet"; // TODO (priority 5) - need to add a fleet type message so it can save/load.
            serverState.AllMessages.Add(message);

            // Add the fleet to the state data so it can be tracked.
            serverState.AllEmpires[fleet.Owner].AddOrUpdateFleet(fleet);

            if (design.Type == ItemType.Starbase)
            {
                if (star.Starbase != null)
                {
                    // Old starbases are not scrapped. Instead, the reduced
                    // upgrade cost should have already been factored when first
                    // queuing the "upgrade", so the old SB is just
                    // discarded and replaced at this point. -Aeglos 2 Aug 11
                    star.Starbase = null;
                    // waypointTasks.Scrap(star.Starbase, star, false);
                }

                star.Starbase = fleet;
                fleet.Type    = ItemType.Starbase;
                fleet.Name    = star.Name + " " + fleet.Type;
                fleet.InOrbit = star;

                if (empire.Race.HasTrait("ISB"))
                {
                    fleet.Cloaked = 20;
                }
            }
            else
            {
                fleet.InOrbit = star;
            }
        }
Beispiel #5
0
        public void Generate_Dont_ScrapFleets()
        {
            // ToDo: Fleet-Generation and other things to seperate class/es and/or methods
            Fleet fleet = new Fleet(2);

            fleet.Owner = 1;
            NovaPoint point = new NovaPoint(0, 0);

            fleet.Position = point;
            ShipDesign shipDesign = new ShipDesign(2);

            shipDesign.Blueprint = new Component();
            Hull hull = new Hull();

            hull.Modules = new List <HullModule>();
            hull.Modules.Add(new HullModule());
            shipDesign.Blueprint.Properties.Add("Hull", hull);
            ShipToken shipToken = new ShipToken(shipDesign, 1);

            fleet.Composition.Add(shipToken.Key, shipToken);
            fleets.Add(fleet);
            Waypoint  waypoint      = new Waypoint();
            NovaPoint waypointpoint = new NovaPoint(1, 1);

            waypoint.Position = waypointpoint;
            IWaypointTask task = new NoTask();

            waypoint.Task        = task;
            waypoint.Destination = "Star1";
            fleet.Waypoints.Add(waypoint);

            empireData.AddOrUpdateFleet(fleet);
            // empireData.OwnedFleets.Add(fleet); // ToDo: this should not be allowed I think

            Console.WriteLine("2 Fleets: " + fleets.Count());
            Assert.IsNotEmpty(serverData.IterateAllFleets().ToList());
            Console.WriteLine("all Fleets count: " + serverData.IterateAllFleets().ToList().Count());

            SimpleTurnGenerator turnGenerator = new SimpleTurnGenerator(serverData);

            turnGenerator.Generate();
            // Assert.AreEqual(fleets.First().Composition.Count(), 1);
            Assert.IsNotEmpty(serverData.IterateAllFleets().ToList());
        }
Beispiel #6
0
        public async Task <IList <string> > GetLocationsForShip(ShipToken ship)
        {
            //Take the ID out of ship, load the XML, use XDocument to return all the internal strings of the LOCATION XML elements.

            /*var client = new HttpClient ();
             * var stream = await client.GetStreamAsync (string.Format("http://s3-us-west-2.amazonaws.com/danfs/{0}.xml", ship.ID));
             * var document = XDocument.Load (stream);
             * return document.Descendants ("LOCATION").Select (e => e.Value).ToList ();*/

            //Get these from the SQLite database now, instead of processing the XML.
            using (var connection = new SQLite.Net.SQLiteConnection(
                       TinyIoC.TinyIoCContainer.Current.Resolve <ISQLitePlatform>(),
                       TinyIoC.TinyIoCContainer.Current.Resolve <IFolderProvider>().MapDatabasePath))
            {
                var table = connection.Table <shipLocationDate>();

                var query = table.Where(r => r.shipID == ship.ID).OrderBy(r => r.startdate);

                return(query.Select(r => r.locationname).ToList());
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //API key: AIzaSyCfm_xR9xztvnrG49r7QMcbotKwTzv19Lc

            base.OnCreate(savedInstanceState);

            base.SetContentView(Resource.Layout.ShipLocation);

            // Create your application here
            ShipLocationTextView = FindViewById <TextView>(Resource.Id.shipLocationTextView);

            /*MapFragment mapFrag = (MapFragment) FragmentManager.FindFragmentById(Resource.Id.map);
             * Map = mapFrag.Map;
             * if (Map != null) {
             *      Map.MapType = GoogleMap.MapTypeSatellite;
             * }*/

            //Pull the Ship data we are supposed to show locations for.
            ShipToken = ShipToken.Deserialize(this.Intent.GetStringExtra("ShipToken"));

            RefreshData();
        }
Beispiel #8
0
        public void SetFleet(Fleet sourceFleet, Fleet otherFleet)
        {
            // Use copies as fleets will get modified in the Task, not here.
            SourceComposition = new Dictionary <long, ShipToken>();
            OtherComposition  = new Dictionary <long, ShipToken>();

            foreach (long key in sourceFleet.Composition.Keys)
            {
                if (!SourceComposition.ContainsKey(key))
                {
                    SourceComposition[key] = new ShipToken(sourceFleet.Composition[key].Design, sourceFleet.Composition[key].Quantity);
                }

                if (!OtherComposition.ContainsKey(key))
                {
                    OtherComposition[key] = new ShipToken(SourceComposition[key].Design, 0);
                }
            }

            if (otherFleet != null)
            {
                foreach (long key in otherFleet.Composition.Keys)
                {
                    if (!OtherComposition.ContainsKey(key))
                    {
                        OtherComposition[key] = new ShipToken(otherFleet.Composition[key].Design, otherFleet.Composition[key].Quantity);
                    }
                    else
                    {
                        OtherComposition[key].Quantity += otherFleet.Composition[key].Quantity;
                    }

                    if (!SourceComposition.ContainsKey(key))
                    {
                        SourceComposition[key] = new ShipToken(OtherComposition[key].Design, 0);
                    }
                }
            }

            designs = new List <ShipDesign>();
            designs.AddRange(SourceComposition.Values.Select(d => d.Design).OrderBy(x => x.Name));

            leftNumerics  = new List <NumericUpDown>();
            rightNumerics = new List <NumericUpDown>();

            lblFleetLeft.Text  = sourceFleet.Name;
            lblFleetRight.Text = otherFleet == null ? "New Fleet" : otherFleet.Name;

            fleetLayoutPanel.Controls.Clear();
            fleetLayoutPanel.RowCount = designs.Count;
            foreach (RowStyle rowStyle in fleetLayoutPanel.RowStyles)
            {
                rowStyle.SizeType = SizeType.AutoSize;
            }
            fleetLayoutPanel.Height = designs.Count * 26;
            this.Height            += (designs.Count * 26) - 26;

            for (int i = 0; i < designs.Count; ++i)
            {
                int           index = i;
                NumericUpDown num   = new NumericUpDown();
                num.Width   = 62;
                num.Maximum = SourceComposition[designs[i].Key].Quantity + OtherComposition[designs[i].Key].Quantity;
                num.Value   = SourceComposition[designs[i].Key].Quantity;
                leftNumerics.Add(num);
                num.ValueChanged += delegate { ValueChanged(Side.Left, index); };
                fleetLayoutPanel.Controls.Add(num, 0, i);

                Label designName = new Label();
                designName.Text      = designs[i].Name;
                designName.Anchor    = AnchorStyles.None;
                designName.TextAlign = ContentAlignment.MiddleCenter;
                fleetLayoutPanel.Controls.Add(designName, 1, i);

                num         = new NumericUpDown();
                num.Width   = 62;
                num.Maximum = SourceComposition[designs[i].Key].Quantity + OtherComposition[designs[i].Key].Quantity;
                num.Value   = OtherComposition[designs[i].Key].Quantity;
                rightNumerics.Add(num);
                num.ValueChanged += delegate { ValueChanged(Side.Right, index); };
                fleetLayoutPanel.Controls.Add(num, 2, i);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Allocate an initial set of resources to a player's "home" star system. for
        /// each player giving it some colonists and initial resources.
        /// </summary>
        /// <param name="star"></param>
        /// <param name="race"></param>
        private void AllocateHomeStarOrbitalInstallations(Star star, EmpireData empire, string player)
        {
            ShipDesign colonyShipDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Santa Maria")
                {
                    colonyShipDesign = design;
                }
            }

            if (empire.Race.Traits.Primary.Code != "HE")
            {
                ShipToken cs     = new ShipToken(colonyShipDesign, 1);
                Fleet     fleet1 = new Fleet(cs, star, empire.GetNextFleetKey());
                fleet1.Name = colonyShipDesign.Name + " #1";
                empire.AddOrUpdateFleet(fleet1);
            }
            else
            {
                for (int i = 1; i <= 3; i++)
                {
                    ShipToken cs    = new ShipToken(colonyShipDesign, 1);
                    Fleet     fleet = new Fleet(cs, star, empire.GetNextFleetKey());
                    fleet.Name = string.Format("{0} #{1}", colonyShipDesign.Name, i);
                    empire.AddOrUpdateFleet(fleet);
                }
            }

            ShipDesign scoutDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Scout")
                {
                    scoutDesign = design;
                }
            }

            ShipToken scout      = new ShipToken(scoutDesign, 1);
            Fleet     scoutFleet = new Fleet(scout, star, empire.GetNextFleetKey());

            scoutFleet.Name = "Scout #1";
            empire.AddOrUpdateFleet(scoutFleet);

            ShipDesign starbaseDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Starbase")
                {
                    starbaseDesign = design;
                }
            }

            ShipToken starbase      = new ShipToken(starbaseDesign, 1);
            Fleet     starbaseFleet = new Fleet(starbase, star, empire.GetNextFleetKey());

            starbaseFleet.Name = star.Name + " Starbase";
            star.Starbase      = starbaseFleet;
            empire.AddOrUpdateFleet(starbaseFleet);
        }
Beispiel #10
0
        /// <Summary>
        /// Initializes a new instance of the BattleEngineTest class.
        /// Create 4 test fleets and add them
        /// into the "all fleets" list. Make one design more powerful than the other
        /// so that the weaker one gets destroyed in the battle.
        /// </Summary>
        public BattleEngineTest()
        {
            battleEngine = new BattleEngine(serverState, new BattleReport());
            Resources cost = new Resources(10, 20, 30, 40);

            // Initialize empires
            EmpireData empireData1 = new EmpireData();
            EmpireData empireData2 = new EmpireData();
            EmpireData empireData3 = new EmpireData();

            empireData1.Id        = 1;
            empireData2.Id        = 2;
            empireData3.Id        = 3;
            empireData1.Race.Name = "Tom";
            empireData2.Race.Name = "Dick";
            empireData2.Race.Name = "Harry";

            serverState.AllEmpires[empireData1.Id] = empireData1;
            serverState.AllEmpires[empireData2.Id] = empireData2;
            serverState.AllEmpires[empireData3.Id] = empireData3;

            empireData1.BattlePlans["Default"] = new BattlePlan();
            empireData2.BattlePlans["Default"] = new BattlePlan();

            empireData1.EmpireReports.Add(2, new EmpireIntel(empireData2));
            empireData2.EmpireReports.Add(1, new EmpireIntel(empireData1));

            empireData1.EmpireReports[2].Relation = PlayerRelation.Enemy;
            empireData2.EmpireReports[1].Relation = PlayerRelation.Enemy;

            Component shipHull = new Component();
            Hull      hull     = new Hull();

            hull.FuelCapacity = 100;
            hull.Modules      = new List <HullModule>();
            shipHull.Cost     = cost;
            shipHull.Mass     = 5000;
            shipHull.Properties.Add("Hull", hull);
            shipHull.Properties.Add("Battle Movement", new DoubleProperty(1.0));

            cruiser.Blueprint = shipHull;
            cruiser.Name      = "Cruiser";

            frigate.Blueprint = shipHull;
            frigate.Name      = "Frigate";

            token1 = new ShipToken(cruiser, 1);
            token2 = new ShipToken(frigate, 1);
            token3 = new ShipToken(cruiser, 1);
            token4 = new ShipToken(frigate, 1);

            token1.Armor = 100;
            token2.Armor = 200;
            token3.Armor = 100;
            token4.Armor = 200;

            fleet1.Composition.Add(token1.Key, token1);
            fleet2.Composition.Add(token2.Key, token2);
            fleet3.Composition.Add(token3.Key, token3);
            fleet4.Composition.Add(token4.Key, token4);

            serverState.AllEmpires[Player1Id].OwnedFleets.Add(fleet1);
            serverState.AllEmpires[Player2Id].OwnedFleets.Add(fleet2);
            serverState.AllEmpires[Player3Id].OwnedFleets.Add(fleet3);
            serverState.AllEmpires[Player3Id].OwnedFleets.Add(fleet4);
        }