[Add] Some work on ship equipment.
This commit is contained in:
		
							parent
							
								
									7b92a3fdf9
								
							
						
					
					
						commit
						13c6600e20
					
				| @ -33,6 +33,11 @@ void InfoView::UpdateInfo(void) { | ||||
|                              stats->total_mass); | ||||
|   nfo += std::string(buf); | ||||
| 
 | ||||
|   e = L3D::player->m_equipment.Get(Equip::SLOT_LASER, 0); | ||||
|   nfo += std::string("\n\nFront weapon:   ")+EquipType::types[e].name; | ||||
|   e = L3D::player->m_equipment.Get(Equip::SLOT_LASER, 1); | ||||
|   nfo += std::string("\nRear weapon:    ")+EquipType::types[e].name; | ||||
| 
 | ||||
|   snprintf(buf, sizeof(buf), "\n\nHyperspace range: %.2f light years.", stats->hyperspace_range); | ||||
|   nfo += std::string(buf); | ||||
| 
 | ||||
|  | ||||
| @ -9,6 +9,7 @@ public: | ||||
|   void UpdateInfo(void); | ||||
|   virtual void Update(void); | ||||
|   virtual void Draw3D(void); | ||||
|   virtual void OnSwitchTo(void) { } | ||||
| private: | ||||
|   Gui::Label* info1; | ||||
| }; | ||||
|  | ||||
| @ -152,6 +152,7 @@ void L3D::SetMapView(enum MapView v) { | ||||
| void L3D::SetView(View* v) { | ||||
|   if(currentView) currentView->HideAll(); | ||||
|   currentView = v; | ||||
|   currentView->OnSwitchTo(); | ||||
|   currentView->ShowAll(); | ||||
| } | ||||
| 
 | ||||
| @ -206,6 +207,7 @@ void L3D::HandleEvents(void) { | ||||
|           ship->SetLabel("A friend?"); | ||||
|           ship->SetFrame(L3D::player->GetFrame()); | ||||
|           ship->SetPosition(L3D::player->GetPosition()+100.0*dir); | ||||
|           ship->SetVelocity(L3D::player->GetVelocity()); | ||||
|           Space::AddBody(ship); | ||||
|         } | ||||
|       } | ||||
| @ -332,13 +334,14 @@ static void draw_intro(float _time) { | ||||
| } | ||||
| 
 | ||||
| void L3D::Start(void) { | ||||
| 
 | ||||
|   player = new Player(ShipType::SLEEK); | ||||
|   player->m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1); | ||||
|   player->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::LASER_2MW_BEAM); | ||||
|   player->m_equipment.Set(Equip::SLOT_LASER, 1, Equip::LASER_4MW_BEAM); | ||||
|   player->SetLabel("Me"); | ||||
|   Space::AddBody(player); | ||||
| 
 | ||||
|   cpan = new ShipCpanel(); | ||||
| 
 | ||||
|   cpan              = new ShipCpanel(); | ||||
|   sectorView        = new SectorView(); | ||||
|   systemView        = new SystemView(); | ||||
|   systemInfoView    = new SystemInfoView(); | ||||
|  | ||||
| @ -10,6 +10,7 @@ public: | ||||
|   ObjectViewerView(void); | ||||
|   virtual void Update(void); | ||||
|   virtual void Draw3D(void); | ||||
|   virtual void OnSwitchTo(void) { } | ||||
| private: | ||||
|   float viewingDist; | ||||
|   Gui::Label* m_infoLabel; | ||||
|  | ||||
| @ -9,7 +9,6 @@ | ||||
| 
 | ||||
| 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(); | ||||
| } | ||||
| @ -159,8 +158,13 @@ void Player::PollControls(void) { | ||||
|     if(L3D::KeyState(SDLK_a)) SetThrusterState(ShipType::THRUSTER_LEFT,   1.0f); | ||||
|     if(L3D::KeyState(SDLK_d)) SetThrusterState(ShipType::THRUSTER_RIGHT,  1.0f); | ||||
| 
 | ||||
|     if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1); | ||||
|     else SetGunState(0,0); | ||||
|     if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) { | ||||
|       if(L3D::worldView->GetCamType() == WorldView::CAM_REAR) SetGunState(1,1); | ||||
|       else SetGunState(0,1); | ||||
|     } else { | ||||
|       SetGunState(0,0); | ||||
|       SetGunState(1,0); | ||||
|     } | ||||
| 
 | ||||
