ID:265729
 
catchy title? I think so,

Through the help of a few of the guru's and some self intuition I have made great leaps in knowledge skill and logic over the past few months. However as seems to be the case I have run into another speed bump. However this time, it is not an error per say, but a poor coding style in my opinion.

I have a segment of code for crafting items, at the present one entry, ie for creating a helmet is about 20 lines, and it has the flexability to use that one entry for 15 metal types and 7 qualities, however I have an entry for every type of armor and weapon, each crafting entry does relatively the same thing with minor changes (sound familiar?). It is my goal to remove these multiple entries and consolidate even further than before. However unlike before there are different variables that go into the equation.

Before I had an entry for every armor type and every metal, and each of these entries calculated 7 types of quality, for a grand total of 6 billion lines of code ;). I am not so superfluous now, but I would like to cut down. At this point the code is very functional and close to completion so I would rather not post it, however I would be more than happy to send it to Lummox JR, or someone of that category of trust. and no I am not flattering myself into thinking I have the holy grail of coding, I just think my work shouldn't find its way into other projects without permission, and I am merely ensuring it doesn't.


I will be making an attempt at it while I await help.
Perilous Knight wrote:
catchy title? I think so,

Through the help of a few of the guru's and some self intuition I have made great leaps in knowledge skill and logic over the past few months. However as seems to be the case I have run into another speed bump. However this time, it is not an error per say, but a poor coding style in my opinion.

I have a segment of code for crafting items, at the present one entry, ie for creating a helmet is about 20 lines, and it has the flexability to use that one entry for 15 metal types and 7 qualities, however I have an entry for every type of armor and weapon, each crafting entry does relatively the same thing with minor changes (sound familiar?). It is my goal to remove these multiple entries and consolidate even further than before. However unlike before there are different variables that go into the equation.

Before I had an entry for every armor type and every metal, and each of these entries calculated 7 types of quality, for a grand total of 6 billion lines of code ;). I am not so superfluous now, but I would like to cut down. At this point the code is very functional and close to completion so I would rather not post it, however I would be more than happy to send it to Lummox JR, or someone of that category of trust. and no I am not flattering myself into thinking I have the holy grail of coding, I just think my work shouldn't find its way into other projects without permission, and I am merely ensuring it doesn't.


I will be making an attempt at it while I await help.

Give a small example on how your mixing the types of metals. Are they each individually coded? Are you using type of list? Cant really help you if you dont give information on what you need help on.

-Lummox JR(lol)
In response to Derekjeterisgod
lummox gave me some great help in the past on this system so he knows it fairly well (ie the reference :P)

the implementation of the various metals and qualities is complete, all 15 metals and all 7 qualities can be calculated flawlessly from the 20 line 'segment'. each segment is from an input list

input( forge, forge)in list( item1 ... item 20)
if( item 1)
calculation for metal
calculation for quality
item specifics
if( item 2)
calculation for metal
calculation for quality
item specifics (small change for say torso armor as opposed to a helmet)

Perhaps instead of having 10 defined objects for armor ie obj/helmet obj/torsoarmor i could have one generic armor entry and when equipping it define if its equip location is say for the torso, then usr.torsoarmor gets filled and his defense goes up?
In response to Perilous Knight
that is similar to what I have done for my metals. I have one metal that through a proc gets defined as one of 15 different metals, however the difference is, each metal doesnt get equipped much less to a completely different variable.
In response to Perilous Knight
Perilous Knight wrote:
lummox gave me some great help in the past on this system so he knows it fairly well (ie the reference :P)

the implementation of the various metals and qualities is complete, all 15 metals and all 7 qualities can be calculated flawlessly from the 20 line 'segment'. each segment is from an input list

input( forge, forge)in list( item1 ... item 20)
if( item 1)
calculation for metal
calculation for quality
item specifics
if( item 2)
calculation for metal
calculation for quality
item specifics (small change for say torso armor as opposed to a helmet)

