Game Development Community

Can't select resources (and other problems)

by Justin Tolchin · in RTS Starter Kit · 03/10/2005 (5:28 pm) · 20 replies

Hi all,

Just a quick question about the resources in the Villager mod: do the resource .dts files need to have a collision box in them in order to be selectable? I can see the green selection circle around the built-in resources (tree, rock, gold - although only when I right-click on them), but when I try to add in my own tree.dts as a resource it stops working. :-( What controls the "selectability" of these objects?

In case it does need the collision stuff, I'm trying to get the collision bounds into our "tree.dts" file but something is messed up and now the tree won't display at all. I keep seeing the error:

Error: shape starter.RTS/data/shapes/resources/trees/tree-a.dts-collision detail 0 (Collision-0) bounds box invalid!

This is coming from line 218 in shapeBase.cc. I know it's really referring to Collision-1 (not 0), that's just a display bug in the code. For some reason the collision bounds has garbage min & max values (like -10 x 10^30 for every value) so it won't validate the box. I don't know if this is causing the tree not to display, but it can't be good.

Does anybody know why this error occurs? I'm using Max 7, and I have a simple cube for the collision mesh called Col-1 which is linked to start01, and a helper node called Collision-1 linked to base01. Is there something else that needs doing?

Thanks!

#1
03/10/2005 (5:36 pm)
Based on my very limited understanding of creating .dts shapes, I think you need a "bounds" shape to be detected by the selection code. I could very well be wrong however!

I would suggest opening up one of the pre-existing resources (or any shape that works and is simple) in Torque Show Tool Pro, and then open up your new shape, and look for differences.
#2
03/10/2005 (7:47 pm)
Do you know how to properly make a DTS shape? Read this tutorial .

I dont know if this has anything to do with your problem, but I just tried creating my first DTS building to use with RTS.SK, and 75% of it is underground!
img98.exs.cx/img98/6789/halfpyra2dj.png
#3
03/11/2005 (7:50 pm)
Justin, I know you just brought this up yesterday, but have you found anything to shed some light on your problem, because I get the same thing? In fact, I can't find any other DTS shape that works other than the three original resources. I have tried all of my own DTS shapes, and lots from TGE. Nothing is selectable, some don't even show up.

I began trying to replace the resource shapes because the rocks actually hover in the air (I discovered in TST that this has to do with the way the model was created.) So I figured, eh didn't like those rocks anyway I'll just use some rocks from my Bravetree Environment pack...but can't select them...sigh.

Just don't want this question to die, I've wracked my brain and spents hours and hours trying to figure this out.

And while we are discussing selecting resources, here are two more odd things that are happening:

1. Selection circle for the tree is huge!
2. Sometimes the resources do not show up until a couple of seconds after the mission is displayed.
#4
03/11/2005 (8:16 pm)
Ironically, I'm battling this issue again myself as I read this. Here's what I "know" (take that with a grain of salt!):

1) The location of the col-1 node is critical to proper positioning against the terrain. As far as I am aware, it is always supposed to be at the point where your shape would intersect the terrain.

2) The width of the selection circle for various objects can be defined by the datablock entry "boundingBox". Unfortunately, (and I've been working on this issue ever since we wrote the World Domination mod for the RTS-SK) if you include/adjust the values in this transformation to get a decent selection circle, you must also fudge in the Z axis parameter as a best guess of the object's bounding box Z length. It seems (and I just tested this) that if you remove the boundingBox parameter, the code falls back to the position of the col-1 node (that's a guess on my part), and if that node does not exist, then it falls back to the origin of the object when it was modelled (this last is a guess on my part, but it's what it seems to be doing).

3) If you do not include a boundingBox override in the datablock, then it uses the object's game calculated bounding box, which in the case of the tree, is big enough to "hold" all of the foilage at the top of the tree as well--causing the very large selection circle.

So it sounds to me that if you want to control the size of the selection circle directly, you need to use the boundingBox parameter in each object's datablock. Unfortunately, this means that you must manually guestimate the Z-Axis so that you get correct positioning against the terrain, and then tweak it endlessly until you are happy.

I tried several different attempts to do all this calculation via script, and I still haven't found a happy medium between the two issues. My current attempts are to use %building.getObjectBox(); and then find the Z-Axis length, divide by 2, and then place the building at that height, but it's not playing well yet. I'm probably going to break down and just do the manual guestimate/tweaking of the Z-axis height for it to work properly.

NOTE: For those that are using the World Domination mod, that's what the "Z-AxisTweak" value is for.

Something else to keep in mind: if you are placing a building on any type of sloped terrain, the stock RTS-SK only takes into account the height of the specific building anchor point--this normally causes parts of the building to be occluded by terrain. The terrain deformation resource I'm working on (which unfortunately needs an entire re-write as of this moment) is designed to fix this problem for RTS-SK folks by having your peons excavate a "flat foundation" for your buildings, so I'd suggest not worrying about the occlusion part, and focusing on the best solution for figuring out what height to place the terrain.

