(Solved)Stuck in doors

Started by mrofa, April 22, 2015, 02:40:50 PM

Previous topic - Next topic

mrofa

Was doing last test before realese and i found wierd thing. My door didnt hold roof or count as a wall for some odd reason.
So if i place them in a wall the room still count as outside. After 2h well im spamming here since i just run out of ideas, hope you guys got any ideas

This is the door dll.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse.AI;
using Verse;
using Verse.Sound;
using RimWorld;

namespace Clutter
{
    class Doors : Building_Door
    {
        private Graphic DoorMat_X;
        private Graphic DoorMat_Y;
        private Graphic DoorMat;
        private static Texture2D WorkProper;
        private static Texture2D DoorWF;
        private static Texture2D DoorNF;
        public Rot4 DoorCurRot;
        private bool FrameActive = false;
        private int Counter = 0;
       
        private Thing DoorFrameCheck
        {
            get
            {
              return childDoorFrame;
            }
        }

        private Thing WallLinkCheck
        {
            get
            {
              return childWallLinker;
            }
        }

        private Thing childDoorFrame = null;
        private Thing childWallLinker = null;

        private const string DoorFrameDefName = "ReinforcedDoorFrame";
        private const string WallLinkerDefName = "DoorLinker";
        private int VisualTicksToOpen
        {
            get
            {
                return this.TicksToOpenNow;
            }
        }

        // Texture switch

        public override Graphic Graphic
        {
            get
            {
                if (this.Rotation == Rot4.North)
                {
                    DoorMat = DoorMat_X;
                }
                if (this.Rotation == Rot4.East)
                {
                    DoorMat = DoorMat_Y;
                }
                return DoorMat;
            }
        }



        public override void SpawnSetup()
        {
            base.SpawnSetup();
            Doors.WorkProper = ContentFinder<Texture2D>.Get("Clutter/Ui/Work_ico", true);
            Doors.DoorWF = ContentFinder<Texture2D>.Get("Clutter/Ui/DoorWithFrame_Ico", true);
            Doors.DoorNF = ContentFinder<Texture2D>.Get("Clutter/Ui/Door_Ico", true);
            DoorMat_X = GraphicDatabase.Get<Graphic_Single>("Clutter/Structure/Door_X",this.def.shader);
            DoorMat_X.drawSize = this.def.DrawSize;
            //DoorMat_X.shader.name = "Transparent";
            DoorMat_Y = GraphicDatabase.Get<Graphic_Single>("Clutter/Structure/Door_Y",this.def.shader);
            DoorMat_Y.drawSize = this.def.DrawSize;
           
            DoorCurRot = this.Rotation;

            if (this.Rotation == Rot4.North)
            {
                DoorMat = DoorMat_X;
            }
            else if (this.Rotation == Rot4.East)
            {
                DoorMat = DoorMat_Y;
            }
           


        }

        public override void ExposeData()
        {
            base.ExposeData();
            Scribe_Values.LookValue<bool>(ref FrameActive, "FrameActive");
            Scribe_Values.LookValue<Rot4>(ref DoorCurRot, "CurrentRotation");
            Scribe_Values.LookValue<int>(ref this.Counter, "Counter");
            Scribe_References.LookReference<Thing>(ref childDoorFrame, "childDoorFrame");
            Scribe_References.LookReference<Thing>(ref childWallLinker, "childWallLinker");

        }

        public override void Tick()
        {

            base.Tick();
           
            if (Counter > 0)
            {
                if (Counter <= 1)
                {
                    FrameActive = !FrameActive;
                    PuffThing();
                }
                Counter -= 1;
            }

            if (this.Destroyed)
            {

             
                childWallLinker.Destroy(DestroyMode.Vanish);
               
            }
            if (this.childDoorFrame != null)
            {
                if(this.childDoorFrame.Destroyed)
                {
                    this.Destroy();
                }
            }
            if (this.childWallLinker != null)
            {
                if (this.childWallLinker.Destroyed)
                {
                    this.Destroy();
                }
            }
            //CheckRot();
            DoorFrameSpawner();
            WallLinker();
        }

