public int RelocateCube(Alliance all, int minType) { // type is too high if (mType > minType) { return(-1); } // already buil a cube on this planet for (int a = 0; a < mQuantumCubeList.Count; a++) { if (mQuantumCubeList[a].AllianceBelongingTo == all) { return(-2); } } // create cube GameObject cubeObj = Instantiate(GameLogic.Instance.prefabQuantumCube) as GameObject; QuantumCube cube = cubeObj.GetComponent <QuantumCube>(); Vector3 newPos = new Vector3(transform.localPosition.x + cubeOffsets[mQuantumCubeList.Count].x, transform.localPosition.y + cubeOffsets[mQuantumCubeList.Count].y, 0); cube.Setup(all, newPos, this); QuantumCubeList.Add(cube); return(0); }
/// <summary> /// Constructs, if possible, a quantum cube. /// </summary> /// <returns>0 - if cube could be built, -1 if influence isn't matching, -2 if there is no more room left on planet, -3 if alliance has already a cube on planet </returns> /// <param name="all">Alliance that wants to build a cube</param> /// <param name="ignoreInfl">If set to <c>true</c> ignores influence check.</param> public int ConstructCube(Alliance all, bool ignoreInfl) { // calc influece of alliance int allInfl = 0; for (int i = 0; i < 4; i++) { if (tileList[ORBITAL_TILES[i]].occupyingShip != null) { Ship occShip = tileList[ORBITAL_TILES[i]].occupyingShip; if (occShip.AllianceBelongingTo == all) { allInfl += occShip.Power; } } } // not correct influence if (allInfl != mType && ignoreInfl == false) { return(-1); } // max amount of cubes built if (mQuantumCubeList.Count >= mNbrOfPossibleCubes) { return(-2); } // already buil a cube on this planet for (int a = 0; a < mQuantumCubeList.Count; a++) { if (mQuantumCubeList[a].AllianceBelongingTo == all) { return(-3); } } // create cube GameObject cubeObj = Instantiate(GameLogic.Instance.prefabQuantumCube) as GameObject; QuantumCube cube = cubeObj.GetComponent <QuantumCube>(); Vector3 newPos = new Vector3(transform.localPosition.x + cubeOffsets[mQuantumCubeList.Count].x, transform.localPosition.y + cubeOffsets[mQuantumCubeList.Count].y, 0); cube.Setup(all, newPos, this); all.QuantumCubesLeft--; QuantumCubeList.Add(cube); return(0); }