void StartConstructionJobButton()
    {
        // Get resource list
        ResourceQuantityQualityList jobResources = resourceChoiceDropdown.GetCurrentChoices();

        JobDef newConstructionJobDef = CreateConstructionJobDef(jobResources, resourceChoiceDropdown.taskName);

        BuildingJobObj newJob = jobManager.AddConstructionJob(newConstructionJobDef, iLoc, jLoc);

        newJob.SetResources(jobResources);
        newJob.StartJob();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();

        // Change surface type to construction
        ManagerBase.domain.mapData.SetSurfaceValue(iLoc, jLoc, ManagerBase.surfaceValueDictionary["Gear"]);

        // Reload the map and re-focus on the tile
        WorldEventHandlerManager.Broadcast(worldEventChannels.map, mapChannelEvents.change, new WorldEventArg(iLoc, jLoc));
    }
Beispiel #2
0
    // Use this for initialization
    void Awake()
    {
        resourceDefinitions         = new List <ResourceDef>();
        ManagerBase.resourceIndexOf = new Dictionary <string, int>();
        string m_Path = Application.dataPath;
        //print(m_Path + "/Definitions/Resources.csv");
        List <string> lines = new List <string>();

        using (var reader = new StreamReader(m_Path + "/Definitions/Resources.csv"))
        {
            // Read the header
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                lines.Add(reader.ReadLine());
            }
        }

        // Create each resource definition
        foreach (var csvLine in lines)
        {
            resourceDefinitions.Add(new ResourceDef(csvLine));
            ManagerBase.resourceIndexOf.Add(resourceDefinitions[resourceDefinitions.Count - 1].name, resourceDefinitions.Count - 1);
        }

        // Initialize the domain's stock
        if (ManagerBase.domain == null)
        {
            ManagerBase.domain = new Domain();
        }
        ManagerBase.domain.stock = new ResourceStock(resourceDefinitions);

        resourceUI.resourceNameSpriteDict = new Dictionary <string, Sprite>();
        foreach (ResourceDef rd in resourceDefinitions)
        {
            resourceUI.resourceNameSpriteDict.Add(rd.name, rd.image);
        }
        resourceUI.domain = ManagerBase.domain;


        resourceUI.enabled       = false;
        resourceUiCanvas.enabled = false;

        // Add a few resources
        ResourceQuantityQualityList startingResources = new ResourceQuantityQualityList();

        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Cow", QualityEnum.normal, 10));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Pine", QualityEnum.normal, 100));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Pine", QualityEnum.good, 50));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Limestone", QualityEnum.normal, 75));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Marble", QualityEnum.normal, 25));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Iron", QualityEnum.normal, 75));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Coarse Sand", QualityEnum.normal, 100));
        startingResources.rqqList.Add(new ResourceNameQuantityQuality("Iron Anvil", QualityEnum.normal, 1));

        startingResources.AddResources(ManagerBase.domain.stock);
    }
    public ResourceQuantityQualityList GetCurrentChoices()
    {
        ResourceQuantityQualityList currentChoices = new ResourceQuantityQualityList();
        int ind = 0;

        foreach (DropdownUIElement rd in elements)
        {
            currentChoices.rqqList.Add(new ResourceNameQuantityQuality(rd.defName, QualityEnum.any, choiceRqqList.rqqList[ind].quantity));
            ind++;
        }
        return(currentChoices);
    }
    void StartJobButton(JobDef jobSelected)
    {
        thisBuilding = BuildingQueries.ByLocation(ManagerBase.domain.buildings, new Vector2Int(iLoc, jLoc)); // Update the building here
        ResourceJobObj newJob = jobManager.AddJob(jobSelected, thisBuilding);
        ResourceQuantityQualityList jobResources = resourceChoiceDropdown.GetCurrentChoices();

        newJob.SetResources(jobResources);
        newJob.StartJob();
        newJob.AddWorker();
        newJob.AddWorker();
        FocusOnTile(iLoc, jLoc);
    }
    private JobDef CreateConstructionJobDef(ResourceQuantityQualityList jobResources, string taskName)
    {
        BuildingDef bd = BuildingQueries.ByName(ManagerBase.buildingDefinitions, taskName).ElementAt(0);
        JobDef      constructionJob = new JobDef();

        constructionJob.name           = "Construction of " + taskName;
        constructionJob.description    = "Construction of " + taskName;
        constructionJob.industry       = "Construction";
        constructionJob.skill          = "Building";
        constructionJob.tier           = bd.tier;
        constructionJob.defaultPMUs    = bd.defaultPMUs;
        constructionJob.inputResources = jobResources;
        constructionJob.outputName     = new List <string>();
        constructionJob.outputName.Add(taskName);
        //List<int> defaultOutputQuantity;

        return(constructionJob);
    }
