/// ------------------------------------- PUBLIC METHODS ----------------------------------- /// /// <summary> /// Public method calls to have this building build a new module if not already full /// </summary> public void BuildNewModule() { if (mEmptySlots == 0) { Debug.Log("This building is full and can't build anymore modules"); return; } CameraShaker camShake = GetComponent <CameraShaker>(); AudioSource audio = GetComponent <AudioSource>(); // special case - if it's the first module, make it a door. if (mEmptySlots == mBuildingWidth * mBuildingHeight) { int doorSlot = (int)(((mBuildingWidth * 0.5f) - 1)); mSlots[doorSlot].GetComponent <BuildingSlot>().SetBuildingModule(mModuleSet.mDoorModules[0]); mSlots[doorSlot].GetComponent <BuildingSlot>().mIsDoor = true; mLastModuleBuiltIndex = doorSlot; mEmptySlots -= 1; // add in little camera shake when building a new module if (camShake) { camShake.ShakeCamera(); } if (audio) { audio.Play(); } return; } //Debug.Log("Building a new module in building " + gameObject); // select which slot to fill next based on what module was built last int nextSlot = SelectNextSlotToBuild(); if (nextSlot < 0) { Debug.LogError("Took too long choosing a random slot, didn't build anything. Try again."); return; } NeighborState neighbors = CheckNeighborSlots(nextSlot); BuildingModule firstModule = mModuleSet.GetModuleOfType(neighbors); mSlots[nextSlot].GetComponent <BuildingSlot>().SetBuildingModule(firstModule); mEmptySlots -= 1; // add in little camera shake when building a new module if (camShake) { camShake.ShakeCamera(); } if (audio) { audio.Play(); } // update neighbor state for all slots to adjust module types if needed for (int i = 0; i < mSlots.Count; i++) { BuildingSlot slot = mSlots[i].GetComponent <BuildingSlot>(); // if this slot is still empty, don't care about its neighbors yet if (slot.IsSlotEmpty()) { continue; } NeighborState nState = CheckNeighborSlots(i); // if this slot's neighbors haven't changed, no need to update if (nState == slot.mModuleType) { continue; } if (slot.mModuleType != NeighborState.empty) { slot.mModuleType = nState; BuildingModule module = mModuleSet.GetModuleOfType(slot.mModuleType); if (slot.mIsDoor) { slot.SetBuildingModule(mModuleSet.mDoorModules[(int)slot.mModuleType]); } else { slot.SetBuildingModule(module); } } } }