About Store Forum Documentation Contact



Post Reply 
Game Object Types
Author Message
hawksprite Offline
Member

Post: #1
Game Object Types
I've been toying around with setting custom game object types for gathering.

So for now I have a list of:
Code:
Game::ObjMemx<<NewObj> Trees;

The trees class is the one from the tutorial file on custom classes.

Then I set it here:
Code:
Game::World.init      (                   )
              .setObjType(Players, OBJ_PLAYER)
              .setObjType(Trees, OBJ_TREE)
              .setObjType(Statics, OBJ_STATIC)
              .setObjType(ObjLightPoints, OBJ_LIGHT_POINT)
              .New       (ChrData.world()->worldDir());

But it doesn't actually seem to do anything with the list of trees. I've also tried making it just a Game::Static list but it also doesn't seem to want to work.

I should clarify i can't find them with a Physhit and there draw overrides aren't actually drawing any objects.
I should post the NewObj struct as well
Header section:
Code:
STRUCT(NewObj , Game::Obj) // extend Game Object
//{
   Vec     position; // the class will contain only position
   MeshPtr mesh    ; // and mesh
   Str gather;
   Str produce;

   // provide necessary methods required by Game::Obj :
      virtual void create(Game::ObjParams &obj); // extend default creation

      virtual Vec  pos(          ) {return position    ;} // get position
      virtual void pos(C Vec &pos) {     T.position=pos;} // set position

      virtual Str Gather() { return gather;}
      virtual void Gather(C Str &lt) { T.gather = lt; }

      virtual Str Produce(){  return produce;}
      virtual void Produce(C Str &ls) { T.produce = ls; }
      

      virtual Matrix matrix(                ) {return position           ;} // get matrix
      virtual void   matrix(C Matrix &matrix) {     T.position=matrix.pos;} // set matrix

      virtual Bool update     () {return true;} // object update
      virtual UInt drawPrepare();               // object draw prepare
      virtual void drawShadow ();               // object draw shadow


   // io methods
   virtual void save(File &f);
   virtual Bool load(File &f);

   // constructor
   NewObj();
};

cpp stuff:
Code:
NewObj::NewObj() // initialize values in constructor
{
   position.zero();
}
void NewObj::create(Game::ObjParams &obj_params)
{
   // now setup custom parameters from 'obj_params'
   position=obj_params.matrixFinal().pos; // obtain our 'position' member from 'obj_params'
   mesh    =obj_params.mesh       ()    ; // set 'mesh'

   Produce(obj_params.findParam("Produce")->asText());
   Gather(obj_params.findParam("Gather")->asText());
}
/******************************************************************************/
UInt NewObj::drawPrepare()
{
   if(mesh && Frustum(mesh->box,matrix()))mesh->draw(matrix());
   return 0; // return 0 because no additional rendering modes are required
}
void NewObj::drawShadow()
{
   if(mesh && Frustum(mesh->box, matrix()))mesh->drawShadow(matrix());
}
/******************************************************************************/
void NewObj::save(File &f)
{
   super::save(f); // default save

   f<<position;           // save custom parameters
   f.putStr(mesh.name()); // save mesh path
}
Bool NewObj::load(File &f)
{
   if(super::load(f)) // if default load was successful
   {
      f>>position;              // load custom parameters
      mesh.require(f.getStr()); // load mesh
      return true; // return success
   }
   return false; // return failure
}
(This post was last modified: 08-19-2012 07:20 PM by hawksprite.)
08-19-2012 07:13 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Game Object Types
your objects in the world editor need to be set to OBJ_TREE and have access mode to Dynamic (not grass/embed into terrain/constant)
08-19-2012 09:07 PM
Find all posts by this user Quote this message in a reply
hawksprite Offline
Member

Post: #3
RE: Game Object Types
I had them set to OBJ_TREE, i'll double check that they are also set to dynamic.
They still don't seem to want to work for me.

I can keep the trees as Static and not have issues but my problem is that I can't figure out how to get Object parameters from a Phy_hit.obj output.

Currently i'm using Phys hit to figure out what object is under the cursor then move to it when you click, what I want to do is only move to it and gather items if it's a tree. I just can't seem to pull parameters out of Phys hit.
(This post was last modified: 08-19-2012 09:28 PM by hawksprite.)
08-19-2012 09:23 PM
Find all posts by this user Quote this message in a reply
hawksprite Offline
Member

Post: #4
RE: Game Object Types
Ok I think I finally fixed my issue. Later today when I get back from class i'll post my code and what all I did for those who are having this issue or trying to learn this feature for gathering.
08-20-2012 12:14 PM
Find all posts by this user Quote this message in a reply
Post Reply