Container

From TrainzOnline
Revision as of 18:59, 28 April 2024 by Ek.skirl (Talk | contribs)

Jump to: navigation, search

Contents

Container objects

Container types

There are ten container types used in the aCTS: 10ftsc, 10fthc, 20ftsc, 20fthc, 40ftsc, 40fthc, 45ftsc, 45fthc and 53ftsc, 53fthc. An aCTS usable container is predefined with its origin at the geometrical middle of the bottom face.

A container knows its container stack and its position in it. A container is able to report its parameter soups, including a yet not used virtual list of content to transport within it.

Container from other asset builder

So the container assets of other asset builders need possibly a variant with config setted position and rotation. Additionally the scale may be needed to set for fitting the technical dimensions. All containers that don't fit the technical dimensions and the logical origin position and rotation have a config extensions sub soup with the name "acts.origindelta-251489" and tags for correcting the assets values to the aCTS fitting ones (accuracy 0.1 mm and 0.1 °), looking like follows:

 acts.delta-251489 {
   px.delta    0.0
   py.delta    0.0
   pz.delta    0.0
   rx.delta    0.0
   ry.delta    0.0
   rz.delta    0.0
 }

The values will be used while calculation the location and orientation to posit them into the world by adding them to the normal calculated values. The adding is meant in positiv directin and ccw.

Unfortunately the scale of the mesh may not be corrected by some factor to fit the aCTS dimensions. So for containers with other dimensions one may see a small gap between stacked containers or they run optical into each other.


Asset files pre version 0.1

The files compile errorless and the messaging runs well. No more functionality implemented and tested in this pre version.

config.txt

XY is the KUID part, LL the length and HH or hh the height for the container type.

X   1 for 10ft, 2 for 20ft, 3 for 40ft, 4 for 45ft and 5 for 53ft
Y   1 for standard height, 2 for heigh cube height
LL  the fitting length as 10, 20, 40, 45, 53
hh  the fitting height as sc, hc
HH  the fitting height as SC, HC

 kuid               <Kuid2:215489:11002XY:1>
 username           "aCTS CONTAINER LLft HH Scenery Utility V0.1"
 kind               "Scenery"
 category-class     "BU"
 description        "aCTS CONTAINER LLft HH Scenery Utility V0.1"
 
 trainz-build       4.6
 
 surveyor-only      0
 
 script             "acts_container.gs"
 class              "acts_container"
 
 kuid-table 
 {
   skinskuid        <kuid2:215489:1100200:1>
   scriptinclude    <kuid2:215489:110000:1>
 }
 
 script-include-table 
 {
   scriptinclude    <kuid2:215489:110000:1>
 }
 
 mesh-table-lod-transition-distances    1000
 mesh-detail-level-count                1
 
 mesh-table
 {
   contLLft-lod0
   {
     mesh                   "acts_cont_LLfthh.trainzmesh"
     auto-create            1
     lod-level              0
     effects 
     {
       skincolor 
       {
         kind       "texture-replacement"
         texture    "acts_container_allinone.texture"
       }
       namev 
       {
         kind       "name"
         name       "GOIDV"
         att        "a.namev"
         font       "swiss"
         fontsize   0.3
         fontcolor  1.0,1.0,1.0
       }
       nameh 
       {
         kind       "name"
         name       "GOIDH"
         att        "a.nameh"
         font       "swiss"
         fontsize   0.3
         fontcolor  1.0,1.0,1.0
       }
     }
   }
 }
 
 thumbnails
 {
   0
   {
     image          "acts_cont_LLfthh_thumb.jpg"
     width          240
     height         180
   }
 }
 

