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
|
static Direction
|
||||||
monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position *dest)
|
||||||
{
|
{
|
||||||
int x_dist, y_dist;
|
int x_dist, y_dist;
|
||||||
Position mPos;
|
Position mPos;
|
||||||
|
@ -275,7 +275,7 @@ monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position_equals(&next, &rm->playerRoomPos)) {
|
if (position_equals(&next, dest)) {
|
||||||
chosenDirection = (Direction) i;
|
chosenDirection = (Direction) i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -283,8 +283,8 @@ monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
||||||
if (!position_in_roommatrix(&next))
|
if (!position_in_roommatrix(&next))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
x_dist = abs(next.x - rm->playerRoomPos.x);
|
x_dist = abs(next.x - dest->x);
|
||||||
y_dist = abs(next.y - rm->playerRoomPos.y);
|
y_dist = abs(next.y - dest->y);
|
||||||
|
|
||||||
if (rm->spaces[next.x][next.y].occupied || rm->spaces[next.x][next.y].lethal) {
|
if (rm->spaces[next.x][next.y].occupied || rm->spaces[next.x][next.y].lethal) {
|
||||||
nextScore += 50;
|
nextScore += 50;
|
||||||
|
@ -293,10 +293,18 @@ monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
||||||
nextScore += x_dist > y_dist ? x_dist : y_dist;
|
nextScore += x_dist > y_dist ? x_dist : y_dist;
|
||||||
if (nextScore < currentScore) {
|
if (nextScore < currentScore) {
|
||||||
currentScore = nextScore;
|
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) {
|
switch (chosenDirection) {
|
||||||
case UP:
|
case UP:
|
||||||
move(m, rm, VECTOR2D_UP);
|
move(m, rm, VECTOR2D_UP);
|
||||||
|
@ -324,7 +332,6 @@ monster_coward_walk(Monster *m, RoomMatrix *rm)
|
||||||
x_dist = mPos.x - rm->playerRoomPos.x;
|
x_dist = mPos.x - rm->playerRoomPos.x;
|
||||||
y_dist = mPos.y - rm->playerRoomPos.y;
|
y_dist = mPos.y - rm->playerRoomPos.y;
|
||||||
|
|
||||||
|
|
||||||
if (abs(x_dist) > abs(y_dist)) {
|
if (abs(x_dist) > abs(y_dist)) {
|
||||||
if (x_dist > 0)
|
if (x_dist > 0)
|
||||||
move(m, rm, VECTOR2D_RIGHT);
|
move(m, rm, VECTOR2D_RIGHT);
|
||||||
|
|
Loading…
Reference in New Issue