Sets/Clears a permission for a ship on a given player if pnum is -1 then all players will be set, else player is the player number returns true on success
| 3630 | // if pnum is -1 then all players will be set, else player is the player number |
| 3631 | // returns true on success |
| 3632 | bool PlayerSetShipPermission(int pnum, char *ship_name, bool allowed) { |
| 3633 | ASSERT(ship_name); |
| 3634 | |
| 3635 | if (pnum < -1 || pnum >= MAX_PLAYERS) // illegal value |
| 3636 | return false; |
| 3637 | |
| 3638 | int ship_index = FindShipName(ship_name); |
| 3639 | if (ship_index == -1) { |
| 3640 | ASSERT(ship_index != -1); |
| 3641 | return false; |
| 3642 | } |
| 3643 | int bit = 0x01; |
| 3644 | bit = bit << ship_index; |
| 3645 | |
| 3646 | if (pnum == -1) { |
| 3647 | // go through everyone |
| 3648 | for (int i = 0; i < MAX_PLAYERS; i++) { |
| 3649 | if (allowed) |
| 3650 | Players[i].ship_permissions |= bit; |
| 3651 | else |
| 3652 | Players[i].ship_permissions &= ~bit; |
| 3653 | } |
| 3654 | } else { |
| 3655 | if (allowed) |
| 3656 | Players[pnum].ship_permissions |= bit; |
| 3657 | else |
| 3658 | Players[pnum].ship_permissions &= ~bit; |
| 3659 | } |
| 3660 | return true; |
| 3661 | } |
| 3662 | |
| 3663 | // Resets the ship permissions for a given player |
| 3664 | // pass false for set_default if you don't want the default ship allowed |
no test coverage detected