How to suspend and resume a task in the ai task queue
Moderator: Moderators
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
How to suspend and resume a task in the ai task queue
How to suspend and resume a task in the ai task queue ?
Actually, I want to insert a route task that is prio to other route tasks !
Actually, I want to insert a route task that is prio to other route tasks !
-
- Developers
- Posts: 1798
- Joined: 05 Dec 2008, 05:42
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
Tasks in the queue aren't under control of TaskManager and all the tasks which aren't on the tip of the queue aren't being processed at all. That's probably not how it should really be, it's probably for compatibility with the other (non-task) things in the queue.
Just put new route task in the queue. Consider calling $char->route(map, x, y) which would do all the work with tasks and queue for you.
Just put new route task in the queue. Consider calling $char->route(map, x, y) which would do all the work with tasks and queue for you.
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
Now, the char could travel by airplane automaticly without macros !
But one more problem....
When char is on the airplane, "he" will move to the portal of exit immediately.
Then it makes the char lands on wrong map(field)....
Now, I found some packets(0229) that are the "switch(open/close)" of the portals of exits on airplane.
They are unique ID's for each portals of exits (for landing difference fields)
I try to write a onAirplane plugin for:
1. How to hold the "route" task of char on airplane for a while, when the char on board ?
(Such as moving to some position away from the portal of exit, and to sit for wait).
2. How to wait the portal of exit of destnation to open (the "portal open" packet),
and to resume the "route" task ?
Could you tell me what can I do ?
The 0229 packets:
But one more problem....
When char is on the airplane, "he" will move to the portal of exit immediately.
Then it makes the char lands on wrong map(field)....
Now, I found some packets(0229) that are the "switch(open/close)" of the portals of exits on airplane.
They are unique ID's for each portals of exits (for landing difference fields)
I try to write a onAirplane plugin for:
1. How to hold the "route" task of char on airplane for a while, when the char on board ?
(Such as moving to some position away from the portal of exit, and to sit for wait).
2. How to wait the portal of exit of destnation to open (the "portal open" packet),
and to resume the "route" task ?
Could you tell me what can I do ?
The 0229 packets:
Code: Select all
The line for Izlude-Yuno-Rachel (airplane_01)
The portal of exit to Izlude
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 52 C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 51 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
Close
<< Received packet: 0229 [15 bytes]
0> 29 02 52 C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 51 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
The portal of exit to Yuno
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 54 C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 53 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
Close
<< Received packet: 0229 [15 bytes]
0> 29 02 54 C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 53 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
The portal of exit to Rachel (ra_fild12)
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 56 C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 55 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
Close
<< Received packet: 0229 [15 bytes]
0> 29 02 56 C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 55 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
---------------------------------------------------------------
The line for Einbroch-Yuno-Lighthalzen-Hugel (airplane)
The portal of exit to Einbroch
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 5F C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 60 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
Close
<< Received packet: 0229 [15 bytes]
0> 29 02 5F C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 60 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
The portal of exit to Yuno
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 61 C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 62 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
CLose
<< Received packet: 0229 [15 bytes]
0> 29 02 61 C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 62 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
The portal of exit to Lighthalzen
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 66 C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 67 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
Close
<< Received packet: 0229 [15 bytes]
0> 29 02 66 C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 67 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
The portal of exit to Hugel
Open
<< Received packet: 0229 [15 bytes]
0> 29 02 73 C3 00 00 00 00 00 00 00 00 00 00 00 (north exit)
0> 29 02 74 C3 00 00 00 00 00 00 00 00 00 00 00 (south exit)
Close
<< Received packet: 0229 [15 bytes]
0> 29 02 73 C3 00 00 00 00 00 00 02 00 00 00 00 (north exit)
0> 29 02 74 C3 00 00 00 00 00 00 02 00 00 00 00 (south exit)
-
- Developers
- Posts: 1798
- Joined: 05 Dec 2008, 05:42
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
Do something like http://forums.openkore.com/viewtopic.php?t=13551 and insert whatever actions you want before Task::Function in the chain.How to hold the "route" task of char on airplane for a while, when the char on board ?
(Such as moving to some position away from the portal of exit, and to sit for wait).
These packets say that portal has EFFECTSTATE_BURROW status when not active. We can use that to change ->{active} for the portal, but can we reliably determine which portal leads where if they're all on the same coordinates? We can try to map by actor ID, but it's not like they can't possibly change.to open (the "portal open" packet)
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
Sorry, I don't realy understand what you mean.EternalHarvest wrote:Do something like http://forums.openkore.com/viewtopic.php?t=13551 and insert whatever actions you want before Task::Function in the chain.
Now I know that we can use Task:Chained to combine multiple tasks into a "tasks pack".
But, What I need is to insert(not append) tasks between two mapSolutions !
Now, there is a route task with multiple mapSolutions.
If I want to insert tasks between two mapSolutions,
firstly, we have to seperate into two tasks.
Such as, seperate a T into T1 and T2.
And then, use Task:Chained to chain T1 + my Tasks + T2.
Am I right ?
If I am right, how to seperate a task ?
Last edited by sofax222 on 26 Apr 2012, 19:38, edited 1 time in total.
-
- Developers
- Posts: 1798
- Joined: 05 Dec 2008, 05:42
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
Well, task probably can be separated, but it's way easier to just create two Task::Route tasks initially, as was done in the linked patch. That's the most straightforward and easy way for the airship case, since there is distFromGoal option (and there is a working example already).Such as, seperate a T into T1 and T2.
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
As what you said, I should add code lines into the iterate function of MapRoute.pm.EternalHarvest wrote:Well, task probably can be separated, but it's way easier to just create two Task::Route tasks initially....
And the code lines should be add after:
Code: Select all
if ( Task::Route->getRoute( \@solution, $field, $self->{actor}{pos_to}, $self->{mapSolution}[0]{pos} ) ) {
# Portal is reachable from current position
# >> Then "route" to it
..........
If the $self->{mapSolution}[0]{map} is airplane, I sould add three tasks before the task that routes to the exit portal.
These three tasks are:
1. Route to somewhere on airplane.
2. To sit for waiting the open of exit portal of the desnation.
3. To stand
Am I right ?
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
I try to modify the MapRoute.pm like what you said.
Such as (call the setSubtask funtion twice):
I got the errors message:
Error message:
Assertion failed!
at /u/ro/ok3/src/deps/Carp/Assert.pm line 271
Carp::Assert::assert('') called at src/Task/WithSubtask.pm line 187
Task::WithSubtask::setSubtask('Task::MapRoute=HASH(0x80a0a1a50)', 'Task::Route=HASH(0x809dd9af8
Task::MapRoute::iterate('Task::MapRoute=HASH(0x80a0a1a50)') called at src/Actor.pm line 815
Actor::processTask('Actor::You=HASH(0x809d25240)', 'route', 'onError', 'CODE(0x806b5e618)') cal
AI::CoreLogic::iterate() called at src/functions.pl line 736
main::mainLoop_initialized() called at src/functions.pl line 70
main::mainLoop() called at src/Interface.pm line 75
Interface::mainLoop('Interface::Console::Unix=HASH(0x806f2eea0)') called at /u/ro/ok3/openkore.
main::__start() called at /u/ro/ok3/openkore.pl line 187
Stack trace:
Assertion failed!
at /u/ro/ok3/src/deps/Carp/Assert.pm line 271
Carp::Assert::assert('') called at src/Task/WithSubtask.pm line 187
Task::WithSubtask::setSubtask('Task::MapRoute=HASH(0x80a0a1a50)', 'Task::Route=HASH(0x809dd9af8
Task::MapRoute::iterate('Task::MapRoute=HASH(0x80a0a1a50)') called at src/Actor.pm line 815
Actor::processTask('Actor::You=HASH(0x809d25240)', 'route', 'onError', 'CODE(0x806b5e618)') cal
AI::CoreLogic::iterate() called at src/functions.pl line 736
main::mainLoop_initialized() called at src/functions.pl line 70
main::mainLoop() called at src/Interface.pm line 75
Interface::mainLoop('Interface::Console::Unix=HASH(0x806f2eea0)') called at /u/ro/ok3/openkore.
main::__start() called at /u/ro/ok3/openkore.pl line 187
at /u/ro/ok3/src/deps/Carp/Assert.pm line 271
Carp::Assert::assert('') called at src/Task/WithSubtask.pm line 187
Task::WithSubtask::setSubtask('Task::MapRoute=HASH(0x80a0a1a50)', 'Task::Route=HASH(0x809dd9af8
Task::MapRoute::iterate('Task::MapRoute=HASH(0x80a0a1a50)') called at src/Actor.pm line 815
Actor::processTask('Actor::You=HASH(0x809d25240)', 'route', 'onError', 'CODE(0x806b5e618)') cal
AI::CoreLogic::iterate() called at src/functions.pl line 736
main::mainLoop_initialized() called at src/functions.pl line 70
main::mainLoop() called at src/Interface.pm line 75
Interface::mainLoop('Interface::Console::Unix=HASH(0x806f2eea0)') called at /u/ro/ok3/openkore.
main::__start() called at /u/ro/ok3/openkore.pl line 187
Such as (call the setSubtask funtion twice):
Code: Select all
# Portal is reachable from current position
# >> Then "route" to it
debug "Portal route within same map.\n", "route";
$self->{teleportTries} = 0;
if ($self->{mapSolution}[0]{map} eq "airplane_01") {
my $task1 = new Task::Chained(tasks => [
new Task::Route(
actor => $self->{actor},
x => 230,
y => 58,
),
new Task::Wait(
actor => $self->{actor},
seconds => 10
),
]);
$self->setSubtask($task1);
}
my $task = new Task::Route(
actor => $self->{actor},
x => $self->{mapSolution}[0]{pos}{x},
y => $self->{mapSolution}[0]{pos}{y},
maxTime => $self->{maxTime},
avoidWalls => $self->{avoidWalls},
solution => \@solution
);
$self->setSubtask($task);
Error message:
Assertion failed!
at /u/ro/ok3/src/deps/Carp/Assert.pm line 271
Carp::Assert::assert('') called at src/Task/WithSubtask.pm line 187
Task::WithSubtask::setSubtask('Task::MapRoute=HASH(0x80a0a1a50)', 'Task::Route=HASH(0x809dd9af8
Task::MapRoute::iterate('Task::MapRoute=HASH(0x80a0a1a50)') called at src/Actor.pm line 815
Actor::processTask('Actor::You=HASH(0x809d25240)', 'route', 'onError', 'CODE(0x806b5e618)') cal
AI::CoreLogic::iterate() called at src/functions.pl line 736
main::mainLoop_initialized() called at src/functions.pl line 70
main::mainLoop() called at src/Interface.pm line 75
Interface::mainLoop('Interface::Console::Unix=HASH(0x806f2eea0)') called at /u/ro/ok3/openkore.
main::__start() called at /u/ro/ok3/openkore.pl line 187
Stack trace:
Assertion failed!
at /u/ro/ok3/src/deps/Carp/Assert.pm line 271
Carp::Assert::assert('') called at src/Task/WithSubtask.pm line 187
Task::WithSubtask::setSubtask('Task::MapRoute=HASH(0x80a0a1a50)', 'Task::Route=HASH(0x809dd9af8
Task::MapRoute::iterate('Task::MapRoute=HASH(0x80a0a1a50)') called at src/Actor.pm line 815
Actor::processTask('Actor::You=HASH(0x809d25240)', 'route', 'onError', 'CODE(0x806b5e618)') cal
AI::CoreLogic::iterate() called at src/functions.pl line 736
main::mainLoop_initialized() called at src/functions.pl line 70
main::mainLoop() called at src/Interface.pm line 75
Interface::mainLoop('Interface::Console::Unix=HASH(0x806f2eea0)') called at /u/ro/ok3/openkore.
main::__start() called at /u/ro/ok3/openkore.pl line 187
at /u/ro/ok3/src/deps/Carp/Assert.pm line 271
Carp::Assert::assert('') called at src/Task/WithSubtask.pm line 187
Task::WithSubtask::setSubtask('Task::MapRoute=HASH(0x80a0a1a50)', 'Task::Route=HASH(0x809dd9af8
Task::MapRoute::iterate('Task::MapRoute=HASH(0x80a0a1a50)') called at src/Actor.pm line 815
Actor::processTask('Actor::You=HASH(0x809d25240)', 'route', 'onError', 'CODE(0x806b5e618)') cal
AI::CoreLogic::iterate() called at src/functions.pl line 736
main::mainLoop_initialized() called at src/functions.pl line 70
main::mainLoop() called at src/Interface.pm line 75
Interface::mainLoop('Interface::Console::Unix=HASH(0x806f2eea0)') called at /u/ro/ok3/openkore.
main::__start() called at /u/ro/ok3/openkore.pl line 187
-
- Developers
- Posts: 214
- Joined: 24 Nov 2010, 03:08
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
I do more try for Task::Chained.
This time I chage to call setSubtask once only.
Such as:
Then, it works.......
But now, how to implement the "Task::Wait" task ??
Could I wait for some specific console message with the "Task::Wait" task ??
(PS: Something like the "console" condition in automacro)
This time I chage to call setSubtask once only.
Such as:
Code: Select all
# Portal is reachable from current position
# >> Then "route" to it
debug "Portal route within same map.\n", "route";
$self->{teleportTries} = 0;
my $task;
if ($self->{mapSolution}[0]{map} eq "airplane_01") {
$task = new Task::Chained(tasks => [
new Task::Route(
actor => $self->{actor},
x => 230,
y => 58,
),
new Task::Wait(
actor => $self->{actor},
seconds => 10
),
new Task::Route(
actor => $self->{actor},
x => $self->{mapSolution}[0]{pos}{x},
y => $self->{mapSolution}[0]{pos}{y},
maxTime => $self->{maxTime},
avoidWalls => $self->{avoidWalls},
solution => \@solution
),
]);
} else {
$task = new Task::Route(
actor => $self->{actor},
x => $self->{mapSolution}[0]{pos}{x},
y => $self->{mapSolution}[0]{pos}{y},
maxTime => $self->{maxTime},
avoidWalls => $self->{avoidWalls},
solution => \@solution
);
}
$self->setSubtask($task);
But now, how to implement the "Task::Wait" task ??
Could I wait for some specific console message with the "Task::Wait" task ??
(PS: Something like the "console" condition in automacro)
-
- Noob
- Posts: 12
- Joined: 18 Sep 2012, 09:49
- Noob?: Yes
Re: How to suspend and resume a task in the ai task queue
You don't prolly need to do chained task or task wait. For simplicity, you can just prevent the task from running until certain conditions are met. e.g:
I think 
edit: below works for me (just have to change Lightharlzen to Lighthalzen in maps.txt for it to work properly for lighthalzen) - used maps.txt for yuno = juno
Code: Select all
# Portal is reachable from current position
# >> Then "route" to it
# However, we are onboard Airplane or Airplane_01
# Let us do nothing unless local broadcast says
# the airplane is heading to our destination
if ($self->{mapSolution}[0]{map} =~ /[aA]irplane[\s\S]*/) {
my ($from, $to) = split /=/, $self->{mapSolution}[0]{portal};
my ($left, $right) = split /,/, $maps_lut{$portals_lut{$from}{dest}{$to}{map}.'.rsw'};
my ($map1, undef) = split /\s/, $left, 2;
my ($map2, undef) = split /\s/, $right, 2;
return unless (($map1 && $self->{localBroadcast} =~ /[\s\S]+to\s$map1[\s\S]+/)
|| ($map2 && $self->{localBroadcast} =~ /[\s\S]+to\s$map2[\s\S]+/));
}

edit: below works for me (just have to change Lightharlzen to Lighthalzen in maps.txt for it to work properly for lighthalzen) - used maps.txt for yuno = juno
Code: Select all
Index: MapRoute.pm
===================================================================
--- MapRoute.pm (revision 8230)
+++ MapRoute.pm (working copy)
@@ -110,13 +110,14 @@
my @holder = ($self);
Scalar::Util::weaken($holder[0]);
$self->{mapChangedHook} = Plugins::addHook('Network::Receive::map_changed', \&mapChanged, \@holder);
-
+ $self->{localBroadcastHook} = Plugins::addHook('packet_localBroadcast', \&localBroadcast, \@holder);
return $self;
}
sub DESTROY {
my ($self) = @_;
Plugins::delHook($self->{mapChangedHook}) if $self->{mapChangedHook};
+ Plugins::delHook($self->{localBroadcastHook}) if $self->{localBroadcastHook};
$self->SUPER::DESTROY();
}
@@ -331,6 +332,20 @@
if ( Task::Route->getRoute( \@solution, $field, $self->{actor}{pos_to}, $self->{mapSolution}[0]{pos} ) ) {
# Portal is reachable from current position
# >> Then "route" to it
+
+ # However, we are onboard Airplane or Airplane_01
+ # Let us do nothing unless local broadcast says
+ # the airplane is heading to our destination
+ if ($self->{mapSolution}[0]{map} =~ /[aA]irplane[\s\S]*/) {
+ my ($from, $to) = split /=/, $self->{mapSolution}[0]{portal};
+ my ($left, $right) = split /,/, $maps_lut{$portals_lut{$from}{dest}{$to}{map}.'.rsw'}, 2;
+ my ($map1, undef) = split /\s/, $left, 2;
+ my ($map2, undef) = split /\s/, $right, 2;
+
+ return unless (($map1 && $self->{localBroadcast} =~ /[\s\S]+to\s$map1[\s\S]+/)
+ || ($map2 && $self->{localBroadcast} =~ /[\s\S]+to\s$map2[\s\S]+/));
+ }
+
debug "Portal route within same map.\n", "route";
$self->{teleportTries} = 0;
my $task = new Task::Route(
@@ -447,4 +462,10 @@
$self->{mapChanged} = 1;
}
+sub localBroadcast {
+ my (undef, $args, $holder) = @_;
+ my $self = $holder->[0];
+ $self->{localBroadcast} = $args->{Msg};
+}
+
1;
}
Last edited by blue_crim on 18 Oct 2012, 02:09, edited 3 times in total.