コード例 #1
0
        public override void ComposeSensorTargetSet(GameActor gameActor, Reflex reflex)
        {
            List <Filter> filters = reflex.Filters;

            _typeList.Clear();

            /// We never fire until we have valid data to base a trigger on.

            if (TerrainMaterial.IsValid(OverrideSenseMaterial, false, false))
            {
                _typeList.AddType(OverrideSenseMaterial);

                reflex.targetSet.Param = _typeList;

                reflex.targetSet.Action = TestObjectSet(reflex);
            }
            else if (gameActor.Chassis.TerrainDataValid)
            {
                gameActor.Chassis.GetTerrainMaterials(_typeList);

                reflex.targetSet.Param = _typeList;

                reflex.targetSet.Action = TestObjectSet(reflex);
            }
            else
            {
                reflex.targetSet.Action = false;
            }
        }   // end of ComposeSensorTargetSet()
コード例 #2
0
            public void Load(BinaryReader br, bool use16BitMatIdx)
            {
                for (int i = 0; i < PixPerMap; ++i)
                {
                    for (int j = 0; j < PixPerMap; ++j)
                    {
                        ushort val;

                        if (use16BitMatIdx)
                        {
                            val = br.ReadUInt16();
                        }
                        else
                        {
                            val = br.ReadByte();
                        }

                        // If user was editing terrain with a huge brush and saved before
                        // all tiles were updated, some of them may be saved with the
                        // selection flag in place.  Obviously this doesn't make sense to
                        // have on loading, so clear it out just to be sure.
                        val &= (ushort)~TerrainMaterial.Flags.Selection;

                        // Is the material we read valid? If not, replace it with empty.
                        if (!TerrainMaterial.IsValid(val, true, false))
                        {
                            Debug.Assert(false, "Why are we reading invalid values from this map?");
                            val = TerrainMaterial.EmptyMatIdx;
                        }

                        map[i, j] = val;
                    }
                }
            }
コード例 #3
0
        }   // end of PlayCollision()

        /// <summary>
        /// Play audio for actor/terrrain collision
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="material">Material index.</param>
        public static void PlayCollision(GameThing actor, ushort material)
        {
            // Get the proper collision sound from the material index.
            if (!TerrainMaterial.IsValid(material, false, false))
            {
                //Debug.Assert(false, "Why do we have an invalid material here?");
                // Why?  Well because we sometimes clear the material in the feeler
                // collision testing.  So it's no longer a valid way to tell what
                // terrain we're over.  In general, it works when we're on the ground
                // but not when jumping.  Argh.

                collisionMetalSoft.Play(actor);
                return;
            }

            PlayActorCollision(actor);

            CollisionSound cs = TerrainMaterial.Get(material).CollisionSound;

            switch (cs)
            {
            case CollisionSound.plasticHard:
                collisionPlasticHard.Play(actor);
                break;

            case CollisionSound.plasticSoft:
                collisionPlasticSoft.Play(actor);
                break;

            case CollisionSound.metalHard:
                collisionMetalHard.Play(actor);
                break;

            case CollisionSound.metalSoft:
                collisionMetalSoft.Play(actor);
                break;

            case CollisionSound.rover:
                collisionRover.Play(actor);
                break;

            case CollisionSound.dirt:
                collisionDirt.Play(actor);
                break;

            case CollisionSound.grass:
                collisionGrass.Play(actor);
                break;

            case CollisionSound.rock:
                collisionRock.Play(actor);
                break;

            default:
                break;
            }
        }   // end of PlayCollision()
コード例 #4
0
ファイル: Tile.cs プロジェクト: Yash-Codemaster/KoduGameLab
        /// <summary>
        /// An assured renderable for each possible material.
        /// Will create if it doesn't exist.
        /// </summary>
        /// <param name="matIdx"></param>
        /// <returns></returns>
        private Renderable GetOrMakeRenderable(ushort matIdx)
        {
            Debug.Assert(TerrainMaterial.IsValid(matIdx, false, true)); // There is no reason to fetch a renderable
                                                                        // for an empty or invalid material.

            if (!renderableDict.ContainsKey(matIdx))
            {
                renderableDict[matIdx] = new Renderable(matIdx);
            }
            return(renderableDict[matIdx]);
        }
