public void SetUp(GameObject ground, ScenarioData scenario, IntPoint2D tileLoc, ScenarioMgr mgr)
 {
     scenarioInfo = scenario;
     centerTile   = tileLoc;
     popMgr       = ground.GetComponent("PopulationManager") as PopulationManager;
     numWorkers   = 0;
     scenarioMgr  = mgr;
     StartCoroutine("GetWorkers");
     StartCoroutine("GrowFarm");
 }
예제 #2
0
        public void SplitContribution(Player earnedBy, uint contrib)
        {
            if (earnedBy.WorldGroup == null)
            {
                if (Players.ContainsKey(earnedBy.CharacterId))
                {
                    Players[earnedBy.CharacterId].BaseContribution += contrib;
                }
            }

            else
            {
                earnedBy.WorldGroup.GetPlayerList(_inGroup);

                for (int i = 0; i < _inGroup.Count; ++i)
                {
                    if (!Players.ContainsKey(_inGroup[i].CharacterId))
                    {
                        _inGroup.RemoveAt(i);
                        --i;
                    }

                    else
                    {
                        ScenarioMgr.AddToBalanceVector(_balance, _inGroup[i]);
                    }
                }

                _balance.Multiply(1f / _inGroup.Count);

                // Divide the contribution by the number of members,
                // and add a scaling bonus depending on how
                // balanced the current group is, up to 4x.
                float balanceBonusMult = 1f - _balance.Magnitude;
                contrib = (uint)(contrib * (1f / _inGroup.Count) * (1 + balanceBonusMult));

                foreach (Player player in _inGroup)
                {
                    if (player != null && Players.ContainsKey(player.CharacterId))
                    {
                        Players[player.CharacterId].BaseContribution += Math.Max(contrib, 1);
                    }
                }

                _inGroup.Clear();
                _balance.X = 0;
                _balance.Y = 0;
            }
        }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("in PopulationManager start");
        homeless  = population;
        workforce = (int)(population * workforcePercentage);
        employed  = 0;
        unfilledWorkerRequests = 0;
        startTile          = new IntPoint2D(citizenEntryX, citizenEntryY);
        houseCollection    = new Dictionary <IntPoint2D, HouseManager> ();
        homelessCollection = new Queue <CitizenManager> ();
        walkerPool         = gameObject.GetComponent("WalkerPool") as WalkerPool;
        ScenarioMgr scenMgr = gameObject.GetComponent("ScenarioMgr") as ScenarioMgr;

        scenario = scenMgr.GetInfo();
        StartCoroutine("InitPopulation");
    }
    private IEnumerator StartRetrieval()
    {
        GameObject   gameController = GameObject.FindWithTag("GameController");
        ScenarioMgr  scenarioMgr    = gameController.GetComponent("ScenarioMgr") as ScenarioMgr;
        ScenarioData scenarioInfo   = scenarioMgr.GetInfo();

        // first lets find the possible places to go
        GameObject[] stores = GameObject.FindGameObjectsWithTag("Store");
        if (stores.Length > 0)
        {
            //Debug.Log("found some stores");
            List <IntPoint2D> startTiles = scenarioInfo.GetAdjacentRoadTiles(myData.GetLoc());
            List <IntPoint2D> endTiles;
            //bestPath;// = new Stack<IntPoint2D>();

            StoreManager bestmgr = null;
            foreach (GameObject store in stores)
            {
                //  get the store manager
                StoreManager mgr = store.GetComponent("StoreManager") as StoreManager;
                // see if there's available capacity
                if (mgr.GetGoodsAmt() > 0)
                {
                    // get adjacent roads
                    endTiles = scenarioInfo.GetAdjacentRoadTiles(mgr.GetLoc());
                    Stack <IntPoint2D> path = scenarioInfo.ShortestPath(startTiles, endTiles);
                    if (path.Count > 0 && (bestPath.Count == 0 || path.Count < bestPath.Count))
                    {
                        bestPath = path;
                        bestmgr  = mgr;
                    }
                }
                yield return(null);
            }

            gettingResource2 = false;
            if (bestPath.Count > 0)
            {
                IntPoint2D start = bestPath.Pop();
                GetGoods(start, bestPath, bestmgr, scenarioInfo);
                gettingResource2 = true;
            }
        }
        yield return(null);
    }
