Refactor Body inheritance tree to remove Object and CityOnPlanet (#4995)

* Remove CityOnPlanet from Object hierarchy

* Remove Object from the inheritance hierarchy

* Rename Object -> ObjectType
master
Webster Sheets 2020-11-11 19:33:04 -05:00 committed by GitHub
parent 10006ebfc9
commit 37c96041e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 294 additions and 335 deletions

View File

@ -51,8 +51,8 @@ void Beam::BuildModel()
//+z forwards (or projectile direction)
const float w = 0.5f;
vector3f one(0.f, -w, 0.f); //top left
vector3f two(0.f, w, 0.f); //top right
vector3f one(0.f, -w, 0.f); //top left
vector3f two(0.f, w, 0.f); //top right
vector3f three(0.f, w, -1.f); //bottom right
vector3f four(0.f, -w, -1.f); //bottom left
@ -262,24 +262,18 @@ void Beam::StaticUpdate(const float timeStep)
frame->GetCollisionSpace()->TraceRay(GetPosition(), m_dir.Normalized(), m_length, &c, static_cast<ModelBody *>(m_parent)->GetGeom());
if (c.userData1) {
Object *o = static_cast<Object *>(c.userData1);
if (o->IsType(Object::CITYONPLANET)) {
Pi::game->GetSpace()->KillBody(this);
} else if (o->IsType(Object::BODY)) {
Body *hit = static_cast<Body *>(o);
if (hit != m_parent) {
hit->OnDamage(m_parent, GetDamage(), c);
m_active = false;
if (hit->IsType(Object::SHIP))
LuaEvent::Queue("onShipHit", dynamic_cast<Ship *>(hit), dynamic_cast<Body *>(m_parent));
}
Body *hit = static_cast<Body *>(c.userData1);
if (hit != m_parent) {
hit->OnDamage(m_parent, GetDamage(), c);
m_active = false;
if (hit->IsType(ObjectType::SHIP))
LuaEvent::Queue("onShipHit", dynamic_cast<Ship *>(hit), dynamic_cast<Body *>(m_parent));
}
}
if (m_mining) {
// need to test for terrain hit
if (frame->GetBody() && frame->GetBody()->IsType(Object::PLANET)) {
if (frame->GetBody() && frame->GetBody()->IsType(ObjectType::PLANET)) {
Planet *const planet = static_cast<Planet *>(frame->GetBody());
const SystemBody *b = planet->GetSystemBody();
vector3d pos = GetPosition();

View File

@ -8,7 +8,6 @@
#include "Body.h"
#include "Color.h"
#include "Object.h"
#include "matrix4x4.h"
#include "vector3.h"

View File

@ -83,15 +83,15 @@ void Body::ToJson(Json &jsonObj, Space *space)
jsonObj["body_type"] = int(GetType());
switch (GetType()) {
case Object::STAR:
case Object::PLANET:
case Object::SPACESTATION:
case Object::SHIP:
case Object::PLAYER:
case Object::MISSILE:
case Object::CARGOBODY:
case Object::PROJECTILE:
case Object::HYPERSPACECLOUD:
case ObjectType::STAR:
case ObjectType::PLANET:
case ObjectType::SPACESTATION:
case ObjectType::SHIP:
case ObjectType::PLAYER:
case ObjectType::MISSILE:
case ObjectType::CARGOBODY:
case ObjectType::PROJECTILE:
case ObjectType::HYPERSPACECLOUD:
SaveToJson(jsonObj, space);
break;
default:
@ -104,33 +104,33 @@ Body *Body::FromJson(const Json &jsonObj, Space *space)
if (!jsonObj["body_type"].is_number_integer())
throw SavedGameCorruptException();
Object::Type type = Object::Type(jsonObj["body_type"]);
ObjectType type = ObjectType(jsonObj["body_type"]);
switch (type) {
case Object::STAR:
case ObjectType::STAR:
return new Star(jsonObj, space);
case Object::PLANET:
case ObjectType::PLANET:
return new Planet(jsonObj, space);
case Object::SPACESTATION:
case ObjectType::SPACESTATION:
return new SpaceStation(jsonObj, space);
case Object::SHIP: {
case ObjectType::SHIP: {
Ship *s = new Ship(jsonObj, space);
// Here because of comments in Ship.cpp on following function
s->UpdateLuaStats();
return static_cast<Body *>(s);
}
case Object::PLAYER: {
case ObjectType::PLAYER: {
Player *p = new Player(jsonObj, space);
// Read comments in Ship.cpp on following function
p->UpdateLuaStats();
return static_cast<Body *>(p);
}
case Object::MISSILE:
case ObjectType::MISSILE:
return new Missile(jsonObj, space);
case Object::PROJECTILE:
case ObjectType::PROJECTILE:
return new Projectile(jsonObj, space);
case Object::CARGOBODY:
case ObjectType::CARGOBODY:
return new CargoBody(jsonObj, space);
case Object::HYPERSPACECLOUD:
case ObjectType::HYPERSPACECLOUD:
return new HyperspaceCloud(jsonObj, space);
default:
assert(0);

View File

@ -4,8 +4,8 @@
#ifndef _BODY_H
#define _BODY_H
#include "DeleteEmitter.h"
#include "FrameId.h"
#include "Object.h"
#include "lua/PropertiedObject.h"
#include "matrix3x3.h"
#include "vector3.h"
@ -21,9 +21,41 @@ namespace Graphics {
}
struct CollisionContact;
class Body : public Object, public PropertiedObject {
// ObjectType is used as a form of RTTI for Body and its children.
// Think carefully before adding more entries; we'd like to switch
// to a composition-based system instead.
enum class ObjectType { // <enum name=PhysicsObjectType scope='ObjectType' public>
// only creating enum strings for types that are exposed to Lua
BODY,
MODELBODY,
DYNAMICBODY, // <enum skip>
SHIP,
PLAYER,
SPACESTATION,
TERRAINBODY, // <enum skip>
PLANET,
STAR,
CARGOBODY,
PROJECTILE, // <enum skip>
MISSILE,
HYPERSPACECLOUD // <enum skip>
};
#define OBJDEF(__thisClass, __parentClass, __TYPE) \
virtual ObjectType GetType() const override { return ObjectType::__TYPE; } \
virtual bool IsType(ObjectType c) const override \
{ \
if (__thisClass::GetType() == (c)) \
return true; \
else \
return __parentClass::IsType(c); \
}
class Body : public DeleteEmitter, public PropertiedObject {
public:
OBJDEF(Body, Object, BODY);
virtual ObjectType GetType() const { return ObjectType::BODY; }
virtual bool IsType(ObjectType c) const { return GetType() == c; }
Body();
Body(const Json &jsonObj, Space *space);
virtual ~Body();
@ -49,9 +81,9 @@ public:
}
// return true if to do collision response and apply damage
virtual bool OnCollision(Object *o, Uint32 flags, double relVel) { return false; }
virtual bool OnCollision(Body *o, Uint32 flags, double relVel) { return false; }
// Attacker may be null
virtual bool OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData) { return false; }
virtual bool OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData) { return false; }
// Override to clear any pointers you hold to the body
virtual void NotifyRemoved(const Body *const removedBody) {}

View File

@ -166,7 +166,7 @@ void Camera::Update()
const float pixSize = Graphics::GetScreenHeight() * 2.0 * rad / (attrs.camDist * Graphics::GetFovFactor());
// terrain objects are visible from distance but might not have any discernable features
if (b->IsType(Object::TERRAINBODY)) {
if (b->IsType(ObjectType::TERRAINBODY)) {
if (pixSize < BILLBOARD_PIXEL_THRESHOLD) {
attrs.billboard = true;
@ -177,9 +177,9 @@ void Camera::Update()
// limit the minimum billboard size for planets so they're always a little visible
attrs.billboardSize = std::max(1.0f, pixSize);
if (b->IsType(Object::STAR)) {
if (b->IsType(ObjectType::STAR)) {
attrs.billboardColor = StarSystem::starRealColors[b->GetSystemBody()->GetType()];
} else if (b->IsType(Object::PLANET)) {
} else if (b->IsType(ObjectType::PLANET)) {
// XXX this should incorporate some lighting effect
// (ie, colour of the illuminating star(s))
attrs.billboardColor = b->GetSystemBody()->GetAlbedo();
@ -188,7 +188,7 @@ void Camera::Update()
}
// this should always be the main star in the system - except for the star itself!
if (!m_lightSources.empty() && !b->IsType(Object::STAR)) {
if (!m_lightSources.empty() && !b->IsType(ObjectType::STAR)) {
const Graphics::Light &light = m_lightSources[0].GetLight();
attrs.billboardColor *= light.GetDiffuse(); // colour the billboard a little with the Starlight
}
@ -239,7 +239,7 @@ void Camera::Draw(const Body *excludeBody)
if (camParent && camParent->IsRotFrame()) {
//check if camera is near a planet
Body *camParentBody = camParent->GetBody();
if (camParentBody && camParentBody->IsType(Object::PLANET)) {
if (camParentBody && camParentBody->IsType(ObjectType::PLANET)) {
Planet *planet = static_cast<Planet *>(camParentBody);
const vector3f relpos(planet->GetInterpPositionRelTo(camFrameId));
double altitude(relpos.Length());
@ -305,14 +305,14 @@ void Camera::CalcShadows(const int lightNum, const Body *b, std::vector<Shadow>
const vector3d lightDir = bLightPos.Normalized();
double bRadius;
if (b->IsType(Object::TERRAINBODY))
if (b->IsType(ObjectType::TERRAINBODY))
bRadius = b->GetSystemBody()->GetRadius();
else
bRadius = b->GetPhysRadius();
// Look for eclipsing third bodies:
for (const Body *b2 : Pi::game->GetSpace()->GetBodies()) {
if (b2 == b || b2 == lightBody || !(b2->IsType(Object::PLANET) || b2->IsType(Object::STAR)))
if (b2 == b || b2 == lightBody || !(b2->IsType(ObjectType::PLANET) || b2->IsType(ObjectType::STAR)))
continue;
double b2Radius = b2->GetSystemBody()->GetRadius();

View File

@ -96,7 +96,7 @@ void CargoBody::TimeStepUpdate(const float timeStep)
DynamicBody::TimeStepUpdate(timeStep);
}
bool CargoBody::OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData)
bool CargoBody::OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData)
{
m_hitpoints -= kgDamage * 0.001f;
if (m_hitpoints < 0) {
@ -106,10 +106,10 @@ bool CargoBody::OnDamage(Object *attacker, float kgDamage, const CollisionContac
return true;
}
bool CargoBody::OnCollision(Object *b, Uint32 flags, double relVel)
bool CargoBody::OnCollision(Body *b, Uint32 flags, double relVel)
{
// ignore collision if its about to be scooped
if (b->IsType(Object::SHIP)) {
if (b->IsType(ObjectType::SHIP)) {
int cargoscoop_cap = 0;
static_cast<Ship *>(b)->Properties().Get("cargo_scoop_cap", cargoscoop_cap);
if (cargoscoop_cap > 0)

View File

@ -22,8 +22,8 @@ public:
virtual void SetLabel(const std::string &label) override;
virtual void Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) override;
virtual void TimeStepUpdate(const float timeStep) override;
virtual bool OnCollision(Object *o, Uint32 flags, double relVel) override;
virtual bool OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData) override;
virtual bool OnCollision(Body *o, Uint32 flags, double relVel) override;
virtual bool OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData) override;
~CargoBody(){};

View File

@ -17,8 +17,8 @@
#include "scenegraph/SceneGraph.h"
static const unsigned int DEFAULT_NUM_BUILDINGS = 1000;
static const double START_SEG_SIZE = CITY_ON_PLANET_RADIUS;
static const double START_SEG_SIZE_NO_ATMO = CITY_ON_PLANET_RADIUS / 5.0f;
static const double START_SEG_SIZE = CityOnPlanet::RADIUS;
static const double START_SEG_SIZE_NO_ATMO = CityOnPlanet::RADIUS / 5.0f;
using SceneGraph::Model;
@ -232,7 +232,7 @@ CityOnPlanet::CityOnPlanet(Planet *planet, SpaceStation *station, const Uint32 s
citybuildinglist_t *buildings = &s_buildingList;
vector3d cent = p;
const int cellsize_i = 80;
const double cellsize = double(cellsize_i); // current widest building = 92
const double cellsize = double(cellsize_i); // current widest building = 92
const double bodyradius = planet->GetSystemBody()->GetRadius(); // cache for bodyradius value
static const int gmid = (cityradius / cellsize_i);
@ -297,7 +297,10 @@ CityOnPlanet::CityOnPlanet(Planet *planet, SpaceStation *station, const Uint32 s
// rotate the building to face a random direction
const int32_t orient = rand.Int32(4);
Geom *geom = new Geom(cmesh->GetGeomTree(), orientcalc[orient], cent, this);
// FIXME: geoms need a userdata to tell gameplay code what we actually hit.
// We don't want to create a separate Body for each instance of the buildings, so we
// scam the code by pretending we're part of the host planet.
Geom *geom = new Geom(cmesh->GetGeomTree(), orientcalc[orient], cent, GetPlanet());
// add it to the list of buildings to render
m_buildings.push_back({ bt.instIndex, float(cmesh->GetRadius()), orient, cent, geom });

View File

@ -6,7 +6,6 @@
#include "CollMesh.h"
#include "FrameId.h"
#include "Object.h"
#include "Random.h"
#include <set>
@ -26,11 +25,8 @@ namespace SceneGraph {
class Animation;
} // namespace SceneGraph
#define CITY_ON_PLANET_RADIUS 5000.0
class CityOnPlanet : public Object {
class CityOnPlanet {
public:
OBJDEF(CityOnPlanet, Object, CITYONPLANET);
CityOnPlanet() = delete;
CityOnPlanet(Planet *planet, SpaceStation *station, const Uint32 seed);
virtual ~CityOnPlanet();
@ -41,6 +37,8 @@ public:
static void Uninit();
static void SetCityModelPatterns(const SystemPath &path);
static constexpr double RADIUS = 5000.0;
private:
void AddStaticGeomsToCollisionSpace();
void RemoveStaticGeomsFromCollisionSpace();

View File

@ -101,7 +101,7 @@ void DynamicBody::GetCurrentAtmosphericState(double &pressure, double &density)
{
Frame *f = Frame::GetFrame(GetFrame());
Body *body = f->GetBody();
if (!body || !f->IsRotFrame() || !body->IsType(Object::PLANET)) {
if (!body || !f->IsRotFrame() || !body->IsType(ObjectType::PLANET)) {
pressure = density = 0;
return;
}
@ -224,7 +224,7 @@ void DynamicBody::CalcExternalForce()
Frame *f = Frame::GetFrame(GetFrame());
if (!f) return; // no external force if not in a frame
Body *body = f->GetBody();
if (body && !body->IsType(Object::SPACESTATION)) { // they ought to have mass though...
if (body && !body->IsType(ObjectType::SPACESTATION)) { // they ought to have mass though...
vector3d b1b2 = GetPosition();
double m1m2 = GetMass() * body->GetMass();
double invrsqr = 1.0 / b1b2.LengthSqr();
@ -235,7 +235,7 @@ void DynamicBody::CalcExternalForce()
m_gravityForce = m_externalForce;
// atmospheric drag
if (body && f->IsRotFrame() && body->IsType(Object::PLANET)) {
if (body && f->IsRotFrame() && body->IsType(ObjectType::PLANET)) {
vector3d fAtmoForce = CalcAtmosphericForce();
// make this a bit less daft at high time accel
@ -278,7 +278,7 @@ void DynamicBody::TimeStepUpdate(const float timeStep)
SetPosition(GetPosition() + m_vel * double(timeStep));
//if (this->IsType(Object::PLAYER))
//if (this->IsType(ObjectType::PLAYER))
//Output("pos = %.1f,%.1f,%.1f, vel = %.1f,%.1f,%.1f, force = %.1f,%.1f,%.1f, external = %.1f,%.1f,%.1f\n",
// pos.x, pos.y, pos.z, m_vel.x, m_vel.y, m_vel.z, m_force.x, m_force.y, m_force.z,
// m_externalForce.x, m_externalForce.y, m_externalForce.z);
@ -342,15 +342,15 @@ void DynamicBody::SetAngVelocity(const vector3d &v)
m_angVel = v;
}
bool DynamicBody::OnCollision(Object *o, Uint32 flags, double relVel)
bool DynamicBody::OnCollision(Body *o, Uint32 flags, double relVel)
{
// don't bother doing collision damage from a missile that will now explode, or may have already
// also avoids an occasional race condition where destruction event of this could be queued twice
// returning true to ensure that the missile can react to the collision
if (o->IsType(Object::MISSILE)) return true;
if (o->IsType(ObjectType::MISSILE)) return true;
double kineticEnergy = 0;
if (o->IsType(Object::DYNAMICBODY)) {
if (o->IsType(ObjectType::DYNAMICBODY)) {
kineticEnergy = KINETIC_ENERGY_MULT * static_cast<DynamicBody *>(o)->GetMass() * relVel * relVel;
} else {
kineticEnergy = KINETIC_ENERGY_MULT * m_mass * relVel * relVel;
@ -359,7 +359,7 @@ bool DynamicBody::OnCollision(Object *o, Uint32 flags, double relVel)
// damage (kineticEnergy is being passed as a damage value) is measured in kilograms
// ignore damage less than a gram except for cargo, which is very fragile.
CollisionContact dummy;
if (this->IsType(Object::CARGOBODY)) {
if (this->IsType(ObjectType::CARGOBODY)) {
OnDamage(o, float(kineticEnergy), dummy);
} else if (kineticEnergy > 1e-3) {
OnDamage(o, float(kineticEnergy), dummy);

View File

@ -28,7 +28,7 @@ public:
virtual void SetFrame(FrameId fId) override;
vector3d GetAngVelocity() const;
void SetAngVelocity(const vector3d &v);
virtual bool OnCollision(Object *o, Uint32 flags, double relVel) override;
virtual bool OnCollision(Body *o, Uint32 flags, double relVel) override;
vector3d GetAngularMomentum() const;
double GetAngularInertia() const { return m_angInertia; }
void SetMassDistributionFromModel();

View File

@ -12,7 +12,6 @@
#include "GameSaveError.h"
#include "HyperspaceCloud.h"
#include "MathUtil.h"
#include "Object.h"
#include "collider/CollisionSpace.h"
#include "core/GZipFormat.h"
#include "galaxy/Economy.h"
@ -76,7 +75,7 @@ Game::Game(const SystemPath &path, const double startDateTime) :
m_player->SetFrame(b->GetFrame());
if (b->GetType() == Object::SPACESTATION) {
if (b->GetType() == ObjectType::SPACESTATION) {
m_player->SetDockedWith(static_cast<SpaceStation *>(b), 0);
} else {
const SystemBody *sbody = b->GetSystemBody();
@ -358,7 +357,7 @@ bool Game::UpdateTimeAccel()
else {
for (const Body *b : m_space->GetBodies()) {
if (b == m_player.get()) continue;
if (b->IsType(Object::HYPERSPACECLOUD)) continue;
if (b->IsType(ObjectType::HYPERSPACECLOUD)) continue;
vector3d toBody = m_player->GetPosition() - b->GetPositionRelTo(m_player->GetFrame());
double dist = toBody.Length();
@ -433,7 +432,7 @@ void Game::SwitchToHyperspace()
m_hyperspaceClouds.clear();
for (Body *b : m_space->GetBodies()) {
if (!b->IsType(Object::HYPERSPACECLOUD)) continue;
if (!b->IsType(ObjectType::HYPERSPACECLOUD)) continue;
// only want departure clouds with ships in them
HyperspaceCloud *cloud = static_cast<HyperspaceCloud *>(b);
@ -664,7 +663,7 @@ void Game::SetTimeAccel(TimeAccel t)
// Give all ships a half-step acceleration to stop autopilot overshoot
if (t < m_timeAccel)
for (Body *b : m_space->GetBodies())
if (b->IsType(Object::SHIP))
if (b->IsType(ObjectType::SHIP))
(static_cast<Ship *>(b))->TimeAccelAdjust(0.5f * GetTimeStep());
bool emitPaused = (t == TIMEACCEL_PAUSED && t != m_timeAccel);

View File

@ -156,7 +156,7 @@ void Missile::TimeStepUpdate(const float timeStep)
}
}
bool Missile::OnCollision(Object *o, Uint32 flags, double relVel)
bool Missile::OnCollision(Body *o, Uint32 flags, double relVel)
{
if (!IsDead()) {
Explode();
@ -164,7 +164,7 @@ bool Missile::OnCollision(Object *o, Uint32 flags, double relVel)
return true;
}
bool Missile::OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData)
bool Missile::OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData)
{
if (!IsDead()) {
Explode();
@ -187,7 +187,7 @@ void Missile::Explode()
if (dist < damageRadius) {
// linear damage decay with distance
body->OnDamage(m_owner, kgDamage * (damageRadius - dist) / damageRadius, dummy);
if (body->IsType(Object::SHIP))
if (body->IsType(ObjectType::SHIP))
LuaEvent::Queue("onShipHit", dynamic_cast<Ship *>(body), m_owner);
}
}

View File

@ -18,8 +18,8 @@ public:
virtual ~Missile();
void StaticUpdate(const float timeStep) override;
void TimeStepUpdate(const float timeStep) override;
virtual bool OnCollision(Object *o, Uint32 flags, double relVel) override;
virtual bool OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData) override;
virtual bool OnCollision(Body *o, Uint32 flags, double relVel) override;
virtual bool OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData) override;
virtual void NotifyRemoved(const Body *const removedBody) override;
virtual void PostLoadFixup(Space *space) override;
virtual void Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) override;

View File

@ -300,7 +300,7 @@ void ModelBody::CalcLighting(double &ambient, double &direct, const Camera *came
ambient = minAmbient;
direct = 1.0;
Body *astro = Frame::GetFrame(GetFrame())->GetBody();
if (!(astro && astro->IsType(Object::PLANET)))
if (!(astro && astro->IsType(ObjectType::PLANET)))
return;
Planet *planet = static_cast<Planet *>(astro);

View File

@ -1,41 +0,0 @@
// Copyright © 2008-2020 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#ifndef _OBJECT_H
#define _OBJECT_H
#include "DeleteEmitter.h"
class Object : public DeleteEmitter {
public:
// only creating enum strings for types that are exposed to Lua
enum Type { // <enum scope='Object' name=PhysicsObjectType public>
OBJECT, // <enum skip>
BODY,
MODELBODY,
DYNAMICBODY, // <enum skip>
SHIP,
PLAYER,
SPACESTATION,
TERRAINBODY, // <enum skip>
PLANET,
STAR,
CARGOBODY,
CITYONPLANET, // <enum skip>
PROJECTILE, // <enum skip>
MISSILE,
HYPERSPACECLOUD // <enum skip>
};
virtual Type GetType() const { return OBJECT; }
virtual bool IsType(Type c) const { return GetType() == c; }
};
#define OBJDEF(__thisClass, __parentClass, __TYPE) \
virtual Object::Type GetType() const override { return Object::__TYPE; } \
virtual bool IsType(Type c) const override \
{ \
if (__thisClass::GetType() == (c)) \
return true; \
else \
return __parentClass::IsType(c); \
}
#endif /* _OBJECT_H */

View File

@ -77,7 +77,7 @@ void ObjectViewerView::Draw3D()
}
if (m_targetBody) {
if (m_targetBody->IsType(Object::STAR))
if (m_targetBody->IsType(ObjectType::STAR))
light.SetPosition(vector3f(0.f));
else {
light.SetPosition(vector3f(0.577f));
@ -106,9 +106,9 @@ void ObjectViewerView::OnSwitchTo()
void ObjectViewerView::ReloadState()
{
if (m_targetBody->IsType(Object::SPACESTATION)) {
if (m_targetBody->IsType(ObjectType::SPACESTATION)) {
m_systemBody = static_cast<SpaceStation *>(m_targetBody)->GetSystemBody();
} else if (m_targetBody->IsType(Object::TERRAINBODY)) {
} else if (m_targetBody->IsType(ObjectType::TERRAINBODY)) {
m_systemBody = static_cast<TerrainBody *>(m_targetBody)->GetSystemBody();
m_isTerrainBody = m_systemBody != nullptr;
}

View File

@ -12,7 +12,6 @@
#include "Pi.h"
#include "SectorView.h"
#include "Sfx.h"
#include "ShipCpanel.h"
#include "SpaceStation.h"
#include "StringF.h"
#include "SystemView.h" // for the transfer planner
@ -120,7 +119,7 @@ bool Player::DoDamage(float kgDamage)
}
//XXX perhaps remove this, the sound is very annoying
bool Player::OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData)
bool Player::OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData)
{
bool r = Ship::OnDamage(attacker, kgDamage, contactData);
if (!IsDead() && (GetPercentHull() < 25.0f)) {
@ -195,7 +194,7 @@ void Player::NotifyRemoved(const Body *const removedBody)
if (GetCombatTarget() == removedBody) {
SetCombatTarget(0);
if (!GetNavTarget() && removedBody->IsType(Object::SHIP))
if (!GetNavTarget() && removedBody->IsType(ObjectType::SHIP))
SetNavTarget(static_cast<const Ship *>(removedBody)->GetHyperspaceCloud());
}

View File

@ -22,7 +22,7 @@ public:
virtual void SetDockedWith(SpaceStation *, int port) override;
virtual bool DoDamage(float kgDamage) override final; // overloaded to add "crush" audio
virtual bool OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData) override;
virtual bool OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData) override;
virtual bool SetWheelState(bool down) override; // returns success of state change, NOT state itself
virtual Missile *SpawnMissile(ShipType::Id missile_type, int power = -1) override;
virtual void SetAlertState(Ship::AlertState as) override;

View File

@ -48,8 +48,8 @@ void Projectile::BuildModel()
//+z forwards (or projectile direction)
const float w = 0.5f;
vector3f one(0.f, -w, 0.f); //top left
vector3f two(0.f, w, 0.f); //top right
vector3f one(0.f, -w, 0.f); //top left
vector3f two(0.f, w, 0.f); //top right
vector3f three(0.f, w, -1.f); //bottom right
vector3f four(0.f, -w, -1.f); //bottom left
@ -263,25 +263,19 @@ void Projectile::StaticUpdate(const float timeStep)
frame->GetCollisionSpace()->TraceRay(GetPosition(), vel.Normalized(), vel.Length(), &c);
if (c.userData1) {
Object *o = static_cast<Object *>(c.userData1);
if (o->IsType(Object::CITYONPLANET)) {
Body *hit = static_cast<Body *>(c.userData1);
if (hit != m_parent) {
hit->OnDamage(m_parent, GetDamage(), c);
Pi::game->GetSpace()->KillBody(this);
} else if (o->IsType(Object::BODY)) {
Body *hit = static_cast<Body *>(o);
if (hit != m_parent) {
hit->OnDamage(m_parent, GetDamage(), c);
Pi::game->GetSpace()->KillBody(this);
if (hit->IsType(Object::SHIP))
LuaEvent::Queue("onShipHit", dynamic_cast<Ship *>(hit), dynamic_cast<Body *>(m_parent));
}
if (hit->IsType(ObjectType::SHIP))
LuaEvent::Queue("onShipHit", dynamic_cast<Ship *>(hit), dynamic_cast<Body *>(m_parent));
}
}
if (m_mining) // mining lasers can break off chunks of terrain
{
// need to test for terrain hit
Planet *const planet = static_cast<Planet *>(frame->GetBody()); // cache the value even for the if statement
if (planet && planet->IsType(Object::PLANET)) {
if (planet && planet->IsType(ObjectType::PLANET)) {
vector3d pos = GetPosition();
double terrainHeight = planet->GetTerrainHeight(pos.Normalized());
if (terrainHeight > pos.Length()) {

View File

@ -66,7 +66,7 @@ bool Sensors::ChooseTarget(TargetingCriteria crit)
for (auto it = m_radarContacts.begin(); it != m_radarContacts.end(); ++it) {
//match object type
//match iff
if (it->body->IsType(Object::SHIP)) {
if (it->body->IsType(ObjectType::SHIP)) {
//if (it->iff != IFF_HOSTILE) continue;
//should move the target to ship after all (from PlayerShipController)
//targeting inputs stay in PSC
@ -83,7 +83,7 @@ Sensors::IFF Sensors::CheckIFF(Body *other)
{
PROFILE_SCOPED();
//complicated relationship check goes here
if (other->IsType(Object::SHIP)) {
if (other->IsType(ObjectType::SHIP)) {
Uint8 rel = m_owner->GetRelations(other);
if (rel == 0)
return IFF_HOSTILE;
@ -106,7 +106,7 @@ void Sensors::Update(float time)
//contacts, worldview labels too.
Space::BodyNearList nearby = Pi::game->GetSpace()->GetBodiesMaybeNear(m_owner, 100000.0f);
for (Body *body : nearby) {
if (body == m_owner || !body->IsType(Object::SHIP)) continue;
if (body == m_owner || !body->IsType(ObjectType::SHIP)) continue;
if (body->IsDead()) continue;
auto cit = m_radarContacts.begin();
@ -171,10 +171,9 @@ void Sensors::PopulateStaticContacts()
for (Body *b : Pi::game->GetSpace()->GetBodies()) {
switch (b->GetType()) {
case Object::STAR:
case Object::PLANET:
case Object::CITYONPLANET:
case Object::SPACESTATION:
case ObjectType::STAR:
case ObjectType::PLANET:
case ObjectType::SPACESTATION:
break;
default:
continue;

View File

@ -180,7 +180,7 @@ void SfxManager::AddExplosion(Body *b)
if (!sfxman) return;
float speed = 200.0f;
if (b->IsType(Object::SHIP)) {
if (b->IsType(ObjectType::SHIP)) {
ModelBody *mb = static_cast<ModelBody *>(b);
speed = mb->GetAabb().radius * 8.0;
}

View File

@ -86,7 +86,7 @@ void Ship::AIFlyTo(Body *target)
AIClearInstructions();
SetFuelReserve((GetFuel() < 0.5) ? GetFuel() / 2 : 0.25);
if (target->IsType(Object::SHIP)) { // test code
if (target->IsType(ObjectType::SHIP)) { // test code
vector3d posoff(-1000.0, 0.0, 1000.0);
m_curAICmd = new AICmdFormation(this, static_cast<Ship *>(target), posoff);
} else

View File

@ -4,7 +4,6 @@
#include "Ship.h"
#include "CargoBody.h"
#include "CityOnPlanet.h"
#include "EnumStrings.h"
#include "Frame.h"
#include "Game.h"
@ -466,7 +465,7 @@ vector3d Ship::CalcAtmoTorque() const
return fAtmoTorque;
}
bool Ship::OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData)
bool Ship::OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData)
{
if (m_invulnerable) {
Sound::BodyMakeNoise(this, "Hull_hit_Small", 0.5f);
@ -499,10 +498,7 @@ bool Ship::OnDamage(Object *attacker, float kgDamage, const CollisionContact &co
Properties().Set("hullPercent", 100.0f * (m_stats.hull_mass_left / float(m_type->hullMass)));
if (m_stats.hull_mass_left < 0) {
if (attacker) {
if (attacker->IsType(Object::BODY))
LuaEvent::Queue("onShipDestroyed", this, dynamic_cast<Body *>(attacker));
else if (attacker->IsType(Object::CITYONPLANET))
LuaEvent::Queue("onShipDestroyed", this, dynamic_cast<CityOnPlanet *>(attacker)->GetPlanet());
LuaEvent::Queue("onShipDestroyed", this, attacker);
}
Explode();
@ -523,35 +519,35 @@ bool Ship::OnDamage(Object *attacker, float kgDamage, const CollisionContact &co
return true;
}
bool Ship::OnCollision(Object *b, Uint32 flags, double relVel)
bool Ship::OnCollision(Body *b, Uint32 flags, double relVel)
{
// Collision with SpaceStation docking surface is
// completely handled by SpaceStations, you only
// need to return a "true" value in order to trigger
// a bounce in Space::OnCollision
// NOTE: 0x10 is a special flag set on docking surfaces
if (b->IsType(Object::SPACESTATION) && (flags & 0x10)) {
if (b->IsType(ObjectType::SPACESTATION) && (flags & 0x10)) {
return true;
}
// hitting cargo scoop surface shouldn't do damage
int cargoscoop_cap = 0;
Properties().Get("cargo_scoop_cap", cargoscoop_cap);
if (cargoscoop_cap > 0 && b->IsType(Object::CARGOBODY) && !dynamic_cast<Body *>(b)->IsDead()) {
LuaRef item = dynamic_cast<CargoBody *>(b)->GetCargoType();
if (cargoscoop_cap > 0 && b->IsType(ObjectType::CARGOBODY) && !b->IsDead()) {
LuaRef item = static_cast<CargoBody *>(b)->GetCargoType();
if (LuaObject<Ship>::CallMethod<int>(this, "AddEquip", item) > 0) { // try to add it to the ship cargo.
Pi::game->GetSpace()->KillBody(dynamic_cast<Body *>(b));
if (this->IsType(Object::PLAYER))
Pi::game->GetSpace()->KillBody(b);
if (this->IsType(ObjectType::PLAYER))
Pi::game->log->Add(stringf(Lang::CARGO_SCOOP_ACTIVE_1_TONNE_X_COLLECTED, formatarg("item", ScopedTable(item).CallMethod<std::string>("GetName"))));
// XXX SfxManager::Add(this, TYPE_SCOOP);
UpdateEquipStats();
return true;
}
if (this->IsType(Object::PLAYER))
if (this->IsType(ObjectType::PLAYER))
Pi::game->log->Add(Lang::CARGO_SCOOP_ATTEMPTED);
}
if (b->IsType(Object::PLANET)) {
if (b->IsType(ObjectType::PLANET)) {
// geoms still enabled when landed
if (m_flightState != FLYING)
return false;
@ -563,15 +559,13 @@ bool Ship::OnCollision(Object *b, Uint32 flags, double relVel)
}
}
if (b->IsType(Object::CITYONPLANET) ||
b->IsType(Object::SHIP) ||
b->IsType(Object::PLAYER) ||
b->IsType(Object::SPACESTATION) ||
b->IsType(Object::PLANET) ||
b->IsType(Object::STAR) ||
b->IsType(Object::CARGOBODY)) {
LuaEvent::Queue("onShipCollided", this,
b->IsType(Object::CITYONPLANET) ? dynamic_cast<CityOnPlanet *>(b)->GetPlanet() : dynamic_cast<Body *>(b));
if (b->IsType(ObjectType::SHIP) ||
b->IsType(ObjectType::PLAYER) ||
b->IsType(ObjectType::SPACESTATION) ||
b->IsType(ObjectType::PLANET) ||
b->IsType(ObjectType::STAR) ||
b->IsType(ObjectType::CARGOBODY)) {
LuaEvent::Queue("onShipCollided", this, b);
}
return DynamicBody::OnCollision(b, flags, relVel);
@ -802,7 +796,7 @@ Ship::ECMResult Ship::UseECM()
Space::BodyNearList nearby = Pi::game->GetSpace()->GetBodiesMaybeNear(this, ECM_RADIUS);
for (Body *body : nearby) {
if (body->GetFrame() != GetFrame()) continue;
if (!body->IsType(Object::MISSILE)) continue;
if (!body->IsType(ObjectType::MISSILE)) continue;
double dist = (body->GetPosition() - GetPosition()).Length();
if (dist < ECM_RADIUS) {
@ -909,7 +903,7 @@ void Ship::Blastoff()
Frame *f = Frame::GetFrame(GetFrame());
assert(f->GetBody()->IsType(Object::PLANET));
assert(f->GetBody()->IsType(ObjectType::PLANET));
const double planetRadius = 2.0 + static_cast<Planet *>(f->GetBody())->GetTerrainHeight(up);
SetVelocity(vector3d(0, 0, 0));
@ -930,7 +924,7 @@ void Ship::TestLanded()
Frame *f = Frame::GetFrame(GetFrame());
if (f->GetBody()->IsType(Object::PLANET)) {
if (f->GetBody()->IsType(ObjectType::PLANET)) {
double speed = GetVelocity().Length();
vector3d up = GetPosition().Normalized();
const double planetRadius = static_cast<Planet *>(f->GetBody())->GetTerrainHeight(up);
@ -1049,7 +1043,7 @@ void Ship::TimeAccelAdjust(const float timeStep)
{
if (!AIIsActive()) return;
#ifdef DEBUG_AUTOPILOT
if (this->IsType(Object::PLAYER))
if (this->IsType(ObjectType::PLAYER))
Output("Time accel adjustment, step = %.1f, decel = %s\n", double(timeStep),
m_decelerating ? "true" : "false");
#endif
@ -1113,7 +1107,7 @@ void Ship::UpdateAlertState()
for (auto i : nearbyBodies) {
if ((i) == this) continue;
if ((i)->IsType(Object::SHIP)) {
if ((i)->IsType(ObjectType::SHIP)) {
// TODO: Here there were a const on Ship*, now it cannot remain because of ship->firing and so, this open a breach...
// A solution is to put a member on ship: true if is firing, false if is not
Ship *ship = static_cast<Ship *>(i);
@ -1130,7 +1124,7 @@ void Ship::UpdateAlertState()
break;
}
}
} else if ((i)->IsType(Object::MISSILE)) {
} else if ((i)->IsType(ObjectType::MISSILE)) {
Missile *missile = static_cast<Missile *>(i);
if (missile->GetOwner() != this) {
@ -1217,7 +1211,7 @@ void Ship::UpdateFuel(const float timeStep)
void Ship::StaticUpdate(const float timeStep)
{
// do player sounds before dead check, so they also turn off
if (IsType(Object::PLAYER)) DoThrusterSounds();
if (IsType(ObjectType::PLAYER)) DoThrusterSounds();
if (IsDead()) return;
@ -1231,7 +1225,7 @@ void Ship::StaticUpdate(const float timeStep)
if (m_flightState == FLYING) {
Frame *frame = Frame::GetFrame(GetFrame());
Body *astro = frame->GetBody();
if (astro && astro->IsType(Object::PLANET)) {
if (astro && astro->IsType(ObjectType::PLANET)) {
Planet *p = static_cast<Planet *>(astro);
double dist = GetPosition().Length();
double pressure, density;
@ -1255,7 +1249,7 @@ void Ship::StaticUpdate(const float timeStep)
if (m_flightState == FLYING && capacity > 0) {
Frame *frame = Frame::GetFrame(GetFrame());
Body *astro = frame->GetBody();
if (astro && astro->IsType(Object::PLANET)) {
if (astro && astro->IsType(ObjectType::PLANET)) {
Planet *p = static_cast<Planet *>(astro);
if (p->GetSystemBody()->IsScoopable()) {
const double dist = GetPosition().Length();
@ -1274,7 +1268,7 @@ void Ship::StaticUpdate(const float timeStep)
LuaTable hydrogen = LuaTable(l, -1).Sub("cargo").Sub("hydrogen");
LuaObject<Ship>::CallMethod(this, "AddEquip", hydrogen);
UpdateEquipStats();
if (this->IsType(Object::PLAYER)) {
if (this->IsType(ObjectType::PLAYER)) {
Pi::game->log->Add(stringf(Lang::FUEL_SCOOP_ACTIVE_N_TONNES_H_COLLECTED,
formatarg("quantity", LuaObject<Ship>::CallMethod<int>(this, "CountEquip", hydrogen))));
}
@ -1301,7 +1295,7 @@ void Ship::StaticUpdate(const float timeStep)
LuaTable cargo = LuaTable(l, -1).Sub("cargo");
if (LuaObject<Ship>::CallMethod<int>(this, "RemoveEquip", cargo.Sub(t))) {
LuaObject<Ship>::CallMethod<int>(this, "AddEquip", cargo.Sub("fertilizer"));
if (this->IsType(Object::PLAYER)) {
if (this->IsType(ObjectType::PLAYER)) {
Pi::game->log->Add(Lang::CARGO_BAY_LIFE_SUPPORT_LOST);
}
lua_pop(l, 4);
@ -1416,7 +1410,7 @@ void Ship::StaticUpdate(const float timeStep)
// after the whole physics update, which means the flight state on next
// step would be HYPERSPACE, thus breaking quite a few things.
LuaEvent::Queue("onLeaveSystem", this);
} else if (!(is_equal_exact(m_wheelState, 0.0f)) && this->IsType(Object::PLAYER)) {
} else if (!(is_equal_exact(m_wheelState, 0.0f)) && this->IsType(ObjectType::PLAYER)) {
AbortHyperjump();
Sound::BodyMakeNoise(this, "Missile_Inbound", 1.0f);
}
@ -1595,7 +1589,7 @@ void Ship::SetShipType(const ShipType::Id &shipId)
m_skin.Apply(GetModel());
Init();
onFlavourChanged.emit();
if (IsType(Object::PLAYER))
if (IsType(ObjectType::PLAYER))
Pi::game->GetWorldView()->shipView->GetCameraController()->Reset();
InitEquipSet();

View File

@ -108,8 +108,8 @@ public:
bool IsDecelerating() const { return m_decelerating; }
virtual void NotifyRemoved(const Body *const removedBody) override;
virtual bool OnCollision(Object *o, Uint32 flags, double relVel) override;
virtual bool OnDamage(Object *attacker, float kgDamage, const CollisionContact &contactData) override;
virtual bool OnCollision(Body *o, Uint32 flags, double relVel) override;
virtual bool OnDamage(Body *attacker, float kgDamage, const CollisionContact &contactData) override;
enum FlightState { // <enum scope='Ship' name=ShipFlightState public>
FLYING, // open flight (includes autopilot)

View File

@ -265,7 +265,7 @@ bool AICmdKamikaze::TimeStepUpdate()
{
if (!m_target || m_target->IsDead()) return true;
if (m_dBody->IsType(Object::SHIP)) {
if (m_dBody->IsType(ObjectType::SHIP)) {
// "Standard" checks for a ship...
Ship *ship = static_cast<Ship *>(m_dBody);
assert(ship != nullptr);
@ -365,7 +365,7 @@ void AICmdKill::PostLoadFixup(Space *space)
bool AICmdKill::TimeStepUpdate()
{
if (m_dBody->IsType(Object::SHIP)) {
if (m_dBody->IsType(ObjectType::SHIP)) {
Ship *ship = static_cast<Ship *>(m_dBody);
assert(ship != nullptr);
if (ship->GetFlightState() == Ship::JUMPING) return false;
@ -658,8 +658,8 @@ static double MaxFeatureRad(Body *body)
static double MaxEffectRad(Body *body, Propulsion *prop)
{
if (!body) return 0.0;
if (!body->IsType(Object::TERRAINBODY)) {
if (!body->IsType(Object::SPACESTATION)) return body->GetPhysRadius() + 1000.0;
if (!body->IsType(ObjectType::TERRAINBODY)) {
if (!body->IsType(ObjectType::SPACESTATION)) return body->GetPhysRadius() + 1000.0;
return static_cast<SpaceStation *>(body)->GetStationType()->ParkingDistance() + 1000.0;
}
return std::max(body->GetPhysRadius(), sqrt(G * body->GetMass() / prop->GetAccelUp()));
@ -670,7 +670,7 @@ static double GetGravityAtPos(FrameId targframeId, const vector3d &posoff)
{
Frame *targframe = Frame::GetFrame(targframeId);
Body *body = targframe->GetBody();
if (!body || body->IsType(Object::SPACESTATION)) return 0;
if (!body || body->IsType(ObjectType::SPACESTATION)) return 0;
double rsqr = posoff.LengthSqr();
return G * body->GetMass() / rsqr;
// inverse is: sqrt(G * m1m2 / thrust)
@ -824,7 +824,7 @@ static bool CheckSuicide(DynamicBody *dBody, const vector3d &tandir)
if (dBody->Have(DynamicBody::PROPULSION)) return false;
Propulsion *prop = dBody->GetPropulsion();
assert(prop != nullptr);
if (!body || !body->IsType(Object::TERRAINBODY)) return false;
if (!body || !body->IsType(ObjectType::TERRAINBODY)) return false;
double vel = dBody->GetVelocity().Dot(tandir); // vel towards is negative
double dist = dBody->GetPosition().Length() - MaxFeatureRad(body);
@ -876,12 +876,12 @@ AICmdFlyTo::AICmdFlyTo(DynamicBody *dBody, Body *target) :
m_endvel = 0;
m_tangent = false;
m_is_flyto = true;
if (!target->IsType(Object::TERRAINBODY))
if (!target->IsType(ObjectType::TERRAINBODY))
m_dist = VICINITY_MIN;
else
m_dist = VICINITY_MUL * MaxEffectRad(target, m_prop.Get());
if (target->IsType(Object::SPACESTATION) && static_cast<SpaceStation *>(target)->IsGroundStation()) {
if (target->IsType(ObjectType::SPACESTATION) && static_cast<SpaceStation *>(target)->IsGroundStation()) {
m_posoff = target->GetPosition() + VICINITY_MIN * target->GetOrient().VectorY();
// m_posoff += 500.0 * target->GetOrient().VectorX();
m_targframeId = target->GetFrame();
@ -949,7 +949,7 @@ bool AICmdFlyTo::TimeStepUpdate()
* wheels, launch and flightstate, so
* it is better to split them in a module
*/
if (m_dBody->IsType(Object::SHIP)) {
if (m_dBody->IsType(ObjectType::SHIP)) {
Ship *ship = static_cast<Ship *>(m_dBody);
assert(ship != nullptr);
if (ship->GetFlightState() == Ship::JUMPING) return false;
@ -985,7 +985,7 @@ bool AICmdFlyTo::TimeStepUpdate()
double targdist = relpos.Length();
#ifdef DEBUG_AUTOPILOT
if (m_ship->IsType(Object::PLAYER))
if (m_ship->IsType(ObjectType::PLAYER))
Output("Autopilot dist = %.1f, speed = %.1f, zthrust = %.2f, state = %i\n",
targdist, relvel.Length(), m_ship->GetLinThrusterState().z, m_state);
#endif
@ -1037,7 +1037,7 @@ bool AICmdFlyTo::TimeStepUpdate()
}
// target ship acceleration adjustment
if (m_target && m_target->IsType(Object::SHIP)) {
if (m_target && m_target->IsType(ObjectType::SHIP)) {
Ship *targship = static_cast<Ship *>(m_target);
matrix3x3d orient = Frame::GetFrame(m_target->GetFrame())->GetOrientRelTo(m_frameId);
vector3d targaccel = orient * targship->GetLastForce() / m_target->GetMass();
@ -1072,7 +1072,7 @@ bool AICmdFlyTo::TimeStepUpdate()
// cap target speed according to spare fuel remaining
double fuelspeed = m_prop->GetSpeedReachedWithFuel();
if (m_target && m_target->IsType(Object::SHIP)) fuelspeed -=
if (m_target && m_target->IsType(ObjectType::SHIP)) fuelspeed -=
m_dBody->GetVelocityRelTo(Pi::game->GetSpace()->GetRootFrame()).Length();
if (ispeed > curspeed && curspeed > 0.9 * fuelspeed) ispeed = curspeed;
@ -1125,7 +1125,7 @@ bool AICmdFlyTo::TimeStepUpdate()
return true;
} else
m_prop->AIFaceDirection(head);
if (body && body->IsType(Object::PLANET) && m_dBody->GetPosition().LengthSqr() < 2 * erad * erad)
if (body && body->IsType(ObjectType::PLANET) && m_dBody->GetPosition().LengthSqr() < 2 * erad * erad)
m_prop->AIFaceUpdir(m_dBody->GetPosition()); // turn bottom thruster towards planet
// termination conditions: check
@ -1166,7 +1166,7 @@ AICmdDock::AICmdDock(DynamicBody *dBody, SpaceStation *target) :
m_state(eDockGetDataStart)
{
Ship *ship = nullptr;
if (!dBody->IsType(Object::SHIP)) return;
if (!dBody->IsType(ObjectType::SHIP)) return;
ship = static_cast<Ship *>(dBody);
assert(ship != nullptr);
@ -1234,7 +1234,7 @@ bool AICmdDock::TimeStepUpdate()
if (!ProcessChild()) return false;
if (!m_target) return true;
if (!m_dBody->IsType(Object::SHIP)) return false;
if (!m_dBody->IsType(ObjectType::SHIP)) return false;
ship = static_cast<Ship *>(m_dBody);
assert(ship != nullptr);
@ -1414,7 +1414,7 @@ void AICmdFlyAround::Setup(Body *obstructor, double alt, double vel, int mode)
// generate suitable velocity if none provided
double minacc = (mode == 2) ? 0 : m_prop->GetAccelMin();
double mass = obstructor->IsType(Object::TERRAINBODY) ? obstructor->GetMass() : 0;
double mass = obstructor->IsType(ObjectType::TERRAINBODY) ? obstructor->GetMass() : 0;
if (vel < 1e-30) m_vel = sqrt(m_alt * 0.8 * minacc + mass * G / m_alt);
}
@ -1482,7 +1482,7 @@ double AICmdFlyAround::MaxVel(double targdist, double targalt)
bool AICmdFlyAround::TimeStepUpdate()
{
if (m_dBody->IsType(Object::SHIP)) {
if (m_dBody->IsType(ObjectType::SHIP)) {
Ship *ship = nullptr;
ship = static_cast<Ship *>(m_dBody);
assert(ship != 0);
@ -1629,7 +1629,7 @@ void AICmdFormation::PostLoadFixup(Space *space)
bool AICmdFormation::TimeStepUpdate()
{
if (m_dBody->IsType(Object::SHIP)) {
if (m_dBody->IsType(ObjectType::SHIP)) {
Ship *ship = static_cast<Ship *>(m_dBody);
assert(ship != 0);
@ -1669,7 +1669,7 @@ bool AICmdFormation::TimeStepUpdate()
double ispeed = calc_ivel(targdist, 0.0, maxdecel);
vector3d vdiff = ispeed * reldir - relvel;
m_prop->AIChangeVelDir(vdiff * m_dBody->GetOrient());
if (m_target->IsType(Object::SHIP)) {
if (m_target->IsType(ObjectType::SHIP)) {
Ship *target_ship = static_cast<Ship *>(m_target);
if (target_ship->IsDecelerating()) m_dBody->SetDecelerating(true);
} else {

View File

@ -64,6 +64,14 @@ ShipCpanel::~ShipCpanel()
delete m_radar;
}
void ShipCpanel::SetRadarVisible(bool visible)
{
if (visible)
m_radar->Show();
else
m_radar->Hide();
}
void ShipCpanel::Update()
{
PROFILE_SCOPED()

View File

@ -6,7 +6,6 @@
#include "Game.h"
#include "Ship.h"
#include "ShipCpanelMultiFuncDisplays.h"
#include "WorldView.h"
#include "gui/Gui.h"
#include "libs.h"
@ -17,6 +16,7 @@ namespace Graphics {
class Renderer;
}
class RadarWidget;
class ShipCpanel : public Gui::Fixed {
public:
ShipCpanel(Graphics::Renderer *r, Game *game);
@ -29,13 +29,7 @@ public:
void SaveToJson(Json &jsonObj);
void SetRadarVisible(bool visible)
{
if (visible)
m_radar->Show();
else
m_radar->Hide();
}
void SetRadarVisible(bool visible);
private:
void InitObject();

View File

@ -208,7 +208,7 @@ void RadarWidget::Update()
switch (body->GetType()) {
case Object::MISSILE:
case ObjectType::MISSILE:
// player's own missiles are ignored for range calc but still shown
if (static_cast<const Missile *>(body)->GetOwner() == Pi::player) {
c.isSpecial = true;
@ -217,7 +217,7 @@ void RadarWidget::Update()
// else fall through
case Object::SHIP: {
case ObjectType::SHIP: {
const Ship *s = static_cast<const Ship *>(body);
if (s->GetFlightState() != Ship::FLYING && s->GetFlightState() != Ship::LANDED)
continue;
@ -236,9 +236,9 @@ void RadarWidget::Update()
break;
}
case Object::SPACESTATION:
case Object::CARGOBODY:
case Object::HYPERSPACECLOUD:
case ObjectType::SPACESTATION:
case ObjectType::CARGOBODY:
case ObjectType::HYPERSPACECLOUD:
if ((body) == Pi::player->GetNavTarget()) c.isSpecial = true;
@ -321,35 +321,35 @@ void RadarWidget::DrawBlobs(bool below)
const Color *color = 0;
switch (i->type) {
case Object::SHIP:
case ObjectType::SHIP:
if (i->isSpecial)
color = &radarCombatTargetColour;
else
color = &radarShipColour;
break;
case Object::MISSILE:
case ObjectType::MISSILE:
if (i->isSpecial)
color = &radarPlayerMissileColour;
else
color = &radarMissileColour;
break;
case Object::SPACESTATION:
case ObjectType::SPACESTATION:
if (i->isSpecial)
color = &radarNavTargetColour;
else
color = &radarStationColour;
break;
case Object::CARGOBODY:
case ObjectType::CARGOBODY:
if (i->isSpecial)
color = &radarNavTargetColour;
else
color = &radarCargoColour;
break;
case Object::HYPERSPACECLOUD:
case ObjectType::HYPERSPACECLOUD:
if (i->isSpecial)
color = &radarNavTargetColour;
else

View File

@ -5,9 +5,9 @@
#define _SHIPCPANELMULTIFUNCDISPLAYS_H
#include "JsonFwd.h"
#include "Object.h"
#include "gui/Gui.h"
enum class ObjectType;
class Body;
namespace Graphics {
class Renderer;
@ -52,7 +52,7 @@ private:
sigc::connection m_toggleScanModeConnection;
struct Contact {
Object::Type type;
ObjectType type;
vector3d pos;
bool isSpecial;
};

View File

@ -246,7 +246,7 @@ void Space::RebuildBodyIndex()
// also index ships inside clouds
// XXX we should not have to know about this. move indexing grunt work
// down into the bodies?
if (b->IsType(Object::HYPERSPACECLOUD)) {
if (b->IsType(ObjectType::HYPERSPACECLOUD)) {
Ship *s = static_cast<HyperspaceCloud *>(b)->GetShip();
if (s) m_bodyIndex.push_back(s);
}
@ -363,7 +363,7 @@ void Space::GetHyperspaceExitParams(const SystemPath &source, const SystemPath &
pos += primary->GetPositionRelTo(GetRootFrame());
}
Body *Space::FindNearestTo(const Body *b, Object::Type t) const
Body *Space::FindNearestTo(const Body *b, ObjectType t) const
{
Body *nearest = 0;
double dist = FLT_MAX;
@ -752,7 +752,7 @@ static FrameId MakeFramesFor(const double at_time, SystemBody *sbody, Body *b, F
Frame *rotFrame = Frame::GetFrame(rotFrameId);
assert(rotFrame->IsRotFrame());
assert(rotFrame->GetBody()->IsType(Object::PLANET));
assert(rotFrame->GetBody()->IsType(ObjectType::PLANET));
matrix3x3d rot;
vector3d pos;
Planet *planet = static_cast<Planet *>(rotFrame->GetBody());
@ -798,17 +798,11 @@ void Space::GenBody(const double at_time, SystemBody *sbody, FrameId fId, std::v
}
}
static bool OnCollision(Object *o1, Object *o2, CollisionContact *c, double relativeVel)
static bool OnCollision(Body *o1, Body *o2, CollisionContact *c, double relativeVel)
{
Body *pb1 = static_cast<Body *>(o1);
Body *pb2 = static_cast<Body *>(o2);
/* Not always a Body (could be CityOnPlanet, which is a nasty exception I should eradicate) */
if (o1->IsType(Object::BODY)) {
if (pb1 && !pb1->OnCollision(o2, c->geomFlag, relativeVel)) return false;
}
if (o2->IsType(Object::BODY)) {
if (pb2 && !pb2->OnCollision(o1, c->geomFlag, relativeVel)) return false;
}
/* XXX: if you create a new class inheriting from Object instead of Body, this code must be updated */
if (o1 && !o1->OnCollision(o2, c->geomFlag, relativeVel)) return false;
if (o2 && !o2->OnCollision(o1, c->geomFlag, relativeVel)) return false;
return true;
}
@ -816,11 +810,11 @@ static void hitCallback(CollisionContact *c)
{
//Output("OUCH! %x (depth %f)\n", SDL_GetTicks(), c->depth);
Object *po1 = static_cast<Object *>(c->userData1);
Object *po2 = static_cast<Object *>(c->userData2);
Body *po1 = static_cast<Body *>(c->userData1);
Body *po2 = static_cast<Body *>(c->userData2);
const bool po1_isDynBody = po1->IsType(Object::DYNAMICBODY);
const bool po2_isDynBody = po2->IsType(Object::DYNAMICBODY);
const bool po1_isDynBody = po1->IsType(ObjectType::DYNAMICBODY);
const bool po2_isDynBody = po2->IsType(ObjectType::DYNAMICBODY);
// collision response
assert(po1_isDynBody || po2_isDynBody);
@ -935,7 +929,7 @@ static void hitCallback(CollisionContact *c)
// temporary one-point version
static void CollideWithTerrain(Body *body, float timeStep)
{
if (!body->IsType(Object::DYNAMICBODY))
if (!body->IsType(ObjectType::DYNAMICBODY))
return;
DynamicBody *dynBody = static_cast<DynamicBody *>(body);
if (!dynBody->IsMoving())
@ -944,7 +938,7 @@ static void CollideWithTerrain(Body *body, float timeStep)
Frame *f = Frame::GetFrame(body->GetFrame());
if (!f || !f->GetBody() || f->GetId() != f->GetBody()->GetFrame())
return;
if (!f->GetBody()->IsType(Object::TERRAINBODY))
if (!f->GetBody()->IsType(ObjectType::TERRAINBODY))
return;
TerrainBody *terrain = static_cast<TerrainBody *>(f->GetBody());

View File

@ -7,7 +7,6 @@
#include "Background.h"
#include "FrameId.h"
#include "IterationProxy.h"
#include "Object.h"
#include "RefCounted.h"
#include "galaxy/StarSystem.h"
#include "vector3.h"
@ -15,6 +14,7 @@
class Body;
class Frame;
class Game;
enum class ObjectType;
class Space {
public:
@ -62,7 +62,7 @@ public:
return GetHyperspaceExitPoint(source, m_starSystem->GetPath());
}
Body *FindNearestTo(const Body *b, Object::Type t) const;
Body *FindNearestTo(const Body *b, ObjectType t) const;
Body *FindBodyForPath(const SystemPath *path) const;
Uint32 GetNumBodies() const { return static_cast<Uint32>(m_bodies.size()); }

View File

@ -201,7 +201,7 @@ void SpaceStation::InitStation()
m_navLights.reset(new NavLights(model, 2.2f));
m_navLights->SetEnabled(true);
if (ground) SetClipRadius(CITY_ON_PLANET_RADIUS); // overrides setmodel
if (ground) SetClipRadius(CityOnPlanet::RADIUS); // overrides setmodel
m_doorAnimation = model->FindAnimation("doors");
@ -341,7 +341,7 @@ bool SpaceStation::GetDockingClearance(Ship *s, std::string &outMsg)
// distance-to-station check
const double shipDist = s->GetPositionRelTo(this).Length();
double requestDist = 100000.0; //100km
if (s->IsType(Object::PLAYER) && shipDist > requestDist) {
if (s->IsType(ObjectType::PLAYER) && shipDist > requestDist) {
outMsg = Lang::CLEARANCE_DENIED_TOO_FAR;
return false;
}
@ -362,9 +362,9 @@ bool SpaceStation::GetDockingClearance(Ship *s, std::string &outMsg)
return false;
}
bool SpaceStation::OnCollision(Object *b, Uint32 flags, double relVel)
bool SpaceStation::OnCollision(Body *b, Uint32 flags, double relVel)
{
if ((flags & 0x10) && (b->IsType(Object::SHIP))) {
if ((flags & 0x10) && (b->IsType(ObjectType::SHIP))) {
Ship *s = static_cast<Ship *>(b);
int port = -1;
@ -724,7 +724,7 @@ void SpaceStation::Render(Graphics::Renderer *r, const Camera *camera, const vec
Body *b = Frame::GetFrame(GetFrame())->GetBody();
assert(b);
if (!b->IsType(Object::PLANET)) {
if (!b->IsType(ObjectType::PLANET)) {
// orbital spaceport -- don't make city turds or change lighting based on atmosphere
RenderModel(r, camera, viewCoords, viewTransform);
m_navLights->Render(r);

View File

@ -39,7 +39,7 @@ public:
virtual ~SpaceStation();
virtual vector3d GetAngVelocity() const { return vector3d(0, m_type->AngVel(), 0); }
virtual bool OnCollision(Object *b, Uint32 flags, double relVel) override;
virtual bool OnCollision(Body *b, Uint32 flags, double relVel) override;
bool DoShipDamage(Ship *s, Uint32 flags, double relVel);
virtual void Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) override;
virtual void StaticUpdate(const float timeStep) override;

View File

@ -429,9 +429,9 @@ void SystemInfoView::UpdateIconSelections()
//navtarget can be only set in current system
Body *navtarget = Pi::player->GetNavTarget();
if (navtarget &&
(navtarget->IsType(Body::STAR) ||
navtarget->IsType(Body::PLANET) ||
navtarget->IsType(Body::SPACESTATION))) {
(navtarget->IsType(ObjectType::STAR) ||
navtarget->IsType(ObjectType::PLANET) ||
navtarget->IsType(ObjectType::SPACESTATION))) {
const SystemPath &navpath = navtarget->GetSystemBody()->GetPath();
if (bodyIcon.first == navpath.bodyIndex) {
bodyIcon.second->SetSelectColor(Color(0, 255, 0, 255));

View File

@ -430,7 +430,7 @@ void SystemView::GetTransformTo(Projectable &p, vector3d &pos)
pos = vector3d(0., 0., 0.);
if (p.base == Projectable::SYSTEMBODY)
GetTransformTo(p.ref.sbody, pos);
else if (p.ref.body->GetType() == Object::Type::SHIP || p.ref.body->GetType() == Object::Type::PLAYER) {
else if (p.ref.body->GetType() == ObjectType::SHIP || p.ref.body->GetType() == ObjectType::PLAYER) {
const Ship *s = static_cast<const Ship *>(p.ref.body);
CalculateShipPositionAtTime(s, s->ComputeOrbit(), m_time, pos);
pos = -pos;
@ -653,7 +653,7 @@ void SystemView::RefreshShips(void)
auto bs = m_game->GetSpace()->GetBodies();
for (auto s = bs.begin(); s != bs.end(); s++) {
if ((*s) != Pi::player &&
(*s)->GetType() == Object::SHIP) {
(*s)->GetType() == ObjectType::SHIP) {
const auto c = static_cast<Ship *>(*s);
m_contacts.push_back(std::make_pair(c, c->ComputeOrbit()));

View File

@ -25,7 +25,7 @@ public:
virtual void Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) override;
virtual void SubRender(Graphics::Renderer *r, const matrix4x4d &modelView, const vector3d &camPos) {}
virtual void SetFrame(FrameId fId) override;
virtual bool OnCollision(Object *b, Uint32 flags, double relVel) override { return true; }
virtual bool OnCollision(Body *b, Uint32 flags, double relVel) override { return true; }
virtual double GetMass() const override { return m_mass; }
double GetTerrainHeight(const vector3d &pos) const;
virtual const SystemBody *GetSystemBody() const override { return m_sbody; }

View File

@ -306,7 +306,7 @@ void WorldView::UpdateProjectedObjects()
matrix3x3d cam_rot = cam_frame->GetOrient();
// later we might want non-ship enemies (e.g., for assaults on military bases)
assert(!Pi::player->GetCombatTarget() || Pi::player->GetCombatTarget()->IsType(Object::SHIP));
assert(!Pi::player->GetCombatTarget() || Pi::player->GetCombatTarget()->IsType(ObjectType::SHIP));
// update combat HUD
Ship *enemy = static_cast<Ship *>(Pi::player->GetCombatTarget());
@ -707,7 +707,7 @@ static vector3d projectToScreenSpace(const vector3d &pos, RefCountedPtr<CameraCo
// project a body in world-space to a screen-space location
vector3d WorldView::WorldSpaceToScreenSpace(const Body *body) const
{
if (body->IsType(Object::PLAYER) && !shipView->IsExteriorView())
if (body->IsType(ObjectType::PLAYER) && !shipView->IsExteriorView())
return vector3d(0, 0, 0);
vector3d pos = body->GetInterpPositionRelTo(m_cameraContext->GetCameraFrame());
@ -743,7 +743,7 @@ vector3d WorldView::CameraSpaceToScreenSpace(const vector3d &pos) const
vector3d WorldView::GetTargetIndicatorScreenPosition(const Body *body) const
{
if (body->IsType(Object::PLAYER) && !shipView->IsExteriorView())
if (body->IsType(ObjectType::PLAYER) && !shipView->IsExteriorView())
return vector3d(0, 0, 0);
// get the target indicator position in body-local coordinates

View File

@ -6,7 +6,6 @@
#include "enum_table.h"
#include "DynamicBody.h"
#include "Object.h"
#include "Ship.h"
#include "ShipAICmd.h"
#include "ShipType.h"
@ -40,15 +39,15 @@ const struct EnumItem ENUM_ShipAIError[] = {
};
const struct EnumItem ENUM_PhysicsObjectType[] = {
{ "BODY", int(Object::BODY) },
{ "MODELBODY", int(Object::MODELBODY) },
{ "SHIP", int(Object::SHIP) },
{ "PLAYER", int(Object::PLAYER) },
{ "SPACESTATION", int(Object::SPACESTATION) },
{ "PLANET", int(Object::PLANET) },
{ "STAR", int(Object::STAR) },
{ "CARGOBODY", int(Object::CARGOBODY) },
{ "MISSILE", int(Object::MISSILE) },
{ "BODY", int(ObjectType::BODY) },
{ "MODELBODY", int(ObjectType::MODELBODY) },
{ "SHIP", int(ObjectType::SHIP) },
{ "PLAYER", int(ObjectType::PLAYER) },
{ "SPACESTATION", int(ObjectType::SPACESTATION) },
{ "PLANET", int(ObjectType::PLANET) },
{ "STAR", int(ObjectType::STAR) },
{ "CARGOBODY", int(ObjectType::CARGOBODY) },
{ "MISSILE", int(ObjectType::MISSILE) },
{ 0, 0 },
};

View File

@ -161,14 +161,14 @@ static int l_body_is_moon(lua_State *l)
static int l_body_is_missile(lua_State *l)
{
Body *body = LuaObject<Body>::CheckFromLua(1);
LuaPush<bool>(l, body->GetType() == Object::Type::MISSILE);
LuaPush<bool>(l, body->GetType() == ObjectType::MISSILE);
return 1;
}
static int l_body_is_station(lua_State *l)
{
Body *body = LuaObject<Body>::CheckFromLua(1);
LuaPush<bool>(l, body->GetType() == Object::Type::SPACESTATION);
LuaPush<bool>(l, body->GetType() == ObjectType::SPACESTATION);
return 1;
}
@ -191,21 +191,21 @@ static int l_body_is_ground_station(lua_State *l)
static int l_body_is_cargo_container(lua_State *l)
{
Body *body = LuaObject<Body>::CheckFromLua(1);
LuaPush<bool>(l, body->GetType() == Object::Type::CARGOBODY);
LuaPush<bool>(l, body->GetType() == ObjectType::CARGOBODY);
return 1;
}
static int l_body_is_ship(lua_State *l)
{
Body *body = LuaObject<Body>::CheckFromLua(1);
LuaPush<bool>(l, body->GetType() == Object::Type::SHIP);
LuaPush<bool>(l, body->GetType() == ObjectType::SHIP);
return 1;
}
static int l_body_is_hyperspace_cloud(lua_State *l)
{
Body *body = LuaObject<Body>::CheckFromLua(1);
LuaPush<bool>(l, body->GetType() == Object::Type::HYPERSPACECLOUD);
LuaPush<bool>(l, body->GetType() == ObjectType::HYPERSPACECLOUD);
return 1;
}
@ -304,7 +304,7 @@ static int l_body_get_altitude_rel_to(lua_State *l)
const Body *other = LuaObject<Body>::CheckFromLua(2);
vector3d pos = Pi::player->GetPositionRelTo(other);
double center_dist = pos.Length();
if (other && other->IsType(Object::TERRAINBODY)) {
if (other && other->IsType(ObjectType::TERRAINBODY)) {
const TerrainBody *terrain = static_cast<const TerrainBody *>(other);
vector3d surface_pos = pos.Normalized();
double radius = 0.0;
@ -401,7 +401,7 @@ static int l_body_attr_super_type(lua_State *l)
static int l_body_attr_frame_body(lua_State *l)
{
Body *b = LuaObject<Body>::CheckFromLua(1);
if (!b->IsType(Object::DYNAMICBODY)) {
if (!b->IsType(ObjectType::DYNAMICBODY)) {
lua_pushnil(l);
return 1;
}
@ -430,7 +430,7 @@ static int l_body_attr_frame_body(lua_State *l)
static int l_body_attr_frame_rotating(lua_State *l)
{
Body *b = LuaObject<Body>::CheckFromLua(1);
if (!b->IsType(Object::DYNAMICBODY)) {
if (!b->IsType(ObjectType::DYNAMICBODY)) {
lua_pushnil(l);
return 1;
}
@ -473,7 +473,7 @@ static int l_body_attr_frame_rotating(lua_State *l)
static int l_body_is_dynamic(lua_State *l)
{
Body *b = LuaObject<Body>::CheckFromLua(1);
lua_pushboolean(l, b->IsType(Object::DYNAMICBODY));
lua_pushboolean(l, b->IsType(ObjectType::DYNAMICBODY));
return 1;
}
@ -544,7 +544,7 @@ static int l_body_distance_to(lua_State *l)
static int l_body_get_ground_position(lua_State *l)
{
Body *b = LuaObject<Body>::CheckFromLua(1);
if (!b->IsType(Object::DYNAMICBODY)) {
if (!b->IsType(ObjectType::DYNAMICBODY)) {
lua_pushnil(l);
return 1;
}
@ -559,7 +559,7 @@ static int l_body_get_ground_position(lua_State *l)
lua_pushnumber(l, latitude);
lua_pushnumber(l, longitude);
Body *astro = f->GetBody();
if (astro->IsType(Object::TERRAINBODY)) {
if (astro->IsType(ObjectType::TERRAINBODY)) {
double radius = static_cast<TerrainBody *>(astro)->GetTerrainHeight(pos.Normalized());
double altitude = pos.Length() - radius;
lua_pushnumber(l, altitude);
@ -602,7 +602,7 @@ static int l_body_get_ground_position(lua_State *l)
static int l_body_find_nearest_to(lua_State *l)
{
Body *b = LuaObject<Body>::CheckFromLua(1);
Object::Type type = static_cast<Object::Type>(LuaConstants::GetConstantFromArg(l, "PhysicsObjectType", 2));
ObjectType type = static_cast<ObjectType>(LuaConstants::GetConstantFromArg(l, "PhysicsObjectType", 2));
Body *nearest = Pi::game->GetSpace()->FindNearestTo(b, type);
LuaObject<Body>::PushToLua(nearest);
@ -663,7 +663,7 @@ static int l_body_get_atmospheric_state(lua_State *l)
// const SystemBody *sb = b->GetSystemBody();
vector3d pos = Pi::player->GetPosition();
double center_dist = pos.Length();
if (b->IsType(Object::PLANET)) {
if (b->IsType(ObjectType::PLANET)) {
double pressure, density;
static_cast<Planet *>(b)->GetAtmosphericState(center_dist, &pressure, &density);
lua_pushnumber(l, pressure);
@ -693,34 +693,34 @@ static bool push_body_to_lua(Body *body)
{
assert(body);
switch (body->GetType()) {
case Object::BODY:
case ObjectType::BODY:
LuaObject<Body>::PushToLua(body);
break;
case Object::MODELBODY:
case ObjectType::MODELBODY:
LuaObject<Body>::PushToLua(dynamic_cast<ModelBody *>(body));
break;
case Object::SHIP:
case ObjectType::SHIP:
LuaObject<Ship>::PushToLua(dynamic_cast<Ship *>(body));
break;
case Object::PLAYER:
case ObjectType::PLAYER:
LuaObject<Player>::PushToLua(dynamic_cast<Player *>(body));
break;
case Object::SPACESTATION:
case ObjectType::SPACESTATION:
LuaObject<SpaceStation>::PushToLua(dynamic_cast<SpaceStation *>(body));
break;
case Object::PLANET:
case ObjectType::PLANET:
LuaObject<Planet>::PushToLua(dynamic_cast<Planet *>(body));
break;
case Object::STAR:
case ObjectType::STAR:
LuaObject<Star>::PushToLua(dynamic_cast<Star *>(body));
break;
case Object::CARGOBODY:
case ObjectType::CARGOBODY:
LuaObject<Star>::PushToLua(dynamic_cast<CargoBody *>(body));
break;
case Object::MISSILE:
case ObjectType::MISSILE:
LuaObject<Missile>::PushToLua(dynamic_cast<Missile *>(body));
break;
case Object::HYPERSPACECLOUD:
case ObjectType::HYPERSPACECLOUD:
LuaObject<HyperspaceCloud>::PushToLua(dynamic_cast<HyperspaceCloud *>(body));
break;
default:

View File

@ -1697,13 +1697,13 @@ PiGui::TScreenSpace lua_world_space_to_screen_space(const Body *body)
bool PiGui::first_body_is_more_important_than(Body *body, Body *other)
{
Object::Type a = body->GetType();
ObjectType a = body->GetType();
const SystemBody *sb_a = body->GetSystemBody();
bool a_gas_giant = sb_a && sb_a->GetSuperType() == SystemBody::SUPERTYPE_GAS_GIANT;
bool a_planet = sb_a && sb_a->IsPlanet();
bool a_moon = sb_a && sb_a->IsMoon();
Object::Type b = other->GetType();
ObjectType b = other->GetType();
const SystemBody *sb_b = other->GetSystemBody();
bool b_gas_giant = sb_b && sb_b->GetSuperType() == SystemBody::SUPERTYPE_GAS_GIANT;
bool b_planet = sb_b && sb_b->IsPlanet();
@ -1714,12 +1714,12 @@ bool PiGui::first_body_is_more_important_than(Body *body, Body *other)
// if type is the same, just sort alphabetically
// planets are different, because moons are
// less important (but don't have their own type)
if (a == b && a != Object::Type::PLANET) result = body->GetLabel() < other->GetLabel();
if (a == b && a != ObjectType::PLANET) result = body->GetLabel() < other->GetLabel();
// a star is larger than any other object
else if (a == Object::Type::STAR)
else if (a == ObjectType::STAR)
result = true;
// any (non-star) object is smaller than a star
else if (b == Object::Type::STAR)
else if (b == ObjectType::STAR)
result = false;
// a gas giant is larger than anything but a star,
// but remember to keep total order in mind: if both are
@ -1746,34 +1746,30 @@ bool PiGui::first_body_is_more_important_than(Body *body, Body *other)
// a non-moon is smaller than any moon
else if (b_moon)
result = false;
// spacestation > city > ship > hyperspace cloud > cargo body > missile > projectile
else if (a == Object::Type::SPACESTATION)
// spacestation > ship > hyperspace cloud > cargo body > missile > projectile
else if (a == ObjectType::SPACESTATION)
result = true;
else if (b == Object::Type::SPACESTATION)
else if (b == ObjectType::SPACESTATION)
result = false;
else if (a == Object::Type::CITYONPLANET)
else if (a == ObjectType::SHIP)
result = true;
else if (b == Object::Type::CITYONPLANET)
else if (b == ObjectType::SHIP)
result = false;
else if (a == Object::Type::SHIP)
else if (a == ObjectType::HYPERSPACECLOUD)
result = true;
else if (b == Object::Type::SHIP)
else if (b == ObjectType::HYPERSPACECLOUD)
result = false;
else if (a == Object::Type::HYPERSPACECLOUD)
else if (a == ObjectType::CARGOBODY)
result = true;
else if (b == Object::Type::HYPERSPACECLOUD)
else if (b == ObjectType::CARGOBODY)
result = false;
else if (a == Object::Type::CARGOBODY)
else if (a == ObjectType::MISSILE)
result = true;
else if (b == Object::Type::CARGOBODY)
else if (b == ObjectType::MISSILE)
result = false;
else if (a == Object::Type::MISSILE)
else if (a == ObjectType::PROJECTILE)
result = true;
else if (b == Object::Type::MISSILE)
result = false;
else if (a == Object::Type::PROJECTILE)
result = true;
else if (b == Object::Type::PROJECTILE)
else if (b == ObjectType::PROJECTILE)
result = false;
else
Error("don't know how to compare %i and %i\n", a, b);
@ -1829,8 +1825,8 @@ static int l_pigui_get_projected_bodies_grouped(lua_State *l)
for (Body *body : Pi::game->GetSpace()->GetBodies()) {
if (body == Pi::game->GetPlayer()) continue;
if (body->GetType() == Object::PROJECTILE) continue;
if (body->GetType() == Object::SHIP &&
if (body->GetType() == ObjectType::PROJECTILE) continue;
if (body->GetType() == ObjectType::SHIP &&
body->GetPositionRelTo(Pi::player).Length() > ship_max_distance) continue;
const PiGui::TScreenSpace res = lua_world_space_to_screen_space(body); // defined in LuaPiGui.cpp
if (!res._onScreen) continue;
@ -1934,7 +1930,7 @@ static int l_pigui_get_projected_bodies(lua_State *l)
filtered.reserve(Pi::game->GetSpace()->GetNumBodies());
for (Body *body : Pi::game->GetSpace()->GetBodies()) {
if (body == Pi::game->GetPlayer()) continue;
if (body->GetType() == Object::PROJECTILE) continue;
if (body->GetType() == ObjectType::PROJECTILE) continue;
const PiGui::TScreenSpace res = lua_world_space_to_screen_space(body); // defined in LuaPiGui.cpp
if (!res._onScreen) continue;
filtered.emplace_back(res);
@ -1966,7 +1962,7 @@ static int l_pigui_get_targets_nearby(lua_State *l)
filtered.reserve(nearby.size());
for (Body *body : nearby) {
if (body == Pi::player) continue;
if (body->GetType() == Object::PROJECTILE) continue;
if (body->GetType() == ObjectType::PROJECTILE) continue;
filtered.push_back(body);
};

View File

@ -604,7 +604,7 @@ static int l_get_gps(lua_State *l)
Frame *playerFrame = Frame::GetFrame(playerFrameId);
if (playerFrameId.valid()) {
Body *astro = Frame::GetFrame(playerFrameId)->GetBody();
if (astro && astro->IsType(Object::TERRAINBODY)) {
if (astro && astro->IsType(ObjectType::TERRAINBODY)) {
TerrainBody *terrain = static_cast<TerrainBody *>(astro);
if (!playerFrame->IsRotFrame())
playerFrame = Frame::GetFrame(playerFrame->GetRotFrame());

View File

@ -937,7 +937,7 @@ static int l_ship_get_set_speed_target(lua_State *l)
{
Ship *s = LuaObject<Ship>::CheckFromLua(1);
Body *t = s->GetController()->GetSetSpeedTarget();
if (s->GetType() == Object::Type::PLAYER && t == nullptr) {
if (s->GetType() == ObjectType::PLAYER && t == nullptr) {
FrameId fId = s->GetFrame();
Frame *f = Frame::GetFrame(fId);
if (f)
@ -1401,7 +1401,7 @@ static int l_ship_ai_enter_low_orbit(lua_State *l)
if (s->GetFlightState() == Ship::HYPERSPACE)
return luaL_error(l, "Ship:AIEnterLowOrbit() cannot be called on a ship in hyperspace");
Body *target = LuaObject<Body>::CheckFromLua(2);
if (!target->IsType(Object::PLANET) && !target->IsType(Object::STAR))
if (!target->IsType(ObjectType::PLANET) && !target->IsType(ObjectType::STAR))
luaL_argerror(l, 2, "expected a Planet or a Star");
s->AIOrbit(target, 1.2);
return 0;
@ -1432,7 +1432,7 @@ static int l_ship_ai_enter_medium_orbit(lua_State *l)
if (s->GetFlightState() == Ship::HYPERSPACE)
return luaL_error(l, "Ship:AIEnterMediumOrbit() cannot be called on a ship in hyperspace");
Body *target = LuaObject<Body>::CheckFromLua(2);
if (!target->IsType(Object::PLANET) && !target->IsType(Object::STAR))
if (!target->IsType(ObjectType::PLANET) && !target->IsType(ObjectType::STAR))
luaL_argerror(l, 2, "expected a Planet or a Star");
s->AIOrbit(target, 1.6);
return 0;
@ -1463,7 +1463,7 @@ static int l_ship_ai_enter_high_orbit(lua_State *l)
if (s->GetFlightState() == Ship::HYPERSPACE)
return luaL_error(l, "Ship:AIEnterHighOrbit() cannot be called on a ship in hyperspace");
Body *target = LuaObject<Body>::CheckFromLua(2);
if (!target->IsType(Object::PLANET) && !target->IsType(Object::STAR))
if (!target->IsType(ObjectType::PLANET) && !target->IsType(ObjectType::STAR))
luaL_argerror(l, 2, "expected a Planet or a Star");
s->AIOrbit(target, 3.5);
return 0;

View File

@ -196,7 +196,7 @@ void ExternalCameraController::Update()
// when landed don't let external view look from below
// XXX shouldn't be limited to player
const Ship *ship = GetShip();
if (ship->IsType(Object::PLAYER)) {
if (ship->IsType(ObjectType::PLAYER)) {
if (ship->GetFlightState() == Ship::LANDED ||
ship->GetFlightState() == Ship::DOCKED) {
m_rotX = Clamp(m_rotX, DEG2RAD(-170.0), DEG2RAD(-5.0));

View File

@ -5,7 +5,6 @@
#include "Game.h"
#include "GameSaveError.h"
#include "Object.h" // <- here only for comment in AIFaceDirection (line 320)
#include "Pi.h"
#include "Player.h"
#include "PlayerShipController.h"
@ -437,7 +436,7 @@ double Propulsion::AIFaceDirection(const vector3d &dir, double av)
// baseclass version in Ship would always be 0. the version in Player
// would be constructed from user input. that adjustment could then be
// considered by this method when computing the required change
if (m_dBody->IsType(Object::PLAYER)) {
if (m_dBody->IsType(ObjectType::PLAYER)) {
auto *playerController = static_cast<const Player *>(m_dBody)->GetPlayerController();
if (playerController->InputBindings.roll->IsActive())
diff.z = GetAngThrusterState().z;

View File

@ -152,7 +152,7 @@ void AmbientSounds::Update()
Frame *playerFrame = Frame::GetFrame(Pi::player->GetFrame());
if (playerFrame->IsRotFrame()) {
const Body *astro = playerFrame->GetBody();
if (astro->IsType(Object::PLANET)) {
if (astro->IsType(ObjectType::PLANET)) {
const double dist = Pi::player->GetPosition().Length();
double pressure, density;
static_cast<const Planet *>(astro)->GetAtmosphericState(dist, &pressure, &density);
@ -230,7 +230,7 @@ void AmbientSounds::Update()
Frame *playerFrame = Frame::GetFrame(Pi::player->GetFrame());
const Body *astro = playerFrame->GetBody();
if (astro && playerFrame->IsRotFrame() && (astro->IsType(Object::PLANET))) {
if (astro && playerFrame->IsRotFrame() && (astro->IsType(ObjectType::PLANET))) {
double dist = Pi::player->GetPosition().Length();
double pressure, density;
static_cast<const Planet *>(astro)->GetAtmosphericState(dist, &pressure, &density);

View File

@ -19,7 +19,6 @@
#include "GeoPatch.h"
#include "GeoPatchContext.h"
#include "GeoSphere.h"
#include "Object.h"
#include "ObjectViewerView.h"
#include "Pi.h"
#include "Planet.h"