Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
taskgoto.h
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // *
4 // * This program is free software: you can redistribute it and/or modify
5 // * it under the terms of the GNU General Public License as published by
6 // * the Free Software Foundation, either version 3 of the License, or
7 // * (at your option) any later version.
8 // *
9 // * This program is distributed in the hope that it will be useful,
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // * GNU General Public License for more details.
13 // *
14 // * You should have received a copy of the GNU General Public License
15 // * along with this program. If not, see http://www.gnu.org/licenses/.
16 
17 // taskgoto.h
18 
19 #pragma once
20 
21 
22 #include "object/task/task.h"
23 
24 #include "math/vector.h"
25 
26 
27 
28 const int MAXPOINTS = 500;
29 
30 
31 
32 enum TaskGotoGoal
33 {
34  TGG_DEFAULT = -1, // default mode
35  TGG_STOP = 0, // goes to destination pausing with precision
36  TGG_EXPRESS = 1, // goes to destination without stopping
37 };
38 
39 enum TaskGotoCrash
40 {
41  TGC_DEFAULT = -1, // default mode
42  TGC_HALT = 0, // stops if collision
43  TGC_RIGHTLEFT = 1, // right-left
44  TGC_LEFTRIGHT = 2, // left-right
45  TGC_LEFT = 3, // left
46  TGC_RIGHT = 4, // right
47  TGC_BEAM = 5, // algorithm "sunlight"
48 };
49 
50 
51 enum TaskGotoPhase
52 {
53  TGP_ADVANCE = 1, // advance
54  TGP_LAND = 2, // landed
55  TGP_TURN = 3, // turns to finish
56  TGP_MOVE = 4, // advance to finish
57  TGP_CRWAIT = 5, // waits after collision
58  TGP_CRTURN = 6, // turns right after collision
59  TGP_CRADVANCE = 7, // advance to the right after collision
60  TGP_CLWAIT = 8, // waits after collision
61  TGP_CLTURN = 9, // turns left after collision
62  TGP_CLADVANCE = 10, // advance to the left after collision
63  TGP_BEAMLEAK = 11, // beam: leak (leaking)
64  TGP_BEAMSEARCH = 12, // beam: search
65  TGP_BEAMWCOLD = 13, // beam: expects cool reactor
66  TGP_BEAMUP = 14, // beam: off
67  TGP_BEAMGOTO = 15, // beam: goto dot list
68  TGP_BEAMDOWN = 16, // beam: landed
69 };
70 
71 
72 
73 class CTaskGoto : public CTask
74 {
75 public:
76  CTaskGoto(CObject* object);
77  ~CTaskGoto();
78 
79  bool EventProcess(const Event &event);
80 
81  Error Start(Math::Vector goal, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode);
82  Error IsEnded();
83 
84 protected:
85  CObject* WormSearch(Math::Vector &impact);
86  void WormFrame(float rTime);
87  CObject* SearchTarget(Math::Vector pos, float margin);
88  bool AdjustTarget(CObject* pObj, Math::Vector &pos, float &distance);
89  bool AdjustBuilding(Math::Vector &pos, float margin, float &distance);
90  bool GetHotPoint(CObject *pObj, Math::Vector &pos, bool bTake, float distance, float &suppl);
91  bool LeakSearch(Math::Vector &pos, float &delay);
92  void ComputeRepulse(Math::Point &dir);
93  void ComputeFlyingRepulse(float &dir);
94 
95  int BeamShortcut();
96  void BeamStart();
97  void BeamInit();
98  Error BeamSearch(const Math::Vector &start, const Math::Vector &goal, float goalRadius);
99  Error BeamExplore(const Math::Vector &prevPos, const Math::Vector &curPos, const Math::Vector &goalPos, float goalRadius, float angle, int nbDiv, float step, int i, int nbIter);
100  Math::Vector BeamPoint(const Math::Vector &startPoint, const Math::Vector &goalPoint, float angle, float step);
101 
102  void BitmapDebug(const Math::Vector &min, const Math::Vector &max, const Math::Vector &start, const Math::Vector &goal);
103  bool BitmapTestLine(const Math::Vector &start, const Math::Vector &goal, float stepAngle, bool bSecond);
104  void BitmapObject();
105  void BitmapTerrain(const Math::Vector &min, const Math::Vector &max);
106  void BitmapTerrain(int minx, int miny, int maxx, int maxy);
107  bool BitmapOpen();
108  bool BitmapClose();
109  void BitmapSetCircle(const Math::Vector &pos, float radius);
110  void BitmapClearCircle(const Math::Vector &pos, float radius);
111  void BitmapSetDot(int rank, int x, int y);
112  void BitmapClearDot(int rank, int x, int y);
113  bool BitmapTestDot(int rank, int x, int y);
114 
115 protected:
116  Math::Vector m_goal;
117  Math::Vector m_goalObject;
118  float m_angle;
119  float m_altitude;
120  TaskGotoCrash m_crashMode;
121  TaskGotoGoal m_goalMode;
122  TaskGotoPhase m_phase;
123  int m_try;
124  Error m_error;
125  bool m_bTake;
126  float m_stopLength; // braking distance
127  float m_time;
128  Math::Vector m_pos;
129  bool m_bWorm;
130  bool m_bApprox;
131  float m_wormLastTime;
132  float m_lastDistance;
133 
134  int m_bmSize; // width or height of the table
135  int m_bmOffset; // m_bmSize/2
136  int m_bmLine; // increment line m_bmSize/8
137  unsigned char* m_bmArray; // bit table
138  int m_bmMinX, m_bmMinY;
139  int m_bmMaxX, m_bmMaxY;
140  int m_bmTotal; // number of points in m_bmPoints
141  int m_bmIndex; // index in m_bmPoints
142  Math::Vector m_bmPoints[MAXPOINTS+2];
143  char m_bmIter[MAXPOINTS+2];
144  int m_bmIterCounter;
145  CObject* m_bmFretObject;
146  float m_bmFinalMove; // final advance distance
147  float m_bmFinalDist; // effective distance to advance
148  Math::Vector m_bmFinalPos; // initial position before advance
149  float m_bmTimeLimit;
150  int m_bmStep;
151  Math::Vector m_bmWatchDogPos;
152  float m_bmWatchDogTime;
153  Math::Vector m_leakPos; // initial position leak
154  float m_leakDelay;
155  float m_leakTime;
156  bool m_bLeakRecede;
157 };
158 
2D point
Definition: point.h:46
Vector struct and related functions.
Definition: task.h:61
Error
Type of error or info message.
Definition: global.h:29
3D (3x1) vector
Definition: vector.h:49
Event sent by system, interface or game.
Definition: event.h:687
Definition: taskgoto.h:73
Definition: object.h:372