コード例 #5
0
ファイル: Tile.cs プロジェクト: Yash-Codemaster/KoduGameLab
        /// <summary>
        /// Build up renderable geometry for each possible material. Discard empties.
        /// </summary>
        /// <param name="neighbors"></param>
        /// <param name="colorMap"></param>
        /// <returns></returns>
        private bool MakeRenderables(
            VirtualMap.HeightMapNeighbors heightNeighbors,
            VirtualMap.ColorMapNeighbors colorNeighbors)
        {
            var heightMap = heightNeighbors[VirtualMap.HeightMapNeighbors.Dir.Center];

            VirtualMap.ColorMap colorMap = colorNeighbors[VirtualMap.ColorMapNeighbors.Dir.Center];

            Renderable.PrepareToBuild(heightMap.Size, Min, minLut);

            //Dispose();
            //renderableDict.Clear();

            // Reset number of local vertices in each Renderable
            // since we're about to remake the list.
            ResetAllVertexCounts();


            Vector2 cubeSize = new Vector2(
                heightMap.Scale.X / (float)heightMap.Size.X,
                heightMap.Scale.Y / (float)heightMap.Size.Y);
            Vector2 halfSize = cubeSize * 0.5f;

            Point vert = new Point(0, 0);

            for (vert.X = 0; vert.X < heightMap.Size.X; vert.X += 1)
            {
                for (vert.Y = 0; vert.Y < heightMap.Size.Y; vert.Y += 1)
                {
                    float h = heightMap.GetHeightUnsafe(vert.X, vert.Y);
                    if (h != 0)
                    {
                        ushort color = colorMap[vert.X, vert.Y];

                        //Debug.Assert(TerrainMaterial.IsValid(color, false, true));

                        if (TerrainMaterial.IsValid(color, false, true))
                        {
                            Vector3 pos = new Vector3(
                                (float)vert.X * cubeSize.X + halfSize.X,
                                (float)vert.Y * cubeSize.Y + halfSize.Y,
                                h);

                            Renderable r = GetOrMakeRenderable(colorMap[vert.X, vert.Y]);

                            r.AddVertices(pos, halfSize, vert, heightNeighbors, colorNeighbors);
                        }
                    }
                }
            }

            return(FinishGeometry(cubeSize, halfSize));
        }
コード例 #6
0
 public ushort this[int i, int j]
 {
     get
     {
         ushort val = map[i, j];
         return(val);
     }
     set
     {
         Debug.Assert(TerrainMaterial.IsValid(value, allowEmpty: true, allowSelectionFlag: true));
         map[i, j] = value;
     }
 }
コード例 #7
0
        }   // end of MaterialPicker c'tor

        /// <summary>
        /// Sample the type under the cursor and translate to a UISlot.
        /// Return -1 on no terrain.
        /// </summary>
        /// <returns></returns>
        public int SampleType()
        {
            Vector2 pos = InGame.inGame.Cursor3D.Position2d;

            if (MouseEdit.TriggerSample())
            {
                Vector3 p = MouseEdit.HitInfo.TerrainPosition;
                pos = new Vector2(p.X, p.Y);
            }

            ushort t = Terrain.GetMaterialType(pos);

            return(TerrainMaterial.IsValid(t, false, false) ? Terrain.MaterialIndexToUISlot(t) : -1);
        }
コード例 #8
0
        public void HandleMouseInput()
        {
            if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse)
            {
                return;
            }
            // In eyedropper mode, show the pointy cursor.
            if (KeyboardInput.AltIsPressed)
            {
                inGame.Cursor3D.Rep    = Cursor3D.Visual.Pointy;
                inGame.Cursor3D.Hidden = false;
            }
            else
            {
                inGame.Cursor3D.Hidden = true;
            }

            if (KeyboardInput.AltIsPressed)
            {
                // Sample the current terrain.
                if (MouseEdit.TriggerSample())
                {
                    MouseInput.Left.IgnoreUntilReleased = true;

                    // Prevent terrain from being painted when Alt is being used to select material.
                    editMode = Terrain.EditMode.Noop;

                    Vector3 p   = MouseEdit.HitInfo.TerrainPosition;
                    Vector2 pos = new Vector2(p.X, p.Y);

                    ushort matIdx = Terrain.GetMaterialType(pos);
                    if (TerrainMaterial.IsValid(matIdx, false, false))
                    {
                        Terrain.CurrentMaterialIndex = matIdx;
                        Foley.PlayCut();
                    }
                }
            }
            else if (!PickerXInUse && !PickerYInUse)
            {
                if (DebouncePending)
                {
                    return;
                }

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                {
                    // Set the mode based on whether or not
                    // option keys are pressed.
                    if (MouseInput.Left.WasPressed)
                    {
                        editMode = Terrain.EditMode.PaintAndAddMaterial;
                        if (KeyboardInput.ShiftIsPressed)
                        {
                            editMode = Terrain.EditMode.PaintMaterial;
                        }
                        else if (KeyboardInput.CtrlIsPressed)
                        {
                            editMode = Terrain.EditMode.AddAtCenter;
                        }
                    }
                }
            }
        }
