I am creating a string of fences of which there are 3 styles. I create and place the 3 versions then run a loop randomly picking a style and placing it. From the documentation, dbInstanceObject was the way to go
When I run the code with dbCloneObject it works fine. When I use dbInstanceObject, I only get my 3 original fence pieces.
Any ideas ?
I am posting the code but it is probably pretty useless without the models (they are from fpsc model pack 11). MakeObject() is my own function that returns a unique object number.
#define FENCE_CORNER 30
#define FENCE_SCALE 0.5
#define FENCE_DELTA 0.75
#define FENCE_GROUND 0.1
void MakeFences(void)
{
int fence[3];
int texture, tempfence, whatfence;
float fp;
fence[0] = MakeObject("fence", COW_PATROL);
dbLoadObject("scenery\\Fence3_a.x", fence[0]);
texture = MakeObject("fence texture", COW_PATROL);
dbLoadImage("scenery\\fe3tex.jpg",texture);
dbTextureObject(fence[0],texture);
dbPositionObject(fence[0], -1*FENCE_CORNER, FENCE_GROUND, FENCE_CORNER);
dbScaleObject(fence[0],FENCE_SCALE,FENCE_SCALE,FENCE_SCALE);
dbSetObjectCollisionOn ( fence[0] ) ;
fence[1] = MakeObject("fence", COW_PATROL);
dbLoadObject("scenery\\Fence3_b.x", fence[1]);
dbTextureObject(fence[1],texture);
dbPositionObject(fence[1], -1*FENCE_CORNER + FENCE_DELTA, FENCE_GROUND, FENCE_CORNER);
dbScaleObject(fence[1],FENCE_SCALE,FENCE_SCALE,FENCE_SCALE);
dbSetObjectCollisionOn ( fence[1] ) ;
fence[2] = MakeObject("fence", COW_PATROL);
dbLoadObject("scenery\\Fence3_c.x", fence[2]);
dbTextureObject(fence[2],texture);
dbPositionObject(fence[2], -1*FENCE_CORNER + 2*FENCE_DELTA, FENCE_GROUND, FENCE_CORNER);
dbScaleObject(fence[2],FENCE_SCALE,FENCE_SCALE,FENCE_SCALE);
dbSetObjectCollisionOn ( fence[2] ) ;
// backfence
for( fp = -1*FENCE_CORNER + 3*FENCE_DELTA; fp < FENCE_CORNER; fp += FENCE_DELTA)
{
whatfence = (dbRND(100) % 3);
tempfence = MakeObject("fence", COW_PATROL);
dbCloneObject(tempfence, fence[whatfence]);
dbPositionObject(tempfence, fp, FENCE_GROUND, FENCE_CORNER);
}
return;
}