wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Systems
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 08-24-2008, 03:04 PM   #1
Artificial
User
 
Join Date: Aug 2008
Posts: 14

Submissions (1)

Artificial is on a distinguished road (12)

Default RecipeSYS

NOTE: You have been redirected in order for our attachments to be made available to you. This will only last two minutes; these measures where taken to avoid hotlinking and bandwidth theft.
To avoid these restrictions Log in or Register

Yes, it's true. Yet another one.
RecipeSYS
v0.6d

RecipeSYS is a system that allows you to have recipes that combine two or more (up to six) items into one item. The code has a rather good documentation on how to use it, and the map also contains an example trigger of usage in GUI.
All you need to do is add one line of Jass for each recipe you want, and the system will do the rest.
The system can even be used for stacking charged items (not the easiest way of doing that, though, as you would need one line for every item that can stack).

Features
Supports having several items of the same type as ingredients in the same recipe.
Supports having the same item type as an ingredient in several recipes.
Allows to override the (customizable) default special point and attachment point by using the Ex functions.
All you need to do is add the recipes.
You can remove recipes.
You can add recipes with results that have charges.
The amount of charges can be predefined, the sum of charges left in the ingredients, or the amount of charges in the ingredient with most charges.
You can disable and enable single recipes or the whole system.
You can disassemble items.
You can use any event you want.

Requirements
A vJass compiler (NewGen includes one).
Table by Vexorian.

The Code
Expand C++:

Example of Usage
Trigger:
T
Collapse Events
Time - Elapsed game time is 0.00 seconds
Conditions
Collapse Actions
Custom script: local recipe re = AddRecipe('rde2', 'rde2', 0, 0, 0, 0, 'belv')
Custom script: call AddRecipe('rde1', 'rde2', 0, 0, 0, 0, 'belv')
Custom script: call AddRecipeWithCharges('fgdg', 'fgdg', 0, 0, 0, 0, 'fgdg', 0)
Set Item = Boots of Quel'Thalas +6 0028 <gen>
Custom script: call DisassembleItemByRecipe(udg_Item, null, re)
Custom script: call EnableRecipeByResult('belv', false)
Wait 10.00 seconds
Game - Display to (All players) the text: Enabling.
Custom script: call EnableRecipeByResult('belv', true)
Wait 10.00 seconds
Game - Display to (All players) the text: Destroying.
Custom script: call RemoveRecipeByResult('belv')

Importing
Copy the trigger called RecipeSYS from the attached map or create a trigger named RecipeSYS, convert it to custom text, and replace everything inside it with the code above.

Q&A
Q: There are lots of recipe systems already. Why on earth did you make another one?!
A: I felt like it. Duh...

Q: How is this different from the other systems?
A: Well, I didn't make the other ones (although you might think I did (even though you've never heard of me before)). You could also take a look at the feature list, it might have some differences.

Q: The 'Features' list is like exactly the same as the 'Strengths' list in the comments!
A: No shit, Sherlock.

Q: Does the system have any weaknesses?
A: Besides the ones mentioned at the end of the comment block, I don't know. You tell me.

Q: Can I leave suggestions, questions, and/or comments?
A: If they are somehow intelligent.

Q: How many recipes can I have at once?
A: Up to 1365.

Q: I seriously think no more recipe systems are needed.
A: Ok.

Q: How do I use this system?
A: Didn't you look at the code at all? The 4th row with text is 'How To Use RecipeSYS'. Could there be instructions for usage under that title? I doupt. :)

Changelog

Code:
v0.6d
 Made the system flush the entrys for items it destroys.
 Removed a scenario that made the system try to destroy unexistant dynamic arrays.

v0.6c
 Removed some duplication of code.
 Removed the usage of item data, now using Table for it.
 Removed some unnecessary variables.
 Made ClearRecipeFrom... methods free the arrays and flush tha table thingy when the array is empty.
 Renamed ingTable to ING_TABLE and resTable to RES_TABLE so it'd be easier to see they are globals.

v0.6b
 Split up ClearRecipeFromItem to ClearRecipeFromIngredient and ClearRecipeFromResult.
 Split up GetItemTypeRecipes to GetResultRecipes and GetIngredientRecipes.
 Removed GetResultRecipes and GetIngredientRecipes.
 Made ClearRecipeFromItem take care of holes in the arrays.
 Made ingIn and resIn extend recipe arrays instead of integer arrays.
 Removed the type recipes.
 Removed the recipe array RECIPES.
 Removed count (the global variable).
 Changed StringTables to Tables.