        // Frame check and spawn
        private void DoorFrameSpawner()
        {

           
            if ((childDoorFrame == null || childDoorFrame.Destroyed) && FrameActive)
            {
                childDoorFrame = GenSpawn.Spawn(ThingDef.Named(DoorFrameDefName), Position);
               
            }
            if (childDoorFrame != null && !childDoorFrame.Destroyed && !FrameActive)
            {
                childDoorFrame.Destroy(DestroyMode.Vanish);
                //childDoorFrame = null;
            }

        }

        // Door Rotation Check
        //private void CheckRot()
        //{
        //    if (DoorCurRot != this.Rotation)
        //    {

        //        if (this.Rotation == Rot4.North || this.Rotation == Rot4.South)
        //        {
        //            DoorMat = DoorMat_X;
        //        }
        //        else if (this.Rotation == Rot4.East || this.Rotation == Rot4.West)
        //        {
        //            DoorMat = DoorMat_Y;
        //        }
        //        DoorCurRot = this.Rotation;

        //    }
        //}


        //Wall Linker Spawn and Destroy
        public void WallLinker()
        {


            if ((childWallLinker == null || childWallLinker.Destroyed) && FrameActive)
            {
                childWallLinker = GenSpawn.Spawn(ThingDef.Named(WallLinkerDefName), Position);
            }

            if (childWallLinker != null && !childWallLinker.Destroyed && !FrameActive)
            {
                childWallLinker.Destroy(DestroyMode.Deconstruct);
            }


        }



        // Wierd door thing ....
        //public override void Draw()
        //{
        //    if (this.Locked)
        //    {
        //        OverlayDrawer.DrawOverlay(this, OverlayTypes.Locked);
        //    }
        //    base.Rotation = Building_Door.DoorRotationAt(base.Position);
        //    float num = (float)this.visualTicksOpen / (float)this.VisualTicksToOpen;
        //    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;
        //        }

        //        Rot4 rotation = base.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, this.Graphic.MatAt(base.Rotation, null), 0);



        //    }

        //}


        public override IEnumerable<Gizmo> GetGizmos()
        {

            IList<Gizmo> list = new List<Gizmo>();
            Command_Action command_Action = new Command_Action();
            if (FrameActive && Counter <= 0)
            {

                command_Action.icon = Doors.DoorNF;
                command_Action.defaultDesc = "Frame Off";
                command_Action.activateSound = SoundDef.Named("Click");
                command_Action.action = new Action(this.FrameSwitch);
                command_Action.groupKey = 887767541;
                command_Action.hotKey = KeyBindingDefOf.Misc1;


            }
            else if(!FrameActive && Counter <= 0)
            {

                command_Action.icon = Doors.DoorNF;
                command_Action.defaultDesc = "Frame On";
                command_Action.activateSound = SoundDef.Named("Click");
                command_Action.action = new Action(this.FrameSwitch);
                command_Action.groupKey = 887767542;
                command_Action.hotKey = KeyBindingDefOf.Misc1;

            }
            else if (Counter > 0)
            {

                command_Action.icon = Doors.WorkProper;
                command_Action.action = new Action(this.FrameSwitch);
                command_Action.defaultDesc = "Working";
                command_Action.groupKey = 887767543;
                command_Action.hotKey = KeyBindingDefOf.Misc1;
            }



            list.Add(command_Action);
            IEnumerable<Gizmo> commands = base.GetGizmos();
            return (commands == null) ? list.AsEnumerable<Gizmo>() : list.AsEnumerable<Gizmo>().Concat(commands);


        }

        // Frame Switch Couter
        private void FrameSwitch()
        {
            if (Counter <= 0)
            {
                Counter = 500; // 1000;
            }
        }

        // Da Comfy Strings   
        public override string GetInspectString()
        {

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append(base.GetInspectString());
            stringBuilder.AppendLine();
            if (Counter > 0)
            {
                stringBuilder.Append("Working: " + Counter);
            }

            return stringBuilder.ToString();
        }

        //Puff stuff
        public void PuffThing()
        {

            for (int i = 0; i < 20; i++)
            {
                MoteThrower.ThrowAirPuffUp(this.DrawPos); ;
            }
        }

        //Self Own
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            if (WallLinkCheck != null && !WallLinkCheck.Destroyed)
            {
                WallLinkCheck.Destroy(mode);
            }

