void UpdateAnimationTree()
        {
            if (EntitySystemWorld.Instance.Simulation && !EntitySystemWorld.Instance.SystemPauseOfSimulation)
            {
                AnimationTree tree = GetFirstAnimationTree();
                if (tree != null)
                {
                    tree.SetParameterValue("weapon", activeWeapon != null ? 1 : 0);

                    Radian horizontalAngle = 0;
                    Radian verticalAngle   = 0;

                    PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                    if (playerIntellect != null)
                    {
                        Vec2 vec = Vec2.Zero;
                        vec.X += playerIntellect.GetControlKeyStrength(GameControlKeys.Forward);
                        vec.X -= playerIntellect.GetControlKeyStrength(GameControlKeys.Backward);
                        vec.Y += playerIntellect.GetControlKeyStrength(GameControlKeys.Left);
                        vec.Y -= playerIntellect.GetControlKeyStrength(GameControlKeys.Right);
                        if (vec.X < 0)
                        {
                            vec = -vec;
                        }
                        horizontalAngle = MathFunctions.ATan(vec.Y, vec.X);

                        verticalAngle = playerIntellect.LookDirection.Vertical;
                    }

                    tree.SetParameterValue("weaponHorizontalAngle", horizontalAngle.InDegrees());
                    tree.SetParameterValue("weaponVerticalAngle", verticalAngle.InDegrees());
                }
            }
        }
        public static void SetInstance(PlayerIntellect instance)
        {
            if (PlayerIntellect.instance != null && instance != null)
            {
                Log.Fatal("PlayerIntellect: SetInstance: Instance already initialized.");
            }

            if (PlayerIntellect.instance != null)
            {
                //This entity will accept commands of the player
                if (GameControlsManager.Instance != null)
                {
                    GameControlsManager.Instance.GameControlsEvent -=
                        PlayerIntellect.instance.GameControlsManager_GameControlsEvent;
                }
            }

            PlayerIntellect.instance = instance;

            if (PlayerIntellect.instance != null)
            {
                //This entity will accept commands of the player
                if (GameControlsManager.Instance != null)
                {
                    GameControlsManager.Instance.GameControlsEvent +=
                        PlayerIntellect.instance.GameControlsManager_GameControlsEvent;
                }
            }
        }
        public static void SetInstance(PlayerIntellect instance)
        {
            if (PlayerIntellect.instance != null && instance != null)
                Log.Fatal("PlayerIntellect: SetInstance: Instance already initialized.");

            if (PlayerIntellect.instance != null)
            {
                //This entity will accept commands of the player
                if (GameControlsManager.Instance != null)
                {
                    GameControlsManager.Instance.GameControlsEvent -=
                        PlayerIntellect.instance.GameControlsManager_GameControlsEvent;
                }
            }

            PlayerIntellect.instance = instance;

            if (PlayerIntellect.instance != null)
            {
                //This entity will accept commands of the player
                if (GameControlsManager.Instance != null)
                {
                    GameControlsManager.Instance.GameControlsEvent +=
                        PlayerIntellect.instance.GameControlsManager_GameControlsEvent;
                }
            }
        }
Exemplo n.º 4
0
        private void TickLadder()
        {
            //!!!!!â òèï?
            const float ladderClimbingSpeedWalk = 1.5f;
            const float ladderClimbingSpeedRun  = 3;

            SphereDir lookDirection = SphereDir.Zero;
            {
                PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                if (playerIntellect != null)
                {
                    lookDirection = playerIntellect.LookDirection;
                }
            }

            bool wantMove =
                Intellect.IsControlKeyPressed(GameControlKeys.Forward) ||
                Intellect.IsControlKeyPressed(GameControlKeys.Backward) ||
                Intellect.IsControlKeyPressed(GameControlKeys.Left) ||
                Intellect.IsControlKeyPressed(GameControlKeys.Right);

            Ladder ladder = FindLadder(currentLadder != null, wantMove, lookDirection);

            if (ladder != currentLadder)
            {
                SetCurrentLadder(ladder);
            }

            if (currentLadder != null)
            {
                Line line = currentLadder.GetClimbingLine();

                Vec3 projected = MathUtils.ProjectPointToLine(line.Start, line.End, Position);

                Vec3 newPosition = projected;

                float climbingSpeed = IsNeedRun() ? ladderClimbingSpeedRun : ladderClimbingSpeedWalk;

                Vec3 moveVector = Vec3.Zero;

                float lookingSide = new Radian(lookDirection.Vertical).InDegrees() > -20 ? 1 : -1;
                moveVector.Z += Intellect.GetControlKeyStrength(GameControlKeys.Forward) * lookingSide;
                moveVector.Z -= Intellect.GetControlKeyStrength(GameControlKeys.Backward) * lookingSide;

                newPosition += moveVector * (TickDelta * climbingSpeed);

                Position = newPosition;

                if (mainBody != null)
                {
                    mainBody.LinearVelocity  = Vec3.Zero;
                    mainBody.AngularVelocity = Vec3.Zero;
                }
            }
        }
