2012-03-19 11:44:39 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
2012-03-09 16:08:05 +00:00
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// *
|
|
|
|
// * 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
|
2012-04-10 15:57:16 +00:00
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
// taskgoto.h
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#pragma once
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "common/misc.h"
|
|
|
|
#include "graphics/d3d/d3dengine.h"
|
2012-04-14 22:50:13 +00:00
|
|
|
|
|
|
|
|
2012-03-08 18:32:05 +00:00
|
|
|
class CInstanceManager;
|
|
|
|
class CTerrain;
|
|
|
|
class CBrain;
|
|
|
|
class CPhysics;
|
|
|
|
class CObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-11 15:28:27 +00:00
|
|
|
const int MAXPOINTS = 500;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum TaskGotoGoal
|
|
|
|
{
|
2012-04-10 15:57:16 +00:00
|
|
|
TGG_DEFAULT = -1, // default mode
|
|
|
|
TGG_STOP = 0, // goes to destination pausing with precision
|
|
|
|
TGG_EXPRESS = 1, // goes to destination without stopping
|
2012-03-08 18:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum TaskGotoCrash
|
|
|
|
{
|
2012-04-10 15:57:16 +00:00
|
|
|
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"
|
2012-03-08 18:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum TaskGotoPhase
|
|
|
|
{
|
2012-04-10 15:57:16 +00:00
|
|
|
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
|
2012-03-08 18:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CTaskGoto : public CTask
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTaskGoto(CInstanceManager* iMan, CObject* object);
|
|
|
|
~CTaskGoto();
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool EventProcess(const Event &event);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error Start(D3DVECTOR goal, float altitude, TaskGotoGoal goalMode, TaskGotoCrash crashMode);
|
|
|
|
Error IsEnded();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CObject* WormSearch(D3DVECTOR &impact);
|
|
|
|
void WormFrame(float rTime);
|
|
|
|
CObject* SearchTarget(D3DVECTOR pos, float margin);
|
2012-06-10 13:28:12 +00:00
|
|
|
bool AdjustTarget(CObject* pObj, D3DVECTOR &pos, float &distance);
|
|
|
|
bool AdjustBuilding(D3DVECTOR &pos, float margin, float &distance);
|
|
|
|
bool GetHotPoint(CObject *pObj, D3DVECTOR &pos, bool bTake, float distance, float &suppl);
|
|
|
|
bool LeakSearch(D3DVECTOR &pos, float &delay);
|
2012-03-08 18:32:05 +00:00
|
|
|
void ComputeRepulse(FPOINT &dir);
|
|
|
|
void ComputeFlyingRepulse(float &dir);
|
|
|
|
|
|
|
|
int BeamShortcut();
|
|
|
|
void BeamStart();
|
|
|
|
void BeamInit();
|
|
|
|
Error BeamSearch(const D3DVECTOR &start, const D3DVECTOR &goal, float goalRadius);
|
|
|
|
Error BeamExplore(const D3DVECTOR &prevPos, const D3DVECTOR &curPos, const D3DVECTOR &goalPos, float goalRadius, float angle, int nbDiv, float step, int i, int nbIter);
|
|
|
|
D3DVECTOR BeamPoint(const D3DVECTOR &startPoint, const D3DVECTOR &goalPoint, float angle, float step);
|
|
|
|
|
|
|
|
void BitmapDebug(const D3DVECTOR &min, const D3DVECTOR &max, const D3DVECTOR &start, const D3DVECTOR &goal);
|
2012-06-10 13:28:12 +00:00
|
|
|
bool BitmapTestLine(const D3DVECTOR &start, const D3DVECTOR &goal, float stepAngle, bool bSecond);
|
2012-03-08 18:32:05 +00:00
|
|
|
void BitmapObject();
|
|
|
|
void BitmapTerrain(const D3DVECTOR &min, const D3DVECTOR &max);
|
|
|
|
void BitmapTerrain(int minx, int miny, int maxx, int maxy);
|
2012-06-10 13:28:12 +00:00
|
|
|
bool BitmapOpen();
|
|
|
|
bool BitmapClose();
|
2012-03-08 18:32:05 +00:00
|
|
|
void BitmapSetCircle(const D3DVECTOR &pos, float radius);
|
|
|
|
void BitmapClearCircle(const D3DVECTOR &pos, float radius);
|
|
|
|
void BitmapSetDot(int rank, int x, int y);
|
|
|
|
void BitmapClearDot(int rank, int x, int y);
|
2012-06-10 13:28:12 +00:00
|
|
|
bool BitmapTestDot(int rank, int x, int y);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
D3DVECTOR m_goal;
|
|
|
|
D3DVECTOR m_goalObject;
|
|
|
|
float m_angle;
|
|
|
|
float m_altitude;
|
|
|
|
TaskGotoCrash m_crashMode;
|
|
|
|
TaskGotoGoal m_goalMode;
|
|
|
|
TaskGotoPhase m_phase;
|
|
|
|
int m_try;
|
|
|
|
Error m_error;
|
2012-06-10 13:28:12 +00:00
|
|
|
bool m_bTake;
|
2012-04-10 15:57:16 +00:00
|
|
|
float m_stopLength; // braking distance
|
2012-03-08 18:32:05 +00:00
|
|
|
float m_time;
|
|
|
|
D3DVECTOR m_pos;
|
2012-06-10 13:28:12 +00:00
|
|
|
bool m_bWorm;
|
|
|
|
bool m_bApprox;
|
2012-03-08 18:32:05 +00:00
|
|
|
float m_wormLastTime;
|
|
|
|
float m_lastDistance;
|
|
|
|
|
2012-04-10 15:57:16 +00:00
|
|
|
int m_bmSize; // width or height of the table
|
2012-03-08 18:32:05 +00:00
|
|
|
int m_bmOffset; // m_bmSize/2
|
2012-04-10 15:57:16 +00:00
|
|
|
int m_bmLine; // increment line m_bmSize/8
|
|
|
|
unsigned char* m_bmArray; // bit table
|
2012-03-08 18:32:05 +00:00
|
|
|
int m_bmMinX, m_bmMinY;
|
|
|
|
int m_bmMaxX, m_bmMaxY;
|
2012-04-10 15:57:16 +00:00
|
|
|
int m_bmTotal; // number of points in m_bmPoints
|
|
|
|
int m_bmIndex; // index in m_bmPoints
|
2012-03-08 18:32:05 +00:00
|
|
|
D3DVECTOR m_bmPoints[MAXPOINTS+2];
|
|
|
|
char m_bmIter[MAXPOINTS+2];
|
|
|
|
int m_bmIterCounter;
|
|
|
|
CObject* m_bmFretObject;
|
2012-04-10 15:57:16 +00:00
|
|
|
float m_bmFinalMove; // final advance distance
|
|
|
|
float m_bmFinalDist; // effective distance to advance
|
|
|
|
D3DVECTOR m_bmFinalPos; // initial position before advance
|
2012-03-08 18:32:05 +00:00
|
|
|
float m_bmTimeLimit;
|
|
|
|
int m_bmStep;
|
|
|
|
D3DVECTOR m_bmWatchDogPos;
|
|
|
|
float m_bmWatchDogTime;
|
2012-04-10 15:57:16 +00:00
|
|
|
D3DVECTOR m_leakPos; // initial position leak
|
2012-03-08 18:32:05 +00:00
|
|
|
float m_leakDelay;
|
|
|
|
float m_leakTime;
|
2012-06-10 13:28:12 +00:00
|
|
|
bool m_bLeakRecede;
|
2012-03-08 18:32:05 +00:00
|
|
|
};
|
|
|
|
|