Exemplo n.º 1
0
        public void EstablishConnections()
        {
            if (!parent.Spawned)
            {
                return;
            }
            List <CompShipLandingBeacon> list  = new List <CompShipLandingBeacon>();
            List <CompShipLandingBeacon> list2 = new List <CompShipLandingBeacon>();
            List <Thing> list3 = parent.Map.listerThings.ThingsOfDef(ThingDefOf.ShipLandingBeacon);

            foreach (Thing item in list3)
            {
                CompShipLandingBeacon compShipLandingBeacon = item.TryGetComp <CompShipLandingBeacon>();
                if (compShipLandingBeacon != null && CanLinkTo(compShipLandingBeacon))
                {
                    if (parent.Position.x == compShipLandingBeacon.parent.Position.x)
                    {
                        list2.Add(compShipLandingBeacon);
                    }
                    else if (parent.Position.z == compShipLandingBeacon.parent.Position.z)
                    {
                        list.Add(compShipLandingBeacon);
                    }
                }
            }
            foreach (CompShipLandingBeacon h in list)
            {
                foreach (CompShipLandingBeacon v in list2)
                {
                    Thing thing = list3.FirstOrDefault((Thing x) => x.Position.x == h.parent.Position.x && x.Position.z == v.parent.Position.z);
                    if (thing != null)
                    {
                        ShipLandingArea shipLandingArea = new ShipLandingArea(CellRect.FromLimits(thing.Position, parent.Position).ContractedBy(1), parent.Map);
                        shipLandingArea.beacons = new List <CompShipLandingBeacon>
                        {
                            this,
                            thing.TryGetComp <CompShipLandingBeacon>(),
                            v,
                            h
                        };
                        TryAddArea(shipLandingArea);
                    }
                }
            }
            for (int num = landingAreas.Count - 1; num >= 0; num--)
            {
                foreach (CompShipLandingBeacon beacon in landingAreas[num].beacons)
                {
                    if (!beacon.TryAddArea(landingAreas[num]))
                    {
                        RemoveArea(landingAreas[num]);
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void RemoveArea(ShipLandingArea area)
 {
     foreach (CompShipLandingBeacon beacon in area.beacons)
     {
         if (beacon.landingAreas.Contains(area))
         {
             beacon.landingAreas.Remove(area);
         }
     }
     landingAreas.Remove(area);
 }
Exemplo n.º 3
0
 public bool TryAddArea(ShipLandingArea newArea)
 {
     if (!landingAreas.Contains(newArea))
     {
         for (int num = landingAreas.Count - 1; num >= 0; num--)
         {
             if (landingAreas[num].MyRect.Overlaps(newArea.MyRect) && landingAreas[num].MyRect != newArea.MyRect)
             {
                 if (landingAreas[num].MyRect.Area <= newArea.MyRect.Area)
                 {
                     return(false);
                 }
                 RemoveArea(landingAreas[num]);
             }
         }
         landingAreas.Add(newArea);
     }
     return(true);
 }