acts_container.gs

 include "acts_container_script.gs"
 
 //-----------------------------------------------------------------------------
 // aCTS Container V0.1 Central Script - acts_container.gs
 //-----------------------------------------------------------------------------
 // X acts_container             <-- acts_container_script
 //   acts_container_script      <-- acts_container_skinreplace
 //   acts_container_skinreplace <-- acts_container_register
 //   acts_container_register    <-- acts_container_globals
 //   acts_container_globals     <-- acts_global_values
 //   acts_global_values         <-- MapObject
 //-----------------------------------------------------------------------------
 
 class acts_container isclass acts_container_script
 {
   // --------------------------------------------------------------------------
   // Mandatory INIT method
   // --------------------------------------------------------------------------
   public void Init(Asset asset)
   {
     inherited(asset);
     //-------------------------------------------------------------------------
     // Make shure that the right module is set for World.GetCurrentModle()
     // (see world.gs lines 939ff.) to start driver related initiations and
     // tell me, if my Init and SetProperties methods are finished.
     // Add handler for my tasks as dispatcher.
     //-------------------------------------------------------------------------
     AddHandler(me, "World", "ModuleInit", "WorldInitHandler");
     AddHandler(me, "OBJECTINIT", "", "ObjectInitHandler");
     AddHandler(me, "DISPATCHER", "", "DispatcherHandler");
     //-------------------------------------------------------------------------
     // It's nessecary to initalise the lib to force subscript preparing
     //-------------------------------------------------------------------------
     //World.GetLibrary(GetAsset().LookupKUIDTable("dummylibrary"));
     dispobj = World.GetLibrary(GetAsset().LookupKUIDTable("scriptinclude"));
     dispgoid = (cast<GameObject>dispobj).GetGameObjectID();
     //-------------------------------------------------------------------------
     // Set asset special initial values
     //-------------------------------------------------------------------------
     contlength = "20ft";
     contheight = "sc";
     //-------------------------------------------------------------------------
     isInitMethodFinnished = true;
     PostMessage(me,"OBJECTINIT","INIT_FINNISHED",0.0);   // Init method finnished
     return;
   }    
   //---------------------------------------------------------------------------
 };

