| 07-25-2008, 04:14 PM | #1 |
I'm looking towards making a debt system & need some advice. Technically speaking its works quite similar to assistance systems. Debt System Gold = Gold (Just as normal) Gold is given as a reward for killing enemy units. Lumber = Debt Debt is incurred when teamkilling. The teammate's bounty value will need to be paid off, before gold can be accumulated once again. So example:
This is pretty simple, but gets a bit complicated if a player teamkills multiple ppl, or multiple players owe each other gold.[/list]So I basically just wanted to ask how this could be done or how you would handle this, more specifically how to keep track of multiple debts? I have to rush off to work atm, but what I've planned so far (not much yet):
Would this be the most efficient method? thx for any advice |
| 07-25-2008, 05:20 PM | #2 |
The main alternative is a linked list of structs, which is probably better than strings. |
| 07-25-2008, 05:21 PM | #3 |
Make a struct for each player. JASS:globals Debt array PlayerDebts endglobals struct Debt integer array owe[11] integer id integer total method addDebt takes integer ID, real amount returns nothing local Debt d = PlayerDebts[ID] // the debts the other player owes if ID = .id then // player can't owe himself money return endif if d.owe[.id] != 0 then // the there other player owes this player money then refund as much as you can with this debt if d.owe[.id] < amount // covers it all, so player will now be in debt of remainder set amount = amount - d.owe[.id] set d.total = d.total - d.owe[.id] set d.owe[.id] = 0 set .owe[ID] = amount set .total = .total + amount else // other player will still owe this player money set d.owe[.id] = d.owe[.id] - amount set d.total = d.total - amount // do nothing to the other player as all his potential debt was used paying off the other guys debt endif else // other player doesn't owe any money, so give it all as debt set .owe[ID] = .owe[ID] + amount set .total = .total + amount endif endmethod endstruct You would then need to check when a player gains money and see if he has any debts to pay off. I would make it a last, out style, so he pays off the latest debts first, and then proceeds upwards. edit: linked list of structs would be better than my idea, now that I think about it. It would help with the last out method. |
| 07-25-2008, 10:45 PM | #4 |
Thx for the sample Ammorth. Sorry but what is/do you mean by a linked list of structs? |
| 07-25-2008, 11:38 PM | #5 |
JASS:scope example private struct link[400000] //I seriously doubt you'd ever need more than 8000... link next integer value static method create takes integer value returns link local link l=link.allocate() set l.next=0 set l.value=value return l endmethod endstruct struct list link first=0 link last=0 static method addlink takes integer value returns nothing local link l=.first if(l==0)then set .first=link.create(value) return endif loop exitwhen l.next==0 set l=l.next endloop set l.next=link.create(value) endmethod endstruct endscope If you use a linked list, you don't have to compile all the debts to a single player together - rather, you would just add a link to your list with the debt info, and periodically go through your list, solving the links and erasing them, starting of course from the first one. Then, debt is payed off in exactly the order it is incurred. Once you are out of gold, you would loop through the rest of the links and add up the values to find the remaining debt (which you would assumedly want to display.) |
| 07-26-2008, 04:35 AM | #6 |
After posting, I started working on a debt system (planning on doing something like this in a map I'm currently thinking about). I'm almost finished, but I need to clean up, test and write brief instructions on how to use it. I'll post it here and then in the resource section when I'm done. |
| 07-26-2008, 09:22 AM | #7 |
thx for the sample Here-b-Trollz @Ammorth, yea that would be awesome. |
| 07-26-2008, 11:47 PM | #8 |
I haven't forgotten, I've just been really busy. Hopefully have it polished by tomorrow. |
