Currency Handler

by Danny Roe
A small system to easily handle your in-game currency.
ID:1189009
 
This is a currency system such as seen in World of Warcraft, where:

100 Copper = 1 Silver
100 Silver = 1 Gold

Updating a mobs currency is easily handled through the use of the proc currencyUpdate(). Please refer to Notes.dm for further information on using this library.
Kinda surprised because I was about to post another Economy Handler, seems I will just keep it to myself and see how this does progress.
I've always wondered about these systems, and while the implementation isn't bad per say, wouldn't it be way more convenient to simply make ONE variable which holds 'currency', and simply SHOW the user the gold/silver/copper/kryptonite values which correspond with that value? I don't really see the point in making a variable (even though it's a list) for all of gold/silver/copper/whatevs.

var/list/currencies = list("gold" = 1000,"silver" = 100, "bronze" = 5, "copper"=1)
//Easily editable values and their worth
//Mind you, I didn't include sorting so it must go from high to low
//Every 1000 of currency is a gold, every 100 a silver, every 5 a bronze, and the rest is copper

mob
var/currency = 4867 // Random test value
proc
getCurrency(_cur)
var/index = currencies.Find(_cur)
if(index)
. = currency
if(index == 1) ./=currencies[currencies[1]] // If it's the first one in the list, don't bother looping
for(var/i=2,i<=index,i++)
. %= currencies[currencies[i-1]] // modulo of the 1-higher value
if(currencies[i] == _cur) // If it's your currency
./=currencies[currencies[i]] // Divide to get the amount and break out
break
return round(.)
getCurrencyString(_cur) return num2text(getCurrency(_cur),20) // No scientific notation
verb
displayCurrency()
usr<<"[getCurrencyString("gold")] gold, [getCurrencyString("silver")] silver, [getCurrencyString("bronze")] bronze and [getCurrencyString("copper")] copper"


If anyone can improve the algorithm feel free, randomly jumbo'd it up.
I had considered using one single numerical variable and just displaying it as Gold, Silver and Copper (You will notice I convert it all to copper to check you have enough to subtract from a mob). However I personally just found this much neater.
I have to agree with Danny on his choice. Two less variables is just being nit picky and a waste of time to condense it down further. Honestly with the memory allocation in today's computers, memory is only a problem if it leaks.
In response to Solomn Architect
Solomn Architect wrote:
I have to agree with Danny on his choice. Two less variables is just being nit picky and a waste of time to condense it down further. Honestly with the memory allocation in today's computers, memory is only a problem if it leaks.

I was plainly talking about convenience of having one simple number. Nowhere did I ever mention it taking in less memory.
Well, my assumption was that you were taking away simplicity for efficiency.
Okay, so I get how this currency system works, however is there away that I could make variables so that, for example, when someone completes a level for the first time, they get 10 copper, but after that, they don't get anything? Or is there a way I could delete the, i guess you could call them "variations" of currency and just use coins? I do know this is very convenient, but I just want a simpler economy... In my game there isn't really much to buy.

EDIT: I know I can delete the gold/silver/bronze/copper list and just replace it with 'currencies = Coins' but I don't know how to replace the other stuff.