acts_container_script.gs

 include "acts_container_globals.gs"
 include "acts_tools_script.gs"
 
 //-----------------------------------------------------------------------------
 // aCTS Container V0.1 Central Script - acts_container_script.gs
 //-----------------------------------------------------------------------------
 //   acts_container             <-- acts_container_script
 // X acts_container_script      <-- acts_container_skinreplace
 // X acts_container_skinreplace <-- acts_container_register
 // X acts_container_register    <-- acts_container_globals
 //   acts_container_globals     <-- acts_global_values
 //   acts_global_values         <-- MapObject
 //-----------------------------------------------------------------------------
 
 class acts_container_register isclass acts_container_globals
 {
   //---------------------------------------------------------------------------
   // TBD: Outsource from acts_container_script
   //---------------------------------------------------------------------------
 };
 
 class acts_container_skinreplace isclass acts_container_register
 {
   //---------------------------------------------------------------------------
   // TBD: Outsource from acts_container_script
   //---------------------------------------------------------------------------
 };
 
 class acts_container_script isclass acts_container_skinreplace
 {
   //---------------------------------------------------------------------------
   public void SetProperties(Soup soup)   // Callback method after Init method
   {
     inherited(soup);
     //-------------------------------------------------------------------------
     SkinDataSoup.Copy(soup.GetNamedSoup("SkinData"));
     ObjectDataSoup.Copy(soup.GetNamedSoup("ObjectData"));
     LocationSoup.Copy(soup.GetNamedSoup("Location"));
     OrientationSoup.Copy(soup.GetNamedSoup("Orientation"));
     ContentDataSoup.Copy(soup.GetNamedSoup("ContentData"));
     //-------------------------------------------------------------------------
     isSetPropertiesMethodFinnished = true;
     PostMessage(me,"OBJECTINIT","SETPROPS_FINNISHED",0.0);
     return;
   }
   //---------------------------------------------------------------------------
   public Soup GetProperties(void)   // Callback method before closing session 
   {
     Soup soup = inherited();
     //-------------------------------------------------------------------------
     if (acts_debug)Interface.Log(Interface.GetTimeStamp()
               + " [" + objectgoid.SerialiseToString() + "]"
               + " CONTAINER SKINDATASOUP");
     if (acts_debug)actsTools.ShowSoup(SkinDataSoup,"=>");
     //-------------------------------------------------------------------------*/
     soup.SetNamedSoup("SkinData",SkinDataSoup);
     soup.SetNamedSoup("ObjectData",ObjectDataSoup);
     soup.SetNamedSoup("Location",LocationSoup);
     soup.SetNamedSoup("Orientation",OrientationSoup);
     soup.SetNamedSoup("ContentData",ContentDataSoup);
     //-------------------------------------------------------------------------
     return soup;
   }
   //---------------------------------------------------------------------------
   public void WorldInitHandler(Message msg)
   {
     if (acts_debug)Interface.Log(Interface.GetTimeStamp()
             + " [" + objectgoid.SerialiseToString() + "]"
             + " CONTAINER GOT WORLDINIT MESSAGE ["
             + msg.major+"] ["+msg.minor+"]");
     //-------------------------------------------------------------------------*/
     // If one of the two methods (Init or SetProperties) isn't finished yet, 
     // post "World","ModuleInit" message a little bit later again.
     // So it is guaranteed that the Init and SetProperties methods are finished
     // as well as the "World","ModuleInit" message tells to be save using the 
     // World.GetCurrentModule method.
     //-------------------------------------------------------------------------
     if (!(isSetPropertiesMethodFinnished and isInitMethodFinnished))
     {
       PostMessage(me, "World", "ModuleInit", 0.1);
     }
     //-------------------------------------------------------------------------
     isWorldInitFinnished = true;
     PostMessage(me, "OBJECTINIT", "WORLD_INIT_FINNISHED", 0.0);
     //-------------------------------------------------------------------------
     return;
   }
   //---------------------------------------------------------------------------
   public void ObjectInitHandler(Message msg)
   {
     //-------------------------------------------------------------------------
     // Until the Trainz core send the "World","ModuleInit" was send it is not
     // guarented to decide with the World.GetCurrentModule method to be in the 
     // returned module! 
     //-------------------------------------------------------------------------
     if (acts_debug)Interface.Log(Interface.GetTimeStamp()
             + " [" + objectgoid.SerialiseToString() + "]"
             + " CONTAINER GOT MESSAGE ["+msg.major+"] ["+msg.minor+"]");
     //-------------------------------------------------------------------------*/
     if (msg.dst==me and msg.major=="OBJECTINIT")
     {
       if (msg.minor=="INIT_FINNISHED")
       {
         //---------------------------------------------------------------------
         // Show the goid on both sides of me (for debugging purpose)
         //---------------------------------------------------------------------
         SetFXNameText("GOIDV","["+objectgoid.SerialiseToString()+"]");
         SetFXNameText("GOIDH","["+objectgoid.SerialiseToString()+"]");
         //---------------------------------------------------------------------
         skins = GetAsset().FindAsset("skinskuid");
         //---------------------------------------------------------------------
       }
       //-----------------------------------------------------------------------
       if (msg.minor=="SETPROPS_FINNISHED")
       {
         //---------------------------------------------------------------------
         // Adjust position and rotation to rounded values 
         // (see acts_toolsscript.gs)
         //---------------------------------------------------------------------
         //Soup sp = actsTools.AutoAdjustMapObject(me);
         //LocationSoup    = sp.GetNamedSoup("AdjustedLocationSoup");
         //OrientationSoup = sp.GetNamedSoup("AdjustedOrientationSoup");
         //---------------------------------------------------------------------
         // Random skin number or load skin number from soup
         // TBD: Additionally set the skin with the properties browser.
         //---------------------------------------------------------------------
         if (SkinDataSoup.CountTags()==0)
         {
           textcount = 9;
           skin = Math.Rand(1, textcount+1);
           skinDescription = "TR_Random_Texture [#"+skin+"]";
           SkinDataSoup.SetNamedTag("skin",skin);
           SkinDataSoup.SetNamedTag("skinDescription",skinDescription);
         }
         else
         {
           skin            = SkinDataSoup.GetNamedTagAsInt("skin");
           skinDescription = SkinDataSoup.GetNamedTag("skinDescription");
         }
         if (skin == 0) SetFXTextureReplacement("skincolor",null,0);
         else SetFXTextureReplacement("skincolor",skins,skin-1);
         //---------------------------------------------------------------------
         if (acts_debug)Interface.Log(Interface.GetTimeStamp()
                   + " [" + objectgoid.SerialiseToString() + "]"
                   + " CONTAINER SKIN ["+skin+"] ["+skinDescription+"]");
         if (acts_debug)actsTools.ShowSoup(SkinDataSoup,"=>");
         //---------------------------------------------------------------------*/
         if (ObjectDataSoup.CountTags()==0)
         {
           //-------------------------------------------------------------------
           // LoadObjectDataInfos(ObjectDataSoup);
           //-------------------------------------------------------------------
           ObjectDataSoup.SetNamedTag("goid",objectgoid);
           ObjectDataSoup.SetNamedTag("type",objecttype);
           ObjectDataSoup.SetNamedTag("length",contlength);
           ObjectDataSoup.SetNamedTag("height",contheight);
           ObjectDataSoup.SetNamedTag("regID",-1);
           ObjectDataSoup.SetNamedTag("active",false);   // False: Not reachable
           ObjectDataSoup.SetNamedTag("requested",false);
           ObjectDataSoup.SetNamedTag("hooked",false);
         }
         //---------------------------------------------------------------------
         if (acts_debug)Interface.Log(Interface.GetTimeStamp()
                     + " =>SOUP 'ObjectDataSoup'");
         if (acts_debug)actsTools.ShowSoup(ObjectDataSoup,"=>");
         //---------------------------------------------------------------------*/
         if (LocationSoup.CountTags()==0)
         {
           //-------------------------------------------------------------------
           // LoadLocationDataInfos(LocationDataSoup);
           //-------------------------------------------------------------------
           WorldCoordinate WC = me.GetMapObjectPosition();
           LocationSoup.SetNamedTag("bbx",WC.baseboardX);
           LocationSoup.SetNamedTag("bby",WC.baseboardY);
           LocationSoup.SetNamedTag("px",WC.x);
           LocationSoup.SetNamedTag("py",WC.y);
           LocationSoup.SetNamedTag("pz",WC.z);
         }
         //---------------------------------------------------------------------
         if (OrientationSoup.CountTags()==0)
         {
           //-------------------------------------------------------------------
           // LoadOrientationDataInfos(OrientationDataSoup);
           //-------------------------------------------------------------------
           Orientation OR = me.GetMapObjectOrientation();
           LocationSoup.SetNamedTag("rx",OR.rx);
           LocationSoup.SetNamedTag("ry",OR.ry);
           LocationSoup.SetNamedTag("rz",OR.rz);
           LocationSoup.SetNamedTag("gx",OR.rx*180.0/Math.PI);
           LocationSoup.SetNamedTag("gy",OR.ry*180.0/Math.PI);
           LocationSoup.SetNamedTag("gz",OR.rz*180.0/Math.PI);
         }
         //---------------------------------------------------------------------
       }
     }
   }
   //---------------------------------------------------------------------------
 public void DispatcherHandler(Message msg)
   {
     if (msg.dst==me and msg.major=="DISPATCHER")
     {
       //-----------------------------------------------------------------------
       if (acts_debug)Interface.Log(Interface.GetTimeStamp()
               + " [" + objectgoid.SerialiseToString() + "] ["
               + " CONTAINER GOT MESSAGE FROM DISPATCHER"
               + (cast<GameObject>msg.src).GetGameObjectID().SerialiseToString()
               + "] ["+msg.major+"] ["+msg.minor+"]");
       //-----------------------------------------------------------------------*/
       if (msg.minor=="UPDATED")
       {
         //---------------------------------------------------------------------
         // Update the own ObjectDataSoup
         //---------------------------------------------------------------------
         ObjectDataSoup.Copy(cast<Soup>msg.paramSoup);
         if (acts_debug)Interface.Log(Interface.GetTimeStamp()
                 + " SOUP CONTENT OF 'Updated DataSoup' GOID"
                 + " [" + objectgoid.SerialiseToString() + "]");
         if (acts_debug)actsTools.ShowSoup(ObjectDataSoup,"=>");
         //---------------------------------------------------------------------*/
       }
       if (msg.minor=="INSERTED")
       {
         //---------------------------------------------------------------------
         // Update the own ObjectDataSoup
         //---------------------------------------------------------------------
         ObjectDataSoup.Copy(cast<Soup>msg.paramSoup);
         if (acts_debug)Interface.Log(Interface.GetTimeStamp()
                 + " SOUP CONTENT OF 'Inserted DataSoup' GOID"
                 + " [" + objectgoid.SerialiseToString() + "]");
         if (acts_debug)actsTools.ShowSoup(ObjectDataSoup,"=>");
         //---------------------------------------------------------------------*/
       }
       if (msg.minor=="APPENDED")
       {
         //---------------------------------------------------------------------
         // Update the own ObjectDataSoup
         //---------------------------------------------------------------------
         ObjectDataSoup.Copy(cast<Soup>msg.paramSoup);
         if (acts_debug)Interface.Log(Interface.GetTimeStamp()
                 + " SOUP CONTENT OF 'Added DataSoup' GOID"
                 + " [" + objectgoid.SerialiseToString() + "]");
         if (acts_debug)actsTools.ShowSoup(ObjectDataSoup,"=>");
         //---------------------------------------------------------------------*/
       }
     }
     //-------------------------------------------------------------------------
     return;
   }
   //---------------------------------------------------------------------------*/
 };
 

