Exemplo n.º 1
0
    // 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);
    }
Exemplo n.º 2
0
 // switch currently selected node to the neighbor in the given direction. if the direction isnt out
 // of grid bounds and if port is used with a bridge coming out, then we move out in the direction
 // by one or two node (depending on its a double bridge or not) and select that node
 public void SelectNeighborNode(Direction dir)
 {
     if (selectedNode.selectedHub.IsPortUsed(dir))
     {
         HorizontalBuildingType bridgeType = selectedNode.selectedHub.GetPortConnectorType(dir);
         int bridgeLen;
         if (bridgeType == HorizontalBuildingType.LargeBridge || bridgeType == HorizontalBuildingType.SmallBridge)
         {
             bridgeLen = 1;
         }
         else if (bridgeType == HorizontalBuildingType.LargeBridgeDouble || bridgeType == HorizontalBuildingType.SmallBridgeDouble)
         {
             bridgeLen = 2;
         }
         else
         {
             return; // port does not connect to bridge type, must be turret or something else
         }
         int x = currentStation.first + DirectionEastWest(dir) * bridgeLen;
         int y = currentStation.second + DirectionNorthSouth(dir) * bridgeLen;
         if (!IsIndexInGridBounds(x) || !IsIndexInGridBounds(y))
         {
             return; // no node exists in this direction because it's out of bounds
         }
         currentStation.first  = x;
         currentStation.second = y;
         prevSelectedNode      = selectedNode;
         lastDirChange         = dir;
         SetSelectedNode();
     }
 }
Exemplo n.º 3
0
 public static float GetBridgeLength(HorizontalBuildingType bridge)
 {
     if (bridge == HorizontalBuildingType.LargeBridge || bridge == HorizontalBuildingType.SmallBridge)
     {
         return(smBridgeLength);
     }
     if (bridge == HorizontalBuildingType.LargeBridgeDouble || bridge == HorizontalBuildingType.SmallBridgeDouble)
     {
         return(bigBridgeLength);
     }
     Debug.Log("bridge length on non bridge type");
     return(0);//turret
 }
Exemplo n.º 4
0
    public float GetBridgeLenByType(HorizontalBuildingType btype)
    {
        if (btype == HorizontalBuildingType.LargeBridge || btype == HorizontalBuildingType.SmallBridge)
        {
            return(SpaceStation.smBridgeLength);
        }
        else if (btype == HorizontalBuildingType.SmallBridgeDouble || btype == HorizontalBuildingType.LargeBridgeDouble)
        {
            return(SpaceStation.bigBridgeLength);
        }

        return(0);
    }
Exemplo n.º 5
0
    // 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);
    }
Exemplo n.º 6
0
    public Vector3 GetBridgePosFromPort(Direction dir, HorizontalBuildingType btype)
    {
        float bridgeLen = GetBridgeLenByType(btype);

        if (bridgeLen == 0)
        {
            return(Vector3.zero);
        }

        Vector3 ans = Vector3.zero;

        ans    = selectedHub.pos + SpaceStation.GetDisplacementVector(dir, bridgeLen / 2);
        ans.y -= SpaceStation.buildingHeightTable[BuildingType.MainConnector] / 2;
        return(ans);
    }
Exemplo n.º 7
0
 private GameObject MakeBridgeGOInstance(HorizontalBuildingType btype)
 {
     if (btype == HorizontalBuildingType.LargeBridge)
     {
         return((GameObject)Instantiate(Resources.Load("hbThickBridge")));
     }
     if (btype == HorizontalBuildingType.LargeBridgeDouble)
     {
         return((GameObject)Instantiate(Resources.Load("hbThickBridgeDouble")));
     }
     if (btype == HorizontalBuildingType.SmallBridge)
     {
         return((GameObject)Instantiate(Resources.Load("hbThinBridge")));
     }
     if (btype == HorizontalBuildingType.SmallBridgeDouble)
     {
         return((GameObject)Instantiate(Resources.Load("hbThinBridgeDouble")));
     }
     Debug.Log("building not supported");
     return(null);
 }