예제 #5
0
 // Use this for initialization
 void Start()
 {
     scenario = gameObject.GetComponent("ScenarioMgr") as ScenarioMgr;
 }
예제 #6
0
    IEnumerator Wander()
    {
        Vector3    startPos = gameObject.transform.position, endPos = startPos;
        Quaternion startAngle = gameObject.transform.rotation;
        Quaternion endAngle   = startAngle;
        bool       rotating   = false;

        ScenarioMgr.Direction nextFacing = facing;
        IntPoint2D            nextTile   = curTile;

        while (wandering)
        {
            bool       goingNowhere = false;
            int        x = curTile.xCoord, y = curTile.yCoord;
            IntPoint2D tileAhead = curTile, tileLeft = curTile, tileRight = curTile, tileBehind = curTile;
            switch (facing)
            {
            case ScenarioMgr.Direction.Left:
                tileAhead  = new IntPoint2D(x - 1, y);
                tileRight  = new IntPoint2D(x, y - 1);
                tileLeft   = new IntPoint2D(x, y + 1);
                tileBehind = new IntPoint2D(x + 1, y);
                break;

            case ScenarioMgr.Direction.Up:
                tileLeft   = new IntPoint2D(x - 1, y);
                tileAhead  = new IntPoint2D(x, y - 1);
                tileBehind = new IntPoint2D(x, y + 1);
                tileRight  = new IntPoint2D(x + 1, y);
                break;

            case ScenarioMgr.Direction.Right:
                tileBehind = new IntPoint2D(x - 1, y);
                tileRight  = new IntPoint2D(x, y + 1);
                tileLeft   = new IntPoint2D(x, y - 1);
                tileAhead  = new IntPoint2D(x + 1, y);
                break;

            case ScenarioMgr.Direction.Down:
                tileRight  = new IntPoint2D(x - 1, y);
                tileBehind = new IntPoint2D(x, y - 1);
                tileAhead  = new IntPoint2D(x, y + 1);
                tileLeft   = new IntPoint2D(x + 1, y);
                break;
            }
            // pick direction
            int p = Random.Range(0, 100);
            if (p < 30)
            {
                goingNowhere = true;
                rotating     = false;
            }
            else if (p < 60 && scenarioInfo.IsPassableTile(tileAhead))
            {
                rotating   = false;
                nextFacing = facing;
                nextTile   = tileAhead;
            }
            else if (p < 80 && scenarioInfo.IsPassableTile(tileLeft))
            {
                rotating   = true;
                nextTile   = tileLeft;
                nextFacing = ScenarioMgr.GetLeftTurn(facing);
            }
            else if (scenarioInfo.IsPassableTile(tileRight))
            {
                rotating   = true;
                nextTile   = tileRight;
                nextFacing = ScenarioMgr.GetRightTurn(facing);
            }
            else if (scenarioInfo.IsPassableTile(tileBehind))
            {
                rotating   = true;
                nextTile   = tileBehind;
                nextFacing = ScenarioMgr.GetReverseDirection(facing);
            }
            else
            {
                goingNowhere = true;
                rotating     = false;
            }

            startPos   = transform.position;
            startAngle = gameObject.transform.rotation;

            if (goingNowhere)
            {
                //Debug.Log("no road to move to");
                // no rotation, no movement, no nothing -- just wait things out for a second
                yield return(new WaitForSeconds(tileMoveTime));
            }
            else
            {
                endPos = scenarioInfo.ComputeTopLeftPointOfTile(nextTile) + citizenTileOffset;
                // compute ending position
                switch (nextFacing)
                {
                case ScenarioMgr.Direction.Left:
                    endAngle = Quaternion.Euler(0, 180, 0);
                    break;

                case ScenarioMgr.Direction.Up:
                    endAngle = Quaternion.Euler(0, 90, 0);
                    break;

                case ScenarioMgr.Direction.Down:
                    endAngle = Quaternion.Euler(0, 270, 0);
                    break;

                case ScenarioMgr.Direction.Right:
                    endAngle = Quaternion.Euler(0, 0, 0);
                    break;
                }
                float elapsedTime = 0;
                if (rotating)
                {
                    // first handle the rotation
                    while (elapsedTime < this.turnTime)
                    {
                        this.gameObject.transform.rotation = Quaternion.Slerp(startAngle, endAngle, (elapsedTime / this.turnTime));
                        elapsedTime += Time.deltaTime;
                        yield return(0);
                    }
                }
                //Debug.Log("starting movement from " + startPos.ToString() + " to " + endPos.ToString());
                //Debug.Log("from tile " + curTile.ToString() + " to " + nextTile.ToString());
                // move
                float moveTime = this.tileMoveTime;
                if (!scenarioInfo.IsRoadTile(curTile))
                {
                    moveTime = moveTime * 2;
                }
                elapsedTime = 0;
                while (elapsedTime <= moveTime)
                {
                    this.gameObject.transform.position = Vector3.Lerp(startPos, endPos, (elapsedTime / moveTime));
                    elapsedTime += Time.deltaTime;
                    yield return(0);
                }
                // fix data for next tile
                this.facing  = nextFacing;
                this.curTile = nextTile;
                startPos     = this.gameObject.transform.position;
                startAngle   = endAngle;
            }
        }
        //Debug.Log("Starting takepath coroutine from Wander");
        //startPath = true;
    }
