コード例 #1
0
ファイル: MapImporter.cs プロジェクト: wandsmire/OpenSA
        void LoadActors()
        {
            for (var a = 0; a < numberOfActors; a++)
            {
                var id   = stream.ReadInt32();
                var type = stream.ReadInt32();
                var x    = (int)Math.Round((float)stream.ReadInt32() / map.Grid.TileSize.Width);
                var y    = (int)Math.Round((float)stream.ReadInt32() / map.Grid.TileSize.Height);

                var invalidLocation = false;
                if (x < 0 || x > mapSize.Width || y < 0 || y > mapSize.Height)
                {
                    Console.WriteLine("Invalid coordinates {0},{1} for actor type {2}.".F(x, y, type));
                    invalidLocation = true;
                }

                stream.Seek(4, SeekOrigin.Current);
                var numberOfProperties = stream.ReadInt32();
                stream.Seek(4, SeekOrigin.Current);
                if (numberOfProperties > 0)
                {
                    for (var p = 0; p < numberOfProperties; p++)
                    {
                        var key   = stream.ReadASCII(128);
                        var value = stream.ReadInt32();
                        Console.WriteLine(key + ": " + value);
                    }
                }

                if (!ActorMap.ContainsKey(type))
                {
                    Console.WriteLine("Ignoring unknown actor type: `{0}` @ {1},{2}".F(type, x, y));
                    continue;
                }

                if (invalidLocation)
                {
                    continue;
                }

                var actorInfo = ActorMap[type];
                var actorType = actorInfo.ActorType.ToLowerInvariant();
                var actor     = new ActorReference(actorType)
                {
                    new LocationInit(new CPos(x + MapCordonWidth, y + MapCordonWidth)),
                };

                if (actorInfo.Color == Color.White)
                {
                    actor.Add(new OwnerInit("Neutral"));
                }
                if (actorInfo.Color == Color.Green)
                {
                    actor.Add(new OwnerInit("Ants"));
                }
                if (actorInfo.Color == Color.Blue)
                {
                    actor.Add(new OwnerInit("Beetles"));
                }
                if (actorInfo.Color == Color.Red)
                {
                    actor.Add(new OwnerInit("Spiders"));
                }
                if (actorInfo.Color == Color.Yellow)
                {
                    actor.Add(new OwnerInit("Wasps"));
                }
                if (actorInfo.Color == Color.Black)
                {
                    actor.Add(new OwnerInit("Creeps"));
                }

                AddPlayer(actorInfo.Color);

                var actorCount = map.ActorDefinitions.Count;

                if (!map.Rules.Actors.ContainsKey(actorType))
                {
                    Console.WriteLine("Ignoring unknown actor type: `{0}`".F(actorType));
                }
                else
                {
                    map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, actor.Save()));
                }
            }
        }