| 1101 | |
| 1102 | |
| 1103 | staticfn void |
| 1104 | cast_protection(void) |
| 1105 | { |
| 1106 | int l = u.ulevel, loglev = 0, |
| 1107 | gain, natac = u.uac + u.uspellprot; |
| 1108 | /* note: u.uspellprot is subtracted when find_ac() factors it into u.uac, |
| 1109 | so adding here factors it back out |
| 1110 | (versions prior to 3.6 had this backwards) */ |
| 1111 | |
| 1112 | /* loglev=log2(u.ulevel)+1 (1..5) */ |
| 1113 | while (l) { |
| 1114 | loglev++; |
| 1115 | l /= 2; |
| 1116 | } |
| 1117 | |
| 1118 | /* The more u.uspellprot you already have, the less you get, |
| 1119 | * and the better your natural ac, the less you get. |
| 1120 | * |
| 1121 | * LEVEL AC SPELLPROT from successive SPE_PROTECTION casts |
| 1122 | * 1 10 0, 1, 2, 3, 4 |
| 1123 | * 1 0 0, 1, 2, 3 |
| 1124 | * 1 -10 0, 1, 2 |
| 1125 | * 2-3 10 0, 2, 4, 5, 6, 7, 8 |
| 1126 | * 2-3 0 0, 2, 4, 5, 6 |
| 1127 | * 2-3 -10 0, 2, 3, 4 |
| 1128 | * 4-7 10 0, 3, 6, 8, 9, 10, 11, 12 |
| 1129 | * 4-7 0 0, 3, 5, 7, 8, 9 |
| 1130 | * 4-7 -10 0, 3, 5, 6 |
| 1131 | * 7-15 -10 0, 3, 5, 6 |
| 1132 | * 8-15 10 0, 4, 7, 10, 12, 13, 14, 15, 16 |
| 1133 | * 8-15 0 0, 4, 7, 9, 10, 11, 12 |
| 1134 | * 8-15 -10 0, 4, 6, 7, 8 |
| 1135 | * 16-30 10 0, 5, 9, 12, 14, 16, 17, 18, 19, 20 |
| 1136 | * 16-30 0 0, 5, 9, 11, 13, 14, 15 |
| 1137 | * 16-30 -10 0, 5, 8, 9, 10 |
| 1138 | */ |
| 1139 | natac = (10 - natac) / 10; /* convert to positive and scale down */ |
| 1140 | gain = loglev - (int) u.uspellprot / (4 - min(3, natac)); |
| 1141 | |
| 1142 | if (gain > 0) { |
| 1143 | if (!Blind) { |
| 1144 | int rmtyp; |
| 1145 | const char *hgolden = hcolor(NH_GOLDEN), *atmosphere; |
| 1146 | |
| 1147 | if (u.uspellprot) { |
| 1148 | pline_The("%s haze around you becomes more dense.", hgolden); |
| 1149 | } else { |
| 1150 | struct permonst *pm = u.ustuck ? u.ustuck->data : 0; |
| 1151 | |
| 1152 | rmtyp = levl[u.ux][u.uy].typ; |
| 1153 | atmosphere = (pm && u.uswallow) |
| 1154 | ? ((pm == &mons[PM_FOG_CLOUD]) ? "mist" |
| 1155 | : is_whirly(pm) ? "maelstrom" |
| 1156 | : enfolds(pm) ? "folds" |
| 1157 | : is_animal(pm) ? "maw" |
| 1158 | : "ooze") |
| 1159 | : (u.uinwater ? hliquid("water") |
| 1160 | : (rmtyp == CLOUD) ? "cloud" |
no test coverage detected