PoC: Conditional portals (airship)

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

Moderator: Moderators

EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

PoC: Conditional portals (airship)

#1 Post by EternalHarvest »

Code: Select all

Index: FileParsers.pm
===================================================================
--- FileParsers.pm	(revision 7634)
+++ FileParsers.pm	(working copy)
@@ -579,7 +579,7 @@
 			$$r_hash{$portal}{'dest'}{$dest}{'cost'} = $args[6];
 			$$r_hash{$portal}{'dest'}{$dest}{'steps'} = $args[7];
 			$$r_hash{$portal}{dest}{$dest}{enabled} = 1; # is available permanently (can be used when calculating a route)
-			#$$r_hash{$portal}{dest}{$dest}{active} = 1; # TODO: is available right now (otherwise, wait until it becomes available)
+			$$r_hash{$portal}{dest}{$dest}{active} = 1; # is available right now (otherwise, wait until it becomes so)
 		}
 	}
 	close FILE;
Index: Task/MapRoute.pm
===================================================================
--- Task/MapRoute.pm	(revision 7634)
+++ Task/MapRoute.pm	(working copy)
@@ -23,6 +23,8 @@
 use Task::Route;
 use Task::CalcMapRoute;
 use Task::TalkNPC;
+use Task::Chained;
+use Task::Function;
 use base qw(Task::WithSubtask);
 use Translation qw(T TF);
 use Log qw(message debug warning error);
@@ -330,14 +332,26 @@
 					# >> Then "route" to it
 					debug "Portal route within same map.\n", "route";
 					$self->{teleportTries} = 0;
-					my $task = new Task::Route(
-						x => $self->{mapSolution}[0]{pos}{x},
-						y => $self->{mapSolution}[0]{pos}{y},
-						maxTime => $self->{maxTime},
-						avoidWalls => $self->{avoidWalls},
-						solution => \@solution
-					);
-					$self->setSubtask($task);
+					$self->setSubtask(new Task::Chained(tasks => [
+						new Task::Route(
+							x => $self->{mapSolution}[0]{pos}{x},
+							y => $self->{mapSolution}[0]{pos}{y},
+							maxTime => $self->{maxTime},
+							distFromGoal => 10,
+							avoidWalls => $self->{avoidWalls},
+							solution => \@solution
+						),
+						new Task::Function(function => sub {
+							$_[0]->setDone if
+							$portals_lut{"$self->{mapSolution}[0]{map} $self->{mapSolution}[0]{pos}{x} $self->{mapSolution}[0]{pos}{y}"}
+							{dest}{"$self->{mapSolution}[0]{dest_map} $self->{mapSolution}[0]{dest_pos}{x} $self->{mapSolution}[0]{dest_pos}{y}"}
+							{active}
+						}),
+						new Task::Route(
+							x => $self->{mapSolution}[0]{pos}{x},
+							y => $self->{mapSolution}[0]{pos}{y},
+						),
+					]));
 
 				} else {
 					warning TF("No LOS from %s (%s,%s) to Portal at (%s,%s).\n",

Code: Select all

automacro air_reset_mapchange {                                                                     
        location not airplane                                                                          
        timeout 10
        call air_reset                                                                              
}                                                                                                   
automacro air_reset_takeoff {                                                                       
        console /^(?:Currently we are in .+\. The Airship will take off shortly\.|The Airship is leaving the ground\. Our next destination is .+\.)$/                                                   
        call air_reset                                                                              
}                                                                                                   
macro air_reset {                                                                                   
        air_0()                                                                                     
}                                                                                                   
automacro air_einbroch {                                                                            
        console "Welcome to Einbroch. Have a safe trip."                                            
        call {                                                                                      
                air_1('einbroch 92 278')                                                            
        }                                                                                           
}                                                                                                   
automacro air_hugel {                                                                               
        console "Welcome to Hugel. Have a safe trip."                                               
        call {                                                                                      
                air_1('hugel 181 146')                                                              
        }                                                                                           
}                                                                                                   
automacro air_lighthalzen {                                                                         
        console "Welcome to Lighthalzen. Have a safe trip."                                         
        call {                                                                                      
                air_1('lighthalzen 302 75')                                                         
        }                                                                                           
}                                                                                                   
automacro air_yuno {                                                                                
        console "Welcome to Juno. Have a safe trip."                                                
        call {                                                                                      
                air_1('yuno 92 260')                                                                
        }                                                                                           
}                                                                                                   
sub air_0 {                                                                                         
        for (values %{$portals_lut{'airplane 243 73'}{dest}}) { $_->{active} = 0 }                  
}                                                                                                   
sub air_1 {                                                                                         
        $portals_lut{'airplane 243 73'}{dest}{$_[0]}{active} = 1                                    
}
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: PoC: Conditional portals (airship)

#2 Post by kLabMouse »

Nice. ISA Stable?
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: PoC: Conditional portals (airship)

#3 Post by EternalHarvest »

Not stable, just a proof of concept. The only thing that works reliably here is waiting right before the portal.
Portal state triggers are just for testing, they should not be implemented via macro plugin.
DrKN
Developers
Developers
Posts: 79
Joined: 06 Oct 2010, 09:22
Noob?: No

Re: PoC: Conditional portals (airship)

#4 Post by DrKN »

yup... only can recognize the portal by the SYSChat...