Exemplo n.º 5
0
        public void ReceiveObject(MapObject obj, Teleporter source)
        {
            if (!string.IsNullOrEmpty(Type.ReceiveParticleName))
            {
                Map.Instance.CreateAutoDeleteParticleSystem(Type.ReceiveParticleName, Position);
            }

            if (source == null)
            {
                float offset = obj.Position.Z - obj.PhysicsModel.GetGlobalBounds().Minimum.Z;
                obj.Position = Position + new Vec3(0, 0, offset);
                obj.Rotation = Rotation;
                obj.SetOldTransform(obj.Position, obj.Rotation, obj.Scale);
            }
            else
            {
                Quat destRotation = Rotation * Mat3.FromRotateByZ(new Degree(180).InRadians()).ToQuat();

                foreach (Body body in obj.PhysicsModel.Bodies)
                {
                    body.Rotation = body.Rotation * source.Rotation.GetInverse() * destRotation;
                    Vec3 localPosOffset = (body.Position - source.Position) * source.Rotation.GetInverse();
                    body.Position    = Position + localPosOffset * destRotation;
                    body.OldPosition = body.Position;
                    body.OldRotation = body.Rotation;

                    body.LinearVelocity  = body.LinearVelocity * source.Rotation.GetInverse() * destRotation;
                    body.AngularVelocity = body.AngularVelocity * source.Rotation.GetInverse() * destRotation;
                }

                obj.UpdatePositionAndRotationByPhysics(true);
                obj.SetOldTransform(obj.Position, obj.Rotation, obj.Scale);

                Unit unit = obj as Unit;
                if (unit != null)
                {
                    PlayerIntellect playerIntellect = unit.Intellect as PlayerIntellect;
                    if (playerIntellect != null)
                    {
                        Vec3 vec = playerIntellect.LookDirection.GetVector();
                        Vec3 v   = vec * source.Rotation.GetInverse() * destRotation;
                        playerIntellect.LookDirection = SphereDir.FromVector(v);
                    }
                }
            }

            //add object to the list of processed objects. object can't activate teleportation.
            processedObjectsInActiveArea.AddWithCheckAlreadyContained(obj);

            //skip ticks to wait for update physics body of transfered object after teleportation.
            skipTicks += 2;
        }
