processFollow code question

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

obsc
Noob
Noob
Posts: 18
Joined: 11 Sep 2009, 03:58
Noob?: Yes

processFollow code question

#1 Post by obsc »

ok, here's one pretty dumb question regarding a part of code in src/AI/CoreLogic.pm::processFollow function (routine, procedure or whatever it's called in perl)... well, it's actually more like okore-specific-perl-coding-help-request.

here's the part of code in question:

Code: Select all

...
		} elsif ($players_old{$args->{'ID'}}{'disappeared'}) {
 			message T("Trying to find lost master\n"), "follow", 1;

			delete $args->{'ai_follow_lost_char_last_pos'};
			delete $args->{'follow_lost_portal_tried'};
			$args->{'ai_follow_lost'} = 1;
			$args->{'ai_follow_lost_end'}{'timeout'} = $timeout{'ai_follow_lost_end'}{'timeout'};
			$args->{'ai_follow_lost_end'}{'time'} = time;
			$args->{'ai_follow_lost_vec'} = {};
			getVector($args->{'ai_follow_lost_vec'}, $players_old{$args->{'ID'}}{'pos_to'}, $chars[$config{'char'}]{'pos_to'});

			#check if player went through portal
			my $first = 1;
			my $foundID;
			my $smallDist;
			foreach (@portalsID) {
				next if (!defined $_);
				$ai_v{'temp'}{'dist'} = distance($players_old{$args->{'ID'}}{'pos_to'}, $portals{$_}{'pos'});
				if ($ai_v{'temp'}{'dist'} <= 7 && ($first || $ai_v{'temp'}{'dist'} < $smallDist)) {
					$smallDist = $ai_v{'temp'}{'dist'};
					$foundID = $_;
					undef $first;
				}
			}
			$args->{'follow_lost_portalID'} = $foundID;
		} else {
...
i beleive it's pretty brilliant idea of someone, but it seems to me that it's pretty much THAT code which completely screws up situation where bot follows someone (bot or player) it's in party with. well, i haven't yet verified my assumptions, but should be able to do it in like 1-3 days.

so, finally, the question/help request is: could anyone be so generous and kind to provide me modified condition check that could replace this one:

Code: Select all

...
		} elsif ($players_old{$args->{'ID'}}{'disappeared'}) {
...
what i want is pretty basic stuff, but still i'm not that familiar with perl/okore to do it myself. let's say now it checks <something>. i'd like the condition that'd check (<something> and <my_follow_target_is_NOT_in_party_with_me>) . if anyone could provide that to me, that'd be great - if not, i can test out my assumptions just commenting out the entire contents of this else-block, but that's obviously not the best thing to do.

thanks in advance to anyone that may bother.
obsc
Noob
Noob
Posts: 18
Joined: 11 Sep 2009, 03:58
Noob?: Yes

Re: processFollow code question

#2 Post by obsc »

well, seems like i figured it myself. thanks for help everyone ^^;;

in case anyone uses group of bots partied together set to follow another party member and is not satisfied with how openkore handles master-goes-out-of-sight situation, here is diff that helped me improve the situation:

Code: Select all

Index: src/AI/CoreLogic.pm
===================================================================
--- src/AI/CoreLogic.pm	(revision 6917)
+++ src/AI/CoreLogic.pm	(working copy)
@@ -2123,30 +2123,36 @@
 			}
 
 		} elsif ($players_old{$args->{'ID'}}{'disappeared'}) {
- 			message T("Trying to find lost master\n"), "follow", 1;
+			# [-sinny-]
+			my $partyFID = main::findPartyUserID($config{followTarget});
+			
+			if ( $partyFID eq "" )
+			{
+				message T("Trying to find lost master\n"), "follow", 1;
 
-			delete $args->{'ai_follow_lost_char_last_pos'};
-			delete $args->{'follow_lost_portal_tried'};
-			$args->{'ai_follow_lost'} = 1;
-			$args->{'ai_follow_lost_end'}{'timeout'} = $timeout{'ai_follow_lost_end'}{'timeout'};
-			$args->{'ai_follow_lost_end'}{'time'} = time;
-			$args->{'ai_follow_lost_vec'} = {};
-			getVector($args->{'ai_follow_lost_vec'}, $players_old{$args->{'ID'}}{'pos_to'}, $chars[$config{'char'}]{'pos_to'});
+				delete $args->{'ai_follow_lost_char_last_pos'};
+				delete $args->{'follow_lost_portal_tried'};
+				$args->{'ai_follow_lost'} = 1;
+				$args->{'ai_follow_lost_end'}{'timeout'} = $timeout{'ai_follow_lost_end'}{'timeout'};
+				$args->{'ai_follow_lost_end'}{'time'} = time;
+				$args->{'ai_follow_lost_vec'} = {};
+				getVector($args->{'ai_follow_lost_vec'}, $players_old{$args->{'ID'}}{'pos_to'}, $chars[$config{'char'}]{'pos_to'});
 
-			#check if player went through portal
-			my $first = 1;
-			my $foundID;
-			my $smallDist;
-			foreach (@portalsID) {
-				next if (!defined $_);
-				$ai_v{'temp'}{'dist'} = distance($players_old{$args->{'ID'}}{'pos_to'}, $portals{$_}{'pos'});
-				if ($ai_v{'temp'}{'dist'} <= 7 && ($first || $ai_v{'temp'}{'dist'} < $smallDist)) {
-					$smallDist = $ai_v{'temp'}{'dist'};
-					$foundID = $_;
-					undef $first;
+				#check if player went through portal
+				my $first = 1;
+				my $foundID;
+				my $smallDist;
+				foreach (@portalsID) {
+					next if (!defined $_);
+					$ai_v{'temp'}{'dist'} = distance($players_old{$args->{'ID'}}{'pos_to'}, $portals{$_}{'pos'});
+					if ($ai_v{'temp'}{'dist'} <= 7 && ($first || $ai_v{'temp'}{'dist'} < $smallDist)) {
+						$smallDist = $ai_v{'temp'}{'dist'};
+						$foundID = $_;
+						undef $first;
+					}
 				}
+				$args->{'follow_lost_portalID'} = $foundID;
 			}
-			$args->{'follow_lost_portalID'} = $foundID;
 		} else {
  			message T("Don't know what happened to Master\n"), "follow", 1;
 		}
p.s. yeah, i do think that inter-bot communications via in-game private messages are pretty bad way to go and therefore prefer much more natural (imo) solutions.