Perhaps instead of having 10 defined objects for armor ie obj/helmet obj/torsoarmor i could have one generic armor entry and when equipping it define if its equip location is say for the torso, then usr.torsoarmor gets filled and his defense goes up?

What it sounds like is your making the calculations to many time, instead of all the if(itemx) call a proc to check the type of metal and send a return on the stat bonus for different types of metals, OR if your just trying to get the information just make an equip var and check if theres an item equip like this:
mob/var/equip=0

obj
helmet
Equip(var/mob/M as mob)
if(!M.equip)
M.defense+=2
M.equip=1
M << "You equip [src]"
else
M << "You already have something equipped!"


But that seems to basic to need be asking help for, so Im still not 100% sure on what you need, let me know if that helps you.
In response to Derekjeterisgod
I believe we are suffering a grave mis-communication here derek.

let me refer you to previous posts concerning this system, perhaps indirectly this will give you a more firm grasp on what I have accomplished so far;

http://developer.byond.com/forum/ index.cgi?action=message_read&id=533595&forum=5&view=1

http://developer.byond.com/forum/ index.cgi?action=message_read&id=512900&forum=5&view=0

i will post this much of my present code.

turf
anvil
icon = 'mining-smithing.dmi'
icon_state = "Anvil"
name = "Anvil"
density = 1
verb
Craft(var/obj/mining/ingot/M in usr)
set src in oview(1)
if(M.homename == "ingot")
var/choice = input("What would you like to Create?","The Forge")in list("Tools","Weapons","Armor","Cancel")
if(choice == "Tools")
usr << "no tools implemented at this point in time"
if(choice == "Armor")
var/choice2 = input("What armor would you like to make?")in list("Helmet","Boots","Chainmail","Light Plate Mail","Medium Plate Mail","Heavy Plate Mail","Cancel")
if(choice2 == "Helmet")
if(!usr.swinging)
usr.swinging = 1//basic macro restriction to prevent people from performing another task while this one is already in session
usr << "<b>* You start to hammer the metal *"
sleep(10)
usr.minskill = M.kindof*15-15 // first kind starts @ 1 so this allows a player with 0 skill to craft
if(usr.smithing >= usr.minskill)
if(M.amount >= 3) // more than three ingots
var/success = //equation for success would be here
if(success)
var/obj/armor/helmet/S = new(usr) // creates the new base item instead of having 7*15 helms i have already consolidated it
var/quality = //quality equation
S.quality = quality
S.kindof = M.kindof // sets the kind of metal as an interger, copying the value from the ingot used, ie 1 = iron, so in a future proc this is utilized for naming and metal bonuses
M.amount -= 3 // remove this amount of ingots from the pile
S.Identifyarmor() //the proc used in assigning bonuses, color to the item, and names
usr << "You create a [S.name]"
//smithing gain would go here next
if(!success)
usr << "<b>* You failed to create the item and your materials are lost *"
M.amount -= 3
if(!M.amount)
del(M)
//smithing gain would go here next
else
usr << "<b>* You have insufficient ingots to create this item *"
return

// notice the minute changes from the first to the second? very negligent at best, I want to further consolidate this so that I dont have to repeat this for 10 armors and 10 weapons
// my first thought would be to create one base armor that would get defined here as torsoequip or headequip then when you go to put it on it checks that variable then assigns that location as its equip variable
// doing that I could just use a switch proc.
// i just want insight before I dive headlong, or perhaps a snippet...