v0.6
 Changed pretty much stuff.
 Made it use Table (by Vexorian) for better performance.
 The functions now take and return recipes instead of ids.
 The struct recipe is not private anymore.
 You can now also create recipes with the create method of the struct.
 Some functions were renamed:
 - EnableRecipe        -> EnableRecipeByResult
 - EnableRecipeById    -> set (yourRecipe).enabled =
 - RemoveRecipe        -> RemoveRecipeByResult
 - RemoveRecipeById    -> (yourRecipe).destroy
 - DisassembleItemById -> DisassembleItemByRecipe
 Added GetItemTypeRecipes and RecipesRelease.
 Added three globals: AMOUNT_ING, AMOUNT_RES, and AMOUNT_RECS.

0.5b
 Fixed the bug with having AUTO_COMBINE as false making it impossible to disassemble items.

0.5
 Added CheckForRecipes.
 Added AUTO_COMBINE.
 Made TRIGGER unconstant.
 Made Combine store the result to bj_lastCreatedItem.

0.4
 Fixed a problem with the DisassembleItem function enabling triggers.
 Added DisassembleItemById.
 Added USE_ITEM_DATA.
 Some minor changes in a couple of functions.

0.3
 Made the functions that add the recipes return the id of the recipe (used for 'ById' functions).
 Added RemoveRecipeById.
 Added EnableRecipeById.
 Removed the "set RECIPES[count] = 0" from RemoveRecipe.
 Made Combine return a boolean and updated Check a bit.

0.2
 Added EnableRecipe function.
 Added DisassembleItem function.
 Added the global trigger RecipeSYS_TRIGGER so you can disable and enable the system completely.

0.1
 Made it possible to use the same item as an ingredient for several recipes.
 Added support for charged results.
 
0.0b
 Inlined TriggerRegisterAnyUnitEvent.
 Changed the action to condition.
 
0.0
 First release.

Attached Images
File Type: png RecipeSYS.png (21.2 KB, 1230 views)
Attached Files
File Type: w3x RecipeSYSv0.6d.w3x (48.6 KB, 705 views)
__________________
How to solve problems:
- Write the problem on paper.
- Think hard.
- Write the answer.
♪♫ "Dansa med oss, klappa era händer.
Gör som vi gör, ta några steg åt vänster.
Lyssna och lär, missa inte chansen.
Nu är vi här med caramelldansen."

Last edited by Artificial : 08-30-2008 at 01:49 PM. Reason: Update to v0.6d
Artificial is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 08-24-2008, 05:41 PM   #2
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

You could have made it much faster, right now, you need to loop through every single recipe in the game when a unit acquires an item, think about it, with only 6 items in a unit's inventory, there got to be a better way...
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 08-24-2008, 06:31 PM   #3
Artificial
User
 
Join Date: Aug 2008
Posts: 14

Submissions (1)

Artificial is on a distinguished road (12)

Default

I'm still rather new with Jass (excuses), and I'm having a hard time figuring out how to make it faster, although I know it probably could be done better.
The only thing I can think of would be linking the recipes to the item types, which I don't know how to do. I guess the only way of doing that would be using gamecache. That should be faster, right? Maybe I'll need to learn to use gamecache, then.
__________________
How to solve problems:
- Write the problem on paper.
- Think hard.
- Write the answer.
♪♫ "Dansa med oss, klappa era händer.
Gör som vi gör, ta några steg åt vänster.
Lyssna och lär, missa inte chansen.
Nu är vi här med caramelldansen."
Artificial is offline   Reply With Quote
Old 08-24-2008, 06:33 PM   #4
Vestras
User


Project Member: LoC
 
Join Date: Dec 2007
Posts: 756

Submissions (4)

Vestras will become famous soon enough (40)Vestras will become famous soon enough (40)

Default

