예제 #1
0
        protected void ProcessSpawnQueue()
        {
            currentSpawnProgress += spawnIncrement;
            if (currentSpawnProgress > _maxSpawnProgress)
            {
                if (Agent.GetCommander())
                {
                    //if (audioElement != null)
                    //{
                    //    audioElement.Play(finishedJobSound);
                    //}
                    Vector2d spawnOutside = new Vector2d(this.transform.position);
                    RTSAgent agent        = Agent.Controller.CreateAgent(spawnQueue.Dequeue(), spawnOutside);
                    agent.SetProvision(true);

                    if (cachedRally)
                    {
                        if (cachedRally.spawnPoint != cachedRally.rallyPoint)
                        {
                            Command moveCom = new Command(AbilityDataItem.FindInterfacer("Move").ListenInputID);
                            moveCom.Add <Vector2d>(new Vector2d(cachedRally.rallyPoint));
                            moveCom.ControllerID = agent.Controller.ControllerID;
                            moveCom.Add <Influence>(new Influence(agent));

                            CommandManager.SendCommand(moveCom);
                        }
                    }
                }
                currentSpawnProgress = 0;
            }
        }
예제 #2
0
        public void StartHarvest(RTSAgent resource)
        {
            if (resource != Agent && resource != null)
            {
                Agent.Tag = AgentTag.Harvester;
                //if (audioElement != null)
                //{
                //    audioElement.Play(startHarvestSound);
                //}
                resourceTarget = resource;
                ResourceType resourceType = resource.GetAbility <ResourceDeposit>().ResourceType;
                // we can only collect one resource at a time, other resources are lost
                if (resourceType == ResourceType.Unknown || resourceType != HarvestType)
                {
                    HarvestType       = resourceType;
                    currentLoadAmount = 0;
                }
                IsHarvesting = true;
                IsCasting    = true;
                IsEmptying   = false;

                if (!CheckRange(resourceTarget.Body))
                {
                    StartHarvestMove(resourceTarget.Body._position);
                }
            }
        }
        public static RTSAgent FindClosestAgent(Vector2d position, FastList <RTSAgent> agents)
        {
            long     sourceX         = position.x;
            long     sourceY         = position.y;
            RTSAgent closestAgent    = null;
            long     closestDistance = 0;
            int      foundBuffer     = FoundScanBuffer;

            foreach (RTSAgent agent in agents)
            {
                if (closestAgent != null)
                {
                    long tempDistance = agent.Body._position.FastDistance(sourceX, sourceY);
                    if (tempDistance < closestDistance)
                    {
                        closestAgent    = agent;
                        closestDistance = tempDistance;
                        foundBuffer     = FoundScanBuffer;
                    }
                    else
                    {
                        foundBuffer--;
                    }
                }
                else
                {
                    closestAgent    = agent;
                    closestDistance = agent.Body._position.FastDistance(sourceX, sourceY);
                }
            }
            return(closestAgent);
        }
예제 #4
0
        protected override void OnInitialize()
        {
            basePriority   = Agent.Body.Priority;
            constructCount = 0;
            CurrentProject = null;
            IsBuilding     = false;
            IsBuildMoving  = false;
            inRange        = false;
            IsFocused      = false;

            repathTimer.Reset(repathInterval);
            repathRandom = LSUtility.GetRandom(repathInterval);

            //caching parameters
            var spawnVersion = Agent.SpawnVersion;
            var controller   = Agent.Controller;

            if (Agent.GetCommander() && loadedSavedValues && loadedProjectId >= 0)
            {
                RTSAgent obj = Agent.GetCommander().GetObjectForId(loadedProjectId);
                if (obj.MyAgentType == AgentType.Building)
                {
                    CurrentProject = obj;
                }
            }
        }
예제 #5
0
 public static void UnselectAgent(RTSAgent agent)
 {
     if (agent.IsNotNull())
     {
         Selector.Remove(agent);
     }
 }
