Firing more than 2 images
by Amr Bekhit · in Torque Game Engine · 03/08/2007 (4:54 am) · 12 replies
Hello all,
I currently need to fire multiple weapons at once. In my previous tests, I've used 2 weapons, and this has been solved by incrementing mvTriggerCount0 for the first weapon and mvTriggerCount1 for the second. However, I am now using 6 weapons and incrementing mvTriggerCount2-5 has had no effect on the extra weapons.
I have come to understand that mvTriggerCount2-5 are used for other purposes and that only mvTriggerCount0-1 are used for firing ShapeBaseImages mounted in slots 0 and 1.
For information sake, what are mvTriggerCount2-5 assigned to? Also, how can I add more mvTriggerCount variables to trigger weapon firing in slots 2-5?
Thanks
--Amr
I currently need to fire multiple weapons at once. In my previous tests, I've used 2 weapons, and this has been solved by incrementing mvTriggerCount0 for the first weapon and mvTriggerCount1 for the second. However, I am now using 6 weapons and incrementing mvTriggerCount2-5 has had no effect on the extra weapons.
I have come to understand that mvTriggerCount2-5 are used for other purposes and that only mvTriggerCount0-1 are used for firing ShapeBaseImages mounted in slots 0 and 1.
For information sake, what are mvTriggerCount2-5 assigned to? Also, how can I add more mvTriggerCount variables to trigger weapon firing in slots 2-5?
Thanks
--Amr
#2
Just wondering: In what kind of situtation or game do you want to fire 6 weapons simultanesly?
03/08/2007 (5:29 am)
@Amr: The triggers 2-5 are initially not "used" or code-wise updated if I remember right off-head. You need to look how the first triggers are handled and then to the same for the orther triggers (requires engine changes I guess).Just wondering: In what kind of situtation or game do you want to fire 6 weapons simultanesly?
#3
What I'm aiming for is a ship with 6 cannons, 3 on each side. The player would use the mouse buttons to fire all the cannons on one side. The reason why I haven't implemented all the cannons as a single object is because the cannons are bought and added to the ship one by one, so I needed them as seperate objects.
@Martin: Hmm, I don't think triggers 2-5 are unused as vehicles use mvTriggerCount3 for jetting.
I found this forum thread which goes into some detail about the C++ side of triggers. From what I understood from that thread, I made the following changes to the source code:
In player.cc, in Player::updateMove, I added the following at the start of the function
Unfortunately, this causes the executable to crash when you start a mission.
Any pointers on this?
--Amr
03/08/2007 (6:34 am)
Thanks for the replies.What I'm aiming for is a ship with 6 cannons, 3 on each side. The player would use the mouse buttons to fire all the cannons on one side. The reason why I haven't implemented all the cannons as a single object is because the cannons are bought and added to the ship one by one, so I needed them as seperate objects.
@Martin: Hmm, I don't think triggers 2-5 are unused as vehicles use mvTriggerCount3 for jetting.
I found this forum thread which goes into some detail about the C++ side of triggers. From what I understood from that thread, I made the following changes to the source code:
In player.cc, in Player::updateMove, I added the following at the start of the function
// Trigger images
if (mDamageState == Enabled) {
setImageTriggerState(0,move->trigger[0]);
setImageTriggerState(1,move->trigger[1]);
setImageTriggerState(2,move->trigger[2]); //My additions
setImageTriggerState(3,move->trigger[3]); //My additions
setImageTriggerState(4,move->trigger[4]); //My additions
setImageTriggerState(5,move->trigger[5]); //My additions
}Unfortunately, this causes the executable to crash when you start a mission.
Any pointers on this?
--Amr
#4
Hmm, guess what, I would do it different. I think I would create 6 mountpoints for each weapon, mount to the left and right side each the 3 weapons, but have all 6 weapons maybe only one weapon image. Then, in the onFire for the weapon, cycle through each mountpoint and spawn one projectile from the mointpoint. In this way you would not need so many triggers. Might work, it's just off-head without checking it in deep. But might be an idea.
03/08/2007 (6:46 am)
Ah ok, usual players have only 2 triggers - flying vehicles tend to have 3, right.Hmm, guess what, I would do it different. I think I would create 6 mountpoints for each weapon, mount to the left and right side each the 3 weapons, but have all 6 weapons maybe only one weapon image. Then, in the onFire for the weapon, cycle through each mountpoint and spawn one projectile from the mointpoint. In this way you would not need so many triggers. Might work, it's just off-head without checking it in deep. But might be an idea.
#5
03/08/2007 (7:27 am)
Trigger 2 is usually used for jumping. You can use as many as 6, defined in moveManager.h.
#6
Thanks
--Amr
03/08/2007 (7:33 am)
I couldn't find a moveManager.cpp, only a moveManager.h (using TGE 1.5) where I could change the maximum number of triggers. Were can I change their function?Thanks
--Amr
#7
Lets say that in the boat's onFire() you call a function to fire the 6 cannon images?
Psudo code:
function Boat::onFire(%this, %obj, %slot)
{
%obj.mountedCannon1.onFire();
%obj.mountedCannon2.onFire();
%obj.mountedCannon3.onFire();
%obj.mountedCannon4.onFire();
%obj.mountedCannon5.onFire();
%obj.mountedCannon6.onFire();
}
Or something. I just woke up, so :)
03/08/2007 (8:09 am)
I have not tested this, but it might work.Lets say that in the boat's onFire() you call a function to fire the 6 cannon images?
Psudo code:
function Boat::onFire(%this, %obj, %slot)
{
%obj.mountedCannon1.onFire();
%obj.mountedCannon2.onFire();
%obj.mountedCannon3.onFire();
%obj.mountedCannon4.onFire();
%obj.mountedCannon5.onFire();
%obj.mountedCannon6.onFire();
}
Or something. I just woke up, so :)
#8
03/08/2007 (11:13 am)
Corrected the typo, thanks.
#9
I'll have a look at the alternative methods suggested, but if anyone has any info on adding extra triggers, I'd be very willing to hear about it.
--Amr
03/09/2007 (6:06 am)
Thanks for the replies guys.I'll have a look at the alternative methods suggested, but if anyone has any info on adding extra triggers, I'd be very willing to hear about it.
--Amr
#10
Thanks
--Amr
03/11/2007 (11:48 am)
Hoi just wanted to bump this. Any pointers as to how to add and assign new triggers to firing shapeBaseImages?Thanks
--Amr
#11
Well, I sat down this morning and said I'd have a crack at this and thankfully, I've had success. The process involves the following:
1-If necessary, increase the maximum number of StaticShapeImages that can be mounted on a ShapeBase object.
2-If necessary, increase the maximum number of triggers.
3-Attach the triggers to ShapeBaseImage slots in the objects updateMove function.
1-Increasing the maximum number of StaticShapeImages that can be mounted is done by modifying the following in shapeBase.h on line 560:
2-In stock TGE there are 6 triggers defined. Triggers 0 and 1 are used to trigger the images mounted in slots 0 and 1 respectively. Trigger 2 is used to jump (player objects) and trigger 3 is used for jetting (vehicles). I think the rest of the triggers are unused, but I'm not sure. In any case, it's not hard to add more than 6 triggers. Simply modify the following at the top of moveManager.h, line 10:
3-The last step is to attach the triggers to firing ShapeBaseImage slots. This is done in the updateMove function of an object (players, vehicles etc). For example, this is what I did in player.cc at the start of the updateMove function:
--Amr
03/20/2007 (4:26 am)
Hello all!Well, I sat down this morning and said I'd have a crack at this and thankfully, I've had success. The process involves the following:
1-If necessary, increase the maximum number of StaticShapeImages that can be mounted on a ShapeBase object.
2-If necessary, increase the maximum number of triggers.
3-Attach the triggers to ShapeBaseImage slots in the objects updateMove function.
1-Increasing the maximum number of StaticShapeImages that can be mounted is done by modifying the following in shapeBase.h on line 560:
public:
enum PublicConstants {
ThreadSequenceBits = 6,
MaxSequenceIndex = (1 << ThreadSequenceBits) - 1,
EnergyLevelBits = 5,
DamageLevelBits = 6,
DamageStateBits = 2,
// The thread and image limits should not be changed without
// also changing the ShapeBaseMasks enum values declared
// further down.
MaxSoundThreads = 4, ///< Should be a power of 2
MaxScriptThreads = 4, ///< Should be a power of 2
[b]MaxMountedImages = 6 //<--Modify this to change the max number of Images[/b]2-In stock TGE there are 6 triggers defined. Triggers 0 and 1 are used to trigger the images mounted in slots 0 and 1 respectively. Trigger 2 is used to jump (player objects) and trigger 3 is used for jetting (vehicles). I think the rest of the triggers are unused, but I'm not sure. In any case, it's not hard to add more than 6 triggers. Simply modify the following at the top of moveManager.h, line 10:
enum MoveConstants {
[b]MaxTriggerKeys = 10, //Declare the triggers you want here[/b]
MaxMoveQueueSize = 45,
};3-The last step is to attach the triggers to firing ShapeBaseImage slots. This is done in the updateMove function of an object (players, vehicles etc). For example, this is what I did in player.cc at the start of the updateMove function:
void Player::updateMove(const Move* move)
{
delta.move = *move;
// Trigger images
if (mDamageState == Enabled) {
setImageTriggerState(0,move->trigger[0]);
setImageTriggerState(1,move->trigger[1]);
[b]setImageTriggerState(2,move->trigger[6]); //mvTriggerCount6 now triggers the weapon in slot 2
setImageTriggerState(3,move->trigger[7]); //mvTriggerCount7 now triggers the weapon in slot 3, etc
setImageTriggerState(4,move->trigger[8]);
setImageTriggerState(5,move->trigger[9]);[/b]
}--Amr
#12
Rather than 6 triggers, I'd make 1 trigger and a "weapon selector" via scripting. If you want to "chain fire" all 6 weapons, you could increment $weapon_selection by one for each round fired. Your onFire scripts could then determine which image should be producing the projectile.
If you're looking for individual fire buttons, $weapon_selection could be made via the "1" thru "6" keys, updating $weapon_selection accordingly. Then all you need is 1 trigger w/ 6 weapon selection keys, keeping "traditional" FPS weapon selection behavior. You could even add a call to the onFire method during the weapon selection function to eliminate the need to select AND pulling the trigger (one keypress instead of a keypress and a trigger press).
To quote a MechWarrior term, if you want to "alpha strike" (all weapons at once), you could set a $weapon_selection = 7 that is interpreted by onFire accordingly.
Furthermore, this method allows for custom weapon groupings that follow the same scripting paradigm, whereas should you decide to implement such a feature later on, it would be more laborious given the method you've chosen to employ.
Just my .02
03/27/2007 (4:39 pm)
It seems you have this resolved and I don't know the design of your game, but engine modifications just seem like the wrong way to go. You may have to make engine modifications to allow for extra mounted images, but that's about it. The rest can be handled 100% via scripting.Rather than 6 triggers, I'd make 1 trigger and a "weapon selector" via scripting. If you want to "chain fire" all 6 weapons, you could increment $weapon_selection by one for each round fired. Your onFire scripts could then determine which image should be producing the projectile.
If you're looking for individual fire buttons, $weapon_selection could be made via the "1" thru "6" keys, updating $weapon_selection accordingly. Then all you need is 1 trigger w/ 6 weapon selection keys, keeping "traditional" FPS weapon selection behavior. You could even add a call to the onFire method during the weapon selection function to eliminate the need to select AND pulling the trigger (one keypress instead of a keypress and a trigger press).
To quote a MechWarrior term, if you want to "alpha strike" (all weapons at once), you could set a $weapon_selection = 7 that is interpreted by onFire accordingly.
Furthermore, this method allows for custom weapon groupings that follow the same scripting paradigm, whereas should you decide to implement such a feature later on, it would be more laborious given the method you've chosen to employ.
Just my .02
Torque Owner Surge
MDNAMEDIA
If so could they all just run off the same trigger?