Esempio n. 1
0
        protected WorldDescription LoadFromFile(string fileName)
        {
            WorldDescription desc = WorldIO.Load(fileName);

            SetTerrain(desc.Terrain);
            return(desc);
        }
        public void LoadWorld(string name)
        {
            World.UnloadTerrain();
            WorldDescription desc = WorldIO.Load(name, false);

            World.SetTerrain(desc.Terrain);
            WorldEditor.TerrainEditor.ClearUndoRedo();

            Window.UpdateTitle(name);
            CurrentFile = name;

            var commandposts = desc.GetObjectsByTag("CommandPost");

            foreach (WorldObjectDescription ob in commandposts)
            {
                Vector3           position          = ob.GetVector3("Position");
                CommandPostObject editorCommandPost = new CommandPostObject(position);
                Team team = (Team)(ob.GetField <byte>("Team") ?? 0);
                editorCommandPost.Team = team;

                World.AddGameObject(editorCommandPost);
            }

            var intels = desc.GetObjectsByTag("Intel");

            foreach (WorldObjectDescription ob in intels)
            {
                Vector3     position    = ob.GetVector3("Position");
                IntelObject editorIntel = new IntelObject(position);
                Team        team        = (Team)(ob.GetField <byte>("Team") ?? 0);
                editorIntel.Team = team;

                World.AddGameObject(editorIntel);
            }
        }
Esempio n. 3
0
 public Reasoning()
 {
     worldDescription        = new WorldDescription();
     scenarioDescriptionList = new List <ScenarioDescription>();
     _logger = ServiceLocator.Current.GetInstance <ILog>();
     TInf    = 100;
 }
        private void ProcessPacket(Packet packet, Stream socketStream)
        {
            switch (packet.Type)
            {
            case PacketTypes.WorldStatus:
            {
                WorldDescription currentDescription = _userWorld.GetCurrentDescription();

                var returnPacket = new Packet(PacketTypes.WorldStatus, currentDescription);

                returnPacket.CopyTo(socketStream);
                break;
            }

            case PacketTypes.ClientCommand:
            {
                MoveArguments args = packet.Data as MoveArguments;

                if (args == null)
                {
                    return;
                }

                _userWorld.SendTo(args.Units, args.Position);
                break;
            }
            }
        }
Esempio n. 5
0
        private void CreateNewGame(PlayerEntity player)
        {
            Player = player;
            var generator = new WorldGenerator();
            var desc      = WorldDescription.FromFile("world.json");

            World      = generator.Generate(desc, player);
            PlayerView = new ViewCharacter(this, Renderer, Player);
        }
        public void SaveWorld(string filePath)
        {
            if (World.Terrain != null)
            {
                CurrentFile = filePath;
                Window.UpdateTitle(filePath);

                WorldDescription desc = World.CreateDescription();
                WorldIO.Save(filePath, desc, false);
            }
        }
Esempio n. 7
0
 private void ProcessPacket(Packet packet)
 {
     switch (packet.Type)
     {
     case PacketTypes.WorldStatus:
     {
         LastDescription = (WorldDescription)packet.Data;
         break;
     }
     }
 }
Esempio n. 8
0
        internal List <Vertex> GenerateChildsForLeaf(WorldDescription worldDescription, ScenarioDescription scenarioDescription, int TInf)
        {
            List <Vertex> vertices = new List <Vertex>();

            int nextTime = GetNextTimestamp(scenarioDescription, TInf);

            if (!CheckNearestObservations(scenarioDescription, nextTime))
            {
                return(GetImpossibleChilds());
            }

            var         implications = worldDescription.GetImplications(this, nextTime);
            WorldAction nextAction   = scenarioDescription.GetActionAtTime(nextTime);

            vertices = CreateChildsBasedOnImplications(implications, nextAction, nextTime);

            return(vertices);
        }
Esempio n. 9
0
 public bool LoadFromFile(string fileName)
 {
     DashCMD.WriteImportant("[ServerWorld] Loading world '{0}'...", fileName);
     try
     {
         Description = WorldIO.Load(CurrentWorldName = fileName);
         SetTerrain(Description.Terrain);
         Terrain.LockBottomLayer = true;
         DashCMD.WriteImportant("[ServerWorld] Successfully loaded world '{0}'.", fileName);
         return(true);
     }
     catch (IOException ioex)
     {
         DashCMD.WriteError("[ServerWorld] Failed to load world '{0}'!", fileName);
         DashCMD.WriteError(ioex);
         return(false);
     }
 }
