protected override bool OnTake(Unit unit)
        {
            base.OnTake(unit);

            if (Type.InfluenceType == null)
            {
                Log.Warning("InfluenceItem.OnTake: Type.InfluenceType == null");
                return false;
            }

            unit.AddInfluence(Type.InfluenceType, Type.InfluenceTime, true);
            return true;
        }
Beispiel #2
0
 //if spawned == null, we spawn a new unit immediately. if there is a spawned unit
 //we destroy it and defer the spawning of the new unit until that process has
 //completed by listening to the units destroyed event
 public void SpawnUnit(UnitType unit)
 {
     if (HasSpawnedUnit())
     {
         selectedUnit = unit;
         spawned.Destroying += new DestroyingDelegate(spawned_Destroying);
         spawned.SetForDeletion(false);
         spawned = null;
     }
     else
     {
         CreateUnit(unit);
     }
 }
Beispiel #3
0
        public Unit CreateUnit(UnitType unit)
        {
            Unit newUnit = (Unit)Entities.Instance.Create(unit, Parent);

            newUnit.Position = Position + new Vec3(0, 0, unit.SpawnHeight);
            newUnit.Rotation = Rotation;

            spawned = newUnit;
            newUnit.PostCreate();
            selectedUnit = null;
            if (UnitSpawned != null)
                UnitSpawned(newUnit);

            return newUnit;
        }
        protected override bool OnTake(Unit unit)
        {
            bool take = base.OnTake(unit);

            if (Type.WeaponType != null)
            {
                PlayerCharacter character = unit as PlayerCharacter;
                if (character != null && character.TakeWeapon(Type.WeaponType))
                    take = true;
            }
            else
                Log.Warning("WeaponItem.OnTake: Type.WeaponType == null");

            return take;
        }
        private float GetAttackObjectPriority(Unit obj)
        {
            if (ControlledObject == obj)
                return 0;
            if (obj.Intellect == null)
                return 0;
            if (obj.Intellect.Faction == null)
                return 0;
            if (Faction == obj.Intellect.Faction)
                return 0;

            Vec3 distance = obj.Position - ControlledObject.Position;
            float len = distance.Length();
            return 1.0f / len + 1.0f;
        }
Beispiel #6
0
        public bool Take( Unit unit )
        {
            bool ret = OnTake( unit );
            if( ret )
            {
                string soundTakeFullPath =
                    RelativePathUtils.ConvertToFullPath( Path.GetDirectoryName( Type.FilePath ), Type.SoundTake );
                unit.SoundPlay3D( soundTakeFullPath, .5f, true );

                if( EntitySystemWorld.Instance.IsServer() )
                    Server_SendSoundPlayTakeToAllClients();

                Die();
            }
            return ret;
        }
        protected override bool OnTake(Unit unit)
        {
            bool take = base.OnTake(unit);

            float healthMax = unit.Type.HealthMax;

            if (unit.Health < healthMax)
            {
                float health = unit.Health + Type.Health;
                if (health > healthMax)
                    health = healthMax;

                unit.Health = health;

                take = true;
            }

            return take;
        }
Beispiel #8
0
        protected override bool OnTake( Unit unit )
        {
            bool take = base.OnTake( unit );

            PlayerCharacter character = unit as PlayerCharacter;
            if( character != null )
            {
                bool taked = false;
                bool taked2 = false;

                if( Type.BulletType != null )
                    taked = character.TakeBullets( Type.BulletType, Type.BulletCount );
                if( Type.BulletType2 != null )
                    taked2 = character.TakeBullets( Type.BulletType2, Type.BulletCount2 );

                if( taked || taked2 )
                    take = true;
            }

            return take;
        }
        private MapObjectAttachedObject GetAliasPoint(Unit player, int position)
        {
            if (player == null || (position > 7 || position < 1))
                return null;

            foreach (MapObjectAttachedObject obj in player.AttachedObjects)
            {
                if (obj as MapObjectAttachedHelper == null)
                    continue;

                if (obj.Alias == "MainBall" && position == 6)
                    return obj;
                else if (obj.Alias == "MountLeft" && position == 1)
                    return obj;
                else if (obj.Alias == "MountRight" && position == 2)
                    return obj;
                else if (obj.Alias == "MountRear" && position == 3)
                    return obj;
                else if (obj.Alias == "MountFront" && position == 4)
                    return obj;
                else if (obj.Alias == "BallGlow" && position == 5)
                    return obj;
            }
            return null;
        }
        //void RemoveMiniTurret(Unit player)
        //{
        //    if (player == null)
        //    {
        //        return;
        //    }

        //    if (turret != null)
        //    {
        //        //turret.UserData = null;
        //        turret.SetForDeletion(false); //SetShouldDelete();
        //        activeturrets = 0;
        //        turretTimer = 0;
        //    }
        //}

        private MapObjectAttachedMesh GetAliasMesh(Unit player, int selecteditem)
        {
            foreach (MapObjectAttachedMesh obj in player.AttachedObjects)
            {
                if (obj as MapObjectAttachedMesh == null)
                    continue;

                if (obj.Alias == "BallGlow" && selecteditem == 1)
                {
                    return obj;
                }
                else if (obj.Alias == "MainBall" && selecteditem == 2)
                {
                    return obj;
                }
                //else
                //    return null;
            }
            return null;
        }
