Beispiel #1
0
        // This resets this sector data and all sectors that require updating after me
        public void Reset()
        {
            if (isupdating)
            {
                return;
            }

            isupdating = true;

            // This is set to false so that this sector is rebuilt the next time it is needed!
            updated = false;

            // The visual sector associated is now outdated
            if (mode.VisualSectorExists(sector))
            {
                BaseVisualSector vs = (BaseVisualSector)mode.GetVisualSector(sector);
                vs.UpdateSectorGeometry(false);
            }

            // Also reset the sectors that depend on this sector
            foreach (KeyValuePair <Sector, bool> s in updatesectors)
            {
                SectorData sd = mode.GetSectorData(s.Key);
                sd.Reset();
            }

            isupdating = false;
        }
Beispiel #2
0
        // This builds the thing geometry. Returns false when nothing was created.
        public virtual bool Setup()
        {
            PixelColor sectorcolor = new PixelColor(255, 255, 255, 255);

            // Must have a width and height!
            if ((info.Radius < 0.1f) || (info.Height < 0.1f))
            {
                return(false);
            }

            // Find the sector in which the thing resides
            Thing.DetermineSector(mode.BlockMap);

            if (sprite != null)
            {
                if (Thing.Sector != null)
                {
                    SectorData  sd    = mode.GetSectorData(Thing.Sector);
                    SectorLevel level = sd.GetLevelAbove(new Vector3D(Thing.Position.x, Thing.Position.y, Thing.Position.z + Thing.Sector.FloorHeight));
                    if (level != null)
                    {
                        // Use sector brightness for color shading
                        PixelColor areabrightness = PixelColor.FromInt(mode.CalculateBrightness(level.brightnessbelow));
                        PixelColor areacolor      = PixelColor.Modulate(level.colorbelow, areabrightness);
                        sectorcolor = areacolor.WithAlpha(255);
                    }
                }

                // Check if the texture is loaded
                sprite.LoadImage();
                isloaded = sprite.IsImageLoaded;
                if (isloaded)
                {
                    float offsetx = 0.0f;
                    float offsety = 0.0f;

                    base.Texture = sprite;

                    // Determine sprite size and offset
                    float radius = sprite.ScaledWidth * 0.5f;
                    float height = sprite.ScaledHeight;
                    if (sprite is SpriteImage)
                    {
                        offsetx = (sprite as SpriteImage).OffsetX - radius;
                        offsety = (sprite as SpriteImage).OffsetY - height;
                    }

                    // Scale by thing type/actor scale
                    // We do this after the offset x/y determination above, because that is entirely in sprite pixels space
                    radius  *= info.SpriteScale.Width;
                    height  *= info.SpriteScale.Height;
                    offsetx *= info.SpriteScale.Width;
                    offsety *= info.SpriteScale.Height;

                    // Make vertices
                    WorldVertex[] verts = new WorldVertex[6];
                    verts[0] = new WorldVertex(-radius + offsetx, 0.0f, 0.0f + offsety, sectorcolor.ToInt(), 0.0f, 1.0f);
                    verts[1] = new WorldVertex(-radius + offsetx, 0.0f, height + offsety, sectorcolor.ToInt(), 0.0f, 0.0f);
                    verts[2] = new WorldVertex(+radius + offsetx, 0.0f, height + offsety, sectorcolor.ToInt(), 1.0f, 0.0f);
                    verts[3] = verts[0];
                    verts[4] = verts[2];
                    verts[5] = new WorldVertex(+radius + offsetx, 0.0f, 0.0f + offsety, sectorcolor.ToInt(), 1.0f, 1.0f);
                    SetVertices(verts);
                }
                else
                {
                    base.Texture = General.Map.Data.Hourglass3D;

                    // Determine sprite size
                    float radius = Math.Min(info.Radius, info.Height / 2f);
                    float height = Math.Min(info.Radius * 2f, info.Height);

                    // Make vertices
                    WorldVertex[] verts = new WorldVertex[6];
                    verts[0] = new WorldVertex(-radius, 0.0f, 0.0f, sectorcolor.ToInt(), 0.0f, 1.0f);
                    verts[1] = new WorldVertex(-radius, 0.0f, height, sectorcolor.ToInt(), 0.0f, 0.0f);
                    verts[2] = new WorldVertex(+radius, 0.0f, height, sectorcolor.ToInt(), 1.0f, 0.0f);
                    verts[3] = verts[0];
                    verts[4] = verts[2];
                    verts[5] = new WorldVertex(+radius, 0.0f, 0.0f, sectorcolor.ToInt(), 1.0f, 1.0f);
                    SetVertices(verts);
                }
            }

            // Determine position
            Vector3D pos = Thing.Position;

            if (Thing.Type == 9501)
            {
                // This is a special thing that needs special positioning
                SectorData sd = mode.GetSectorData(Thing.Sector);
                pos.z = sd.Ceiling.sector.CeilHeight + Thing.Position.z;
            }
            else if (Thing.Type == 9500)
            {
                // This is a special thing that needs special positioning
                SectorData sd = mode.GetSectorData(Thing.Sector);
                pos.z = sd.Floor.sector.FloorHeight + Thing.Position.z;
            }
            else if (info.AbsoluteZ)
            {
                // Absolute Z position
                pos.z = Thing.Position.z;
            }
            else if (info.Hangs)
            {
                // Hang from ceiling
                if (Thing.Sector != null)
                {
                    SectorData sd = mode.GetSectorData(Thing.Sector);
                    if (Thing.Position.z > 0)
                    {
                        pos.z = sd.Ceiling.plane.GetZ(Thing.Position) - info.Height;
                    }
                    else
                    {
                        pos.z = Thing.Sector.CeilHeight - info.Height;
                    }
                }

                pos.z -= Thing.Position.z;

                // Check if below floor
                if ((Thing.Sector != null) && (pos.z < Thing.Sector.FloorHeight))
                {
                    // Put thing on the floor
                    SectorData sd = mode.GetSectorData(Thing.Sector);
                    pos.z = sd.Floor.plane.GetZ(Thing.Position);
                }
            }
            else
            {
                // Stand on floor
                if (Thing.Sector != null)
                {
                    SectorData sd = mode.GetSectorData(Thing.Sector);
                    if (Thing.Position.z == 0)
                    {
                        pos.z = sd.Floor.plane.GetZ(Thing.Position);
                    }
                    else
                    {
                        pos.z = Thing.Sector.FloorHeight;
                    }
                }

                pos.z += Thing.Position.z;

                // Check if above ceiling
                if ((Thing.Sector != null) && ((pos.z + info.Height) > Thing.Sector.CeilHeight))
                {
                    // Put thing against ceiling
                    SectorData sd = mode.GetSectorData(Thing.Sector);
                    pos.z = sd.Ceiling.plane.GetZ(Thing.Position) - info.Height;
                }
            }

            // Apply settings
            SetPosition(pos);
            SetCageSize(info.Radius, info.Height);
            SetCageColor(Thing.Color);

            // Keep info for object picking
            cageradius2 = info.Radius * Angle2D.SQRT2;
            cageradius2 = cageradius2 * cageradius2;
            pos2d       = pos;
            boxp1       = new Vector3D(pos.x - info.Radius, pos.y - info.Radius, pos.z);
            boxp2       = new Vector3D(pos.x + info.Radius, pos.y + info.Radius, pos.z + info.Height);

            // Done
            changed = false;
            return(true);
        }
Beispiel #3
0
 // This retreives the sector data for this sector
 public SectorData GetSectorData()
 {
     return(mode.GetSectorData(this.Sector));
 }