Unified · Split
| @@ -160,7 +160,7 @@ move(Point src, int dir) · 159 unmodified lines | ||
| 160 | 160 | if(adj && *adj + c >= 0 && *adj + c < lim){ |
| 161 | 161 | *adj += c; |
| 162 | 162 | t = tileat(level, dst); |
| 163 | − if(hasflagat(level, dst, Fblocked) && t->monst != nil){ | |
| 163 | + if(eqpt(src, pos) && hasflagat(level, dst, Fblocked) && t->monst != nil){ | |
| 164 | 164 | /* monster; attack it */ |
| 165 | 165 | if(--t->monst->hp == 0){ |
| 166 | 166 | free(t->monst); |
| @@ -196,16 +196,21 @@ movemons(void) · 29 unmodified lines | ||
| 196 | 196 | |
| 197 | 197 | for(p.x = 0; p.x < level->width; p.x++){ |
| 198 | 198 | for(p.y = 0; p.y < level->height; p.y++){ |
| 199 | − if(!eqpt(p, pos) && manhattan(p, pos) < 6 * ORTHOCOST && hasflagat(level, p, Fhasmonster)){ | |
| 200 | − /* move the monster toward player */ | |
| 201 | − npath = pathfind(level, p, pos, &path); | |
| 202 | − if(npath >= 0){ | |
| 203 | − /* step once along path, path[0] is cur pos */ | |
| 204 | − p2 = subpt(p, path[1]); | |
| 205 | − double ang = atan2(p2.y, p2.x); | |
| 206 | − movdir = (int)(4 * ang / (2*PI) + 4.5) % 4; | |
| 207 | − p2 = move(p, movdir+1); | |
| 208 | − free(path); | |
| 199 | + if(!eqpt(p, pos) && hasflagat(level, p, Fhasmonster)){ | |
| 200 | + if(manhattan(p, pos) < 6 * ORTHOCOST){ | |
| 201 | + /* move the monster toward player */ | |
| 202 | + npath = pathfind(level, p, pos, &path); | |
| 203 | + if(npath >= 0){ | |
| 204 | + /* step once along path, path[0] is cur pos */ | |
| 205 | + p2 = subpt(p, path[1]); | |
| 206 | + double ang = atan2(p2.y, p2.x); | |
| 207 | + movdir = (int)(4 * ang / (2*PI) + 4.5) % 4; | |
| 208 | + p2 = move(p, movdir+1); | |
| 209 | + free(path); | |
| 210 | + } | |
| 211 | + } else { | |
| 212 | + /* random move */ | |
| 213 | + move(p, nrand(4)+1); | |
| 209 | 214 | } |
| 210 | 215 | } |
| 211 | 216 | } |