Ejemplo n.º 1
0
        //-------------------------------------------------------------------------

        static StrategyEntity()
        {
            // Specify the entities this type of entity can depend on.
            EntityRelationshipManager.AddAllowedDependency(typeof(StrategyEntity), typeof(StrategyEntity));
            EntityRelationshipManager.AddAllowedDependency(typeof(StrategyEntity), typeof(RealisationEntity));
            EntityRelationshipManager.AddAllowedDependency(typeof(StrategyEntity), typeof(GoalEntity));
        }
Ejemplo n.º 2
0
 public void SetPersonality(EntityPersonality personality)
 {
     if (EntityRelationshipManager == null)
     {
         EntityRelationshipManager = new EntityRelationshipManager(this, personality);
     }
     else
     {
         EntityRelationshipManager.SetPersonality(personality);
     }
 }
Ejemplo n.º 3
0
        public void AllowedDependencies()
        {
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            Assert.IsTrue(
                EntityRelationshipManager.GetIsDependencyAllowed(
                    typeof(EntityMocks.EntityMock1),
                    typeof(EntityMocks.EntityMock2)));

            Assert.IsFalse(
                EntityRelationshipManager.GetIsDependencyAllowed(
                    typeof(EntityMocks.EntityMock2),
                    typeof(EntityMocks.EntityMock1)));
        }
Ejemplo n.º 4
0
        public void XmlPersistence()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Add some entities.
            EntityMocks.EntityMock1 mock1   = TestObject.AddEntity <EntityMocks.EntityMock1>();
            EntityMocks.EntityMock2 mock2_1 = TestObject.AddEntity <EntityMocks.EntityMock2>();
            EntityMocks.EntityMock2 mock2_2 = TestObject.AddEntity <EntityMocks.EntityMock2>();

            // Add dependencies.
            mock1.AddDependency(mock2_1);
            mock1.AddDependency(mock2_2);

            // Get as xml.
            XmlDocument xmlDoc = new XmlDocument();
            XmlElement  xml    = xmlDoc.CreateElement("Roadmap");

            TestObject.GetAsXml(xml);

            // Initialise a new roadmap using the xml.
            Roadmap newRoadmap = new Roadmap();

            newRoadmap.InitialiseFromXml(xml);

            // Check the entities are present.
            Entity newMock1   = newRoadmap.GetEntity(mock1.Id);
            Entity newMock2_1 = newRoadmap.GetEntity(mock2_1.Id);
            Entity newMock2_2 = newRoadmap.GetEntity(mock2_2.Id);

            Assert.IsNotNull(newMock1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_2.Title, "Entity not found.");

            // Check the dependencies are present.
            ReadOnlyCollection <Entity> dependencies;

            newMock1.GetDependencies(out dependencies);

            Assert.IsTrue(dependencies.Contains(newMock2_1), "Dependency not found.");
            Assert.IsTrue(dependencies.Contains(newMock2_2), "Dependency not found.");
        }
