[Add] Very crappy autopilot.
This commit is contained in:
parent
7673c1a10a
commit
03fe164ce1
BIN
icons/autopilot.png
Normal file
BIN
icons/autopilot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 715 B |
BIN
icons/manual_control.png
Normal file
BIN
icons/manual_control.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 300 B |
@ -5,10 +5,12 @@
|
|||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
#include "world_view.h"
|
#include "world_view.h"
|
||||||
#include "space_station_view.h"
|
#include "space_station_view.h"
|
||||||
|
#include "serializer.h"
|
||||||
|
|
||||||
Player::Player(ShipType::Type shipType) : Ship(shipType) {
|
Player::Player(ShipType::Type shipType) : Ship(shipType) {
|
||||||
m_mouseCMov[0] = m_mouseCMov[1] = 0;
|
m_mouseCMov[0] = m_mouseCMov[1] = 0;
|
||||||
m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1);
|
m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1);
|
||||||
|
m_flightControlState = CONTROL_MANUAL;
|
||||||
UpdateMass();
|
UpdateMass();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,6 +19,33 @@ Player::~Player(void) {
|
|||||||
L3D::player = 0;
|
L3D::player = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::Save(void) {
|
||||||
|
using namespace Serializer::Write;
|
||||||
|
Ship::Save();
|
||||||
|
wr_int(static_cast<int>(m_flightControlState));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::Load(void) {
|
||||||
|
using namespace Serializer::Read;
|
||||||
|
Ship::Load();
|
||||||
|
m_flightControlState = static_cast<FlightControlState>(rd_int());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::SetFlightControlState(enum FlightControlState s) {
|
||||||
|
m_flightControlState = s;
|
||||||
|
if(m_flightControlState == CONTROL_AUTOPILOT) {
|
||||||
|
Body* target = GetNavTarget();
|
||||||
|
AIClearInstructions();
|
||||||
|
if(target && target->IsType(Object::SHIP)) {
|
||||||
|
AIInstruct(Ship::DO_KILL, target);
|
||||||
|
} else if(target) {
|
||||||
|
AIInstruct(Ship::DO_KILL, target);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AIClearInstructions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Player::Render(const Frame* camFrame) {
|
void Player::Render(const Frame* camFrame) {
|
||||||
if(L3D::worldView->GetCamType() == WorldView::CAM_EXTERNAL) {
|
if(L3D::worldView->GetCamType() == WorldView::CAM_EXTERNAL) {
|
||||||
Ship::Render(camFrame);
|
Ship::Render(camFrame);
|
||||||
|
@ -13,10 +13,17 @@ public:
|
|||||||
void DrawHUD(const Frame* cam_frame);
|
void DrawHUD(const Frame* cam_frame);
|
||||||
virtual void SetDockedWith(SpaceStation*, int port);
|
virtual void SetDockedWith(SpaceStation*, int port);
|
||||||
void TimeStepUpdate(const float timeStep);
|
void TimeStepUpdate(const float timeStep);
|
||||||
|
enum FlightControlState { CONTROL_MANUAL, CONTROL_AUTOPILOT };
|
||||||
|
FlightControlState GetFlightControlState(void) const { return m_flightControlState; }
|
||||||
|
void SetFlightControlState(FlightControlState s);
|
||||||
|
protected:
|
||||||
|
virtual void Save(void);
|
||||||
|
virtual void Load(void);
|
||||||
private:
|
private:
|
||||||
void DrawTargetSquares();
|
void DrawTargetSquares();
|
||||||
void DrawTargetSquare(const Body* const target);
|
void DrawTargetSquare(const Body* const target);
|
||||||
float m_mouseCMov[2];
|
float m_mouseCMov[2];
|
||||||
bool polledControlsThisTurn;
|
bool polledControlsThisTurn;
|
||||||
|
enum FlightControlState m_flightControlState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
|
|
||||||
enum AICommand { DO_NOTHING, DO_KILL };
|
enum AICommand { DO_NOTHING, DO_KILL };
|
||||||
void AIInstruct(enum AICommand, void* arg);
|
void AIInstruct(enum AICommand, void* arg);
|
||||||
void AiClearInstruction(void) { m_todo.clear(); }
|
void AIClearInstructions(void) { m_todo.clear(); }
|
||||||
virtual void PostLoadFixup(void);
|
virtual void PostLoadFixup(void);
|
||||||
protected:
|
protected:
|
||||||
virtual void Save(void);
|
virtual void Save(void);
|
||||||
|
@ -15,15 +15,15 @@ WorldView::WorldView(void): View() {
|
|||||||
float size[2];
|
float size[2];
|
||||||
GetSize(size);
|
GetSize(size);
|
||||||
|
|
||||||
labelsOn = true;
|
m_labelsOn = true;
|
||||||
m_camType = CAM_FRONT;
|
m_camType = CAM_FRONT;
|
||||||
SetTransparency(true);
|
SetTransparency(true);
|
||||||
m_externalViewRotX = m_externalViewRotY = 0;
|
m_externalViewRotX = m_externalViewRotY = 0;
|
||||||
m_externalViewDist = 200;
|
m_externalViewDist = 200;
|
||||||
|
|
||||||
commsOptions = new Fixed(size[0], size[1]/2);
|
m_commsOptions = new Fixed(size[0], size[1]/2);
|
||||||
commsOptions->SetTransparency(true);
|
m_commsOptions->SetTransparency(true);
|
||||||
Add(commsOptions, 10, 20);
|
Add(m_commsOptions, 10, 20);
|
||||||
|
|
||||||
Gui::MultiStateImageButton* wheels_button = new Gui::MultiStateImageButton();
|
Gui::MultiStateImageButton* wheels_button = new Gui::MultiStateImageButton();
|
||||||
wheels_button->SetShortcut(SDLK_F6, KMOD_NONE);
|
wheels_button->SetShortcut(SDLK_F6, KMOD_NONE);
|
||||||
@ -45,15 +45,22 @@ WorldView::WorldView(void): View() {
|
|||||||
m_hyperspaceButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickHyperspace));
|
m_hyperspaceButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickHyperspace));
|
||||||
m_rightButtonBar->Add(m_hyperspaceButton, 66, 2);
|
m_rightButtonBar->Add(m_hyperspaceButton, 66, 2);
|
||||||
|
|
||||||
launchButton = new Gui::ImageButton("icons/blastoff.png");
|
m_launchButton = new Gui::ImageButton("icons/blastoff.png");
|
||||||
launchButton->SetShortcut(SDLK_F5, KMOD_NONE);
|
m_launchButton->SetShortcut(SDLK_F5, KMOD_NONE);
|
||||||
launchButton->SetToolTip("Takeoff");
|
m_launchButton->SetToolTip("Takeoff");
|
||||||
launchButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickBlastoff));
|
m_launchButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickBlastoff));
|
||||||
m_rightButtonBar->Add(launchButton, 2, 2);
|
m_rightButtonBar->Add(m_launchButton, 2, 2);
|
||||||
|
|
||||||
flightStatus = new Gui::Label("");
|
m_flightControlButton = new Gui::MultiStateImageButton();
|
||||||
flightStatus->SetColor(1, .7, 0);
|
m_flightControlButton->SetShortcut(SDLK_F5, KMOD_NONE);
|
||||||
m_rightRegion2->Add(flightStatus, 10, 3);
|
m_flightControlButton->AddState(Player::CONTROL_MANUAL, "icons/manual_control.png", "Manual control.");
|
||||||
|
m_flightControlButton->AddState(Player::CONTROL_AUTOPILOT, "icons/autopilot.png", "Autopilot on.");
|
||||||
|
m_flightControlButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnChangeFlightState));
|
||||||
|
m_rightButtonBar->Add(m_flightControlButton, 2, 2);
|
||||||
|
|
||||||
|
m_flightStatus = new Gui::Label("");
|
||||||
|
m_flightStatus->SetColor(1, .7, 0);
|
||||||
|
m_rightRegion2->Add(m_flightStatus, 10, 3);
|
||||||
|
|
||||||
m_bgstarsDlist = glGenLists(1);
|
m_bgstarsDlist = glGenLists(1);
|
||||||
|
|
||||||
@ -118,8 +125,12 @@ void WorldView::OnChangeWheelsState(Gui::MultiStateImageButton* b) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldView::OnChangeFlightState(Gui::MultiStateImageButton* b) {
|
||||||
|
L3D::player->SetFlightControlState(static_cast<Player::FlightControlState>(b->GetState()));
|
||||||
|
}
|
||||||
|
|
||||||
void WorldView::OnChangeLabelsState(Gui::MultiStateImageButton* b) {
|
void WorldView::OnChangeLabelsState(Gui::MultiStateImageButton* b) {
|
||||||
labelsOn = b->GetState();
|
m_labelsOn = b->GetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldView::OnClickBlastoff(void) {
|
void WorldView::OnClickBlastoff(void) {
|
||||||
@ -218,26 +229,28 @@ void WorldView::Update(void) {
|
|||||||
|
|
||||||
Body* target = L3D::player->GetNavTarget();
|
Body* target = L3D::player->GetNavTarget();
|
||||||
if(target) {
|
if(target) {
|
||||||
commsOptions->ShowAll();
|
m_commsOptions->ShowAll();
|
||||||
} else {
|
} else {
|
||||||
//commsOptions->HideAll();
|
//m_commsOptions->HideAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(L3D::player->GetFlightState() == Ship::LANDED) {
|
if(L3D::player->GetFlightState() == Ship::LANDED) {
|
||||||
flightStatus->SetText("Landed");
|
m_flightStatus->SetText("Landed");
|
||||||
launchButton->Show();
|
m_launchButton->Show();
|
||||||
|
m_flightControlButton->Hide();
|
||||||
} else {
|
} else {
|
||||||
flightStatus->SetText("Manual Controls");
|
m_flightStatus->SetText("Manual Controls");
|
||||||
launchButton->Hide();
|
m_launchButton->Hide();
|
||||||
|
m_flightControlButton->Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui::Button* WorldView::AddCommsOption(std::string msg, int ypos) {
|
Gui::Button* WorldView::AddCommsOption(std::string msg, int ypos) {
|
||||||
Gui::Label* l = new Gui::Label(msg);
|
Gui::Label* l = new Gui::Label(msg);
|
||||||
commsOptions->Add(l, 50, ypos);
|
m_commsOptions->Add(l, 50, ypos);
|
||||||
|
|
||||||
Gui::TransparentButton* b = new Gui::TransparentButton();
|
Gui::TransparentButton* b = new Gui::TransparentButton();
|
||||||
commsOptions->Add(b, 16, ypos);
|
m_commsOptions->Add(b, 16, ypos);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,20 +261,20 @@ static void PlayerRequestDockingClearance(SpaceStation* s) {
|
|||||||
|
|
||||||
void WorldView::UpdateCommsOptions(void) {
|
void WorldView::UpdateCommsOptions(void) {
|
||||||
Body* const navtarget = L3D::player->GetNavTarget();
|
Body* const navtarget = L3D::player->GetNavTarget();
|
||||||
commsOptions->DeleteAllChildren();
|
m_commsOptions->DeleteAllChildren();
|
||||||
|
|
||||||
float size[2];
|
float size[2];
|
||||||
commsOptions->GetSize(size);
|
m_commsOptions->GetSize(size);
|
||||||
int ypos = size[1]-16;
|
int ypos = size[1]-16;
|
||||||
if(navtarget) {
|
if(navtarget) {
|
||||||
if(navtarget->IsType(Object::SPACESTATION)) {
|
if(navtarget->IsType(Object::SPACESTATION)) {
|
||||||
commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
m_commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
||||||
ypos -= 32;
|
ypos -= 32;
|
||||||
Gui::Button* b = AddCommsOption("Request docking clearance", ypos);
|
Gui::Button* b = AddCommsOption("Request docking clearance", ypos);
|
||||||
b->onClick.connect(sigc::bind(sigc::ptr_fun(&PlayerRequestDockingClearance), (SpaceStation*)navtarget));
|
b->onClick.connect(sigc::bind(sigc::ptr_fun(&PlayerRequestDockingClearance), (SpaceStation*)navtarget));
|
||||||
ypos -= 32;
|
ypos -= 32;
|
||||||
} else {
|
} else {
|
||||||
commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
m_commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
||||||
ypos -= 32;
|
ypos -= 32;
|
||||||
std::string msg = "Do something to "+navtarget->GetLabel();
|
std::string msg = "Do something to "+navtarget->GetLabel();
|
||||||
Gui::Button* b = AddCommsOption(msg, ypos);
|
Gui::Button* b = AddCommsOption(msg, ypos);
|
||||||
|
@ -12,7 +12,7 @@ public:
|
|||||||
virtual void Draw3D(void);
|
virtual void Draw3D(void);
|
||||||
static const float PICK_OBJECT_RECT_SIZE;
|
static const float PICK_OBJECT_RECT_SIZE;
|
||||||
void UpdateCommsOptions(void);
|
void UpdateCommsOptions(void);
|
||||||
bool GetShowLabels(void) { return labelsOn; }
|
bool GetShowLabels(void) { return m_labelsOn; }
|
||||||
void DrawBgStars(void);
|
void DrawBgStars(void);
|
||||||
vector3d GetExternalViewTranslation(void);
|
vector3d GetExternalViewTranslation(void);
|
||||||
void ApplyExternalViewRotation(matrix4x4d& m);
|
void ApplyExternalViewRotation(matrix4x4d& m);
|
||||||
@ -30,14 +30,16 @@ private:
|
|||||||
void OnClickBlastoff(void);
|
void OnClickBlastoff(void);
|
||||||
void OnChangeWheelsState(Gui::MultiStateImageButton* b);
|
void OnChangeWheelsState(Gui::MultiStateImageButton* b);
|
||||||
void OnChangeLabelsState(Gui::MultiStateImageButton* b);
|
void OnChangeLabelsState(Gui::MultiStateImageButton* b);
|
||||||
|
void OnChangeFlightState(Gui::MultiStateImageButton* b);
|
||||||
virtual bool OnMouseDown(Gui::MouseButtonEvent* e);
|
virtual bool OnMouseDown(Gui::MouseButtonEvent* e);
|
||||||
Body* PickBody(const float screenX, const float screenY) const;
|
Body* PickBody(const float screenX, const float screenY) const;
|
||||||
Gui::ImageButton* m_hyperspaceButton;
|
Gui::ImageButton* m_hyperspaceButton;
|
||||||
GLuint m_bgstarsDlist;
|
GLuint m_bgstarsDlist;
|
||||||
Gui::Fixed* commsOptions;
|
Gui::Fixed* m_commsOptions;
|
||||||
Gui::Label* flightStatus;
|
Gui::Label* m_flightStatus;
|
||||||
Gui::ImageButton* launchButton;
|
Gui::ImageButton* m_launchButton;
|
||||||
bool labelsOn;
|
Gui::MultiStateImageButton* m_flightControlButton;
|
||||||
|
bool m_labelsOn;
|
||||||
enum CamType m_camType;
|
enum CamType m_camType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user