Beispiel #11
0
        //protected float GetMoveObjectPriority( Unit obj )
        //{
        //    return 0;
        //}
        protected float GetAttackObjectPriority( Unit obj )
        {
            if( ControlledObject == obj )
                return 0;

            if( obj.Intellect == null )
                return 0;

            //RTSConstructor specific
            if( ControlledObject.Type.Name == "RTSConstructor" )
            {
                if( Faction == obj.Intellect.Faction )
                {
                    if( obj.Health < obj.Type.HealthMax )
                    {
                        Vec3 distance = obj.Position - ControlledObject.Position;
                        float len = distance.Length();
                        return 1.0f / len + 1.0f;
                    }
                }
            }
            else
            {
                if( Faction != null && obj.Intellect.Faction != null && Faction != obj.Intellect.Faction )
                {
                    Vec3 distance = obj.Position - ControlledObject.Position;
                    float len = distance.Length();
                    return 1.0f / len + 1.0f;
                }
            }

            return 0;
        }
        //Incin - give weapons to players
        public bool GiveWeapon(WeaponType weaponType, Unit unit)
        {
            Weapon weapon = null;
            PlayerCharacter playerCharacter = null;
            playerCharacter = unit as PlayerCharacter;

            int index = GetWeaponIndex(weaponType);
            if (index == -1)
                return false;

            if (weapons[index].exists)
                return true;

            weapons[index].exists = true;
            SetActiveWeapon(index);

            if (playerCharacter != null)
            {
                weapon = playerCharacter.ActiveWeapon;
            }
            else
                return false;

            Gun gun = weapon as Gun;
            if (gun != null)
            {
                if (gun.Type.NormalMode != null && (gun.Type.NormalMode.BulletType != null && gun.Type.NormalMode.BulletCapacity != 0))
                {
                    gun.AddBullets(gun.Type.NormalMode.BulletType, gun.Type.NormalMode.BulletCapacity);
                    TakeBullets(gun.Type.NormalMode.BulletType, gun.Type.NormalMode.BulletCapacity);
                    //BulletItem bullet = (Bullet)gun.Type.NormalMode.BulletType.GetType();
                    //bullet.GiveBullets(unit);
                }
                else
                {
                    ;
                }

                if (gun.Type.AlternativeMode != null && (gun.Type.AlternativeMode.BulletType != null && gun.Type.AlternativeMode.BulletCapacity != 0))
                {
                    gun.AddBullets(gun.Type.AlternativeMode.BulletType, gun.Type.AlternativeMode.BulletCapacity);
                    TakeBullets(gun.Type.AlternativeMode.BulletType, gun.Type.AlternativeMode.BulletCapacity);
                }
                else
                {
                    ;
                }
            }

            return true;
        }
        //Incin  -- give all weapons to player
        public void GiveAllWeapons(Unit unit)
        {
            if (Type.Weapons.Count <= 0)
                return;

            for (int n = 0; n < Type.Weapons.Count; n++)
            {
                GiveWeapon(Type.Weapons[n].WeaponType, unit);
            }
        }
        private void ServerOrSingle_ChangeMainControlledUnit(Unit unit)
        {
            //Change player controlled unit
            mainNotActiveUnit = ControlledObject;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);

            if (mainNotActiveUnit != null)
            {
                SubscribeToDeletionEvent(mainNotActiveUnit);

                mainNotActiveUnit.SetIntellect(null, false);
                mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position;

                //disable collision for shapes and save contact groups
                mainNotActiveUnitShapeContactGroups = new Dictionary<Shape, int>();
                foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                {
                    foreach (Shape shape in body.Shapes)
                    {
                        mainNotActiveUnitShapeContactGroups.Add(shape, shape.ContactGroup);
                        shape.ContactGroup = (int)ContactGroup.NoContact;
                    }
                }

                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = false;

                ControlledObject = unit;
                unit.SetIntellect(this, false);

                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                    unit.InitialFaction = mainNotActiveUnit.InitialFaction;
                unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying;
            }
        }
        protected override void OnControlledObjectChange(Unit oldObject)
        {
            base.OnControlledObjectChange(oldObject);

            if (oldObject != null)
                oldObject.Damage -= ControlledObject_Damage;
            if (ControlledObject != null)
                ControlledObject.Damage += ControlledObject_Damage;
        }
        protected override void OnControlledObjectChange(Unit oldObject)
        {
            base.OnControlledObjectChange(oldObject);

            //update look direction
            if (ControlledObject != null)
                lookDirection = SphereDir.FromVector(ControlledObject.Rotation * new Vec3(1, 0, 0));

            //TankGame specific
            {
                //set small damage for player tank
                Tank oldTank = oldObject as Tank;
                if (oldTank != null)
                    oldTank.ReceiveDamageCoefficient = 1;
                Tank tank = ControlledObject as Tank;
                if (tank != null)
                    tank.ReceiveDamageCoefficient = .1f;
            }
        }
