コード例 #1
0
    /// <summary>
    /// Creates a random payload of blocks constrained by the block manager. Payloads are by default
    /// created to be a size of 20 when randomly created
    /// </summary>
    /// <returns></returns>
    public static IndividualDatastructure createRandomPayload(int payloadsize)
    {
        ///So now that we've added our open space, we attempt to insert random blocks
        int count = 0;

        IndividualDatastructure payload = new IndividualDatastructure();
        ///Here we need to init an open space. I want this to be at the centre of the 3D space
        int centre = IndividualManager.Instance.maxIndividualSize / 2;

        ///Calculating the offset of the centre
        double offset = BlockFunctions.calculateOffset(centre, centre, centre);

        payload.openSpaces.Add(offset);

        ///Here we grab the payload type that is tagged as such
        BlockType type = null;

        type = BlockManager.Instance.blockTypes[BlockFunctions.findBlockID("payload")];
        if (type == null)
        {
            throw new Exception("There was no block of type payload defined");
        }

        payloadsize = Math.Min(payloadsize, IndividualManager.Instance.startIndividualSize);
        ///While we have less blocks than desired, and less failed consecutive attempts than defined
        while (count < payloadsize && count < IndividualManager.Instance.startIndividualSize)///This number may need to be tweaked. I feel 200 consecutive failed attempts is enough though
        {
            if (BlockFunctions.insertBlockTypeAtRandom(payload, type))
            {
                count++;
            }
        }
        Debug.Log("Payload created with size of " + count);
        return(payload);
    }
コード例 #2
0
    /// <summary>
    /// Pass in the structure which holds your blocks, and this will add a random block to it if able.
    /// </summary>
    /// <param name="structure"></param>
    /// <returns>The altered datastructure, null if it failed</returns>
    internal static bool insertBlockAtRandom(IndividualDatastructure structure)
    {
        List <BlockType> blocks  = blockMan.blockTypes;
        BlockType        desired = blocks[random.Next(0, blocks.Count - 1)];

        return(insertBlockTypeAtRandom(structure, desired));
    }
コード例 #3
0
    internal static IndividualDatastructure copyPayload(IndividualDatastructure container)
    {
        IndividualDatastructure ret = new IndividualDatastructure();

        ret.contents   = new Dictionary <double, Block>(container.contents);
        ret.openSpaces = new List <double>(container.openSpaces);
        return(ret);
    }
コード例 #4
0
    /// <summary>
    /// Creates a random payload of blocks constrained by the block manager. Payloads are by default
    /// created to be a size of 20 when randomly created
    /// </summary>
    /// <returns></returns>
    public static IndividualDatastructure createRandomHull(IndividualDatastructure hull, int hullSize)
    {
        int count = 0;

        ///Here i'm making sure that we don't fall into an infinite loop of trying to place blocks when it's not possible
        ///Normally this wouldn't be an issue, but because users can input their own blocks
        ///I need to safeguard against assholes.
        hullSize = Math.Min(hullSize, IndividualManager.Instance.startIndividualSize);
        ///While we have less blocks than desired, and less failed consecutive attempts than defined
        while (count < hullSize && count < IndividualManager.Instance.startIndividualSize)///This number may need to be tweaked. I feel 200 consecutive failed attempts is enough though
        {
            if (BlockFunctions.insertBlockAtRandom(hull))
            {
                count++;
            }
        }
        return(hull);
    }
コード例 #5
0
    /// <summary>
    /// Pass in the structure which holds your blocks, as well as the type of block you would like added, and
    /// this will add that block at a random spot to your structure
    /// </summary>
    /// <param name="structure"></param>
    /// <param name="type"></param>
    /// <returns>The altered datastructure, null if failed</returns>
    internal static bool insertBlockTypeAtRandom(IndividualDatastructure structure, BlockType type)
    {
        double openSpace = BlockFunctions.randomOpenSpace(structure.openSpaces);
        ///This is our block
        facing   face   = Randomizer.RandomEnumValue <facing>();
        rotation rot    = Randomizer.RandomEnumValue <rotation>();
        Block    pBlock = new Block(type.UID, face, rot);

        ///If we've gotten to this point, then we can successfully place ourself into the individual

        /*
         * IVE BEEN GETTING AN ERROR WHERE WE TRY TO PLACE BLOCKS THAT ALREADY EXIST.
         * NO IDEA WHY THIS HAPPENS AND IT SHOULDN'T SO I'M SIMPLY PUTTING THIS CONDITIONAL HERE AS A JANK FIX
         */
        if (structure.contents.ContainsKey(openSpace))
        {
            return(false);
        }
        structure.contents.Add(openSpace, pBlock);


        ///Remove the open space from structure.openSpaces
        structure.openSpaces.Remove(openSpace);
        ///Add the possible neighbours of the placed block to our open neighbours list
        List <double> openConsiderations = BlockFunctions.addNeighboursToOpen(openSpace, structure.contents);

        ///Iterating over the open spots we are considering, and check to see if they are already filled or not.
        ///Then adding them to our open spaces list if they are not.

        foreach (double possible in openConsiderations)
        {
            if (structure.contents.ContainsKey(possible))
            {
                continue;
            }
            structure.openSpaces.Add(possible);
        }
        return(true);
    }
コード例 #6
0
 /// <summary>
 /// Creates the rocket hull container around the passed in IndividualDataStructure
 /// </summary>
 /// <param name="alreadyCreated"></param>
 public RocketHull(IndividualDatastructure alreadyCreated)
 {
     container = HullFunctions.copyPayload(alreadyCreated);
 }
コード例 #7
0
 /// <summary>
 /// When you have a given assortment.
 /// </summary>
 /// <param name="payload"></param>
 public BlockAssortmentContainer(IndividualDatastructure conts)
 {
     container = conts;
 }
コード例 #8
0
 /// <summary>
 /// Creates a container surrounding the IndividualDataStructure passed in
 /// </summary>
 /// <param name="alreadyCreated"></param>
 public Payload(IndividualDatastructure alreadyCreated)
 {
     this.container = alreadyCreated;
 }