[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 "world_view.h"
|
||||
#include "space_station_view.h"
|
||||
#include "serializer.h"
|
||||
|
||||
Player::Player(ShipType::Type shipType) : Ship(shipType) {
|
||||
m_mouseCMov[0] = m_mouseCMov[1] = 0;
|
||||
m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1);
|
||||
m_flightControlState = CONTROL_MANUAL;
|
||||
UpdateMass();
|
||||
}
|
||||
|
||||
@ -17,6 +19,33 @@ Player::~Player(void) {
|
||||
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) {
|
||||
if(L3D::worldView->GetCamType() == WorldView::CAM_EXTERNAL) {
|
||||
Ship::Render(camFrame);
|
||||
|
@ -13,10 +13,17 @@ public:
|
||||
void DrawHUD(const Frame* cam_frame);
|
||||
virtual void SetDockedWith(SpaceStation*, int port);
|
||||
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:
|
||||
void DrawTargetSquares();
|
||||
void DrawTargetSquare(const Body* const target);
|
||||
float m_mouseCMov[2];
|
||||
bool polledControlsThisTurn;
|
||||
enum FlightControlState m_flightControlState;
|
||||
};
|
||||
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
|
||||
enum AICommand { DO_NOTHING, DO_KILL };
|
||||
void AIInstruct(enum AICommand, void* arg);
|
||||
void AiClearInstruction(void) { m_todo.clear(); }
|
||||
void AIClearInstructions(void) { m_todo.clear(); }
|
||||
virtual void PostLoadFixup(void);
|
||||
protected:
|
||||
virtual void Save(void);
|
||||
|
@ -15,15 +15,15 @@ WorldView::WorldView(void): View() {
|
||||
float size[2];
|
||||
GetSize(size);
|
||||
|
||||
labelsOn = true;
|
||||
m_labelsOn = true;
|
||||
m_camType = CAM_FRONT;
|
||||
SetTransparency(true);
|
||||
m_externalViewRotX = m_externalViewRotY = 0;
|
||||
m_externalViewDist = 200;
|
||||
|
||||
commsOptions = new Fixed(size[0], size[1]/2);
|
||||
commsOptions->SetTransparency(true);
|
||||
Add(commsOptions, 10, 20);
|
||||
m_commsOptions = new Fixed(size[0], size[1]/2);
|
||||
m_commsOptions->SetTransparency(true);
|
||||
Add(m_commsOptions, 10, 20);
|
||||
|
||||
Gui::MultiStateImageButton* wheels_button = new Gui::MultiStateImageButton();
|
||||
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_rightButtonBar->Add(m_hyperspaceButton, 66, 2);
|
||||
|
||||
launchButton = new Gui::ImageButton("icons/blastoff.png");
|
||||
launchButton->SetShortcut(SDLK_F5, KMOD_NONE);
|
||||
launchButton->SetToolTip("Takeoff");
|
||||
launchButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickBlastoff));
|
||||
m_rightButtonBar->Add(launchButton, 2, 2);
|
||||
m_launchButton = new Gui::ImageButton("icons/blastoff.png");
|
||||
m_launchButton->SetShortcut(SDLK_F5, KMOD_NONE);
|
||||
m_launchButton->SetToolTip("Takeoff");
|
||||
m_launchButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickBlastoff));
|
||||
m_rightButtonBar->Add(m_launchButton, 2, 2);
|
||||
|
||||
flightStatus = new Gui::Label("");
|
||||
flightStatus->SetColor(1, .7, 0);
|
||||
m_rightRegion2->Add(flightStatus, 10, 3);
|
||||
m_flightControlButton = new Gui::MultiStateImageButton();
|
||||
m_flightControlButton->SetShortcut(SDLK_F5, KMOD_NONE);
|
||||
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);
|
||||
|
||||
@ -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) {
|
||||
labelsOn = b->GetState();
|
||||
m_labelsOn = b->GetState();
|
||||
}
|
||||
|
||||
void WorldView::OnClickBlastoff(void) {
|
||||
@ -218,26 +229,28 @@ void WorldView::Update(void) {
|
||||
|
||||
Body* target = L3D::player->GetNavTarget();
|
||||
if(target) {
|
||||
commsOptions->ShowAll();
|
||||
m_commsOptions->ShowAll();
|
||||
} else {
|
||||
//commsOptions->HideAll();
|
||||
//m_commsOptions->HideAll();
|
||||
}
|
||||
|
||||
if(L3D::player->GetFlightState() == Ship::LANDED) {
|
||||
flightStatus->SetText("Landed");
|
||||
launchButton->Show();
|
||||
m_flightStatus->SetText("Landed");
|
||||
m_launchButton->Show();
|
||||
m_flightControlButton->Hide();
|
||||
} else {
|
||||
flightStatus->SetText("Manual Controls");
|
||||
launchButton->Hide();
|
||||
m_flightStatus->SetText("Manual Controls");
|
||||
m_launchButton->Hide();
|
||||
m_flightControlButton->Show();
|
||||
}
|
||||
}
|
||||
|
||||
Gui::Button* WorldView::AddCommsOption(std::string msg, int ypos) {
|
||||
Gui::Label* l = new Gui::Label(msg);
|
||||
commsOptions->Add(l, 50, ypos);
|
||||
m_commsOptions->Add(l, 50, ypos);
|
||||
|
||||
Gui::TransparentButton* b = new Gui::TransparentButton();
|
||||
commsOptions->Add(b, 16, ypos);
|
||||
m_commsOptions->Add(b, 16, ypos);
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -248,20 +261,20 @@ static void PlayerRequestDockingClearance(SpaceStation* s) {
|
||||
|
||||
void WorldView::UpdateCommsOptions(void) {
|
||||
Body* const navtarget = L3D::player->GetNavTarget();
|
||||
commsOptions->DeleteAllChildren();
|
||||
m_commsOptions->DeleteAllChildren();
|
||||
|
||||
float size[2];
|
||||
commsOptions->GetSize(size);
|
||||
m_commsOptions->GetSize(size);
|
||||
int ypos = size[1]-16;
|
||||
if(navtarget) {
|
||||
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;
|
||||
Gui::Button* b = AddCommsOption("Request docking clearance", ypos);
|
||||
b->onClick.connect(sigc::bind(sigc::ptr_fun(&PlayerRequestDockingClearance), (SpaceStation*)navtarget));
|
||||
ypos -= 32;
|
||||
} else {
|
||||
commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
||||
m_commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
||||
ypos -= 32;
|
||||
std::string msg = "Do something to "+navtarget->GetLabel();
|
||||
Gui::Button* b = AddCommsOption(msg, ypos);
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
virtual void Draw3D(void);
|
||||
static const float PICK_OBJECT_RECT_SIZE;
|
||||
void UpdateCommsOptions(void);
|
||||
bool GetShowLabels(void) { return labelsOn; }
|
||||
bool GetShowLabels(void) { return m_labelsOn; }
|
||||
void DrawBgStars(void);
|
||||
vector3d GetExternalViewTranslation(void);
|
||||
void ApplyExternalViewRotation(matrix4x4d& m);
|
||||
@ -30,14 +30,16 @@ private:
|
||||
void OnClickBlastoff(void);
|
||||
void OnChangeWheelsState(Gui::MultiStateImageButton* b);
|
||||
void OnChangeLabelsState(Gui::MultiStateImageButton* b);
|
||||
void OnChangeFlightState(Gui::MultiStateImageButton* b);
|
||||
virtual bool OnMouseDown(Gui::MouseButtonEvent* e);
|
||||
Body* PickBody(const float screenX, const float screenY) const;
|
||||
Gui::ImageButton* m_hyperspaceButton;
|
||||
GLuint m_bgstarsDlist;
|
||||
Gui::Fixed* commsOptions;
|
||||
Gui::Label* flightStatus;
|
||||
Gui::ImageButton* launchButton;
|
||||
bool labelsOn;
|
||||
enum CamType m_camType;
|
||||
Gui::ImageButton* m_hyperspaceButton;
|
||||
GLuint m_bgstarsDlist;
|
||||
Gui::Fixed* m_commsOptions;
|
||||
Gui::Label* m_flightStatus;
|
||||
Gui::ImageButton* m_launchButton;
|
||||
Gui::MultiStateImageButton* m_flightControlButton;
|
||||
bool m_labelsOn;
|
||||
enum CamType m_camType;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user