Code: Show/Hide struct ShipSaved { unsigned Prizes : 28; Uint16 Items[15]; }; struct pSave { char name[20]; ShipSaved Ship[8]; }; |
Code: Show/Hide typedef unsigned char bits_t; //just for laziness :-P
struct ShipSaved { bits_t Unknown : 1; bits_t Recharge : 5; //or however many you need bits_t Energy : 5; //and so on Uint16 Items[15]; }; |
Code: Show/Hide struct pSave
{ char name[20]; unsigned char items[15]; }; int prize_to_index(int prize) { if (prize > 28) { prize = 7; } else if (prize > 25) { prize = prize - 14; } else if (prize > 20) { prize = prize - 13; } else if (prize > 10) { prize = prize - 6; } else if (prize > 7) { prize = prize - 5; } else if (prize > 0) { prize = prize - 1; } return prize; } void add_prize(struct pSave *psave, int prize, int amount) { index = prize_to_index(prize); if (index != prize) psave->items[index] += amount; } |
Code: Show/Hide BYTE prize[] = {1,2,3,8,9,11,12,29,21,22,23,24,26,27,28}; |
Code: Show/Hide const Uint16 ItemNum[15]={1,2,3,8,9,11,12,19,21,22,23,24,26,27,28}; void botInfo::GivePrizes(Player *p) { String Message; pSave *theSave=FindSave(p->name); if(theSave!=NULL && p->ship<8) { Uint16 j; Uint32 PrizeBit=1; for(Uint16 i=1;i<=28;i++) { if(theSave->Ship[p->ship].Prizes & PrizeBit) { if(PrizeBit & 0xEF40D87) { for(j=0;j<15;j++) { if(ItemNum[j]==i) { j=theSave->Ship[p->ship].Items[j]; break; } } } else {j=1;} Message="*prize #"; Message+=i; while(j-->0) { sendPrivate(p,0,Message.msg); } } PrizeBit<<=1; } } } |
50% Packetloss wrote: |
Doing it that way is the exact same as a switch. |