private void BuildIGRList()
    {
        //create resource exchange icon group
        labels.Add("Resources:");
        IconGroupReusable igr = IconGroupReusable.GetResourcesIconGroupReusable(blueprintDesign, false);

        igrList.Add(igr);

        //create materials needed icon group
        igr = new IconGroupReusable(true);
        igrList.Add(igr);
        labels.Add("Materials needed:");
        foreach (ThingTypes tt in blueprintDesign.GetThingTotal().Keys)
        {
            Texture texture = ThingFactory.MakeThing(tt).iconTexture;
            int     count   = blueprintDesign.GetThingTotal()[tt];
            igr.AddIcons(texture, null, count);
        }

        //create work needed icon group
        igr = new IconGroupReusable(true);
        igrList.Add(igr);
        labels.Add("Tools needed:");
        foreach (ThingTypes tt in blueprintDesign.GetToolTotal().Keys)
        {
            Texture texture = ThingFactory.MakeThing(tt).iconTexture;
            float   amount  = blueprintDesign.GetToolTotal()[tt];
            igr.AddIcons(texture, null, Mathf.CeilToInt(amount));
        }
    }
Exemple #2
0
    public void SetAudioClip(ThingTypes thingType)
    {
        if (thingType == ThingTypes.greasegun || thingType == ThingTypes.hammerdrill ||
            thingType == ThingTypes.shovel || thingType == ThingTypes.wrench || thingType == ThingTypes.electricdrill)
        {
            if (audioClips == null)
            {
                audioClips = new Dictionary <string, AudioClip>();
            }

            string filename = ThingFactory.GetKeyFromThingType(thingType);
            string path     = "sounds/tools/" + filename;

            if (!audioClips.ContainsKey(path))
            {
                audioClip = Resources.Load(path) as AudioClip;
                if (audioClip == null)
                {
                    Debug.LogError("Expected to find an audioclip, but did not. '" + path + "'");
                }
                audioClips.Add(path, audioClip);
            }
            audioClip = audioClips[path];
        }
    }
        public override IThing CreateSourceItem(IGraph <IVisual, IVisualEdge> sink,
                                                IGraph <IThing, ILink> source, IVisual b)
        {
            var result = ThingFactory.CreateItem(source as IThingGraph, b.Data);

            return(result);
        }
    private static GameObject GetStructurePrefab(ThingTypes thingType)
    {
        if (structurePrefabs == null)
        {
            structurePrefabs = new Dictionary <ThingTypes, GameObject>();
        }

        if (!ThingFactory.IsBlueprint(thingType))
        {
            Debug.LogError("GetStructurePrefab got thingType that isn't a blueprint. " + thingType);
            return(null);
        }

        if (!structurePrefabs.ContainsKey(thingType))
        {
            Thing      thingTemplate   = ThingFactory.MakeThing(thingType);
            string     path            = "structures/" + thingTemplate.key;
            GameObject structurePrefab = Resources.Load(path) as GameObject;

            if (structurePrefab == null)
            {
                Debug.LogError("GetStructurePrefab failed to load prefab: " + path);
            }
            structurePrefabs.Add(thingType, structurePrefab);
        }
        return(structurePrefabs[thingType]);
    }
        public void InheritanceMissing()
        {
            var cityDef = new SiteDefinition()
            {
                Name         = "City",
                Description  = "A moderate sized settlement",
                InheritsFrom = "Population Center",
            };

            cityDef.Attributes["Population"] = new AttributeDefinition()
            {
                BaseValue = "rand.Next(20000, 100000)"
            };

            IList <SiteDefinition> sites = new List <SiteDefinition>
            {
                cityDef,
            };

            var definitions = new DefinitionCollection(sites);

            int worldSeed = 915434125;

            ThingFactory factory = new ThingFactory(definitions);

            //factory.CreateSite(new Random(worldSeed), 0, 0, "City");
        }
Exemple #6
0
    public void SelectTool(ThingTypes thingType, bool animateIfIdenticalThingType)
    {
        if (selectedThingType == thingType && !animateIfIdenticalThingType)
        {
            return;
        }

        if (tool != null)
        {
            Destroy(tool);
        }

        if (!ThingFactory.IsTool(thingType))
        {
            Debug.LogError("ToolGUI.SelectTool got non-tool. " + thingType);
            return;
        }

        selectedThingType = thingType;
        isMoving          = true;
        moveTimer         = 0;
        tool = Instantiate(GetToolGUIPrefab(thingType)) as GameObject;
        tool.transform.parent = player.transform;

        tool.transform.position = toolDownTransform.position;
        tool.transform.rotation = toolDownTransform.rotation;
    }
