Making a weapon's damage dependent on the presence of a QCPU
Is it possible to design a weapon that does additional damage if a quantum cpu is installed or to design a weapon that uses a different set of damage parameters if a quantum cpu is installed? Alternatively, is it possible to have any of the parameters of an installed device change depending on the presence of some other specific device on the ship, and can this be done with or without switching out the first device in the background whenever the second device is installed/uninstalled?
Cabbage Corp, the only mod with cabbages!
Please feel free to submit bug reports or issues related to the Cabbage Corp mod on the GitHub page, the forum thread, in a private message or even on the Xelerus page. Suggestions are fine too.
Please feel free to submit bug reports or issues related to the Cabbage Corp mod on the GitHub page, the forum thread, in a private message or even on the Xelerus page. Suggestions are fine too.
There are at least three ways to do this.
1) in <OnFireWeapon> check for the QCPU and fire using a higher bonus if it's present.
2) in <OnDamageArmor> and <OnDamageShield> check if the QCPU is present on the firing ship and return different damage parameters.
3) make a virual weapon. In <OnFireWeapon> check for the presence of the QCPU and fire the virtual weapon instead of the real weapon if it's present.
1) in <OnFireWeapon> check for the QCPU and fire using a higher bonus if it's present.
2) in <OnDamageArmor> and <OnDamageShield> check if the QCPU is present on the firing ship and return different damage parameters.
3) make a virual weapon. In <OnFireWeapon> check for the presence of the QCPU and fire the virtual weapon instead of the real weapon if it's present.
Literally is the new Figuratively
- AssumedPseudonym
- Fleet Officer
- Posts: 1215
- Joined: Thu Aug 29, 2013 5:18 am
- Location: On the other side of the screen.
Atarlost answered better than I could have (which stands to reason, he’s been at this longer than I have), so I’ll just leave you the links I’d looked up. This page on the wiki should be helpful for part of it, and this page over at Xelerus.de should help on most of the rest.

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)
My mods on Xelerus: Click here!
Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
Before I type anything else, I feel like I should point out that I am trying to design this weapon for the 1.3b2 version, and this theoretical weapon currently is designed to fire multiple converging shots so I am very limited when using <OnFireWeapon>. I do not believe that I can have a virtual weapon be fired in place of the original weapon without having the virtual weapon fire 4+ times which seems kind of overkill. Nevertheless, I would like to thank Atarlost for informing me of the existence of those event triggers in the first place even if I still can't get them to do anything, and AssumedPseudonym for informing me that those kinds of pages existed on the wiki and on Xelerus.
To my understanding, the itmIsInstalled function would only apply to a single specific item so while it would work for my second question it doesn't really apply for detecting QuantumCPU variants from mods and seems like a kind of compatibility issue. So I gave up on originality and decided to base my code around the code for mnemonic cubes. To my understanding the objGetItems function only returns a list or nil depending on whether or not it finds an items matching the criteria so it has to be paired with a not operator and a switch to return a function if the device is present.
The following codes should work as far as I know, but they don't. I have been testing this code with the <OnWeaponFire> section being in the <ItemType> section for the weapon. This seems logical to me but if it is wrong I would appreciate being told so.
The way I read the codes, the first one should give the weapon a 100% damage bonus if any device with the QuantumCPU attribute is currently installed and reset the weapon to a 0% damage bonus if it is fired without a device with the QuantumCPU attribute installed. My problem with this code is that it seems like it would screw up weapons that already have enhancements. On the other hand, it shouldn't cause any significant problems due to it running four times every time the weapon is fired.
The Second version should do nothing but fire the weapon normally if there is no device with the QuantumCPU installed, and if one is installed then the device should fire an additional shot of the same weapon, equating to a 100% damage bonus for each shot fired initially. My problem with this path is that my weapon has a configuration that fires four converging shots, and thus <OnFireWeapon> would run for each shot which would result in the weapon firing five times total which equates to a minimum 400% damage increase. Also, while the guide on Xelerus for sysCreateWeaponFire shows how to repeat weapon fire for standard weapons or omni weapons, I have no idea how to properly create additional weapons fire for weapons with a minFireArc and a maxFireArc.
I also spent about four hours trying to get some form of itmSetData, itmSetGlobalData, objSetItemData, typsetGlobalData, itmSetStaticData (there is an itmGetStaticData so I figure I might as well try this last one out) to work, but as far as I know these don't actually change the parameters of the item but tag a variable onto the item with a name such as "damage" that has nothing to do with the amount of damage the weapon does.
--------------------------------------------------------------------------------
<OnFireWeapon>
(switch
(not (objGetItems gsource "*I+QuantumCPU")
(shpEnhanceItem gSource gitem 0x0100)
)
(shpEnhanceItem gSource gitem 0x010A)
)
</OnFireWeapon>
--------------------------------------------------------------------------------
<OnFireWeapon>
(switch
(not (objGetItems gsource "*I+QuantumCPU"))
((sysCreateWeaponFire (itmGetType gItem) gSource aFirePos aFireAngle (typGetDataField (itmGetType gItem) 'speed) aTargetObj))
)
</OnFireWeapon>
--------------------------------------------------------------------------------
edit1: I have pretty much given up on writing the actual code myself and would gladly accept any alternative codes that would actually work to increase the damage, but at the moment what I would most prefer would be something that could temporarily change the damage value of the weapon from say "ion:2" to "ion:4;WMD1". Ideally this change would not remove or alter existing enhancements on the weapon and previously existing enhancements would still take effect when firing the weapon. Also, given that the weapon uses the lightning effect, I think that if the code could also change the intensity value of the beam to provide a visual indication of the increased damage then this whole setup would be nearly perfect. The weapon also utilizes a capacitor, so in case any of you were wondering, yes I am in fact trying to make this weapon as complicated as is humanly possible.
also edit1: Here is the code for the converging shots bit. As I said (directly) above, I am trying to make this weapon ridiculously complicated. This weapon is set up so that it tracks the target if it is within a firing arc in front of the ship. To reach my goal of complication I was wondering if it would be possible to make each shot from the weapon be fired directly at the current target instead of just firing parallel to each other in the direction of the target or firing such that they always converge at the same distance, in the direction of the target (as they currently do). I believe that I could accomplish this using two dual-fire weapons on both sides of the ship with linked fire but that would leave the inventory more cluttered and each weapon would only be half as impressive.
<Configuration aimTolerance="0">
<Shot posAngle="42" posRadius="30" angle="-1"/>
<Shot posAngle="-42" posRadius="30" angle="1"/>
<Shot posAngle="38" posRadius="30" angle="-1"/>
<Shot posAngle="-38" posRadius="30" angle="1"/>
</Configuration>
(The weapon is intended for a large ship)
To my understanding, the itmIsInstalled function would only apply to a single specific item so while it would work for my second question it doesn't really apply for detecting QuantumCPU variants from mods and seems like a kind of compatibility issue. So I gave up on originality and decided to base my code around the code for mnemonic cubes. To my understanding the objGetItems function only returns a list or nil depending on whether or not it finds an items matching the criteria so it has to be paired with a not operator and a switch to return a function if the device is present.
The following codes should work as far as I know, but they don't. I have been testing this code with the <OnWeaponFire> section being in the <ItemType> section for the weapon. This seems logical to me but if it is wrong I would appreciate being told so.
The way I read the codes, the first one should give the weapon a 100% damage bonus if any device with the QuantumCPU attribute is currently installed and reset the weapon to a 0% damage bonus if it is fired without a device with the QuantumCPU attribute installed. My problem with this code is that it seems like it would screw up weapons that already have enhancements. On the other hand, it shouldn't cause any significant problems due to it running four times every time the weapon is fired.
The Second version should do nothing but fire the weapon normally if there is no device with the QuantumCPU installed, and if one is installed then the device should fire an additional shot of the same weapon, equating to a 100% damage bonus for each shot fired initially. My problem with this path is that my weapon has a configuration that fires four converging shots, and thus <OnFireWeapon> would run for each shot which would result in the weapon firing five times total which equates to a minimum 400% damage increase. Also, while the guide on Xelerus for sysCreateWeaponFire shows how to repeat weapon fire for standard weapons or omni weapons, I have no idea how to properly create additional weapons fire for weapons with a minFireArc and a maxFireArc.
I also spent about four hours trying to get some form of itmSetData, itmSetGlobalData, objSetItemData, typsetGlobalData, itmSetStaticData (there is an itmGetStaticData so I figure I might as well try this last one out) to work, but as far as I know these don't actually change the parameters of the item but tag a variable onto the item with a name such as "damage" that has nothing to do with the amount of damage the weapon does.
--------------------------------------------------------------------------------
<OnFireWeapon>
(switch
(not (objGetItems gsource "*I+QuantumCPU")
(shpEnhanceItem gSource gitem 0x0100)
)
(shpEnhanceItem gSource gitem 0x010A)
)
</OnFireWeapon>
--------------------------------------------------------------------------------
<OnFireWeapon>
(switch
(not (objGetItems gsource "*I+QuantumCPU"))
((sysCreateWeaponFire (itmGetType gItem) gSource aFirePos aFireAngle (typGetDataField (itmGetType gItem) 'speed) aTargetObj))
)
</OnFireWeapon>
--------------------------------------------------------------------------------
edit1: I have pretty much given up on writing the actual code myself and would gladly accept any alternative codes that would actually work to increase the damage, but at the moment what I would most prefer would be something that could temporarily change the damage value of the weapon from say "ion:2" to "ion:4;WMD1". Ideally this change would not remove or alter existing enhancements on the weapon and previously existing enhancements would still take effect when firing the weapon. Also, given that the weapon uses the lightning effect, I think that if the code could also change the intensity value of the beam to provide a visual indication of the increased damage then this whole setup would be nearly perfect. The weapon also utilizes a capacitor, so in case any of you were wondering, yes I am in fact trying to make this weapon as complicated as is humanly possible.
also edit1: Here is the code for the converging shots bit. As I said (directly) above, I am trying to make this weapon ridiculously complicated. This weapon is set up so that it tracks the target if it is within a firing arc in front of the ship. To reach my goal of complication I was wondering if it would be possible to make each shot from the weapon be fired directly at the current target instead of just firing parallel to each other in the direction of the target or firing such that they always converge at the same distance, in the direction of the target (as they currently do). I believe that I could accomplish this using two dual-fire weapons on both sides of the ship with linked fire but that would leave the inventory more cluttered and each weapon would only be half as impressive.
<Configuration aimTolerance="0">
<Shot posAngle="42" posRadius="30" angle="-1"/>
<Shot posAngle="-42" posRadius="30" angle="1"/>
<Shot posAngle="38" posRadius="30" angle="-1"/>
<Shot posAngle="-38" posRadius="30" angle="1"/>
</Configuration>
(The weapon is intended for a large ship)
Cabbage Corp, the only mod with cabbages!
Please feel free to submit bug reports or issues related to the Cabbage Corp mod on the GitHub page, the forum thread, in a private message or even on the Xelerus page. Suggestions are fine too.
Please feel free to submit bug reports or issues related to the Cabbage Corp mod on the GitHub page, the forum thread, in a private message or even on the Xelerus page. Suggestions are fine too.
What you're doing is adding a permanent enhancement.
If you want to do double damage it's easy.
<onfireweapon>
(objincvel (sysCreateWeaponFire aWeaponType gSource aFirePos aFireAngle (typGetDataField aWeaponType 'speed) objTarget nil (subtract (multiply 2 (add 100 aWeaponBonus)) 100)) (objgetvel gsource))
</onfireweapon>
This will be called for every shot in your configuration with aFirePos and aFireAngle offset from the ship in accordance with the configuration and syscreateweaponfire always creates one shot without regard for the configuration so it can be used this way.
If you're using a particles weapon rather than a beam or missile it's harder because there's no shot object. There is, however, a library on the multiverse that solves this problem.
<Library unid="0xA0070010"/>
<onfireweapon>
(objincvel (sysCreateWeaponFire aWeaponType gSource aFirePos (AU_calcFireAngle gSource (typGetDataField aWeaponType 'speed)) (AU_calcFireSpeed gSource (typGetDataField aWeaponType 'speed)) objTarget nil (subtract (multiply 2 (add 100 aWeaponBonus)) 100)) (objgetvel gsource))
</onfireweapon>
The particle clouds will be askew compared to how they would lay they would normally, but this is the best workaround possible at present.
If you want to do double damage it's easy.
<onfireweapon>
(objincvel (sysCreateWeaponFire aWeaponType gSource aFirePos aFireAngle (typGetDataField aWeaponType 'speed) objTarget nil (subtract (multiply 2 (add 100 aWeaponBonus)) 100)) (objgetvel gsource))
</onfireweapon>
This will be called for every shot in your configuration with aFirePos and aFireAngle offset from the ship in accordance with the configuration and syscreateweaponfire always creates one shot without regard for the configuration so it can be used this way.
If you're using a particles weapon rather than a beam or missile it's harder because there's no shot object. There is, however, a library on the multiverse that solves this problem.
<Library unid="0xA0070010"/>
<onfireweapon>
(objincvel (sysCreateWeaponFire aWeaponType gSource aFirePos (AU_calcFireAngle gSource (typGetDataField aWeaponType 'speed)) (AU_calcFireSpeed gSource (typGetDataField aWeaponType 'speed)) objTarget nil (subtract (multiply 2 (add 100 aWeaponBonus)) 100)) (objgetvel gsource))
</onfireweapon>
The particle clouds will be askew compared to how they would lay they would normally, but this is the best workaround possible at present.
Literally is the new Figuratively
A weapon that:
1) Detects installed Quantum CPUs and adjusts damage and effect
2) Has a capacitor
3) Omnidirectional
4) Multiple shot configuration
Can easily be made with Omni+, which should be available at Xelerus
Get started with the XML, I'll post a reference <OnFireWeapon> event implementation later.
1) Detects installed Quantum CPUs and adjusts damage and effect
2) Has a capacitor
3) Omnidirectional
4) Multiple shot configuration
Can easily be made with Omni+, which should be available at Xelerus
Get started with the XML, I'll post a reference <OnFireWeapon> event implementation later.
Fiction is reality, simplified for mass consumption.
PGP: 0x940707ED, 5DB8 4CB4 1EF5 E987 18A0 CD99 3554 3C13 9407 07ED
Bitcoin: 1LLDr7pnZDjXVT5mMDrkqRKkAPByPCQiXQ
PGP: 0x940707ED, 5DB8 4CB4 1EF5 E987 18A0 CD99 3554 3C13 9407 07ED
Bitcoin: 1LLDr7pnZDjXVT5mMDrkqRKkAPByPCQiXQ
If you want your configuration fixed (ie. the angles track the target but the fire positions don't) there's a library for that.
<Library unid="0xA0070010"/>
With a configuration and no arc (put aimtolerance in the configuration) this will produce shots that converge on the nearest foe in the arc or fire straight. Each shots seeking arc is taken from the configuration, as is its default fire angle.
<Library unid="0xA0070010"/>
Code: Select all
<OnFireWeapon>
(block (newFireAngle defaultTarget shot range arc)
; the fire arc of the weapon
(setq arc 15)
; the fire arc of the weapon
(setq range 60)
(setq defaultTarget aTargetObj)
(setq aTargetObj nil)
(AU_FireConfirm (cat "sTAEN:" range) arc)
(if (not aTargetObj) (setq aTargetObj defaultTarget))
(setq newFireAngle (if aTargetObj
(sysCalcFireSolution (sysvectorsubtract (objGetPos aTargetObj) aFirePos) (sysvectorsubtract (objGetVel aTargetObj) (objGetVel gSource)) (typGetDataField aWeaponType "speed"))
aFireAngle
)) (if (geq (AU_AngleMargin newFireAngle aFireAngle) arc) (setq newFireAngle aFireAngle))
(setq shot (sysCreateWeaponFire aWeaponType gSource aFirePos newFireAngle (typGetDataField aWeaponType "speed") aTargetObj nil aWeaponBonus))
(objincvel shot (objgetvel gsource))
"true"
)
</OnFireWeapon>
Literally is the new Figuratively