Пример #1
0
        AI.Group CreateHerd(int numAnimals, LivingID livingID)
        {
            var world = m_env.World;

            var group = new AI.Group();

            var center = m_env.GetRandomEnterableSurfaceLocation();

            using (var iter = IntVector2.SquareSpiral(center.ToIntVector2(), 20).GetEnumerator())
            {
                for (int i = 0; i < numAnimals; ++i)
                {
                    bool ok = true;

                    while (true)
                    {
                        if (iter.MoveNext() == false)
                        {
                            ok = false;
                            break;
                        }

                        var p2 = iter.Current;

                        if (m_env.Size.Plane.Contains(p2) == false)
                        {
                            continue;
                        }

                        var p = m_env.GetSurfaceLocation(p2);

                        if (m_env.CanEnter(p) == false)
                        {
                            continue;
                        }

                        var livingBuilder = new LivingObjectBuilder(livingID);

                        var living = livingBuilder.Create(world);
                        var ai     = new Dwarrowdelf.AI.HerbivoreAI(living, world.PlayerID);
                        ai.Group = group;
                        living.SetAI(ai);
                        living.MoveToMustSucceed(m_env, p);

                        break;
                    }

                    if (!ok)
                    {
                        break;
                    }
                }
            }

            return(group);
        }
Пример #2
0
        AI.Group CreateHerd(int numAnimals, LivingID livingID)
        {
            var world = m_env.World;

            var group = new AI.Group();

            var center = m_env.GetRandomEnterableSurfaceLocation();

            using (var iter = IntVector2.SquareSpiral(center.ToIntVector2(), 20).GetEnumerator())
            {
                for (int i = 0; i < numAnimals; ++i)
                {
                    bool ok = true;

                    while (true)
                    {
                        if (iter.MoveNext() == false)
                        {
                            ok = false;
                            break;
                        }

                        var p2 = iter.Current;

                        if (m_env.Size.Plane.Contains(p2) == false)
                            continue;

                        var p = m_env.GetSurfaceLocation(p2);

                        if (m_env.CanEnter(p) == false)
                            continue;

                        var livingBuilder = new LivingObjectBuilder(livingID);

                        var living = livingBuilder.Create(world);
                        var ai = new Dwarrowdelf.AI.HerbivoreAI(living, world.PlayerID);
                        ai.Group = group;
                        living.SetAI(ai);
                        living.MoveToMustSucceed(m_env, p);

                        break;
                    }

                    if (!ok)
                        break;
                }
            }

            return group;
        }