Exemplo n.º 1
0
 public ObjectPoolData(ObjectPoolName name, APoolable prefab, int initialCapacity, RootBase root)
 {
     this.name            = name;
     this.prefab          = prefab;
     this.initialCapacity = initialCapacity;
     this.Root            = root;
 }
Exemplo n.º 2
0
    public static bool IsNull(this RootBase rb)
    {
        if (rb == null)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 3
0
 //---------------------------------------------------------------------------------------------------------------
 public static bool IsNull(this RootBase root)
 {
     return(root != null);
 }
Exemplo n.º 4
0
            void MakeRoots(IList <RootBase> rootbases)
            {
                if (rootbases.Count == 0)
                {
                    return;
                }
                foreach (Vector3I coord in FoliageCoords)
                {
                    float dist  = (float)Math.Sqrt(Sqr(coord[0] - Pos[0]) + Sqr(coord[2] - Pos[2]));
                    float ydist = coord[1] - Pos[1];
                    float value = (BranchDensity * 220 * Height) / Cub(ydist + dist);
                    if (value < Args.Rand.NextDouble())
                    {
                        continue;
                    }

                    RootBase rootbase       = rootbases[Args.Rand.Next(0, rootbases.Count)];
                    int      rootx          = rootbase.X;
                    int      rootz          = rootbase.Z;
                    float    rootbaseradius = rootbase.Radius;

                    float    rndr       = (float)(Math.Sqrt(Args.Rand.NextDouble()) * rootbaseradius * .618);
                    float    rndang     = (float)(Args.Rand.NextDouble() * 2 * Math.PI);
                    int      rndx       = (int)(rndr * Math.Sin(rndang) + .5);
                    int      rndz       = (int)(rndr * Math.Cos(rndang) + .5);
                    int      rndy       = (int)(Args.Rand.NextDouble() * rootbaseradius * .5);
                    Vector3I startcoord = new Vector3I {
                        X = rootx + rndx,
                        Z = rootz + rndz,
                        Y = Pos[1] + rndy
                    };
                    Vector3F offset = new Vector3F(startcoord - coord);

                    if (Args.Shape == TreeShape.Mangrove)
                    {
                        // offset = [int(val * 1.618 - 1.5) for val in offset]
                        offset = offset * 1.618f - HalfBlock * 3;
                    }

                    Vector3I endcoord      = startcoord + offset.RoundDown();
                    float    rootstartsize = (float)(rootbaseradius * .618 * Math.Abs(offset[1]) / (Height * .618));

                    if (rootstartsize < 1)
                    {
                        rootstartsize = 1;
                    }
                    const float endsize = 1;

                    if (Args.Roots == RootMode.ToStone ||
                        Args.Roots == RootMode.Hanging)
                    {
                        float offlength = offset.Length;
                        if (offlength < 1)
                        {
                            continue;
                        }
                        float    rootmid = endsize;
                        Vector3F vec     = offset / offlength;

                        Block searchIndex = Block.Air;
                        if (Args.Roots == RootMode.ToStone)
                        {
                            searchIndex = Block.Stone;
                        }
                        else if (Args.Roots == RootMode.Hanging)
                        {
                            searchIndex = Block.Air;
                        }

                        int      startdist   = (int)(Args.Rand.NextDouble() * 6 * Math.Sqrt(rootstartsize) + 2.8);
                        Vector3I searchstart = new Vector3I(startcoord + vec * startdist);

                        dist = startdist + DistanceToBlock(Args.Map, new Vector3F(searchstart), vec, searchIndex);

                        if (dist < offlength)
                        {
                            rootmid += (rootstartsize - endsize) * (1 - dist / offlength);
                            endcoord = new Vector3I(startcoord + vec * dist);
                            if (Args.Roots == RootMode.Hanging)
                            {
                                float    remainingDist = offlength - dist;
                                Vector3I bottomcord    = endcoord;
                                bottomcord[1] -= (int)remainingDist;
                                TaperedLimb(endcoord, bottomcord, rootmid, endsize);
                            }
                        }
                        TaperedLimb(startcoord, endcoord, rootstartsize, rootmid);
                    }
                    else
                    {
                        TaperedLimb(startcoord, endcoord, rootstartsize, endsize);
                    }
                }
            }
 public RootTypeAttribute(RootBase root)
 {
     this.root = root;
 }
Exemplo n.º 6
0
            void MakeRoots( RootBase[] rootbases ) {
                if( rootbases.Length == 0 ) return;
                foreach( Vector3i coord in FoliageCoords ) {
                    float dist = (float)Math.Sqrt( Sqr( coord[0] - Pos[0] ) + Sqr( coord[2] - Pos[2] ) );
                    float ydist = coord[1] - Pos[1];
                    float value = (BranchDensity * 220 * Height) / Cub( ydist + dist );
                    if( value < Args.Rand.NextDouble() ) continue;

                    RootBase rootbase = rootbases[Args.Rand.Next( 0, rootbases.Length )];
                    int rootx = rootbase.X;
                    int rootz = rootbase.Z;
                    float rootbaseradius = rootbase.Radius;

                    float rndr = (float)(Math.Sqrt( Args.Rand.NextDouble() ) * rootbaseradius * .618);
                    float rndang = (float)(Args.Rand.NextDouble() * 2 * Math.PI);
                    int rndx = (int)(rndr * Math.Sin( rndang ) + .5);
                    int rndz = (int)(rndr * Math.Cos( rndang ) + .5);
                    int rndy = (int)(Args.Rand.NextDouble() * rootbaseradius * .5);
                    Vector3i startcoord = new Vector3i {
                        X = rootx + rndx,
                        Z = rootz + rndz,
                        Y = Pos[1] + rndy
                    };
                    Vector3f offset = new Vector3f( startcoord - coord );

                    if( Args.Shape == TreeShape.Mangrove ) {
                        offset = offset * 1.618f - 1.5f;
                    }

                    Vector3i endcoord = startcoord + new Vector3i( offset );
                    float rootstartsize = (float)(rootbaseradius * .618 * Math.Abs( offset[1] ) / (Height * .618));

                    if( rootstartsize < 1 ) rootstartsize = 1;
                    const float endsize = 1;

                    if( Args.Roots == RootMode.ToStone ||
                        Args.Roots == RootMode.Hanging ) {
                        float offlength = offset.Length;
                        if( offlength < 1 ) continue;
                        float rootmid = endsize;
                        Vector3f vec = offset / offlength;

                        Block searchIndex = Block.Air;
                        if( Args.Roots == RootMode.ToStone ) {
                            searchIndex = Block.Stone;
                        } else if( Args.Roots == RootMode.Hanging ) {
                            searchIndex = Block.Air;
                        }

                        int startdist = (int)(Args.Rand.NextDouble() * 6 * Math.Sqrt( rootstartsize ) + 2.8);
                        Vector3i searchstart = new Vector3i( startcoord + vec * startdist );

                        dist = startdist + DistanceToBlock( Args.InMap, new Vector3f( searchstart ), vec, searchIndex );

                        if( dist < offlength ) {
                            rootmid += (rootstartsize - endsize) * (1 - dist / offlength);
                            endcoord = new Vector3i( startcoord + vec * dist );
                            if( Args.Roots == RootMode.Hanging ) {
                                float remainingDist = offlength - dist;
                                Vector3i bottomcord = endcoord;
                                bottomcord[1] -= (int)remainingDist;
                                TaperedLimb( endcoord, bottomcord, rootmid, endsize );
                            }
                        }
                        TaperedLimb( startcoord, endcoord, rootstartsize, rootmid );
                    } else {
                        TaperedLimb( startcoord, endcoord, rootstartsize, endsize );
                    }
                }
            }
Exemplo n.º 7
0
            void MakeRoots(RootBase[] rootbases)
            {
                foreach (Vector3i coord in foliageCoords)
                {
                    float dist = (float)Math.Sqrt(Sqr(coord[0] - pos[0]) + Sqr(coord[2] - pos[2]));
                    float ydist = coord[1] - pos[1];
                    float value = (branchDensity * 220 * height) / Cub(ydist + dist);
                    if (value < args.rand.NextDouble()) continue;

                    RootBase rootbase = rootbases[args.rand.Next(0, rootbases.Length)];
                    int rootx = rootbase.x;
                    int rootz = rootbase.z;
                    float rootbaseradius = rootbase.radius;

                    float rndr = (float)(Math.Sqrt(args.rand.NextDouble()) * rootbaseradius * .618);
                    float rndang = (float)(args.rand.NextDouble() * 2 * Math.PI);
                    int rndx = (int)(rndr * Math.Sin(rndang) + .5);
                    int rndz = (int)(rndr * Math.Cos(rndang) + .5);
                    int rndy = (int)(args.rand.NextDouble() * rootbaseradius * .5);
                    Vector3i startcoord = new Vector3i
                    {
                        x = rootx + rndx,
                        z = rootz + rndz,
                        y = pos[1] + rndy
                    };
                    Vector3f offset = new Vector3f(startcoord - coord);

                    if (args.SHAPE == TreeShape.Mangrove)
                    {
                        offset = offset * 1.618f - 1.5f;
                    }

                    Vector3i endcoord = startcoord + new Vector3i(offset);
                    float rootstartsize = (float)(rootbaseradius * .618 * Math.Abs(offset[1]) / (height * .618));

                    if (rootstartsize < 1) rootstartsize = 1;
                    float endsize = 1;

                    if (args.ROOTS == RootMode.ToStone ||
                        args.ROOTS == RootMode.Hanging)
                    {
                        float offlength = offset.GetLength();
                        if (offlength < 1) continue;
                        float rootmid = endsize;
                        Vector3f vec = offset / offlength;

                        int searchIndex = TILETYPE_AIR;
                        if (args.ROOTS == RootMode.ToStone)
                        {
                            searchIndex = TILETYPE_STONE;
                        }
                        else if (args.ROOTS == RootMode.Hanging)
                        {
                            searchIndex = TILETYPE_AIR;
                        }

                        int startdist = (int)(args.rand.NextDouble() * 6 * Math.Sqrt(rootstartsize) + 2.8);
                        Vector3i searchstart = new Vector3i(startcoord + vec * startdist);

                        dist = startdist + DistanceToBlock(args.inMap, new Vector3f(searchstart), vec, searchIndex);

                        if (dist < offlength)
                        {
                            rootmid += (rootstartsize - endsize) * (1 - dist / offlength);
                            endcoord = new Vector3i(startcoord + vec * dist);
                            if (args.ROOTS == RootMode.Hanging)
                            {
                                float remaining_dist = offlength - dist;
                                Vector3i bottomcord = endcoord;
                                bottomcord[1] -= (int)remaining_dist;
                                TaperedLimb(endcoord, bottomcord, rootmid, endsize);
                            }
                        }
                        TaperedLimb(startcoord, endcoord, rootstartsize, rootmid);
                    }
                    else
                    {
                        TaperedLimb(startcoord, endcoord, rootstartsize, endsize);
                    }
                }
            }
Exemplo n.º 8
0
            void MakeRoots(RootBase[] rootbases)
            {
                foreach (Vector3i coord in foliageCoords)
                {
                    float dist  = (float)Math.Sqrt(Sqr(coord[0] - pos[0]) + Sqr(coord[2] - pos[2]));
                    float ydist = coord[1] - pos[1];
                    float value = (branchDensity * 220 * height) / Cub(ydist + dist);
                    if (value < args.rand.NextDouble())
                    {
                        continue;
                    }

                    RootBase rootbase       = rootbases[args.rand.Next(0, rootbases.Length)];
                    int      rootx          = rootbase.x;
                    int      rootz          = rootbase.z;
                    float    rootbaseradius = rootbase.radius;

                    float    rndr       = (float)(Math.Sqrt(args.rand.NextDouble()) * rootbaseradius * .618);
                    float    rndang     = (float)(args.rand.NextDouble() * 2 * Math.PI);
                    int      rndx       = (int)(rndr * Math.Sin(rndang) + .5);
                    int      rndz       = (int)(rndr * Math.Cos(rndang) + .5);
                    int      rndy       = (int)(args.rand.NextDouble() * rootbaseradius * .5);
                    Vector3i startcoord = new Vector3i
                    {
                        x = rootx + rndx,
                        z = rootz + rndz,
                        y = pos[1] + rndy
                    };
                    Vector3f offset = new Vector3f(startcoord - coord);

                    if (args.SHAPE == TreeShape.Mangrove)
                    {
                        offset = offset * 1.618f - 1.5f;
                    }

                    Vector3i endcoord      = startcoord + new Vector3i(offset);
                    float    rootstartsize = (float)(rootbaseradius * .618 * Math.Abs(offset[1]) / (height * .618));

                    if (rootstartsize < 1)
                    {
                        rootstartsize = 1;
                    }
                    float endsize = 1;

                    if (args.ROOTS == RootMode.ToStone ||
                        args.ROOTS == RootMode.Hanging)
                    {
                        float offlength = offset.GetLength();
                        if (offlength < 1)
                        {
                            continue;
                        }
                        float    rootmid = endsize;
                        Vector3f vec     = offset / offlength;

                        int searchIndex = TILETYPE_AIR;
                        if (args.ROOTS == RootMode.ToStone)
                        {
                            searchIndex = TILETYPE_STONE;
                        }
                        else if (args.ROOTS == RootMode.Hanging)
                        {
                            searchIndex = TILETYPE_AIR;
                        }

                        int      startdist   = (int)(args.rand.NextDouble() * 6 * Math.Sqrt(rootstartsize) + 2.8);
                        Vector3i searchstart = new Vector3i(startcoord + vec * startdist);

                        dist = startdist + DistanceToBlock(args.inMap, new Vector3f(searchstart), vec, searchIndex);

                        if (dist < offlength)
                        {
                            rootmid += (rootstartsize - endsize) * (1 - dist / offlength);
                            endcoord = new Vector3i(startcoord + vec * dist);
                            if (args.ROOTS == RootMode.Hanging)
                            {
                                float    remaining_dist = offlength - dist;
                                Vector3i bottomcord     = endcoord;
                                bottomcord[1] -= (int)remaining_dist;
                                TaperedLimb(endcoord, bottomcord, rootmid, endsize);
                            }
                        }
                        TaperedLimb(startcoord, endcoord, rootstartsize, rootmid);
                    }
                    else
                    {
                        TaperedLimb(startcoord, endcoord, rootstartsize, endsize);
                    }
                }
            }
Exemplo n.º 9
0
            void MakeRoots([NotNull] IList <RootBase> rootBases)
            {
                if (rootBases == null)
                {
                    throw new ArgumentNullException("rootBases");
                }
                if (rootBases.Count == 0)
                {
                    return;
                }
                foreach (Vector3I coord in FoliageCoords)
                {
                    float dist  = (float)Math.Sqrt(Sqr(coord[0] - Pos[0]) + Sqr(coord[2] - Pos[2]));
                    float distY = coord[1] - Pos[1];
                    float value = (BranchDensity * 220 * Height) / Cub(distY + dist);
                    if (value < Args.Rand.NextDouble())
                    {
                        continue;
                    }

                    RootBase rootBase       = rootBases[Args.Rand.Next(0, rootBases.Count)];
                    float    rootBaseRadius = rootBase.Radius;

                    float    randR      = (float)(Math.Sqrt(Args.Rand.NextDouble()) * rootBaseRadius * .618);
                    float    randAng    = (float)(Args.Rand.NextDouble() * 2 * Math.PI);
                    int      randX      = (int)(randR * Math.Sin(randAng) + .5);
                    int      randZ      = (int)(randR * Math.Cos(randAng) + .5);
                    int      randY      = (int)(Args.Rand.NextDouble() * rootBaseRadius * .5);
                    Vector3I startCoord = new Vector3I {
                        X = rootBase.X + randX,
                        Z = rootBase.Z + randZ,
                        Y = Pos[1] + randY
                    };
                    Vector3F offset = new Vector3F(startCoord - coord);

                    if (Args.Shape == TreeShape.Mangrove)
                    {
                        // offset = [int(val * 1.618 - 1.5) for val in offset]
                        offset = offset * 1.618f - HalfBlock * 3;
                    }

                    Vector3I endCoord      = startCoord + offset.RoundDown();
                    float    rootStartSize = (float)(rootBaseRadius * .618 * Math.Abs(offset[1]) / (Height * .618));

                    if (rootStartSize < 1)
                    {
                        rootStartSize = 1;
                    }
                    const float endSize = 1;

                    if (Args.Roots == RootMode.ToStone ||
                        Args.Roots == RootMode.Hanging)
                    {
                        float offLength = offset.Length;
                        if (offLength < 1)
                        {
                            continue;
                        }
                        float    rootMid = endSize;
                        Vector3F vec     = offset / offLength;

                        Block searchIndex = Block.Air;
                        if (Args.Roots == RootMode.ToStone)
                        {
                            searchIndex = Block.Stone;
                        }
                        else if (Args.Roots == RootMode.Hanging)
                        {
                            searchIndex = Block.Air;
                        }

                        int      startDist   = (int)(Args.Rand.NextDouble() * 6 * Math.Sqrt(rootStartSize) + 2.8);
                        Vector3I searchStart = new Vector3I(startCoord + vec * startDist);

                        dist = startDist + DistanceToBlock(Args.Map, new Vector3F(searchStart), vec, searchIndex);

                        if (dist < offLength)
                        {
                            rootMid += (rootStartSize - endSize) * (1 - dist / offLength);
                            endCoord = new Vector3I(startCoord + vec * dist);
                            if (Args.Roots == RootMode.Hanging)
                            {
                                float    remainingDist = offLength - dist;
                                Vector3I bottomCord    = endCoord;
                                bottomCord[1] -= (int)remainingDist;
                                TaperedLimb(endCoord, bottomCord, rootMid, endSize);
                            }
                        }
                        TaperedLimb(startCoord, endCoord, rootStartSize, rootMid);
                    }
                    else
                    {
                        TaperedLimb(startCoord, endCoord, rootStartSize, endSize);
                    }
                }
            }