Picture this: You have this fancy gun. One magazine, which contains a dozen shots, costs a million. You have two. So you save the shots for when it's going to count. One day, you fire once when a chryssalid jumps at you and, upon your return to base, are told your clip with 11/12 bullets doesn't meet regulations. The quartermaster takes it back and doesn't have another to give you, so you're down to one clip. As you sadly walk away, you can hear him cackling with glee as he fires the other 11/12 shots! Same thing happens to your buddy when he goes to see the quartermaster after the mission.
That's how it was in XCom: If you had fired a shot, that clip was useless.
In OpenXCom: You're a bit more clever. First make a tally of all available shots for a clip type, divide by the number of shot per clip, and round down. So you put your bullets together and save a clip before going to see the quartermaster. It is a HUGE improvement, but it is not yet quite there. You still get short-changed on those leftover bullets that could have amounted to up to 99.999999999999999% of a clip.
So here comes my proposition:
Take those leftover bullets, divide by the number of bullets in a clip and that's your odds of getting a "free" clip. "
FREE?!" you say? well, not really, but you are getting some extra bullets for free, IF you get the clip. If you don't, then you lose all the extra bullets you had.
Take a gun with 6 shots per clip. You fire 3 shots, you have 50% chance of getting a clip back. If you do, yay!, but next time you fire 3 shots, maybe you'll lose the whole 6 shots clip. Over time, it will average to losing a clip (=6 shots) every other battle, which means 3 shots per battle. Instead of the current situation where you lose a clip every time.
This is especially visible in some mods with special weapons of which you only take a few. For example, the Fusion Torch or Heavy Machine Gun. You take one, you fire once, you lose a whole clip. Annoyingly, it makes you gun-shy. But once you fire once in the mission, since you know you'll lose the clip, you can happily fire until you run out. I decided I'd go for a more average approach.
So I went into the OpenXCom code to look at DebriefingState.cpp, and I found:
https:// calculate the clips for each type based on the recovered rounds.
for (std::map<RuleItem*, int>::const_iterator i = _rounds.begin(); i != _rounds.end(); ++i)
{
int total_clips = i->second / i->first->getClipSize();
if (total_clips > 0)
base->getItems()->addItem(i->first->getType(), total_clips);
}
This is how OpenXCom gets the total number of rounds, divides by the number of rounds per clip and it is rounded down since we are doing integer arithmetic.
I think... Then if there are clips left, they are added back to the stock at the base.
The easiest way to implement my change is simply to add 0 to clipSize-1 "free" bullets at the end of the battle. If you get enough that the total goes once more over the clip size, you get a free clip. If it wasn't enough to make a difference, you don't and you lose all the extra bullets you had. I implemented this as:
- int total_clips = i->second / i->first->getClipSize();
+ int total_clips = ( i->second + RNG::generate(0, ( i->first->getClipSize() - 1 ) ) )/ i->first->getClipSize();
So say you had a clip of 6 shots and fired 3 shots. This would add 0 to 5 "free" shots, then divide by 6. If you get 0, 1 or 2 free shots (bringing the total to 3, 4 or 5), you don't get a clip back and lose your unused shots. If you got lucky with 3-4-5 free shots (total 6-7-8), you can a clip back. So you used 50% of your shots and you have 50% chance of getting the clip back.
If you had 3 clips of six shots and fired 3 shots, then you have 15 shots left, plus 0-5 "free shots". 0-1-2 gives you 15-16-17, so you get two clips back. 3-4-5 gives you 18-19-20, so you get 3. Theoretically, it should work.
In practice? I'm not 100% sure, since I'm not 100% sure that I coded it right (it's only my second patch for OpenXCom, and second attempt at coding in c++). I ran a quick trial by assaulting a base, firing 3 shots out of a weapon with 6 shots/clip and then aborting, repeat (ie go back to base and come back, not reload, although that could have worked with save scumming turned on). It took 22 missions to lose 8 clips. The expected number would be 16 missions (lose a clip every other mission), so I was lucky? Or I was dumb and coded something wrong.. Not sure.. The sample size is a bit small, but the experiment got boring