Exemplo n.º 8
0
    // if we build a hBuildingType building from the currently selected hub in the direction dir
    // return the position we end up at
    public Vector3 GetNextNodePosFromSelectedHub(Direction dir, HorizontalBuildingType hBuildingType)
    {
        float bridgeLen;

        if (hBuildingType == HorizontalBuildingType.LargeBridge || hBuildingType == HorizontalBuildingType.SmallBridge)
        {
            bridgeLen = SpaceStation.bigBridgeLength;
        }
        else if (hBuildingType == HorizontalBuildingType.SmallBridgeDouble || hBuildingType == HorizontalBuildingType.LargeBridgeDouble)
        {
            bridgeLen = SpaceStation.bigBridgeLength * 2;
        }
        else //if (hBuildingType == HorizontalBuildingType.Turret)
        {
            return(Vector3.zero);
        }

        if (selectedHub.IsPortUsed(dir))
        {
            return(selectedHub.pos + SpaceStation.GetDisplacementVector(dir, bridgeLen));
        }
        return(Vector3.zero);
    }
Exemplo n.º 9
0
    public Vector GetBridgePosFromPort(Direction dir, HorizontalBuildingType btype)
    {
        float bridgeLen;

        if (btype == HorizontalBuildingType.LargeBridge || btype == HorizontalBuildingType.SmallBridge)
        {
            bridgeLen = SpaceStation.smBridgeLength;
        }
        else if (btype == HorizontalBuildingType.SmallBridgeDouble || btype == HorizontalBuildingType.LargeBridgeDouble)
        {
            bridgeLen = SpaceStation.bigBridgeLength;
        }
        else //if (hBuildingType == HorizontalBuildingType.Turret)
        {
            return(Vector.Zero);
        }

        Vector ans = Vector.Zero;

        ans    = selectedHub.pos + SpaceStation.GetDisplacementVector(dir, bridgeLen / 2);
        ans.y -= SpaceStation.buildingHeightTable[BuildingType.MainConnector] / 2;
        return(ans);
    }
Exemplo n.º 10
0
    public void OnBridgeBuildButton(HorizontalBuildingType bridgeType)
    {
        if (bridgeType == HorizontalBuildingType.LargeBridgeDouble || bridgeType == HorizontalBuildingType.SmallBridgeDouble)
        {
            if (GetNodeInSelectedDir() == null)
            {
                stationGrid[currentStation.first + DirectionEastWest(selectedDir), currentStation.second + DirectionNorthSouth(selectedDir)] = new StationNode();
            }
            GetNodeInSelectedDir().IsBridgeCovered = true;
            TurretSlot slot1 = new TurretSlot();
            TurretSlot slot2 = new TurretSlot();
            selectedNode.BuildBridgeOnSelectedHub(selectedDir, bridgeType, ref slot1, ref slot2);
            turretSlots.Add(slot1); turretSlots.Add(slot2);
            bool        isValidNode    = true;;
            StationNode connectingNode = GetNodeInDirection(selectedDir, 2, ref isValidNode);
            if (isValidNode && connectingNode == null) // node was in bounds and has not been constructed
            {
                connectingNode = new StationNode();
            }
        }
        if (bridgeType == HorizontalBuildingType.LargeBridge || bridgeType == HorizontalBuildingType.SmallBridge)
        {
            TurretSlot slot1 = new TurretSlot();
            TurretSlot slot2 = new TurretSlot();
            if (GetNodeInSelectedDir() == null)
            {
                stationGrid[currentStation.first + DirectionEastWest(selectedDir), currentStation.second + DirectionNorthSouth(selectedDir)] = new StationNode();
            }
            selectedNode.BuildBridgeOnSelectedHub(selectedDir, bridgeType, ref slot1, ref slot2);
            turretSlots.Add(slot1); turretSlots.Add(slot2);
        }


        // note that any hubs we add, besides the first, will ned to check adjacent grid squares to see if they are covered by a bridge
        // or 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
    }