Example #1
0
        // Raise/lower thing
        public virtual void OnChangeTargetHeight(int amount)
        {
            if (General.Map.FormatInterface.HasThingHeight)
            {
                if ((General.Map.UndoRedo.NextUndo == null) || (General.Map.UndoRedo.NextUndo.TicketID != undoticket))
                {
                    undoticket = mode.CreateUndo("Change thing height");
                }

                Thing.Move(Thing.Position + new Vector3D(0.0f, 0.0f, (float)amount));

                mode.SetActionResult("Changed thing height to " + Thing.Position.z + ".");

                // Update what must be updated
                ThingData td = mode.GetThingData(this.Thing);
                foreach (KeyValuePair <Sector, bool> s in td.UpdateAlso)
                {
                    if (mode.VisualSectorExists(s.Key))
                    {
                        BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(s.Key);
                        vs.UpdateSectorGeometry(s.Value);
                    }
                }

                this.Changed = true;
            }
        }
        // This makes sure we are updated with the source linedef information
        public override void Update()
        {
            // Create vertices in clockwise order
            Vector3D[] verts = new Vector3D[3];
            int        index = 0;

            foreach (Sidedef sd in data.Sector.Sidedefs)
            {
                Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start;

                // Presume not sloped
                if (slopefloor)
                {
                    verts[index] = new Vector3D(v.Position.x, v.Position.y, data.Floor.plane.GetZ(v.Position));
                }
                else
                {
                    verts[index] = new Vector3D(v.Position.x, v.Position.y, data.Ceiling.plane.GetZ(v.Position));
                }

                // Find the thing at this position
                foreach (Thing t in things)
                {
                    if ((Vector2D)t.Position == v.Position)
                    {
                        ThingData td = data.Mode.GetThingData(t);
                        td.AddUpdateSector(data.Sector, true);
                        verts[index] = t.Position;
                    }
                }

                index++;
            }

            // Make new plane
            if (slopefloor)
            {
                data.Floor.plane = new Plane(verts[0], verts[1], verts[2], true);
            }
            else
            {
                data.Ceiling.plane = new Plane(verts[0], verts[2], verts[1], false);
            }
        }
        // This makes sure we are updated with the source linedef information
        public override void Update()
        {
            ThingData td = data.Mode.GetThingData(thing);
            Thing     t  = thing;

            // Find the tagged line
            Linedef ld = null;

            foreach (Linedef l in General.Map.Map.Linedefs)
            {
                if (l.Tag == t.Args[0])
                {
                    ld = l;
                    break;
                }
            }

            if (ld != null)
            {
                if (t.Type == 9500)
                {
                    // Slope the floor from the linedef to thing
                    t.DetermineSector(data.Mode.BlockMap);
                    if (t.Sector != null)
                    {
                        Vector3D v3 = new Vector3D(t.Position.x, t.Position.y, t.Position.z + t.Sector.FloorHeight);
                        if (ld.SideOfLine(t.Position) < 0.0f)
                        {
                            Vector3D   v1 = new Vector3D(ld.Start.Position.x, ld.Start.Position.y, ld.Front.Sector.FloorHeight);
                            Vector3D   v2 = new Vector3D(ld.End.Position.x, ld.End.Position.y, ld.Front.Sector.FloorHeight);
                            SectorData sd = data.Mode.GetSectorData(ld.Front.Sector);
                            sd.AddUpdateSector(data.Sector, true);
                            if (!sd.Updated)
                            {
                                sd.Update();
                            }
                            td.AddUpdateSector(ld.Front.Sector, true);
                            sd.Floor.plane = new Plane(v1, v2, v3, true);
                        }
                        else
                        {
                            Vector3D   v1 = new Vector3D(ld.Start.Position.x, ld.Start.Position.y, ld.Back.Sector.FloorHeight);
                            Vector3D   v2 = new Vector3D(ld.End.Position.x, ld.End.Position.y, ld.Back.Sector.FloorHeight);
                            SectorData sd = data.Mode.GetSectorData(ld.Back.Sector);
                            sd.AddUpdateSector(data.Sector, true);
                            if (!sd.Updated)
                            {
                                sd.Update();
                            }
                            td.AddUpdateSector(ld.Back.Sector, true);
                            sd.Floor.plane = new Plane(v2, v1, v3, true);
                        }
                    }
                }
                else if (t.Type == 9501)
                {
                    // Slope the ceiling from the linedef to thing
                    t.DetermineSector(data.Mode.BlockMap);
                    if (t.Sector != null)
                    {
                        td.AddUpdateSector(t.Sector, true);
                        Vector3D v3 = new Vector3D(t.Position.x, t.Position.y, t.Position.z + t.Sector.CeilHeight);
                        if (ld.SideOfLine(t.Position) < 0.0f)
                        {
                            Vector3D   v1 = new Vector3D(ld.Start.Position.x, ld.Start.Position.y, ld.Front.Sector.CeilHeight);
                            Vector3D   v2 = new Vector3D(ld.End.Position.x, ld.End.Position.y, ld.Front.Sector.CeilHeight);
                            SectorData sd = data.Mode.GetSectorData(ld.Front.Sector);
                            sd.AddUpdateSector(data.Sector, true);
                            td.AddUpdateSector(ld.Front.Sector, true);
                            if (!sd.Updated)
                            {
                                sd.Update();
                            }
                            sd.Ceiling.plane = new Plane(v1, v2, v3, false);
                        }
                        else
                        {
                            Vector3D   v1 = new Vector3D(ld.Start.Position.x, ld.Start.Position.y, ld.Back.Sector.CeilHeight);
                            Vector3D   v2 = new Vector3D(ld.End.Position.x, ld.End.Position.y, ld.Back.Sector.CeilHeight);
                            SectorData sd = data.Mode.GetSectorData(ld.Back.Sector);
                            sd.AddUpdateSector(data.Sector, true);
                            td.AddUpdateSector(ld.Back.Sector, true);
                            if (!sd.Updated)
                            {
                                sd.Update();
                            }
                            sd.Ceiling.plane = new Plane(v2, v1, v3, false);
                        }
                    }
                }
            }
        }