Exemple #1
0
        private static LSEffect GenEffect(EffectCode effectCode, int id = -1)
        {
            FastStack <LSEffect> pool   = EffectPool[effectCode];
            LSEffect             effect = null;

            if (pool.Count > 0)
            {
                effect = pool.Pop();
            }
            else
            {
                Debug.Log(effectCode);
                EffectDataItem dataItem = CodeDataMap[effectCode];
                effect = GameObject.Instantiate <GameObject> (dataItem.Prefab).GetComponent <LSEffect> ();
                effect.Setup(effectCode);
            }

            if (id == -1)
            {
                id = GenerateID();
            }
            if (effect.Create(id))
            {
                return(effect);
            }
            else
            {
                return(GenEffect(effectCode, id));
            }
        }
        public LSAgent CreateAgent(AgentCode agentCode)
        {
            FastStack <LSAgent> cache = CachedAgents[(int)agentCode];

            if (cache != null && cache.Count > 0)
            {
                curAgent = cache.Pop();
            }
            else
            {
                curAgent = GameObject.Instantiate(AgentObjects[(int)agentCode]).GetComponent <LSAgent> ();
            }

            localID              = GenerateLocalID();
            curAgent.LocalID     = localID;
            Agents[localID]      = curAgent;
            AgentActive[localID] = true;

            globalID          = GenerateGlobalID();
            curAgent.GlobalID = globalID;

            curAgent.Initialize();

            RingController ringController = GameObject.Instantiate(LockstepManager.Instance.SelectionRing).GetComponent <RingController> ();

            ringController.Initialize(curAgent);
            curAgent.ringController = ringController;

            return(curAgent);
        }
        /// <summary>
        /// Create an uninitialized LSAgent
        /// </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 LSAgent CreateRawAgent(string agentCode)
        {
            if (!IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }
            FastStack <LSAgent> cache    = CachedAgents [agentCode];
            LSAgent             curAgent = null;

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

                curAgent = GameObject.Instantiate(AgentController.GetAgentTemplate(agentCode).gameObject).GetComponent <LSAgent> ();
                curAgent.Setup(interfacer);

                RegisterRawAgent(curAgent);
            }
            return(curAgent);
        }
Exemple #4
0
        public LSAgent CreateAgent(
            string agentCode,
            Vector2d?position = null,  //nullable position
            Vector2d?rotation = null   //Nullable rotation for default parametrz
            )
        {
            Vector2d pos = position != null ? position.Value : new Vector2d(0, 0);
            Vector2d rot = rotation != null ? rotation.Value : Vector2d.radian0;


            if (!IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }


            FastStack <LSAgent> cache    = CachedAgents [agentCode];
            LSAgent             curAgent = null;

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();
            }
            else
            {
                IAgentData interfacer = AgentController.CodeInterfacerMap [agentCode];

                curAgent = GameObject.Instantiate(interfacer.GetAgent().gameObject).GetComponent <LSAgent>();
                curAgent.Setup(interfacer);
            }
            InitializeAgent(curAgent, pos, rot);
            return(curAgent);
        }
        public LSAgent CreateAgent(AgentCode agentCode,
                                   Vector2d position = default(Vector2d))
        {
            Vector2d vec = new Vector2d(0, 1);

            if (Enum.IsDefined(typeof(AgentCode), agentCode) == false)
            {
                throw new System.MissingMemberException("Specified AgentCode does not exist.");
            }
            FastStack <LSAgent> cache    = CachedAgents[agentCode];
            LSAgent             curAgent = null;

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();
            }
            else
            {
                AgentInterfacer interfacer = AgentController.CodeInterfacerMap[agentCode];
                curAgent = GameObject.Instantiate(AgentController.CodeInterfacerMap[agentCode].Prefab).GetComponent <LSAgent>();
                curAgent.Setup(interfacer);
            }
            InitializeAgent(curAgent, position);
            return(curAgent);
        }