예제 #7
0
    IEnumerator Walk()
    {
        Vector3    startPos = gameObject.transform.position, endPos = startPos;
        Quaternion startAngle = gameObject.transform.rotation;
        Quaternion endAngle   = startAngle;
        bool       rotating   = false;

        ScenarioMgr.Direction nextFacing = facing;
        IntPoint2D            nextTile   = curTile;

        while (tilesToGo > 0)
        {
            //Debug.Log("doing distribution");
            // do water delivery
            scenarioInfo.DistributeWater(new IntPoint2D(curTile.xCoord, curTile.yCoord - 1));
            scenarioInfo.DistributeWater(new IntPoint2D(curTile.xCoord, curTile.yCoord + 1));
            scenarioInfo.DistributeWater(new IntPoint2D(curTile.xCoord - 1, curTile.yCoord));
            scenarioInfo.DistributeWater(new IntPoint2D(curTile.xCoord + 1, curTile.yCoord));
            // check for road tile ahead and turn appropriately
            int        x = curTile.xCoord, y = curTile.yCoord;
            IntPoint2D tileAhead = curTile, tileLeft = curTile, tileRight = curTile, tileBehind = curTile;
            switch (facing)
            {
            case ScenarioMgr.Direction.Left:
                tileAhead  = new IntPoint2D(x - 1, y);
                tileRight  = new IntPoint2D(x, y - 1);
                tileLeft   = new IntPoint2D(x, y + 1);
                tileBehind = new IntPoint2D(x + 1, y);
                break;

            case ScenarioMgr.Direction.Up:
                tileLeft   = new IntPoint2D(x - 1, y);
                tileAhead  = new IntPoint2D(x, y - 1);
                tileBehind = new IntPoint2D(x, y + 1);
                tileRight  = new IntPoint2D(x + 1, y);
                break;

            case ScenarioMgr.Direction.Right:
                tileBehind = new IntPoint2D(x - 1, y);
                tileRight  = new IntPoint2D(x, y + 1);
                tileLeft   = new IntPoint2D(x, y - 1);
                tileAhead  = new IntPoint2D(x + 1, y);
                break;

            case ScenarioMgr.Direction.Down:
                tileRight  = new IntPoint2D(x - 1, y);
                tileBehind = new IntPoint2D(x, y - 1);
                tileAhead  = new IntPoint2D(x, y + 1);
                tileLeft   = new IntPoint2D(x + 1, y);
                break;
            }
            startPos   = transform.position;
            startAngle = gameObject.transform.rotation;
            bool goingNowhere = false;
            if (scenarioInfo.IsRoadTile(tileAhead))
            {
                // no rotation required, just moving straight ahead
                rotating   = false;
                nextFacing = facing;
                nextTile   = tileAhead;
            }
            else
            {
                rotating = true;
                // we can't just go straight ahead, so we're doing some sort of rotation
                if (turningLeft)
                {
                    // check left first
                    if (scenarioInfo.IsRoadTile(tileLeft))
                    {
                        // turning left
                        nextTile   = tileLeft;
                        nextFacing = ScenarioMgr.GetLeftTurn(facing);
                    }
                    else if (scenarioInfo.IsRoadTile(tileRight))
                    {
                        // turn right because we can't turn left
                        nextTile   = tileRight;
                        nextFacing = ScenarioMgr.GetRightTurn(facing);
                    }
                    else if (scenarioInfo.IsRoadTile(tileBehind))
                    {
                        nextTile   = tileBehind;
                        nextFacing = ScenarioMgr.GetReverseDirection(facing);
                    }
                    else
                    {
                        goingNowhere = true;
                        rotating     = false;
                    }
                }
                else
                {
                    // check right first
                    if (scenarioInfo.IsRoadTile(tileRight))
                    {
                        nextTile   = tileRight;
                        nextFacing = ScenarioMgr.GetRightTurn(facing);
                    }
                    else if (scenarioInfo.IsRoadTile(tileLeft))
                    {
                        // turning left because we can't turn right
                        nextTile   = tileLeft;
                        nextFacing = ScenarioMgr.GetLeftTurn(facing);
                    }
                    else if (scenarioInfo.IsRoadTile(tileBehind))
                    {
                        nextTile   = tileBehind;
                        nextFacing = ScenarioMgr.GetReverseDirection(facing);
                    }
                    else
                    {
                        goingNowhere = true;
                        rotating     = false;
                    }
                }
            }


            if (goingNowhere)
            {
                //Debug.Log("no road to move to");
                // no rotation, no movement, no nothing -- just wait things out for a second
                yield return(new WaitForSeconds(tileMoveTime));
            }
            else
            {
                // compute ending position
                switch (nextFacing)
                {
                case ScenarioMgr.Direction.Left:
                    endPos   = startPos + new Vector3(-1, 0, 0);
                    endAngle = Quaternion.Euler(0, 180, 0);
                    break;

                case ScenarioMgr.Direction.Up:
                    endPos   = startPos + new Vector3(0, 0, -1);
                    endAngle = Quaternion.Euler(0, 90, 0);
                    break;

                case ScenarioMgr.Direction.Down:
                    endPos   = startPos + new Vector3(0, 0, 1);
                    endAngle = Quaternion.Euler(0, 270, 0);
                    break;

                case ScenarioMgr.Direction.Right:
                    endPos   = startPos + new Vector3(1, 0, 0);
                    endAngle = Quaternion.Euler(0, 0, 0);
                    break;
                }
                float elapsedTime = 0;
                if (rotating)
                {
                    // first handle the rotation
                    while (elapsedTime < this.turnTime)
                    {
                        this.gameObject.transform.rotation = Quaternion.Slerp(startAngle, endAngle, (elapsedTime / this.turnTime));
                        elapsedTime += Time.deltaTime;
                        yield return(0);
                    }
                }
                //Debug.Log("starting movement from " + startPos.ToString() + " to " + endPos.ToString());
                //Debug.Log("from tile " + curTile.ToString() + " to " + nextTile.ToString());
                // move
                elapsedTime = 0;
                while (elapsedTime < this.tileMoveTime)
                {
                    this.gameObject.transform.position = Vector3.Lerp(startPos, endPos, (elapsedTime / this.tileMoveTime));
                    elapsedTime += Time.deltaTime;
                    yield return(0);
                }
                // fix data for next tile
                this.facing  = nextFacing;
                this.curTile = nextTile;
                startPos     = endPos;
                startAngle   = endAngle;
            }

            tilesToGo--;
        }
        Destroy(gameObject);
    }