예제 #6
0
        public void Setup(RTSAgent agent)
        {
            Agent = agent;
            Body  = agent.Body;

            if (Agent.GetAbility <Attack>() && Agent.GetAbility <Attack>().IsOffensive)
            {
                AgentAI.Add(new OffensiveAI());
            }

            if (Agent.GetAbility <Harvest>())
            {
                AgentAI.Add(new HarvesterAI());
            }

            if (Agent.GetAbility <Construct>())
            {
                AgentAI.Add(new ConstructorAI());
            }

            foreach (var AI in AgentAI)
            {
                AI.OnSetup(agent);
            }
        }
        private void ApplyCone(Vector3d center3d, Vector2d forward, long radius, long angle)
        {
            Vector2d center    = center3d.ToVector2d();
            long     fastRange = radius * radius;

            Scan(center, radius);
            for (int i = 0; i < ScanOutput.Count; i++)
            {
                RTSAgent agent      = ScanOutput [i];
                Vector2d agentPos   = agent.Body._position;
                Vector2d difference = agentPos - center;

                if (difference.FastMagnitude() > fastRange)
                {
                    continue;
                }
                if (forward.Dot(difference) < 0)
                {
                    continue;
                }
                difference.Normalize();

                long cross = forward.Cross(difference).Abs();
                if (cross > angle)
                {
                    continue;
                }
                HitAgent(agent);
            }
        }
예제 #8
0
        protected override void OnInitialize()
        {
            basePriority    = Agent.Body.Priority;
            harvestCount    = 0;
            IsHarvesting    = false;
            IsHarvestMoving = false;
            inRange         = false;
            IsFocused       = false;

            repathTimer.Reset(repathInterval);
            repathRandom = LSUtility.GetRandom(repathInterval);

            //caching parameters
            var spawnVersion = Agent.SpawnVersion;
            var controller   = Agent.Controller;

            if (Agent.GetCommander() && loadedSavedValues && loadedDepositId >= 0)
            {
                RTSAgent obj = Agent.GetCommander().GetObjectForId(loadedDepositId);
                if (obj.MyAgentType == AgentType.Resource)
                {
                    resourceTarget = obj;
                }
            }
            else
            {
                HarvestType = ResourceType.Unknown;
            }
        }
예제 #9
0
        private RTSAgent ClosestResourceStore()
        {
            //change list to fastarray
            List <RTSAgent> playerBuildings = new List <RTSAgent>();

            // use RTS influencer?
            foreach (RTSAgent child in Agent.Controller.Commander.GetComponentInChildren <RTSAgents>().GetComponentsInChildren <RTSAgent>())
            {
                if (child.GetAbility <Structure>() &&
                    child.GetAbility <Structure>().CanStoreResources(HarvestType) &&
                    !child.GetAbility <Structure>().NeedsConstruction)
                {
                    playerBuildings.Add(child);
                }
            }
            if (playerBuildings.Count > 0)
            {
                RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(playerBuildings, transform.position) as RTSAgent;
                return(nearestObject);
            }
            else
            {
                return(null);
            }
        }
        public void Setup(RTSAgent agent)
        {
            setupActives.FastClear();
            Abilitys = agent.AttachedAbilities;
            for (int i = 0; i < Abilitys.Length; i++)
            {
                Ability abil = Abilitys[i];

                ActiveAbility activeAbil = abil as ActiveAbility;
                if (activeAbil.IsNotNull())
                {
                    setupActives.Add(activeAbil);
                }
            }

            ActiveAbilitys = setupActives.ToArray();

            for (int i = 0; i < Abilitys.Length; i++)
            {
                Abilitys[i].Setup(agent, i);
            }
            for (int i = 0; i < Abilitys.Length; i++)
            {
                Abilitys[i].LateSetup();
            }
            for (int i = 0; i < ActiveAbilitys.Length; i++)
            {
                if (ActiveAbilitys[i].Data.IsNotNull())
                {
                    Interfacers.Add(ActiveAbilitys[i].Data);
                }
            }
        }
