internal override bool Tool_MouseButtonClick( MouseButton Button ) { Actor Actor; Actor = GameEnv.GetActiveActor(); // printf("Click : %ld\n",Button); if( Actor != null ) { switch( Button ) { case MouseButton.Button2: // Right mouse button if( Actor.PointedVoxel.Collided ) { Inventory.Entry InventorySlot; ushort VoxelType; //ULong OtherInfos; btVector3 VoxelCenter, VoxelDistance; bool IsOnGround; ; // Ensure you are not to close to the voxel position you want to build. bool NotTooClose; NotTooClose = true; Actor.PointedVoxel.PredPointedVoxel.GetVoxelCenterCoords( out VoxelCenter ); VoxelCenter.Sub( ref Actor.ViewDirection.m_origin, out VoxelDistance ); //printf("VoxelDistance : %lf,%lf,%lf\n", VoxelDistance.x, VoxelDistance.y, VoxelDistance.z); if( VoxelDistance.y < 512.0 && VoxelDistance.y > -127.0 ) { if( ( VoxelDistance.x < 203.0 && VoxelDistance.x > -203.0 ) && ( VoxelDistance.z < 203.0 && VoxelDistance.z > -203.0 ) ) { NotTooClose = false; GameEnv.GameWindow_Advertising.Advertise( "TOO CLOSE", GameWindow_Advertising.Visibility.VISIBILITY_HIGH, 0, 2000, 1000 ); } } InventorySlot = Actor.Inventory.GetActualItemSlot(); VoxelType = InventorySlot.VoxelType; //OtherInfos = 0; // printf("Location (%lf,%lf,%lf) Voxel (%lf,%lf,%lf)\n", Actor.Location.x,Actor.Location.y,Actor.Location.z, VoxelCenter.x, VoxelCenter.y, VoxelCenter.z); #if COMPILEOPTION_ALLOWJUMPANDBUILD IsOnGround = true; #else IsOnGround = Actor.IsOnGround; #endif if( VoxelType > 0 && InventorySlot.Quantity > 0 && NotTooClose && IsOnGround ) { if( 1 == Actor.Inventory.UnstoreBlocks( VoxelType, 1 ) ) { //VoxelExtensionType = GameEnv.VoxelTypeManager.GetVoxelType(VoxelType).ExtensionType; //if (VoxelExtensionType!=0) OtherInfos = (ULong)GameEnv.World.ExtensionFactory.CreateVoxelExtension(VoxelExtensionType); //GameEnv.World.SetVoxel_WithCullingUpdate(Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, OtherInfos); // new VoxelRef VLoc; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X , Actor.PointedVoxel.PredPointedVoxel.Y , Actor.PointedVoxel.PredPointedVoxel.Z , VoxelType , VoxelSector.ModifiedFieldFlags.CRITICAL, true , out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( false ) { int dx = Actor.PointedVoxel.PredPointedVoxel.X - Actor.PointedVoxel.PointedVoxel.X; int dy = Actor.PointedVoxel.PredPointedVoxel.Y - Actor.PointedVoxel.PointedVoxel.Y; int dz = Actor.PointedVoxel.PredPointedVoxel.Z - Actor.PointedVoxel.PointedVoxel.Z; if( dx != 0 ) { if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3 + 1, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3 - 1, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3, Actor.PointedVoxel.PredPointedVoxel.Y + 1, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3, Actor.PointedVoxel.PredPointedVoxel.Y - 1, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z + 1, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + dx * 3, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z - 1, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; } if( dy != 0 ) { if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + 1, Actor.PointedVoxel.PredPointedVoxel.Y + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X - 1, Actor.PointedVoxel.PredPointedVoxel.Y + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + 1 + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y - 1 + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + 0 + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z + 1, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + 0 + dy * 3, Actor.PointedVoxel.PredPointedVoxel.Z - 1, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; } if( dz != 0 ) { if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X + 1, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X - 1, Actor.PointedVoxel.PredPointedVoxel.Y, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + 1, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y - 1, Actor.PointedVoxel.PredPointedVoxel.Z, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + 0, Actor.PointedVoxel.PredPointedVoxel.Z + 1, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PredPointedVoxel.X, Actor.PointedVoxel.PredPointedVoxel.Y + 0, Actor.PointedVoxel.PredPointedVoxel.Z - 1, VoxelType, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; } } GameEnv.Sound.PlaySound( 7 ); } } } break; case MouseButton.Button5: // Wheel Button if( Actor.PointedVoxel.Collided ) { VoxelExtension OtherInfos; ushort VoxelType; int x, y, z; x = Actor.PointedVoxel.PointedVoxel.X; y = Actor.PointedVoxel.PointedVoxel.Y; z = Actor.PointedVoxel.PointedVoxel.Z; VoxelType = GameEnv.World.GetVoxelExt( x, y, z, out OtherInfos ); GameEnv.VoxelTypeManager.GetVoxelType( VoxelType ).UserAction_Activate( OtherInfos, x, y, z ); // printf("Location x:%ld y:%ld z:%ld \n", x, y, z); } break; case MouseButton.Button1: // Left button { ushort Voxel; VoxelType VoxelType; if( Actor.PointedVoxel.Collided ) { Voxel = GameEnv.World.GetVoxel( Actor.PointedVoxel.PointedVoxel.X, Actor.PointedVoxel.PointedVoxel.Y, Actor.PointedVoxel.PointedVoxel.Z ); VoxelType = GameEnv.VoxelTypeManager.GetVoxelType( Voxel ); if( ToolCompatibleTypes[VoxelType.properties.MiningType] ) { Mining_MaterialResistanceCounter = VoxelType.properties.MiningHardness; MiningInProgress = true; MinedVoxel = Actor.PointedVoxel.PointedVoxel; GameEnv.GameProgressBar.SetCompletion( 0.0f ); GameEnv.GameProgressBar.Show(); #if COMPILEOPTION_FNX_SOUNDS_1 if( SoundHandle == 0 ) SoundHandle = GameEnv.Sound.Start_PlaySound( 5, true, true, 1.0, 0 ); #endif } else { GameEnv.GameWindow_Advertising.Advertise( "TOO HARD", GameWindow_Advertising.Visibility.VISIBILITY_MEDIUM, 1, 1000, 200 ); } } /* UShort VoxelType; VoxelType = GameEnv.World.GetVoxel(Actor.PointedVoxel.PointedVoxel.x, Actor.PointedVoxel.PointedVoxel.y, Actor.PointedVoxel.PointedVoxel.z); GameEnv.World.SetVoxel_WithCullingUpdate(Actor.PointedVoxel.PointedVoxel.x, Actor.PointedVoxel.PointedVoxel.y, Actor.PointedVoxel.PointedVoxel.z,0); Actor.Inventory.StoreBlocks(VoxelType,1); printf("Mining\n"); */ } break; case MouseButton.Button3: // Mouse scroll down //if( Actor.Inventory.Select_PreviousItem(); // printf("Selected : %ld : %s\n", Actor.Inventory.GetActualItemSlotNum(), GameEnv.VoxelTypeManager.VoxelTable[Actor.Inventory.GetActualItemSlot().VoxelType].VoxelTypeName.String); break; case MouseButton.Button4: // Mouse scroll up Actor.Inventory.Select_NextItem(); // printf("Selected : %ld : %s\n", Actor.Inventory.GetActualItemSlotNum(), GameEnv.VoxelTypeManager.VoxelTable[Actor.Inventory.GetActualItemSlot().VoxelType].VoxelTypeName.String); break; } } return ( true ); }
internal bool Equals( ref VoxelCoords b ) { if( X == b.X && Y == b.Y && Z == b.Z ) return true; return false; }
internal override bool Tool_StillEvents( double FrameTime, MouseDevice MouseButtonMatrix, KeyboardDevice KeyboardMatrix ) { Actor Actor; Actor = GameEnv.GetActiveActor(); if( Actor == null ) return ( true ); // Breaking material in progress if( MouseButtonMatrix[MouseButton.Button2] && MiningInProgress ) { ushort Voxel; VoxelType VoxelType; // Get actualy pointed voxel if( !Actor.PointedVoxel.Collided ) { Mining_MaterialResistanceCounter = 1000; GameEnv.GameProgressBar.SetCompletion( 0.0f ); return ( true ); } Voxel = GameEnv.World.GetVoxel( Actor.PointedVoxel.PointedVoxel.X, Actor.PointedVoxel.PointedVoxel.Y, Actor.PointedVoxel.PointedVoxel.Z ); VoxelType = GameEnv.VoxelTypeManager.GetVoxelType( Voxel ); // Uhhh, the player has moved is tool on another voxel, so resetting mining. if( !Actor.PointedVoxel.PointedVoxel.Equals( ref MinedVoxel ) ) { // Does this tool can break this material ? if( ToolCompatibleTypes[VoxelType.properties.MiningType] ) { Mining_MaterialResistanceCounter = VoxelType.properties.MiningHardness; MiningInProgress = true; MinedVoxel = Actor.PointedVoxel.PointedVoxel; } } // Material resistance is slowly going down Mining_MaterialResistanceCounter -= this.ToolForce[VoxelType.properties.MiningType] * (float)FrameTime; // printf("Resistance :%lf\n",Mining_MaterialResistanceCounter); GameEnv.GameProgressBar.SetCompletion( ( 100.0f / VoxelType.properties.MiningHardness ) * ( VoxelType.properties.MiningHardness - Mining_MaterialResistanceCounter ) ); // Ok, it's breaking if( Mining_MaterialResistanceCounter < 0.0 ) { Mining_MaterialResistanceCounter = 10000.0f; if( Actor.Inventory.StoreBlocks( Voxel, 1 ) ) { VoxelRef VLoc; if( GameEnv.World.SetVoxel_WithCullingUpdate( Actor.PointedVoxel.PointedVoxel.X, Actor.PointedVoxel.PointedVoxel.Y, Actor.PointedVoxel.PointedVoxel.Z, 0, VoxelSector.ModifiedFieldFlags.CRITICAL, true, out VLoc ) ) VLoc.Sector.Flag_HighPriorityRefresh = true; } #if COMPILEOPTION_FNX_SOUNDS_1 //GameEnv.Sound.PlaySound( 6 ); //if( SoundHandle != 0 ) { GameEnv.Sound.Stop_PlaySound( SoundHandle ); SoundHandle = 0; } #endif // Sector.Flag_HighPriorityRefresh } } return ( true ); }
bool RayCast2( float x, float y, float z, float yaw, float pitch, float roll, ref VoxelCoords PointedCube, ref VoxelCoords CubeBeforePointed ) { btVector3 Delta_h; Vector3 Offset_h; Vector3 Norm_h; Vector3 Collision_h; int ActualCube_x, ActualCube_y, ActualCube_z; int NewCube_x, NewCube_y, NewCube_z; int i; // Delta_h.X = tan((- yaw)/57.295779513); Delta_h.y = (float)Math.Tan( -pitch / 57.295779513 ); Delta_h.z = (float)Math.Tan( ( yaw + 90.0 ) / 57.295779513 ); Collision_h.X = ( (float)Math.Floor( x / VoxelBlockSize ) + 1.0f ) * VoxelBlockSize; Collision_h.Y = ( Collision_h.X - x ) * Delta_h.y + y; Collision_h.Z = ( Collision_h.X - x ) * Delta_h.z + z; if( yaw >= 0.0 && yaw < 180.0 ) Offset_h.X = VoxelBlockSize; else Offset_h.X = -VoxelBlockSize; Offset_h.Y = Delta_h.y * VoxelBlockSize; Offset_h.Z = Delta_h.z * VoxelBlockSize; Norm_h.X = Offset_h.X / VoxelBlockSize; Norm_h.Y = Offset_h.Y / VoxelBlockSize; Norm_h.Z = Offset_h.Z / VoxelBlockSize; // printf("Angle (y:%lf p:%lf) XYZ:(%lf %lf %lf) Off(%lf %lf %lf) Coll(%lf %lf %lf)\n", yaw,pitch,x,y,Z, Offset_h.X, Offset_h.Y, Offset_h.Z, Collision_h.X, Collision_h.Y, Collision_h.Z); for( i = 0; i < 50; i++ ) { ActualCube_x = (int)( ( Collision_h.X - Norm_h.X ) / VoxelBlockSize ); ActualCube_y = (int)( ( Collision_h.Y - Norm_h.Y ) / VoxelBlockSize ); ActualCube_z = (int)( ( Collision_h.Z - Norm_h.Z ) / VoxelBlockSize ); NewCube_x = (int)Math.Floor( ( Collision_h.X + Norm_h.X ) / VoxelBlockSize ); NewCube_y = (int)Math.Floor( ( Collision_h.Y + Norm_h.Y ) / VoxelBlockSize ); NewCube_z = (int)Math.Floor( ( Collision_h.Z + Norm_h.Z ) / VoxelBlockSize ); Collision_h.X += Offset_h.X; Collision_h.Y += Offset_h.Y; Collision_h.Z += Offset_h.Z; if( GetVoxel( NewCube_x, NewCube_y, NewCube_z ) > 0 ) { CubeBeforePointed.X = ActualCube_x; CubeBeforePointed.Y = ActualCube_y; CubeBeforePointed.Z = ActualCube_z; PointedCube.X = NewCube_x; PointedCube.Y = NewCube_y; PointedCube.Z = NewCube_z; //printf("MATCH: %ld %ld %ld POS %lf %lf %lf\n",PointedCube.X, PointedCube.Y, PointedCube.Z, Collision_h.X, Collision_h.Y, Collision_h.Z); return ( true ); } } // printf("\n"); return ( false ); //printf("first_h_x : %lf first_h_y %lf\n",first_h_x,first_h_y); }