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