Esempio n. 10
0
        public SPWorld(MasterRenderer renderer)
            : base(renderer)
        {
            WorldDescription desc = LoadFromFile(Program.GetConfigString("Singleplayer/world"));

            spawnPos = new Vector3(100, 400, 100);

            var commandposts = desc.GetObjectsByTag("CommandPost");

            foreach (WorldObjectDescription ob in commandposts)
            {
                Vector3     position    = ob.GetVector3("Position");
                Team        team        = (Team)(ob.GetField <byte>("Team") ?? 0);
                CommandPost commandPost = new CommandPost(position, team);
                AddGameObject(commandPost);

                if (team == Team.A)
                {
                    spawnPos = position;
                }
            }

            var intels = desc.GetObjectsByTag("Intel");

            foreach (WorldObjectDescription ob in intels)
            {
                Vector3 position    = ob.GetVector3("Position");
                Team    team        = (Team)(ob.GetField <byte>("Team") ?? 0);
                Intel   editorIntel = new Intel(position, team);
                AddGameObject(editorIntel);
            }

            Player = new SPPlayer(Renderer, this, Camera.Active, spawnPos, Team.A);
            AddGameObject(Player);
            hud        = new HUD(Renderer);
            hud.Player = Player;
            hud.ShowCharacterInformation = true;
            hud.Enable();

            Player.AttachCamera();
        }
        public void SetUp()
        {
            // BASIC WORLD DESCRIPTION
            _worldDescription = new WorldDescription();
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.Initially, new InitialRecord("a || b || c || d")));
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(this._actionA2, "a && !b", "c")));
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(this._actionB3, "a || b", "d")));

            // BASIC SCENARIO
            _scenarioDescription = new ScenarioDescription("basic");
            _scenarioDescription.addObservation(new SimpleLogicExpression("a && b && c && d"), 0);
            _scenarioDescription.addACS(this._actionA2, 1);
            _scenarioDescription.addObservation(new SimpleLogicExpression("a && !b && c && d"), 4);

            _reasoning = new Reasoning();

            foreach (var description in _worldDescription.Descriptions.Select(t => t.Item2))
            {
                _reasoning.AddWorldDescriptionRecord(description);
            }
        }
        public void SetUp()
        {
            _state = new State {
                Fluents = new List <Fluent> {
                    new Fluent {
                        Name = "a", Value = true
                    },
                    new Fluent {
                        Name = "b", Value = true
                    },
                    new Fluent {
                        Name = "c", Value = true
                    },
                    new Fluent {
                        Name = "e", Value = true
                    }
                }
            };

            var fluentC = new Fluent {
                Name = "c", Value = true
            };

            _worldDescription = new WorldDescription();

            // INITIALLY
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.Initially, new InitialRecord("a || b || c || e")));

            // ACTION CAUSES IF
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(action_A_2, "a && !b", "c")));
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(action_B_3, "a || b", "e")));
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionCausesIf, new ActionCausesIfRecord(action_B_3, "!b && !c", "e")));

            // RELEASE FLUENT
            _worldDescription.Descriptions.Add(new Tuple <WorldDescriptionRecordType, WorldDescriptionRecord>(WorldDescriptionRecordType.ActionReleasesIf, new ActionReleasesIfRecord(action_B_3, fluentC, "e || c")));
        }
    private void UpdateWorldState(WorldDescription newDescription)
    {
        Camera camera  = Camera.main;
        int    newSize = newDescription.WorldSize;
        float  minSize = Math.Min(camera.rect.width, camera.rect.height);

        float cellZPosition = 30;
        float unitZPosition = 29;

        if (_currentDesctiption == null || newDescription.WorldSize != _currentDesctiption.WorldSize)
        {
            foreach (var cell in _fieldCells)
            {
                Destroy(cell);
            }

            _fieldCells.Clear();

            for (int i = 1; i <= newSize; i++)
            {
                for (int j = 1; j <= newSize; j++)
                {
                    Sprite fieldSprite = Resources.Load <Sprite>("Sprites/FieldCell");

                    var obj = new GameObject();

                    var rend = obj.AddComponent <SpriteRenderer>();
                    rend.sprite = fieldSprite;

                    obj.AddComponent <CircleCollider2D>();

                    var cellView = obj.AddComponent <CellView>();
                    cellView.Point    = new Point(i - 1, j - 1);
                    cellView.Clicked += Cell_Clicked;

                    obj.transform.localScale = new Vector3(
                        0.1f * fieldSprite.rect.width * (minSize / (newSize + 1)),
                        0.1f * fieldSprite.rect.height * (minSize / (newSize + 1)),
                        1);

                    obj.transform.position = camera.ViewportToWorldPoint(new Vector3(i / (float)(newSize + 1), j / (float)(newSize + 1), cellZPosition));

                    _fieldCells.Add(obj);
                }
            }
        }

        _currentDesctiption = newDescription;

        foreach (var unit in _currentDesctiption.Units)
        {
            if (!_unitSprites.ContainsKey(unit.UnitId))
            {
                var view = new UnitView();
                view.IsSelected = false;

                view.SetScale(new Vector3(
                                  0.9f * 2 * (minSize / (newSize + 1)),
                                  0.9f * 2 * (minSize / (newSize + 1)),
                                  1));

                _unitSprites.Add(unit.UnitId, view);
            }

            _unitSprites[unit.UnitId].SetPosition(camera.ViewportToWorldPoint(
                                                      new Vector3((unit.Position.X + 1) / (float)(newSize + 1),
                                                                  (unit.Position.Y + 1) / (float)(newSize + 1), unitZPosition)));

            if (unit.Destination.HasValue)
            {
                _unitSprites[unit.UnitId].SetState(UnitState.Moving);
            }
            else
            {
                _unitSprites[unit.UnitId].SetState(UnitState.Stopped);
            }
        }

        // Здесь возможно удаление исчезнувших юнитов, но в
        // нашем случае это не нужно.
    }
Esempio n. 14
0
 public World(WorldDescription description)
 {
     Description = description;
     Entities    = new List <Entity>();
     Locations   = new List <Location>();
 }