예제 #1
0
        private void SetAutoDonateAndDonateAllMoneyToTeamLeader(IshipIGCWrapper teamLeaderShip)
        {
            if (teamLeaderShip != null)
            {
                Log($"Setting auto-donate to {teamLeaderShip?.GetName()}, donating {ClientConnection.GetMoney()} to the new commander.");

                AllegianceInterop.FMD_C_AUTODONATE autoDonate = new AllegianceInterop.FMD_C_AUTODONATE(teamLeaderShip.GetObjectID(), ClientConnection.GetMoney());
                ClientConnection.SendMessageServer(autoDonate);
            }
        }
예제 #2
0
        private void ClearShipCargo(IshipIGCWrapper ship)
        {
            // Clear the cargo.
            for (sbyte i = -5; i < 0; i++)
            {
                var currentPart = ship.GetMountedPart((short)EquipmentType.NA, i);
                if (currentPart != null)
                {
                    currentPart.Terminate();
                }
            }

            // Clear weapons
            for (sbyte i = 0; i < 4; i++)
            {
                var currentPart = ship.GetMountedPart((short)EquipmentType.ET_Weapon, i);
                if (currentPart != null)
                {
                    currentPart.Terminate();
                }
            }

            // Clear turrets
            for (sbyte i = 0; i < ship.GetHullType().GetMaxWeapons() - ship.GetHullType().GetMaxFixedWeapons(); i++)
            {
                var currentPart = ship.GetMountedPart((short)EquipmentType.ET_Turret, i);
                if (currentPart != null)
                {
                    currentPart.Terminate();
                }
            }

            // Clear missiles
            for (sbyte i = 0; i < 1; i++)
            {
                var currentPart = ship.GetMountedPart((short)EquipmentType.ET_Magazine, i);
                if (currentPart != null)
                {
                    currentPart.Terminate();
                }
            }

            // Clear Dispenser
            for (sbyte i = 0; i < 1; i++)
            {
                var currentPart = ship.GetMountedPart((short)EquipmentType.ET_Dispenser, i);
                if (currentPart != null)
                {
                    currentPart.Terminate();
                }
            }
        }
예제 #3
0
 private void DoTargetedSweep(IshipIGCWrapper ship)
 {
     Log("DoTargetedSweep(): Find the missing aleph using triangulation on the other alephs.");
 }
