Esempio n. 1
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);
    }