1 package cz.cuni.amis.pogamut.ut2004.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.base.agent.navigation.IStuckDetector;
7 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
8 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
9 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
10 import cz.cuni.amis.utils.exception.PogamutException;
11
12
13
14
15
16
17
18
19
20 public abstract class AbstractUT2004PathNavigator<PATH_ELEMENT extends ILocated> implements IUT2004PathNavigator<PATH_ELEMENT>{
21
22
23
24
25
26 protected UT2004Bot bot;
27
28
29
30
31
32 protected IUT2004PathExecutorHelper<PATH_ELEMENT> executor;
33
34
35
36
37 protected Self self;
38
39 protected boolean botWaiting = false;
40
41 protected void setBotWaiting(boolean state) {
42 botWaiting = state;
43 for (IStuckDetector detector : executor.getStuckDetectors()) {
44 detector.setBotWaiting(state);
45 }
46 }
47
48 @Override
49 public void setBot(UT2004Bot bot) {
50 this.bot = bot;
51 }
52
53 @Override
54 public void setExecutor(IUT2004PathExecutorHelper<PATH_ELEMENT> owner) {
55 this.executor = owner;
56 }
57
58 @Override
59 public void navigate(ILocated focus) {
60 if (bot == null) throw new PogamutException("The 'bot' field is null (or was not set by the executor), can't navigate.", this);
61 if (executor == null) throw new PogamutException("The 'executor' field is null (ow was not set by the executor), can't navigate.", this);
62
63 int pathElementIndex = executor.getPathElementIndex();
64 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);
65 if (self == null) {
66 self = bot.getWorldView().getSingle(Self.class);
67 if (self == null) throw new PogamutException("Can't navigate the bot, no Self instance is available in the world view.", this);
68 }
69
70 navigate(focus, pathElementIndex);
71 }
72
73
74
75
76
77
78 protected abstract void navigate(ILocated focus, int pathElementIndex);
79
80 }