예제 #4
0
        private void PlaceStation(IshipIGCWrapper ship, short clusterID)
        {
            if (_constuctorsInFlightToClusterObjectIDByShipObjectID.ContainsKey(ship.GetObjectID()) == true)
            {
                return;
            }

            StationType stationType;

            if (ship.GetName().Contains("Outpost") == true)
            {
                stationType = StationType.Outpost;
            }
            else if (ship.GetName().Contains("Teleport") == true)
            {
                stationType = StationType.Teleport;
            }
            else if (ship.GetName().Contains("Refinery") == true)
            {
                stationType = StationType.Refinery;
            }
            else
            {
                throw new NotSupportedException($"No station type found for ship name: {ship.GetName()}");
            }



            var targetCluster = GetStationBuildCluster(stationType);
            var shipCluster   = ClientConnection.GetCore().GetCluster(clusterID);

            Log($"\tPlaceStation: {stationType.ToString()}, constructor: {ship.GetName()}, currentCluster: {shipCluster.GetName()}");

            if (targetCluster == null)
            {
                Log("\t\tNo valid target cluster could be found, waiting for a cluster finish building to plot this station's destination.");
                return;
            }

            _constuctorsInFlightToClusterObjectIDByShipObjectID.Add(ship.GetObjectID(), new InflightConstructor()
            {
                Cluster     = targetCluster,
                Ship        = ship,
                StationType = stationType
            });


            if (targetCluster != null)
            {
                Task.Run(() =>
                {
                    IclusterIGCWrapper intermediateCluster = null;

                    while (targetCluster.GetAsteroids().Count == 0 && _cancellationTokenSource.IsCancellationRequested == false)
                    {
                        if (intermediateCluster == null || (shipCluster.GetObjectID() == intermediateCluster.GetObjectID()))
                        //if (ship.GetCommandID((sbyte) CommandType.c_cmdCurrent) <= (sbyte) CommandID.c_cidNone)
                        {
                            Log($"Looking for intermediate cluster, target cluster: {targetCluster.GetName()} has not been discovered yet. Current ship command is: {((CommandID)ship.GetCommandID((sbyte)CommandType.c_cmdCurrent)).ToString()}");

                            var pathFinder = new DijkstraPathFinder(GameInfo.Clusters, targetCluster.GetObjectID(), GetHomeCluster().GetObjectID());

                            // Find a sector on the route that we have already explored, we will send the constructor there while we wait for scouts to find the way.
                            for (intermediateCluster = targetCluster; intermediateCluster.GetAsteroids().Count == 0; intermediateCluster = pathFinder.NextCluster(intermediateCluster, GetHomeCluster()))
                            {
                                ;
                            }


                            if (intermediateCluster != null && shipCluster != null && shipCluster.GetObjectID() != intermediateCluster.GetObjectID())
                            {
                                Log($"Found intermediate cluster: {intermediateCluster.GetName()}, sending con there.");

                                // Send the con to the middle of the cluster, and wait for the way to be found.
                                var buoy    = ClientConnection.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, 0, 0, 0, intermediateCluster.GetObjectID(), true);
                                var command = ship.GetDefaultOrder(buoy);

                                ClientConnection.SendChat(ClientConnection.GetShip(), ChatTarget.CHAT_INDIVIDUAL, ship.GetObjectID(), 0, "", (sbyte)command, buoy.GetObjectType(), buoy.GetObjectID(), buoy, true);
                            }
                        }

                        Thread.Sleep(250);
                    }

                    if (targetCluster.GetAsteroids().Count > 0)
                    {
                        var targetRock = GetStationBuildRock(stationType, targetCluster);
                        Log($"Found target rock for con: {ship.GetName()}, sending con to: {targetCluster.GetName()}, {targetRock.GetName()}");

                        ClientConnection.SendChat(ClientConnection.GetShip(), ChatTarget.CHAT_INDIVIDUAL, ship.GetObjectID(), 0, "", (sbyte)CommandID.c_cidBuild, targetRock.GetObjectType(), targetRock.GetObjectID(), targetRock, true);
                    }
                });
            }



            //var foundClusters = ClientConnection.GetCore().GetClusters();
            //var stations = ClientConnection.GetSide().GetStations();


            //var homeStation = stations.Where(p => p.GetCluster().GetHomeSector() == true).FirstOrDefault();
            //var homeCluster = homeStation.GetCluster();

            //var asteroidNames = homeCluster.GetAsteroids().ToDictionary(r => r.GetObjectID(), p => p.GetName());

            //Log("\t\tHome asteroids");
            //foreach (var name in asteroidNames.Values)
            //{
            //    Log($"\t\t\t{name}");
            //}

            //var homeRock = homeCluster.GetAsteroids().Where(p => p.GetName().StartsWith("He") == false && p.GetName().StartsWith("a") == false && String.IsNullOrWhiteSpace(p.GetName()) == false).FirstOrDefault();

            //Log($"\t\thomeRock: {homeRock.GetName()}");

            //var nextSectorTechRocks = homeCluster.GetWarps()
            //    .Select(p => p.GetDestination().GetCluster())
            //    .Select(r => r.GetAsteroids())
            //    .Select(q => q.Where(s => s.GetName().StartsWith("He") == false && s.GetName().StartsWith("a") == false && String.IsNullOrWhiteSpace(s.GetName()) == false).FirstOrDefault())
            //    .Where(t => t != null && String.IsNullOrWhiteSpace(t.GetName()) == false);

            //foreach (var nextSectorTechRock in nextSectorTechRocks)
            //    Log($"\t\tnextSectorTechRock: {nextSectorTechRock.GetName()}");

            //var viableNextSectors = nextSectorTechRocks.Where(p => String.IsNullOrWhiteSpace(p.GetName()) == false && String.IsNullOrWhiteSpace(homeRock.GetName()) == false  && p.GetName()[0] == homeRock.GetName()[0]);

            //foreach (var viableNextSectorItem in viableNextSectors)
            //    Log($"\t\tviableNextSector: {viableNextSectorItem.GetName()}");

            //var viableNextSector = viableNextSectors.FirstOrDefault();

            //var targetNextSector = homeCluster.GetWarps().FirstOrDefault().GetDestination().GetCluster();
            //if (viableNextSector != null)
            //    targetNextSector = viableNextSector.GetCluster();

            //Log($"targeting {targetNextSector.GetName()} for possible future tech base, will build outpost forward of this sector.");

            //// Find the next adjacent sector that does not lead back to the home sector! (We want a sector that is at least two hops away!)
            ////var targetBuildCluster = targetNextSector.GetWarps()
            ////    .Where(p =>
            ////        p.GetDestination().GetCluster().GetObjectID() != homeCluster.GetObjectID() // Don't go back to the home sector!
            ////        && p.GetDestination().GetCluster().GetWarps().Exists(r => r.GetDestination().GetCluster().GetObjectID() == homeCluster.GetObjectID()) == false)
            ////     .FirstOrDefault()
            ////     ?.GetCluster(); // Don't go to a sector that leads back to the home sector.

            //var targetBuildCluster = targetNextSector.GetWarps()
            //    .OrderByDescending(p => new DijkstraPathFinder(GameInfo.Clusters, p.GetDestination().GetCluster().GetObjectID(), homeCluster.GetObjectID()).GetDistance(p.GetDestination().GetCluster().GetObjectID(), homeCluster.GetObjectID()))
            //    .Select(p => p.GetDestination().GetCluster())
            //    .FirstOrDefault();

            //// Find the next forward sector if it's been found yet. We are only interested a sector that is two hops from home base.
            ////foreach (var nextSectorWarp in targetNextSector.GetWarps())
            ////{
            ////    var d = new DijkstraPathFinder(ClientConnection.GetCore(), nextSectorWarp.GetDestination().GetCluster(), homeCluster);
            ////}

            //bool foundTarget = false;

            //if (targetBuildCluster != null)
            //{
            //    Log($"\t\ttargeting {targetBuildCluster.GetName()} for outpost cluster.");

            //    // find closest rock to the center
            //    VectorWrapper centerPoint = new VectorWrapper(0, 0, 0);
            //    var targetRock = targetBuildCluster.GetAsteroids()
            //        .Where(p => p.GetName().StartsWith("a") == true)
            //        .OrderBy(p => (centerPoint - p.GetPosition()).LengthSquared())
            //        .FirstOrDefault();

            //    if (targetRock != null)
            //    {
            //        Log($"\t\ttargeting {targetRock.GetName()} for outpost rock.");

            //        ClientConnection.SendChat(ClientConnection.GetShip(), ChatTarget.CHAT_INDIVIDUAL, ship.GetObjectID(), 0, "", (sbyte)CommandID.c_cidBuild, targetRock.GetObjectType(), targetRock.GetObjectID(), targetRock, true);

            //        //ship.SetCommand((sbyte)CommandType.c_cmdCurrent, targetRock, (sbyte)CommandID.c_cidBuild);
            //        //ship.SetCommand((sbyte)CommandType.c_cmdAccepted, targetRock, (sbyte)CommandID.c_cidBuild);

            //        foundTarget = true;
            //        //ship.SetAutopilot(true);
            //    }
            //    else
            //    {
            //        Log($"Couldn't find a target rock in cluster: {targetBuildCluster.GetName()}");
            //    }
            //}
            //else
            //{
            //    Log($"Couldn't find a target cluster to build in.");
            //}

            //if (foundTarget == false)
            //{
            //    Log($"Couldn't find a target build rock, moving to sector: {targetNextSector.GetName()} while we wait for the rock to be found.");

            //    var buoy = ClientConnection.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, 0, 0, 0, targetNextSector.GetObjectID(), true);
            //    var command = ship.GetDefaultOrder(buoy);

            //    ClientConnection.SendChat(ClientConnection.GetShip(), ChatTarget.CHAT_INDIVIDUAL, ship.GetObjectID(), 0, "", (sbyte)command, buoy.GetObjectType(), buoy.GetObjectID(), buoy, true);


            //    //ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command);
            //    //ship.SetCommand((sbyte)CommandType.c_cmdAccepted, buoy, command);

            //    //ship.SetCommand((sbyte)CommandType.c_cmdCurrent, targetNextSector, (sbyte)CommandID.c_cidGoto);
            //    //ship.SetCommand((sbyte)CommandType.c_cmdAccepted, targetNextSector, (sbyte)CommandID.c_cidGoto);
            //}
        }