Exemple #7
0
    private void Setup()
    {
        if (isSetup)
        {
            return;
        }

        gameObject.AddComponent <GUIManager> ();
        gameObject.AddComponent <ClickController> ();

        crew = player.GetComponent <Crew> ();

        ThingFactory.Setup();
        GUIFunctions.Setup();
        BlueprintDesignManager.Setup();

        //setup structures that are already in scene
        foreach (StructureController sc in GameObject.FindObjectsOfType <StructureController>())
        {
            sc.SetupRealStructure();
            sc.SetAltitudeToMatchTerrain();
        }

        isSetup = true;
    }
    public static GameObject MakeStructure(ThingTypes thingType, bool isBlueprint)
    {
        if (!ThingFactory.IsBlueprint(thingType))
        {
            Debug.LogError("StructureFactory.MakeStructure got a non-blueprint thingType: " + thingType);
            return(null);
        }

        GameObject          prefab    = GetStructurePrefab(thingType);
        GameObject          structure = Instantiate(prefab) as GameObject;
        StructureController sc        = structure.GetComponent <StructureController>();

        if (isBlueprint)
        {
            sc.SetupBlueprint();
        }
        else
        {
            sc.SetupRealStructure();
        }

        if (isBlueprint)
        {
            ParentChildFunctions.SetMaterialOfChildren(structure, Blueprint.GetBlueprintMaterial());
            ParentChildFunctions.SetCollisionForChildren(structure, false);
        }
        else if (!sc.HasColliders())
        {
            //real structures with no colliders get mesh colliders
            ParentChildFunctions.SetCollisionForChildren(structure, !isBlueprint);
        }

        return(structure);
    }
 private StructureReusable GetStructureReusable(Rect drawRect, BlueprintDesign blueprintDesign)
 {
     if (!structureReusables.ContainsKey(blueprintDesign))
     {
         Thing             thing = ThingFactory.MakeThing(blueprintDesign.thingType);
         StructureReusable sr    = new StructureReusable(drawRect, thing.iconTexture, thing.longName, blueprintDesign);
         structureReusables.Add(blueprintDesign, sr);
     }
     return(structureReusables[blueprintDesign]);
 }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RequirementSpecificationMappingDialogViewModel"/> class.
        /// </summary>
        /// <param name="thingFactory">The <see cref="ThingFactory"/></param>
        /// <param name="iteration">The iteration</param>
        /// <param name="session">The session</param>
        /// <param name="thingDialogNavigationService">The thing Dialog Navigation Service</param>
        /// <param name="lang">The current langguage code</param>
        public RequirementSpecificationMappingDialogViewModel(ThingFactory thingFactory, Iteration iteration, ISession session, IThingDialogNavigationService thingDialogNavigationService, string lang)
            : base(iteration, session, thingDialogNavigationService, lang)
        {
            this.PreviewRows  = new ReactiveList <IRowViewModelBase <Thing> >();
            this.thingFactory = thingFactory;

            this.PopulateRows();

            this.InitializeCommands();
        }
Exemple #11
0
        public void TestIThingFactory()
        {
            IThingFactory itf   = ThingFactory.GiveMeAFactory();
            IThing        thing =
                itf
                .AddInteger(94)
                .AddString("hello, world")
                .Create();

            Assert.AreEqual(94, thing.SomeIntegerFunction(8));
            Assert.AreEqual("goodbye", thing.SaySomething("g'day"));
        }
    private void SetupGeneric()
    {
        //this stuff happens for blueprint structures and real structures

        //static
        SetThingStructurePairs();
        structureControllerCount++;

        matchingThingType = thingAndStructurePairs [structureType];
        matchingThing     = ThingFactory.MakeThing(matchingThingType);
        structureInfo     = new StructureInfo(matchingThingType);
    }
