コード例 #1
0
ファイル: Migration.cs プロジェクト: alexturpin/Zombles
        public Migration(Desires.Migration desire, Beliefs beliefs)
            : base(desire, beliefs)
        {
            _destBlock = desire.Destination;

            var size = new Vector2(_destBlock.Width, _destBlock.Height);

            int tries = 16;
            do {
                _destPos = new Vector2(_destBlock.X, _destBlock.Y) + Vector2.Multiply(size, new Vector2(
                    Tools.Random.NextSingle(0.4f, 0.6f),
                    Tools.Random.NextSingle(0.4f, 0.6f)));

                _destPos.X = (float) Math.Round(_destPos.X - 0.5f) + 0.5f;
                _destPos.Y = (float) Math.Round(_destPos.Y - 0.5f) + 0.5f;
            } while (--tries > 0 && !Beliefs.Entity.World.IsPositionNavigable(_destPos));

            if (tries <= 0) {
                _destPos = _destBlock.GetNearestPosition(Entity.Position2D);
                _destPos += (_destBlock.Center - _destPos).Normalized() * 2f;
            }

            _nav = new RouteNavigator(Entity, _destPos);
        }
コード例 #2
0
ファイル: Barricading.cs プロジェクト: alexturpin/Zombles
        public override IEnumerable<Action> GetActions()
        {
            _pendingTiles = _destTiles.Where(x => x.StaticEntities.Count() == 0).ToArray();

            if (ShouldAbandon()) {
                if (Human.IsHoldingItem) {
                    yield return new DropItemAction(1f);
                }

                yield break;
            }

            if (!Human.IsHoldingItem) {
                _destTile = null;

                if (_destResource != null && (_destResource.Entity.Position2D != _destResource.LastPos || !_destResource.Entity.IsValid)) {
                    _destResource = null;
                }

                if (_destResource == null) {
                    _destResource = _blockBeliefs.Entities
                        .Union(Beliefs.Entities)
                        .Where(x => x.Type == EntityType.PlankSource || x.Type == EntityType.PlankPile)
                        .Where(x => World.GetTile(x.LastPos).IsInterior)
                        .OrderBy(x => World.Difference(x.LastPos, Entity.Position2D).LengthSquared)
                        .FirstOrDefault();

                    if (_destResource == null) {
                        _noResources = true;
                        yield break;
                    } else {
                        if (_nav != null) {
                            _nav.Dispose();
                        }

                        _nav = new RouteNavigator(Entity, _destResource.LastPos +
                            World.Difference(_destResource.LastPos, Entity.Position2D).Normalized() * 1.4f);
                    }
                }

                var diff = World.Difference(Entity.Position2D, _destResource.LastPos);

                if (_nav.HasEnded) {
                    yield return new MovementAction(diff.Normalized() * 2f);
                } else if (_nav.HasDirection) {
                    yield return new MovementAction(_nav.GetDirection() * 2f);
                }

                if (diff.LengthSquared < 2f) {
                    if (_destResource.Type == EntityType.PlankSource) {
                        yield return new AttackAction(_destResource.Entity);
                    } else if (_destResource.Entity.GetComponent<Item>().CanPickup(Entity)) {
                        yield return new PickupItemAction(_destResource.Entity, 2f);
                    }
                }
            } else {
                _destResource = null;

                if (_destTile != null && !_pendingTiles.Contains(_destTile)) {
                    _destTile = null;
                }

                if (_destTile == null) {
                    _destTile = _pendingTiles
                        .OrderBy(x => World.Difference(Entity.Position2D, x.Position).LengthSquared)
                        .FirstOrDefault();

                    if (_nav != null) {
                        _nav.Dispose();
                    }

                    _nav = new RouteNavigator(Entity, _destTile.Position);
                }

                if (_destTile != null) {
                    var diff = World.Difference(Entity.Position2D, _destTile.Position);

                    if (_nav.HasDirection) {
                        yield return new MovementAction(_nav.GetDirection() * 2f);
                    }

                    if (diff.LengthSquared < 0.25f) {
                        yield return new DropItemAction(2f);
                    }
                }
            }
        }
コード例 #3
0
 public PlayerMovementCommand(Desires.PlayerMovementCommand desire, Beliefs beliefs)
     : base(desire, beliefs)
 {
     _nav = new RouteNavigator(Entity, desire.Destination);
 }