@@ -290,10 +290,10 @@ void Game_Character::UpdateMoveRoute(int32_t& current_index, const lcf::rpg::Mov
290290 TurnRandom ();
291291 break ;
292292 case Code::move_towards_hero:
293- TurnTowardHero ( );
293+ TurnTowardCharacter (CharPlayer );
294294 break ;
295295 case Code::move_away_from_hero:
296- TurnAwayFromHero ( );
296+ TurnAwayFromCharacter (CharPlayer );
297297 break ;
298298 case Code::move_forward:
299299 break ;
@@ -347,10 +347,10 @@ void Game_Character::UpdateMoveRoute(int32_t& current_index, const lcf::rpg::Mov
347347 TurnRandom ();
348348 break ;
349349 case Code::face_hero:
350- TurnTowardHero ( );
350+ TurnTowardCharacter (CharPlayer );
351351 break ;
352352 case Code::face_away_from_hero:
353- TurnAwayFromHero ( );
353+ TurnAwayFromCharacter (CharPlayer );
354354 break ;
355355 default :
356356 break ;
@@ -528,20 +528,21 @@ void Game_Character::Turn90DegreeLeftOrRight() {
528528 }
529529}
530530
531- int Game_Character::GetDirectionToHero ( ) {
532- int sx = DistanceXfromPlayer ( );
533- int sy = DistanceYfromPlayer ( );
531+ int Game_Character::GetDirectionToCharacter ( const Game_Character* target ) {
532+ int sx = DistanceXfromCharacter (target );
533+ int sy = DistanceYfromCharacter (target );
534534
535- if ( std::abs (sx) > std::abs (sy) ) {
535+ if (std::abs (sx) > std::abs (sy)) {
536536 return (sx > 0 ) ? Left : Right;
537- } else {
537+ }
538+ else {
538539 return (sy > 0 ) ? Up : Down;
539540 }
540541}
541542
542- int Game_Character::GetDirectionAwayHero ( ) {
543- int sx = DistanceXfromPlayer ( );
544- int sy = DistanceYfromPlayer ( );
543+ int Game_Character::GetDirectionAwayCharacter ( const Game_Character* target ) {
544+ int sx = DistanceXfromCharacter (target );
545+ int sy = DistanceYfromCharacter (target );
545546
546547 if ( std::abs (sx) > std::abs (sy) ) {
547548 return (sx > 0 ) ? Right : Left;
@@ -550,12 +551,18 @@ int Game_Character::GetDirectionAwayHero() {
550551 }
551552}
552553
553- void Game_Character::TurnTowardHero () {
554- SetDirection (GetDirectionToHero ());
554+ void Game_Character::TurnTowardCharacter (int targetID) {
555+ Game_Character* target = GetCharacter (targetID, targetID);
556+ if (target) {
557+ SetDirection (GetDirectionToCharacter (target));
558+ }
555559}
556560
557- void Game_Character::TurnAwayFromHero () {
558- SetDirection (GetDirectionAwayHero ());
561+ void Game_Character::TurnAwayFromCharacter (int targetID) {
562+ Game_Character* target = GetCharacter (targetID, targetID);
563+ if (target) {
564+ SetDirection (GetDirectionAwayCharacter (target));
565+ }
559566}
560567
561568void Game_Character::TurnRandom () {
@@ -591,10 +598,10 @@ bool Game_Character::BeginMoveRouteJump(int32_t& current_index, const lcf::rpg::
591598 TurnRandom ();
592599 break ;
593600 case Code::move_towards_hero:
594- TurnTowardHero ( );
601+ TurnTowardCharacter (CharPlayer );
595602 break ;
596603 case Code::move_away_from_hero:
597- TurnAwayFromHero ( );
604+ TurnAwayFromCharacter (CharPlayer );
598605 break ;
599606 case Code::move_forward:
600607 break ;
@@ -635,10 +642,10 @@ bool Game_Character::BeginMoveRouteJump(int32_t& current_index, const lcf::rpg::
635642 TurnRandom ();
636643 break ;
637644 case Code::face_hero:
638- TurnTowardHero ( );
645+ TurnTowardCharacter (CharPlayer );
639646 break ;
640647 case Code::face_away_from_hero:
641- TurnAwayFromHero ( );
648+ TurnAwayFromCharacter (CharPlayer );
642649 break ;
643650 default :
644651 break ;
@@ -724,32 +731,39 @@ bool Game_Character::Jump(int x, int y) {
724731 return true ;
725732}
726733
727- int Game_Character::DistanceXfromPlayer () const {
728- int sx = GetX () - Main_Data::game_player->GetX ();
729- if (Game_Map::LoopHorizontal ()) {
730- if (std::abs (sx) > Game_Map::GetTilesX () / 2 ) {
731- if (sx > 0 )
732- sx -= Game_Map::GetTilesX ();
733- else
734- sx += Game_Map::GetTilesX ();
734+ int Game_Character::DistanceXfromCharacter (const Game_Character* target) const {
735+ if (target) {
736+ int sx = GetX () - target->GetX ();
737+ if (Game_Map::LoopHorizontal ()) {
738+ if (std::abs (sx) > Game_Map::GetTilesX () / 2 ) {
739+ if (sx > 0 )
740+ sx -= Game_Map::GetTilesX ();
741+ else
742+ sx += Game_Map::GetTilesX ();
743+ }
735744 }
745+ return sx;
736746 }
737- return sx;
747+ return 0 ; // Return a default value or handle the case where target is nullptr.
738748}
739749
740- int Game_Character::DistanceYfromPlayer () const {
741- int sy = GetY () - Main_Data::game_player->GetY ();
742- if (Game_Map::LoopVertical ()) {
743- if (std::abs (sy) > Game_Map::GetTilesY () / 2 ) {
744- if (sy > 0 )
745- sy -= Game_Map::GetTilesY ();
746- else
747- sy += Game_Map::GetTilesY ();
750+ int Game_Character::DistanceYfromCharacter (const Game_Character* target) const {
751+ if (target) {
752+ int sy = GetY () - target->GetY ();
753+ if (Game_Map::LoopVertical ()) {
754+ if (std::abs (sy) > Game_Map::GetTilesY () / 2 ) {
755+ if (sy > 0 )
756+ sy -= Game_Map::GetTilesY ();
757+ else
758+ sy += Game_Map::GetTilesY ();
759+ }
748760 }
761+ return sy;
749762 }
750- return sy;
763+ return 0 ; // Return a default value or handle the case where target is nullptr.
751764}
752765
766+
753767void Game_Character::ForceMoveRoute (const lcf::rpg::MoveRoute& new_route,
754768 int frequency) {
755769 if (!IsMoveRouteOverwritten ()) {
0 commit comments