Exemple #13
0
        public void VerifyThatThingFactoryWorks()
        {
            var datatypeMap  = new Dictionary <DatatypeDefinition, DatatypeDefinitionMap>();
            var datatypedef1 = new DatatypeDefinitionMap(this.stringDatadef, this.pt, null);

            datatypeMap.Add(this.stringDatadef, datatypedef1);

            var spectypeMap      = new Dictionary <SpecType, SpecTypeMap>();
            var specificationMap = new SpecTypeMap(this.specificationtype, null, new [] { this.specCategory }, new [] { new AttributeDefinitionMap(this.specAttribute, AttributeDefinitionMapKind.NAME) });
            var requirementMap   = new SpecObjectTypeMap(this.specobjecttype, null, new [] { this.reqCateory }, new[] { new AttributeDefinitionMap(this.reqAttribute, AttributeDefinitionMapKind.FIRST_DEFINITION) }, true);
            var specRelationMap  = new SpecRelationTypeMap(this.specrelationtype, new [] { this.parameterRule }, new [] { this.specRelationCategory }, new[] { new AttributeDefinitionMap(this.specRelationAttribute, AttributeDefinitionMapKind.PARAMETER_VALUE) }, new [] { this.reqRule });
            var relationGroupMap = new RelationGroupTypeMap(this.relationgrouptype, null, new [] { this.relationGroupCategory }, new[] { new AttributeDefinitionMap(this.relationgroupAttribute, AttributeDefinitionMapKind.NONE) }, new [] { this.specRule });

            spectypeMap.Add(this.specificationtype, specificationMap);
            spectypeMap.Add(this.specobjecttype, requirementMap);
            spectypeMap.Add(this.specrelationtype, specRelationMap);
            spectypeMap.Add(this.relationgrouptype, relationGroupMap);

            var factory = new ThingFactory(this.iteration, datatypeMap, spectypeMap, this.domain, this.reqIf.Lang);

            factory.ComputeRequirementThings(this.reqIf);

            Assert.AreEqual(1, factory.RelationGroupMap.Count);
            Assert.AreEqual(1, factory.SpecRelationMap.Count);
            Assert.AreEqual(2, factory.SpecificationMap.Count);
            Assert.IsTrue(factory.SpecificationMap.All(x => x.Value.Requirement.Count == 1));


            var reqSpec1 = factory.SpecificationMap[this.specification1];
            var reqSpec2 = factory.SpecificationMap[this.specification2];
            var req1     = reqSpec1.Requirement.Single();
            var req2     = reqSpec2.Requirement.Single();

            var specificationRelationship = factory.RelationGroupMap.Single().Value;
            var reqRelatinoship           = factory.SpecRelationMap.Single().Value;

            Assert.AreSame(specificationRelationship.Source, reqSpec1);
            Assert.AreSame(specificationRelationship.Target, reqSpec2);
            Assert.AreSame(reqRelatinoship.Source, req1);
            Assert.AreSame(reqRelatinoship.Target, req2);

            Assert.IsNotEmpty(req1.Definition);
            Assert.IsNotEmpty(req2.Definition);

            Assert.AreEqual(reqSpec1.Name, this.specValue1.TheValue);
            Assert.AreEqual(reqSpec2.Name, this.specValue2.TheValue);

            var parameterValue = reqRelatinoship.ParameterValue.Single();

            Assert.AreEqual(parameterValue.Value[0], this.specrelationValue.TheValue);

            //todo to complete
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RequirementSpecificationMappingDialogViewModel"/> class.
        /// </summary>
        /// <param name="thingFactory">The <see cref="ThingFactory"/></param>
        /// <param name="iteration">The iteration</param>
        /// <param name="session">The session</param>
        /// <param name="thingDialogNavigationService">The thing Dialog Navigation Service</param>
        /// <param name="dialogNavigationService">The <see cref="IDialogNavigationService"/></param>
        /// <param name="lang">The current langguage code</param>
        /// <param name="importMappingConfiguration">The <see cref="ImportMappingConfiguration"/></param>
        public RequirementSpecificationMappingDialogViewModel(ThingFactory thingFactory, Iteration iteration, ISession session, IThingDialogNavigationService thingDialogNavigationService, IDialogNavigationService dialogNavigationService, string lang, ImportMappingConfiguration importMappingConfiguration)
            : base(iteration, session, thingDialogNavigationService, lang)
        {
            this.PreviewRows                = new DisposableReactiveList <IRowViewModelBase <Thing> >();
            this.thingFactory               = thingFactory;
            this.dialogNavigationService    = dialogNavigationService;
            this.pluginSettingsService      = ServiceLocator.Current.GetInstance <IPluginSettingsService>();
            this.importMappingConfiguration = importMappingConfiguration;

            this.PopulateRows();

            this.InitializeCommands();
        }
        public override ILink CreateSourceEdge(IGraph <IVisual, IVisualEdge> sink,
                                               IGraph <IThing, ILink> source, IVisualEdge b)
        {
            var thingGraph = source as IThingGraph;
            var data       = b.Data;
            var marker     = thingGraph.GetByData(data, true).FirstOrDefault();

            if (marker != null)
            {
                data = marker;
            }
            return(ThingFactory.CreateEdge(thingGraph, data));
        }
Exemple #16
0
    private static GameObject GetToolGUIPrefab(ThingTypes thingType)
    {
        if (!toolGUIPrefabs.ContainsKey(thingType))
        {
            string     path          = "gui/" + ThingFactory.GetKeyFromThingType(thingType);
            GameObject toolGUIPrefab = Resources.Load(path) as GameObject;

            if (toolGUIPrefab == null)
            {
                Debug.LogError("GetToolGUIPrefab failed to load prefab: " + path);
            }
            toolGUIPrefabs.Add(thingType, toolGUIPrefab);
        }
        return(toolGUIPrefabs [thingType]);
    }
        public virtual IThing SetThingByData(IGraph <IThing, ILink> graph, IThing thing, object data)
        {
            var itemToChange = graph.ThingToDisplay(thing);

            if (thing != null && itemToChange == thing && SchemaFacade.DescriptionableThing(thing))
            {
                itemToChange = ThingFactory.CreateItem(data);
                graph.Add(new Link(thing, itemToChange, CommonSchema.DescriptionMarker));
            }
            else
            {
                graph.DoChangeData(itemToChange, data);
            }
            return(itemToChange);
        }
Exemple #18
0
        public Id CreateAndAddStreamThing()
        {
            long len = Stream.Length;

            var factory = new ThingFactory();

            var thing = factory.CreateItem(Graph, Stream) as IStreamThing;

            Graph.Add(thing);

            thing.Flush();
            thing.ClearRealSubject();

            this.Close();


            return(thing.Id);
        }
        /// <summary>
        /// Initializes the context object.
        /// </summary>
        /// <returns>THe context object.</returns>
        public static Context InitContext()
        {
            int worldSeed = 915434125;

            ConditionCompiler <BaseGlobalVariables> processor =
                new ConditionCompiler <BaseGlobalVariables>(new BaseGlobalVariables()
            {
                World = new World(),
            });
            Definitions  definitions = DefinitionSerializer.DeserializeFromDirectory(processor, "Definitions");
            ThingFactory factory     = new ThingFactory(definitions);

            HistoryGenerator history = new HistoryGenerator(factory, definitions);

            WorldGen.WorldGenerator worldGen = new WorldGen.WorldGenerator(worldSeed, factory);
            int   width  = 200;
            int   height = 200;
            World world  = worldGen.GenerateWorld(width, height);

            processor.UpdateGlobalVariables(g => g.World = world);

            Random rdm = new Random(worldSeed);

            for (int i = 0; i < 100; i++)
            {
                int  x        = rdm.Next(0, width - 1);
                int  y        = rdm.Next(0, height - 1);
                Site cityInst = factory.CreateSite(rdm, x, y, "City");
                world.Grid.AddThing(cityInst);
            }

            foreach (var thing in world.Grid.AllGridEntries.SelectMany(x => x.Square.GetThings()))
            {
                thing.FinalizeConstruction(new Random());
            }

            Context.Instance.Attach(history, world, processor);

            return(Context.Instance);
        }
Exemple #20
0
    public void SelectSlotIndex(int slotIndex)
    {
        //Debug.Log ("SelectSlotIndex " + slotIndex);
        if (!isSetup)
        {
            Setup();
        }
        if (!gameManager.GetCrew().IsSlotIndexValid(slotIndex))
        {
            Debug.LogError("SelectSlotIndex given bad slotIndex. slotIndex=" + slotIndex);
        }
        selectedSlotIndex = slotIndex;
        selectedThing     = gameManager.GetCrew().GetThingFromSlotIndex(slotIndex);
        if (selectedThing != null)
        {
            if (ThingFactory.IsBlueprintVisor(selectedThing.thingType))
            {
                Debug.Log("ThingFactory.IsBlueprintVisor(selectedThing.thingType)");
                GetCursorBlueprint().StartBlueprint(GetSelectedBlueprintThing());
            }
            else
            {
                GetCursorBlueprint().StopBlueprint();
            }

            if (selectedThing.IsTool())
            {
                GetToolGUI().SelectTool(selectedThing.thingType, false);
            }
            else
            {
                GetToolGUI().UnselectTool();
            }
        }
        else
        {
            SelectNull();
        }
    }
        public void InheritanceMissing()
        {
            var cityDef = new SiteDefinition()
            {
                Name         = "City",
                Description  = "A moderate sized settlement",
                InheritsFrom = "Population Center",
            };

            cityDef.Attributes["Population"] = new AttributeDefinition()
            {
                BaseValue = "rand.Next(20000, 100000)"
            };

            IList <SiteDefinition> sites = new List <SiteDefinition>
            {
                cityDef,
            };

            var definitions = new Definitions(sites);

            _ = new ThingFactory(definitions);
        }
Exemple #22
0
    void SetupDebugInventory()
    {
        int i = 0;

        foreach (ThingTypes thingType in System.Enum.GetValues(typeof(ThingTypes)))
        {
            if (!ThingFactory.IsBlueprint(thingType))
            {
                GetInventory() [i] = ThingFactory.MakeThing(thingType);
                if (!ThingFactory.IsTool(thingType))
                {
                    inventory [i].quantity = 1000;
                }
                i++;
            }
        }

        inventory [58] = ThingFactory.MakeThing(ThingTypes.vrvisor);
        inventory [59] = ThingFactory.MakeThing(ThingTypes.greasegun);
        inventory [60] = ThingFactory.MakeThing(ThingTypes.shovel);
        inventory [61] = ThingFactory.MakeThing(ThingTypes.wirecutters);
        inventory [62] = ThingFactory.MakeThing(ThingTypes.wrench);
        inventory [63] = ThingFactory.MakeThing(ThingTypes.solderinggun);
    }
Exemple #23
0
 public bool IsTool()
 {
     return(ThingFactory.IsTool(thingType));
 }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.session = new Mock <ISession>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.permissionService            = new Mock <IPermissionService>();
            this.path = Path.Combine(TestContext.CurrentContext.TestDirectory, "ReqIf", "testreq.reqif");
            this.fileDialogService = new Mock <IOpenSaveFileDialogService>();
            this.fileDialogService.Setup(x => x.GetOpenFileDialog(true, true, false, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), 1)).Returns(new string[] { this.path });
            this.reqIf = new ReqIF {
                Lang = "en"
            };
            this.reqIf.TheHeader = new ReqIFHeader()
            {
                Identifier = Guid.NewGuid().ToString()
            };
            var corecontent = new ReqIFContent();

            this.reqIf.CoreContent = corecontent;
            this.stringDatadef     = new DatatypeDefinitionString();
            this.spectype          = new SpecificationType();
            this.attribute         = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.spectype.SpecAttributes.Add(this.attribute);

            corecontent.DataTypes.Add(this.stringDatadef);
            this.settings = new RequirementsModuleSettings()
            {
                SavedConfigurations = { new ImportMappingConfiguration()
                                        {
                                            ReqIfId = this.reqIf.TheHeader.Identifier
                                        } }
            };
            this.pluginSettingService = new Mock <IPluginSettingsService>();
            this.pluginSettingService.Setup(x => x.Read <RequirementsModuleSettings>(It.IsAny <bool>(), It.IsAny <JsonConverter[]>())).Returns(this.settings);
            this.pluginSettingService.Setup(x => x.Write(It.IsAny <PluginSettings>(), It.IsAny <JsonConverter[]>()));

            this.reqIfSerialiser = new Mock <IReqIFDeSerializer>();
            this.reqIfSerialiser.Setup(x => x.Deserialize(It.IsAny <string>(), It.IsAny <bool>(), null)).Returns(new[] { this.reqIf });
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString());
            this.assembler = new Assembler(this.uri);

            this.sitedir        = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.modelsetup     = new EngineeringModelSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.domain         = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.sitedir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);

            this.model = new EngineeringModel(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                IterationSetup = this.iterationSetup
            };

            this.sitedir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationSetup);
            this.sitedir.Domain.Add(this.domain);
            this.model.Iteration.Add(this.iteration);

            this.person      = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.participant = new Participant(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Person = this.person
            };
            this.sitedir.Person.Add(this.person);
            this.modelsetup.Participant.Add(this.participant);

            this.pt = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.srdl.ParameterType.Add(this.pt);

            this.session.Setup(x => x.ActivePerson).Returns(this.person);
            this.session.Setup(x => x.OpenIterations).Returns(new Dictionary <Iteration, Tuple <DomainOfExpertise, Participant> > {
                { this.iteration, new Tuple <DomainOfExpertise, Participant>(this.domain, this.participant) }
            });

            this.assembler.Cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy <Thing>(() => this.iteration));

            this.serviceLocator = new Mock <IServiceLocator>();
            this.serviceLocator.Setup(x => x.GetInstance <IPluginSettingsService>()).Returns(this.pluginSettingService.Object);
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);

            var thingFactory = new ThingFactory(this.iteration, new Dictionary <DatatypeDefinition, DatatypeDefinitionMap>(), new Dictionary <SpecType, SpecTypeMap>(), this.domain);

            this.dialog = new RequirementSpecificationMappingDialogViewModel(thingFactory, this.iteration, this.session.Object, this.thingDialogNavigationService.Object, this.dialogNavigationService.Object, "EN", this.settings.SavedConfigurations[0] as ImportMappingConfiguration);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.sitedir);
        }
