[Move] AI stuff could be useful for autopilot, so moved to Ship.
This commit is contained in:
		
							parent
							
								
									3505b14b39
								
							
						
					
					
						commit
						bb735a1204
					
				@ -10,7 +10,7 @@ include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h
 | 
				
			|||||||
		planet.h player.h dynamic_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \
 | 
							planet.h player.h dynamic_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \
 | 
				
			||||||
		system_view.h vector3.h view.h world_view.h date.h space_station.h space_station_view.h model_body.h gui_iselectable.h \
 | 
							system_view.h vector3.h view.h world_view.h date.h space_station.h space_station_view.h model_body.h gui_iselectable.h \
 | 
				
			||||||
		ship_type.h object.h info_view.h model_coll_mesh_data.h object_viewer_view.h fixed.h custom_starsystems.h gameconsts.h \
 | 
							ship_type.h object.h info_view.h model_coll_mesh_data.h object_viewer_view.h fixed.h custom_starsystems.h gameconsts.h \
 | 
				
			||||||
		aabb.h serializer.h sfx.h ai_ship.h
 | 
							aabb.h serializer.h sfx.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
libgui_a_SOURCES = gui_button.cpp gui.cpp gui_fixed.cpp gui_screen.cpp gui_label.cpp gui_toggle_button.cpp gui_radio_button.cpp \
 | 
					libgui_a_SOURCES = gui_button.cpp gui.cpp gui_fixed.cpp gui_screen.cpp gui_label.cpp gui_toggle_button.cpp gui_radio_button.cpp \
 | 
				
			||||||
									 gui_radio_group.cpp gui_image_button.cpp gui_image.cpp gui_image_radio_button.cpp gui_multi_state_image_button.cpp gui_widget.cpp \
 | 
														 gui_radio_group.cpp gui_image_button.cpp gui_image.cpp gui_image_radio_button.cpp gui_multi_state_image_button.cpp gui_widget.cpp \
 | 
				
			||||||
@ -20,7 +20,7 @@ Lephisto3D_SOURCES	= main.cpp glfreetype.cpp body.cpp space.cpp ship.cpp player.
 | 
				
			|||||||
											star.cpp frame.cpp ship_cpanel.cpp sector_view.cpp mtrand.cpp world_view.cpp system_view.cpp \
 | 
																star.cpp frame.cpp ship_cpanel.cpp sector_view.cpp mtrand.cpp world_view.cpp system_view.cpp \
 | 
				
			||||||
											star_system.cpp sector.cpp system_info_view.cpp generic_system_view.cpp date.cpp space_station.cpp \
 | 
																star_system.cpp sector.cpp system_info_view.cpp generic_system_view.cpp date.cpp space_station.cpp \
 | 
				
			||||||
											space_station_view.cpp model_body.cpp ship_type.cpp info_view.cpp model_coll_mesh_data.cpp \
 | 
																space_station_view.cpp model_body.cpp ship_type.cpp info_view.cpp model_coll_mesh_data.cpp \
 | 
				
			||||||
											object_viewer_view.cpp custom_starsystems.cpp serializer.cpp sfx.cpp ai_ship.cpp
 | 
																object_viewer_view.cpp custom_starsystems.cpp serializer.cpp sfx.cpp
 | 
				
			||||||
Lephisto3D_LDADD = sbre/libsbre.a collider/libcollider.a libgui.a
 | 
					Lephisto3D_LDADD = sbre/libsbre.a collider/libcollider.a libgui.a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ModelViewer_SOURCES = sbre_viewer.cpp glfreetype.cpp
 | 
					ModelViewer_SOURCES = sbre_viewer.cpp glfreetype.cpp
 | 
				
			||||||
 | 
				
			|||||||
@ -1,77 +0,0 @@
 | 
				
			|||||||
#include "libs.h"
 | 
					 | 
				
			||||||
#include "ai_ship.h"
 | 
					 | 
				
			||||||
#include "serializer.h"
 | 
					 | 
				
			||||||