Beispiel #6
0
    // Set the resource list
    public bool SetResources(ResourceQuantityQualityList input)
    {
        // Check that they're all nqqs
        foreach (ResourceQuantityQuality rqq in input.rqqList)
        {
            if (!(rqq is ResourceNameQuantityQuality))
            {
                return(false);
            }
        }

        float qualityMultiplier = input.CheckResourcesQuality(stock);
        float tierMultiplier    = 1; // Needs to be updated

        this.inputMaterialQualityMultiplier = qualityMultiplier * tierMultiplier;

        this.inputResources = input;

        return(true);
    }
    void StartDemolitionJobButton()
    {
        //Debug.Log("StartDemolitionJobButton");
        short  surfaceValue = ManagerBase.domain.mapData.GetSurfaceValue(iLoc, jLoc);
        string surfaceType  = ManagerBase.surfaceValueDictionary.FirstOrDefault(x => x.Value == surfaceValue).Key;

        JobDef newDemolitionJobDef = CreateDemolitionJobDef(surfaceType);

        ResourceQuantityQualityList jobResources = new ResourceQuantityQualityList();

        //Debug.Log("AddDemolitionJob");
        DemoJobObj newJob = jobManager.AddDemolitionJob(newDemolitionJobDef, iLoc, jLoc);

        //Debug.Log("SetResources");
        newJob.SetResources(jobResources);
        newJob.StartJob();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();
        newJob.AddWorker();

        // Change surface type to construction
        //Debug.Log("SetSurfaceValue");
        ManagerBase.domain.mapData.SetSurfaceValue(iLoc, jLoc, ManagerBase.surfaceValueDictionary["Cancel"]);

        // Reload the map and re-focus on the tile
        //Debug.Log("Broadcast");
        WorldEventHandlerManager.Broadcast(worldEventChannels.map, mapChannelEvents.change, new WorldEventArg(iLoc, jLoc));

        //Debug.Log("Done StartDemolitionJobButton");
    }
Beispiel #8
0
    override public void UpdateJob(float deltaTimeSeconds)
    {
        // Don't update inactive or unset jobs
        if (!this.isSet || !this.isActive)
        {
            return;
        }

        // Check if it has started
        if (!this.hasStarted)
        { // Not started:
          // Check that there are enough resources
            if (!inputResources.CheckResources(stock))
            {
                // This will eventually need to be an event
                Debug.Log("Not enough resources to start job - waiting");
                return;
            }

            // There are enough resources
            // Remove the resources and recalculate the qualityMultiplier
            float qualityMultiplier = inputResources.RemoveResources(stock);
            float tierMultiplier    = 1; // Needs to be updated
                                         // Update the quality multiplier
            this.inputMaterialQualityMultiplier = qualityMultiplier * tierMultiplier;
            // Reset the PMUs
            this.workPMUsRemaining = this.jobDef.defaultPMUs;
            // Set it to started!
            this.hasStarted = true;
            Debug.Log("Resource Job: " + jobDef.name + " being set to started");
        }
        else
        {                                                                  // Has started
          // Add PMUs
            float addedPMUs = this.currentPMURate * deltaTimeSeconds / 60; // div by 60 to convert to minutes (PMUs)
            this.workPMUsRemaining -= addedPMUs;
            // Accumulate quality
            this.accumulatedQualityPoints += this.buildingBonusQuantityMultiplier * this.leaderBonusQuantityMultiplier * this.inputMaterialQualityMultiplier *
                                             (addedPMUs / this.jobDef.defaultPMUs); // Quality multipliers normalized by work fraction
                                                                                    // Probably need to normalize this by tier of the product as well, but this needs a formula

            // If it's done?
            if (this.workPMUsRemaining <= 0)
            {
                this.hasStarted = false;
                ResourceQuantityQualityList products = new ResourceQuantityQualityList();

                // Allow for multiple outputs
                for (int i = 0; i < this.jobDef.outputName.Count; i++)
                {
                    int outputQuantity = Mathf.RoundToInt(this.jobDef.defaultOutputQuantity[i] * this.buildingBonusQuantityMultiplier * this.leaderBonusQuantityMultiplier);
                    // Add the resource
                    products.rqqList.Add(new ResourceNameQuantityQuality(
                                             this.jobDef.outputName[i], QualityEnum.normal,
                                             outputQuantity));
                }
                products.AddResources(stock);
                // Need to trigger an event here for display of done
            }
            Debug.Log("Resource Job: " + jobDef.name + " going with " + this.workPMUsRemaining.ToString() + " PMUs left");
        }
    }
