Tynan, A small modders request for a snippet of code

Started by skullywag, February 02, 2015, 03:32:01 PM

Previous topic - Next topic

skullywag

Hey Tynan, could I get the CalculateWindCells code from the wind turbine. Its not visible to outside sources and I cant stuffify it without it. No rush and if you dont wanna I totally understand.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Haplo

You can find the WindTurbine code in here.
Look for this: "Example 2b - FineTuned BuildingWindTurbine.cs" :)

Coenmcj

Think he might be meaning how the Wind turbines work in the more recent builds?.. but if he does it might of been best to ask the Private tester forums.
Moderator on discord.gg/rimworld come join us! We don't bite

skullywag

Does your version have the same shape calculation in it Haplo? I didnt think yours calculated the same area...

and no i was after the A8 version so this forum is correct.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Haplo

Hmm, I might have reduced it to make it easier for the beginners. I'll take a look at it this evening and tell you. If not then I have the original shape code somewhere on my hard drive. I just have to find it :)

Edit: Checked it out. It is the full one.

The part you're looking for is this:

        // Find the cells of the wind path before and behind the wind turbine
        private IEnumerable<IntVec3> GetCellsOfConeBeforeAndBehindObject(IntVec3 thingCenter, IntRot thingRot, IntVec2 thingSize)
        {
            // Base cone:
            //  +++          +xx+
            // +++++        ++xx++
            // XXXXX        ++xx++       
            // XXXXX        ++xx++
            // +++++        ++xx++
            //  +++          +xx+

            // Description:
            // X - Object
            // + - Returned cells

            int numBaseX1, numBaseX2, numBaseZ1, numBaseZ2;
            int num1X1, num1X2, num2X1, num2X2, num1Z1, num1Z2, num2Z1, num2Z2;
            int num3X1, num3X2, num3Z1, num3Z2, num4X1, num4X2, num4Z1, num4Z2;

            // change to resize wind path
            int extensionLengthFront = 5;
            int extensionLengthBack = 2;

            // Find base points to work with
            // X1 and Z1 are the lower values
            if (thingRot == IntRot.north)
            {
                numBaseX1 = thingCenter.x - (thingSize.x + 1) / 2 + 1;
                numBaseX2 = numBaseX1 + thingSize.x - 1;
                numBaseZ1 = thingCenter.z - (thingSize.z + 1) / 2 + 1;
                numBaseZ2 = numBaseZ1 + thingSize.z - 1;
            }
            else if (thingRot == IntRot.east)
            {
                numBaseX1 = thingCenter.x - (thingSize.z + 1) / 2 + 1;
                numBaseX2 = numBaseX1 + thingSize.z - 1;
                numBaseZ1 = thingCenter.z - thingSize.x / 2;
                numBaseZ2 = numBaseZ1 + thingSize.x - 1;
            }
            else if (thingRot == IntRot.south)
            {
                numBaseX1 = thingCenter.x - thingSize.x / 2;
                numBaseX2 = numBaseX1 + thingSize.x - 1;
                numBaseZ1 = thingCenter.z - thingSize.z / 2;
                numBaseZ2 = numBaseZ1 + thingSize.z - 1;
            }
            else //if ( thingRot == IntRot.west )
            {
                numBaseX1 = thingCenter.x - thingSize.z / 2;
                numBaseX2 = numBaseX1 + thingSize.z - 1;
                numBaseZ1 = thingCenter.z - (thingSize.x + 1) / 2 + 1;
                numBaseZ2 = numBaseZ1 + thingSize.x - 1;
            }

            IntVec3 intVec3;

            // Get the cells from here if the rotation is north or south
            if (Rotation == IntRot.north || Rotation == IntRot.south)
            {
                // Base cone, inner part
                num1X1 = numBaseX1 + 0;
                num1X2 = numBaseX2 + 0;
                num1Z1 = numBaseZ1 - 1;
                num1Z2 = numBaseZ2 + 1;
                // Base cone, outer part
                num2X1 = numBaseX1 + 0; // original: +1
                num2X2 = numBaseX2 + 0; // original: -1
                num2Z1 = numBaseZ1 - 2;
                num2Z2 = numBaseZ2 + 2;

                if (Rotation == IntRot.north)
                {
                    // Extended dome
                    num3X1 = numBaseX1 + 1;
                    num3X2 = numBaseX2 - 1;
                    num3Z1 = numBaseZ1 - 2 - extensionLengthBack;
                    num3Z2 = numBaseZ1 - 2;

                    num4X1 = numBaseX1 + 1;
                    num4X2 = numBaseX2 - 1;
                    num4Z1 = numBaseZ2 + (extensionLengthFront - 2);
                    num4Z2 = numBaseZ2 + (extensionLengthFront + 2);
                }
                else //if (Rotation == IntRot.south)
                {
                    // Extended dome
                    num3X1 = numBaseX1 + 1;
                    num3X2 = numBaseX2 - 1;
                    num3Z1 = numBaseZ1 - (extensionLengthFront + 2);
                    num3Z2 = numBaseZ1 - (extensionLengthFront - 2);

                    num4X1 = numBaseX1 + 1;
                    num4X2 = numBaseX2 - 1;
                    num4Z1 = numBaseZ2 + 2;
                    num4Z2 = numBaseZ2 + 2 + extensionLengthBack;
                }


                intVec3 = new IntVec3(num1X1, 0, num1Z1);
                do
                {
                    yield return intVec3;
                    intVec3.x += 1;
                } while (intVec3.x <= num1X2);

                intVec3 = new IntVec3(num2X1, 0, num2Z1);
                do
                {
                    yield return intVec3;
                    intVec3.x += 1;
                } while (intVec3.x <= num2X2);


                intVec3 = new IntVec3(num1X1, 0, num1Z2);
                do
                {
                    yield return intVec3;
                    intVec3.x += 1;
                } while (intVec3.x <= num1X2);

                intVec3 = new IntVec3(num2X1, 0, num2Z2);
                do
                {
                    yield return intVec3;
                    intVec3.x += 1;
                } while (intVec3.x <= num2X2);


                // Extended dome
                intVec3 = new IntVec3(num3X1 - 1, 0, num3Z1);
                while (intVec3.x < num3X2 || intVec3.z < num3Z2)
                {
                    if (intVec3.x < num3X2)
                    {
                        intVec3.x += 1;
                    }
                    else if (intVec3.z <= num3Z2)
                    {
                        intVec3.x = num3X1;
                        intVec3.z += 1;
                    }
                    yield return intVec3;
                }

                intVec3 = new IntVec3(num4X1 - 1, 0, num4Z1);
                while (intVec3.x < num4X2 || intVec3.z < num4Z2)
                {
                    if (intVec3.x < num4X2)
                    {
                        intVec3.x += 1;
                    }
                    else if (intVec3.z <= num4Z2)
                    {
                        intVec3.x = num4X1;
                        intVec3.z += 1;
                    }
                    yield return intVec3;
                }

            }

            // Get the cells from here if the rotation is east or west
            if (Rotation == IntRot.east || Rotation == IntRot.west)
            {
                // Base cone, inner part
                num1X1 = numBaseX1 - 1;
                num1X2 = numBaseX2 + 1;
                num1Z1 = numBaseZ1 + 0;
                num1Z2 = numBaseZ2 + 0;
                // Base cone, outer part
                num2X1 = numBaseX1 - 2;
                num2X2 = numBaseX2 + 2;
                num2Z1 = numBaseZ1 + 0; // original: +1
                num2Z2 = numBaseZ2 + 0; // original: -1

                if (Rotation == IntRot.east)
                {
                    // Extended dome
                    num3X1 = numBaseX1 - 2 - extensionLengthBack;
                    num3X2 = numBaseX1 - 2;
                    num3Z1 = numBaseZ1 + 1;
                    num3Z2 = numBaseZ2 - 1;

                    num4X1 = numBaseX2 + (extensionLengthFront - 2);
                    num4X2 = numBaseX2 + (extensionLengthFront + 2);
                    num4Z1 = numBaseZ1 + 1;
                    num4Z2 = numBaseZ2 - 1;
                }
                else //if (Rotation == IntRot.west)
                {
                    // Extended dome
                    num3X1 = numBaseX1 - (extensionLengthFront + 2);
                    num3X2 = numBaseX1 - (extensionLengthFront - 2);
                    num3Z1 = numBaseZ1 + 1;
                    num3Z2 = numBaseZ2 - 1;

                    num4X1 = numBaseX2 + 2;
                    num4X2 = numBaseX2 + 2 + extensionLengthBack;
                    num4Z1 = numBaseZ1 + 1;
                    num4Z2 = numBaseZ2 - 1;
                }


                intVec3 = new IntVec3(num1X1, 0, num1Z1);
                do
                {
                    yield return intVec3;
                    intVec3.z += 1;
                } while (intVec3.z <= num1Z2);

                intVec3 = new IntVec3(num2X1, 0, num2Z1);
                do
                {
                    yield return intVec3;
                    intVec3.z += 1;
                } while (intVec3.z <= num2Z2);


                intVec3 = new IntVec3(num1X2, 0, num1Z1);
                do
                {
                    yield return intVec3;
                    intVec3.z += 1;
                } while (intVec3.z <= num1Z2);

                intVec3 = new IntVec3(num2X2, 0, num2Z1);
                do
                {
                    yield return intVec3;
                    intVec3.z += 1;
                } while (intVec3.z <= num2Z2);


                // Extended dome
                intVec3 = new IntVec3(num3X1 - 1, 0, num3Z1);
                while (intVec3.x < num3X2 || intVec3.z < num3Z2)
                {
                    if (intVec3.x < num3X2)
                    {
                        intVec3.x += 1;
                    }
                    else if (intVec3.z <= num3Z2)
                    {
                        intVec3.x = num3X1;
                        intVec3.z += 1;
                    }
                    yield return intVec3;
                }

                intVec3 = new IntVec3(num4X1 - 1, 0, num4Z1);
                while (intVec3.x < num4X2 || intVec3.z < num4Z2)
                {
                    if (intVec3.x < num4X2)
                    {
                        intVec3.x += 1;
                    }
                    else if (intVec3.z <= num4Z2)
                    {
                        intVec3.x = num4X1;
                        intVec3.z += 1;
                    }
                    yield return intVec3;
                }
            }


Beware: I never said anything about it being a simple piece of code ;)

skullywag

Thanks Haplo, I was only needing it to stuffify the wind turbine, so understanding it wasnt the issue. I can actually understand most of that randomly though!
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?