Exemple #25
0
    private Thing GetSelectedBlueprintThing()
    {
        BlueprintDesign bd = Toolbar.GetBlueprintWindow().GetSelectedBlueprintDesign();

        return(ThingFactory.MakeThing(bd.thingType));
    }
Exemple #26
0
    public void AddTool(ThingTypes requiredThingType, float energyPerNode, int replacedNodeCount)
    {
        string nodeSubstring = ThingFactory.GetKeyFromThingType(requiredThingType);

        AddTool(requiredThingType, energyPerNode, replacedNodeCount, nodeSubstring);
    }
        public void Happypath()
        {
            var popCenter = new SiteDefinition()
            {
                Name        = "Population Center",
                Description = "A center of population.",
            };

            popCenter.Attributes["Evil"] = new AttributeDefinition()
            {
                BaseValue = "Rand.Next(-5, 5)"
            };
            popCenter.Attributes["Population"] = new AttributeDefinition()
            {
                BaseValue = "Rand.Next(0, 1000000)"
            };

            var cityDef = new SiteDefinition()
            {
                Name         = "City",
                Description  = "A moderate sized settlement",
                InheritsFrom = "Population Center",
            };

            cityDef.Attributes["Population"] = new AttributeDefinition()
            {
                BaseValue = "Rand.Next(20000, 100000)"
            };

            IList <SiteDefinition> sites = new List <SiteDefinition>
            {
                popCenter,
                cityDef,
            };

            var definitions = new DefinitionCollection(sites);

            int    worldSeed = 915434125;
            Random rdm       = new Random(worldSeed);

            ConditionCompiler <BaseGlobalVariables> processor = new ConditionCompiler <BaseGlobalVariables>(new BaseGlobalVariables()
            {
                World = new Contracts.World(),
            });

            definitions.Attach(processor);
            ThingFactory factory = new ThingFactory(definitions);

            for (int i = 0; i < 100; i++)
            {
                Site city = factory.CreateSite(rdm, 0, 0, "City");
                city.FinalizeConstruction(rdm);
                Console.WriteLine($"City created: {city.EffectiveAttribute("Population")} {city.EffectiveAttribute("Evil")}");

                Assert.AreEqual(ThingType.Site, city.ThingType);
                Assert.AreEqual(cityDef, city.Definition);
                int population = city.EffectiveAttribute("Population");
                Assert.IsTrue(population <= 100000);
                Assert.IsTrue(population >= 20000);
                int evil = city.EffectiveAttribute("Evil");
                Assert.IsTrue(evil <= 5);
                Assert.IsTrue(evil >= -5);
            }
        }
 public ThingManager(ThingFactory factory)
 {
     _factory = factory;
     _locks   = new ConditionalWeakTable <Thing, object>();
 }
Exemple #29
0
    public void AddThing(ThingTypes requiredThingType, int quantityPerNode, int replacedNodeCount)
    {
        string nodeSubstring = ThingFactory.GetKeyFromThingType(requiredThingType);

        AddThing(requiredThingType, quantityPerNode, replacedNodeCount, nodeSubstring);
    }