Exemple #1
0
        private static void DrawEntityDesignations(WorldManager World, DesignationSet Set)
        {
            // Todo: Can this be drawn by the entity, allowing it to be properly frustrum culled?
            // - Need to add a 'gestating' entity state to the alive/dead/active mess.

            foreach (var entity in Set.EnumerateEntityDesignations())
            {
                if ((entity.Type & World.Renderer.PersistentSettings.VisibleTypes) == entity.Type)
                {
                    var props = Library.GetDesignationTypeProperties(entity.Type).Value;

                    // Todo: More consistent drawing?
                    if (entity.Type == DesignationType.Craft)
                    {
                        entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, true);
                        if (!entity.Body.Active)
                        {
                            entity.Body.SetVertexColorRecursive(props.Color);
                        }
                    }
                    else
                    {
                        var box = entity.Body.GetBoundingBox();
                        _addBox(box.Min, box.Max - box.Min, props.Color, props.LineWidth, false);
                        entity.Body.SetVertexColorRecursive(props.Color);
                    }
                }
                else if (entity.Type == DesignationType.Craft) // Make the ghost object invisible if these designations are turned off.
                {
                    entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, false);
                }
            }
        }
Exemple #2
0
        public Body GetRandomGatherDesignationWithTag(string tag)
        {
            var des = Designations.EnumerateEntityDesignations(DesignationType.Gather)
                      .Where(d => d.Body.Tags.Contains(tag)).ToList();

            return(des.Count == 0 ? null : des[MathFunctions.Random.Next(0, des.Count)].Body);
        }
        public void DrawHilites(
            WorldManager World,
            DesignationSet Set,
            Action <Vector3, Vector3, Color, float, bool> DrawBoxCallback,
            Action <Vector3, VoxelType> DrawPhantomCallback)
        {
            var colorModulation = Math.Abs(Math.Sin(DwarfTime.LastTime.TotalGameTime.TotalSeconds * 2.0f));

            foreach (var properties in DesignationProperties)
            {
                properties.Value.ModulatedColor = new Color(
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.R * colorModulation + 50), 0.0f, 255.0f)),
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.G * colorModulation + 50), 0.0f, 255.0f)),
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.B * colorModulation + 50), 0.0f, 255.0f)),
                    255);
            }

            // Todo: Can this be drawn by the entity, allowing it to be properly frustrum culled?
            // - Need to add a 'gestating' entity state to the alive/dead/active mess.

            foreach (var entity in Set.EnumerateEntityDesignations())
            {
                if ((entity.Type & VisibleTypes) == entity.Type)
                {
                    var props = DefaultProperties;
                    if (DesignationProperties.ContainsKey(entity.Type))
                    {
                        props = DesignationProperties[entity.Type];
                    }

                    // Todo: More consistent drawing?
                    if (entity.Type == DesignationType.Craft)
                    {
                        entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, true);
                        if (!entity.Body.Active)
                        {
                            entity.Body.SetVertexColorRecursive(props.ModulatedColor);
                        }
                    }
                    else
                    {
                        var box = entity.Body.GetBoundingBox();
                        DrawBoxCallback(box.Min, box.Max - box.Min, props.ModulatedColor, props.LineWidth, false);
                        entity.Body.SetVertexColorRecursive(props.ModulatedColor);
                    }
                }
                else if (entity.Type == DesignationType.Craft) // Make the ghost object invisible if these designations are turned off.
                {
                    entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, false);
                }
            }
        }
        public void DrawHilites(
            DesignationSet Set,
            Action <Vector3, Vector3, Color, float, bool> DrawBoxCallback,
            Action <Vector3, VoxelType> DrawPhantomCallback)
        {
            var colorModulation = Math.Abs(Math.Sin(DwarfTime.LastTime.TotalGameTime.TotalSeconds * 2.0f));

            foreach (var properties in DesignationProperties)
            {
                properties.Value.ModulatedColor = new Color(
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.R * colorModulation + 50), 0.0f, 255.0f)),
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.G * colorModulation + 50), 0.0f, 255.0f)),
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.B * colorModulation + 50), 0.0f, 255.0f)),
                    255);
            }

            foreach (var voxel in Set.EnumerateDesignations())
            {
                if ((voxel.Type & VisibleTypes) == voxel.Type)
                {
                    var props = DefaultProperties;
                    if (DesignationProperties.ContainsKey(voxel.Type))
                    {
                        props = DesignationProperties[voxel.Type];
                    }

                    var v = voxel.Voxel.Coordinate.ToVector3();
                    if (props.Icon != null)
                    {
                        Drawer2D.DrawSprite(props.Icon, v + Vector3.One * 0.5f, Vector2.One * 0.5f, Vector2.Zero, new Color(255, 255, 255, 100));
                    }

                    if (voxel.Type == DesignationType.Put) // Hate this.
                    {
                        DrawPhantomCallback(v, VoxelLibrary.GetVoxelType((voxel.Tag as short?).Value));
                    }
                    else
                    {
                        DrawBoxCallback(v, Vector3.One, props.ModulatedColor, props.LineWidth, true);
                    }
                }
            }

            foreach (var entity in Set.EnumerateEntityDesignations())
            {
                if ((entity.Type & VisibleTypes) == entity.Type)
                {
                    var props = DefaultProperties;
                    if (DesignationProperties.ContainsKey(entity.Type))
                    {
                        props = DesignationProperties[entity.Type];
                    }

                    entity.Body.SetTintRecursive(props.ModulatedColor);

                    // Todo: More consistent drawing?
                    if (entity.Type == DesignationType.Craft)
                    {
                        entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, true);
                    }
                    else
                    {
                        var box = entity.Body.GetBoundingBox();
                        DrawBoxCallback(box.Min, box.Max - box.Min, props.ModulatedColor, props.LineWidth, false);
                    }

                    if (props.Icon != null)
                    {
                        Drawer2D.DrawSprite(props.Icon, entity.Body.Position + Vector3.One * 0.5f, Vector2.One * 0.5f, Vector2.Zero, new Color(255, 255, 255, 100));
                    }
                }
                else if (entity.Type == DesignationType.Craft) // Make the ghost object invisible if these designations are turned off.
                {
                    entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, false);
                }
            }
        }