* Return the correct graphics character index using wall type, wall mode, * and the seen vector. It is expected that seenv is non zero. * * All T-wall vectors are rotated to be TDWALL. All single crosswall * blocks are rotated to bottom right. All double crosswall are rotated * to W_X_BLTR. All results are converted back. * * The only way to understand this is to take out pen and paper
| 3510 | * seen vector (SV). |
| 3511 | */ |
| 3512 | staticfn int |
| 3513 | wall_angle(struct rm *lev) |
| 3514 | { |
| 3515 | unsigned int seenv = lev->seenv & 0xff; |
| 3516 | const int *row; |
| 3517 | int col, idx; |
| 3518 | |
| 3519 | #define only(sv, bits) (((sv) & (bits)) && !((sv) & ~(bits))) |
| 3520 | switch (lev->typ) { |
| 3521 | case TUWALL: |
| 3522 | row = wall_matrix[T_u]; |
| 3523 | seenv = (seenv >> 4 | seenv << 4) & 0xff; /* rotate to tdwall */ |
| 3524 | goto do_twall; |
| 3525 | case TLWALL: |
| 3526 | row = wall_matrix[T_l]; |
| 3527 | seenv = (seenv >> 2 | seenv << 6) & 0xff; /* rotate to tdwall */ |
| 3528 | goto do_twall; |
| 3529 | case TRWALL: |
| 3530 | row = wall_matrix[T_r]; |
| 3531 | seenv = (seenv >> 6 | seenv << 2) & 0xff; /* rotate to tdwall */ |
| 3532 | goto do_twall; |
| 3533 | case TDWALL: |
| 3534 | row = wall_matrix[T_d]; |
| 3535 | do_twall: |
| 3536 | switch (lev->wall_info & WM_MASK) { |
| 3537 | case 0: |
| 3538 | if (seenv == SV4) { |
| 3539 | col = T_tlcorn; |
| 3540 | } else if (seenv == SV6) { |
| 3541 | col = T_trcorn; |
| 3542 | } else if (seenv & (SV3 | SV5 | SV7) |
| 3543 | || ((seenv & SV4) && (seenv & SV6))) { |
| 3544 | col = T_tdwall; |
| 3545 | } else if (seenv & (SV0 | SV1 | SV2)) { |
| 3546 | col = (seenv & (SV4 | SV6) ? T_tdwall : T_hwall); |
| 3547 | } else { |
| 3548 | t_warn(lev); |
| 3549 | col = T_stone; |
| 3550 | } |
| 3551 | break; |
| 3552 | case WM_T_LONG: |
| 3553 | if (seenv & (SV3 | SV4) && !(seenv & (SV5 | SV6 | SV7))) { |
| 3554 | col = T_tlcorn; |
| 3555 | } else if (seenv & (SV6 | SV7) && !(seenv & (SV3 | SV4 | SV5))) { |
| 3556 | col = T_trcorn; |
| 3557 | } else if ((seenv & SV5) |
| 3558 | || ((seenv & (SV3 | SV4)) && (seenv & (SV6 | SV7)))) { |
| 3559 | col = T_tdwall; |
| 3560 | } else { |
| 3561 | /* only SV0|SV1|SV2 */ |
| 3562 | if (!only(seenv, SV0 | SV1 | SV2)) |
| 3563 | t_warn(lev); |
| 3564 | col = T_stone; |
| 3565 | } |
| 3566 | break; |
| 3567 | case WM_T_BL: |
| 3568 | if (only(seenv, SV4 | SV5)) |
| 3569 | col = T_tlcorn; |
no test coverage detected