Beispiel #9
0
    private static ResourceDropdown Create(Transform parent, Vector3 localPosition, ResourceQuantityQualityList choiceRqqList, string taskName, Domain domain, bool isStatic)
    {
        GameObject       newGo            = new GameObject("Resource Dropdown");
        ResourceDropdown resourceDropdown = newGo.AddComponent <ResourceDropdown>();

        resourceDropdown.choiceRqqList = choiceRqqList;
        resourceDropdown.taskName      = taskName;
        resourceDropdown.domain        = domain;

        int resInd = 0;

        foreach (ResourceQuantityQuality rqq in choiceRqqList.rqqList)
        {
            Dictionary <string, Sprite> stringSprite = rqq.GetImageOptions(rqq.minTier);

            // Create the button
            resourceDropdown.elements.Add(UIElementFunctions.Dropdown(parent, null, "", localPosition, new Vector2(64, 64)));
            //resourceDropdown[resInd].transform.localPosition = localPosition;

            localPosition.x += imageSize * 3 / 2;
            resourceDropdown.elements[resInd].thisGo.name = "Resource Dropdown Item";
            resourceDropdown.elements[resInd].childHeight = imageSize;

            int ind = 0;
            foreach (KeyValuePair <string, Sprite> entry in stringSprite)
            {
                ResourceNameQuantityQuality nqq = new ResourceNameQuantityQuality(entry.Key, QualityEnum.any, rqq.quantity);

                if (ind == 0)
                {
                    resourceDropdown.elements[resInd].imageGo.sprite = entry.Value;
                    resourceDropdown.elements[resInd].textGo.text    = "";
                    resourceDropdown.elements[resInd].defName        = entry.Key;
                }
                if (!isStatic)
                {
                    resourceDropdown.elements[resInd].AddChild();
                    resourceDropdown.elements[resInd].children[ind].tooltipData    = entry.Key;
                    resourceDropdown.elements[resInd].children[ind].defName        = entry.Key;
                    resourceDropdown.elements[resInd].children[ind].imageGo.sprite = entry.Value;
                }

                if (!nqq.CheckResource(domain.stock))
                {
                    if (ind == 0)
                    {
                        resourceDropdown.elements[resInd].imageGo.color = Color.red;
                        resourceDropdown.elements[resInd].allowed       = false;
                    }
                    if (!isStatic)
                    {
                        resourceDropdown.elements[resInd].children[ind].imageGo.color         = Color.red;
                        resourceDropdown.elements[resInd].children[ind].buttonGo.interactable = false;
                        resourceDropdown.elements[resInd].children[ind].allowed = false;
                    }
                }
                if (!isStatic)
                {
                    resourceDropdown.elements[resInd].children[ind].textGo.text = "";
                }

                // Add a quantity text
                string          quantityString = rqq.quantity.ToString();
                CustomUIElement temp           = UIElementFunctions.TextOnly(resourceDropdown.elements[resInd].thisGo.transform, quantityString, new Vector3(0, imageSize - 20), new Vector2(imageSize, 20F));
                temp.textGo.alignment = TextAnchor.MiddleCenter;

                ind++;
            }
            resInd++;
        }
        return(resourceDropdown);
    }