예제 #11
0
        void SetupConfigs()
        {
            IUnitConfigDataProvider database;

            //todo guard
            if (LSDatabaseManager.TryGetDatabase(out database))
            {
                ConfigElementData = database.UnitConfigElementData;
                ConfigElementMap  = new Dictionary <string, UnitConfigElementDataItem> ();
                for (int i = 0; i < ConfigElementData.Length; i++)
                {
                    var item = ConfigElementData [i];
                    ConfigElementMap.Add(item.Name, item);
                }
                ConfigData = database.UnitConfigData;
                for (int i = 0; i < ConfigData.Length; i++)
                {
                    IUnitConfigDataItem item  = ConfigData [i];
                    RTSAgent            agent = GameResourceManager.GetAgentTemplate(item.Target);
                    for (int j = 0; j < item.Stats.Length; j++)
                    {
                        Stat stat = item.Stats [j];
                        //todo guard
                        var       element   = ConfigElementMap [stat.ConfigElement];
                        Component component = agent.GetComponent(element.ComponentType);
                        SetField(component, element.Field, stat.Value);
                    }
                }
            }
        }
예제 #12
0
 internal void Setup(RTSAgent agent, int id)
 {
     System.Type mainType = this.GetType();
     if (mainType.IsSubclassOf(typeof(ActiveAbility)))
     {
         while (mainType.BaseType != typeof(ActiveAbility) &&
                mainType.GetCustomAttributes(typeof(CustomActiveAbilityAttribute), false).Length == 0)
         {
             mainType = mainType.BaseType;
         }
         Data = AbilityDataItem.FindInterfacer(mainType);
         if (Data == null)
         {
             throw new System.ArgumentException("The Ability of type " + mainType + " has not been registered in database");
         }
         this.MyAbilityCode = Data.Name;
     }
     else
     {
         this.MyAbilityCode = mainType.Name;
     }
     _agent = agent;
     ID     = id;
     TemplateSetup();
     OnSetup();
     this.VariableContainerTicket = LSVariableManager.Register(this);
     this._variableContainer      = LSVariableManager.GetContainer(VariableContainerTicket);
 }
예제 #13
0
 protected void CallExtraOnHit(RTSAgent agent, bool isCurrent)
 {
     if (ExtraOnHit != null)
     {
         ExtraOnHit(agent, isCurrent);
     }
 }
        private static void DestroyAgentBuffer(DeactivationData data)
        {
            RTSAgent agent = data.Agent;

            if (agent.IsActive == false)
            {
                return;
            }
            bool immediate = data.Immediate;

            agent.Deactivate(immediate);
            ChangeController(agent, null);

            //Pool if the agent is registered
            ushort agentCodeID;

            if (agent.TypeIndex != UNREGISTERED_TYPE_INDEX)
            {
                // if (CodeIndexMap.TryGetValue(agent.MyAgentCode, out agentCodeID))
                // {
                agentCodeID = GameResourceManager.GetAgentCodeIndex(agent.MyAgentCode);
                if (agentCodeID.IsNotNull())
                {
                    TypeAgentsActive[agentCodeID][agent.TypeIndex] = false;
                }
            }
        }
        /// <summary>
        /// Create an uninitialized RTSAgent
        /// </summary>
        /// <returns>The raw agent.</returns>
        /// <param name="agentCode">Agent code.</param>
        /// <param name="isBare">If set to <c>true</c> is bare.</param>
        public static RTSAgent CreateRawAgent(string agentCode, Vector2d startPosition = default(Vector2d), Vector2d startRotation = default(Vector2d))
        {
            if (!GameResourceManager.IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }
            FastStack <RTSAgent> cache    = CachedAgents[agentCode];
            RTSAgent             curAgent = null;

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();
                ushort agentCodeID = GameResourceManager.GetAgentCodeIndex(agentCode);
                Debug.Log(curAgent.TypeIndex);
                TypeAgentsActive[agentCodeID][curAgent.TypeIndex] = true;
            }
            else
            {
                IAgentData interfacer = GameResourceManager.AgentCodeInterfacerMap[agentCode];

                Vector3    pos = startPosition.ToVector3();
                Quaternion rot = new Quaternion(0, startRotation.y, 0, startRotation.x);

                curAgent = GameObject.Instantiate(GameResourceManager.GetAgentTemplate(agentCode).gameObject, pos, rot).GetComponent <RTSAgent>();
                curAgent.Setup(interfacer);

                RegisterRawAgent(curAgent);
            }
            return(curAgent);
        }
 public void InitializeAgent(RTSAgent agent,
                             Vector2d position,
                             Vector2d rotation)
 {
     AddAgent(agent);
     agent.Initialize(position, rotation);
 }
