Fixes: #21 Complex method issue in monster.c
At least this is an attempt at a fix
This commit is contained in:
parent
b12e5d4f7a
commit
58e9c7ed13
|
@ -245,8 +245,8 @@ monster_drunk_walk(Monster *m, RoomMatrix *rm)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
||||
static Direction
|
||||
get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position *dest)
|
||||
{
|
||||
int x_dist, y_dist;
|
||||
Position mPos;
|
||||
|
@ -275,7 +275,7 @@ monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
|||
break;
|
||||
}
|
||||
|
||||
if (position_equals(&next, &rm->playerRoomPos)) {
|
||||
if (position_equals(&next, dest)) {
|
||||
chosenDirection = (Direction) i;
|
||||
break;
|
||||
}
|
||||
|
@ -283,8 +283,8 @@ monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
|||
if (!position_in_roommatrix(&next))
|
||||
continue;
|
||||
|
||||
x_dist = abs(next.x - rm->playerRoomPos.x);
|
||||
y_dist = abs(next.y - rm->playerRoomPos.y);
|
||||
x_dist = abs(next.x - dest->x);
|
||||
y_dist = abs(next.y - dest->y);
|
||||
|
||||
if (rm->spaces[next.x][next.y].occupied || rm->spaces[next.x][next.y].lethal) {
|
||||
nextScore += 50;
|
||||
|
@ -293,10 +293,18 @@ monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
|||
nextScore += x_dist > y_dist ? x_dist : y_dist;
|
||||
if (nextScore < currentScore) {
|
||||
currentScore = nextScore;
|
||||
chosenDirection = (Direction)i;
|
||||
chosenDirection = (Direction) i;
|
||||
}
|
||||
}
|
||||
|
||||
return chosenDirection;
|
||||
}
|
||||
|
||||
static void
|
||||
monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
||||
{
|
||||
unsigned int chosenDirection = get_optimal_move_towards(m, rm, &rm->playerRoomPos);
|
||||
|
||||
switch (chosenDirection) {
|
||||
case UP:
|
||||
move(m, rm, VECTOR2D_UP);
|
||||
|
@ -324,7 +332,6 @@ monster_coward_walk(Monster *m, RoomMatrix *rm)
|
|||
x_dist = mPos.x - rm->playerRoomPos.x;
|
||||
y_dist = mPos.y - rm->playerRoomPos.y;
|
||||
|
||||
|
||||
if (abs(x_dist) > abs(y_dist)) {
|
||||
if (x_dist > 0)
|
||||
move(m, rm, VECTOR2D_RIGHT);
|
||||
|
|
Loading…
Reference in New Issue