Ejemplo n.º 1
0
 /// <summary>
 /// Drops the current Load.
 /// </summary>
 public void Drop()
 {
     if (carrierLoad != null)
     {
         carrierLoad.RemoveCarrier(this);
         CarrierLoad = null;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Pick up a new Item.
        /// </summary>
        /// <param name="item">Portable Item</param>
        public bool Carry(PortableProperty item)
        {
            // item == null means a Drop
            if (item == null)
            {
                Drop();
                return(true);
            }

            // Handle the old Load
            if (CarrierLoad != null)
            {
                // Ignore if old load the same as the new load
                if (CarrierLoad == item)
                {
                    return(true);
                }

                // Drop the old load
                Drop();
            }

            // Check if the new load is part of the simulation
            if (Item.Engine == null)
            {
                throw new NotSupportedException("Carrier is not Part of the Simulation");
            }
            if (item.Item.Engine == null || item.Item.Engine != Item.Engine)
            {
                throw new NotSupportedException("Portable is not Part of the same Simulation");
            }

            // Check if the load is not the carrier
            if (item.Item == Item)
            {
                throw new NotSupportedException("Carrier can not carry itself");
            }

            // TODO: Check for circular references (Carrier/Portable <-> Carrier/Portable)

            // Check if load is close enought
            if (item.PortableRadius < Item.GetDistance(Item, item.Item))
            {
                return(false);
            }

            // Pick up Item
            CarrierLoad = item;
            item.AddCarrier(this);
            return(true);
        }
Ejemplo n.º 3
0
        public PhysicsUnit(Item item, Dictionary<int, PhysicsUnit> items)
        {
            this.item = item;
            this.items = items;
            moving = item.GetProperty<WalkingProperty>();
            collidable = item.GetProperty<CollidableProperty>();
            carrier = item.GetProperty<CarrierProperty>();
            portable = item.GetProperty<PortableProperty>();

            map = item.Engine.Map;

            mapSize = map.GetSize();

            // Attach Item Stuff
            item.CellChanged += item_CellChanged;

            // Attach Moving Stuff
            if (moving != null)
            {
                moving.OnMaximumMoveSpeedChanged += moving_OnMaximumMoveSpeedChanged;
                moving.OnMoveDirectionChanged += moving_OnMoveDirectionChanged;
                moving.OnMoveSpeedChanged += moving_OnMoveSpeedChanged;
                moving.MoveMalus = 1;
            }

            // Attach Collision Stuff
            if (collidable != null)
            {
                collidable.OnCollisionMassChanged += collidable_OnCollisionMassChanged;
                collidable.OnCollisionFixedChanged += collidable_OnCollisionFixedChanged;
            }

            // Attach Carrier Stuff
            if (carrier != null)
            {
                carrier.OnCarrierLoadChanged += carrier_OnCarrierLoadChanged;
                carrier.OnCarrierStrengthChanged += carrier_OnCarrierStrengthChanged;
            }

            // Attach Portable Stuff
            if (portable != null)
            {
                portable.OnPortableWeightChanged += portable_OnPortableMassChanged;
                portable.OnNewCarrierItem += portable_OnNewCarrierItem;
                portable.OnLostCarrierItem += portable_OnLostCarrierItem;
                clusterUnits = new HashSet<PhysicsUnit>();
            }

            Recalc();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Das tragende Teil wurde geändert - Abhängigkeiten neu prüfen
        /// </summary>
        /// <param name="item"></param>
        /// <param name="newValue"></param>
        private void carrier_OnCarrierLoadChanged(Item item, PortableProperty newValue)
        {
            if (newValue != null)
            {
                int id = newValue.Item.Id;
                if (!items.ContainsKey(id))
                    throw new IndexOutOfRangeException("Item does not exist");

                load = items[id];
            }
            else
                load = null;

            Recalc();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Default Constructor for the Type Mapper.
 /// </summary>
 /// <param name="item">Related Engine Item</param>
 /// <param name="property">Related Engine Property</param>
 public PortableState(Item item, PortableProperty property) : base(item, property)
 {
     // Bind Weight Property to the Item Weight
     Weight = property.PortableWeight;
     property.OnPortableWeightChanged += (i, v) => { Weight = v; };
 }