if(choice2 == "Boots")
if(!usr.swinging)
usr.swinging = 1//basic macro restriction to prevent people from performing another task while this one is already in session
usr << "<b>* You start to hammer the metal *"
sleep(10)
usr.minskill = M.kindof*15-10 // first kind starts @ 1 so this allows a player with 0 skill to craft
if(usr.smithing >= usr.minskill)
if(M.amount >= 3) // more than three ingots
var/success = //equation for success would be here
if(success)
var/obj/armor/helmet/S = new(usr) // creates the new base item instead of having 7*15 helms i have already consolidated it
var/quality = //quality equation
S.quality = quality
S.kindof = M.kindof // sets the kind of metal as an interger, copying the value from the ingot used, ie 1 = iron, so in a future proc this is utilized for naming and metal bonuses
M.amount -= 3 // remove this amount of ingots from the pile
S.Identifyarmor() //the proc used in assigning bonuses, color to the item, and names
usr << "You create a [S.name]"
//smithing gain would go here next
if(!success)
usr << "<b>* You failed to create the item and your materials are lost *"
M.amount -= 3
if(!M.amount)
del(M)
//smithing gain would go here next
else
usr << "<b>* You have insufficient ingots to create this item *"
return


For some faint reason I feel this is the blind leading the blind.
In response to Perilous Knight
If you want to consolidate this you need to have a seperate proc that can be called with arguments to handle the crafting after your user has made his choice. All your craft verb has to do is determine what the user wants to craft and then it could pass that information to a secondary proc as an argument. This way, instead of having the same code copied over and over, you only have it once in your doCrafting() type proc.
            Craft(var/obj/mining/ingot/M in usr)
set src in oview(1)
if(M.homename == "ingot")
var/choice = input("What would you like to Create?","The Forge")in list("Tools","Weapons","Armor","Cancel")
if(choice == "Tools")
usr << "no tools implemented at this point in time"
if(choice == "Armor")
var/choice2 = input("What armor would you like to make?")in list("Helmet","Boots","Chainmail","Light Plate Mail","Medium Plate Mail","Heavy Plate Mail","Cancel")
doCrafting(choice2)
proc/doCrafting(itemtype)
//Crafting process

Note that you would have the crafting as a single process at the top of the procedure and then determine and create the itemtype afterwords so you're not repeating code again.
In response to Hobbesx
indeed this is what I was thinking, however the specifics on exactly how to do this are eluding me.
My thinking on this would be that you'd want to calculate the item's stat boosts based on the material it's made of, at the time of forging. I'd probably calculate it like this:

stat = (base value for type) × (material multiplier) × (quality multiplier)

You can have different base values and multipliers per stat. One stat might be defense, where material may not vary the multiplier very much except when going from leather to metal. Another might be weight, where quality will almost always have a 1 multiplier. You can calculate the armor's effect on dexterity using the weight, or you can affect it directly:

(dexterity loss) = round((base value for type) × (material multiplier) × (quality multiplier))

Normally these values would be small; additionally, high quality might have a slightly lower multiplier. Heavy metals would have a higher material multiplier here.

Loss of stealth is another worthy stat to track. There, quality and material would both have an impact, material much more so.

So this is what a basic table might look like for a given component. For simplicity, let's say that all base values are calculated such that Material:Iron and Quality:Average have multipliers of 1 all across the board.

Item:Plate Mail

Item slot: Armor
Attack: 0
Defense: 5
Weight: 20
Dexterity loss: 3
Durability: 200
Stealth loss: 20
- Metal only -

Material:Copper

Attack: 0.8
Defense: 0.5
Weight: 0.7
Dexterity loss: 0.9
Durability: 0.4
Stealth loss: 0.9

Quality:Good

Attack: 1.2
Defense: 1.1
Weight: 1
Dexterity loss: 0.98
Durability: 1.1
Stealth loss: 0.95


So as you see, each particular component has variables that affect the calculations. You could stick this in a table and read it in at runtime. You also have the option of playing with trade-offs, where leather for example will give you far better stealth than metal, but in exchange for lower defense ratios. Different metals have different hardness and weight, and price (for upkeep as well as to buy). You could also figure repair cost into the figures above, such that different materials require different amounts of money to fix, and higher quality might exponentially increase the repair cost while buying only a little more durability.

Lummox JR