Beispiel #1
0
        public override void MoveVisitors(int currentTick)
        {
            foreach (var connectionTuple in _connectionMatcherGroup.MatchingEntities)
            {
                var exitNode = connectionTuple.Component2.ExitPositions.Single();

                foreach (var visitorId in connectionTuple.Component3.Values.ToArray())
                {
                    if (VisitorMatcherGroup.TryGetMatchingEntity(visitorId, out var visitorTuple))
                    {
                        var nextPosition = visitorTuple.Component1.PositionDecimal + (_movementSpeedSystem.GetMovementSpeed(visitorTuple.Component3) / connectionTuple.Component4.Value);

                        if (nextPosition >= exitNode.Value)
                        {
                            // overflow disabled to prevent transitioning around the system when entering behind the junction
                            var overflow = 0;                             //Math.Max((int)nextPosition - exitNode.Value, 0);

                            RemoveVisitorFromNode(connectionTuple.Entity.Id, connectionTuple.Component3, visitorTuple.Entity, visitorTuple.Component2);

                            OnVisitorTransition(exitNode.Key, visitorId, connectionTuple.Entity.Id, overflow, currentTick);
                        }
                        else
                        {
                            visitorTuple.Component1.SetPosition(nextPosition, currentTick);
                            visitorTuple.Component2.Tick();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public override void AddVisitorToNode(int nodeId, int visitorId, int sourceId, int initialPosition, int currentTick)
        {
            if (_subsystemMatcherGroup.TryGetMatchingEntity(nodeId, out var subsystemTuple))
            {
                // determine entrance position
                var direction = subsystemTuple.Component2.EntrancePositions.ContainsKey(sourceId)
                                        ? subsystemTuple.Component2.EntrancePositions[sourceId].FromPosition(SimulationConstants.SubsystemPositions)
                                        : EdgeDirection.North;

                var position = direction.ToPosition(SimulationConstants.SubsystemPositions) + initialPosition;

                AddVisitor(nodeId, subsystemTuple.Component3, visitorId, position, currentTick);

                if (VisitorMatcherGroup.TryGetMatchingEntity(visitorId, out var visitorTuple) &&
                    visitorTuple.Component4.Value.HasValue)
                {
                    if (visitorTuple.Component4.Value == nodeId)
                    {
                        visitorTuple.Component4.Value = null;
                    }
                }
            }
        }
Beispiel #3
0
        public override void MoveVisitors(int currentTick)
        {
            foreach (var subsystemTuple in _subsystemMatcherGroup.MatchingEntities)
            {
                foreach (var visitorId in subsystemTuple.Component3.Values.ToArray())
                {
                    if (VisitorMatcherGroup.TryGetMatchingEntity(visitorId, out var visitorTuple))
                    {
                        int?exitNode = null;

                        #region movement intent handling

                        // TODO: extract this into the intent system?

                        if (visitorTuple.Component4.Value.HasValue)
                        {
                            if (visitorTuple.Component4.Value.Value == subsystemTuple.Entity.Id)
                            {
                                visitorTuple.Component4.Value = null;
                            }
                            else
                            {
                                exitNode = subsystemTuple.Component4[visitorTuple.Component4.Value.Value];
                            }
                        }

                        #endregion

                        var nextPosition = (visitorTuple.Component1.PositionDecimal + _movementSpeedSystem.GetMovementSpeed(visitorTuple.Component3) / Math.Max(1, subsystemTuple.Component5.Value)) % SimulationConstants.SubsystemPositions;

                        if (exitNode != null)
                        {
                            var exitPosition          = subsystemTuple.Component2.ExitPositions[exitNode.Value];
                            var exitAfterTop          = exitPosition < visitorTuple.Component1.Position;
                            var nextPositionAfterTop  = nextPosition < visitorTuple.Component1.Position;
                            var nextPositionAfterExit = nextPosition > exitPosition;

                            if (visitorTuple.Component1.Position == exitPosition ||
                                (exitAfterTop && nextPositionAfterTop && nextPositionAfterExit) ||
                                (exitAfterTop == false & nextPositionAfterExit))
                            {
                                var overflow = 0;                                 // Math.Max((int)nextPosition - exitPosition, 0);

                                RemoveVisitorFromNode(subsystemTuple.Entity.Id, subsystemTuple.Component3, visitorTuple.Entity, visitorTuple.Component2);

                                //exitNode.GetComponent<IMovementSystemExtension>().AddVisitor(visitor, Entity, overflow, currentTick);
                                OnVisitorTransition(exitNode.Value, visitorId, subsystemTuple.Entity.Id, overflow, currentTick);
                                //TODO move to a better place
                                _movementSpeedSystem.LeaveSystem(visitorId);
                            }
                            else
                            {
                                visitorTuple.Component1.SetPosition(nextPosition, currentTick);
                                visitorTuple.Component2.Tick();
                            }
                        }
                        else
                        {
                            visitorTuple.Component1.SetPosition(nextPosition, currentTick);
                            visitorTuple.Component2.Tick();
                        }
                    }
                }
            }
        }