예제 #17
0
 public static void SelectAgent(RTSAgent agent)
 {
     if (agent.IsNotNull())
     {
         Selector.Add(agent);
     }
 }
        //integrate into LSF...
        //void OnEnable()
        //{
        //    //Tell our 'OnLevelFinishedLoading' function to start listening for a scene change as soon as this script is enabled.
        //    SceneManager.sceneLoaded += OnLevelFinishedLoading;
        //}

        //void OnDisable()
        //{
        //    //Tell our 'OnLevelFinishedLoading' function to stop listening for a scene change as soon as this script is disabled. Remember to always have an unsubscription for every delegate you subscribe to!
        //    SceneManager.sceneLoaded -= OnLevelFinishedLoading;
        //}

        //void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
        //{
        //    if (ResourceManager.LevelName != null && ResourceManager.LevelName != "")
        //    {
        //        LoadManager.LoadGame(ResourceManager.LevelName);
        //    }
        //    Time.timeScale = 1.0f;
        //    ResourceManager.MenuOpen = false;
        //}

        public void LaunchSpawns()
        {
            foreach (SpawnInfo info in Spawns)
            {
                var controller = AgentControllerHelper.Instance.GetInstanceManager(info.ControllerCode);

                for (int j = 0; j < info.Count; j++)
                {
                    RTSAgent agent = controller.CreateAgent(info.AgentCode, info.Position);
                    if (AutoCommand)
                    {
                        Selector.Add(agent);
                    }
                }
            }

            if (AutoCommand)
            {
                //Find average of spawn positions
                Vector2d battlePos = Vector2d.zero;
                foreach (SpawnInfo info in Spawns)
                {
                    battlePos += info.Position;
                }
                battlePos /= Spawns.Length;
                Command com = new Command(Data.AbilityDataItem.FindInterfacer <Attack>().ListenInputID);
                com.Add <Vector2d>(battlePos);

                PlayerManager.SendCommand(com);
                Selector.Clear();
            }
        }
예제 #19
0
        public void StopConstruction(bool complete = false)
        {
            inRange    = false;
            IsFocused  = false;
            IsBuilding = false;
            IsCasting  = false;

            CurrentProject      = null;
            CachedBody.Priority = basePriority;

            if (complete)
            {
                IsBuildMoving = false;
                Agent.Tag     = AgentTag.None;
                ConstructQueue.Clear();
            }
            else
            {
                if (IsBuildMoving && this.CurrentProject)
                {
                    cachedMove.StartMove(this.CurrentProject.Body.Position);
                }
                else if (!inRange)
                {
                    cachedMove.StopMove();
                }
            }
        }
예제 #20
0
 public EnvironmentAgentInfo(string agentCode, RTSAgent agent, Vector3d pos, Vector2d rot)
 {
     AgentCode = agentCode;
     Agent     = agent;
     Position  = pos;
     Rotation  = rot;
 }