Arti, gc is slow. (I'm Vestras, from mapcrafting.com, in case you forgot your own site)

Last edited by Vestras : 08-24-2008 at 06:34 PM.
Vestras is offline   Reply With Quote
Old 08-24-2008, 06:58 PM   #5
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,368

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

gc is pretty fast as a two key hash table. Big arrays are faster, if they'll do what you need.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 08-24-2008, 07:18 PM   #6
Artificial
User
 
Join Date: Aug 2008
Posts: 14

Submissions (1)

Artificial is on a distinguished road (12)

Default

> gc is slow
I know it's somehow slow, but I guess it's faster than looping through every single recipe.
And I know who you are, don't worry. ^_^

> Big arrays are faster, if they'll do what you need.
I thought about arrays, but I can't figure out a way to transform the item's rawcode into a form that could be used as an array pointer. They are like WAY too big and vary too much.
__________________
How to solve problems:
- Write the problem on paper.
- Think hard.
- Write the answer.
♪♫ "Dansa med oss, klappa era händer.
Gör som vi gör, ta några steg åt vänster.
Lyssna och lär, missa inte chansen.
Nu är vi här med caramelldansen."
Artificial is offline   Reply With Quote
Old 08-24-2008, 07:22 PM   #7
Here-b-Trollz
Corkscrew Chainsaw!!!
 
Join Date: Jun 2006
Posts: 711

Here-b-Trollz has a spectacular aura about (149)

Hero Contest #2 - 2nd Place

Default

Why do item systems need to be fast anyway? They aren't being called by periodic timers or anything. Items should be, to quote TC, 'powerful'.
__________________
By reading this signature, you agree that I cannot be held accountable for anything that I might say or do.

Last edited by Here-b-Trollz : 08-24-2008 at 07:23 PM.
Here-b-Trollz is offline   Reply With Quote
Old 08-24-2008, 08:51 PM   #8
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Item systems don't need to be fast but this thing is a recipe system which will trigger everytime you pick up an item, anyway. Artificial: Yes, something like that would be good, another thing would be that in the case of a pickup event you only need to consider the recipes that use the item.

GC is ok for this in terms of speed since it is O(1) instead of O(n) it would be faster, you could make your own hash table, but I think Griffen got a good idea with big arrays, it still though requires a way to convert the item type to an array index. The problem is how to implement this stuff without adding weight to the requirements, making it use its whole gamecache file would be a little too much. Also you'd have to be careful not to make this cause an item type limit. -you could use one of many libraries out there that do hashing-

it wouldn't scale well with things like 50 recipes in the whole system, it seems like a big value but there isn't too much reason to use one of these systems if you don't plan having plenty of recipes in your map.

--
The optimization would not be a requirement for approval, Something I don't like too much is how it forces the guy to use plain integers for the recipes thus losing some type safety and convenience around, you could actually make recipes creatable as just recipe.create() and what not, you can also make the functions return a recipe and make the recipe struct public and have some read only fields that could be helpful for the guy using your system. Even if you don't add these things, make the functions take and return recipe, it will make life easier when jasshelper gets type safety and that stuff.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 08-25-2008, 10:14 AM   #9
The Elite
For External Use Only
 
The Elite's Avatar
 
Join Date: Jun 2007
Posts: 672

Submissions (6)

The Elite will become famous soon enough (60)The Elite will become famous soon enough (60)The Elite will become famous soon enough (60)

Default

indent much?
and what is 'cre8', i dont think i speak your language. Please speak english
__________________

Goths are nerds that dress like vampires. -Dominant-Male
Oh, and wc3c wasn't dying back in 2007 and it isn't now. Our secret is simple: you can't kill the undead ... - Vexorian

We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft. - Chris Metzen on the Warcraft Movie
Man, we're considered elitist all over the internet. This makes me feel nice and warm inside. - ghenjis
Please help! I'll provide no information, you must guess! - Whitehorn
The Elite is offline   Reply With Quote
Old 08-25-2008, 11:09 PM   #10
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,727

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

This isn't his thread anyways and I'll permit no thread-hijacking, so I've deleted that post.
__________________
Rising_Dusk is offline   Reply With Quote
Old 08-26-2008, 02:02 PM   #11
Artificial
User
 
Join Date: Aug 2008
Posts: 14

Submissions (1)

Artificial is on a distinguished road (12)

Default

Ok, I made some improvements. First of all, I made the functions take and return recipes instead of integers, and the recipe struct no longer is private.
Second of all, I made 2 versions of it; one using GC and one a hash table I found (this one). Now I'm wondering if you guys could tell me which one should be better, or if there is a way for me to test their speeds (which I would like to do even though you would be able to say which one is better) and how to do it.

Here are the codes in case you wanna see them.
Expand Gamecache:
Expand Hash table:
It was fun learning how to use GC and that hash table, so thanks for making me learn to use them.
__________________
How to solve problems:
- Write the problem on paper.
- Think hard.
- Write the answer.
♪♫ "Dansa med oss, klappa era händer.
Gör som vi gör, ta några steg åt vänster.
Lyssna och lär, missa inte chansen.
Nu är vi här med caramelldansen."

Last edited by Artificial : 08-27-2008 at 10:49 AM.
Artificial is offline   Reply With Quote
Old 08-26-2008, 10:01 PM   #12
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,061

Submissions (19)

Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

I really don't know what you're doing in the GetItemTypeRecipes function. Why work with strings when you could easily have stored integers to GC? Speaking of GC, you shouldn't be creating your own cache for this, you should use an external gamecache library like Table.
__________________
Anitarf is offline   Reply With Quote
Old 08-27-2008, 04:40 AM   #13
Artificial
User
 
Join Date: Aug 2008
Posts: 14

Submissions (1)

Artificial is on a distinguished road (12)

Default

Why I'm working with strings is that I couldn't figure out a way to use integers without limiting an item-type to only be cabable of being used in one recipe.
GetItemTypeRecipes just separates the integers (=recipes) stored to the string, sets them to the array and returns the array.
And I'll look to that Table. :)
__________________
How to solve problems:
- Write the problem on paper.
- Think hard.
- Write the answer.
♪♫ "Dansa med oss, klappa era händer.
Gör som vi gör, ta några steg åt vänster.
Lyssna och lär, missa inte chansen.
Nu är vi här med caramelldansen."
Artificial is offline   Reply With Quote
Old 08-27-2008, 01:53 PM   #14
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,061

Submissions (19)

Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)Anitarf has a brilliant future (883)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Couldn't you just create a dynamic array for each item that stores all the recipies that item is involved in, and then link that array (which is just an integer when vJass compiles to Jass) to the item type via GC? Seems like the only sane way to do this.
__________________
Anitarf is offline   Reply With Quote
Old 08-27-2008, 07:41 PM   #15
Artificial
User
 
