Beispiel #1
0
        Player CreatePlayer(int playerNum, EnvironmentObject env)
        {
            const int NUM_DWARVES = 7;

            var player = new FortressPlayer(2 + playerNum, this, env);

            IntVector3 pos;

            switch (playerNum)
            {
                case 0:
                    pos = env.StartLocation;
                    break;

                case 1:
                    pos = env.GetSurfaceLocation(env.Width / 4, env.Height / 4);
                    break;

                case 2:
                    pos = env.GetSurfaceLocation(env.Width / 4 * 3, env.Height / 4 * 3);
                    break;

                default:
                    throw new Exception();
            }

            var startRect = FindStartLocation(env, pos);

            if (!startRect.HasValue)
                throw new Exception();

            player.EnvObserver.Add(startRect.Value);

            var startLocs = startRect.Value.Range().ToArray();

            // clear trees
            foreach (var p in startLocs)
            {
                var td = env.GetTileData(p);
                if (td.HasTree)
                {
                    td.ID = TileID.Grass;
                    td.MaterialID = MaterialID.RyeGrass;
                    env.SetTileData(p, td);
                }
            }

            var list = new List<LivingObject>();

            for (int i = 0; i < NUM_DWARVES; ++i)
            {
                var p = startLocs[Helpers.GetRandomInt(startLocs.Length - 1)];

                var l = CreateDwarf(i);

                l.SetAI(new DwarfAI(l, player.EnvObserver, this.World.PlayerID));

                l.MoveToMustSucceed(env, p);

                list.Add(l);
            }

            player.AddControllables(list);

            return player;
        }
Beispiel #2
0
        Player CreatePlayer(int playerNum, EnvironmentObject env)
        {
            const int NUM_DWARVES = 7;

            var player = new FortressPlayer(2 + playerNum, this, env);

            IntVector3 pos;

            switch (playerNum)
            {
            case 0:
                pos = env.StartLocation;
                break;

            case 1:
                pos = env.GetSurfaceLocation(env.Width / 4, env.Height / 4);
                break;

            case 2:
                pos = env.GetSurfaceLocation(env.Width / 4 * 3, env.Height / 4 * 3);
                break;

            default:
                throw new Exception();
            }

            var startRect = FindStartLocation(env, pos);

            if (!startRect.HasValue)
            {
                throw new Exception();
            }

            player.EnvObserver.Add(startRect.Value);

            var startLocs = startRect.Value.Range().ToArray();

            // clear trees
            foreach (var p in startLocs)
            {
                var td = env.GetTileData(p);
                if (td.HasTree)
                {
                    td.ID         = TileID.Grass;
                    td.MaterialID = MaterialID.RyeGrass;
                    env.SetTileData(p, td);
                }
            }

            var list = new List <LivingObject>();

            for (int i = 0; i < NUM_DWARVES; ++i)
            {
                var p = startLocs[Helpers.GetRandomInt(startLocs.Length - 1)];

                var l = CreateDwarf(i);

                l.SetAI(new DwarfAI(l, player.EnvObserver, this.World.PlayerID));

                l.MoveToMustSucceed(env, p);

                list.Add(l);
            }

            player.AddControllables(list);

            return(player);
        }