Beispiel #10
0
    public static ResourceDropdown CreateResourceChoiceDropdown(Transform parent, Vector3 localPosition, ResourceQuantityQualityList choiceRqqList, string taskName, Domain domain, Sprite resultSprite)
    {
        ResourceDropdown rd = Create(parent, localPosition, choiceRqqList, taskName, domain, false);

        AddUiElements(rd, parent, resultSprite, false);
        return(rd);
    }
Beispiel #11
0
    // Constructor
    public JobDef(string csvLine, Dictionary <string, List <int> > column)
    {
        guid = Guid.NewGuid();

        inputResources        = new ResourceQuantityQualityList();
        outputName            = new List <string>();
        defaultOutputQuantity = new List <int>();

        string[] values = csvLine.Split(',');

        // Job Name
        if (values[column["Job Name"][0]].Length > 0)
        {
            name = values[column["Job Name"][0]];
        }

        // Description
        if (values[column["Description"][0]].Length > 0)
        {
            description = values[column["Description"][0]];
        }

        //Industry,Skill
        if (values[column["Industry"][0]].Length > 0)
        {
            industry = values[column["Industry"][0]];
        }

        if (values[column["Skill"][0]].Length > 0)
        {
            skill = values[column["Skill"][0]];
        }

        // Tier
        if (values[column["Tier"][0]].Length > 0)
        {
            if (!Int32.TryParse(values[column["Tier"][0]], out tier))
            {
                Debug.Log("Cannot Parse Job Tier");
            }
        }

        // Tiles Required
        if (values[column["Tiles Required"][0]].Length > 0)
        {
            tileRequired = values[column["Tiles Required"][0]];
        }

        // Max Workers
        if (values[column["Work PMU"][0]].Length > 0)
        {
            if (!Single.TryParse(values[column["Work PMU"][0]], out defaultPMUs))
            {
                Debug.Log("Cannot Parse Work PMU");
            }
        }

        // Resources to Craft
        List <int> inputName  = column["Input Name"];
        List <int> inputType  = column["Input Type"];
        List <int> inputTier  = column["Input Tier"];
        List <int> inputQuant = column["Input Quantity"];

        for (int i = 0; i < inputName.Count; i++)
        {
            // Check for NQQ
            if (values[inputName[i]].Length > 0)
            {
                string name = values[inputName[i]];
                int    quantity;
                if (!Int32.TryParse(values[inputQuant[i]], out quantity))
                {
                    Debug.Log("Cannot Parse Input Quantity: " + values[inputQuant[i]]);
                }
                ResourceNameQuantityQuality nqq = new ResourceNameQuantityQuality(name, QualityEnum.any, quantity);
                inputResources.rqqList.Add(nqq);
                // Error check
                if (values[inputType[i]].Length > 0)
                {
                    Debug.LogWarning("Job Definition file should not have both Name and Type of a Job Input Resource");
                }
            }
            // check for TQQ
            else if (values[inputType[i]].Length > 0)
            {
                string type = values[inputType[i]];
                int    quantity, minTier;
                if (!Int32.TryParse(values[inputQuant[i]], out quantity))
                {
                    Debug.Log("Cannot Parse Input Quantity: " + values[inputQuant[i]]);
                }
                if (!Int32.TryParse(values[inputTier[i]], out minTier))
                {
                    Debug.Log("Cannot Parse Input Tier: " + values[inputTier[i]]);
                }
                ResourceTypeQuantityQuality tqq = new ResourceTypeQuantityQuality(type, QualityEnum.any, quantity, minTier);
                inputResources.rqqList.Add(tqq);
            }
        }

        // Output Resources
        List <int> outputNameC     = column["Output Name"];
        List <int> outputQuantityC = column["Output Quantity"];

        for (int i = 0; i < outputNameC.Count; i++)
        {
            // Output Name
            if (values[outputNameC[i]].Length > 0)             // There is an output in this column
            {
                outputName.Add(values[column["Output Name"][0]]);
                int q = 0;
                if (!Int32.TryParse(values[outputQuantityC[i]], out q))
                {
                    Debug.Log("Cannot Parse Output Quantity");
                }
                defaultOutputQuantity.Add(q);
            }
        }
    }