Join Date: Aug 2008
Posts: 14

Submissions (1)

Artificial is on a distinguished road (12)

Default

At some point I came up with an idea of using dynamic arrays, but I abandoned that idea as I thought it'd restrict the system too much (if you increase the amount of recipes an item can be in, the amount of different item-types that can be used goes down), and I didn't know a way to store them well when in dynamic arrays. Didn't know they are that much like structs. So thanks for Anitarf, Vexorian, and everyone else who has left suggestions/comments.

So I think it's about the time to release the version 0.6 after tweaking the code kinda much, now using Table and dynamic arrays and stuff. And it even worked in my tests.
Changelog

Code:
v0.6
 Changed pretty much stuff.
 Made it use Table (by Vexorian) for better performance.
 The functions now take and return recipes instead of ids.
 The struct recipe is not private anymore.
 You can now also create recipes with the create method of the struct.
 Some functions were renamed:
 - EnableRecipe        -> EnableRecipeByResult
 - EnableRecipeById    -> set (yourRecipe).enabled =
 - RemoveRecipe        -> RemoveRecipeByResult
 - RemoveRecipeById    -> (yourRecipe).destroy
 - DisassembleItemById -> DisassembleItemByRecipe
 Added GetItemTypeRecipes and RecipesRelease.
 Added three globals: AMOUNT_ING, AMOUNT_RES, and AMOUNT_RECS.

Tell me if I missed something someone suggested. The only thing I know I missed was this:
Quote:
Originally Posted by Vexorian
have some read only fields that could be helpful for the guy using your system.
And missing that was just because I can't figure out what read only fields to make. Or well, I guess the GetItemTypeRecipes could count?

Edit: Heh, maybe I shouldn't do this just before getting to bed. I noted I've been using strings to store the data, even though I could've just used integers. Will be fixed for the next version, don't worry.
__________________
How to solve problems:
- Write the problem on paper.
- Think hard.
- Write the answer.
♪♫ "Dansa med oss, klappa era händer.
Gör som vi gör, ta några steg åt vänster.
Lyssna och lär, missa inte chansen.
Nu är vi här med caramelldansen."

Last edited by Artificial : 08-28-2008 at 06:12 AM.
Artificial is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 06:46 AM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services