I've answered this on discord but I'll answer this here as well for posterity - you can achieve this using a WeaponOPCostModifier listener that gets attached to the ship's variant through a hullmod.
thoguh it can't do this specific thing (setting the OP cost of a weapon based on the mount it's being put in), it can do basically anything else.
Yep. Thank you for the answers!
Just one more note here: the HullModEffect.affectsOPCosts() method should also return true for this kind of hullmod - this is a critical step for OP-affecting hullmods and is very easy to forget.
Any way to spawn a ship wing with a source-ship set? im having a shipsystem that spawns a clone of a deployed fighter, using "Global.getCombatEngine().getFleetManager(owner).spawnFleetMember(member, location, facing, 0f)" to spawn the wing in. However this wing has no sourceShip, and some mods have weapons or hullmods that asume their fighter to always have one and will get a Nullpointer. This Nullpointer happens as soon as the line is called, so while the API does not even have a method to set a wings sourceShip, i couldnt set it even if there was. Any way to go around this issue?
Ah, I see why there's no setter - that's just a convenience method to get the ship for the wing's source fighter bay. Let me add FighterWingAPI.setSourceBay().
As to working around this, hmm. I don't think so. This would require a new method to pass in a source fighter bay, I think. I realize this is not a helpful answer but I'm inclined to say this is just a straight-up bug in the mods that do this, even if it's one that doesn't manifest too often.
Ugh. The code path from the spawnFleetMember call to where the wing is actually spawned is annoyingly long, too, so passing in any sort of parameter would probably be some sort of "pass it into the initial method, set in a static variable, use it, and unset it" hack. Digging into this, it's actually not super clear exactly how to do this; I'd have to really test it out to make sure I didn't break something. The only reason these kinds of weapons/hullmods work is that vanilla happens to "deploy" a fighter wing with no members, set its source bay afterwards, and then start deploying members from the bay one at a time. This is such an implementation detail; it could totally create the fighters before deployign them and then set the wing's source.