aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-08-30 03:12:36 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-08-30 03:12:36 -0300
commite5fae2f8fc7e9da9de46ef830d05be3fc8ee2b89 (patch)
tree1ed08517a480884c1d5d0ce3c811b8a4cd8da7bd
parent28ba2e02ed6fd32f93a4088a40f7656e6902440b (diff)
downloadgame-e5fae2f8fc7e9da9de46ef830d05be3fc8ee2b89.tar.gz
game-e5fae2f8fc7e9da9de46ef830d05be3fc8ee2b89.zip
fix and cleanup `SearchFlightField`
-rw-r--r--src/info.cc63
-rw-r--r--src/operate.cc2
2 files changed, 17 insertions, 48 deletions
diff --git a/src/info.cc b/src/info.cc
index eb655c4..b507395 100644
--- a/src/info.cc
+++ b/src/info.cc
@@ -1051,58 +1051,26 @@ bool SearchFlightField(uint32 FugitiveID, uint32 PursuerID, int *x, int *y, int
return false;
}
- // NOTE(fusion): Fugitive's coordinates relative to the pursuer.
- int FugitiveX = Fugitive->posx - Pursuer->posx;
- int FugitiveY = Fugitive->posy - Pursuer->posy;
-
- int Try[8] = {};
- for(int i = 0; i < NARRAY(Try); i += 1){
- Try[i] = DIRECTION_NONE;
- }
-
- if(FugitiveY <= 0){
- Try[0] = DIRECTION_NORTH;
- }
-
- if(FugitiveX >= 0){
- Try[1] = DIRECTION_EAST;
- }
-
- if(FugitiveY >= 0){
- Try[2] = DIRECTION_SOUTH;
- }
-
- if(FugitiveX <= 0){
- Try[3] = DIRECTION_WEST;
- }
-
- if(FugitiveX <= 0 && FugitiveY >= 0){
- Try[4] = DIRECTION_SOUTHWEST;
- }
-
- if(FugitiveX >= 0 && FugitiveY >= 0){
- Try[5] = DIRECTION_SOUTHEAST;
- }
-
- if(FugitiveX >= 0 && FugitiveY <= 0){
- Try[6] = DIRECTION_NORTHEAST;
- }
-
- if(FugitiveX <= 0 && FugitiveY <= 0){
- Try[7] = DIRECTION_NORTHWEST;
- }
-
- RandomShuffle(&Try[0], 4);
- RandomShuffle(&Try[4], 4);
- for(int i = 0; i < NARRAY(Try); i += 1){
- if(Try[i] == DIRECTION_NONE){
+ int Dir[8];
+ Dir[0] = (Fugitive->posy <= Pursuer->posy) ? DIRECTION_NORTH : DIRECTION_NONE;
+ Dir[1] = (Fugitive->posx >= Pursuer->posx) ? DIRECTION_EAST : DIRECTION_NONE;
+ Dir[2] = (Fugitive->posy >= Pursuer->posy) ? DIRECTION_SOUTH : DIRECTION_NONE;
+ Dir[3] = (Fugitive->posx <= Pursuer->posx) ? DIRECTION_WEST : DIRECTION_NONE;
+ Dir[4] = (Fugitive->posx <= Pursuer->posx && Fugitive->posy >= Pursuer->posy) ? DIRECTION_SOUTHWEST : DIRECTION_NONE;
+ Dir[5] = (Fugitive->posx >= Pursuer->posx && Fugitive->posy >= Pursuer->posy) ? DIRECTION_SOUTHEAST : DIRECTION_NONE;
+ Dir[6] = (Fugitive->posx >= Pursuer->posx && Fugitive->posy <= Pursuer->posy) ? DIRECTION_NORTHEAST : DIRECTION_NONE;
+ Dir[7] = (Fugitive->posx <= Pursuer->posx && Fugitive->posy <= Pursuer->posy) ? DIRECTION_NORTHWEST : DIRECTION_NONE;
+ RandomShuffle(&Dir[0], 4);
+ RandomShuffle(&Dir[4], 4);
+ for(int i = 0; i < NARRAY(Dir); i += 1){
+ if(Dir[i] == DIRECTION_NONE){
continue;
}
int FieldX = Fugitive->posx;
int FieldY = Fugitive->posy;
int FieldZ = Fugitive->posz;
- switch(Try[i]){
+ switch(Dir[i]){
case DIRECTION_NORTH: FieldY -= 1; break;
case DIRECTION_EAST: FieldX += 1; break;
case DIRECTION_SOUTH: FieldY += 1; break;
@@ -1112,7 +1080,7 @@ bool SearchFlightField(uint32 FugitiveID, uint32 PursuerID, int *x, int *y, int
case DIRECTION_NORTHWEST: FieldX -= 1; FieldY -= 1; break;
case DIRECTION_NORTHEAST: FieldX += 1; FieldY -= 1; break;
default:{
- error("SearchFlightField: Ungültige Richtung %d.\n", Try[i]);
+ error("SearchFlightField: Ungültige Richtung %d.\n", Dir[i]);
return false;
}
}
@@ -1120,6 +1088,7 @@ bool SearchFlightField(uint32 FugitiveID, uint32 PursuerID, int *x, int *y, int
if(Fugitive->MovePossible(FieldX, FieldY, FieldZ, false, false)){
*x = FieldX;
*y = FieldY;
+ *z = FieldZ;
return true;
}
}
diff --git a/src/operate.cc b/src/operate.cc
index 0808bc8..24004a4 100644
--- a/src/operate.cc
+++ b/src/operate.cc
@@ -2430,7 +2430,7 @@ void Talk(uint32 CreatureID, int Mode, const char *Addressee, const char *Text,
// TODO(fusion): We should probably review this. You'd assume creature
// should be a player when talking to any channel.
- if(Channel == 0 && (Creature->Type != PLAYER
+ if(Channel == CHANNEL_GUILD && (Creature->Type != PLAYER
|| strcmp(((TPlayer*)Creature)->Guild, Subscriber->Guild) != 0)){
continue;
}