(DLL) How to get the rotation of another object?

Started by Cala13er, August 24, 2014, 06:10:57 PM

Previous topic - Next topic

Cala13er

Honestly have no clue with this one but is there a way within dll to get the rotation of another object? For example,

I want my nuclear Reactor to only use resources from an adjacent hopper that is facing towards it. How would I go about doing this?

mrofa

private static int AlignQualityAgainst(IntVec3 sq)
{
if (!sq.InBounds())
{
return 0;
}
if (!sq.Walkable())
{
return 9;
}
List<Thing> list = Find.ThingGrid.ThingsListAt(sq);
for (int i = 0; i < list.Count; i++)
{
Thing thing = list[i];
if (thing.def.eType == EntityType.Door)
{
return 1;
}
Thing thing2 = thing as Blueprint;
if (thing2 != null)
{
if (thing2.def.entityDefToBuild.passability == Traversability.Impassable)
{
return 9;
}
if (thing2.def.eType == EntityType.Door)
{
return 1;
}
}
}
return 0;
}
public static IntRot DoorRotationAt(IntVec3 loc)
{
int num = 0;
int num2 = 0;
num += Building_Door.AlignQualityAgainst(loc + IntVec3.east);
num += Building_Door.AlignQualityAgainst(loc + IntVec3.west);
num2 += Building_Door.AlignQualityAgainst(loc + IntVec3.north);
num2 += Building_Door.AlignQualityAgainst(loc + IntVec3.south);
if (num >= num2)
{
return IntRot.north;
}
return IntRot.east;
}


This code is from Building_door, had play with it only for few hours, but i think if you use point system from AlignQualityAgainst, you will be able to get rotation of another object.
All i do is clutter all around.

RawCode


        public IntRot rotation = new IntRot();

is property of thing class nearly every object extends...

used only inside draw procedure


            Graphics.DrawMesh(this.DrawMesh, drawLoc, asQuat, this.DrawMat(this.rotation), 0);


Since question is "how to get" answer is:

read field named "rotation"

mrofa

#3
Thats not correct answere, had same idea while working on the door, but rotation is always 0 in this case, not sure why.
Here is how i did it, its still in thinkering phase but object introt detection works.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse.AI;
using Verse;
using Verse.Sound;
using VerseBase;
using RimWorld;

namespace Clutter_Structure
{
    class Doors : Building_Door
    {
        private Material DoorMat_X;
        private Material DoorMat_Y;
        private Material DoorMat;
        private IntRot DoorRot
        {
            get
             {
            return Building_Door.DoorRotationAt(base.Position);
             }
        }

        //public override Material DrawMat(IntRot rot)
        //{

        //    {
        //        if (DoorRot == IntRot.north)
        //        {
        //            DoorMat = DoorMat_X;
        //        }
        //        if (DoorRot == IntRot.east)
        //        {
        //            DoorMat = DoorMat_Y;
        //        }
        //        return DoorMat;
        //    }
        //}

       

        public override void SpawnSetup()
        {
            base.SpawnSetup();

            DoorMat_X = MaterialPool.MatFrom("Door_X", MatBases.Transparent);
            DoorMat_Y = MaterialPool.MatFrom("Door_Y", MatBases.Transparent);
            //DoorMat = DoorMat_X;
            if (DoorRot == IntRot.north)
            {
                DoorMat = DoorMat_X;
            }
            if (DoorRot == IntRot.east)
            {
                DoorMat = DoorMat_Y;
            }
           
           
                       
           
        }



       
        public override void Draw()
        {
            this.rotation = Building_Door.DoorRotationAt(base.Position);
            float num = (float)this.visualTicksOpen / 10f;
            float d = 0f + 0.5f * num;
            for (int i = 0; i < 2; i++)
            {
                Vector3 vector = default(Vector3);
                Mesh mesh;
                if (i == 0)
                {
                    vector = new Vector3(0f, 0f, -1f);
                    mesh = MeshPool.plane10;
                }
                else
                {
                    vector = new Vector3(0f, 0f, 1f);
                    mesh = MeshPool.plane10Flip;
                }
                IntRot rotation = this.rotation;
                rotation.Rotate(RotationDirection.Clockwise);
                vector = rotation.AsQuat * vector;
                Vector3 vector2 = this.DrawPos;
                vector2.y = Altitudes.AltitudeFor(AltitudeLayer.DoorMoveable);
                vector2 += vector * d;
                Graphics.DrawMesh(mesh, vector2, this.rotation.AsQuat, DoorMat, 0);
            }
            base.Comps_Draw();
        }

       
    }
}
All i do is clutter all around.

RawCode

Door is not only object that "rotate".

For projectiles valid property is "ExactRotation"

Also battery clearly uses that field for rendering, check Building_Battery self.

mrofa

#5
Well if you say so, but then why rotate dont return any other value than 0. While door addjust to its surroiding.

Edit: Well stupid me :D
Did test it on ticker insted of spawnsetup, and your right rotation change between 0 and 3.
So yehh checking and changing rotation with this.rotation is possible.
And i just fixed my door issue cool :D
All i do is clutter all around.

Rikiki

#6
I did not tested it but I think the code below could work.
 
Thing adjacentReactorHopper = Find.ThingGrid.ThingAt(anAdjacentSquare, ThingDef.Named("NuclearReactorHopper"));
if ((adjacentReactorHopper != null)
    && (adjacentReactorHopper.rotation == this.rotation)) // You may change this condition in function of the rotation you want.
{
    // Check if it contains resources...
}


You just need to test each square around your reactor.

You should probably perform a check in function of the nuclear reactor rotation with this:
 
if (this.rotation == IntRot.north)
{
    if (adjacentReactorHopper.rotation == IntRot.east)
    {
        // PerformTreatment();   
    }
}
else if (this.rotation == IntRot.east)
{
    ...