Exemplo n.º 1
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate(bool loaded)
        {
            base.OnPostCreate(loaded);

            //mainMeshObject = GetFirstAttachedObjectByAlias("animations") as MapObjectAttachedMesh;

            foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
            {
                MapObjectAttachedMapObject attachedMapObject = attachedObject as MapObjectAttachedMapObject;
                if (attachedMapObject == null)
                    continue;
            }

            AddTimer();

            if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor)
            {
                if (PhysicsModel == null)
                {
                    Log.Error("Mech: Physics model not exists.");
                    return;
                }

                chassisBody = PhysicsModel.GetBody("mainBody");
                if (chassisBody == null)
                {
                    Log.Error("Mech: \"mainBody\" body does not exist.");
                    return;
                }
            }

            //initialize currentGear
            currentGear = Type.Gears.Find(delegate(MechType.Gear gear)
            {
                return gear.Number == 0;
            });

            //if (loaded && EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor)
            //{
            //if (chassisBody != null)
            //    chassisBody.Static = true;
            // }
        }
Exemplo n.º 2
0
        private void TickCurrentGear()
        {
            //currently gears used only for sounds

            if (currentGear == null)
                return;

            if (motorOn)
            {
                float speed = GetFootsSpeed();

                MechType.Gear newGear = null;

                if (speed < currentGear.SpeedRange.Minimum || speed > currentGear.SpeedRange.Maximum)
                {
                    //find new gear
                    newGear = Type.Gears.Find(delegate(MechType.Gear gear)
                    {
                        return speed >= gear.SpeedRange.Minimum && speed <= gear.SpeedRange.Maximum;
                    });
                }

                if (newGear != null && currentGear != newGear)
                {
                    //change gear
                    MechType.Gear oldGear = currentGear;
                    OnGearChange(oldGear, newGear);
                    currentGear = newGear;
                }
            }
            else
            {
                if (currentGear.Number != 0)
                {
                    currentGear = Type.Gears.Find(delegate(MechType.Gear gear)
                    {
                        return gear.Number == 0;
                    });
                }
            }
        }