Exemplo n.º 1
0
        public void AddDrone(ConquestDrone drone)
        {
            foreach (var squad in _squads)
            {
                if (squad.DroneCount() < DronesPerConquestSquad)
                {
                    Util.GetInstance().Log("[ConquestDronemanager.AddDrone] drone added!");
                    squad.AddDrone(drone);
                    return;
                }
            }

            if (_squads.Count < MaxNumConquestSquads)
            {
                var sq = new ConquestDroneSquad(drone.GetOwnerId());
                sq.AddDrone(drone);
                Util.GetInstance().Log("[ConquestDronemanager.AddDrone] squad created: drone added!");
                _squads.Add(sq);
                sq.SetOwner(drone.GetOwnerId());
            }
        }
Exemplo n.º 2
0
        public void UpdateSquadMission(ConquestDroneSquad squad)
        {
            ConquestMission mission = null;

            if (squad.Mission() != null && squad.Mission().MissionType == ActionTypes.Patrol)
            {
                mission = GenerateMission(squad, true);
                if (mission != null)
                {
                    squad.IssueMission(mission);
                    squad.SetOwner(GetMothershipID());
                    Util.GetInstance().Log("[ConquestDroneManager.UpdateSquadMission] Switching from patrol mission to assist Mission " + squad.myid, logpath);
                }
            }

            if (mission == null)
            {
                mission = squad.ReadyForNewMission(ticks) ? GenerateMission(squad) : squad.Mission();
                squad.IssueMission(mission);
                squad.SetOwner(GetMothershipID());
            }
        }
Exemplo n.º 3
0
        private ConquestMission GenerateMission(ConquestDroneSquad squad, bool assistOnly = false)
        {
            bool readyForNewMission   = squad.ReadyForNewMission(ticks);
            bool previousMissionGuard = squad.Mission() != null && squad.Mission().MissionType == ActionTypes.Guard;

            if (!readyForNewMission && !assistOnly)
            {
                return(null);
            }

            if (!previousMissionGuard)
            {
                Util.GetInstance().Log("[ConquestDroneManager.GenerateMission] PreviousMission Expired " + squad.myid, logpath);
            }

            if (squad.Mission() != null && squad.Mission().IsAsteroid)
            {
                _asteroids[squad.Mission().asteroid] = _asteroids[squad.Mission().asteroid] + 1;
            }

            bool            ong     = false;
            Vector3D        loc     = Vector3D.Zero;
            int             start   = ticks;
            ConquestMission mission = null;


            if (!assistOnly)
            {
                //try to patrol around the mothership if there are open positions
                if (NumGuardingDroneSquads < MaxNumGuardingDroneSquads)
                {
                    loc = _mothershipLocation;
                    // the 0 is to make this mission always last only one command cycle, so if the squad dies I wont have to so multipule updates removing it as a guarding squad
                    mission = new ConquestMission(ong, loc, start, ActionTypes.Guard);
                    //Util.GetInstance().Log("[ConquestDroneManager.GenerateMission] guard Home "+squad.myid, logpath);
                    NumGuardingDroneSquads++;
                    return(mission);
                }
            }

            //if any drones are in need of assistance then assist them
            foreach (var pair in _combatSites)
            {
                if (!(CalculateTargetPriority(pair.Key) >= _combatSites[pair.Key] + 1))
                {
                    continue;
                }

                Util.GetInstance()
                .Log(
                    "[ConquestDroneManager.GenerateMission] Number of combat sites in need of help " +
                    _combatSites.Count(), logpath);
                loc = pair.Key * 3000;
                _combatSites[pair.Key] = _combatSites[pair.Key] + 1;
                mission = new ConquestMission(ong, loc, start, ActionTypes.Assist);
                Util.GetInstance()
                .Log("[ConquestDroneManager.GenerateMission] joining in combat " + squad.myid, logpath);

                return(mission);
            }

            //i dont think visiting asteroids is nessessary, they explore enough to find players as is
            //if (!assistOnly)
            //{
            //    var asteroids =
            //        _asteroids.OrderBy(x => x.Value)
            //            .Where(y => (y.Key.GetPosition() - squad.GetLocation()).Length() < DroneMaxRange);
            //    //if there are nearby unexplored asteroids explore them
            //    foreach (var pair in asteroids)
            //    {
            //        int max = _asteroids.Values.Max();
            //        if (pair.Value < max || _asteroids.Count == _asteroids.Count(x=>x.Value == max))
            //        {
            //            loc = pair.Key.GetPosition();
            //            mission = new ConquestMission(ong, loc, start, ActionTypes.Assist, DroneMaxRange/15, true,
            //                pair.Key);
            //            Util.GetInstance()
            //                .Log("[ConquestDroneManager.GenerateMission] orbit asteroid " + squad.myid, logpath);
            //        }
            //        return mission;
            //    }
            //}

            if (assistOnly)
            {
                return(mission);
            }
            //generate a random patrol route

            int X = r.Next(-DroneMaxRange, DroneMaxRange);
            int Y = r.Next(-DroneMaxRange, DroneMaxRange);
            int Z = r.Next(-DroneMaxRange, DroneMaxRange);

            loc = _mothershipLocation + new Vector3D(X, Y, Z);
            Util.GetInstance().Log("[ConquestDroneManager.GenerateMission] Patrol loc:" + loc + " " + squad.myid, logpath);
            mission = new ConquestMission(ong, loc, start, ActionTypes.Patrol, DroneMaxRange / 1000 * 60);

            return(mission);
        }