Beispiel #17
0
        protected override void OnTick()
        {
            base.OnTick();

            if (currentDelay < Type.HomingDelay)
            {
                currentDelay += TickDelta;
                return;
            }

            if (target == null || target.Died)
                target = AquireNewTarget();

            if (target == null)
                return;

            if (firstTick)
            {
                startDistance = (target.Position - Position).Length();
                firstTick = false;
            }

            // NH & KEEN - lose target if it is out of our view angle (stops missiles from doing endless circles around the target)
            if (Type.HomingAngle < 360.0f)
            {
                float homingAngle = Type.HomingAngle / 2;

                if (CalculateAngleToTarget(target) > new Degree(homingAngle).InRadians())
                {
                    target = null;
                    return;
                }
            }

            // NH & KEEN - explode if we get closer than proximityDistance to the target (used for Bluestreak Missiles)
            if ((target.Position - Position).Length() < Type.ProximityDistance)
            {
                HitObjects_Create();
                Die();
            }

            MomentaryTurnToPositionUpdate(target.Position);

            Vec3 velocity = Rotation.GetForward().GetNormalize() * Type.Velocity;
            base.Velocity = velocity;
        }
Beispiel #18
0
 protected virtual bool OnTake( Unit unit )
 {
     return false;
 }
        private void Client_ReceiveMainNotActiveUnit(RemoteEntityWorld sender, ReceiveDataReader reader)
        {
            uint networkUIN = reader.ReadVariableUInt32();
            if (!reader.Complete())
                return;

            if (mainNotActiveUnit != null)
                mainNotActiveUnit.Visible = true;

            mainNotActiveUnit = Entities.Instance.GetByNetworkUIN(networkUIN) as Unit;
        }
        private void ServerOrSingle_RestoreMainControlledUnit()
        {
            if (mainNotActiveUnit == null)
                return;

            if (ControlledObject != null)
            {
                ControlledObject.SetIntellect(null, false);
                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                    ControlledObject.InitialFaction = null;

                ControlledObject.Destroying -= AlternativeUnitAllowPlayerControl_Destroying;
            }

            if (!mainNotActiveUnit.IsSetForDeletion)
            {
                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = true;

                mainNotActiveUnit.Position = mainNotActiveUnitRestorePosition;
                //find free position for movable player controlled units
                if (ControlledObject != null)
                {
                    //Tank, AKCar specific
                    if (ControlledObject is Tank || ControlledObject is AKCar)
                    {
                        mainNotActiveUnit.Position = FindFreePositionForUnit(
                            mainNotActiveUnit, ControlledObject.Position);
                    }

                    if (ControlledObject is AKunit)
                    {
                        mainNotActiveUnit.Position = FindFreePositionForUnit(
                            mainNotActiveUnit, ControlledObject.Position);
                    }
                }

                mainNotActiveUnit.OldPosition = mainNotActiveUnit.Position;

                mainNotActiveUnit.Visible = true;

                UnsubscribeToDeletionEvent(mainNotActiveUnit);

                //restore contact groups for shapes
                if (mainNotActiveUnitShapeContactGroups != null)
                {
                    if (mainNotActiveUnit.PhysicsModel != null && mainNotActiveUnit.PhysicsModel.Bodies != null)
                    {
                        foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                        {
                            foreach (Shape shape in body.Shapes)
                            {
                                int group;
                                if (mainNotActiveUnitShapeContactGroups.TryGetValue(shape, out group))
                                    shape.ContactGroup = group;
                            }
                        }
                    }
                    mainNotActiveUnitShapeContactGroups.Clear();
                    mainNotActiveUnitShapeContactGroups = null;
                }

                mainNotActiveUnit.SetIntellect(this, false);

                ControlledObject = mainNotActiveUnit;
            }
            else
                ControlledObject = null;

            mainNotActiveUnit = null;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);
        }
        public void TryToChangeMainControlledUnit(Unit unit)
        {
            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
            {
                ServerOrSingle_ChangeMainControlledUnit(unit);
            }

            if (EntitySystemWorld.Instance.IsClientOnly())
            {
                SendDataWriter writer = BeginNetworkMessage(typeof(PlayerIntellect),
                    (ushort)NetworkMessages.ChangeMainControlledUnitToServer);
                writer.WriteVariableUInt32(unit.NetworkUIN);
                EndNetworkMessage();
            }
        }
        private MapObjectAttachedObject GetRandomAliasPoint(Unit player)
        {
            int position = (int)World.Instance.Random.NextFloat() * 4;

            if (position == 0)
                position = 1;

            foreach (MapObjectAttachedObject obj in player.AttachedObjects)
            {
                if (obj as MapObjectAttachedHelper == null)
                    continue;

                if (obj.Alias == "MountLeft" && position == 1)
                    return obj;
                else if (obj.Alias == "MountRight" && position == 2)
                    return obj;
                else if (obj.Alias == "MountRear" && position == 3)
                    return obj;
                else if (obj.Alias == "MountFront" && position == 4)
                    return obj;
            }
            return null;
        }
        private void SetMiniTurret(Unit player)
        {
            if (player == null)
                return;

            Vec3 location = new Vec3(1.5f, 1.5f, .5f); //set default above to start of player ball

            if (activeturrets == 1)
            {
                //Get Current position
                //Spawner spawner = new Spawner();

                //GameEntities.TurretAI turretAi = new GameEntities.TurretAI();
                //turretAi.unitWeapons
                turret = (Turret)Entities.Instance.Create("TurretScaled", Map.Instance);
                turret.Position = this.Position + location;
                turret.ViewRadius = turret.Type.ViewRadius;
                turret.Health = turret.Type.HealthMax;

                //if(player != null)
                //	turret.UserData = (Object)player;

                //turret.Armor = turret.Type.ArmorMax;
                turret.SubscribeToDeletionEvent((Entity)turret);
                //turret.InitialAI = turret.Type.InitialAI;
                //turret.InitialFaction = player.InitialFaction; //(FactionType)EntityTypes.Instance.GetByName("BadFaction");
                turret.PostCreate();

                //PhysicsModel.PopFromWorld();

                //////bool foundspot = true; //trick to make it reloop for next for loop

                //////for (int i = 1; i < 5; i++) //Change this for more alias MapObjectAttachedHelper points
                //////{
                //////    MapObjectAttachedObject helperpoint = GetAliasPoint(player, i);

                //////    if (helperpoint == null)
                //////        return;

                //////    location = Position + helperpoint.PositionOffset;

                //////    foreach (Body body in turret.PhysicsModel.Bodies)
                //////    {
                //////        if (foundspot == false) //flagging back to true to break foreach loop
                //////        {
                //////            //this should goto for loop
                //////            foundspot = true;
                //////            break;
                //////        }

                //////        //look down for a clear spot if none found break from for each
                //////        RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(new Ray( location, new Vec3(0, 0, -100)),
                //////        (int)body.Shapes[0].ContactGroup);

                //////        //find anything?
                //////        if (piercingResult.Length == 0)
                //////            continue;

                //////        foreach (RayCastResult result in piercingResult)
                //////        {
                //////            if (result.Shape.Body == body) //if self physics body
                //////                continue;

                //////            //check if throwing inside a mapobjects walls I am trying to do?
                //////            Bounds bounds = result.Shape.GetGlobalBounds().Intersect(body.Shapes[0].GetGlobalBounds());
                //////            if (bounds!= null &&
                //////                //body.GetGlobalBounds().IsContainsPoint(result.Shape.GetGlobalBounds().GetSize()))
                //////                //!result.Shape.GetGlobalBounds().IsContainsPoint(body.GetGlobalBounds().GetSize()))
                //////            {
                //////                if (result.Shape.ShapeType == Shape.Type.HeightField)
                //////                {
                //////                    turret.Position = new Vec3(location.X, location.Y, result.Position.Z + 1f); //1f is offset from floor
                //////                    //positioned = true;
                //////                    return;
                //////                }
                //////                else if (result.Shape.ShapeType == Shape.Type.Mesh || result.Shape.Body.Static)
                //////                {
                //////                    turret.Position = new Vec3(location.X, location.Y, result.Position.Z + 1f); //1f is offset from floor
                //////                    //positioned = true;
                //////                    return;
                //////                }
                //////                else
                //////                {
                //////                    foundspot = false;
                //////                    break;
                //////                }
                //////            }
                //////            else
                //////            {
                //////                //bad position
                //////                foundspot = false;
                //////                break;
                //////            }

                //////            //if (result.Shape.ShapeType == Shape.Type.HeightField)
                //////            //    turret.Position = new Vec3(location.X, location.Y, result.Position.Z + 1f); //1f is offset from floor
                //////            // {
                //////            //   //positioned = true;
                //////            //    return;
                //////            //}

                //////        }
                //////    }
                //////}

                foreach (Body body in turret.PhysicsModel.Bodies)
                {
                    RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(new Ray(this.Position + location, new Vec3(0, 0, -100)),
                     (int)body.Shapes[0].ContactGroup); //use only "base"

                    if (piercingResult.Length == 0)
                        continue;

                    foreach (RayCastResult result in piercingResult)
                    {
                        if (result.Shape.Body == body) //if self physics body
                            continue;

                        Bounds bounds = result.Shape.GetGlobalBounds().Intersect(body.Shapes[0].GetGlobalBounds());

                        if (bounds != null && result.Shape.Name.Contains("Map"))//.ShapeType != Shape.Type.HeightField)
                        {
                            turret.Position = this.Position + location;
                            return;
                        }
                        else if (result.Shape.ShapeType == Shape.Type.HeightField && result.Shape.Position != Vec3.Zero)
                        {
                            turret.Position = this.Position + location;//new Vec3(turret.Position.X, turret.Position.Y, result.Position.Z + 1f) + location; //1f is offset from floor
                            return;
                        }
                        else if (result.Distance <= 2f)
                        {
                            turret.Position = this.Position + location;
                            return;
                        }
                        else
                        {
                            // turret.Position = new Vec3(turret.Position.X, turret.Position.Y, turret.Position.Z) + location;
                        }
                    }
                }

                //PhysicsModel.PushToWorld();
            }
            else
            {
                return;
            }
        }
 protected float GetTaskAttackObjectPriority(Unit obj)
 {
     if (ControlledObject != obj)
     {
         if (obj.Intellect != null && Faction != obj.Intellect.Faction)
         {
             Vec3 distance = obj.Position - ControlledObject.Position;
             float len = distance.Length();
             if (len == 0)
                 len = .01f;
             return 1.0f / len + 1.0f;
         }
     }
     return 0;
 }
