コード例 #1
0
 public static LSAgent GetScreenAgent(Vector2 screenPos, Func<LSAgent, bool> conditional = null)
 {
     if (conditional == null)
         conditional = (agent) => {
             return true;};
     agentFound = false;
     Ray ray = Camera.main.ScreenPointToRay (screenPos);
     checkDir = ray.direction;
     checkOrigin = ray.origin;
     for (int i = 0; i < AgentController.PeakGlobalID; i++) {
         if (AgentController.GlobalAgentActive [i]) {
             LSAgent agent = AgentController.GlobalAgents [i];
             if (agent.IsVisible) {
                 if (conditional (agent)) {
                     if (AgentIntersects (agent)) {
                         if (agentFound) {
                             if (heightDif < closestDistance) {
                                 closestDistance = heightDif;
                                 closestAgent = agent;
                             }
                         } else {
                             agentFound = true;
                             closestAgent = agent;
                             closestDistance = heightDif;
                         }
                     }
                 }
             }
         }
     }
     if (agentFound)
         return closestAgent;
     return null;
 }
コード例 #2
0
        public void ScanAll(int deltaCount, FastList<LSAgent> outputAgents,
		                      bool CheckAllegiance = false,
		                      AllegianceType allegianceType = AllegianceType.Neutral)
        {
            for (i = 0; i < deltaCount; i++) {
                tempNode = GridManager.GetNode (
                    LocatedNode.gridX + DeltaCache.CacheX[i],
                    LocatedNode.gridY + DeltaCache.CacheY[i]);

                if (tempNode != null && tempNode.LocatedAgents != null) {
                    tempBucket = tempNode.LocatedAgents;
                    for (j = 0; j < tempBucket.PeakCount; j++) {
                        if (LSUtility.GetBitTrue (tempBucket.arrayAllocation, j)) {
                            tempAgent = tempBucket.innerArray [j].Agent;
                            if (System.Object.ReferenceEquals (tempAgent, Agent) == false) {
                                if (CheckAllegiance)
                                {
                                    if (Agent.MyAgentController.DiplomacyFlags
                                        [tempAgent.MyAgentController.ControllerID] != allegianceType) continue;
                                }
                                outputAgents.Add (tempAgent);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
 public void Initialize(LSAgent agent)
 {
     Agent = agent;
     Body = agent.Body;
     LocatedNode = GridManager.GetNode (Body.Position.x, Body.Position.y);
     LocatedNode.Add (this);
 }
コード例 #4
0
 public override void Initialize(LSAgent agent)
 {
     Body = agent.Body;
     timescaledTurnRate = TurnRate * LockstepManager.Timestep >> FixedMath.SHIFT_AMOUNT;
     TargetReached = true;
     TargetRotation = Vector2d.up;
 }
コード例 #5
0
 public static void BoxAgent(LSAgent agent)
 {
     if (System.Object.ReferenceEquals (agent, null))
         return;
     BoxedAgents.Add (agent);
     agent.IsHighlighted = true;
 }
コード例 #6
0
 public static void BoxAgent(LSAgent agent)
 {
     if (agent == null)
         return;
     BoxedAgents.Add (agent);
     agent.IsHighlighted = true;
 }
コード例 #7
0
    void Start()
    {
        LockstepManager.Initialize ();
        GridManager.Generate ();
        const int count = 32;

        for (int i = -count; i < count; i++)
        {
            for (int j = -count; j < count; j++)
            {
                if (i * i + j * j < 16) continue;
                if (LSUtility.GetRandom (2) == 0)
                {
                    Vector2d pos = new Vector2d(i,j);
                    GridManager.GetNode(pos.x,pos.y).Unwalkable = true;
                    Instantiate(TestWall).GetComponent<LSBody>().Initialize(pos);
                }
            }
        }

        /*LSBody wall = Instantiate (TestWall).GetComponent<LSBody> ();
        wall.Initialize (new Vector2d (-32 + 14, 0));
        for (long i = wall.XMin; i <= wall.XMax; i+= FixedMath.One) {
            for (long j = wall.YMin; j <= wall.YMax; j+= FixedMath.One) {
                GridManager.GetNode (i, j).Unwalkable = true;
            }
        }*/

        GridManager.Initialize ();
        controller = AgentController.Create ();
        for (int i = 0; i < 256; i++) {
            agent = controller.CreateAgent (AgentCode.Minion);
        }
        PlayerManager.AddAgentController (controller);
    }
コード例 #8
0
		public static void Remove (LSAgent agent)
		{
			leIndex = agent.BoxedAgentsIndex;
			agent.BoxedAgentsIndex = -1;
			OpenSlots.Add (leIndex);
			arrayAllocated[leIndex] = false;
			Count--;
		}
コード例 #9
0
 public void Setup(LSAgent agent)
 {
     cachedRenderer = GetComponent<Renderer>();
     cachedMaterial = cachedRenderer.material;
     transform.parent = agent.VisualCenter;
     transform.localPosition = Vector3.zero;
     float size = agent.SelectionRadius * 2;
     transform.localScale = new Vector3(size,size,1);
 }
コード例 #10
0
ファイル: Move.cs プロジェクト: B1sounours/Lockstep-Framework
    public override void Initialize(LSAgent agent)
    {
        MyMovementGroupID = -1;

        Body = agent.Body;
        Body.Mover = this;
        Body.OnContact += HandleCollision;

        timescaledSpeed = ((Speed * LockstepManager.Timestep) >> FixedMath.SHIFT_AMOUNT);
        closingDistance = agent.Body.Radius;
    }
コード例 #11
0
 public void Initialize(LSAgent agent)
 {
     if (this.renderer == null)
         this.renderer = base.GetComponent<Renderer>();
     material = this.renderer.material;
     if (this.transform == null)
         this.transform = base.GetComponent<Transform> ();
     float scale = agent.SelectionRadius * 2;
     transform.localScale = new Vector3(scale,scale,scale);
     material.color = UnselectColor;
     Agent = agent;
 }
コード例 #12
0
		public static void Add (LSAgent agent)
		{
			if (OpenSlots.Count > 0)
			{
				leIndex = OpenSlots.Pop ();
			}
			else {
				leIndex = PeakCount++;
			}
			agent.BoxedAgentsIndex = leIndex;
			innerArray[leIndex] = agent;
			arrayAllocated[leIndex] = true;
			Count++;
		}
コード例 #13
0
 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;
 }
コード例 #14
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;
 }
コード例 #15
0
        public static LSAgent Scan(int gridX, int gridY, int deltaCount,
		                     Func<LSAgent,bool> conditional, long sourceX, long sourceY)
        {
            agentFound = false;
            for (int i = 0; i < deltaCount; i++) {
                tempNode = GridManager.GetScanNode (
                    gridX + DeltaCache.CacheX [i],
                    gridY + DeltaCache.CacheY [i]);

                if (tempNode .IsNotNull () && tempNode.LocatedAgents .IsNotNull ()) {
                    tempBucket = tempNode.LocatedAgents;
                    arrayAllocation = tempBucket.arrayAllocation;
                    for (int j = 0; j < tempBucket.PeakCount; j++) {
                        if (arrayAllocation.Get (j)) {
                            tempAgent = tempBucket [j];
                            if (conditional (tempAgent)) {
                                if (agentFound) {
                                    if ((tempDistance = tempAgent.Body.Position.FastDistance (sourceX, sourceY)) < closestDistance) {
                                        secondClosest = closestAgent;
                                        closestAgent = tempAgent;
                                        closestDistance = tempDistance;
                                    }
                                } else {
                                    closestAgent = tempAgent;
                                    agentFound = true;
                                    closestDistance = tempAgent.Body.Position.FastDistance (sourceX, sourceY);
                                }
                            }
                        }
                    }
                    if (agentFound) {
                        return closestAgent;
                    }
                }
            }
            return null;
        }
コード例 #16
0
        private static bool ScanConditionalSource(LSAgent agent)
        {
            if (System.Object.ReferenceEquals(agent, Source))
            {
                return(false);
            }

            if (TargetAllegiance != AllegianceType.Any)
            {
                if (Source.GetAllegiance(agent) != TargetAllegiance)
                {
                    return(false);
                }
            }
            if (TargetPlatform != PlatformType.Any)
            {
                if (agent.Platform != agent.Platform)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #17
0
        public void Engage(LSAgent other)
        {
            if (other != Agent && other != null)
            {
                cachedTargetHealth = other.GetAbility <Health>();
                if (cachedTargetHealth.IsNotNull())
                {
                    OnEngage(other);
                    Target             = other;
                    targetVersion      = Target.SpawnVersion;
                    IsCasting          = true;
                    fastRangeToTarget  = Range + (Target.Body.IsNotNull() ? Target.Body.Radius : 0) + Agent.Body.Radius;
                    fastRangeToTarget *= fastRangeToTarget;

                    if (!CheckRange())
                    {
                        if (CanMove)
                        {
                            cachedMove.StartMove(Target.Body.Position);
                        }
                    }
                }
            }
        }
コード例 #18
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);
        }
コード例 #19
0
        public static LSAgent FindClosestAgent(Vector2d position, IEnumerable <LSAgent> agents)
        {
            long    sourceX         = position.x;
            long    sourceY         = position.y;
            LSAgent closestAgent    = null;
            long    closestDistance = 0;
            int     foundBuffer     = FoundScanBuffer;

            foreach (LSAgent agent in agents)
            {
                if (FoundScanBuffer == 0)
                {
                    break;
                }
                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);
        }
コード例 #20
0
        private static void DestroyAgentBuffer(DeactivationData data)
        {
            LSAgent 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))
                {
                    TypeAgentsActive[agentCodeID][agent.TypeIndex] = false;
                }
            }
        }
コード例 #21
0
        public static void ChangeController(LSAgent agent, AgentController newCont)
        {
            AgentController leController = agent.Controller;

            if (leController != null)
            {
                leController.LocalAgentActive[agent.LocalID] = false;
                GlobalAgentActive[agent.GlobalID]            = false;
                leController.OpenLocalIDs.Add(agent.LocalID);
                OpenGlobalIDs.Add(agent.GlobalID);

                if (newCont == null)
                {
                    agent.InitializeController(null, 0, 0);
                }
                else
                {
                    agent.Influencer.Deactivate();

                    newCont.AddAgent(agent);
                    agent.Influencer.Initialize();
                }
            }
        }
コード例 #22
0
        public static int GetStateHash()
        {
            int operationToggle = 0;
            int hash            = LSUtility.PeekRandom(int.MaxValue);

            for (int i = 0; i < PeakGlobalID; i++)
            {
                if (GlobalAgentActive[i])
                {
                    LSAgent agent = GlobalAgents[i];
                    int     n1    = agent.Body._position.GetHashCode() + agent.Body._rotation.GetStateHash();
                    switch (operationToggle)
                    {
                    case 0:
                        hash ^= n1;
                        break;

                    case 1:
                        hash += n1;
                        break;

                    default:
                        hash ^= n1 * 3;
                        break;
                    }
                    operationToggle++;
                    if (operationToggle >= 2)
                    {
                        operationToggle = 0;
                    }
                }
            }


            return(hash);
        }
コード例 #23
0
        public static void Update()
        {
            MousePosition = Input.mousePosition;
            MouseWorldPosition = Interfacing.GetWorldPos (MousePosition);
            CanClearSelection = !Input.GetKey (KeyCode.LeftShift);
            GetMousedAgent ();

            if (Boxing) {
                BoxingTime += Time.deltaTime;
                if (MousePosition != BoxEnd) {
                    Vector2 RaycastTopLeft;
                    Vector2 RaycastTopRight;
                    Vector2 RaycastBotLeft;
                    Vector2 RaycastBotRight;

                    BoxEnd = MousePosition;
                    if (BoxStart.x < BoxEnd.x) {
                        RaycastTopLeft.x = BoxStart.x;
                        RaycastBotLeft.x = BoxStart.x;
                        RaycastTopRight.x = BoxEnd.x;
                        RaycastBotRight.x = BoxEnd.x;
                    } else {
                        RaycastTopLeft.x = BoxEnd.x;
                        RaycastBotLeft.x = BoxEnd.x;
                        RaycastTopRight.x = BoxStart.x;
                        RaycastBotRight.x = BoxStart.x;
                    }
                    if (BoxStart.y < BoxEnd.y) {
                        RaycastBotLeft.y = BoxStart.y;
                        RaycastBotRight.y = BoxStart.y;
                        RaycastTopLeft.y = BoxEnd.y;
                        RaycastTopRight.y = BoxEnd.y;
                    } else {
                        RaycastBotLeft.y = BoxEnd.y;
                        RaycastBotRight.y = BoxEnd.y;
                        RaycastTopLeft.y = BoxStart.y;
                        RaycastTopRight.y = BoxStart.y;
                    }

                    Box_TopLeft = Interfacing.GetWorldPos (RaycastTopLeft);
                    Box_TopRight = Interfacing.GetWorldPos (RaycastTopRight);
                    Box_BottomLeft = Interfacing.GetWorldPos (RaycastBotLeft);
                    Box_BottomRight = Interfacing.GetWorldPos (RaycastBotRight);
                }

                ClearBox ();
                int lecount = 0;
                if ((BoxEnd - BoxStart).sqrMagnitude >= MinBoxSqrDist) {
                    bufferBoxedAgents.Clear ();
                    for (int i = 0; i < PlayerManager.AgentControllerCount; i++) {
                        var agentController = PlayerManager.GetAgentController (i);
                        for (int j = 0; j < AgentController.MaxAgents; j++) {
                            if (agentController.LocalAgentActive [j]) {
                                curAgent = agentController.LocalAgents [j];
                                if (curAgent.CanSelect) {
                                    if (curAgent.RefEquals (MousedAgent)) {
                                        bufferBoxedAgents.Add (curAgent);
                                    } else {
                                        agentPos = curAgent.Position2;
                                        Edge = Box_TopRight - Box_TopLeft;
                                        Point = agentPos - Box_TopLeft;
                                        if (DotEdge () < 0) {
                                            Edge = Box_BottomRight - Box_TopRight;
                                            Point = agentPos - Box_TopRight;
                                            if (DotEdge () < 0) {
                                                Edge = Box_BottomLeft - Box_BottomRight;
                                                Point = agentPos - Box_BottomRight;
                                                if (DotEdge () < 0) {
                                                    Edge = Box_TopLeft - Box_BottomLeft;
                                                    Point = agentPos - Box_BottomLeft;
                                                    if (DotEdge () < 0) {
                                                        bufferBoxedAgents.Add (curAgent);
                                                        continue;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                    bufferBoxable.FastClear ();
                    bool noneBoxable = true;
                    if (bufferBoxedAgents.Count > 0) {
                        int peakBoxPriority = bufferBoxedAgents.PeekMax ().BoxPriority;
                        while (bufferBoxedAgents.Count > 0) {
                            LSAgent agent = bufferBoxedAgents.PopMax ();
                            if (agent.BoxPriority < peakBoxPriority) break;
                            BoxAgent (agent);
                        }
                    }

                } else {
                    BoxAgent (MousedAgent);
                }

                if (Input.GetMouseButtonUp (0)) {

                    if (CanClearSelection) {
                        ClearSelection ();
                    }
                    if (PlayerManager.IsInterfacing == false) {
                        SelectBoxedAgents ();
                    }

                    Boxing = false;
                }

            } else {

                if (PlayerManager.IsInterfacing == false && InputManager.GetInformationDown ()) {
                    CheckBoxDistance = true;
                    Boxing = true;
                    BoxingTime = 0f;
                    BoxStart = MousePosition;
                    BoxEnd = MousePosition;
                }

            }
        }
コード例 #24
0
 public static void SelectAgent(LSAgent agent)
 {
     if (agent .IsNotNull ()) {
         agent.IsSelected = true;
         Selector.Add (agent);
     }
 }
コード例 #25
0
 public void InitializeTimed(LSAgent target)
 {
     this.Target        = target;
     this.TargetVersion = this.Target.SpawnVersion;
 }
コード例 #26
0
 public static AllegianceType GetAllegiance(LSAgent agent)
 {
     return(PlayerManager.GetAllegiance(agent.Controller));
 }
コード例 #27
0
 public void AddToSelection(LSAgent agent)
 {
     SelectedAgents.Add(agent);
     SelectionChanged = true;
 }
コード例 #28
0
        private void HandleCollision(LSBody other)
        {
            if (!CanMove)
            {
                return;
            }
            if ((tempAgent = other.Agent) == null)
            {
                return;
            }

            Move otherMover = tempAgent.GetAbility <Move>();

            if (ReferenceEquals(otherMover, null) == false)
            {
                if (IsMoving)
                {
                    //If the other mover is moving to a similar point
                    if (otherMover.MyMovementGroupID == MyMovementGroupID || otherMover.targetPos.FastDistance(this.targetPos) <= (closingDistance * closingDistance))
                    {
                        if (otherMover.IsMoving == false)
                        {
                            if (otherMover.Arrived && otherMover.StoppedTime > MinimumOtherStopTime)
                            {
                                Arrive();
                            }
                        }
                        else
                        {
                            if (hasPath && otherMover.hasPath && otherMover.pathIndex > 0 && otherMover.lastTargetPos.SqrDistance(targetPos.x, targetPos.y) < closingDistance.Mul(closingDistance))
                            {
                                if (this.distance < this.closingDistance)
                                {
                                    this.pathIndex++;
                                }
                            }
                        }
                    }

                    if (GetLookingForStopPause())
                    {
                        //As soon as the original collision stop unit is released, units will start breaking out of pauses
                        if (otherMover.GetCanCollisionStop() == false)
                        {
                            StopPauseLayer = -1;
                            PauseAutoStop();
                        }
                        else if (otherMover.GetCanAutoStop() == false)
                        {
                            if (otherMover.StopPauseLayer < StopPauseLayer)
                            {
                                StopPauseLayer = otherMover.StopPauseLayer + 1;
                                PauseAutoStop();
                            }
                        }
                    }
                    else
                    {
                    }
                }
            }
        }
コード例 #29
0
        public LSProjectile PrepareProjectile(string projectileCode, Vector3d projOffset, LSAgent target)
        {
            LSProjectile currentProjectile = ProjectileManager.Create(
                projectileCode,
                this.Agent,
                projOffset,
                this.TargetAllegiance,
                (other) =>
            {
                Health healther = other.GetAbility <Health>();
                return(healther.IsNotNull() && healther.HealthAmount > 0);
            },
                CachedOnHit);

            switch (currentProjectile.TargetingBehavior)
            {
            case TargetingType.Homing:
                currentProjectile.InitializeHoming(target);
                break;

            case TargetingType.Timed:
                currentProjectile.InitializeTimed(Agent.Body.Forward);
                break;

            case TargetingType.Positional:
                currentProjectile.InitializePositional(target.Body.Position.ToVector3d(target.Body.HeightPos));
                break;

            case TargetingType.Free:
                //TODO
                throw new System.Exception("Not implemented yet.");
                //break;
            }
            OnPrepareProjectile(currentProjectile);
            return(currentProjectile);
        }
コード例 #30
0
 public AllegianceType GetAllegiance(LSAgent other)
 {
     return(Controller.GetAllegiance(other.Controller));
 }
コード例 #31
0
 protected virtual void OnApplyEffect(LSAgent agent)
 {
 }
コード例 #32
0
 protected virtual void ApplyEffect(LSAgent agent)
 {
     OnApplyEffect(agent);
 }
コード例 #33
0
 private void OnChildDie(LSAgent agent)
 {
     agent.onDeactivation -= OnChildDie;
     //Occupied = false;
 }
コード例 #34
0
 protected virtual bool AgentValid(LSAgent agent)
 {
     return(true);
 }
コード例 #35
0
 public static void Add(LSAgent agent)
 {
     innerArray[Count++] = agent;
     agent.BoxVersion    = _Version;
 }
コード例 #36
0
 public bool AllButFriendly(LSAgent other)
 {
     return(this.Source.GetAllegiance(other) != AllegianceType.Friendly);
 }
コード例 #37
0
 public static void CacheAgent(LSAgent agent)
 {
     CachedAgents [agent.MyAgentCode].Add(agent);
 }
コード例 #38
0
 public void DestroyAgent(LSAgent agent)
 {
     agent.Deactivate ();
     CachedAgents[(int)agent.MyAgentCode].Add (agent);
     OpenLocalIDs.Add (agent.LocalID);
     AgentActive[agent.LocalID] = false;
 }
コード例 #39
0
 public void RemoveFromSelection(LSAgent agent)
 {
     SelectedAgents.Remove(agent);
     SelectionChanged = true;
 }
コード例 #40
0
 public void Setup(LSAgent agent)
 {
     Agent = agent;
     Body  = agent.Body;
 }
コード例 #41
0
        public static void Update()
        {
            MousePosition      = Input.mousePosition;
            MouseWorldPosition = RTSInterfacing.GetWorldPos(MousePosition);
            CanClearSelection  = !Input.GetKey(KeyCode.LeftShift);
            GetMousedAgent();
            if (Boxing)
            {
                if (CanBox)
                {
                    BoxingTime += Time.deltaTime;
                    if (MousePosition != BoxEnd)
                    {
                        Vector2 RaycastTopLeft;
                        Vector2 RaycastTopRight;
                        Vector2 RaycastBotLeft;
                        Vector2 RaycastBotRight;

                        BoxEnd = MousePosition;
                        if (BoxStart.x < BoxEnd.x)
                        {
                            RaycastTopLeft.x  = BoxStart.x;
                            RaycastBotLeft.x  = BoxStart.x;
                            RaycastTopRight.x = BoxEnd.x;
                            RaycastBotRight.x = BoxEnd.x;
                        }
                        else
                        {
                            RaycastTopLeft.x  = BoxEnd.x;
                            RaycastBotLeft.x  = BoxEnd.x;
                            RaycastTopRight.x = BoxStart.x;
                            RaycastBotRight.x = BoxStart.x;
                        }
                        if (BoxStart.y < BoxEnd.y)
                        {
                            RaycastBotLeft.y  = BoxStart.y;
                            RaycastBotRight.y = BoxStart.y;
                            RaycastTopLeft.y  = BoxEnd.y;
                            RaycastTopRight.y = BoxEnd.y;
                        }
                        else
                        {
                            RaycastBotLeft.y  = BoxEnd.y;
                            RaycastBotRight.y = BoxEnd.y;
                            RaycastTopLeft.y  = BoxStart.y;
                            RaycastTopRight.y = BoxStart.y;
                        }
                        Box_TopLeft     = RTSInterfacing.GetWorldPos(RaycastTopLeft);
                        Box_TopRight    = RTSInterfacing.GetWorldPos(RaycastTopRight);
                        Box_BottomLeft  = RTSInterfacing.GetWorldPos(RaycastBotLeft);
                        Box_BottomRight = RTSInterfacing.GetWorldPos(RaycastBotRight);
                    }
                    ClearBox();
                    //int lecount = 0;
                    if ((BoxEnd - BoxStart).sqrMagnitude >= MinBoxSqrDist)
                    {
                        bufferBoxedAgents.Clear();
                        for (int i = 0; i < PlayerManager.AgentControllerCount; i++)
                        {
                            var agentController = PlayerManager.GetAgentController(i);
                            for (int j = 0; j < AgentController.MaxAgents; j++)
                            {
                                if (agentController.LocalAgentActive[j])
                                {
                                    curAgent = agentController.LocalAgents[j];
                                    if (curAgent.CanSelect)
                                    {
                                        if (curAgent.RefEquals(MousedAgent))
                                        {
                                            bufferBoxedAgents.Add(curAgent);
                                        }
                                        else
                                        {
                                            agentPos = curAgent.Position2;
                                            Edge     = Box_TopRight - Box_TopLeft;
                                            Point    = agentPos - Box_TopLeft;
                                            if (DotEdge() < 0)
                                            {
                                                Edge  = Box_BottomRight - Box_TopRight;
                                                Point = agentPos - Box_TopRight;
                                                if (DotEdge() < 0)
                                                {
                                                    Edge  = Box_BottomLeft - Box_BottomRight;
                                                    Point = agentPos - Box_BottomRight;
                                                    if (DotEdge() < 0)
                                                    {
                                                        Edge  = Box_TopLeft - Box_BottomLeft;
                                                        Point = agentPos - Box_BottomLeft;
                                                        if (DotEdge() < 0)
                                                        {
                                                            bufferBoxedAgents.Add(curAgent);
                                                            continue;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        bufferBoxable.FastClear();
                        //bool noneBoxable = true;
                        if (bufferBoxedAgents.Count > 0)
                        {
                            int peakBoxPriority = bufferBoxedAgents.PeekMax().BoxPriority;
                            while (bufferBoxedAgents.Count > 0)
                            {
                                LSAgent agent = bufferBoxedAgents.PopMax();
                                if (agent.BoxPriority < peakBoxPriority)
                                {
                                    break;
                                }
                                BoxAgent(agent);
                            }
                        }
                    }
                    else
                    {
                        BoxAgent(MousedAgent);
                    }
                }
                if (Input.GetMouseButtonUp(0))
                {
                    if (CanClearSelection)
                    {
                        ClearSelection();
                    }
                    if (IsGathering == false)
                    {
                        SelectBoxedAgents();
                    }

                    Boxing = false;
                }
            }
            else
            {
                if (IsGathering == false && Input.GetMouseButtonDown(0))
                {
                    _checkBoxDistance = true;
                    StartBoxing(MousePosition);
                }
            }
        }
コード例 #42
0
 private static void GetMousedAgent()
 {
     for (i = 0; i < AgentController.InstanceManagers.Count; i++) {
         AgentController agentController = AgentController.InstanceManagers [i];
         for (j = 0; j < AgentController.MaxAgents; j++) {
             if (agentController.AgentActive [j]) {
                 curAgent = agentController.Agents [j];
                 if (curAgent.cachedRenderer.isVisible) {
                     dif = new Vector2 (
                         curAgent.transform.position.x - MouseWorldPosition.x,
                         curAgent.transform.position.z - MouseWorldPosition.y);
                     if ((dif.x * dif.x + dif.y * dif.y) <= (curAgent.SelectionRadius * curAgent.SelectionRadius)) {
                         MouseOver (curAgent);
                         return;
                     }
                 }
             }
         }
     }
     if (System.Object.ReferenceEquals (MousedAgent, null)==false) {
         MousedAgent.IsHighlighted = false;
         MousedAgent = null;
     }
 }
コード例 #43
0
    public override void Initialize(LSAgent agent)
    {
        MyMovementGroupID = -1;

        Body = agent.Body;
        Body.Mover = this;
        Body.OnContact += HandleCollision;

        Turner = agent.GetAbility<Turn> ();

        timescaledSpeed = ((Speed * LockstepManager.Timestep) >> FixedMath.SHIFT_AMOUNT);
        closingDistance = agent.Body.Radius;

        RepathCount = LSUtility.GetRandom (RepathRate);
        ViableDestination = false;
    }
コード例 #44
0
 private static void MouseOver(LSAgent agent)
 {
     if (System.Object.ReferenceEquals (MousedAgent,agent))
     {
         return;
     }
     if (System.Object.ReferenceEquals (MousedAgent, null)==false) {
         MousedAgent.IsHighlighted = false;
     }
     MousedAgent = agent;
     agent.IsHighlighted = true;
 }
コード例 #45
0
 public static void UnselectAgent(LSAgent agent)
 {
     if (agent .IsNotNull ()) {
         agent.IsSelected = false;
         Selector.Remove (agent);
     }
 }
コード例 #46
0
 public DeactivationData(LSAgent agent, bool immediate)
 {
     Agent     = agent;
     Immediate = immediate;
 }
コード例 #47
0
        private static void MouseOver(LSAgent agent)
        {
            if (MousedAgent.RefEquals (agent)) {
                return;
            }

            if (MousedAgent .IsNotNull ()) {
                MousedAgent.IsHighlighted = false;
            }

            MousedAgent = agent;

            if (agent .IsNotNull ()) {
                if (SelectionManager.Boxing == false)

                agent.IsHighlighted = true;
            }
        }
コード例 #48
0
 public static void DestroyAgent(LSAgent agent, bool immediate = false)
 {
     DeactivationBuffer.Add(new DeactivationData(agent, immediate));
 }
コード例 #49
0
 public override void Initialize(LSAgent agent)
 {
 }
コード例 #50
0
 protected virtual void OnApplyEffect(LSAgent agent, bool isCurrent)
 {
 }
コード例 #51
0
        public LSProjectile FullFireProjectile(string projectileCode, Vector3d projOffset, LSAgent target)
        {
            LSProjectile proj = (PrepareProjectile(projectileCode, projOffset, target));

            FireProjectile(proj);
            return(proj);
        }
コード例 #52
0
 public int Add(LSAgent influencer)
 {
     //Weight += weightPerUnit;
     return LinkedScanNode.LocatedAgents.Add(influencer);
 }
コード例 #53
0
 protected virtual void OnEngage(LSAgent target)
 {
 }
コード例 #54
0
 public AttackerInfo(LSAgent attacker, AgentController controller)
 {
     Attacker   = attacker;
     Controller = controller;
 }
コード例 #55
0
		public abstract void Initialize (LSAgent agent);
コード例 #56
0
 public static void SelectAgent(LSAgent agent)
 {
     if (agent == null)
         return;
     SelectedAgents.Add (agent);
     agent.IsSelected = true;
 }
コード例 #57
0
 private void DealDamage(LSAgent agent)
 {
     agent.Healther.TakeProjectile(this);
 }
コード例 #58
0
 public static void UnselectAgent(LSAgent agent)
 {
     if (agent == null)
         return;
     SelectedAgents.Remove (agent);
     agent.IsSelected = false;
 }
コード例 #59
0
        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;
        }
コード例 #60
0
        public static void Update()
        {
            MousePosition = Input.mousePosition;
            MouseWorldPosition = GetWorldPos (MousePosition);
            CanClearSelection = !Input.GetKey (KeyCode.LeftShift);
            GetMousedAgent ();

            if (Boxing) {
                BoxingTime += Time.deltaTime;
                if (MousePosition != BoxEnd) {
                    Vector2 RaycastTopLeft;
                    Vector2 RaycastTopRight;
                    Vector2 RaycastBotLeft;
                    Vector2 RaycastBotRight;

                    BoxEnd = MousePosition;
                    if (BoxStart.x < BoxEnd.x) {
                        RaycastTopLeft.x = BoxStart.x;
                        RaycastBotLeft.x = BoxStart.x;
                        RaycastTopRight.x = BoxEnd.x;
                        RaycastBotRight.x = BoxEnd.x;
                    } else {
                        RaycastTopLeft.x = BoxEnd.x;
                        RaycastBotLeft.x = BoxEnd.x;
                        RaycastTopRight.x = BoxStart.x;
                        RaycastBotRight.x = BoxStart.x;
                    }
                    if (BoxStart.y < BoxEnd.y) {
                        RaycastBotLeft.y = BoxStart.y;
                        RaycastBotRight.y = BoxStart.y;
                        RaycastTopLeft.y = BoxEnd.y;
                        RaycastTopRight.y = BoxEnd.y;
                    } else {
                        RaycastBotLeft.y = BoxEnd.y;
                        RaycastBotRight.y = BoxEnd.y;
                        RaycastTopLeft.y = BoxStart.y;
                        RaycastTopRight.y = BoxStart.y;
                    }

                    Box_TopLeft = GetWorldPos (RaycastTopLeft);
                    Box_TopRight = GetWorldPos (RaycastTopRight);
                    Box_BottomLeft = GetWorldPos (RaycastBotLeft);
                    Box_BottomRight = GetWorldPos (RaycastBotRight);
                }

                ClearBox ();

                int lecount = 0;
                if ((BoxEnd - BoxStart).sqrMagnitude >= MinBoxSqrDist)
                for (i = 0; i < PlayerManager.agentControllers.Count; i++) {
                    AgentController agentController = PlayerManager.agentControllers [i];
                    for (j = 0; j < AgentController.MaxAgents; j++) {
                        if (agentController.AgentActive [j]) {
                            curAgent = agentController.Agents [j];
                            if (curAgent.cachedRenderer.isVisible) {

                                Vector2 agentPos = new Vector2 (curAgent.transform.position.x, curAgent.transform.position.z);
                                Edge = Box_TopRight - Box_TopLeft;
                                Point = agentPos - Box_TopLeft;
                                if (DotEdge () < 0) {
                                    Edge = Box_BottomRight - Box_TopRight;
                                    Point = agentPos - Box_TopRight;
                                    if (DotEdge () < 0) {
                                        Edge = Box_BottomLeft - Box_BottomRight;
                                        Point = agentPos - Box_BottomRight;
                                        if (DotEdge () < 0) {
                                            Edge = Box_TopLeft - Box_BottomLeft;
                                            Point = agentPos - Box_BottomLeft;
                                            if (DotEdge () < 0) {
                                                BoxAgent (curAgent);
                                                continue;
                                            }
                                        }
                                    }
                                }
                            }
                            if (curAgent.BoxVersion == BoxedAgents._BufferVersion)
                            {
                                curAgent.IsHighlighted = false;
                            }
                        }
                    }
                }

                if (Input.GetMouseButtonUp (0)) {

                    if (CanClearSelection) {
                        ClearSelection ();
                    }
                    SelectBoxedAgents ();
                    SelectAgent (MousedAgent);

                    Boxing = false;
                }

            } else {
                if (Input.GetMouseButtonDown (0)) {
                    CheckBoxDistance = true;
                    Boxing = true;
                    BoxingTime = 0f;
                    BoxStart = MousePosition;
                    BoxEnd = MousePosition;
                }
            }
        }