|     if(L3D::worldView->GetCamType() != WorldView::CAM_EXTERNAL) { | ||||
|       if(L3D::KeyState(SDLK_LEFT))  angThrust.y +=  1; | ||||
| @ -260,6 +264,23 @@ void Player::DrawHUD(const Frame* cam_frame) { | ||||
| 
 | ||||
|       glVertex2f(px, py+sz); | ||||
|       glVertex2f(px, py+0.5*sz); | ||||
| 
 | ||||
|       glVertex2f(px, py+sz); | ||||
|       glVertex2f(px, py+0.5*sz); | ||||
|     glEnd(); | ||||
|   } else if(L3D::worldView->GetCamType() == WorldView::CAM_REAR) { | ||||
|     float px = Gui::Screen::GetWidth()/2.0; | ||||
|     float py = Gui::Screen::GetHeight()/2.0; | ||||
|     const float sz = 0.5*HUD_CROSSHAIR_SIZE; | ||||
|     glBegin(GL_LINES); | ||||
|       glVertex2f(px-sz, py); | ||||
|       glVertex2f(px-0.5*sz, py); | ||||
| 
 | ||||
|       glVertex2f(px+sz, py); | ||||
|       glVertex2f(px+0.5*sz, py); | ||||
| 
 | ||||
|       glVertex2f(px, py-sz); | ||||
|       glVertex2f(px, py-0.5*sz); | ||||
|     glEnd(); | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -16,6 +16,7 @@ public: | ||||
|   bool GetSelectedSystem(int* sector_x, int* sector_y, int* system_idx); | ||||
|   virtual void Save(void); | ||||
|   virtual void Load(void); | ||||
|   virtual void OnSwitchTo(void) { } | ||||
| private: | ||||
|   void DrawSector(int x, int y); | ||||
|   void PutText(std::string& text); | ||||
|  | ||||
							
								
								
									
										22
									
								
								src/ship.cpp
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/ship.cpp
									
									
									
									
									
								
							| @ -44,7 +44,7 @@ void Ship::Save(void) { | ||||
|   wr_int((int)m_shipType); | ||||
|   wr_int(m_dockedWithPort); | ||||
|   wr_int(Serializer::LookupBody(m_dockedWith)); | ||||
|   printf("TODO: NOT SAVING SHIP EQUIPMENT YET!!\n"); | ||||
|   m_equipment.Save(); | ||||
|   wr_float(m_stats.hull_mass_left); | ||||
|   wr_int(m_todo.size()); | ||||
|   for(std::list<AIInstruction>::iterator i = m_todo.begin(); i != m_todo.end(); ++i) { | ||||
| @ -80,8 +80,8 @@ void Ship::Load(void) { | ||||
|   m_shipType = (ShipType::Type)rd_int(); | ||||
|   m_dockedWithPort = rd_int(); | ||||
|   m_dockedWith = (SpaceStation*)rd_int(); | ||||
|   /* TODO: */ | ||||
|   m_equipment = EquipSet(m_shipType); | ||||
|   m_equipment.Load(); | ||||
|   Init(); | ||||
|   m_stats.hull_mass_left = rd_float(); /* Must be after Init();.. */ | ||||
|   int num = rd_int(); | ||||
| @ -360,7 +360,9 @@ void Ship::TimeStepUpdate(const float timeStep) { | ||||
|     GetFrame()->GetCollisionSpace()->TraceRay(pos, dir, 10000.0, &c, GetGeom()); | ||||
|     if(c.userData1) { | ||||
|       Body* hit = static_cast<Body*>(c.userData1); | ||||
|       hit->OnDamage(this, 1000.0); | ||||
|       Equip::Type t = m_equipment.Get(Equip::SLOT_LASER, i); | ||||
|       const float damage = 100.0 * EquipType::types[t].pval; | ||||
|       hit->OnDamage(this, damage); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
| @ -403,7 +405,9 @@ void Ship::SetDockedWith(SpaceStation* s, int port) { | ||||
| } | ||||
| 
 | ||||
| void Ship::SetGunState(int idx, int state) { | ||||
|   m_gunState[idx] = state; | ||||
|   if(m_equipment.Get(Equip::SLOT_LASER, idx) != Equip::NONE) { | ||||
|     m_gunState[idx] = state; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| bool Ship::SetWheelState(bool down) { | ||||
| @ -437,7 +441,15 @@ void Ship::RenderLaserfire(void) { | ||||
|     for(int i = 0; i < ShipType::GUNMOUNT_MAX; i++) { | ||||
|       if(!m_gunState[i]) continue; | ||||
|       glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT); | ||||
|       glColor3f(1, 0, 0); | ||||
|       switch(m_equipment.Get(Equip::SLOT_LASER, i)) { | ||||
|         case Equip::LASER_2MW_BEAM: | ||||
|           glColor3f(1, .5, 0); break; | ||||
|         case Equip::LASER_4MW_BEAM: | ||||
|           glColor3f(1, 1, 0); break; | ||||
|         default: | ||||
|         case Equip::LASER_1MW_BEAM: | ||||
|           glColor3f(1, 0, 0); break; | ||||
|       } | ||||
|       glLineWidth(2.0f); | ||||
|       glBegin(GL_LINES); | ||||
|       vector3f pos = stype.gunMount[i].pos; | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| #include "ship_type.h" | ||||
| #include "serializer.h" | ||||
| 
 | ||||
| const ShipType ShipType::types[] = { | ||||
|   { | ||||
| @ -11,7 +12,7 @@ const ShipType ShipType::types[] = { | ||||
|     1e7, | ||||
|     { | ||||
|       { vector3f(0, -0.5, 0), vector3f(0, 0, -1) }, | ||||
|       { vector3f(0, 0, 0), vector3f(0, 0, 1) } | ||||
|       { vector3f(0, -0.5, 0), vector3f(0, 0, 1) } | ||||
|     }, | ||||
|     { 1, 2, 0 }, | ||||
|     100, 20, | ||||
| @ -65,6 +66,35 @@ const EquipType EquipType::types[] = { | ||||
|     "1MW beam laser", | ||||
|     Equip::SLOT_LASER, | ||||
|     1, 1 | ||||
|   }, | ||||
|   { | ||||
|     "2MW beam laser", | ||||
|     Equip::SLOT_LASER, | ||||
|     1, 2 | ||||
|   }, | ||||
|   { | ||||
|     "4MW beam laser", | ||||
|     Equip::SLOT_LASER, | ||||
|     1, 4 | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| void EquipSet::Save(void) { | ||||
|   using namespace Serializer::Write; | ||||
|   for(int i = 0; i < Equip::SLOT_MAX; i++) { | ||||
|     for(unsigned int j = 0; j < equip[i].size(); j++) { | ||||
|       wr_int(static_cast<int>(equip[i][j])); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /* Should have initialised with EquipSet(ShipType::Type) first. */ | ||||
| void EquipSet::Load(void) { | ||||
|   using namespace Serializer::Read; | ||||
|   for(int i = 0; i < Equip::SLOT_MAX; i++) { | ||||
|     for(unsigned int j = 0; j < equip[i].size(); j++) { | ||||
|       equip[i][j] = static_cast<Equip::Type>(rd_int()); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -5,14 +5,15 @@ | ||||
| 
 | ||||
| namespace Equip { | ||||
|   enum Slot { SLOT_ENGINE, SLOT_LASER, SLOT_MISSILE, SLOT_MAX }; | ||||
|   enum Type { NONE, DRIVE_INTERPLANETARY, DRIVE_CLASS1, LASER_1MW_BEAM }; | ||||
|   enum Type { NONE, DRIVE_INTERPLANETARY, DRIVE_CLASS1, | ||||
|               LASER_1MW_BEAM, LASER_2MW_BEAM, LASER_4MW_BEAM }; | ||||
| }; | ||||
| 
 | ||||
| struct ShipType { | ||||
|   enum Thruster { THRUSTER_FRONT, THRUSTER_REAR, THRUSTER_TOP, THRUSTER_BOTTOM, | ||||
|                   THRUSTER_LEFT, THRUSTER_RIGHT, THRUSTER_MAX }; | ||||
|   enum Type { SLEEK, LADYBIRD, FLOWERFAIRY }; | ||||
|   enum { GUNMOUNT_MAX = 2 }; | ||||
|   enum { GUN_FRONT, GUN_REAR, GUNMOUNT_MAX = 2 }; | ||||
| 
 | ||||
|   /*******************************/ | ||||
|   const char* name; | ||||
| @ -48,6 +49,8 @@ public: | ||||
|   void Set(Equip::Slot s, int idx, Equip::Type e) { | ||||
|     equip[s][idx] = e; | ||||
|   } | ||||
|   void Save(void); | ||||
|   void Load(void); | ||||
| private: | ||||
|   std::vector<Equip::Type> equip[Equip::SLOT_MAX]; | ||||
| }; | ||||
|  | ||||
| @ -3,7 +3,32 @@ | ||||
| #include "player.h" | ||||
| #include "world_view.h" | ||||
| 
 | ||||
| SpaceStationView::SpaceStationView(void) : View() { | ||||
| class StationSubView: public Gui::Fixed { | ||||
| public: | ||||
|   StationSubView(SpaceStationView* parent): Gui::Fixed(Gui::Screen::GetWidth(), Gui::Screen::GetHeight()-64) { | ||||
|     m_parent = parent; | ||||
|   } | ||||
| protected: | ||||
|   SpaceStationView* m_parent; | ||||
| }; | ||||
| 
 | ||||
| /**********************************************************/ | ||||
| class StationFrontView: public StationSubView { | ||||
| public: | ||||
|   StationFrontView(SpaceStationView* parent); | ||||
| private: | ||||
|   void OnClickRequestLaunch(void) { | ||||
|     L3D::player->SetDockedWith(0,0); | ||||
|     L3D::SetView(L3D::worldView); | ||||
|   } | ||||
| 
 | ||||
|   void OnClickGotoShipYard(void) { | ||||
|     m_parent->GotoShipyard(); | ||||
|   } | ||||
| }; | ||||
| /**********************************************************/ | ||||
| 
 | ||||
| StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(parent) { | ||||
|   SetTransparency(false); | ||||
| 
 | ||||
|   Gui::Label* l = new Gui::Label("Hello friend! Thankyou for docking with this space station!\n" | ||||
| @ -21,19 +46,59 @@ SpaceStationView::SpaceStationView(void) : View() { | ||||
|   Add(l, 40, size[1]-100); | ||||
| 
 | ||||
|   Gui::SolidButton* b = new Gui::SolidButton(); | ||||
|   b->onClick.connect(sigc::mem_fun(this, &SpaceStationView::OnClickRequestLaunch)); | ||||
|   b->onClick.connect(sigc::mem_fun(this, &StationFrontView::OnClickRequestLaunch)); | ||||
|   Add(b, 40, size[1]-300); | ||||
|   l = new Gui::Label("Request Launch"); | ||||
|   Add(l, 65, size[1]-300); | ||||
| 
 | ||||
|   l = new Gui::Label("Comms Link"); | ||||
|   b = new Gui::SolidButton(); | ||||
|   b->onClick.connect(sigc::mem_fun(this, &StationFrontView::OnClickGotoShipYard)); | ||||
|   Add(b, 40, size[1]-360); | ||||
|   l = new Gui::Label("Shipyard"); | ||||
|   Add(l, 65, size[1]-360); | ||||
| } | ||||
| 
 | ||||
| /**********************************************************/ | ||||
| class StationShipyardView: public StationSubView { | ||||
| public: | ||||
|   StationShipyardView(SpaceStationView* parent); | ||||
| private: | ||||
|    | ||||
| }; | ||||
| 
 | ||||
| StationShipyardView::StationShipyardView(SpaceStationView* parent): StationSubView(parent) { | ||||
|   SetTransparency(false); | ||||
| } | ||||
| /**********************************************************/ | ||||
| 
 | ||||
| 
 | ||||
| SpaceStationView::SpaceStationView(void): View() { | ||||
|   m_frontview = new StationFrontView(this); | ||||
|   m_shipyard = new StationShipyardView(this); | ||||
|   m_subview = 0; | ||||
|   SwitchView(m_frontview); | ||||
| 
 | ||||
|   Gui::Label* l = new Gui::Label("Comms Link"); | ||||
|   l->SetColor(1, .7, 0); | ||||
|   m_rightRegion2->Add(l, 10, 3); | ||||
| } | ||||
| 
 | ||||
| void SpaceStationView::OnClickRequestLaunch(void) { | ||||
|   L3D::player->SetDockedWith(0,0); | ||||
|   L3D::SetView(L3D::worldView); | ||||
| void SpaceStationView::SwitchView(StationSubView* v) { | ||||
|   if(m_subview) { | ||||
|     m_subview->HideAll(); | ||||
|     Remove(m_subview); | ||||
|   } | ||||
|   m_subview = v; | ||||
|   Add(m_subview, 0, 0); | ||||
|   m_subview->ShowAll(); | ||||
| } | ||||
| 
 | ||||
| void SpaceStationView::GotoShipyard(void) { | ||||
|   SwitchView(m_shipyard); | ||||
| } | ||||
| 
 | ||||
| void SpaceStationView::OnSwitchTo(void) { | ||||
|   SwitchView(m_frontview); | ||||
| } | ||||
| 
 | ||||
| void SpaceStationView::Draw3D(void) { | ||||
|  | ||||
| @ -3,12 +3,19 @@ | ||||
| #include "gui.h" | ||||
| #include "view.h" | ||||
| 
 | ||||
| class StationSubView; | ||||
| 
 | ||||
| class SpaceStationView : public View { | ||||
| public: | ||||
|   SpaceStationView(void); | ||||
|   virtual void Update(void); | ||||
|   virtual void Draw3D(void); | ||||
|   void GotoShipyard(void); | ||||
|   void SwitchView(StationSubView* v); | ||||
|   virtual void OnSwitchTo(void); | ||||
| private: | ||||
|   void OnClickRequestLaunch(void); | ||||
|   StationSubView* m_subview, | ||||
|     *m_frontview, | ||||
|     *m_shipyard; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -10,6 +10,7 @@ public: | ||||
|   SystemInfoView(void); | ||||
|   virtual void Update(void); | ||||
|   virtual void Draw3D(void); | ||||
|   virtual void OnSwitchTo(void) { }; | ||||
| private: | ||||
|   void SystemChanged(StarSystem* s); | ||||
|   void OnBodySelected(StarSystem::SBody* b); | ||||
|  | ||||
| @ -10,7 +10,7 @@ public: | ||||
|   virtual ~SystemView(void); | ||||
|   virtual void Update(void); | ||||
|   virtual void Draw3D(void); | ||||
| 
 | ||||
|   virtual void OnSwitchTo(void) { } | ||||
| private: | ||||
|   void PutOrbit(StarSystem::SBody* b); | ||||
|   void PutBody(StarSystem::SBody* b); | ||||
|  | ||||
| @ -39,6 +39,7 @@ | ||||
|   virtual void Update(void) = 0; | ||||
|   virtual void Save(void) { } | ||||
|   virtual void Load(void) { } | ||||
|   virtual void OnSwitchTo() = 0; | ||||
| protected: | ||||
|   /* Each view can put some buttons in the bottom right of the cpanel. */ | ||||
|   Gui::Fixed* m_rightButtonBar; | ||||
|  | ||||
| @ -10,6 +10,7 @@ public: | ||||
|   WorldView(void); | ||||
|   virtual void Update(void); | ||||
|   virtual void Draw3D(void); | ||||
|   virtual void OnSwitchTo(void) { } | ||||
|   static const float PICK_OBJECT_RECT_SIZE; | ||||
|   void UpdateCommsOptions(void); | ||||
|   bool GetShowLabels(void) { return m_labelsOn; } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Rtch90
						Rtch90