예제 #21
0
        public void StopBuilding(bool complete = false)
        {
            inRange   = false;
            IsFocused = false;
            if (complete)
            {
                IsBuildMoving = false;
            }
            else
            {
                if (IsBuildMoving)
                {
                    cachedMove.StartMove(this.CurrentProject.Body.Position);
                }
                else
                {
                    if (CurrentProject != null && inRange == false)
                    {
                        cachedMove.StopMove();
                    }
                }
            }

            CurrentProject      = null;
            CachedBody.Priority = basePriority;

            IsCasting  = false;
            IsBuilding = false;
        }
예제 #22
0
        protected override void OnInitialize()
        {
            basePriority     = Agent.Body.Priority;
            searchCount      = LSUtility.GetRandom(SearchRate) + 1;
            attackCount      = 0;
            Target           = null;
            IsAttackMoving   = false;
            inRange          = false;
            isFocused        = false;
            CycleCount       = 0;
            this.Destination = Vector2d.zero;
            repathTimer.Reset(repathInterval);
            repathRandom = LSUtility.GetRandom(repathInterval);

            //caching parameters
            var spawnVersion = Agent.SpawnVersion;
            var controller   = Agent.Controller;

            CachedOnHit = (target) => OnHit(target, spawnVersion, controller);

            if ((Agent as RTSAgent).GetCommander() && loadedSavedValues && loadedTargetId >= 0)
            {
                RTSAgent obj = (Agent as RTSAgent).GetCommander().GetObjectForId(loadedTargetId);
                if (obj.MyAgentType == AgentType.Unit || obj.MyAgentType == AgentType.Building)
                {
                    Target = (LSAgent)obj;
                }
            }
        }
 public void AddToSelection(RTSAgent agent)
 {
     if (agent.IsSelected == false)
     {
         SelectedAgents.Add(agent);
         SelectionChanged = true;
     }
 }
 public static bool TryGetAgentInstance(int globalID, out RTSAgent returnAgent)
 {
     if (GlobalAgentActive[globalID])
     {
         returnAgent = GlobalAgents[globalID];
         return(true);
     }
     returnAgent = null;
     return(false);
 }
예제 #25
0
        protected virtual void OnHit(RTSAgent target, uint agentVersion, AgentController controller)
        {
            //If the shooter died, certain effects or records can't be completed
            bool         isCurrent = Agent != null && agentVersion == Agent.SpawnVersion;
            Health       healther  = target.GetAbility <Health>();
            AttackerInfo info      = new AttackerInfo(isCurrent ? Agent : null, controller);

            healther.TakeDamage(Damage, info);
            CallExtraOnHit(target, isCurrent);
        }
예제 #26
0
        public static void BoxAgent(RTSAgent agent)
        {
            if (ReferenceEquals(agent, null))
            {
                return;
            }

            SelectedAgents.Add(agent);
            agent.IsHighlighted = true;
        }
예제 #27
0
 public static void Remove(RTSAgent agent)
 {
     PlayerManager.MainController.RemoveFromSelection(agent);
     agent.IsSelected = false;
     if (agent == MainSelectedAgent)
     {
         agent = SelectedAgents.Count > 0 ? SelectedAgents.PopMax() : null;
     }
     onRemove(agent);
 }
예제 #28
0
        public void Initialize(int duration, RTSAgent target)
        {
            Duration = duration;
            Timer    = 0;
            Target   = target;

            Target.AddBuff(this);
            Active = true;
            this.OnInitialize();
        }
 public static void ClearAgents()
 {
     for (int i = GlobalAgents.Length - 1; i >= 0; i--)
     {
         if (GlobalAgentActive[i])
         {
             RTSAgent agent = GlobalAgents[i];
             AgentController.DestroyAgent(agent);
         }
     }
 }
 public static void CacheAgent(RTSAgent agent)
 {
     if (LockstepManager.PoolingEnabled)
     {
         CachedAgents[agent.MyAgentCode].Add(agent);
     }
     else
     {
         GameObject.Destroy(agent.gameObject);
     }
 }