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; } } }
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); } }
void region_ObjectIn(Entity entity, MapObject obj) { if (!active || destination == null) { return; } if (obj == this) { return; } Vec3 localOldPosOffset = (obj.OldPosition - Position) * Rotation.GetInverse(); if (localOldPosOffset.X < -.3f) { return; } foreach (Body body in obj.PhysicsModel.Bodies) { body.Rotation = body.Rotation * Rotation.GetInverse() * destination.Rotation; body.OldRotation = body.Rotation; Vec3 localPosOffset = (body.Position - Position) * Rotation.GetInverse(); localPosOffset.Y = -localPosOffset.Y; localPosOffset.X = .3f; body.Position = destination.Position + localPosOffset * destination.Rotation; body.OldPosition = body.Position; Vec3 vel = body.LinearVelocity * Rotation.GetInverse(); vel.X = -vel.X; vel.Y = -vel.Y; vel *= destination.Rotation; body.LinearVelocity = vel; vel = body.AngularVelocity * Rotation.GetInverse(); vel.X = -vel.X; vel.Y = -vel.Y; vel *= destination.Rotation; body.AngularVelocity = vel; } 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 * Rotation.GetInverse(); v.X = -v.X; v.Y = -v.Y; v *= destination.Rotation; playerIntellect.LookDirection = SphereDir.FromVector(v); } } //!!!!!!need check telefrag }
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; } } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary> protected override void OnPostCreate( bool loaded ) { base.OnPostCreate( loaded ); if( instance != null ) throw new Exception( "PlayerIntellect already created" ); instance = this; Faction = (FactionType)EntityTypes.Instance.GetByName( "GoodFaction" ); Trace.Assert( Faction != null ); //This entity will accept commands of the player if( GameControlsManager.Instance != null ) GameControlsManager.Instance.GameControlsEvent += GameControlsManager_GameControlsEvent; AllowTakeItems = true; AddTimer(); }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnDestroy()"/>.</summary> protected override void OnDestroy() { if( GameControlsManager.Instance != null ) GameControlsManager.Instance.GameControlsEvent -= GameControlsManager_GameControlsEvent; base.OnDestroy(); if( !IsEditorExcludedFromWorld() ) instance = null; }
/// <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) { 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) { 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.SetShouldDelete(); 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); } } } //create units foreach (PlayerManager.ServerOrSingle_Player player in PlayerManager.Instance.ServerOrSingle_Players) { if (player.Intellect != null && player.Intellect.ControlledObject == null) { ServerOrSingle_CreatePlayerUnit(player); } } } } } }
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) { 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) { SpawnPoint spawnPoint = null; if (shouldChangeMapSpawnPointName != null) { spawnPoint = Entities.Instance.GetByName(shouldChangeMapSpawnPointName) as SpawnPoint; if (spawnPoint == null) { Log.Error("GameWorld: SpawnPoint with name \"{0}\" is not defined.", shouldChangeMapSpawnPointName); } } Unit unit; if (spawnPoint != null) { unit = ServerOrSingle_CreatePlayerUnit(player, spawnPoint); } else { unit = ServerOrSingle_CreatePlayerUnit(player); } if (shouldChangeMapPlayerCharacterInformation != null) { PlayerCharacter playerCharacter = (PlayerCharacter)unit; playerCharacter.ApplyChangeMapInformation( shouldChangeMapPlayerCharacterInformation, spawnPoint); } else { if (unit != null) { intellect.LookDirection = SphereDir.FromVector( unit.Rotation.GetForward()); } } } } } shouldChangeMapName = null; shouldChangeMapSpawnPointName = null; shouldChangeMapPlayerCharacterInformation = null; }
/// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnRender(Camera)"/>.</summary> protected override void OnRender(Camera camera) { base.OnRender(camera); //no update in cubemap generation mode if (Map.Instance.CubemapGenerationMode) { return; } bool playerIntellectFPSCamera = false; { PlayerIntellect playerIntellect = Intellect as PlayerIntellect; if (playerIntellect != null) { playerIntellectFPSCamera = playerIntellect.FPSCamera; } } bool fpsCamera = playerIntellectFPSCamera && RendererWorld.Instance.DefaultCamera == camera; if (activeWeapon != null && GameMap.Instance.GameType != GameMap.GameTypes.TPSArcade) { //FPS mesh material activeWeapon.FPSMeshMaterialNameEnabled = fpsCamera && !camera.IsForShadowMapGeneration(); //update weapon vertical orientation if (activeWeaponAttachedObject.MapObject is Gun) { //for guns if (fpsCamera) { Vec3 p = camera.Position + camera.Rotation * Type.WeaponFPSAttachPosition; Quat r = camera.Rotation; Vec3 s = new Vec3(1, 1, 1); activeWeaponAttachedObject.MapObject.SetTransform(p, r, s); activeWeaponAttachedObject.MapObject.SetOldTransform(p, r, s); //Vec3 diff = playerIntellect.LookDirection.GetVector(); //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.FPSCameraOffset + Type.WeaponFPSAttachPosition * rot; } else { float dirV; if (EntitySystemWorld.Instance.IsClientOnly()) { //client specific dirV = client_weaponVerticalAngle; } else { Vec3 diff = TurnToPosition - Position; 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.WeaponAttachPosition; } } else { //for melee weapons activeWeaponAttachedObject.RotationOffset = Quat.Identity; activeWeaponAttachedObject.PositionOffset = Vec3.Zero; } //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; } } } } //only weapon visible in the FPS mode foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { attachedObject.Visible = !fpsCamera || attachedObject == activeWeaponAttachedObject; } //no cast shadows in the FPS mode if (camera.IsForShadowMapGeneration() && playerIntellectFPSCamera) { foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { attachedObject.Visible = false; } } }