Exemplo n.º 6
0
        void TickIntellect()
        {
            //horizontalMotor
            {
                float throttle = 0;
                throttle += Intellect.GetControlKeyStrength(GameControlKeys.Left);
                throttle -= Intellect.GetControlKeyStrength(GameControlKeys.Right);

                GearedMotor motor = PhysicsModel.GetMotor("horizontalMotor") as GearedMotor;
                if (motor != null)
                {
                    motor.Throttle = throttle;
                }
            }

            //gibbetMotor
            {
                ServoMotor motor = PhysicsModel.GetMotor("gibbetMotor") as ServoMotor;
                if (motor != null)
                {
                    Radian needAngle = motor.DesiredAngle;

                    needAngle += Intellect.GetControlKeyStrength(GameControlKeys.Forward) * .004f;
                    needAngle -= Intellect.GetControlKeyStrength(GameControlKeys.Backward) * .004f;

                    MathFunctions.Clamp(ref needAngle,
                                        new Degree(-20.0f).InRadians(), new Degree(40.0f).InRadians());

                    motor.DesiredAngle = needAngle;
                }
            }

            //Change player LookDirection at rotation
            PlayerIntellect intellect = Intellect as PlayerIntellect;

            if (intellect != null)
            {
                Vec3 lookVector = intellect.LookDirection.GetVector();
                lookVector *= OldRotation.GetInverse();
                lookVector *= Rotation;
                intellect.LookDirection = SphereDir.FromVector(lookVector);
            }
        }
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary>
        protected override void OnRender(Camera camera)
        {
            base.OnRender(camera);

            //get camera state
            bool playerIntellectFPSCamera = false;
            {
                PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                if (playerIntellect != null)
                {
                    playerIntellectFPSCamera = playerIntellect.FPSCamera;
                }
            }
            bool fpsCamera          = playerIntellectFPSCamera && camera.Purpose == Camera.Purposes.MainCamera;
            bool mainCameraUpdating = SceneManager.Instance.CurrentUpdatingCamera.Purpose == Camera.Purposes.MainCamera;

            //update first person arms
            MapObjectAttachedMesh firstPersonArmsAttachedMesh =
                GetFirstAttachedObjectByAlias("firstPersonArms") as MapObjectAttachedMesh;

            if (firstPersonArmsAttachedMesh != null)
            {
                if (EntitySystemWorld.Instance.WorldSimulationType != WorldSimulationTypes.Editor && fpsCamera)
                {
                    UpdateFirstPersonArmsAttachedMesh(firstPersonArmsAttachedMesh, camera);
                }
            }

            //update weapon
            if (activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade &&
                GameMap.Instance.GameType != GameMap.GameTypes.PlatformerDemo)
            {
                //update weapon attached objects visibility depending camera type
                activeWeapon.UpdateTPSFPSCameraAttachedObjectsVisibility(fpsCamera);

                //update weapon position. Guns only.
                if (activeWeaponAttachedObject.MapObject is Gun)
                {
                    //guns
                    if (fpsCamera)
                    {
                        if (firstPersonArmsAttachedMesh != null)
                        {
                            Vec3 p;
                            Quat r;
                            Vec3 s;

                            string slotName = activeWeapon.Type.CharacterBoneSlotFirstPersonCamera;
                            if (!string.IsNullOrEmpty(slotName))
                            {
                                MapObjectAttachedMesh.MeshBoneSlot slot = GetBoneSlotFromAttachedMeshes(slotName);
                                if (slot != null)
                                {
                                    slot.GetGlobalTransform(out p, out r, out s);
                                }
                                else
                                {
                                    p = camera.Position;
                                    r = camera.Rotation;
                                    s = new Vec3(1, 1, 1);
                                }
                            }
                            else
                            {
                                p = camera.Position + camera.Rotation * activeWeapon.Type.FPSCameraAttachPosition;
                                r = camera.Rotation;
                                s = new Vec3(1, 1, 1);
                            }

                            activeWeaponAttachedObject.MapObject.SetTransform(p, r, s);
                            activeWeaponAttachedObject.MapObject.SetOldTransform(p, r, s);
                        }
                    }
                    else
                    {
                        //change active weapon position for non animated characters
                        if (activeWeaponAttachedObject.BoneSlot == null)
                        {
                            Vec3  diff     = TurnToPosition - Position;
                            float dirV     = -MathFunctions.ATan(diff.Z, diff.ToVec2().Length());
                            float halfDirV = dirV * .5f;
                            Quat  rot      = new Quat(0, MathFunctions.Sin(halfDirV), 0,
                                                      MathFunctions.Cos(halfDirV));

                            activeWeaponAttachedObject.RotationOffset = rot;
                            activeWeaponAttachedObject.PositionOffset = Type.NotAnimatedWeaponAttachPosition;
                        }
                    }
                }

                //no cast shadows from active weapon in the FPS mode
                foreach (MapObjectAttachedObject weaponAttachedObject in activeWeapon.AttachedObjects)
                {
                    MapObjectAttachedMesh weaponAttachedMesh = weaponAttachedObject as MapObjectAttachedMesh;
                    if (weaponAttachedMesh != null && weaponAttachedMesh.MeshObject != null)
                    {
                        if (weaponAttachedMesh.RemainingTime == 0)
                        {
                            weaponAttachedMesh.MeshObject.CastShadows = !fpsCamera;
                        }
                    }
                }
            }

            //change visibility of attached objects
            {
                foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
                {
                    if (attachedObject == activeWeaponAttachedObject)
                    {
                        //attached weapon is always visible
                        attachedObject.Visible = true;
                    }
                    else if (attachedObject == firstPersonArmsAttachedMesh)
                    {
                        //first person arms is visible only for first person camera. The weapon is also must be activated.
                        attachedObject.Visible = fpsCamera && activeWeaponAttachedObject != null;
                    }
                    else
                    {
                        //hide attached objects for first person camera
                        attachedObject.Visible = !fpsCamera;
                    }
                }

                //hide shadows for first person camera mode
                if (playerIntellectFPSCamera && mainCameraUpdating && camera.Purpose == Camera.Purposes.ShadowMap)
                {
                    foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
                    {
                        attachedObject.Visible = false;
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnTick()"/>.</summary>
        protected override void OnTick()
        {
            base.OnTick();

            //single mode. recreate player units if need
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    if (PlayerManager.Instance != null)
                    {
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect == null || player.Intellect.ControlledObject == null)
                            {
                                ServerOrSingle_CreatePlayerUnit(player);
                            }
                        }
                    }
                }
            }

            //networking mode
            if (EntitySystemWorld.Instance.IsServer())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) //iNCIN -- OK NOW
                {
                    if (PlayerManager.Instance != null)
                    {
                        UserManagementServerNetworkService userManagementService =
                            GameNetworkServer.Instance.UserManagementService;

                        //remove users
again:
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.User != null && player.User != userManagementService.ServerUser)
                            {
                                NetworkNode.ConnectedNode connectedNode = player.User.ConnectedNode;
                                if (connectedNode == null ||
                                    connectedNode.Status != NetworkConnectionStatuses.Connected)
                                {
                                    if (player.Intellect != null)
                                    {
                                        PlayerIntellect playerIntellect = player.Intellect as PlayerIntellect;
                                        if (playerIntellect != null)
                                        {
                                            playerIntellect.TryToRestoreMainControlledUnit();
                                        }

                                        if (player.Intellect.ControlledObject != null)
                                        {
                                            player.Intellect.ControlledObject.Die();
                                        }
                                        player.Intellect.SetForDeletion(true);
                                        player.Intellect = null;
                                    }

                                    PlayerManager.Instance.ServerOrSingle_RemovePlayer(player);

                                    goto again;
                                }
                            }
                        }

                        //add users
                        foreach (UserManagementServerNetworkService.UserInfo user in
                                 userManagementService.Users)
                        {
                            //check whether "EntitySystem" service on the client
                            if (user.ConnectedNode != null)
                            {
                                if (!user.ConnectedNode.RemoteServices.Contains("EntitySystem"))
                                {
                                    continue;
                                }
                            }

                            PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                         ServerOrSingle_GetPlayer(user);

                            if (player == null)
                            {
                                player = PlayerManager.Instance.Server_AddClientPlayer(user);

                                PlayerIntellect intellect = (PlayerIntellect)Entities.Instance.
                                                            Create("PlayerIntellect", World.Instance);
                                intellect.PostCreate();

                                player.Intellect = intellect;

                                if (GameNetworkServer.Instance.UserManagementService.ServerUser != user)
                                {
                                    //player on client
                                    RemoteEntityWorld remoteEntityWorld = GameNetworkServer.Instance.
                                                                          EntitySystemService.GetRemoteEntityWorld(user);
                                    intellect.Server_SendSetInstanceToClient(remoteEntityWorld);
                                }
                                else
                                {
                                    //player on this server
                                    PlayerIntellect.SetInstance(intellect);
                                }

                                //player.Intellect = intellect;
                                if (player.User.Faction == null)
                                {
                                    return;
                                }
                                FactionType f = (FactionType)EntityTypes.Instance.GetByName(player.User.Faction);
                                player.Intellect.Faction = f;
                            }
                        }

                        //create units
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect != null && player.Intellect.ControlledObject == null)
                            {
                                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                                {
                                    ServerOrSingle_CreatePlayerUnit(player);
                                }
                                else
                                {
                                    ServerOrSingle_CreatePlayerUnit(player);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        internal void DoActionsAfterMapCreated()
        {
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    string playerName = "__SinglePlayer__";

                    //create Player
                    PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                 ServerOrSingle_GetPlayer(playerName);
                    if (player == null)
                    {
                        player = PlayerManager.Instance.Single_AddSinglePlayer(playerName);
                    }

                    //create PlayerIntellect
                    PlayerIntellect intellect = null;
                    {
                        //find already created PlayerIntellect
                        foreach (Entity entity in World.Instance.Children)
                        {
                            intellect = entity as PlayerIntellect;
                            if (intellect != null)
                            {
                                break;
                            }
                        }

                        if (intellect == null)
                        {
                            intellect = (PlayerIntellect)Entities.Instance.Create("PlayerIntellect",
                                                                                  World.Instance);
                            intellect.PostCreate();

                            player.Intellect = intellect;
                        }

                        //set instance
                        if (PlayerIntellect.Instance == null)
                        {
                            PlayerIntellect.SetInstance(intellect);
                        }
                    }

                    //create unit
                    if (intellect.ControlledObject == null)
                    {
                        MapObject spawnPoint = null;
                        if (!string.IsNullOrEmpty(needChangeMapSpawnPointName))
                        {
                            spawnPoint = Entities.Instance.GetByName(needChangeMapSpawnPointName) as MapObject;
                            if (spawnPoint == null)
                            {
                                Log.Warning("GameWorld: Object with name \"{0}\" does not exist.",
                                            needChangeMapSpawnPointName);
                            }
                        }

                        Unit unit;
                        if (spawnPoint != null)
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player, spawnPoint);
                        }
                        else
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player);
                        }

                        if (needChangeMapPlayerCharacterInformation != null)
                        {
                            PlayerCharacter playerCharacter = (PlayerCharacter)unit;
                            playerCharacter.ApplyChangeMapInformation(
                                needChangeMapPlayerCharacterInformation, spawnPoint);
                        }
                        else
                        {
                            if (unit != null)
                            {
                                intellect.LookDirection = SphereDir.FromVector(
                                    unit.Rotation.GetForward());
                            }
                        }
                    }
                }
            }

            needChangeMapName                       = null;
            needChangeMapSpawnPointName             = null;
            needChangeMapPlayerCharacterInformation = null;
        }