            if (DoorFrameCheck != null && !DoorFrameCheck.Destroyed)
            {
                DoorFrameCheck.Destroy(mode);
            }

            base.Destroy(mode);
        }

       

    }
}









This is the door xml

<!--========================= Door =============================-->
   <ThingDef ParentName="BuildingBase" >
      <defName>ClutterReinforcedDoor</defName>
    <label>Reinforced Door</label>
<thingClass>Clutter.Doors</thingClass>
    <blueprintClass>Blueprint_Door</blueprintClass>
    <category>Building</category>
<graphicShaderType>Transparent</graphicShaderType>
    <description>With few pieces of metal added, they seem a bit more durable.</description>
    <blueprintgraphicPath>Things/Building/Door/Door_Blueprint</blueprintgraphicPath>
<graphicPath>Clutter/Structure/Door_X2</graphicPath>
<graphicClass>Graphic_Single</graphicClass>
    <uiIconPath>Clutter/Ui/Door_Ico</uiIconPath>
    <altitudeLayer>DoorMoveable</altitudeLayer>
    <fillPercent>1</fillPercent>
    <useHitPoints>true</useHitPoints>
      <statBases>
   <WorkToMake>650</WorkToMake>
      <MaxHitPoints>150</MaxHitPoints>
      <Flammability>1.0</Flammability>
    </statBases>
<costList>
<Steel>175</Steel>
</costList>
    <leaveResourcesWhenKilled>false</leaveResourcesWhenKilled>
    <selectable>true</selectable>
    <tickerType>Normal</tickerType>
    <size>(1,1)</size>
    <rotatable>false</rotatable>
    <soundImpactDefault>BulletImpactMetal</soundImpactDefault>
    <terrainAffordanceNeeded>Light</terrainAffordanceNeeded>
    <designationCategory>Structure</designationCategory>
    <holdsRoof>true</holdsRoof>
    <staticSunShadowHeight>1.0</staticSunShadowHeight>
    <blockLight>true</blockLight>
    <drawerType>RealtimeOnly</drawerType>
    <building>
      <soundDoorOpenPowered>DoorOpenPowered</soundDoorOpenPowered>
      <soundDoorClosePowered>DoorClosePowered</soundDoorClosePowered>
      <soundDoorOpenManual>DoorOpenManual</soundDoorOpenManual>
      <soundDoorCloseManual>DoorCloseManual</soundDoorCloseManual>
      <ignoreNeedsPower>true</ignoreNeedsPower>
      <canPlaceOverWall>true</canPlaceOverWall>
    </building>
<researchPrerequisite>WallReinforcment</researchPrerequisite>
  </ThingDef>
All i do is clutter all around.

BBream

Did you check "WallLinkerDefName"? I think it spawned door position so it makes door always open. Or it override door so door consider as wall. It just guess.


        //Wall Linker Spawn and Destroy
        public void WallLinker()
        {


            if ((childWallLinker == null || childWallLinker.Destroyed) && FrameActive)
            {
                childWallLinker = GenSpawn.Spawn(ThingDef.Named(WallLinkerDefName), Position);
            }

            if (childWallLinker != null && !childWallLinker.Destroyed && !FrameActive)
            {
                childWallLinker.Destroy(DestroyMode.Deconstruct);
            }


        }


mrofa

Wall linker is only spawned after button is pressed, same go with the frame, normally door are build without them
All i do is clutter all around.

Saularian

Being stuck indoors is no good, you get cabin fever...

Oh you mean it in a different way :)

Could you be specific on what you are trying to achieve? (drawable door?)

Looking at vanilla code (xml) it seems doors have 2 parents (buildingbase, which is parent to doorbase, which then is parent to the actual door.) 

<!--==== Door Base ====-->
   <ThingDef ParentName="BuildingBase" Name="DoorBase" Abstract="True">
