1 package cz.cuni.amis.pogamut.udk.agent.navigation;
2
3 import java.util.List;
4
5 import cz.cuni.amis.pogamut.base.agent.navigation.IPathExecutorHelper;
6 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
7 import cz.cuni.amis.pogamut.udk.bot.impl.UDKBot;
8 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Self;
9 import cz.cuni.amis.utils.exception.PogamutException;
10
11
12
13
14
15
16
17
18
19 public abstract class AbstractUDKPathNavigator<PATH_ELEMENT extends ILocated> implements IUDKPathNavigator<PATH_ELEMENT>{
20
21
22
23
24
25 protected UDKBot bot;
26
27
28
29
30
31 protected IPathExecutorHelper<PATH_ELEMENT> executor;
32
33
34
35
36 protected Self self;
37
38 @Override
39 public void setBot(UDKBot bot) {
40 this.bot = bot;
41 }
42
43 @Override
44 public void setExecutor(IPathExecutorHelper<PATH_ELEMENT> owner) {
45 this.executor = owner;
46 }
47
48 @Override
49 public void navigate() {
50 if (bot == null) throw new PogamutException("The 'bot' field is null (or was not set by the executor), can't navigate.", this);
51 if (executor == null) throw new PogamutException("The 'executor' field is null (ow was not set by the executor), can't navigate.", this);
52
53 int pathElementIndex = executor.getPathElementIndex();
54 if (pathElementIndex < 0 || pathElementIndex >= executor.getPath().size()) throw new PogamutException("Can't navigate as the current path element index is out of path range (index = " + pathElementIndex + ", path.size() = " + executor.getPath().size() + ".", this);
55 if (self == null) {
56 self = bot.getWorldView().getSingle(Self.class);
57 if (self == null) throw new PogamutException("Can't navigate the bot, no Self instance is available in the world view.", this);
58 }
59
60 navigate(pathElementIndex);
61 }
62
63
64
65
66
67
68 protected abstract void navigate(int pathElementIndex);
69
70 }