protected void BtnImport_Click(object sender, EventArgs e)
    {
        PageBase page = (PageBase)this.Page;

        if (UpdFile.PostedFile.FileName != "")
        {
            string timeStr = DateTime.Now.ToString("yyyyMMddhhmmss");
            string filePath = Request.PhysicalApplicationPath + @"Export\" + "jobstructure"+ timeStr +".xls" ;
            UpdFile.SaveAs(filePath);

            string errorMessage;
            string[] sheetNames = ExcelHelper.GetExcelSheetNames(filePath);

            DataSet ds = ExcelHelper.GetDataSetFromExcel(filePath, sheetNames[0], out errorMessage);

            JobStructure job = new JobStructure();
            bool b = job.ImportJobStructure(ds, out errorMessage);
            if (!b)
                page.Alert(errorMessage);
            else
                page.Alert(new RM(ResourceFile.Msg)["SaveSuccess"]);

            DataView dv = ds.Tables[0].DefaultView;
            dv.RowFilter = "pOut = 0";

            if (dv.Count > 0)
            {
                GrdList.DataSource = dv;
                GrdList.DataBind();
            }

            File.Delete(filePath);
        }
    }
Exemplo n.º 2
0
    public void GiveJob(JobStructure j)
    {
        job   = j;
        state = State.Walking;
        GC.inst.idleWorkers.Remove(this);
        UIController.inst.UpdateIdleWorkerText();

        job.beingWorked = true;
    }