<thingClass>Clutter.Doors</thingClass>
    <blueprintClass>Blueprint_Door</blueprintClass>
    <category>Building</category>
    <blueprintgraphicPath>Things/Building/Door/Door_Blueprint</blueprintgraphicPath>
    <altitudeLayer>DoorMoveable</altitudeLayer>
    <fillPercent>1</fillPercent>
    <useHitPoints>true</useHitPoints>
    <statBases>
      <MaxHitPoints>150</MaxHitPoints>
      <Flammability>1.0</Flammability>
    </statBases>
    <leaveResourcesWhenKilled>false</leaveResourcesWhenKilled>
    <selectable>true</selectable>
    <tickerType>Normal</tickerType>
    <size>(1,1)</size>
    <rotatable>false</rotatable>
    <soundImpactDefault>BulletImpactMetal</soundImpactDefault>
    <terrainAffordanceNeeded>Light</terrainAffordanceNeeded>
    <designationCategory>Structure</designationCategory>
    <holdsRoof>true</holdsRoof>
    <staticSunShadowHeight>1.0</staticSunShadowHeight>
    <blockLight>true</blockLight>
    <drawerType>RealtimeOnly</drawerType>
    <building>
      <soundDoorOpenPowered>DoorOpenPowered</soundDoorOpenPowered>
      <soundDoorClosePowered>DoorClosePowered</soundDoorClosePowered>
      <soundDoorOpenManual>DoorOpenManual</soundDoorOpenManual>
      <soundDoorCloseManual>DoorCloseManual</soundDoorCloseManual>
      <ignoreNeedsPower>true</ignoreNeedsPower>
      <canPlaceOverWall>true</canPlaceOverWall>
    </building>
<researchPrerequisite>WallReinforcment</researchPrerequisite>
  </ThingDef>
 
  <!--===== Actual Door =====-->

  <ThingDef ParentName="DoorBase">
    <defName>ClutterReinforcedDoor</defName>
    <label>Reinforced Door</label>
    <description>With few pieces of metal added, they seem a bit more durable.</description>
    <statBases>
   <WorkToMake>650</WorkToMake>
    </statBases>
<graphicPath>Clutter/Structure/Door_X2</graphicPath>
<graphicClass>Graphic_Single</graphicClass>
    <uiIconPath>Clutter/Ui/Door_Ico</uiIconPath>
<costList>
<Steel>175</Steel>
</costList>
  </ThingDef>


This would be more compliant to the vanilla way how the door is set up, but if you don't get any error messages in the debug log, don't think it's the xml that's at fault.

BBream

I'm sure it is C# code problem. If it is changed thingClass to "Building_Door", then it works. I'm still finding.

BBream

#5
I found some code in RimWorld dll. If you want to make room with custom door class, I think you should make region manually.

In RegionMaker:

    private static bool CheckRegionableAndProcessNeighbor(IntVec3 c, Rot4 processingDirection)
    {
      if (!GenGrid.InBounds(c))
      {
        RegionMaker.newReg.touchesMapEdge = true;
        return false;
      }
      if (!GenGrid.Walkable(c))
        return false;
      Thing regionBarrier = GridsUtility.GetRegionBarrier(c);
      if (regionBarrier == null)
        return true;
      if (regionBarrier.def.thingClass == typeof (Building_Door))
        RegionMaker.TryMakePortalSpan(c, processingDirection);
      return false;
    }



NONONONO!!!

I found simple way! just add this line in xml code. Wow! I didn't know it is simple. It can be used refrigerator or other thing!

    <regionBarrier>true</regionBarrier>

mrofa

#6
It works kinda, but prevent colonists to find a path thrug door ...
I checked the code itself and comment everything leaving a empty class, it still dont work normally.
Well my last resort will be to copy entire door class and redo it a bit:D
Still thanks :)

EDIT:
Smees that if i add anythign with a base of Building_Door, it wont work as a room barrier like door do.
So this cant be done atleast in this alpha.

EDIT2:
And becouse im stubborn with this, i found the problem, but it still cant be done in this alpha.
Problem is in pathfinder class,  which specify door by the class "Building_Door".

All i do is clutter all around.

Latta

Just being curious, why the RegionMaker uses typeof? Until A9 it made regions without problem. Isn't it a clue that it used "is" keyword?

mrofa

#8
Building_Door isnt only in specified in pathfinder, building class have it specified to make it a room barrier and one other class that i cant remmber(something along the line to pathfinder).

So i think while tynan was making a optimalization here and therehe just forogot to add the thingdef for it befor the realese :D

Which kinda sux since i got finally a good formula with vanilia code for 2,5D side doors working(took only 8 coffie cups and 1,5 squieerl:D)
All i do is clutter all around.