if (engineType == 2) {whirr();} else {whoosh();}
engine.makeStartupNoise();
class Weapons ; end
class Communications ; end
class Hyperdrive ; end
class Cockpit ; end
class Space_Object ; end # Anything in space?
class Ship < Space_Object
include Cockpit
end
class Fighter < Ship
include Weapons
end
class Satellite < Space_Object
include Communications
end
class Hominid
include Head
include Torso
include Legs
include Arms
end
class Person < Hominid
include Student
include Biker
include Programmer
include PokerPlayer
end
class Ship
{
int _pos_x,_pos_y,_pos_z;
int _max_speed;
int _shield_type;
public:
Ship()
{
_shield_type=SHIELD_MINIMAL;
_max_speed=30;
}
};
class Fighter
{
public:
Fighter(void)
{
Ship::Ship();
_max_speed=20;
}
};
class Ship
{
int _pos_x,_pos_y,_pos_z;
int _max_speed;
int _shield_type;
public:
Ship()
{
_shield_type=SHIELD_MINIMAL;
_max_speed=30;
}
};
class Fighter
{
public:
Fighter(void)
{
Ship::Ship();
_max_speed=20;
}
};
class Chassis
{
private:
Chassis( const Chassis & );
Chassis &operator = ( const Chassis & );
public:
Chassis( );
~Chassis( );
private:
std::string m_Name; // Name of the Chassis, ex: Seinar Fleet Systems TIE Interceptor
/*
* Maneuverability is a combined value that takes a chassis' yaw, pitch and role rates and
* combines them into one simple value, that is used to determine how quickly a ship can
* complete maneuvers of varying types.
*/
short m_Maneuverability; // Base Maneuverabiity rating of the chassis
/*
* Acceleration and Deceleration values are used to determine how quickly a
* chassis can accelerate or decelerate. The value is moved during speeding
* up and slowing down to determine how large each change is.
*/
short m_Acceleration; // Base Acceleration rating of the chassis
short m_Deceleration; // Base Deceleration rating of the chassis
short m_WeaponMounts; // Number of Weapon mounts the Chassis has
/*
* Mass is used to determine how much weight in components a chassis can carry
* Every component will have a mass rating that will be added to the chassis when the
* part is installed.
*/
int m_MaxMass; // Maximum Mass the Chassis can carry
/*
* Hull is the ships hit points rather than individual compnent hitpoints
* Once the current hull reaches 0, the ship is destroyed.
* In the Future, it will be added that destroying a ship produces salvageable
* parts that can be collected based on the Mass of the destroyed ship.
*/
int m_MaxHull; // Maximum Hull Value
public:
// …Maybe these should be in class Ship?
int currentMass; // Current Mass the Chassis is carrying
int currentHull; // Current Hull Value
};
class Armor
{
private:
Armor( const Armor & );
Armor &operator = ( const Armor & );
public:
Armor( );
~Armor( );
private:
std::string m_Name; // Name of the Armor, ex: Gallofree Mark I Starfighter Armor
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Armor Hit points are something exclusive to the Armor part. Armor hit points absorb damage in
* combat. Once these are exhausted, components themselves begin taking damage.
*/
int m_ArmorHitPoints;
public:
};
class Booster
{
private:
Booster( const Booster & );
Booster &operator = ( const Booster & );
public:
Booster( );
~Booster( );
private:
std::string m_Name; // Name of the Booster, ex: Corellian Engineering Corp. TJH-3 Starship Boosters
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Reactor drain is the amount of energy a given part pulls away from the reactor to power itself.
* Typically the lower the number the better, as far as power consumption.
*/
int m_ReactorDrain;
/*
* Booster Energy is the total amount of energy the booster has until it runs out and needs to
* recharge itself.
*/
int m_BoosterEnergy;
/*
* Consumption Rate is how much of the booster energy is consumed each second the booster is
* engaged.
*/
int m_ConsumptionRate;
/*
* Recharge rate is how much the Booster pulls from the Reactor to recharge itself each second.
*/
int m_RechargeRate;
/*
* Top Booster Speed is the top speed attainable while using the booster.
*/
int m_TopBoosterSpeed;
/*
* The Acceleration rating is how much the booster modifies the ships acceleration rating
* when activated to increase the speed to the booster's top speed.
*/
int m_Acceleration;
public:
};
class Capacitor
{
private:
Capacitor( const Capacitor & );
Capacitor &operator = ( const Capacitor & );
public:
Capacitor( );
~Capacitor( );
private:
std::string m_Name; // Name of the Capacitor, ex: Incom BJN-825 Capacitor
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Reactor drain is the amount of energy a given part pulls away from the reactor to power itself.
* Typically the lower the number the better, as far as power consumption.
*/
int m_ReactorDrain;
/*
* Capacitor Energy is the total amount of energy the capacitor has until it runs out and needs to
* recharge itself.
*/
int m_CapacitorEnergy;
/*
* Recharge rate is how much the Capacitor pulls from the Reactor to recharge itself each second.
*/
int m_RechargeRate;
public:
};
class Reactor
{
private:
Reactor( const Reactor & );
Reactor &operator = ( const Reactor & );
public:
Reactor( );
~Reactor( );
private:
std::string m_Name; // Name of the Reactor, ex: Mark I Fusion Reactor
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Generation rate is the rate at which a reactor generates energy per second.
*/
int m_GenerationRate;
/*
* Charge is how much energy the reactor can hold at any given time. Generally you don't want this
* value to be any higher than needed to give power to all your components.
*/
int m_ReactorCharge;
public:
};
class Engine
{
private:
Engine( const Engine & );
Engine &operator = ( const Engine & );
public:
Engine( );
~Engine( );
private:
std::string m_Name; // Name of the Engine, ex: Mark I Starfighter Engine
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Reactor drain is the amount of energy a given part pulls away from the reactor to power itself.
* Typically the lower the number the better, as far as power consumption.
*/
int m_ReactorDrain;
/*
* Top Speed is how fast the engine can make the ship move. This is modified by using a booster, or
* replacing it. Mass of a ship will also play a role in how fast it can move. A large ship will not
* recieve the same top speed as a smaller ship using the same engine.
*/
int m_TopSpeed;
/*
* Maneuverability is a combined value that takes an engine's yaw, pitch and role rates and
* combines them into one simple value, that is used to determine how quickly a ship can
* complete maneuvers of varying types. For Engines, Maneuverability is an ammount added to
* the chassis' maneuverability rating to improve it, rather than replace it.
*/
int m_Maneuverability;
public:
};
class ShieldGenerator
{
private:
ShieldGenerator( const ShieldGenerator & );
ShieldGenerator &operator = ( const ShieldGenerator & );
public:
ShieldGenerator( );
~ShieldGenerator( );
private:
std::string m_Name; // Name of the Shields, ex: Armek Plasma Shell Deflector Shields
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Reactor drain is the amount of energy a given part pulls away from the reactor to power itself.
* Typically the lower the number the better, as far as power consumption.
*/
int m_ReactorDrain;
/*
* Shield strength is equivalent to the HP of the shields themselves, rather than the shield generator
* which is covered in the components hit points.
*/
int m_ShieldStrength;
/*
* Recharge rate is how much the shields pull from the Reactor to recharge itself each second.
*/
int m_RechargeRate;
public:
};
class Weapon
{
private:
Weapon( const Weapon & );
Weapon &operator = ( const Weapon & );
public:
Weapon( );
~Weapon( );
private:
std::string m_Name; // Name of the Weapon, ex: Corellian Cruiser Grade Mark I Blaster
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Reactor drain is the amount of energy a given part pulls away from the reactor to power itself.
* Typically the lower the number the better, as far as power consumption.
*/
int m_ReactorDrain;
/*
* Damage is the base damage the weapon does to a ship. Damage is accompanied by a pair of modifiers
* vsArmor and vsShields. Some weapons are good at damaging armor, but not shields, and these modifiers
* help reflect that.
*/
int m_Damage;
int m_VsArmor;
int m_VsShield;
/*
* Capacitor drain is how much energy per shot a given weapon will drain from the capacitor. If the capacitor
* drain is too high for the capacitor, then the refire rate of the weapon will suffer horribly because it won't
* matter that the weapon can cycle once every 4 seconds when each shot drains the capacitor completely and you
* have to wait till the capacitor recharges to fire again.
*/
int m_CapacitorDrain;
/*
* Refire Rate is the rate at which the weapon cycles and is ready to fire again.
*/
int m_RefireRate;
public:
};
class Launcher
{
private:
Launcher( const Launcher & );
Launcher &operator = ( const Launcher & );
public:
Launcher( );
~Launcher( );
private:
std::string m_Name; // Name of the Launcher, ex: Cygnus Mark I Proton Torpedo Launcher
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Refire Rate is the rate at which the launcher cycles and is ready to fire again.
*/
int m_RefireRate;
/*
* This is the type of ordinance a given Launcher would deploy.
* Examples: Proton Torpedo, Concussion Missile, Space bomb, Seismic Torpedo
*/
short m_Type;
public:
short ammoRemaining; // Number of remaining ordinance before the launcher is empty
Ordinance *loadedOrdinance; // Exact type of Ordinance loaded
};
class CMLauncher
{
private:
CMLauncher( const CMLauncher & );
CMLauncher &operator = ( const CMLauncher & );
public:
CMLauncher( );
~CMLauncher( );
private:
std::string m_Name; // Name of the Launcher, ex: Cygnus Mark I Chaff Deployer
/*
* This is the type of counter measure a given CMLauncher would deploy.
* Examples: Chaff, micro-chaff, EM Emitters, Sensor Decoys, IFF Confusers
*/
short m_Type;
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* Component Hit points are the hitpoints a component has before it becomes damaged beyond repair
* and needs replaced. Depending on the component, destruction of the component could result in
* the destruction of the ship.
*/
int m_ComponentHitPoints;
/*
* Refire Rate is the rate at which the launcher cycles and is ready to fire again.
*/
int m_RefireRate;
/*
* This is the type of counter measure a given CMLauncher would deploy.
* Examples: Chaff, micro-chaff, EM Emitters, Sensor Decoys, IFF Confusers
*/
short m_Type;
public:
short remainingUses; // Number of remaining uses of the CMLauncher before it's empty
CounterMeasure *loadedCM; //Exact Counter Measure loaded
// get functions
const char *getName( ) const { return m_Name.c_str( ); }
short getType( ) const { return m_Type; }
int getMass( ) const { return m_Mass; }
int getComponentHP( ) const { return m_ComponentHitPoints; }
int getRefireRate( ) const { return m_RefireRate; }
// set Functions
void setName( const char *name )
{
if( !m_Name.empty( ) )
m_Name.clear( );
m_Name = name;
}
void setType( short type )
{
if( type >= MAX_CMTYPE || type < 0 )
{
bug( "%s: Invalid counter measure type passed: %d", __FUNCTION__, type );
return;
}
else
m_Type = type;
}
void setMass( int mass ) { m_Mass = mass; }
void setComponentHP( int hp ) { m_ComponentHitPoints = hp; }
void setRefireRate( int rate ) { m_RefireRate = rate; }
};
class Ordinance
{
private:
Ordinance( const Ordinance & );
Ordinance &operator = ( const Ordinance & );
public:
Ordinance( );
~Ordinance( );
private:
std::string m_Name; // Name of the Ordinance, ex: Mark I Proton Torpedo
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* This is the type of ordinance.
* Examples: Proton Torpedo, Concussion Missile, Space bomb, Seismic Torpedo
*/
short m_Type;
/*
* Lock on Time is the amount of time it takes for the ordinance to acquire a lock on before being
* fired.
*/
int m_LockOnTime;
/*
* Damage is the base damage the ordinance does to a ship. Damage is accompanied by a pair of modifiers
* vsArmor and vsShields. Some ordinance are good at damaging armor, but not shields, and these modifiers
* help reflect that.
*/
int m_VsShield;
int m_VsArmor;
int m_Damage;
public:
// get functions
const char *getName( ) const { return m_Name.c_str( ); }
int getMass( ) const { return m_Mass; }
short getType( ) const { return m_Type; }
// set Functions
void setName( const char *name )
{
if( !m_Name.empty( ) )
m_Name.clear( );
m_Name = name;
}
void setMass( int mass ) { m_Mass = mass; }
void setType( short type )
{
if( type >= MAX_ORDINANCE || type < 0 )
{
bug( "%s: Invalid ordinance passed: %d", __FUNCTION__, type );
return;
}
else
m_Type = type;
}
};
class CounterMeasure
{
private:
CounterMeasure( const CounterMeasure & );
CounterMeasure &operator = ( const CounterMeasure & );
public:
CounterMeasure( );
~CounterMeasure( );
private:
std::string m_Name; // Name of the Counter Measure, ex: Mark I Micro-Chaff
/*
* Component Mass is the amount of mass a component takes up on the chassis. A lower mass is better,
* but sometimes lower mass items will be worse than higher mass items.
*/
int m_Mass;
/*
* This is the type of counter measure.
* Examples: Chaff, Micro-Chaff, EM Emitters, Sensor Decoys, IFF Confusers
*/
short m_Type;
public:
// get functions
const char *getName( ) const { return m_Name.c_str( ); }
int getMass( ) const { return m_Mass; }
short getType( ) const { return m_Type; }
// set Functions
void setName( const char *name )
{
if( !m_Name.empty( ) )
m_Name.clear( );
m_Name = name;
}
void setMass( int mass ) { m_Mass = mass; }
void setType( short type )
{
if( type >= MAX_CMTYPE || type < 0 )
{
bug( "%s: Invalid counter measure type passed: %d", __FUNCTION__, type );
return;
}
else
m_Type = type;
}
};
class Ship
{
private:
Ship( const Ship & );
Ship &operator = ( const Ship & );
public:
Ship( );
~Ship( );
private:
// Registry
std::string m_Name;
std::string m_Filename;
std::string m_Owner;
std::string m_Pilot;
std::string m_CoPilot;
// Parts
Chassis *m_Chassis;
Reactor *m_Reactor;
Engine *m_Engine;
Booster *m_Booster;
Capacitor *m_Capacitor;
Armor *m_ForeArmor;
Armor *m_AftArmor;
ShieldGenerator *m_ShieldGenerator;
Launcher *m_Launcher;
CMLauncher *m_CMLauncher;
public:
FlagSet< MAX_SHIPFLAG > flags; // Flags for Ships.
Vector *position; // Current Position of the ship.
Vector *heading; // Current Heading of the ship.
bool shipSettings[MAX_STATUS]; // Status of ship, see shipStatuses for all possible.
// get Functions
const char *getName( ) const { return m_Name.c_str( ); }
const char *getFilename( ) const { return m_Filename.c_str( ); }
const char *getOwner( ) const { return m_Owner.c_str( ); }
const char *getPilot( ) const { return m_Pilot.c_str( ); }
const char *getCoPilot( ) const { return m_CoPilot.c_str( ); }
Chassis getChassis( ) const { return m_Chassis; }
Reactor getReactor( ) const { return m_Reactor; }
Engine getEngine( ) const { return m_Engine; }
Booster getBooster( ) const { return m_Booster; }
Capacitor getCapacitor( ) const { return m_Capacitor; }
Armor getForeArmor( ) const { return m_ForeArmor; }
Armor getAftArmor( ) const { return m_AftArmor; }
ShieldGenerator getShieldGenerator( ) const { return m_ShieldGenerator; }
Launcher getLauncher( ) const { return m_Launcher; }
CMLauncher getCMLauncher( ) const { return m_CMLauncher; }
// set Functions
void setName( const char *name )
{
if( !m_Name.empty( ) )
m_Name.clear( );
m_Name = name;
}
void setFilename( const char *name )
{
if( !m_Filename.empty( ) )
m_Filename.clear( );
m_Filename = name;
}
void setOwner( const char *name )
{
if( !m_Owner.empty( ) )
m_Owner.clear( );
m_Owner = name;
}
void setPilot( const char *name )
{
if( !m_Pilot.empty( ) )
m_Pilot.clear( );
m_Pilot = name;
}
void setCoPilot( const char *name )
{
if( !m_CoPilot.empty( ) )
m_CoPilot.clear( );
m_CoPilot = name;
}
// Misc
bool isRental( );
bool rent( Character *ch );
bool checkPilot( Character *ch );
// Placing/Removing from rooms while landed.
bool toRoom( Room *room );
bool extractFromRoom( );
// I/O
void save( );
void saveToFile( );
void readFromFile( FILE *fp );
// Damage
void destroy( Character *ch, const char *reason );
void damage( int min, int max );
// Movement
void toSpace( );
void launch( );
void land( const char *pad );
void drive( Character *ch, Exit *ex, int fall );
// Vector Stuff
bool isFacing( Ship *target );
bool isFacing( Planet *target );
void turn180( )
{
heading->x *= -1;
heading->y *= -1;
heading->z *= -1;
}
void setCourse( Ship *destination );
void setCourse( Planet *destination );
void setCourse( System *destination );
// This could be so fun to play with.
void setCourse( Star *destination ); // This could result in a lot of "Oops…" moments.
void alignHeading( Ship *target ) { heading->copy( target->heading ); }
};
void setName( const char *name )
if( !m_Name.empty( ) )
m_Name.clear( );
m_Name = name;
My first thought was too many members… possible Stovepipe class.
One possible refactoring is that some of the members might belong
in a ship's registry class, or possibly just Registry as it might apply to
other things beyond ships, like vehicles, cargos, parts, etc.
So….
Just a tiny refactoring.