Exemple #1
0
    // Use this for initialization
    void Start()
    {
        // Subscribe to tile change updates
        WorldEventHandler pmc = new WorldEventHandler(TileUpdated);

        WorldEventHandlerManager.AddListener(worldEventChannels.map, mapChannelEvents.change, pmc);
    }
    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));
    }
    override public void UpdateJob(float deltaTimeSeconds)
    {
        //if (!this.isSet)
        //    Debug.Log("Demo Job: " + jobDef.name + " is NOT set");
        //if (!this.isActive)
        //    Debug.Log("Demo Job: " + jobDef.name + " is NOT active");

        // Don't update inactive or unset jobs
        if (!this.isSet || !this.isActive)
        {
            return;
        }

        // Check if it has started
        if (!this.hasStarted)
        {
            // Reset the PMUs
            this.workPMUsRemaining = this.jobDef.defaultPMUs;
            // Set it to started!
            this.hasStarted = true;
            Debug.Log("Demo Job: " + jobDef.name + " being set to started");
        }
        else
        {   // Has started
            // Add PMUs

            float addedPMUs = this.currentPMURate * deltaTimeSeconds / 60.0F; // div by 60 to convert to minutes (PMUs)
            this.workPMUsRemaining -= addedPMUs;
            // Accumulate quality

            // If it's done?
            if (this.workPMUsRemaining <= 0)
            {
                // Change surface type
                ManagerBase.domain.mapData.SetSurfaceValue(iLoc, jLoc, ManagerBase.surfaceValueDictionary["Nothing"]);

                // Remove workers, clear the job
                while (this.numWorkers > 0)
                {
                    this.RemoveWorker();
                }
                this.toDelete = true;

                // Reload the map
                WorldEventHandlerManager.Broadcast(worldEventChannels.map, mapChannelEvents.change, new WorldEventArg(iLoc, jLoc));

                // Complete the job
                string message = jobDef.name + " at (" + iLoc.ToString() + "," + jLoc.ToString() + ")";
                ManagerBase.domain.eventManager.Broadcast(domainEventChannels.job, jobChannelEvents.constructionComplete, new DomainEventArg(message, iLoc, jLoc));
            }
            Debug.Log("Demo Job: " + jobDef.name + " going with " + this.workPMUsRemaining.ToString() + " PMUs left");
            Debug.Log("   PMU Rate: " + this.currentPMURate.ToString() + ", just added: " + addedPMUs.ToString());
        }
    }
Exemple #4
0
    void Start()
    {
        // Initialize the Domain and MapData
        if (domain == null)
        {
            domain = new Domain();
        }
        N = mapGenerator.GetN();
        domain.mapData = new MapData(N);

        // Load in the tiles
        LoadTiles();

        //Generate the map
        mapGenerator.GenerateMap(domain.mapData);

        // Draw the ground & surface tiles
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                groundTileMap.SetTile(new Vector3Int(i, j, 0), groundTiles[domain.mapData.GetGroundValue(i, j)]);
                if (domain.mapData.GetSurfaceValue(i, j) >= 0)
                {
                    surfaceTileMap.SetTile(new Vector3Int(i, j, 0), surfaceTiles[domain.mapData.GetSurfaceValue(i, j)]);
                }
            }
        }

        // Draw the underground tiles
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                undergroundTileMap.SetTile(new Vector3Int(i, j, 0), undergroundTiles[domain.mapData.GetUndergroundValue(i, j)][domain.mapData.GetStoneValue(i, j)]);
            }
        }
        undergroundTileMap.GetComponent <Renderer>().enabled = false;

        WorldEventHandler pmc = new WorldEventHandler(ProcessMapChange);

        WorldEventHandlerManager.AddListener(worldEventChannels.map, mapChannelEvents.change, pmc);
    }
    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");
    }
    override public void UpdateJob(float deltaTimeSeconds)
    {
        //if (!this.isSet)
        //    Debug.Log("Construction Job: " + jobDef.name + " is NOT set");
        //if (!this.isActive)
        //    Debug.Log("Construction Job: " + jobDef.name + " is NOT active");

        // 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("Construction Job: " + jobDef.name + " being set to started");
        }
        else
        {   // Has started
            // Add PMUs

            float addedPMUs = this.currentPMURate * deltaTimeSeconds / 60.0F; // 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)
            {
                // Need to trigger an event here for display of done

                // Change surface type
                ManagerBase.domain.mapData.SetSurfaceValue(iLoc, jLoc, ManagerBase.surfaceValueDictionary[jobDef.outputName[0]]);

                // Remove workers, clear the job
                while (this.numWorkers > 0)
                {
                    this.RemoveWorker();
                }
                this.toDelete = true;

                // Reload the map
                WorldEventHandlerManager.Broadcast(worldEventChannels.map, mapChannelEvents.change, new WorldEventArg(iLoc, jLoc));

                // Complete the job
                string message = jobDef.name + " at (" + iLoc.ToString() + "," + jLoc.ToString() + ")";
                ManagerBase.domain.eventManager.Broadcast(domainEventChannels.job, jobChannelEvents.constructionComplete, new DomainEventArg(message, iLoc, jLoc));

                BuildingDef thisBuildingDef = ManagerBase.buildingDefinitions[ManagerBase.buildingIndexOf[jobDef.outputName[0]]];

                ManagerBase.domain.buildingManager.AddBuilding(new Vector2Int(iLoc, jLoc), thisBuildingDef, QualityEnum.normal);
            }
            Debug.Log("Construction Job: " + jobDef.name + " going with " + this.workPMUsRemaining.ToString() + " PMUs left");
            Debug.Log("   PMU Rate: " + this.currentPMURate.ToString() + ", just added: " + addedPMUs.ToString());
        }
    }