Ejemplo n.º 1
0
        private void SpawnCargoShip()
        {
            if (m_empireData.civilianFleet.Count >= 2)
            {
                return;
            }

            IMyPlayer randomPlayer = GetRandomPlayer();

            if (randomPlayer == null)
            {
                return;
            }
            SectorId originSector = m_empireData.ownedSectors[Util.rand.Next(m_empireData.ownedSectors.Count)];
            Vector3D sectorCenter = SectorManager.CenterFromSector(originSector);
            Vector3D dirToSector  = Vector3D.Normalize(sectorCenter - randomPlayer.GetPosition());
            Vector3D crossPoint   = MathExtender.RandomPerpendicularVector(dirToSector) * CARGOSHIP_CROSS_DIST;

            GroupInfo group = GetRandomSpawnGroup(SpawnerClass.CIVILIAN, m_empireData.credits);

            if (group == null)
            {
                return;
            }
            Vector3D routeDir = Vector3D.Normalize(sectorCenter - crossPoint);

            if (Util.rand.NextDouble() < 0.5)
            {
                routeDir *= -1;
            }
            Vector3D spawnStart = crossPoint - (routeDir * CARGOSHIP_SPAWN_DIST);
            Vector3D spawnEnd   = crossPoint + (routeDir * CARGOSHIP_SPAWN_DIST * 10);

            SpawnForGroup(group, EncounterType.TransientCargoship, spawnStart, spawnEnd);
        }
Ejemplo n.º 2
0
        /**
         * Convert a sector to it's center
         */
        public static Vector3D CenterFromSector(SectorId pos)
        {
            Vector3D sectorFloat = new Vector3D(pos.x, pos.y, pos.z);

            sectorFloat *= SECTOR_SIZE;
            return(sectorFloat);
        }
Ejemplo n.º 3
0
        public static Sector GetSector(SectorId id)
        {
            Sector sector = null;

            if (m_ocupiedSectors.TryGetValue(id, out sector))
            {
                return(sector);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static bool OwnFreeSector(SectorId id, EmpireData capturingEmpire)
        {
            Sector sector = GetSector(id);

            if (sector == null)
            {
                m_ocupiedSectors.Add(id, new Sector(capturingEmpire));
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public override int GetHashCode()
        {
            //Get hash code for the Name field if it is not null.
            int hashProductName = SectorId.GetHashCode();

            //Get hash code for the Code field.
            int hashProductCode = SectorName.GetHashCode();

            //Calculate the hash code for the product.
            return(hashProductName ^ hashProductCode);
        }
Ejemplo n.º 6
0
 public bool Equals(RelativePerformanceSectorData other)
 {
     if (Object.ReferenceEquals(other, null))
     {
         return(false);
     }
     if (Object.ReferenceEquals(this, other))
     {
         return(true);
     }
     return(SectorId.Equals(other.SectorId) && SectorName.Equals(other.SectorName));
 }
 public override int GetHashCode()
 {
     return(SectorId.GetHashCode());
 }
Ejemplo n.º 8
0
        public static SectorId FindFreeSectorNear(SectorId origin, HashSet <SectorId> checkedSectors = null)
        {
            if (!m_ocupiedSectors.ContainsKey(origin))
            {
                if (!(origin.x == 0 && origin.y == 0 && origin.z == 0))
                {
                    return(origin);
                }
            }
            List <SectorId> checkSectors    = new List <SectorId>();
            List <SectorId> freeSectors     = new List <SectorId>();
            List <SectorId> occupiedSectors = new List <SectorId>();

            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y + 1, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y + 1, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y + 1, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y + 0, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y + 0, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y + 0, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y - 1, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y - 1, z = origin.z + 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y - 1, z = origin.z + 1
            });

            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y + 1, z = origin.z + 0
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y + 1, z = origin.z + 0
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y + 1, z = origin.z + 0
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y + 0, z = origin.z + 0
            });

            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y + 0, z = origin.z + 0
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y - 1, z = origin.z + 0
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y - 1, z = origin.z + 0
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y - 1, z = origin.z + 0
            });

            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y + 1, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y + 1, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y + 1, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y + 0, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y + 0, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y + 0, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 1, y = origin.y - 1, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x + 0, y = origin.y - 1, z = origin.z - 1
            });
            checkSectors.Add(new SectorId()
            {
                x = origin.x - 1, y = origin.y - 1, z = origin.z - 1
            });

            foreach (SectorId id in checkSectors)
            {
                if (m_ocupiedSectors.ContainsKey(id) && (checkedSectors == null || !checkedSectors.Contains(id)))
                {
                    occupiedSectors.Add(id);
                }
                else
                {
                    freeSectors.Add(id);
                }
            }

            if (freeSectors.Count > 0)
            {
                return(freeSectors[Util.rand.Next(freeSectors.Count)]);
            }

            if (checkedSectors == null)
            {
                checkedSectors = new HashSet <SectorId>();
            }
            checkedSectors.Add(origin);
            foreach (SectorId o in occupiedSectors)
            {
                checkedSectors.Add(o);
            }

            Util.Shuffle(occupiedSectors);
            foreach (SectorId id in occupiedSectors)
            {
                SectorId found = FindFreeSectorNear(id, checkedSectors);
                if (found != null)
                {
                    return(found);
                }
            }
            return(null);
        }