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.base.agent.navigation.PathExecutorState;
7 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
8 import cz.cuni.amis.pogamut.udk.bot.impl.UDKBot;
9 import cz.cuni.amis.pogamut.udk.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 AbstractUDKPathNavigator<PATH_ELEMENT extends ILocated> implements IUDKPathNavigator<PATH_ELEMENT>{
21
22
23
24
25
26 protected UDKBot bot;
27
28
29
30
31
32 protected IPathExecutorHelper<PATH_ELEMENT> executor;
33
34
35
36
37 protected Self self;
38
39 @Override
40 public void setBot(UDKBot bot) {
41 this.bot = bot;
42 }
43
44 @Override
45 public void setExecutor(IPathExecutorHelper<PATH_ELEMENT> owner) {
46 this.executor = owner;
47 }
48
49 @Override
50 public void navigate() {
51 if (bot == null) throw new PogamutException("The 'bot' field is null (or was not set by the executor), can't navigate.", this);
52 if (executor == null) throw new PogamutException("The 'executor' field is null (ow was not set by the executor), can't navigate.", this);
53
54 if(executor.inState(PathExecutorState.STOPPED)) {
55
56
57 if(bot.getLog()!= null){
58 bot.getLog().severe("AbstractUDKPathNavigator.navigate() called, eventhough the executor is stopped. Ignoring.");
59 }
60 return;
61 }
62
63
64 int pathElementIndex = executor.getPathElementIndex();
65 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);
66 if (self == null) {
67 self = bot.getWorldView().getSingle(Self.class);
68 if (self == null) throw new PogamutException("Can't navigate the bot, no Self instance is available in the world view.", this);
69 }
70
71 navigate(pathElementIndex);
72 }
73
74
75
76
77
78
79 protected abstract void navigate(int pathElementIndex);
80
81 }