History

stop monsters attacking each other, give monsters random moves when not near player

mischief committed 11 years ago

Commit c455f6c1 parent ed3db101 file · +16 −11Browse files

Unified · Split

hack9.c+16−11
@@ -160,7 +160,7 @@ move(Point src, int dir) · 159 unmodified lines
160160 if(adj && *adj + c >= 0 && *adj + c < lim){
161161 *adj += c;
162162 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){
164164 /* monster; attack it */
165165 if(--t->monst->hp == 0){
166166 free(t->monst);
@@ -196,16 +196,21 @@ movemons(void) · 29 unmodified lines
196196
197197 for(p.x = 0; p.x < level->width; p.x++){
198198 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);
209214 }
210215 }
211216 }