Exemplo n.º 3
0
    void Update()
    {
        float dt = Time.deltaTime;

        if (state == State.Walking)
        {
            // Get vector to destination.
            Vector2 delta = new Vector2(job.transform.position.x - transform.position.x, job.transform.position.y - transform.position.y);


            // Work out our current move speed.
            float curMoveSpeed;

            // See if the tile type we are over is water.
            if (GC.inst.map.GetTileAt(GC.inst.GetHexCoordAt(transform.position)).tileType == "water")
            {
                curMoveSpeed = waterMoveSpeed;
            }
            else
            {
                curMoveSpeed = grassMoveSpeed;
            }

            float distanceToMove = curMoveSpeed * dt;

            // If we are going to overshoot just being in range this frame, then just move close enough, and use the extra time working.
            if (delta.magnitude - closeEnough < distanceToMove)
            {
                distanceToMove = delta.magnitude - closeEnough;

                dt -= distanceToMove / curMoveSpeed;

                state    = State.Working;
                progress = 0f;
                bar      = ProgressBar.CreateBar(transform.position, transform);
            }

            // Move the calculated distance.
            transform.Translate(delta.normalized * distanceToMove);
        }

        // If we are working...
        if (state == State.Working)
        {
            progress += dt / job.jobDuration;

            if (progress >= 1f)
            {
                Destroy(bar.gameObject);

                // Add any resources that get added on completion.
                if (job.getAmountGained != null)
                {
                    int prop = 1;
                    if (job.amountGainedPropToSat)
                    {
                        prop = 2 + GC.inst.map.GetTileAt(GC.inst.GetHexCoordAt(transform.position)).saturation;
                    }

                    GC.inst.rs.Add(job.resourceGainedOnComplete, prop * job.getAmountGained());
                }

                // If the job was a tree job, remove the number of trees on that tile.
                if (job.removeTreeOnComplete)
                {
                    GC.inst.map.GetTileAt(GC.inst.GetHexCoordAt(transform.position)).nTrees -= 1;
                }

                // If this job destroys the game object it is connected to, destroy it.
                if (job.hoverObject != null)
                {
                    Destroy(job.hoverObject);
                    job.hoverObject = null;
                }

                if (job.destroyOnJobFinish)
                {
                    job.Demolish();
                }

                // Otherwise set it to not being worked anymore.
                else
                {
                    job.beingWorked = false;
                }

                // Run the function that it is to be run on completion.
                if (job.onJobFinished != null)
                {
                    job.onJobFinished();
                }

                JobStructure js = job;

                SetIdle();

                // See if the worker dies...
                if (Random.Range(0f, 1f) < js.deathChance)
                {
                    Die();
                    return;
                }
            }
            else
            {
                bar.SetProgress(1f - progress);
            }
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        // Follow the mouse!
        transform.position = new Vector3(mousePos.x, mousePos.y, -7);

        // When the mouse button is pressed...
        if (Input.GetMouseButtonDown(0))
        {
            // This becomes a worksite... provided that the building materials are all there.
            foreach (RStack stack in bt.buildCost)
            {
                if (GC.inst.rs.Get(stack.resource) < stack.amount)
                {
                    Destroy(gameObject);
                    print("Not enough resources!");
                    return;
                }
            }

            // Find the current hex.
            Coord c = GC.inst.GetHexCoordAt(transform.position);
            if (c == null)
            {
                Destroy(gameObject);
                return;
            }

            // Double check that this is a valid hex, and if not simply return.
            Tile t = GC.inst.map.GetTileAt(c);
            if (t == null || t.tileType == "water" || t.nTrees > 0 || t.structure != null)
            {
                Destroy(gameObject);
                if (t == null)
                {
                    print("Tile null");
                }
                else if (t.tileType == "water")
                {
                    print("Water");
                }
                else if (t.nTrees > 0)
                {
                    print("Trees = " + t.nTrees.ToString());
                }
                else if (t.structure != null)
                {
                    print("Structure = " + t.structure);
                }
                return;
            }

            // Use up building materials.
            foreach (RStack stack in bt.buildCost)
            {
                GC.inst.rs.Add(stack.resource, -stack.amount);
            }

            // Move the ghost to the hex center.
            transform.position = c.GetWorldCoords() + Vector3.back;

            // Set a bulding site structure here so that no other buildings can be scheduled to be placed here.
            t.structure = "buildingSite";

            // Add a job structure here, and assign a worker to it.
            JobStructure js = gameObject.AddComponent <JobStructure> ();

            // Set all of the variables of the job structure.
            js.jobDuration              = bt.buildTime;
            js.deathChance              = 0f;
            js.destroyOnJobFinish       = false;
            js.resourceGainedOnComplete = "";
            js.getAmountGained          = null;

            // Setup what happens on job finish.
            js.onJobFinished = () => {
                GameObject go = js.gameObject;

                // Make fully opaque.
                go.GetComponent <SpriteRenderer>().color = Color.white;

                // Generate people equal to housing.
                Coord cd = GC.inst.GetHexCoordAt(go.transform.position);
                for (int i = 0; i < bt.houses; i++)
                {
                    GC.inst.GenerateWorkerAt(cd);
                }

                // Delete the old job structure.
                Destroy(js);

                // Create a new job structure, if this structure has a job associated with it.
                if (bt.jobDuration >= 0)
                {
                    JobStructure njs = go.AddComponent <JobStructure>();
                    njs.jobSymbol   = Resources.Load <Sprite>(bt.hoverSymbolName);
                    njs.jobDuration = bt.jobDuration;
                    njs.deathChance = bt.jobDeathChance;
                    njs.resourceGainedOnComplete = bt.resourceGainedOnJobComplete;
                    njs.getAmountGained          = bt.getAmountGained;
                    njs.amountGainedPropToSat    = bt.propToSaturation;
                }

                // Add structure to the tile.
                GC.inst.map.GetTileAt(cd).structure = bt.name;
            };

            // Assign a worker to this structure.
            js.OnMouseDown();

            // Remove this component.
            Destroy(this);
        }
    }
 protected override DbRowParameter GetParameter()
 {
     JobStructure job = new JobStructure();
     return job.Parameter;
 }
Exemplo n.º 6
0
    public void GenerateWorld()
    {
        // Calculate the world center.
        Coord centre = new Coord(WORLD_SIZE - 1, WORLD_SIZE - 1);

        // Generate a seed for the perlin noise.
        seedX = Random.Range(0f, 1000f);
        seedY = Random.Range(0f, 1000f);

        // First we shall generate a river!
        float dir  = Random.Range(0f, 6f);
        int   idir = (int)dir;
        float opp  = dir + 3f;

        if (opp >= 6f)
        {
            opp -= 6f;
        }
        int iopp = (int)opp;

        GenerateRiver(centre.GetNeighbours()[idir], dir);
        GC.inst.map.SetTileAt(centre, new Tile("water", -1));
        GenerateRiver(centre.GetNeighbours()[iopp], opp);

        // Now generate the lake coordinates!
        int lr = Random.Range(LAKE_MIN_DIST_FROM_EDGE, WORLD_SIZE);
        int lq = Random.Range(LAKE_MIN_DIST_FROM_EDGE, WORLD_SIZE + lr - LAKE_MIN_DIST_FROM_EDGE);

        if (Random.Range(0, 2) == 0)
        {
            lq += WORLD_SIZE - lr - 1;
            lr  = 2 * WORLD_SIZE - lr - 2;
        }

        Coord lakeCoord = new Coord(lq, lr);


        // Generate water tiles around the lake position.
        foreach (var coord in lakeCoord.GetWithin(MAX_LAKE_RADIUS))
        {
            // If within lake radius, this is water.
            int d = coord.DistanceTo(lakeCoord);
            if (d < LAKE_RADIUS)
            {
                GC.inst.map.SetTileAt(coord, new Tile("water", -1));
            }
            else if (d - 1 < LAKE_RADIUS && Random.Range(0f, 1f) < LAKE_CHANCE_1_EXTRA)
            {
                GC.inst.map.SetTileAt(coord, new Tile("water", -1));
            }
            else if (d - 2 < LAKE_RADIUS && Random.Range(0f, 1f) < LAKE_CHANCE_2_EXTRA)
            {
                GC.inst.map.SetTileAt(coord, new Tile("water", -1));
            }
        }

        // Generate the tiles in a big hexagon.

        // Loops through a variable i. In this loop we will create the two rows which are at index i from the top and bottom of the map.
        for (int i = 0; i < WORLD_SIZE; i++)
        {
            // We need to create WORLD_SIZE + i no. of hexes for each row we make.
            for (int c = 0; c < WORLD_SIZE + i; c++)
            {
                // Bottomm Hex:
                CreateHex(c, i);

                // Top Hex:
                if (i != WORLD_SIZE - 1)
                {
                    CreateHex(c + WORLD_SIZE - i - 1, 2 * WORLD_SIZE - i - 2);
                }
            }
        }

        // Generate a hut by the river.
        int  dist = 1;
        bool br   = false;

        while (br == false)
        {
            // Get hexes within distance of 1 (then 2 and so on if no valid hex is found), then shuffle them and pick the first which isn't water.
            List <Coord> spots = centre.GetWithin(dist);
            for (int i = 0; i < spots.Count; i++)
            {
                int   j    = Random.Range(0, spots.Count);
                Coord temp = spots [i];
                spots [i] = spots [j];
                spots [j] = temp;
            }

            foreach (Coord spot in spots)
            {
                if (GC.inst.map.GetTileAt(spot).tileType != "water")
                {
                    // Place a hut here!
                    Instantiate(GC.inst.imagePrefab, spot.GetWorldCoords() + Vector3.back, Quaternion.identity).GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("hut");
                    GC.inst.map.GetTileAt(spot).structure = "hut";

                    // Remove the trees on this tile!
                    GC.inst.map.GetTileAt(spot).nTrees = 0;
                    Vector3             wc    = spot.GetWorldCoords();
                    List <JobStructure> trees = new List <JobStructure> ();
                    RaycastHit2D[]      rcs   = Physics2D.RaycastAll(new Vector2(wc.x, wc.y), Vector2.zero);
                    foreach (RaycastHit2D rc in rcs)
                    {
                        JobStructure t = rc.transform.GetComponentInChildren <JobStructure> ();
                        if (t != null)
                        {
                            trees.Add(t);
                        }
                    }
                    foreach (JobStructure t in trees)
                    {
                        Destroy(t.gameObject);
                        print("Tree Removed!");
                    }

                    // Place some people here!
                    for (int i = 0; i < STARTING_WORKERS; i++)
                    {
                        GC.inst.GenerateWorkerAt(spot);
                    }

                    br = true;
                    break;
                }
            }

            dist += 1;
        }

        // There is no longer any need for this game object.
        Destroy(this);
    }