Ejemplo n.º 5
0
        //-------------------------------------------------------------------------

        private void PopulateDependencies()
        {
            try
            {
                uiDependencies.Items.Clear();

                // Iterate through all the entity types.
                foreach (Type type in EntityTypes.Values)
                {
                    // Is the entity is allowed to depend on this type?
                    bool dependencyAllowed =
                        EntityRelationshipManager.GetIsDependencyAllowed(
                            Entity.GetType(),
                            type);

                    if (dependencyAllowed)
                    {
                        // Get all the entities of the type (which we now know
                        // the entity is allowed to depend on) and add to the UI list.
                        ReadOnlyDictionary <int, Entity> entities;
                        Roadmap.GetEntities(type, out entities);

                        foreach (Entity e in entities.Values)
                        {
                            // Can't depend on itself.
                            if (e != Entity)
                            {
                                uiDependencies.Items.Add(
                                    e,
                                    Entity.GetIsDependantOn(e));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Program.HandleException(ex);
            }
        }
Ejemplo n.º 6
0
        public void XmlFilePersistence()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Add some entities.
            EntityMocks.EntityMock1 mock1   = TestObject.AddEntity <EntityMocks.EntityMock1>();
            EntityMocks.EntityMock2 mock2_1 = TestObject.AddEntity <EntityMocks.EntityMock2>();
            EntityMocks.EntityMock2 mock2_2 = TestObject.AddEntity <EntityMocks.EntityMock2>();

            // Add dependencies.
            mock1.AddDependency(mock2_1);
            mock1.AddDependency(mock2_2);

            // Write to file.
            Roadmap.WriteToFile("XmlFilePersistence.roadmap", TestObject);

            // Initialise a new roadmap from file.
            Roadmap newRoadmap = Roadmap.InstantiateFromFile("XmlFilePersistence.roadmap");

            // Check the entities are present.
            Entity newMock1   = newRoadmap.GetEntity(mock1.Id);
            Entity newMock2_1 = newRoadmap.GetEntity(mock2_1.Id);
            Entity newMock2_2 = newRoadmap.GetEntity(mock2_2.Id);

            Assert.IsNotNull(newMock1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_1.Title, "Entity not found.");
            Assert.IsNotNull(newMock2_2.Title, "Entity not found.");

            // Check the dependencies are present.
            ReadOnlyCollection <Entity> dependencies;

            newMock1.GetDependencies(out dependencies);

            Assert.IsTrue(dependencies.Contains(newMock2_1), "Dependency not found.");
            Assert.IsTrue(dependencies.Contains(newMock2_2), "Dependency not found.");
        }
Ejemplo n.º 7
0
        public void AddDependency()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Create entities.
            EntityMocks.EntityMock1 mock1 = new EntityMocks.EntityMock1(0, TestObject);
            EntityMocks.EntityMock2 mock2 = new EntityMocks.EntityMock2(1, TestObject);

            // Create dependencies between entities.
            bool result = TestObject.AddDependency(mock1, mock2);

            Assert.IsTrue(result, "Failed to add dependency.");

            result = TestObject.AddDependency(mock2, mock1);
            Assert.IsFalse(result, "Added a dependency that should've failed.");

            result = TestObject.AddDependency(mock1, mock1);
            Assert.IsFalse(result, "Added itself as a dependency.");

            // GetDependencies() method.
            ReadOnlyCollection <Entity> dependencies;

            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsTrue(dependencies.Contains(mock2), "Dependency not found.");

            // GetDoesDependencyExist() method.
            Assert.IsTrue(TestObject.GetDoesDependencyExist(mock1, mock2));
            Assert.IsFalse(TestObject.GetDoesDependencyExist(mock2, mock1));

            // GetDependants() method.
            List <Entity> dependants;

            TestObject.GetDependants(mock2, out dependants);

            Assert.IsTrue(dependants.Contains(mock1), "Dependant not found.");
        }
Ejemplo n.º 8
0
        public void RemoveDependency()
        {
            // Set up allowed dependencies.
            EntityRelationshipManager.AddAllowedDependency(
                typeof(EntityMocks.EntityMock1),
                typeof(EntityMocks.EntityMock2));

            // Set up entities.
            EntityMocks.EntityMock1 mock1   = new EntityMocks.EntityMock1(0, TestObject);
            EntityMocks.EntityMock2 mock2_1 = new EntityMocks.EntityMock2(1, TestObject);
            EntityMocks.EntityMock2 mock2_2 = new EntityMocks.EntityMock2(2, TestObject);

            // Add some dependencies.
            TestObject.AddDependency(mock1, mock2_1);
            TestObject.AddDependency(mock1, mock2_2);

            // Remove a dependency.
            TestObject.RemoveDependency(mock1, mock2_1);

            // Check it was removed.
            ReadOnlyCollection <Entity> dependencies;

            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsFalse(dependencies.Contains(mock2_1), "Dependency still present.");

            // Check the other dependency is still present.
            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsTrue(dependencies.Contains(mock2_2), "Dependency not found.");

            // Remove the remaining dependency entity.
            TestObject.RemoveEntity(mock2_2);

            // Check the dependency is now removed.
            TestObject.GetDependencies(mock1, out dependencies);
            Assert.IsFalse(dependencies.Contains(mock2_2), "Dependency still present.");
        }
Ejemplo n.º 9
0
 public NPC(string name = "un-named_entity", bool isFixed = true) : base(new NonAggresiveNPCCombatAI(), new BasicNPCTaskAI(), new EntityMovementData(4, 7, 2), name: name, isFixed: isFixed)
 {
     Debug.Log("new entity created ");
     NPCData = new BasicNPCData();
     EntityRelationshipManager = new EntityRelationshipManager(this);
 }
Ejemplo n.º 10
0
        //-------------------------------------------------------------------------

        public void Reset()
        {
            EntityRelationships = new EntityRelationshipManager();
            EntityFactory       = new EntityFactory(EntityRelationships);
            Entities.Clear();
        }
Ejemplo n.º 11
0
        //-------------------------------------------------------------------------

        public RealisationEntity(int id,
                                 EntityRelationshipManager relationshipManager)
            :
            base(id, relationshipManager)
        {
        }
Ejemplo n.º 12
0
        //-------------------------------------------------------------------------

        public GoalEntity(int id,
                          EntityRelationshipManager relationshipManager)
            :
            base(id, relationshipManager)
        {
        }
Ejemplo n.º 13
0
 public void Initialise()
 {
     TestObject = new EntityRelationshipManager();
 }
Ejemplo n.º 14
0
        //-------------------------------------------------------------------------

        public StrategyEntity(int id,
                              EntityRelationshipManager relationshipManager)
            :
            base(id, relationshipManager)
        {
        }
Ejemplo n.º 15
0
 public EntityMock2(int id, EntityRelationshipManager relationshipManager)
     :
     base(id, relationshipManager)
 {
 }