Beispiel #1
0
    public bool CompareRotatedVariants(int r1, int r2)
    {
        if (!(this.Faces[Orientations.UP] as VerticalFaceDetails).Invariant || !(this.Faces[Orientations.DOWN] as VerticalFaceDetails).Invariant)
        {
            return(false);
        }

        for (int i = 0; i < 4; i++)
        {
            var face1 = this.Faces[Orientations.Rotate(Orientations.HorizontalDirections[i], r1)] as HorizontalFaceDetails;
            var face2 = this.Faces[Orientations.Rotate(Orientations.HorizontalDirections[i], r2)] as HorizontalFaceDetails;

            if (face1.Connector != face2.Connector)
            {
                return(false);
            }

            if (!face1.Symmetric && !face2.Symmetric && face1.Flipped != face2.Flipped)
            {
                return(false);
            }
        }

        return(true);
    }
Beispiel #2
0
    public void CreateModules(bool respectNeigborExclusions = true)
    {
        int count   = 0;
        var modules = new List <Module>();

        var prototypes = this.getPrototypes().ToArray();

        var scenePrototype = new Dictionary <Module, ModulePrototype>();

        for (int i = 0; i < prototypes.Length; i++)
        {
            var prototype = prototypes[i];
            for (int face = 0; face < 6; face++)
            {
                if (prototype.Faces[face].ExcludedNeighbours == null)
                {
                    prototype.Faces[face].ExcludedNeighbours = new ModulePrototype[0];
                }
            }

            for (int rotation = 0; rotation < 4; rotation++)
            {
                if (rotation == 0 || !prototype.CompareRotatedVariants(0, rotation))
                {
                    var module = new Module(prototype.gameObject, rotation, count);
                    modules.Add(module);
                    scenePrototype[module] = prototype;
                    count++;
                }
            }

            EditorUtility.DisplayProgressBar("Creating module prototypes...", prototype.gameObject.name, (float)i / prototypes.Length);
        }

        ModuleData.Current = modules.ToArray();

        foreach (var module in modules)
        {
            module.PossibleNeighbors = new ModuleSet[6];
            for (int direction = 0; direction < 6; direction++)
            {
                var face = scenePrototype[module].Faces[Orientations.Rotate(direction, module.Rotation)];
                module.PossibleNeighbors[direction] = new ModuleSet(modules
                                                                    .Where(neighbor => module.Fits(direction, neighbor) &&
                                                                           (!respectNeigborExclusions || (
                                                                                !face.ExcludedNeighbours.Contains(scenePrototype[neighbor]) &&
                                                                                !scenePrototype[neighbor].Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].ExcludedNeighbours.Contains(scenePrototype[module])) &&
                                                                            (!face.EnforceWalkableNeighbor || scenePrototype[neighbor].Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].Walkable) &&
                                                                            (face.Walkable || !scenePrototype[neighbor].Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].EnforceWalkableNeighbor))
                                                                           ));
            }

            module.PossibleNeighborsArray = module.PossibleNeighbors.Select(ms => ms.ToArray()).ToArray();
        }
        EditorUtility.ClearProgressBar();

        this.Modules = modules.ToArray();
        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets();
    }
Beispiel #3
0
    public ConnectorHint GetConnectorHint(int direction)
    {
        var face = this.ModulePrototype.Faces[direction];

        if (face is ModulePrototype.HorizontalFaceDetails)
        {
            var horizontalFace = face as ModulePrototype.HorizontalFaceDetails;

            foreach (var prototype in this.prototypes)
            {
                if (prototype == this.ModulePrototype || face.ExcludedNeighbours.Contains(prototype))
                {
                    continue;
                }
                for (int rotation = 0; rotation < 4; rotation++)
                {
                    var otherFace = prototype.Faces[Orientations.Rotate(direction, rotation + 2)] as ModulePrototype.HorizontalFaceDetails;
                    if (otherFace.ExcludedNeighbours.Contains(this.ModulePrototype))
                    {
                        continue;
                    }
                    if (otherFace.Connector == face.Connector && ((horizontalFace.Symmetric && otherFace.Symmetric) || otherFace.Flipped != horizontalFace.Flipped))
                    {
                        return(new ConnectorHint(rotation, this.getMesh(prototype)));
                    }
                }
            }
        }

        if (face is ModulePrototype.VerticalFaceDetails)
        {
            var verticalFace = face as ModulePrototype.VerticalFaceDetails;

            foreach (var prototype in this.prototypes)
            {
                if (prototype == this.ModulePrototype || face.ExcludedNeighbours.Contains(prototype))
                {
                    continue;
                }
                var otherFace = prototype.Faces[(direction + 3) % 6] as ModulePrototype.VerticalFaceDetails;
                if (otherFace.ExcludedNeighbours.Contains(this.ModulePrototype) || otherFace.Connector != face.Connector)
                {
                    continue;
                }

                return(new ConnectorHint(verticalFace.Rotation - otherFace.Rotation, this.getMesh(prototype)));
            }
        }

        return(new ConnectorHint());
    }