Beispiel #25
0
 /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnDeleteSubscribedToDeletionEvent(Entity)"/></summary>
 protected override void OnDeleteSubscribedToDeletionEvent(Entity entity)
 {
     base.OnDeleteSubscribedToDeletionEvent(entity);
     if (sourceUnit == entity)
         sourceUnit = null;
 }
        protected override void OnDeleteSubscribedToDeletionEvent(Entity entity)
        {
            base.OnDeleteSubscribedToDeletionEvent(entity);

            //mainNotActiveUnit destroyed
            if (mainNotActiveUnit == entity)
            {
                if (!IsSetForDeletion)
                {
                    if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
                        ServerOrSingle_RestoreMainControlledUnit();
                    else
                        mainNotActiveUnit = null;
                }
                else
                    mainNotActiveUnit = null;
            }
        }
		Vec3 FindFreePositionForUnit( Unit unit, Vec3 center )
		{
			Vec3 volumeSize = unit.MapBounds.GetSize() + new Vec3( 2, 2, 0 );
			for( float zOffset = 0; true; zOffset += .3f )
			{
				for( float radius = 3; radius < 8; radius += .6f )
				{
					for( float angle = 0; angle < MathFunctions.PI * 2; angle += MathFunctions.PI / 32 )
					{
						Vec3 pos = center + new Vec3( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ), 0 ) * radius + new Vec3( 0, 0, zOffset );
						Bounds volume = new Bounds( pos );
						volume.Expand( volumeSize * .5f );
						Body[] bodies = PhysicsWorld.Instance.VolumeCast( volume, (int)ContactGroup.CastOnlyContact );
						if( bodies.Length == 0 )
							return pos;
					}
				}
			}
		}
 protected virtual void OnControlledObjectChange(Unit oldObject)
 {
 }