Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Reaction Templates  (Read 806 times)

EmeraldWind

  • Bay Watcher
  • Hey there, dollface...
    • View Profile
Reaction Templates
« on: September 16, 2011, 05:09:51 pm »

I was thinking of an idea.

I thought it would be neat to mod in a workshop that acted like a smelter, but instead of using a fuel (like magma or coke) it would use power. The idea was it used two grindstones to heat up a boulder into magma and use that to smelt. It would require Power and an extra stone, but gives a slightly different way of smelting.

This idea is actually pretty simple to implement (the stone turning to magma wouldn't actually happen in-game, but is simply the theory behind the thing), except when it comes to the reactions. I would need to copy and paste every single reaction and edit them to work with my new smelter.

I would need to make this:
Code: [Select]
[REACTION:BRASS_MAKING]
[NAME:make brass bars (use ore)]
[BUILDING:SMELTER:NONE]
[REAGENT:A:1:METAL_ORE:ZINC]
[REAGENT:B:1:METAL_ORE:COPPER]
[PRODUCT:100:2:BAR:NO_SUBTYPE:METAL:BRASS][PRODUCT_DIMENSION:150]
[FUEL]
[SKILL:SMELT]
Into this:
Code: [Select]
[REACTION:BRASS_MAKING_GRIND]
[NAME:make brass bars (use ore)]
[BUILDING:GRIND_SMELTER:NONE]
[REAGENT:A:1:METAL_ORE:ZINC]
[REAGENT:B:1:METAL_ORE:COPPER]
[REAGENT:F:1:BOULDER:NO_SUBTYPE:INORGANIC]
[PRODUCT:100:2:BAR:NO_SUBTYPE:METAL:BRASS][PRODUCT_DIMENSION:150]
[SKILL:SMELT]

Now what if, I could simplify this a bit. Now notice these two key points:
First: All the regular smelter reactions share certain lines of info. All my reactions share certain lines of info.
Second: All my reactions are nearly identical to the original smelter reactions except for the lines that the first point mentions.

What I propose is a template system similar to what is used for other objects. If you separate, all the lines that stay the same between the two reactions, but differ between similar reactions I get:
Code: [Select]
[REACTION:BRASS_MAKING]
[NAME:make brass bars (use ore)]
[REAGENT:A:1:METAL_ORE:ZINC]
[REAGENT:B:1:METAL_ORE:COPPER]
[PRODUCT:100:2:BAR:NO_SUBTYPE:METAL:BRASS][PRODUCT_DIMENSION:150]
So I end up with just the formula minus some components. Now I take the parts that differ between the two reactions, but stay that same with-in similar reactions I get:
Code: [Select]
[REACTION:SMELT]
[BUILDING:SMELTER:NONE]
[FUEL]
[SKILL:SMELT]
Code: [Select]
[REACTION:GRIND_SMELT]
[BUILDING:GRIND_SMELTER:NONE]
[REAGENT:F:1:BOULDER:NO_SUBTYPE:INORGANIC]
[SKILL:SMELT]

Now I have all the reaction code from the two building separated. Next I would add two lines to the REACTION_BRASS_MAKING:
Code: [Select]
[USE_TEMPLATE_REACTION:SMELT]
[USE_TEMPLATE_REACTION:GRIND_SMELT]

Doing this would allow reactions to be used at multiple workshops with slightly differing requirements.

The recipe part of the reaction is reusable if someone wanted to add a fourth smelter type for whatever reason. There is also the added bonus of being able to make it so certain reactions can only be done at one building (like in this case I would make it so coke couldn't be produced from a grind smelter) simply by leaving out the template line for the undesirable building.

It also adds some flexibility for modding in general. If someone wants to use my grind smelter with metals from another mod they would have to only add one line to each metal, instead of coping and pasting, adding two lines, editing another line, and deleting another. And the reaction itself wouldn't need to be added to the civilization either (the building would still need permitted though). Overall it would greatly reduce the number of changes a modder would need to make when involved with reactions.

Also reactions would still work they way they currently do, because the current system is still versatile in other ways. You can have one building do a bunch of unrelated reactions without templates. Templates are there to add more versatility not take away from what is there.

Granted, my system isn't perfect and could probably use some other thoughts. Like I wonder if linking the concrete reactions to the templates the way I did is the best way of doing that. I would guess since the game would have to check the templates to find the building types the reaction is linked to it might cause some problems. There would also need to be a way for the reaction to ignore anything in a template linked to a different building (IE: We wouldn't want it asking for the fuel and the extra rock.). Though, most of what I put here would be superficial. It wouldn't change how the game sees things, it just makes it easier for the modders to deal with.

I imagine this has already been put up here somewhere, but I'm not so good at searching since I tend to think in off-the-wall terms. I went through three subject titles for this topic, Polymorphic Reactions and Virtual Reactions were up there before I settled on Reaction Templates.

If this has already been suggested could you point me in the right direction, as I would like to see what others might have come up with. Plus I'd really like to see what they called it so I could find the info easier.  :P

 
Logged
We do not suffer from insanity. We enjoy every single bit of it.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Reaction Templates
« Reply #1 on: September 23, 2011, 11:09:11 pm »

Yes, this is a good idea.

Also, as an addon, allowing power to be required for buildings or allowing to use power in reactions.

EmeraldWind

  • Bay Watcher
  • Hey there, dollface...
    • View Profile
Re: Reaction Templates
« Reply #2 on: September 25, 2011, 12:05:57 am »

Wait... you mean, that power can't be used in buildings?

I assumed it was in there already due to the mills. Dang.

At least I didn't start trying to mod that then.
I was going to mod it in for my next fort, I thought it would be fun to make it require
a lot of power just to make it so the magma is still the better option.

Oh well. I simply assumed all the stuff that other buildings could do would be available to use as tokens.

As for the main part of my idea, I thought it would be a decent idea. It probably still needs a bit of polishing and pounding out and it wouldn't be very useful in the short run. Though as the game gets bigger and interactions become more complex, it will help keep the reactions down to just the lines that change. Ultimately, it is kind of like how other objects are already handled and it simplifies things a bit .

Of course there are still cons to my idea, by taking some of the stuff out of the main reaction you can't see the entire reaction.  Part of my idea is to take some of the clutter out of the reaction, so you can see what makes the reaction unique. At the same time you can't see what makes it the same as the others without looking at the template.

It also becomes useless if there are tons of reactions that are completely unrelated to one another. My idea would still be used along side the current one, so you can still use reactions without using a template but it simply wouldn't be of use in a situation like that.

Another problem is how often will someone want to make a workshop that serves a similar purpose to one that already exists. I mean, besides my weird idea of a smelter I came up with I have trouble thinking of a similar example. In this case, the interface-like design of the template would be useless unless there were more reasons to make custom workshops that do similar things in only a slightly different way. Most of the time when people do make custom workshops, it is to produce things using reactions completely different from the others and there is no reason to use a reaction template, because they don't care about what was going in the original reaction or it is something unrelated.

It honestly needs so fixing, but I haven't done much modding to the game and therefore I'm not sure how helpful it would be. I put it here, because I saw there was nothing like this that I could find by searching. I know what I put here isn't an original idea, far from it in fact. It is a common programming design pattern and it is used in several different places already in the raws. My big thing about this though was also using it like an interface as well as a template, but like I said other than my odd grind-smelter, what else would use that?
Logged
We do not suffer from insanity. We enjoy every single bit of it.

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Reaction Templates
« Reply #3 on: September 26, 2011, 02:36:26 pm »

I suggested reaction templates of this kind here some time ago.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.