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