Пример #1
0
    //builds new citycells out from the starting position
    private void DoNextGenerationStep(List <CityCell> activeCells)
    {
        int           currentIndex = activeCells.Count - 1;
        CityCell      currentCell  = activeCells [currentIndex];
        CityDirection direction    = CityDirections.RandomValue;
        IntVector2    coordinates  = currentCell.coordinates + direction.ToIntVector2();

        if (containsCoordinates(coordinates) && GetCell(coordinates) == null)
        {
            CityCell Neighbor = GetCell(coordinates);
            if (Neighbor == null)
            {
                Neighbor = CreateCell(coordinates);
                CreatePassage(currentCell, Neighbor, direction);
                activeCells.Add(Neighbor);
            }
            else
            {
                CreateWall(currentCell, Neighbor, direction);
                activeCells.RemoveAt(currentIndex);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
            activeCells.RemoveAt(currentIndex);
        }
    }
Пример #2
0
    //create passage
    private void CreatePassage(CityCell cell, CityCell otherCell, CityDirection direction)
    {
        CityPassage passage = Instantiate(passagePrefab) as CityPassage;

        passage.Initialize(cell, otherCell, direction);
        passage = Instantiate(passagePrefab) as CityPassage;
        passage.Initialize(otherCell, cell, direction.getOpposite());
    }
Пример #3
0
 public void Initialize(CityCell Cell, CityCell OtherCell, CityDirection Direction)
 {
     this.cell      = Cell;
     this.otherCell = OtherCell;
     this.direction = Direction;
     cell.SetEdge(Direction, this);
     transform.parent        = Cell.transform;
     transform.localPosition = Vector3.zero;
     transform.localRotation = direction.ToRotation();
 }
Пример #4
0
    //returns a new cityCell at the specified point
    public CityCell CreateCell(IntVector2 coordinates)
    {
        CityCell newCell = Instantiate(cityPrefab) as CityCell;

        cells[coordinates.x, coordinates.z] = newCell;
        newCell.coordinates             = coordinates;
        newCell.name                    = "City Cell " + coordinates.x + " " + coordinates.z;
        newCell.transform.parent        = transform;
        newCell.transform.localPosition = new Vector3(coordinates.x - sizeX * 0.5f + 0.5f, 0f, coordinates.z - sizeZ * 0.5f + 0.5f);
        return(newCell);
    }
Пример #5
0
    //create wall
    private void CreateWall(CityCell cell, CityCell otherCell, CityDirection direction)
    {
        CityWall wall = Instantiate(wallPrefab) as CityWall;

        wall.Initialize(cell, otherCell, direction);
        if (otherCell != null)
        {
            wall = Instantiate(wallPrefab) as CityWall;
            wall.Initialize(otherCell, cell, direction.getOpposite());
        }
    }
 public void UpdateGameBoard()
 {
     for (int i = 0; i < _cols; i++)
     {
         for (int j = 0; j < _rows; j++)
         {
             CityCell cell = _city.Cells[i, j];
             _cellRects[i, j].Fill = GetGradientBrush(CityGrid.GetColorOfType(cell.Type));
             _labels[i, j].Text    = cell.Score.ToString();
         }
     }
 }
Пример #7
0
        void ReleaseDesignerOutlets()
        {
            if (CityCell != null)
            {
                CityCell.Dispose();
                CityCell = null;
            }

            if (IconCell != null)
            {
                IconCell.Dispose();
                IconCell = null;
            }

            if (NameCell != null)
            {
                NameCell.Dispose();
                NameCell = null;
            }
        }
        private void NewGame()
        {
            _grid = new NodeGrid(_cols, _rows);
            _city = new CityGrid(_cols, _rows);
            _city.InitializeCells();
            _labels    = new TextBlock[_cols, _rows];
            _cellRects = new Rectangle[_cols, _rows];

            boardGrid.Width  = _cols;
            boardGrid.Height = _rows;
            boardGrid.ColumnDefinitions.Clear();
            boardGrid.RowDefinitions.Clear();
            Enumerable.Range(0, _cols).ToList().ForEach(x => boardGrid.ColumnDefinitions.Add(new ColumnDefinition()));
            Enumerable.Range(0, _rows).ToList().ForEach(x => boardGrid.RowDefinitions.Add(new RowDefinition()));

            for (int i = 0; i < _cols; i++)
            {
                for (int j = 0; j < _rows; j++)
                {
                    CityCell cell = _city.Cells[i, j];

                    Rectangle cellRect = new Rectangle();
                    cellRect.Fill = GetGradientBrush(CityGrid.GetColorOfType(cell.Type));
                    Grid.SetRow(cellRect, j);
                    Grid.SetColumn(cellRect, i);
                    boardGrid.Children.Add(cellRect);
                    _cellRects[i, j] = cellRect;

                    TextBlock label = new TextBlock {
                        Text = cell.Score.ToString(), FontSize = 0.3, Foreground = Brushes.Black
                    };
                    Grid.SetRow(label, j);
                    Grid.SetColumn(label, i);
                    boardGrid.Children.Add(label);
                    _labels[i, j] = label;
                }
            }
        }
Пример #9
0
    public static MapCell create_cell(int ID, int tier, Tile tile, Pos pos)
    {
        MapCell mc = null;

        // Don't extract name from tile if provided.
        if (ID == PLAINS_ID)
        {
            mc = new Plains(tier, tile, pos);
        }
        else if (ID == FOREST_ID)
        {
            mc = new Forest(tier, tile, pos);
        }
        else if (ID == RUINS_ID)
        {
            mc = new Ruins(tier, tile, pos);
        }
        else if (ID == CLIFF_ID)
        {
            mc = new Cliff(tier, tile, pos);
        }
        else if (ID == CAVE_ID)
        {
            mc = new Cave(tier, tile, pos);
        }
        else if (ID == STAR_ID)
        {
            mc = new Star(tier, tile, pos);
        }
        else if (ID == TITRUM_ID)
        {
            mc = new Titrum(tier, tile, pos);
        }
        else if (ID == LUSH_LAND_ID)
        {
            mc = new LushLand(tier, tile, pos);
            //} else if (name == MIRE) {
            //mc = new Mire(tier, tile, pos);
        }
        else if (ID == MOUNTAIN_ID)
        {
            mc = new Mountain(tier, tile, pos);
        }
        else if (ID == SETTLEMENT_ID)
        {
            mc = new Settlement(tier, tile, pos);
        }
        else if (ID == RUNE_GATE_ID)
        {
            mc = new RuneGate(tier, tile, pos);
        }
        else if (ID == CITY_ID)
        {
            mc = new CityCell(tier, tile, pos);
        }
        else if (ID == GUARDIAN_PASS_ID)
        {
            mc = new GuardianPass(tier, tile, pos);
        }
        else if (ID == CITY_ID)
        {
            mc = new CityCell(tier, tile, pos);
        }
        else
        {
            mc = new MapCell(0, tier, tile, pos);
        }
        //mc.tile_type_ID = tile_type_ID;
        return(mc);
    }
Пример #10
0
 private void create_city()
 {
     city_cell = (CityCell)MapCell.create_cell(MapCell.CITY_ID, 1, city, new Pos(12, 12));
     city_cell.discover();
     map.Add(city_cell.pos, city_cell);
 }
Пример #11
0
	void GoBuild(){
		List<GameObject> housobjs;
		housobjs = new List<GameObject> ();

		if (siz < 3) {
			siz = 3;
		}
		city = new List<string> ();

		Vector2 roads;
		roads = new Vector2 ();
		int tmproad;
		if (Mathf.FloorToInt (siz * 0.5f) < siz * 0.5f) {
			tmproad = Mathf.FloorToInt (siz * 0.5f) + 1;
		} else {
			tmproad = Mathf.FloorToInt (siz * 0.5f);
		}
		roads.x = Mathf.RoundToInt (tmproad * 0.5f);
		roads.y = Mathf.FloorToInt (tmproad * 0.5f);
		//if(tmp)
		List<int> rand1;
		List<int> rand2;
		rand1 = new List<int>();
		rand2 = new List<int>();
		for (int gg = 1; gg < siz - 1; gg++) {
			rand1.Add (gg);
			rand2.Add (gg);
		}
		for (int gg = 0; gg < roads.x; gg++) {
			rand1.RemoveAt ( Random.Range(0, rand1.Count) );
		}
		for (int gg = 0; gg < roads.y; gg++) {
			rand2.RemoveAt ( Random.Range(0, rand2.Count) );
		}
		//Debug.Log (roads);
		for (int go = 0; go < siz; go++) {
			city.Add ("");

			for (int lo = 0; lo < siz; lo++) {
				//city [go] += "0";
				bool done = false;
				if (go == 0 && lo != siz - 1 && lo!= 0) {
					
					if(roads.x>0){
						if (!rand1.Contains (lo)) {

							city[go]+=1;
							done = true;
							roads.x--;
						}


					}

				}
				if (lo == 0 && go != siz - 1 && go!= 0) {

					if(roads.y>0){
						if (!rand2.Contains (go)) {

							city[go]+=1;
							done = true;
							roads.y--;
						}


					}

				}
				if (!done) {
					city[go]+=0;
				}
			
			}

		}
		//Debug.Log (roads);

		cit = new List<CityCell> ();

		// переписать город в удобный формат
		for (int go = 0; go < city.Count; go++) { 
			CityCell tmp;
			tmp = new CityCell ();
			tmp.ids = new List<int> ();
			cit.Add (tmp);
			for( int lo = 0; lo< city[go].Length; lo++){
				string tmpstr;
				tmpstr = city [go];
				string tmprez = ""+ tmpstr [lo];
				tmp.ids.Add (int.Parse ( tmprez));
			}
		}

		// растянуть дороги
		for (int go = 0; go < cit [0].ids.Count; go++) { 
			if (cit [0].ids [go] == 1) {
				for(int lo = 0 ; lo <cit.Count; lo++){
					cit [lo].ids [go] = 1;
				}
			}
		}

		// растянуть вторые дороги поставить перекрестки
		for (int go = 0; go < cit.Count; go++) { 
			if (cit [go].ids [0] == 1) {
				for(int lo = 0 ; lo <cit[go].ids.Count; lo++){
					bool chk = false;

					if (lo != 0 && cit [go].ids [lo] == 1) {
						cit [go].ids [lo] = 3;
						chk = true;
					}
					if (!chk) {
						cit [go].ids [lo] = 2;
					}
				}
			}
		}

		// определить назначение пустых квадратов
		for (int go = 0; go < cit.Count; go++) { 
			for (int lo = 0; lo < cit [go].ids.Count; lo++) {
				if (cit [go].ids [lo] == 0) {
					if (go != 0 && lo != 0 && go != cit.Count - 1 && lo != cit [go].ids.Count - 1) {
						cit [go].ids [lo] = 9;
					} else {
						if (Random.Range (0, 10) < 2) {
							cit [go].ids [lo] = 9;
						}
					}
				}
			}
		}

		//случайным образом урезать дороги по краям города
		for (int go = 0; go < cit.Count; go++) { 
			int tmprnd;

			for(int lo = 0; lo< cit[go].ids.Count; lo++){
				//tmprnd = Random.Range (-1, 2);
				if (cit [go].ids [lo] == 1 && go==0) {
					tmprnd = Random.Range (-1, 2);
					if( tmprnd<0){
						cit[0].ids[lo]=0;
					}
					if( tmprnd>0){
						cit[cit.Count-1].ids[lo]=0;
					}
				}
				if (cit [go].ids [lo] == 2 && lo==0) {
					tmprnd = Random.Range (-1, 2);
					if( tmprnd<0){
						cit[go].ids[0]=0;
					}
					if( tmprnd>0){
						cit[go].ids[cit[go].ids.Count-1]=0;
					}
				}

//				if(cit[go].ids[lo]==1){
//					
//					if( tmprnd<0 && go ==0){
//						cit[go].ids[lo]=0;
//					}
//					if( tmprnd>0 && go ==cit.Count-1){
//						cit[go].ids[lo]=0;
//					}
//				}
//				if(cit[go].ids[lo]==2){
//					if(tmprnd<0 && lo==0){
//						cit[go].ids[lo]=0;
//					}
//					if(tmprnd>0 && lo==cit[go].ids.Count-1 ){
//						cit[go].ids[lo]=0;
//					}
//				}

			}
		}

		// Уменьшить плотность застройки у краев
		for (int go = 0; go < cit.Count; go++) { 
			for (int lo = 0; lo < cit [go].ids.Count; lo++) {

				if (go == 0 || lo == 0 || go == cit.Count - 1 || lo == cit [go].ids.Count - 1) {
					if (cit [go].ids [lo] == 1) {
						cit [go].ids [lo] = 6;
					}
					if (cit [go].ids [lo] == 2) {
						cit [go].ids [lo] = 7;
					}
				}

			}
		}

		// добавить недостающие квадраты
//		if(cit[0].ids.Count % 2 !=0){
//			for( int go =0; go< cit.Count; go++){
//				cit [go].ids.Add (0);
//			}
//		}
//		if (cit.Count % 2 != 0) {
//			CityCell tmp11 = new CityCell();
//			tmp11.ids = new List<int> ();
//			for( int go = 0; go< cit[0].ids.Count; go++){
//				tmp11.ids.Add (0);
//			}
//			cit.Add ( tmp11);
//		}

		GameObject newcit;
		Vector2 citdim;

		newcit = new GameObject ();
		newcit.name = "TOWN";
		citdim = new Vector2 (Mathf.CeilToInt( cit .Count*0.5f)*2, Mathf.CeilToInt( cit[0].ids .Count*0.5f)*2);
		//Debug.Log (citdim);
		//строим город
		for (int go = 0; go < cit.Count; go++) {
			for (int lo = 0; lo < cit [go].ids.Count; lo++) {
				int tmprez = cit[go].ids[lo];
				GameObject tmpcell = null;
				bool done = false;
				float hcount = Random.Range(0.7f, 1f);

				if (tmprez == 1 || tmprez == 6) {
					tmpcell = GameObject.Instantiate (Roads [0]);
					Vector3 lol;
					lol = new Vector3 (0,90f,0);
					tmpcell.transform.localEulerAngles = lol;
					done = true;
					if( tmprez == 6){
						hcount = 0.5f;
					}

				}
				if (tmprez == 2 || tmprez == 7) {
					tmpcell = GameObject.Instantiate (Roads [0]);
					if( tmprez == 7){
						hcount = 0.5f;
					}

					done = true;
				}
				if (tmprez == 3) {
					tmpcell = GameObject.Instantiate (CrossRoads [0]);
					done = true;
				}
				if (tmprez == 9) {
					tmpcell = GameObject.Instantiate (Houses [0]);
					done = true;
				}
				if (tmprez == 0 || !done) {
					tmpcell = GameObject.Instantiate (Empties [0]);
					done = true;
				}

				tmpcell.transform.parent = newcit.transform;
				tmpcell.transform.localPosition = new Vector3 ((go - cit.Count*0.5f+0.5f)*CellScale, 0 , (lo - cit [go].ids.Count*0.5f+0.5f)*CellScale);

				if (done) {
					int hcount2;

					LevelHousePoint[] tsts;
					tsts = tmpcell.transform.GetComponentsInChildren<LevelHousePoint> ();

					List<GameObject> tsts2;
					tsts2 = new List<GameObject> ();
					foreach (LevelHousePoint tst in tsts) {
						//tst.GoGo();
						tsts2.Add( tst.gameObject);
					}
					hcount2 = Mathf.RoundToInt (tsts2.Count * hcount);
					hcount2 = tsts2.Count - hcount2;
					List<int> tool;
					tool = new List<int> ();
					for (int go2 = 0; go2 < hcount2; go2++) {

						tsts2.RemoveAt(Random.Range (0, tsts2.Count));
						//tool.Add (Random.Range (0, tsts2.Count));
					}

					for( int go2 =0; go2< tsts2.Count; go2++){

						//tsts2 [go2].transform.GetComponent<LevelHousePoint> ().GoGo ();

//						tsts2 [go2].transform.GetComponent<LevelHousePoint> ().BoxDim = new Vector2 ( Random.Range(5, 9), Random.Range(5, 9));
//						tsts2[go2].transform.GetComponent<LevelHousePoint>().wins = new List<int>();
//						tsts2 [go2].transform.GetComponent<LevelHousePoint> ().wins.Add (-2);
//						tsts2[go2].transform.GetComponent<LevelHousePoint>().doors = new List<int>();
//						tsts2 [go2].transform.GetComponent<LevelHousePoint> ().doors.Add (2);
//						tsts2 [go2].transform.GetComponent<LevelHousePoint> ().DifHouse ();

						housobjs.Add (tsts2 [go2]);
					}
				}
			}
		}
		//рисуем границы города еслии нужны
		if(cit[0].ids.Count % 2 !=0){
			for (int go = 0; go < cit .Count*2 +2; go++) {
				GameObject tmpbor;
				tmpbor = GameObject.Instantiate (Borders [0]);
				tmpbor.transform.parent = newcit.transform;
				tmpbor.transform.localPosition = new Vector3 ((go - (cit.Count*2+2)*0.5f+0.5f)*CellScale*0.5f,0, ( - (cit[0].ids.Count*2+2)*0.5f+0.5f)*CellScale*0.5f);

				tmpbor = GameObject.Instantiate (Borders [0]);
				tmpbor.transform.parent = newcit.transform;
				tmpbor.transform.localPosition = new Vector3 ((go - (cit.Count*2+2)*0.5f+0.5f)*CellScale*0.5f,0, (  (cit[0].ids.Count*2+2)*0.5f-0.5f)*CellScale*0.5f);
			}
			for (int go = 0; go < cit[0].ids .Count*2; go++) {
				GameObject tmpbor;
				tmpbor = GameObject.Instantiate (Borders [0]);
				tmpbor.transform.parent = newcit.transform;
				tmpbor.transform.localPosition = new Vector3 (( - (cit.Count*2+2)*0.5f+0.5f)*CellScale*0.5f,0, ( go - (cit[0].ids.Count*2)*0.5f+0.5f)*CellScale*0.5f);

				tmpbor = GameObject.Instantiate (Borders [0]);
				tmpbor.transform.parent = newcit.transform;
				tmpbor.transform.localPosition = new Vector3 (( (cit.Count*2)*0.5f+0.5f)*CellScale*0.5f,0, (go -  (cit[0].ids.Count*2-2)*0.5f-0.5f)*CellScale*0.5f);
			}
		}


		//рисуем земли окружающие город

		int xx =0;
		int yy =0;
		for(int go = 0; go< (Landrad*2+ citdim.x*0.5f)* (Landrad*2+citdim.y*0.5f); go++){


			GameObject tmpland;
			tmpland = GameObject.Instantiate (Lands [0]);
			tmpland.transform.parent = newcit.transform;

			float xxx;
			float yyy;
			xxx = (xx +0.5f - (Landrad*2+ citdim.x*0.5f)*0.5f)*CellScale*2f;
			yyy =  (yy +0.5f - (Landrad*2+ citdim.y*0.5f)*0.5f)*CellScale*2f;
			tmpland.transform.localPosition = new Vector3 (xxx,0,yyy);
			bool abrt = false;

			if (xx > Landrad - 1 && xx < (Landrad + citdim.x * 0.5f)
				&& yy > Landrad -1 && yy< (Landrad + citdim.y * 0.5f)) {
				abrt = true;
			}
			xx++;
			if(xx>= Landrad*2+ citdim.x*0.5f){
				xx =0;
				yy++;
			}
			if (abrt) {
				GameObject.Destroy (tmpland);
			}
		}


		//строим дома
		List<int> actvhouses;
		actvhouses = new List<int> ();
		for (int go = 0; go < housobjs.Count; go++) {
			actvhouses.Add (go);
		}
		if (houses > actvhouses.Count) {
			houses = actvhouses.Count;
		}
		for (int go = 0; go < houses; go++) {
			actvhouses.RemoveAt ( Random.Range(0, actvhouses.Count));
		}

		for(int go = 0; go< housobjs.Count; go++){
			if (!actvhouses.Contains (go)) {
				housobjs [go].transform.GetComponent<LevelHousePoint> ().BoxDim = new Vector2 (Random.Range (5, 9), Random.Range (5, 9));
				housobjs [go].transform.GetComponent<LevelHousePoint> ().wins = new List<int> ();
				housobjs [go].transform.GetComponent<LevelHousePoint> ().wins.Add (-2);
				housobjs [go].transform.GetComponent<LevelHousePoint> ().doors = new List<int> ();
				housobjs [go].transform.GetComponent<LevelHousePoint> ().doors.Add (2);
				housobjs [go].transform.GetComponent<LevelHousePoint> ().DifHouse ();
			} else {
				housobjs [go].transform.GetComponent<LevelHousePoint> ().GoGo ();
			}
		}
	}
Пример #12
0
 public void AddCity(CityCell city)
 {
     cities.Add(city);
 }