public void SetDemandRatio(EAssignment _assignment, float _value) { Image img = null; switch (_assignment) { case EAssignment.NONE: break; case EAssignment.LIVING: img = LivingDemand; break; case EAssignment.BUSINESS: img = BusinessDemand; break; case EAssignment.INDUSTRY: img = IndustryDemand; break; } if (img == null) { return; } img.fillAmount = _value; }
public void SetAssignment(EAssignment _newAssigment) { switch (m_CellAssignment) { case EAssignment.NONE: break; case EAssignment.LIVING: GridManager.m_AllLivingCells.Remove(this); break; case EAssignment.BUSINESS: GridManager.m_AllBusinessCells.Remove(this); break; case EAssignment.INDUSTRY: GridManager.m_AllIndustryCells.Remove(this); break; } //Remove from old assignment m_CellAssignment = _newAssigment; switch (_newAssigment) { case EAssignment.NONE: break; case EAssignment.LIVING: GridManager.m_AllLivingCells.Add(this); break; case EAssignment.BUSINESS: GridManager.m_AllBusinessCells.Add(this); break; case EAssignment.INDUSTRY: GridManager.m_AllIndustryCells.Add(this); break; } //Add to new assignment }
private void ChanageMaterial(EAssignment _assignment, int _index, MeshRenderer _mr, MeshRenderer _collMr) { Material mat = null; switch (_assignment) { case EAssignment.NONE: mat = m_ClearMat; break; case EAssignment.LIVING: mat = m_LivingMat; break; case EAssignment.BUSINESS: mat = m_BusinessMat; break; case EAssignment.INDUSTRY: mat = m_IndustryMat; break; default: break; } Material[] mats = _mr.sharedMaterials; mats[_index] = mat; _mr.materials = mats; }
public void ChangeCellAssigtment(Vector2Int _cellPosStart, EAssignment _assignment) { Vector2Int pos = _cellPosStart; while (m_StreetCells.ContainsKey(pos)) { m_StreetCells[pos].SetAssignment(_assignment); pos.x += _cellPosStart.x; //pos.x = -1 change to pos.x = -2 and pos.x = 1 change to pos.x = 2 } }
public override void ToolStart() { Cursor.SetActiv(true); Cursor.SetColor(Color.white); SetMaterialAlpha(m_LivingMat, 1f); SetMaterialAlpha(m_BusinessMat, 1f); SetMaterialAlpha(m_IndustryMat, 1f); m_CurrendAssignment = EAssignment.LIVING; UIManager.Instance.HighlightButton(UIManager.Instance.LivingButton); UIManager.Instance.SetActivAssignment(); }
public GameObject PlaceBuilding(EAssignment _assignment, Street _s, bool _isLeftSide) { EDemand density = EDemand.NONE; switch (_assignment) { case EAssignment.NONE: break; case EAssignment.LIVING: density = m_LivingDemand; break; case EAssignment.BUSINESS: density = m_BusinessDemand; break; case EAssignment.INDUSTRY: density = m_IndustryDemand; break; } GameObject prefab = GetRandomPrefab(_assignment, density); if (prefab == null) { return(null); } Building b = prefab.GetComponent <Building>(); if (_isLeftSide) { if (_s.FindAreaLeftSide(b.Size, _assignment, out Area a)) { return(SpawnPrefab(a, b, prefab)); } } else { if (_s.FindAreaRightSide(b.Size, _assignment, out Area a)) { return(SpawnPrefab(a, b, prefab)); } } return(null); }
private void _handleAssignment(EAssignment assignment, string scope) { var result = _expandParameter(assignment.Parameter); result.Name = assignment.Name; result.Scope = scope; var existingVariable = _stack.FirstOrDefault(v => v.Name == result.Name); if (existingVariable != null) { existingVariable.Value = result.Value; } else { // don't add to non existing variable, that would be weak typing throw new EngineException($"Attempt to assign value to non-existing variable: {assignment.Name}"); } }
private GameObject GetRandomPrefab(EAssignment _assignment, Vector2Int _size) { List <GameObject> validPrefabs = new List <GameObject>(); switch (_assignment) { case EAssignment.NONE: break; case EAssignment.LIVING: if (livingPrefabs_Dic.ContainsKey(_size)) { validPrefabs = livingPrefabs_Dic[_size]; } break; case EAssignment.BUSINESS: if (businessPrefabs_Dic.ContainsKey(_size)) { validPrefabs = businessPrefabs_Dic[_size]; } break; case EAssignment.INDUSTRY: if (industryPrefabs_Dic.ContainsKey(_size)) { validPrefabs = industryPrefabs_Dic[_size]; } break; } if (validPrefabs.Count == 0) { Debug.LogError("No Building with Size: " + _size + " and Assignment: " + _assignment + " found."); return(null); } //Removes buildings whose density does not match the demand int DemandToCheck = 0; switch (_assignment) { case EAssignment.NONE: break; case EAssignment.LIVING: DemandToCheck = (int)m_LivingDemand; break; case EAssignment.BUSINESS: DemandToCheck = (int)m_BusinessDemand; break; case EAssignment.INDUSTRY: DemandToCheck = (int)m_IndustryDemand; break; default: break; } List <GameObject> output = new List <GameObject>(); for (int i = 0; i < validPrefabs.Count; i++) { if (CheckDensity) { Building b = validPrefabs[i].GetComponent <Building>(); if (DemandToCheck == (int)b.m_Density) { output.Add(validPrefabs[i]); } } else { output.Add(validPrefabs[i]); } } if (output.Count == 0) { Debug.LogError($"No Building with Density: {(EDemand)DemandToCheck} and Assignment: {_assignment} found."); return(null); } int index = Random.Range(0, output.Count); return(output[index]); }
private GameObject GetRandomPrefab(EAssignment _assignment, EDemand _density) { List <GameObject> validPrefabs = new List <GameObject>(); switch (_assignment) { case EAssignment.NONE: break; case EAssignment.LIVING: foreach (List <GameObject> objList in livingPrefabs_Dic.Values) { foreach (GameObject obj in objList) { if (CheckDensity) { Building b = obj.GetComponent <Building>(); if (b.m_Density == _density) { validPrefabs.Add(obj); } } else { validPrefabs.Add(obj); } } } break; case EAssignment.BUSINESS: foreach (List <GameObject> objList in businessPrefabs_Dic.Values) { foreach (GameObject obj in objList) { if (CheckDensity) { Building b = obj.GetComponent <Building>(); if (b.m_Density == _density) { validPrefabs.Add(obj); } } else { validPrefabs.Add(obj); } } } break; case EAssignment.INDUSTRY: foreach (List <GameObject> objList in industryPrefabs_Dic.Values) { foreach (GameObject obj in objList) { if (CheckDensity) { Building b = obj.GetComponent <Building>(); if (b.m_Density == _density) { validPrefabs.Add(obj); } } else { validPrefabs.Add(obj); } } } break; } if (validPrefabs.Count == 0) { return(null); } int index = Random.Range(0, validPrefabs.Count); return(validPrefabs[index]); }
/// <summary> /// Moves the pointer a specified amount along the street /// </summary> /// <param name="_sizeY">The amount by which the pointer should be moved</param> /// <param name="pStart">The start pointer, to reset this if the move fails</param> /// <param name="p">The Pointer to move</param> /// <param name="_assignment">The needed assignment to check</param> /// <returns>Can the pointer move by this amount along the street</returns> private bool MoveCellPointerRight(int _sizeY, ref Vector2Int pStart, ref Vector2Int p, EAssignment _assignment, bool _isLeft) { for (int i = 0; i < _sizeY - 1; i++) //move to the right and look if the cell is valid { p.y++; if (!m_StreetCells.ContainsKey(p) || m_StreetCells[p].m_CellAssignment != _assignment || m_StreetCells[p].IsInArea) //if the cell exist and the assigment is valid { pStart = new Vector2Int(1, p.y + 1); //set pStart to right generation and move it back down if (!_isLeft) { pStart.x *= -1; } p = pStart; return(false); } } return(true); }
/// <summary> /// Find a Area with the given settings on the right side of the Road /// </summary> /// <param name="_size">The size of the Area</param> /// <param name="_assignment">The Assignment of the Cells</param> /// <param name="a">The new Area</param> /// <returns>Can there be such an Area</returns> public bool FindAreaRightSide(Vector2Int _size, EAssignment _assignment, out Area a) { //Look Left Side Vector2Int p = new Vector2Int(-1, 0); //Pointer a = null; if (m_StreetCells.Count == 0) { return(false); } Vector2Int pStart = p; //move the StartPointer along the Grid to the Start if the grid for (int i = 0; i < m_RowAmount; i++) { if (m_StreetCells.ContainsKey(pStart) && m_StreetCells[pStart].m_CellAssignment == _assignment) { break; } else { pStart.y++; } } while (m_StreetCells.ContainsKey(pStart)) { //move right as long as this generation dont have the need depht while ((m_StreetCells.ContainsKey(pStart) && m_StreetCells[pStart].IsInArea) || !m_StreetCells.ContainsKey(new Vector2Int(pStart.x - _size.x + 1, pStart.y))) { if (pStart.y > m_RowAmount) { return(false); } pStart.y++; //if this geneartion dont reached this depth move to the right } p.x = -_size.x; //move p to the needed depth p.y = pStart.y; //move right as long as the size.y if (MoveCellPointerRight(_size.y, ref pStart, ref p, _assignment, false)) //if to the right all cells are valid { List <Cell> cells = SetCellsInArea(pStart, _size, false); if (cells == null) { pStart = new Vector2Int(-1, p.y + 1); //set pStart to right generation and move it back down p = pStart; return(false); } a = new Area(_size, cells, this, GetOrientenPointFromCells(m_StreetCells[pStart], m_StreetCells[p])); switch (_assignment) { case EAssignment.NONE: break; case EAssignment.LIVING: m_LivingAreas.Add(a); break; case EAssignment.BUSINESS: m_BusinessAreas.Add(a); break; case EAssignment.INDUSTRY: m_IndustryAreas.Add(a); break; case EAssignment.PRODUCTION: m_ProductionAreas.Add(a); break; } return(true); } } return(false); //if the while ends because the pointer is on an invalid pos, then return false }
/// <summary> /// Find the next biggest Area on the right Side of the Road /// </summary> /// <param name="a">The new Area</param> /// <returns>Can there be a new Area</returns> public bool FindAreaRightSide(out Area a) { Vector2Int p = new Vector2Int(-1, 0); //Pointer int height = 0; int width = 0; a = null; if (m_StreetCells.Count == 0) { return(false); } for (int y = 0; y < m_RowAmount; y++) //Find valid StartPoint { if (m_StreetCells.ContainsKey(p) && !m_StreetCells[p].IsInArea && m_StreetCells[p].m_CellAssignment != EAssignment.NONE) { break; } else { p.y++; } } if (!m_StreetCells.ContainsKey(p)) { return(false); } EAssignment assi = m_StreetCells[p].m_CellAssignment; if (assi == EAssignment.NONE) { return(false); } Vector2Int pStart = p; while (m_StreetCells.ContainsKey(p) && !m_StreetCells[p].IsBlocked && m_StreetCells[p].m_CellAssignment == assi && !m_StreetCells[p].IsInArea) //Go up till up end { p.x--; height++; } if (height == 0) { return(false); } p.x++; while (m_StreetCells.ContainsKey(p) && !m_StreetCells[p].IsBlocked && m_StreetCells[p].m_CellAssignment == assi && !m_StreetCells[p].IsInArea) //Go right till end { p.y++; width++; if (m_StreetCells.ContainsKey(new Vector2Int(p.x - 1, p.y))) { break; // if up exist break because fin } } if (width == 0) { return(false); } List <Cell> areaCells = SetCellsInArea(pStart, new Vector2Int(height, width), false); if (areaCells == null) { return(false); } Debug.Log("Size: X: " + height + " Y: " + width + " Assigmnet: " + assi); a = new Area(new Vector2Int(width, height), areaCells, this, null); return(true); }
private IEnumerator PlaceBuildings() { GameObject obj; bool lastLeft = false; EAssignment lastAssignemnt = EAssignment.NONE; while (true) { if (lastAssignemnt != EAssignment.PRODUCTION && BuildingManager.Instance.m_ProductionBuildWaitingList.Count > 0) { if (!lastLeft) { obj = BuildingManager.Instance.PlaceProductionBuilding( BuildingManager.Instance.m_ProductionBuildWaitingList[0], this, true); lastLeft = true; if (obj != null) { yield return(new WaitForSeconds(BuildingManager.Instance.IndustryWaitTime)); continue; } } if (lastLeft) { obj = BuildingManager.Instance.PlaceProductionBuilding( BuildingManager.Instance.m_ProductionBuildWaitingList[0], this, false); lastLeft = false; if (obj != null) { yield return(new WaitForSeconds(BuildingManager.Instance.LivingWaitTime)); continue; } } } if (lastAssignemnt != EAssignment.LIVING) { //LIVING if (!lastLeft) { obj = BuildingManager.Instance.PlaceBuilding(EAssignment.LIVING, this, true); lastLeft = true; if (obj != null) { lastLeft = true; yield return(new WaitForSeconds(BuildingManager.Instance.BusinessWaitTime)); continue; } } if (lastLeft) { obj = BuildingManager.Instance.PlaceBuilding(EAssignment.LIVING, this, false); lastLeft = false; if (obj != null) { lastLeft = false; yield return(new WaitForSeconds(BuildingManager.Instance.IndustryWaitTime)); continue; } } } if (lastAssignemnt != EAssignment.BUSINESS) { //BUSINESS if (!lastLeft) { obj = BuildingManager.Instance.PlaceBuilding(EAssignment.BUSINESS, this, true); lastLeft = true; if (obj != null) { lastLeft = true; yield return(new WaitForSeconds(1f)); continue; } } if (lastLeft) { obj = BuildingManager.Instance.PlaceBuilding(EAssignment.BUSINESS, this, false); lastLeft = false; if (obj != null) { yield return(new WaitForSeconds(1f)); continue; } } } if (lastAssignemnt != EAssignment.INDUSTRY) { //INDUSTRY if (!lastLeft) { obj = BuildingManager.Instance.PlaceBuilding(EAssignment.INDUSTRY, this, true); lastLeft = true; if (obj != null) { yield return(new WaitForSeconds(1f)); continue; } } if (lastLeft) { obj = BuildingManager.Instance.PlaceBuilding(EAssignment.INDUSTRY, this, false); lastLeft = false; if (obj != null) { yield return(new WaitForSeconds(1f)); continue; } } } lastAssignemnt = EAssignment.NONE; yield return(new WaitForEndOfFrame()); } }
public override void ToolUpdate() { if (Input.GetMouseButton(0)) { foreach (Cell c in GridManager.m_FirstGenCells) { if (MyCollision.SphereSphere(new Vector2(m_hitPos.x, m_hitPos.z), 0.8f, c.m_PosCenter, c.m_Radius)) { if (Input.GetKey(KeyCode.LeftShift)) //Multi Fill { Street s = c.m_Street; Vector2Int pos = c.Pos; EAssignment firstCellAssigment = c.m_CellAssignment; //Go y+ do { if (!s.m_StreetCells.ContainsKey(pos)) { return; } Cell currCell = s.m_StreetCells[pos]; int materialIndex = currCell.Pos.y; if (currCell.Pos.x < 0) { materialIndex += currCell.m_Street.m_RowAmount; } ChanageMaterial(m_CurrendAssignment, materialIndex, currCell.m_Street.m_GridRenderer, currCell.m_Street.m_Coll_GridRenderer); c.m_Street.ChangeCellAssigtment(currCell.Pos, m_CurrendAssignment); pos.y++; if (s.m_StreetCells.ContainsKey(pos) && s.m_StreetCells[pos].m_CellAssignment != firstCellAssigment) { break; } }while (s.m_StreetCells.ContainsKey(pos)); pos = c.Pos; //Go y-- do { Cell currCell = s.m_StreetCells[pos]; int materialIndex = currCell.Pos.y; if (currCell.Pos.x < 0) { materialIndex += currCell.m_Street.m_RowAmount; } ChanageMaterial(m_CurrendAssignment, materialIndex, currCell.m_Street.m_GridRenderer, currCell.m_Street.m_Coll_GridRenderer); c.m_Street.ChangeCellAssigtment(currCell.Pos, m_CurrendAssignment); pos.y--; if (s.m_StreetCells.ContainsKey(pos) && s.m_StreetCells[pos].m_CellAssignment != firstCellAssigment) { break; } }while (s.m_StreetCells.ContainsKey(pos)); } else //Normal Fill { int materialIndex = c.Pos.y; if (c.Pos.x < 0) { materialIndex += c.m_Street.m_RowAmount; } ChanageMaterial(m_CurrendAssignment, materialIndex, c.m_Street.m_GridRenderer, c.m_Street.m_Coll_GridRenderer); c.m_Street.ChangeCellAssigtment(c.Pos, m_CurrendAssignment); } } } } if (Input.GetKeyDown(KeyCode.W)) { m_CurrendAssignment = EAssignment.LIVING; UIManager.Instance.HighlightButton(UIManager.Instance.LivingButton); } if (Input.GetKeyDown(KeyCode.G)) { m_CurrendAssignment = EAssignment.BUSINESS; UIManager.Instance.HighlightButton(UIManager.Instance.BusinessButton); } if (Input.GetKeyDown(KeyCode.I)) { m_CurrendAssignment = EAssignment.INDUSTRY; UIManager.Instance.HighlightButton(UIManager.Instance.IndustryButton); } }