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