// user of function ensures that correct bridge type is used for the building public bool BuildBridgeOnSelectedHub(Direction dir, HorizontalBuildingType connectedNodeType, ref TurretSlot slot1, ref TurretSlot slot2) { if (selectedHub.IsPortUsed(dir)) { return(false); } PortBuilding newBridge = new PortBuilding(); newBridge.dir = dir; newBridge.btype = connectedNodeType; newBridge.mesh = MakeBridgeGOInstance(connectedNodeType); Vector3 bridgePos = GetBridgePosFromPort(dir, connectedNodeType); newBridge.mesh.transform.position = bridgePos; if (dir == Direction.North || dir == Direction.South) { slot1.pos = bridgePos - new Vector3(0, -12, (GetBridgeLenByType(connectedNodeType) / 2f - 18f)); slot2.pos = bridgePos + new Vector3(0, 12, (GetBridgeLenByType(connectedNodeType) / 2f - 18f)); newBridge.mesh.transform.rotation = Quaternion.Euler(180, 90, 90); } else { slot1.pos = bridgePos - new Vector3((GetBridgeLenByType(connectedNodeType) / 2f - 18f), -12, 0); slot2.pos = bridgePos + new Vector3((GetBridgeLenByType(connectedNodeType) / 2f - 18f), 12, 0); newBridge.mesh.transform.rotation = Quaternion.Euler(180, 0, 90); } slot1.associatedBridge = newBridge; slot2.associatedBridge = newBridge; selectedHub.portsUsed.Add(newBridge); return(true); }
// user of function ensures that correct bridge type is used for the building public bool BuildBridgeOnSelectedHub(Direction dir, HorizontalBuildingType connectedNodeType) { if (selectedHub.IsPortUsed(dir)) { return(false); } PortBuilding newBridge = new PortBuilding(); newBridge.dir = dir; newBridge.btype = connectedNodeType; selectedHub.portsUsed.Add(newBridge); return(true); }
public void OnHubButton() { if (IsEmpty) // create first hub for space station { Vector3 playerPos = GetPlayerPos(); if (playerPos == Vector3.zero) // player doesnt exist { return; } CreateFirstHub(playerPos); IsEmpty = false; OnBottomSelected(); } else { // if they are also a hub with the adjacent port used - in both cases it means the new hubs port will need to be set to used upon creation //note that we could allow more hubs to be created on the node if the tower is empty at this height, this might be cooler if (selectedNode.selectedHub == null) // no hub created on this node, { PortBuilding?connectingBridge = prevSelectedNode.GetPortBuilding(lastDirChange); if (connectingBridge != null) // prev node has a bridge going to this node { Vector3 prevNodePos = prevSelectedNode.selectedHub.pos; Vector3 bridgeDisplacement = GetDisplacementVector(lastDirChange, GetBridgeLength(prevSelectedNode.selectedHub.GetPortConnectorType(lastDirChange))); Vector3 newHubPos = prevNodePos + bridgeDisplacement; PortBuilding connectingBridgeReg = (PortBuilding)connectingBridge; connectingBridgeReg.dir = ReverseDirection(connectingBridgeReg.dir); selectedNode.Initialize(true, connectingBridgeReg, newHubPos); OnHubSelect(); OnBottomSelected(); } } } }
public TurretSlot(PortBuilding bridge, Vector3 pos) { associatedBridge = bridge; this.pos = pos; isOccupied = false; }
// hubs used port is the occupied port for this newly initialized node's hub. public void Initialize(bool isBigHub, PortBuilding hubsUsedPort, Vector3 pos) { Initialize(isBigHub, pos); selectedHub.portsUsed.Add(hubsUsedPort); }