Beispiel #4
0
    public static List <Module> CreateModules(MapGenerator mapGenerator)
    {
        int count   = 0;
        var modules = new List <Module>();

        foreach (var prototype in ModulePrototype.GetAll())
        {
            for (int face = 0; face < 6; face++)
            {
                if (prototype.Faces[face].ExcludedNeighbours == null)
                {
                    prototype.Faces[face].ExcludedNeighbours = new ModulePrototype[0];
                }
            }

            for (int rotation = 0; rotation < (prototype.CreateRotatedVariants ? 4 : 1); rotation++)
            {
                modules.Add(new Module(prototype, rotation, count, mapGenerator));
                count++;
            }
        }

        foreach (var variation in Variation.GetAll())
        {
            foreach (var module in modules.Where(module => module.Prototype == variation.Prototype))
            {
                module.Models.Add(variation);
            }
        }

        foreach (var module in modules)
        {
            module.PossibleNeighbors = new Module[6][];
            for (int direction = 0; direction < 6; direction++)
            {
                var face = module.Prototype.Faces[Orientations.Rotate(direction, module.Rotation)];
                module.PossibleNeighbors[direction] = modules
                                                      .Where(neighbor => module.Fits(direction, neighbor) &&
                                                             (!mapGenerator.RespectNeighorExclusions || (
                                                                  !face.ExcludedNeighbours.Contains(neighbor.Prototype) &&
                                                                  !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].ExcludedNeighbours.Contains(module.Prototype)) &&
                                                              (!face.EnforceWalkableNeighbor || neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].Walkable) &&
                                                              (face.Walkable || !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].EnforceWalkableNeighbor))
                                                             )
                                                      .ToArray();
            }
            module.Probability = module.Models.Sum(model => model.Probability);
        }

        return(modules);
    }
Beispiel #5
0
    public bool Fits(int direction, Module module)
    {
        int otherDirection = (direction + 3) % 6;

        if (Orientations.IsHorizontal(direction))
        {
            var f1 = this.Prototype.Faces[Orientations.Rotate(direction, this.Rotation)] as ModulePrototype.HorizontalFaceDetails;
            var f2 = module.Prototype.Faces[Orientations.Rotate(otherDirection, module.Rotation)] as ModulePrototype.HorizontalFaceDetails;
            return(f1.Connector == f2.Connector && (f1.Symmetric || f1.Flipped != f2.Flipped));
        }
        else
        {
            var f1 = this.Prototype.Faces[direction] as ModulePrototype.VerticalFaceDetails;
            var f2 = module.Prototype.Faces[otherDirection] as ModulePrototype.VerticalFaceDetails;
            return(f1.Connector == f2.Connector && (f1.Invariant || (f1.Rotation + this.Rotation) % 4 == (f2.Rotation + module.Rotation) % 4));
        }
    }
    public static List <Module> CreateModules(bool respectNeigborExclusions)
    {
        int count   = 0;
        var modules = new List <Module>();

        foreach (var prototype in ModulePrototype.GetAll())
        {
            for (int face = 0; face < 6; face++)
            {
                if (prototype.Faces[face].ExcludedNeighbours == null)
                {
                    prototype.Faces[face].ExcludedNeighbours = new ModulePrototype[0];
                }
            }

            for (int rotation = 0; rotation < 4; rotation++)
            {
                if (rotation == 0 || !prototype.CompareRotatedVariants(0, rotation))
                {
                    modules.Add(new Module(prototype, rotation, count));
                    count++;
                }
            }
        }

        foreach (var module in modules)
        {
            module.PossibleNeighbors = new Module[6][];
            for (int direction = 0; direction < 6; direction++)
            {
                var face = module.Prototype.Faces[Orientations.Rotate(direction, module.Rotation)];
                module.PossibleNeighbors[direction] = modules
                                                      .Where(neighbor => module.Fits(direction, neighbor) &&
                                                             (!respectNeigborExclusions || (
                                                                  !face.ExcludedNeighbours.Contains(neighbor.Prototype) &&
                                                                  !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].ExcludedNeighbours.Contains(module.Prototype)) &&
                                                              (!face.EnforceWalkableNeighbor || neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].Walkable) &&
                                                              (face.Walkable || !neighbor.Prototype.Faces[Orientations.Rotate((direction + 3) % 6, neighbor.Rotation)].EnforceWalkableNeighbor))
                                                             )
                                                      .ToArray();
            }
        }

        return(modules);
    }
Beispiel #7
0
 public ModulePrototype.FaceDetails GetFace(int direction)
 {
     return(this.Prototype.Faces[Orientations.Rotate(direction, this.Rotation)]);
 }