Second NOTE: Stock RTS-SK cheats a bit by clamping all RTS-SK buildings (including building markers) to 1.5 units above the terrain height. This really isn't a great solution, but if you are comparing code between the World Domination mod and stock, you'll see this difference.
#5
03/11/2005 (8:20 pm)
Quick follow up:

Regarding the resources that are part of the WD mod, Anthony wrote some custom code to position the resources directly above the terrain. Basically, he uses a rayCast against the terrain, and then positions the resource by manually dropping the resource from a large height (5,000!), down to the height returned by his rayCast.

Also, one of the reasons that the resources may be appearing slowly is that there are a LOT of them (they are randomly generated)--that resourceGeneration code was simply meant as a demo for a way to put resources in to play with. My suggestion would be to hand craft a mission, placing the resources where they make sense to your game, and working it from that perspective.
#6
03/11/2005 (9:02 pm)
Stephen, THANKS SO MUCH, those suggestions are right along the same lines I was pursuing. I just feel "hacky" tweaking stuff, but like you I can't find a solution that works for everything. This at least lets me know I am on the right track. Still can't figure out why no other DTS shape works for a resource... even the other tree in TGE doesn't work...hmmm.

Man you should get some sort of medal for all your work on these forums. I for one am very grateful for you taking the time to answer these questions. I know you are working on your own projects and to take out time from that work to answer our questions in such detail and with such patience is admirable. You will get a big credit when I finally finish my game.

Thanks again.
#7
03/11/2005 (9:12 pm)
Thanks by the way! A good 3/4 of my learning comes from explaining things (and of course getting corrected when I'm wrong!), so I benefit a lot myself from these discussions!

Regarding why other resources aren't working for you, here's the deal on creating new resources:

NOTE: To those coming to this thread for the first time, the following code is part of the World Domination through Collaboration Resource, which gives a basis for a lot of RTS style game actions.

1) In server/scripts/resources/resourceGeneration.cs, take a look at the datablocks at the very top of the file:

datablock StaticShapeData(Tree3){
    shapeFile = "~/data/shapes/trees/Tree3.dts";
    RTSUnitTypeName = "treeResource";
    category ="Resources";
    className = "Resource";
};

and just below those,

function Tree3::onAdd(%data, %obj)
{
//   Parent::onCreate(%data, %obj);
  %obj.resourceType = "Termite";

   //do nothing
}

The %obj.resourceType = line is what defines the shape as a harvestable resource.

If you happen to add new resource types (which I would imagine people will!) Keep in mind that you will need to add those resource types in the client side resources-client.cs:

%so = new SimObject(Termite)
  {  
  	count = 0;               // Current value  
  	min = 0;                 // Minimum allowed  
  	max = -1;                // Maximum allowed (-1 is infinite)  
  	gui = SUP_Termite_Count;                 // GuiTextCtrl to display the value in (0 = none)    
  	dangerousLow = 100;        // Resource is running very low...  
  	gettingLow = 200;         // running low..  
  	gettingHigh = -1;        // getting to much.. (-1 = can't have too high)  
  	dangerousHigh = -1;      // overdose time (-1 = can't have too high) 
  };//termite --ewww! 
  
  %resourceStore.add(%so);

as well as adding the same code block to the resources-server.cs file.

Finally, you'll need to create a new GUI control to display the resource count, as well as an icon to represent it. The "gui" line has to point to the proper GUI control name that is defined in playGui.gui.
#8
03/11/2005 (9:29 pm)
Thank you, I got that part figured out, but still good info for everybody.

