Ejemplo n.º 1
0
        public virtual void Update(CosmicUnit unit)
        {
            Position   = unit.Position;
            MoveVector = unit.MoveVector;

            Radius = unit.Radius;
        }
Ejemplo n.º 2
0
        public CosmicUnit ScanReference(Vector position)
        {
            float distance = float.MaxValue;

            Vector     cVector;
            CosmicUnit cUnit = null;

            lock (sync)
                foreach (CosmicUnit unit in stillUnits)
                {
                    cVector = unit.Position - position;

                    if (cVector < distance)
                    {
                        cUnit = unit;

                        distance = cVector.Length;
                    }
                }

            return(cUnit);
        }
Ejemplo n.º 3
0
        public CosmicUnit NextUnit(Vector position)
        {
            float distance = float.MaxValue;

            Vector     cVector;
            CosmicUnit cUnit = null;

            lock (sync)
                foreach (KeyValuePair <string, CosmicUnit> kvp in namedUnits)
                {
                    cVector = kvp.Value.Position - position;

                    if (cVector < distance)
                    {
                        cUnit = kvp.Value;

                        distance = cVector.Length;
                    }
                }

            return(cUnit);
        }
Ejemplo n.º 4
0
 public override void Update(CosmicUnit unit)
 {
     base.Update(unit);
     Timeout = 30;
 }
Ejemplo n.º 5
0
 public override void Update(CosmicUnit unit)
 {
     base.Update(unit);
 }
Ejemplo n.º 6
0
        public bool Merge(Map map)
        {
            CosmicUnit dst  = null;
            Vector     diff = null;

            lock (sync)
                lock (map.sync)
                {
                    foreach (CosmicUnit unit in map.stillUnits)
                    {
                        if (namedUnits.TryGetValue(unit.Name, out dst))
                        { // We found a unit match.
                            diff = unit.Position - dst.Position;

                            break;
                        }
                    }

                    if (diff == null)
                    {
                        return(false);
                    }

                    foreach (KeyValuePair <string, CosmicUnit> kvp in map.namedUnits)
                    {
                        if (namedUnits.TryGetValue(kvp.Key, out dst))
                        {
                            if (!kvp.Value.Still)
                            {
                                kvp.Value.Position -= diff;

                                dst.Update(kvp.Value);
                            }
                        }
                        else
                        {
                            kvp.Value.Position -= diff;

                            namedUnits.Add(kvp.Value.Name, kvp.Value);

                            if (kvp.Value.Still)
                            {
                                stillUnits.Add(kvp.Value);
                            }
                            else
                            {
                                mobileUnits.Add(kvp.Value);
                            }

                            if (kvp.Value is CosmicShot || kvp.Value is CosmicExplosion)
                            {
                                shotUnits.Add(kvp.Value);
                            }

                            if (kvp.Value is CosmicShip)
                            {
                                shipUnits.Add(kvp.Value);
                            }
                        }
                    }
                }

            return(true);
        }
Ejemplo n.º 7
0
        public Map(List <Unit> scannedUnits, Starship scanningShip)
        {
            namedUnits = new Dictionary <string, CosmicUnit>();

            foreach (Unit scannedUnit in scannedUnits)
            {
                if (scannedUnit.Mobility != Mobility.Still)
                {
                    movement = -scannedUnit.Movement;

                    break;
                }
            }

            if (movement == null)
            {
                movement = new Vector();
            }

            foreach (Unit scannedUnit in scannedUnits)
            {
                CosmicUnit tUnit = CosmicUnit.FromFVUnit(scannedUnit);

                if (tUnit.Still)
                {
                    tUnit.MoveVector = new Vector();
                }
                else
                {
                    tUnit.MoveVector += movement;
                }

                if (tUnit.Still)
                {
                    scanningShip.Movement = -scannedUnit.Movement;
                }

                namedUnits.Add(tUnit.Name, tUnit);

                if (tUnit.Still)
                {
                    stillUnits.Add(tUnit);
                }
                else
                {
                    mobileUnits.Add(tUnit);
                }

                if (tUnit is CosmicShot || tUnit is CosmicExplosion)
                {
                    shotUnits.Add(tUnit);
                }

                if (tUnit is CosmicShip)
                {
                    shipUnits.Add(tUnit);
                }
            }

            CosmicStarship ownShip = new CosmicStarship(scanningShip);

            ownShip.MoveVector = scanningShip.Movement;

            namedUnits.Add(ownShip.Name, ownShip);

            if (ownShip.Still)
            {
                stillUnits.Add(ownShip);
            }
            else
            {
                mobileUnits.Add(ownShip);
            }

            shipUnits.Add(ownShip);
        }
Ejemplo n.º 8
0
 public bool TryGetValue(string name, out CosmicUnit unit)
 {
     lock (sync)
         return(namedUnits.TryGetValue(name, out unit));
 }