Assigning positions
BlitzMax Forums/BlitzMax Beginners Area/Assigning positions
| ||
I'm trying to figure it out but it's getting to be a pain. I'd like to know whether anyone here knows a good way of doing this: I've got positions in my ship: Const SHIP_CREW_CAPTAIN = 1 Const SHIP_CREW_PILOT = 2 Const SHIP_CREW_NAVIGATOR = 4 Const SHIP_CREW_ENGINEER = 8 Const SHIP_CREW_TACTICAL = 16 Now on a ship with a crew size of 2, all the positions have to be filled by those two people, so crew member 1 will be a captain, pilot and engineer whilst crew member 2 will be navigator and tactical. It's doesn't matter who is who or who has what positions as long as they're sort of assigned fairly. Am I being totally stupid? Is there an easy way to do this? I need to fill the array: local crew[crewSize] and to fill with the values, so for the above example: crew[0]=1+2+8 crew[1]=4+16 Likewise, a crew size of 5, each person'll have one position on the ship. I'm hoing the replies to this are going to start "erm..." because it's simple. Any help much much appreciated. |
| ||
ouch. thanks everyone. I've fixed it now, but if it hadn't been for your support I'd have never got there. Thanks again! |
| ||
You're welcome! Glad to help! |
| ||
DOH! |
| ||
You're welcome :D ------ never mind this then ----- newplayerpos = 2 For i = 0 until crew.length if i<>newplayerpos if crew[i] & navigator crew[newplayerpos] = crew[newplayerpos] | crew[i] crew[i] = 0 endif endif next Is that what you mean? or should the old navigator keep the other position he might hold? Then it would be: crew[newplayerpos] = crew[newplayerpos] | navigator crew[i] = crew[i] - navigator |
| ||
Was gunna suggest using a bitfield - ie storing the roles as individual bits in an integer or something, then you can have an integer array and store/extract the bit flags yourself. |