My problem is just replacing the original tree3.dts with another dts shape like tree1.dts in the Tree datablock. Nothing works except tree3 or rock1, no matter what dts shape I use. By "nothing works" I mean that the shape is rendered but it is not selectable (i.e no green circle, can't send peons to harvest from it.) This is the original problem Justin was talking about. It is almost like something is hardcoded somewhere for those resources, but I haven't been able to find anything like that.

BTW what time is it where you are? It is 12:30 AM here in Atlanta. I found my second wind but really should be in bed.
#9
03/11/2005 (9:41 pm)
Hehe..11:30 here, but currently weekends are my only real Indy time :( It just so happens that this thread is exactly what I was working on, so while I had to wait for the peons to build my building foundations I could just back over here and post!

Regarding the new resource attempts: Did you have any console errors?

Also, try adding in a boundingBox line (similar to the buildings in /server/scripts/items/buildings.cs) and see if that helps to resolve your issue.
#10
03/11/2005 (10:12 pm)
Hmmm...works with a boundingbox override, but doesn't make any difference in the selection circle size. Not so worried about that one, if I have to I will hardcode the selection circle size for units, buildings, resources etc... I was thinking of going that way anyway. Thanks.
#11
03/11/2005 (11:11 pm)
What size did you make your x,y values for the bounding box override?
#12
03/12/2005 (10:07 am)
I have tried every value from .5 to 20 but it makes no difference to the selection circle size. The selection circle always defaults to the original bounding box size. I am pretty sure I am adding the boundingBox override appropriately???

datablock StaticShapeData(Tree){
    shapeFile = "~/data/shapes/trees/FTREE02.dts";
    RTSUnitTypeName = "treeResource";
    category ="Resources";
    className = "Resource";
    boundingBox = "10.0 10.0 10.0";
};

Still this is not really a problem for me; I will either change the bounding box size on the model or like I said before "hardcode" a selection circle size for specific types (units, buildings, etc...).
#13
03/12/2005 (10:57 am)
Yeah, now that I think about it, the big problem is that the boundingBox isn't actually a persistent field for StaticShapeData, so doesn't apply!

One possible solution is to make them RTSUnit's, or re-implement the boundingBox persistent field in StaticShape. I would probably suggest the first, unless you want to go whole-hog and derive another class from RTSUnit specifically for resources.
#14
03/12/2005 (11:39 am)
Funny, I was just researching the boundingBox on StaticShapes...wish I could say great minds think alike but you are miles and miles ahead of me. Now I have to figure out why the selection circle is suddenly working. I thought it was adding the bounding box override but after further testing I discovered that in actuality the original problem has simply disappeared. (Nice problem to have.)

Actually, right now I am in the middle of merging the Synapse Lighting pack into my code, but when I am done I will do some more research, maybe I can get an answer to Justin's original question.
#15
03/12/2005 (11:43 am)
@Jeff: sorry for semi-hijacking, but would you mind dropping me an email when you get a chance? You don't have a public email in your profile :(
#16
03/14/2005 (10:04 am)
Hi guys. I was sick from Friday on with the flu or I would have provided an update on this. I was able to figure out why my model wasn't displaying properly. It was because we had named the detail level "detail-1". Apparently Torque sees anything with a minus sign as a collision node, so the dts was getting exported incorrectly. The details are here:

www.garagegames.com/mg/forums/result.thread.php?qt=23128

(As an aside: I really don't understand why you have to name things as "collision-1" or "col-1" and then the exporter ignores the rest of the name anyway and just focuses on the number part! Arg!)

Unfortunately when I tried simply renaming the detail node to detail1 or detail128 or something, 3D Studio would crash whenever I exported the dts (also *very* annoying). I had our modeler take the tree model from the kit ("Treetwo12.max") and use that as the basis for our own model (in terms of the node names) and then everything exported fine. The only remaining problem was that it was very difficult to select the tree object unless I hit the exact right pixel, but once she modeled the collision mesh as two separate boxes (again, the same way the tree model in the kit does it) instead of one box it started working fine. So I'm assuming the selection of those objects is based on their collision mesh, although so much changed in the model from export to export that I couldn't swear to it.

@Stephen: I'm confused about one thing you said above. You seem to be saying the positioning of objects are related to their col-1 node. I thought objects were positioned based solely on the pivot point of their bounding box. Is that not true?

@Jeff: I remember the problem you described where the selection circle around the stock tree resource was extremely large. I'm almost positive I tried modifying the boundingBox in script for that object, but it was always the one that I couldn't seem to change no matter what values I picked. The other models had their selection circles modified fine. Never did figure that out. I haven't tried modifying that field for my new tree resource, so I'll give that a try and see what effect it has, if any, but right now the selection circle is the right size.

Also, the only other thing I needed to do to get the resources to show up was to remember to call %resource.scopeToClient(%client); on each one.
#17
03/14/2005 (12:26 pm)
@Justin: My research is all simply guessing--I haven't been able to directly prove one way or the other yet how the code actually works (collision mesh vs boundingBox datablock, etc)--it's just what I've observed through various tests. I've been able to get rts units to drop halfway into the terrain even though they had pivot points at their feet, and I fixed that by calculating the bounding box in source code and setting their z-axis height to be the terrain height + 1/2 boundingBoxLen.z. That's a hack fix however--I want to eventually know exactly the right way to do it!

I do know that you won't be able to use the boundingBox datablock parameter for resources, because resources are one of the StaticShape derived classed, while boundingBox is a persistent field in a different inheritence tree (Player I'm guessing, haven't had a chance to look). If you want to control the selection circle via boundingBox, you'll need to swap the object type for resources, or re-implement boundingBox as a persistent field for them.
#18
04/07/2005 (8:40 pm)
Er, have there been updates to the Villager mod? Because in the version I'm working with, you can't select trees and rocks simply because there isn't script to handle them...
#19
04/08/2005 (6:25 am)
In the currently released version no, you don't actually "select" them, but when you right click on them with peons selected, it issues a resource move.

Good point though, we weren't being completely accurate!
#20
01/30/2006 (7:53 am)
A bump, because I would still like to know how to select resources, to view info like how much is left in them (they show a health bar so I'm guessing I can use health). Like in Warcraft, you can see 3560/5000 for a Gold mine...

[edit] Got it.