Beispiel #12
0
    // Constructor
    public BuildingDef(List <string> csvLines, Dictionary <string, int> column)
    {
        resourcesToBuild = new ResourceQuantityQualityList();
        industry         = new List <string>();
        skill            = new List <string>();
        jobsEnabled      = new List <string>();
        jobMaxTier       = new Dictionary <string, int>();

        foreach (string line in csvLines)
        {
            string[] values = line.Split(',');

            // Current keys into column
            //Debug.Log(line);

            // Name
            if (values[column["Name"]].Length > 0)
            {
                name = values[column["Name"]];
            }

            // Category
            if (values[column["Category"]].Length > 0)
            {
                category = values[column["Category"]];
            }

            // Parent Name
            if (values[column["Parent Name"]].Length > 0)
            {
                parentName = values[column["Parent Name"]];
            }

            // Tier
            if (values[column["Tier"]].Length > 0)
            {
                if (!Int32.TryParse(values[column["Tier"]], out tier))
                {
                    Debug.Log("Cannot Parse Building Tier");
                }
            }

            // Description
            if (values[column["Description"]].Length > 0)
            {
                description = values[column["Description"]];
            }

            // Resource Type to Build
            if (values[column["Resource Type to Build"]].Length > 0)
            {
                int c, t;
                if (!Int32.TryParse(values[column["Resource Count"]], out c))
                {
                    Debug.Log("Cannot Parse Resource Count \"" + values[column["Resource Count"]] + "\"");
                }
                if (!Int32.TryParse(values[column["Min Resource Tier"]], out t))
                {
                    Debug.Log("Cannot Parse Min Resource Tier \"" + values[column["Min Resource Tier"]] + "\"");
                }

                ResourceTypeQuantityQuality tqq = new ResourceTypeQuantityQuality(
                    values[column["Resource Type to Build"]], QualityEnum.any, c, t);

                resourcesToBuild.rqqList.Add(tqq);
            }

            // Max Workers
            if (values[column["Max Workers"]].Length > 0)
            {
                if (!Int32.TryParse(values[column["Max Workers"]], out maxWorkers))
                {
                    Debug.Log("Cannot Parse Max Workers");
                }
            }

            // Max HP
            if (values[column["Max HP"]].Length > 0)
            {
                if (!Int32.TryParse(values[column["Max HP"]], out maxHp))
                {
                    Debug.Log("Cannot Parse Max HP");
                }
            }

            // Housing
            if (values[column["Housing"]].Length > 0)
            {
                if (!Int32.TryParse(values[column["Housing"]], out housing))
                {
                    Debug.Log("Cannot Parse Housing");
                }
            }

            // Housing
            if (values[column["Maintenance Cost"]].Length > 0)
            {
                if (!Int32.TryParse(values[column["Maintenance Cost"]], out maintenanceCost))
                {
                    Debug.Log("Cannot Parse Maintenance Cost");
                }
            }

            // Housing
            if (values[column["Default Max Dist"]].Length > 0)
            {
                if (!Int32.TryParse(values[column["Default Max Dist"]], out defaultMaxDistToWorkTiles))
                {
                    Debug.Log("Cannot Parse Default Max Dist");
                }
            }

            //Industries,Skills
            if (values[column["Industries"]].Length > 0)
            {
                industry.Add(values[column["Industries"]]);
            }
            if (values[column["Skills"]].Length > 0)
            {
                skill.Add(values[column["Skills"]]);
            }

            // PMUs to Build
            if (values[column["PMUs to Build"]].Length > 0)
            {
                if (!Single.TryParse(values[column["PMUs to Build"]], out defaultPMUs))
                {
                    Debug.Log("Cannot Parse PMUs to Build");
                }
            }

            if (sprite == null)
            {
                Texture2D tex;
                if (values[column["Image"]].Length == 0)
                {
                    tex = (Resources.Load("Textures/NeedIcon") as Texture2D);
                }
                else
                {
                    tex = (Resources.Load(values[column["Image"]]) as Texture2D);
                }
                sprite = Sprite.Create(tex,
                                       new Rect(0, 0, tex.width, tex.height),
                                       new Vector2(0.5f, 0.5f), tex.width);
            }

            // Job Name, Job Max Tier
            if (values[column["Job Name"]].Length > 0)
            {
                jobsEnabled.Add(values[column["Job Name"]]);
                jobMaxTier[values[column["Job Name"]]] = Int32.Parse(values[column["Job Max Tier"]]);
            }
        }
    }