コード例 #9
0
        }   // end of ComposeSensorTargetSet()

        #endregion Public

        #region Internal
        /// <summary>
        /// See if the terrain types our object is touching match up with our filters.
        /// </summary>
        /// <param name="reflex"></param>
        /// <returns></returns>
        public new bool TestObjectSet(Reflex reflex)
        {
            GameActor     gameActor = reflex.Task.GameActor;
            List <Filter> filters   = reflex.Filters;

            bool   haveType = false;
            bool   match    = true;
            object param;

            // Only check all this if we're not jumping.  If we are jumping
            // we can just skip this.
            if (!gameActor.Chassis.Jumping)
            {
                for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
                {
                    Filter filter = filters[indexFilter] as Filter;
                    if (!(filter is CountFilter))
                    {
                        if (filter is TerrainFilter)
                        {
                            haveType = true;
                        }
                        if (!filter.MatchAction(reflex, out param))
                        {
                            match = false;
                            break;
                        }
                    }
                }
                if (match && !haveType)
                {
                    match = _typeList.HasAnyValid((matIdx) => TerrainMaterial.IsValid((ushort)matIdx, false, false));
                }

                /// Manually apply the count filters, because they look at the sensorTargetSet.Count,
                /// which is always zero for non-object based sensors like this.
                for (int indexFilter = 0; indexFilter < filters.Count; indexFilter++)
                {
                    if (filters[indexFilter] is CountFilter)
                    {
                        CountFilter countFilter = filters[indexFilter] as CountFilter;
                        int         count       = match ? 1 : 0;
                        match = countFilter.Compare(count);
                    }
                }
            }
            else
            {
                // Jumping...
                match = false;
            }

            if (reflex.Data.GetFilterCountByType(typeof(NotFilter)) > 0)
            {
                match = !match;
            }

            match = PostProcessAction(match, reflex);

            return(match);
        }
コード例 #10
0
        public int OnGetTerrain()
        {
            Debug.Assert(TerrainMaterial.IsValid(lastTerrainIndex, false, false), "If this assert fires, set 'lastTerrainIndex's initial value to 'TerrainMaterial.DefaultMatIdx' and fire Daryl. (DZ)");//ToDo(DZ): Is this assert msg ship-able?

            return(Terrain.MaterialIndexToUISlot(lastTerrainIndex));
        }
コード例 #11
0
        public override void Activate()
        {
            if (state != States.Active)
            {
                pendingState             = States.Active;
                BokuGame.objectListDirty = true;

                Editor editor = InGame.inGame.Editor;
                if (editor.Active)
                {
                    HelpOverlay.Push(@"PieSelectorProgrammingNoSelection");
                }
                else
                {
                    HelpOverlay.Push(@"PieSelectorAddItemNoSelection");
                }

                if (SelectWater || SetWater)
                {
                    WaterPicker waterPicker = InGame.inGame.shared.ToolBox.WaterPicker;

                    holdOnGet  = waterPicker.OnGetType;
                    holdOnSet  = waterPicker.OnSetType;
                    holdOnPick = waterPicker.OnPickType;

                    waterPicker.OnGetType  = OnGetWater;
                    waterPicker.OnSetType  = OnSetWater;
                    waterPicker.OnPickType = OnPickWater;

                    typePicker = waterPicker;
                    if (SetWater)
                    {
                        lastWaterIndex = RootData.SetWaterTypeIndex;
                    }
                    else
                    {
                        lastWaterIndex = RootData.WaterType;
                    }

                    if (lastWaterIndex < 0)
                    {
                        lastWaterIndex = Water.CurrentType;
                    }
                }
                else
                {
                    MaterialPicker matPicker = InGame.inGame.shared.ToolBox.MaterialPicker;

                    holdOnGet  = matPicker.OnGetType;
                    holdOnSet  = matPicker.OnSetType;
                    holdOnPick = matPicker.OnPickType;

                    matPicker.OnGetType     = OnGetTerrain;
                    matPicker.OnSetType     = OnSetTerrain;
                    matPicker.OnPickType    = OnPickTerrain;
                    matPicker.UseAltOverlay = true;

                    typePicker = matPicker;

                    ushort rootDataMatIdx = (ushort)RootData.MaterialType;
                    if (TerrainMaterial.IsValid(rootDataMatIdx, false, false))
                    {
                        lastTerrainIndex = rootDataMatIdx;
                    }
                    else if (!TerrainMaterial.IsValid(lastTerrainIndex, false, false))
                    {
                        lastTerrainIndex = Terrain.CurrentMaterialIndex;
                    }
                }
                typePicker.Active = true;
                typePicker.Hidden = false;
            }
        }