Home » MODDING HQ 1.13 » v1.13 Coding Talk » [IDEA] New Magazine System
Re: [IDEA] New Magazine System[message #335780] Sun, 14 September 2014 20:55 Go to previous messageGo to previous message
Flugente

 
Messages:3507
Registered:April 2009
Location: Germany
DepressivesBrot
Apropos concepts:
@Flugente
If you don't want to do it, would you at least be willing to write down the concepts for implementation that you indicated you had?
Well, why not... might remove a bit of confusion. Here it is:

New Magazine System Implementation concept

This concept outlines how to implement a new system that allows to load magazines with single bullets. This also allows mixing ammotypes of the same caliber (without mixing it becomes easier, but even more pointless, so I won't outline that here).
The additional concept to mix different calibers in magazines, and have guns be able to use different calibers without relying on hacky item transformation is outlined in blue.
Barely useful, annoying bullshit that complicates everything but will be asked for by people that want stuff like this is marked in red.
After a while you will have completely lost your shit and debate why you ever wanted to code this. For this purpose, anal 'realistic' 'features' that mostly serve to let the player feel how much you hate them are marked in green.

Part 1: Basic Idea

The idea is to have ammo separated from magazines.
A magazine can be stacked with ammo.
A magazine can then be inserted into a gun, where we can see it as an attachment.
There are guns that do not accept a magazine, rather the ammo is transferred to them and then stored in the gun itself (speedloaders, shotguns...) .
The gun then fires the ammo from the magazine, in the order that the ammo was inserted into the magazine.
A gun fires ammo of one caliber.
A gun fires ammo of different calibers.
A magazine has a maximum number of ammo it can hold.
Different magazines can have different maximum numbers of ammo.
Guns can use different magazines.
A magazine holds ammo of one caliber, but the ammo types (AP, HP, Glaser, Tracer...) can be different for each ammo.
A magazine can hold ammo of different calibers.
Depending on gun, magazine, tactical/strategic screen, combat/no combat, EDB interface and the cycle of the moon, removing a magazine can leave one bullet in the gun chamber,which the gun can fire..

Part 2: Magazine and ammo setup

In the current state of JA2 1.13, bullets are always in a magazine (crates and boxes are just magazines that have no fitting gun). Whenever we put a mag in a gun, we then tell the gun 'you have x bullets now'. The mazine object vanishes, but we tell the gun what mag that was. From this it knows the ammotype. When removing the mag, a new object if the same itemnumber as the old mag is created, and we insert the correct number of ammo.

We can no longer do that:
  • While the mag is 'in' the gun, we still need to differentiate between ammo in the gun itself and ammo in the mag that is in the gun.
  • Magazine modifiers (+/- reliability etc.) require knowing the status of the magazine object.
  • Magazines can have attachments, because of course they do.
We create a new structure (pseudocode):
typedef struct
{
UINT8 usAmmoType;
UINT8 usCaliber;
} MAG_BULLET;
This structure is all that is required to know of a bullet. Having each bullet as an object is a hideous idea. The memory use alone is haunting. If anybody ever advises this, shoot them in the face.

Because of bullets in the gun chamber, both guns and magazines can hold ammo. Strictly speaking, a gun is now simply a magazine that also happens to be able to fire them.
Thus we need to store ammo on objects. Thus OBJECTTYPE needs a new member:

std::vector<MAG_BULLET> internalmagazine;

Now all objects could store ammo theoretically. We can't use a fixed-size array, as this would blow up all object sizes.
As the size of internalmagazine can vary, OBJECTTYPE saving and loading gets more complicated, so expand these routines accordingly. Reserving space will be especially trickier.
Note that changes to OBJECTTYPE require altering sector loading routines. This also requires different approaches according to map version.
It is very easy to render maps unplayable this way, so be careful in repairing that. Rendering maps permanently unplayable is unacceptable, unless getting your head smashed in with an axe by a guy from Bremen counts as 'acceptable' to you big grin
Upon loading ammo into a mag, create a new MAG_BULLET from the ammo and insert it into internalmagazine.
Upon inserting ammo, check wether there is still room in the magazine, return error if not.
Upon inserting ammo, check wether the caliber fits.

Magazine items need new data:
UINT16 usCapacity; // how many bullets this magazine can store. Will be 1 for most guns.
BOOLEAN fTransparent; // some mags are see-through
std::vector<UINT8> possiblecalibers; // calibers this magazine takes
BOOLEAN fLifo; // FiFo/LiFo extracting of bullets when unloading/chambering
BOOLEAN speedloader; // if true, magazine contents are transferred to the guns internalmagazine upon loading, the magazine object is not attached

Modders will come up with guns that take one magazine, but can have other magazines attached to it. You then need to internally store which magazine is decoration and which one you use to take ammo from.
Modders will come up with guns that feed from multiple magazines at the same time, like some futuristic shotgun that everybody agrees is crap but looks cool. You then need to remove ammo from the mags in an alternating manner, storing which mag you took ammo from last.
Modders will then come up with the urgent need to have a switch on the gun that toggles which mag ammo is currently taken from. This requires altering the above variable and to create a fuckload of UI for that. Nobody will ever use this, but this will be totally necessary for someone's masturbation routine game balance.

Calibers need new data:
UINT16 usAPLoadCost; // the cost of loading a single bullet of this caliber into a magazine
UINT16 usWeight; // the weight of a single bullet in grams. Data in Items.xml is in 100g-units, so adjust internal calculations accordingly
BOOLEAN fDirectLoading; // if set to true, a gun's internalmagazine can also be loaded with bullets by directly loading them into its magazine
UINT16 usPower; // power of the caliber, will be the base of damage calculations
UINT16 usRange; // base of range calculations
UINT16 usAccuraccy; // base of accuracy calculations

Guns need new data:
std::vector<UINT16> acceptedmagazines; // which magazines fit into this gun?
UINT16 usPower; // Combined with the caliber's usPower, calculate bullet damage from this
UINT16 usRange; // Combined with the caliber's usRange, calculate bullet range from this
UINT16 usAccuraccy; // Combined with the caliber's usAccuraccy, calculate bullet accuracy from this

You thought the mag adapters were gone? Silly you big grin Modders will demand more types of adapters:
  • Mag adapters on the gun that allow access to other magazines - kinda like the current ones.
  • Mag adapters on magazines, that then allow fitting those into guns that previously did not accept them. Have fun solving that, jackass.
  • They will demand the ability to attach rubber band, and then a second magazine to that, for quicker reloads. I'm sure you can figure out this one on your own.

Part 3: Loading and firing a gun

Magazines are attachments to guns now. This means there has to be set up in the first place, via Attachments.xml, AttachmentPoints and whatnot. This also means that Old Attachment System people effectively lose one attachment slot. They will complain about that, at which point you say F*** you, this requires New Attachment System because I say so and force this system to require NAS.
Once a mag is attached to the gun, load the first bullet (according to fLifo either from start or end of magazine) into the guns' internal magazine.
Don't do that, instead have the player cycle the gun by firing (similar to shotguns) first. Pointless, so important, apparently.
Whenever you fire the gun, fire the first bullet from its internalmagazine. If it's empty, and the magazine still has bullets, load from there. Some guns, like shotguns, require a manual cycling.
When firing a bullet, check its caliber and determine damage, range and accuracy. At this point, nerds would like to add all kinds of NCTH-modifiers to this, but as the only effect to cth calculations is input data, you can easily deflect that.
Caliber calculation require to come up with the new formulas in the first place, and loads of new data on guns and calibers. Once that is done, one might be able to differentiate caliber types without editing a ton of guns though, so this might be beneficial.

Part 4: Loading a magazine

Now for the ugly parts. First, we require loose bullets. Create new items - 'a handful of bullets' - for each ammotype and caliber. These serve the same function as crates. But unlike crates, we require them to be very small, so we can store them in our inventory. This is required if you want to load different ammotypes into a mag.
When clicking with a handful on a mag, check wether the ammo would fit the mag. If so, fill up the mag with it (realtime)/ add a single bullet (turnbased), AP cost taken from Caliber data.
Loading different ammotypes works in two ways: Either click on the mag with handfuls and switch them while doing so. You will realize this sucks on your second mag, which puts you well ahead of all the tools requesting this nonsense.
What needs to be done is a interface in the magazine's description box. This interface should show you how many bullets, and of what ammotype (and caliber) are already loaded, and in which order. This has to work for magazine sizes like 200+ too, so add a scrollbar and stuff.
This also needs a huge overview over all fitting ammo in your inventory (or sector inventory). It should list these bullets, and how many there are. Clicking on this deducts one bullet and adds it to the mag. Deducting requires looping over the entire secor inventory in this case to find a bullet object to deduct from, so will be slow if you are not careful.
Of course, we will also want to just grab a bullet from anywhere in the mag and remove it. Have fun setting up that bit with miniature mouse regions and callbacks.
Or better, don't. Decline doing so because that would dilute the realistic vision behind it. This saves you work, and anyone complaining will have to admit that they don't really care about realism at all and just want shit without knowing what that entails.
You need two more buttons on the magazine interface, one for removing one bullet, and one for removing all bullets. At that point someone will want a button fro 5, 10, 3, 7 etc. bullets.
Note that magazine weight calculation now depends on the weight of the empty mag and the numbers of bullets and their individual weight, which will vary from caliber to caliber.
Setting up this interface will take a lot more time than everything else combined. Whatever you do, nobody will like how it looks. Nobody will volunteer to draw a replacement.

Clicking with the mag on the gun or the mag attachment slot will replace the magazine item. This is fairly easy. This is tedious if you take into account all that multiple-mag nonsense. Does clicking with a mag on an attached mag with several mags attached replace the whole stack, or just one mag?

Part 5: Unloading a magazine from a gun
Removing the magazine attachment removes the mag. Clicking on the bullet count does the same. This is fairly easy.
This is fairly complicated. Players want guns to have a bullet in the chamber. At the same time, they do not want bullets to remain in guns they want to have empty. The question is as to when the chambered bullet should stay, and when it should be removed and added back to the magazine. Use these rules:
  • Remove attachment: remove mag, chambered bullet stays.
  • Click on gun bullet counter: Remove mag, put mag into inventory, remove chambered bullet, put it into players hand.
  • [Shift]+[Alt]+[f]+[whatever key it is today]: Remove mag, put mag into inventory, remove chambered bullet, put it magazine.
  • [Ctrl]+[Shift]+[Alt]+[chinese symbol for 'donkey']: Remove mag, remove bullets from mag, put mag into inventory, put bullets into inventory remove chambered bullet, put it into inventory.

Part 6: What's in a mag?
As magazines now have mixed ammotypes, we have problem indicating their ammo via colour. We could just use the colour of the first bullet, but that changes when firing. Besides, we cannot look into a gun's bullet chamber, can we now?
Solution: All ammo counters are grey now. Hu. That was easy for once.
If someone complains that mags with only one ammotype loaded should logically get that colour, declare how shocked you are of this unheard of, and frankly, insulting attack on your artistric integrity. As we don't know whether there are several ammotypes inside (we do, but just because we loaded a magazine by hand doesn't mean we will remember what's inside), we have no choice but to always go for the same colour.
New problem: One could look at the magazine description box to find out what loadout you use. How unrealistic! Simply block any indication of ammotype and caliber in that huge interface you created. If players will want to know what a mag has, they have to unload the entire thing, see for themselves, and then load it again. As the ones requesting this are so interested in realism, I am confident they will embrace this mechanic.
Alternatively, use the same mechanic as for the current bullet count: have knowledge depend on wisdom and experience. Transparent mags get a bonus.

The caliber system allows loading mags with a caliber into a gun that does not accept that caliber. Feel free to add all sorts of catastrophes when one shoots a bullet in this case. Damaging the gun won't be enough, as player's will load the fastest, crappy handgun they can find (PM) with .50 BMG and exploit these powerful one-shot devices. A high chance of injury to the firer should put a stop to that.
Provided 2 calibers use the same magazine, you will no longer know which magazine was meant for which gun. Combined with the above mechanic of catasthrophic damage if the wrong caliber was loaded, and taking into account that any sort of inventory sorting will stack magazines together, different contents be damned... This leads to a scenario where firing any gun becomes russian roulette, because you cannot be sure it will have a fitting caliber loaded. Profit!

Part 7: Tend to the AI
Reloading itself shouldn't be a problem to the AI, provided you kept their functions clean. Spawning guns and mags is, however.
AI guns are required to have a magazine (otherwise combat will be kinda dumb). Adjust the object creation functions accordingly - make sure they get one!
Some mags should be standard, others are more advanced and rare to diversify things. Use the first mag a gun can have as the standard for it.
Getting the AI to use different mags requires you altering the drop tables. As there will be more than 50 mags total, increase that table or come up with something smart. Random items might work here, but will likely still have to expand the table once the mods with fucktons of items get their hands on this.
This also requires you to fill the mags with ammo after creating them, so you need to do that too.
People will ask for the AI having less magazines and loading those magazines in combat. Simple.

You also need to come up with a way to get Bobby Ray and merchants working with this. Just have them sell mags as attachments and ammo as boxes - this won't be hard.

Part 8: Filling out xmls, creating items
After setting up the xmls, you will need to fill them with reasonable data. You will also need those magazines and bullet items, including all those pictures.
Create a post where you explain all this, and give a few examples on how to do this, and ask for volunteers to help you with this. Many people will like this. One or two will volunteer, but will vanish due to real-life issues.
Fill out the data yourself, and create the pictures yourself.
In the likely case that nobody comes forward with pictures for this stupid feature they requested, use placeholder pictures, I recommend dildos and pink unicorns.
After adding this to the game, people will complain about your values obviously being off. They will offer absurd alternative values (if at all) which you won't use.
People will not like your pictures. Tell them that these are only placeholders, and you will gladly replace them if they deliver better pictures. This will never happen, and those placeholders will stay in the stock data for the next 5 years.
The only way to get good item pictures is to get a modder interested in this. He will have loads of questions. Explain all this to him. He will draw quality pictures for his mod, which you can then steal for the trunk.

Part 9: Coding
For the love of the dark gods, develop this in a separate branch. NOT in the trunk!!!
Finished features can go into the trunk if they work and are tested.
The trunk is not a code dump.

While coding, comment your code. Explain why you are doing what. Explain the idea of a code bit.
After committing, explain in the pit what this is all about!!!

Part 10: Compatibility
Make this a gamestart option. Switching between old and new system in an ongoing game requires quite a lot of conversions. Not recommended.
You read that right. You cannot remove the old system, because the huge number of people who recognize this is nonsensical shit nobody needs (you and me among them) will protest if the old stuff is removed.

[Updated on: Sat, 11 August 2018 18:15]

Report message to a moderator

Captain

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: (New) Common Attachment Framework (new title; was The NAS Receiver)
Next Topic: Path finding problems in 1.13
Goto Forum:
  


Current Time: Fri Jan 10 14:54:04 GMT+2 2025

Total time taken to generate the page: 0.06651 seconds