File is located in dispatcher library.

acts_container_globals.gs

 include "acts_global_values.gs"
 
 //-----------------------------------------------------------------------------
 // aCTS Container V0.1 Central Script - acts_container_script.gs
 //-----------------------------------------------------------------------------
 //   acts_container             <-- acts_container_script
 //   acts_container_script      <-- acts_container_skinreplace
 //   acts_container_skinreplace <-- acts_container_register
 //   acts_container_register    <-- acts_container_globals
 // X acts_container_globals     <-- acts_global_values
 //   acts_global_values         <-- MapObject
 //-----------------------------------------------------------------------------
 
 class acts_container_globals isclass acts_global_values
 {
   //---------------------------------------------------------------------------
   // AssetInstanceSoup {
   // X ObjectDataSoup { ... },    Only container, contstack, contcrane
   // X LocationSoup { ... },      Only container, contstack, contcrane
   // X OrientationSoup { ... },   Only container, contstack, contcrane
   // X SkinDataSoup { ... },      Only container
   // X ContentDataSoup { ... },   Only container
   //   DispatcherDataSoup { ... } Only dispatcher
   //   ContainerSoups  { ... }    Only dispatcher
   //   ContstackSoups  { ... }    Only dispatcher
   //   ContcraneSoups  { ... }    Only dispatcher
   // }
   //---------------------------------------------------------------------------
   // ObjectDataSoup { goid GameObjectID, type string,
   //                  length string, height string,  
   //                  stack goid, place int,           Only container
   //                  active bool, action string },
   // activ: true means the object sended a register message while session run
   //        All objects were set false while initialising dispatcher and if
   //        they stay false their entries will be deleted next initialising.
   // actions: ["APPENDED", "INSERTED", "UPDATED"];
   //---------------------------------------------------------------------------
   Soup ObjectDataSoup = Constructors.NewSoup();
   //---------------------------------------------------------------------------
   // LocationSoup { bbx int, bby int,               // WorlCoordinate parameter
   //                px float, py float, pz float }
   //---------------------------------------------------------------------------
   Soup LocationSoup = Constructors.NewSoup();
   //---------------------------------------------------------------------------
   // OrientationSoup { rx float, ry float, rz float,    // in rad 
   //                   gx float, gy float, gz float }   // in 1/10°
   //---------------------------------------------------------------------------
   Soup OrientationSoup = Constructors.NewSoup();
   //---------------------------------------------------------------------------
   GameObjectID objectgoid = me.GetGameObjectID();
   string       objecttype = "CONTAINER";
   string       contlength;
   string       contheight;
   Library      dispobj;
   GameObjectID dispgoid;
   //---------------------------------------------------------------------------
   Soup SkinDataSoup = Constructors.NewSoup();
   Soup ContentDataSoup = Constructors.NewSoup();
   //---------------------------------------------------------------------------
   // Container global variables - Skin Texture Replacement
   //---------------------------------------------------------------------------
   bool isAsyncTextureSearchFinnished = false;
   int skin = -1;   // ID-number of the current skin
   string skinDescription = "INITIAL SKIN-DESCRIPTION [Texture #"+skin+"]";
   Asset skins;     // Texture library asset object
   int textcount;
   //---------------------------------------------------------------------------
 };

File is located in dispatcher library.

Personal tools