#include "l3d.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool AIShip::DoKill(const Ship* enemy) {
 | 
					 | 
				
			||||||
  /* Need to deal with frames, large distances, and success! */
 | 
					 | 
				
			||||||
  if(GetFrame() == enemy->GetFrame()) {
 | 
					 | 
				
			||||||
    vector3d dir = vector3d::Normalize(enemy->GetPosition() - GetPosition());
 | 
					 | 
				
			||||||
    AIFaceDirection(dir);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  return false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AIShip::TimeStepUpdate(const float timeStep) {
 | 
					 | 
				
			||||||
  bool done = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if(m_todo.size() != 0) {
 | 
					 | 
				
			||||||
    Instruction& inst = m_todo.front();
 | 
					 | 
				
			||||||
    switch(inst.cmd) {
 | 
					 | 
				
			||||||
      case DO_KILL:
 | 
					 | 
				
			||||||
        done = DoKill(static_cast<const Ship*>(inst.arg));
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
      case DO_NOTHING: done = true; break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if(done) {
 | 
					 | 
				
			||||||
    printf("AI '%s' successfully executed %d:'%s'\n", GetLabel().c_str(), m_todo.front().cmd,
 | 
					 | 
				
			||||||
        static_cast<Ship*>(m_todo.front().arg)->GetLabel().c_str());
 | 
					 | 
				
			||||||
    m_todo.pop_front();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  Ship::TimeStepUpdate(timeStep);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AIShip::Save(void) {
 | 
					 | 
				
			||||||
  using namespace Serializer::Write;
 | 
					 | 
				
			||||||
  Ship::Save();
 | 
					 | 
				
			||||||
  wr_int(m_todo.size());
 | 
					 | 
				
			||||||
  for(std::list<Instruction>::iterator i = m_todo.begin(); i != m_todo.end(); ++i) {
 | 
					 | 
				
			||||||
    wr_int((int)(*i).cmd);
 | 
					 | 
				
			||||||
    switch((*i).cmd) {
 | 
					 | 
				
			||||||
      case DO_KILL:
 | 
					 | 
				
			||||||
        wr_int(Serializer::LookupBody(static_cast<Ship*>((*i).arg)));
 | 
					 | 
				
			||||||
      case DO_NOTHING: wr_int(0); break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AIShip::Load(void) {
 | 
					 | 
				
			||||||
  using namespace Serializer::Read;
 | 
					 | 
				
			||||||
  Ship::Load();
 | 
					 | 
				
			||||||
  int num = rd_int();
 | 
					 | 
				
			||||||
  while(num-- > 0) {
 | 
					 | 
				
			||||||
    Command c= (Command)rd_int();
 | 
					 | 
				
			||||||
    void* arg = (void*)rd_int();
 | 
					 | 
				
			||||||
    printf("COMMAND %d:%p\n", c, arg);
 | 
					 | 
				
			||||||
    m_todo.push_back(Instruction(c, arg));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AIShip::PostLoadFixup(void) {
 | 
					 | 
				
			||||||
  Ship::PostLoadFixup();
 | 
					 | 
				
			||||||
  for(std::list<Instruction>::iterator i = m_todo.begin(); i != m_todo.end(); ++i) {
 | 
					 | 
				
			||||||
    switch((*i).cmd) {
 | 
					 | 
				
			||||||
      case DO_KILL:
 | 
					 | 
				
			||||||
        (*i).arg = Serializer::LookupBody((size_t)(*i).arg);
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
      case DO_NOTHING: break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void AIShip::Instruct(enum Command cmd, void* arg) {
 | 
					 | 
				
			||||||
  m_todo.push_back(Instruction(cmd, arg));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,32 +0,0 @@
 | 
				
			|||||||
#pragma once
 | 
					 | 
				
			||||||
#include <list>
 | 
					 | 
				
			||||||
#include "ship.h"
 | 
					 | 
				
			||||||
#include "ship_type.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class AIShip: public Ship {
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
  OBJDEF(AIShip, Ship, AISHIP);
 | 
					 | 
				
			||||||
  AIShip(ShipType::Type shipType): Ship(shipType) { }
 | 
					 | 
				
			||||||
  AIShip(void): Ship() { }
 | 
					 | 
				
			||||||
  void TimeStepUpdate(const float timeStep);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  enum Command { DO_NOTHING, DO_KILL };
 | 
					 | 
				
			||||||
  void Instruct(enum Command, void* arg);
 | 
					 | 
				
			||||||
  void ClearInstructions(void) { m_todo.clear(); }
 | 
					 | 
				
			||||||
  virtual void PostLoadFixup(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
protected:
 | 
					 | 
				
			||||||
  virtual void Save(void);
 | 
					 | 
				
			||||||
  virtual void Load(void);
 | 
					 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
  bool DoKill(const Ship*);
 | 
					 | 
				
			||||||
  class Instruction {
 | 
					 | 
				
			||||||
  public:
 | 
					 | 
				
			||||||
    Command cmd;
 | 
					 | 
				
			||||||
    void* arg;
 | 
					 | 
				
			||||||
    Instruction(Command c, void* a): cmd(c), arg(a) { }
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  std::list<Instruction> m_todo;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -6,7 +6,6 @@
 | 
				
			|||||||
#include "planet.h"
 | 
					#include "planet.h"
 | 
				
			||||||
#include "space_station.h"
 | 
					#include "space_station.h"
 | 
				
			||||||
#include "ship.h"
 | 
					#include "ship.h"
 | 
				
			||||||
#include "ai_ship.h"
 | 
					 | 
				
			||||||
#include "player.h"
 | 
					#include "player.h"
 | 
				
			||||||
#include "sfx.h"
 | 
					#include "sfx.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -49,7 +48,6 @@ void Body::Serialize(void) {
 | 
				
			|||||||
    case Object::PLANET:
 | 
					    case Object::PLANET:
 | 
				
			||||||
    case Object::SPACESTATION:
 | 
					    case Object::SPACESTATION:
 | 
				
			||||||
    case Object::SHIP:
 | 
					    case Object::SHIP:
 | 
				
			||||||
    case Object::AISHIP:
 | 
					 | 
				
			||||||
    case Object::PLAYER:
 | 
					    case Object::PLAYER:
 | 
				
			||||||
    case Object::SFX:
 | 
					    case Object::SFX:
 | 
				
			||||||
      Save();
 | 
					      Save();
 | 
				
			||||||
@ -76,8 +74,6 @@ Body* Body::Unserialize(void) {
 | 
				
			|||||||
      b = new SpaceStation(); break;
 | 
					      b = new SpaceStation(); break;
 | 
				
			||||||
    case Object::SHIP:
 | 
					    case Object::SHIP:
 | 
				
			||||||
      b = new Ship(); break;
 | 
					      b = new Ship(); break;
 | 
				
			||||||
    case Object::AISHIP:
 | 
					 | 
				
			||||||
      b = new AIShip(); break;
 | 
					 | 
				
			||||||
    case Object::PLAYER:
 | 
					    case Object::PLAYER:
 | 
				
			||||||
      b = new Player(); break;
 | 
					      b = new Player(); break;
 | 
				
			||||||
    case Object::SFX:
 | 
					    case Object::SFX:
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,6 @@
 | 
				
			|||||||
#include "space_station_view.h"
 | 
					#include "space_station_view.h"
 | 
				
			||||||
#include "info_view.h"
 | 
					#include "info_view.h"
 | 
				
			||||||
#include "serializer.h"
 | 
					#include "serializer.h"
 | 
				
			||||||
#include "ai_ship.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
float             L3D::timeAccel = 1.0f;
 | 
					float             L3D::timeAccel = 1.0f;
 | 
				
			||||||
int               L3D::scrWidth;
 | 
					int               L3D::scrWidth;
 | 
				
			||||||
@ -202,8 +201,8 @@ void L3D::HandleEvents(void) {
 | 
				
			|||||||
          station->SetPosition(L3D::player->GetPosition()+5000.0*dir);
 | 
					          station->SetPosition(L3D::player->GetPosition()+5000.0*dir);
 | 
				
			||||||
          Space::AddBody(station);
 | 
					          Space::AddBody(station);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          AIShip* ship = new AIShip(ShipType::LADYBIRD);
 | 
					          Ship* ship = new Ship(ShipType::LADYBIRD);
 | 
				
			||||||
          ship->Instruct(AIShip::DO_KILL, L3D::player);
 | 
					          ship->AIInstruct(Ship::DO_KILL, L3D::player);
 | 
				
			||||||
          ship->SetLabel("A friend?");
 | 
					          ship->SetLabel("A friend?");
 | 
				
			||||||
          ship->SetFrame(L3D::player->GetFrame());
 | 
					          ship->SetFrame(L3D::player->GetFrame());
 | 
				
			||||||
          ship->SetPosition(L3D::player->GetPosition()+100.0*dir);
 | 
					          ship->SetPosition(L3D::player->GetPosition()+100.0*dir);
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class Object {
 | 
					class Object {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  enum Type { OBJECT, BODY, MODELBODY, DYNAMICBODY, SHIP, PLAYER, SPACESTATION, PLANET, STAR, SFX, AISHIP };
 | 
					  enum Type { OBJECT, BODY, MODELBODY, DYNAMICBODY, SHIP, PLAYER, SPACESTATION, PLANET, STAR, SFX };
 | 
				
			||||||
  virtual Type GetType(void) { return OBJECT; }
 | 
					  virtual Type GetType(void) { return OBJECT; }
 | 
				
			||||||
  virtual bool IsType(Type c) { return GetType() == c; }
 | 
					  virtual bool IsType(Type c) { return GetType() == c; }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										58
									
								
								src/ship.cpp
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								src/ship.cpp
									
									
									
									
									
								
							@ -46,6 +46,16 @@ void Ship::Save(void) {
 | 
				
			|||||||
  wr_int(Serializer::LookupBody(m_dockedWith));
 | 
					  wr_int(Serializer::LookupBody(m_dockedWith));
 | 
				
			||||||
  printf("TODO: NOT SAVING SHIP EQUIPMENT YET!!\n");
 | 
					  printf("TODO: NOT SAVING SHIP EQUIPMENT YET!!\n");
 | 
				
			||||||
  wr_float(m_stats.hull_mass_left);
 | 
					  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) {
 | 
				
			||||||
 | 
					    wr_int((int)(*i).cmd);
 | 
				
			||||||
 | 
					    switch((*i).cmd) {
 | 
				
			||||||
 | 
					      case DO_KILL:
 | 
				
			||||||
 | 
					        wr_int(Serializer::LookupBody(static_cast<Ship*>((*i).arg)));
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case DO_NOTHING: wr_int(0); break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Ship::Load(void) {
 | 
					void Ship::Load(void) {
 | 
				
			||||||
@ -74,6 +84,13 @@ void Ship::Load(void) {
 | 
				
			|||||||
  m_equipment = EquipSet(m_shipType);
 | 
					  m_equipment = EquipSet(m_shipType);
 | 
				
			||||||
  Init();
 | 
					  Init();
 | 
				
			||||||
  m_stats.hull_mass_left = rd_float(); /* Must be after Init();.. */
 | 
					  m_stats.hull_mass_left = rd_float(); /* Must be after Init();.. */
 | 
				
			||||||
 | 
					  int num = rd_int();
 | 
				
			||||||
 | 
					  while(num-- > 0) {
 | 
				
			||||||
 | 
					    AICommand c = (AICommand)rd_int();
 | 
				
			||||||
 | 
					    void* arg = (void*)rd_int();
 | 
				
			||||||
 | 
					    printf("COMMAND %d:%p\n", c, arg);
 | 
				
			||||||
 | 
					    m_todo.push_back(AIInstruction(c, arg));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Ship::Init(void) {
 | 
					void Ship::Init(void) {
 | 
				
			||||||
@ -88,6 +105,14 @@ void Ship::PostLoadFixup(void) {
 | 
				
			|||||||
  m_combatTarget = Serializer::LookupBody((size_t)m_combatTarget);
 | 
					  m_combatTarget = Serializer::LookupBody((size_t)m_combatTarget);
 | 
				
			||||||
  m_navTarget = Serializer::LookupBody((size_t)m_navTarget);
 | 
					  m_navTarget = Serializer::LookupBody((size_t)m_navTarget);
 | 
				
			||||||
  m_dockedWith = (SpaceStation*)Serializer::LookupBody((size_t)m_dockedWith);
 | 
					  m_dockedWith = (SpaceStation*)Serializer::LookupBody((size_t)m_dockedWith);
 | 
				
			||||||
 | 
					  for(std::list<AIInstruction>::iterator i = m_todo.begin(); i != m_todo.end(); ++i) {
 | 
				
			||||||
 | 
					    switch((*i).cmd) {
 | 
				
			||||||
 | 
					      case DO_KILL:
 | 
				
			||||||
 | 
					        (*i).arg = Serializer::LookupBody((size_t)(*i).arg);
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case DO_NOTHING: break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Ship::Ship(ShipType::Type shipType) : DynamicBody() {
 | 
					Ship::Ship(ShipType::Type shipType) : DynamicBody() {
 | 
				
			||||||
@ -284,6 +309,7 @@ void Ship::TestLanded(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void Ship::TimeStepUpdate(const float timeStep) {
 | 
					void Ship::TimeStepUpdate(const float timeStep) {
 | 
				
			||||||
  DynamicBody::TimeStepUpdate(timeStep);
 | 
					  DynamicBody::TimeStepUpdate(timeStep);
 | 
				
			||||||
 | 
					  AITimeStep(timeStep);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  m_dockingTimer = (m_dockingTimer-timeStep > 0 ? m_dockingTimer-timeStep : 0);
 | 
					  m_dockingTimer = (m_dockingTimer-timeStep > 0 ? m_dockingTimer-timeStep : 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -347,6 +373,38 @@ void Ship::TimeStepUpdate(const float timeStep) {
 | 
				
			|||||||
  if(m_testLanded) TestLanded();
 | 
					  if(m_testLanded) TestLanded();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Ship::AITimeStep(const float timeStep) {
 | 
				
			||||||
 | 
					  bool done = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if(m_todo.size() != 0) {
 | 
				
			||||||
 | 
					    AIInstruction& inst = m_todo.front();
 | 
				
			||||||
 | 
					    switch(inst.cmd) {
 | 
				
			||||||
 | 
					      case DO_KILL:
 | 
				
			||||||
 | 
					        done = AICmdKill(static_cast<const Ship*>(inst.arg));
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case DO_NOTHING: done = true; break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if(done) {
 | 
				
			||||||
 | 
					    printf("AI '%s' succesfully executed %d:'%s'\n", GetLabel().c_str(), m_todo.front().cmd,
 | 
				
			||||||
 | 
					        static_cast<Ship*>(m_todo.front().arg)->GetLabel().c_str());
 | 
				
			||||||
 | 
					    m_todo.pop_front();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool Ship::AICmdKill(const Ship* enemy) {
 | 
				
			||||||
 | 
					  /* Needs to deal with frames, large distances, and success. */
 | 
				
			||||||
 | 
					  if(GetFrame() == enemy->GetFrame()) {
 | 
				
			||||||
 | 
					    vector3d dir = vector3d::Normalize(enemy->GetPosition() - GetPosition());
 | 
				
			||||||
 | 
					    AIFaceDirection(dir);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Ship::AIInstruct(enum AICommand cmd, void* arg) {
 | 
				
			||||||
 | 
					  m_todo.push_back(AIInstruction(cmd, arg));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Ship::NotifyDeath(const Body* const dyingBody) {
 | 
					void Ship::NotifyDeath(const Body* const dyingBody) {
 | 
				
			||||||
  if(GetNavTarget() == dyingBody)
 | 
					  if(GetNavTarget() == dyingBody)
 | 
				
			||||||
    SetNavTarget(0);
 | 
					    SetNavTarget(0);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								src/ship.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/ship.h
									
									
									
									
									
								
							@ -1,4 +1,5 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					#include <list>
 | 
				
			||||||
#include "libs.h"
 | 
					#include "libs.h"
 | 
				
			||||||
#include "dynamic_body.h"
 | 
					#include "dynamic_body.h"
 | 
				
			||||||
#include "ship_type.h"
 | 
					#include "ship_type.h"
 | 
				
			||||||
@ -50,6 +51,9 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  EquipSet m_equipment;
 | 
					  EquipSet m_equipment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  enum AICommand { DO_NOTHING, DO_KILL };
 | 
				
			||||||
 | 
					  void AIInstruct(enum AICommand, void* arg);
 | 
				
			||||||
 | 
					  void AiClearInstruction(void) { m_todo.clear(); }
 | 
				
			||||||
  virtual void PostLoadFixup(void);
 | 
					  virtual void PostLoadFixup(void);
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
  virtual void Save(void);
 | 
					  virtual void Save(void);
 | 
				
			||||||
@ -61,6 +65,7 @@ protected:
 | 
				
			|||||||
  enum ShipType::Type m_shipType;
 | 
					  enum ShipType::Type m_shipType;
 | 
				
			||||||
  Uint32 m_gunState[ShipType::GUNMOUNT_MAX];
 | 
					  Uint32 m_gunState[ShipType::GUNMOUNT_MAX];
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
 | 
					  void AITimeStep(const float timeStep);
 | 
				
			||||||
  void Init(void);
 | 
					  void Init(void);
 | 
				
			||||||
  bool IsFiringLasers(void);
 | 
					  bool IsFiringLasers(void);
 | 
				
			||||||
  void TestLanded(void);
 | 
					  void TestLanded(void);
 | 
				
			||||||
@ -78,5 +83,13 @@ private:
 | 
				
			|||||||
  Body* m_navTarget;
 | 
					  Body* m_navTarget;
 | 
				
			||||||
  Body* m_combatTarget;
 | 
					  Body* m_combatTarget;
 | 
				
			||||||
  shipstats_t m_stats;
 | 
					  shipstats_t m_stats;
 | 
				
			||||||
 | 
					  class AIInstruction {
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
					    AICommand cmd;
 | 
				
			||||||
 | 
					    void* arg;
 | 
				
			||||||
 | 
					    AIInstruction(AICommand c, void* a): cmd(c), arg(a) { }
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  std::list<AIInstruction> m_todo;
 | 
				
			||||||
 | 
					  bool AICmdKill(const Ship*);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user