Exemple #6
0
 private void Initialize()
 {
     innerArray      = new T[Capacity];
     OpenSlots       = new FastStack <int> (Capacity);
     arrayAllocation = 0;
     Count           = 0;
     PeakCount       = 0;
 }
        public LSAgent CreateAgent(
            string agentCode,
            Vector2d?position = null,  //nullable position
            Vector2d?rotation = null   //Nullable rotation for default parametrz
            )
        {
            Vector2d pos = position != null ? position.Value : new Vector2d(0, 0);
            Vector2d rot = rotation != null ? rotation.Value : Vector2d.radian0;


            if (!IsValidAgentCode(agentCode))
            {
                throw new System.ArgumentException(string.Format("Agent code '{0}' not found.", agentCode));
            }


            FastStack <LSAgent> cache    = CachedAgents [agentCode];
            LSAgent             curAgent = null;
            ushort agentCodeID           = AgentController.GetAgentCodeIndex(agentCode);

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();

                TypeAgentsActive[agentCodeID][curAgent.TypeIndex] = true;
            }
            else
            {
                IAgentData interfacer = AgentController.CodeInterfacerMap [agentCode];

                curAgent = GameObject.Instantiate(interfacer.GetAgent().gameObject).GetComponent <LSAgent>();
                curAgent.Setup(interfacer);


                FastList <bool> typeActive;
                if (!AgentController.TypeAgentsActive.TryGetValue(agentCodeID, out typeActive))
                {
                    typeActive = new FastList <bool>();
                    TypeAgentsActive.Add(agentCodeID, typeActive);
                }
                FastList <LSAgent> typeAgents;
                if (!TypeAgents.TryGetValue(agentCodeID, out typeAgents))
                {
                    typeAgents = new FastList <LSAgent>();
                    TypeAgents.Add(agentCodeID, typeAgents);
                }

                curAgent.TypeIndex = (ushort)typeAgents.Count;
                typeAgents.Add(curAgent);
                typeActive.Add(true);
            }
            InitializeAgent(curAgent, pos, rot);
            return(curAgent);
        }
Exemple #8
0
        private static LSProjectile RawCreate(string projCode)
        {
            FastStack <LSProjectile> pool = ProjectilePool[projCode];

            if (pool.Count > 0)
            {
                curProj = pool.Pop();
            }
            else
            {
                curProj = NewProjectile(projCode);
            }
            return(curProj);
        }
Exemple #9
0
        private static LSProjectile RawCreate(string projCode)
        {
            if (ProjectilePool.ContainsKey(projCode) == false)
            {
                Debug.Log(projCode + " Caused boom");
                return(null);
            }
            FastStack <LSProjectile> pool = ProjectilePool[projCode];

            if (pool.Count > 0)
            {
                curProj = pool.Pop();
            }
            else
            {
                curProj = NewProjectile(projCode);
            }
            return(curProj);
        }
        public static LSProjectile Create(string projCode, LSAgent source, LSAgent target, long damage)
        {
            FastStack <LSProjectile> pool = ProjectilePool[projCode];

            if (pool.Count > 0)
            {
                curProj = pool.Pop();
            }
            else
            {
                curProj = NewProjectile(projCode);
            }
            int id = GenerateID();

            ProjectileBucket[id] = curProj;
            ProjectileActive[id] = true;
            curProj.Initialize(id, source, target);
            curProj.Damage = damage;
            return(curProj);
        }
        public LSAgent CreateAgent(string agentCode,
                                   Vector2d position = default(Vector2d))
        {
            Vector2d vec = new Vector2d(0, 1);

            FastStack <LSAgent> cache    = CachedAgents[agentCode];
            LSAgent             curAgent = null;

            if (cache.IsNotNull() && cache.Count > 0)
            {
                curAgent = cache.Pop();
            }
            else
            {
                AgentInterfacer interfacer = AgentController.CodeInterfacerMap[agentCode];
                curAgent = GameObject.Instantiate(AgentController.CodeInterfacerMap[agentCode].Prefab).GetComponent <LSAgent>();
                curAgent.Setup(interfacer);
            }
            InitializeAgent(curAgent, position);
            return(curAgent);
        }
Exemple #12
0
        public static LSProjectile Create(ProjectileCode projCode, LSAgent source, LSAgent target, long damage)
        {
            if (Enum.IsDefined(typeof(ProjectileCode), projCode) == false)
            {
                throw new System.MissingMemberException("The specified ProjectileCode does not exist");
            }
            FastStack <LSProjectile> pool = ProjectilePool[projCode];

            if (pool.Count > 0)
            {
                curProj = pool.Pop();
            }
            else
            {
                curProj = NewProjectile(projCode);
            }
            int id = GenerateID();

            ProjectileBucket[id] = curProj;
            ProjectileActive[id] = true;
            curProj.Initialize(id, source, target);
            curProj.Damage = damage;
            return(curProj);
        }