Game Development Community

dev|Pro Game Development Curriculum

MountImage with mount point.

by Xavier "eXoDuS" Amado · 05/17/2004 (1:08 pm) · 13 comments

Download Code File

So what this does really is add a mountPoint parameter to the MountedImage structure, and also add it to be transmitted over the network in the ShapeBase class. If you specify a mountpoint along with mountImage like this:
// mountImage(imageData, imageSlot, mountPoint);
%obj.mountImage(CrossbowImage, 0, 0);
The code will take that mount point and mount the image there, if none is specified then it will look for the mountPoint value in the datablock (previous default behaviour). So you get the best of both worlds, you can use the same mountPoint without having to specify it or you can go fancy and override the default.
You can also keep the default value to use in most cases and override it in others using the third parameter in the command.
If you use more arguments in the mountImage call (it takes 7) and you want to still use the datablock value then you can simply pass -1 as the mountPoint, which will effectively make the code to look it up in the datablock instead.

I hope you find it useful, I don't really need this but a friend on IRC was having trouble with slots (got 'em confused with mount points) and I started giving him tips on how to change the code so he could use his weapons on several parts of this ship, and I ended doing this small patch.

NOTE: The patch will also modify the starter.fps scripts in game.cs and weapon.cs to use mountImage with a specified mountPoint which is set to 0 by default.

Have Fun!

Regards,
Xavier.

#1
05/18/2004 (1:12 am)
Thanx a lot! This should go into head, if you ask me :D
#2
05/19/2004 (3:07 pm)
This could be usefull for say... locking missiles or something. At least, I think it could.
#3
05/19/2004 (3:12 pm)
@Burning: You are welcome :)

@Jonathan: Not sure why, but I think it's useful when you need the same weapon on different places, like a dual cannon on a ship, instead of having to mount several images, you mount a single one.
#4
05/27/2004 (10:27 am)
Forgive my ignorance, is imageslot like an alternative for itemslot, and does this affect or require any changing to the datablocks used for weapons to reflect the same imageslot number as the itemslot?

Actually, nevermind, I'm thiking of something else...don't mind me :D
#5
09/07/2005 (12:06 pm)
There seems to be a bug in your code (btw, I don't have the "patch" utility so I made the changes by hand). In the "mountImage" console method you set the "mount" field as an S32 and it defaults to -1 if no mount point is not passed in. But when you pass it to the ShapeBase::mountImage method, the "mount" parameter is specified as a U32 so it can't be -1 (it becomes a very large integer instead). Then you do a comparison against -1 which will always fail.
#6
11/10/2005 (11:19 pm)
I applied this code, but I cannot fire from the muzzlePoint of the weapon. It keeps firing from some where inside the object (aiplayer) that hosts the mountPoints with the mounted images each on their own slot.

How do I fire from the gun and not some location on the host shape?

Thanks,
Frank
#7
11/11/2005 (3:07 pm)
@Justin: It could be, I haven't checked this code in ages :)

@Frank: Are you sure your weapon .dts has the muzzlePoint node and it's being exported (not dumped by the exporter for not being in the .cfg file) ?
#8
08/29/2006 (4:05 pm)
Has anyone gotten this to work in 1.4? If so would you mind sharing?
#9
09/02/2006 (1:28 pm)
It's working for me, although I manually applied the patch.

The main gotcha here is that you can only have one mounted image per image slot. The following code correctly mounts two different machine guns onto two different mount points.

function DefaultGunship::onAdd(%this,%obj)
{
   %obj.mountImage(MachineGunImage, 0, 0);
   %obj.mountImage(MachineGunImage, 1, 1);
}


Whereas this scriptlette doesn't work... it mounts a machine gun on the first image slot and first weapon slot, but then mounts another machine gun in the first image slot and the second image slot... the result is a single machine gun mounted on the second weapon slot.
function DefaultGunship::onAdd(%this,%obj)
{
   %obj.mountImage(MachineGunImage, 0, 0);
   %obj.mountImage(MachineGunImage, 0, 1);
}
#10
08/24/2007 (12:39 pm)
I've implemented this resource in TGEA and works fine but this change cannot be applied. Maybe someone can explain what happened...

--- engine/game/shapeImage.cc	2004/04/21 04:27:31	2.1
+++ engine/game/shapeImage.cc	2004/05/12 06:52:33
@@ -1869,10 +1873,11 @@
    for (S32 i = 0; i < MaxMountedImages; i++)
    {       
       ShapeBaseImageData* imageData = mMountedImageList[i].dataBlock;
+      MountedImage *image = &mMountedImageList[i];
 
       if (imageData != NULL && imageData->lightType != ShapeBaseImageData::NoLight)
       {
-         getRenderMountTransform(imageData->mountPoint,&posMat);
+         getRenderMountTransform(image->mountPoint,&posMat);
          mMountedImageList[i].registerImageLights(lightManager, lightingScene, posMat.getPosition(), mLightTime);
       }
    }

Luck!
Guimo

EDIT:I found a problem with getMountedImage after implementing this resource in TGEA.
EDIT2:It was an error with my script. This resource works fine with TGEA except the change mentioned above.
#11
09/21/2008 (1:07 pm)
This one really needs to go into Head, or at least into TGEA by default. The current system is really limiting. Thanks for this one!
#12
01/14/2009 (2:41 pm)
ummm....this link is broken now?
#13
01/27/2011 (10:57 am)
Need the Download Code File. Or the changes needed to implement this.

Thank you!