1 #ifndef SHIP_TEMPLATE_H 2 #define SHIP_TEMPLATE_H 3 4 #include <unordered_map> 5 #include <unordered_set> 6 #include <optional> 7 #include "engine.h" 8 #include "modelData.h" 9 10 #include "beamTemplate.h" 11 #include "missileWeaponData.h" 12 constexpr static int max_beam_weapons = 16; 13 constexpr static int max_weapon_tubes = 16; 14 constexpr static int max_shield_count = 8; 15 16 enum ESystem 17 { 18 SYS_None = -1, 19 SYS_Reactor = 0, 20 SYS_BeamWeapons, 21 SYS_MissileSystem, 22 SYS_Maneuver, 23 SYS_Impulse, 24 SYS_Warp, 25 SYS_JumpDrive, 26 SYS_FrontShield, 27 SYS_RearShield, 28 SYS_COUNT 29 }; 30 31 /* Define script conversion function for the ESystem enum. */ 32 template<> void convert<ESystem>::param(lua_State* L, int& idx, ESystem& es); 33 34 class ShipRoomTemplate 35 { 36 public: 37 sf::Vector2i position; 38 sf::Vector2i size; 39 ESystem system; 40 ShipRoomTemplate(sf::Vector2i position,sf::Vector2i size,ESystem system)41 ShipRoomTemplate(sf::Vector2i position, sf::Vector2i size, ESystem system) : position(position), size(size), system(system) {} 42 }; 43 class ShipDoorTemplate 44 { 45 public: 46 sf::Vector2i position; 47 bool horizontal; 48 ShipDoorTemplate(sf::Vector2i position,bool horizontal)49 ShipDoorTemplate(sf::Vector2i position, bool horizontal) : position(position), horizontal(horizontal) {} 50 }; 51 52 class SpaceObject; 53 class ShipTemplate : public PObject 54 { 55 public: 56 enum TemplateType 57 { 58 Ship, 59 PlayerShip, 60 Station 61 }; 62 class TubeTemplate 63 { 64 public: 65 float load_time; 66 uint32_t type_allowed_mask; 67 float direction; 68 EMissileSizes size; 69 }; 70 private: 71 static std::unordered_map<string, P<ShipTemplate> > templateMap; 72 string name; 73 string locale_name = ""; 74 string description; 75 string class_name; 76 string sub_class_name; 77 TemplateType type; 78 public: 79 string getName(); 80 string getLocaleName(); 81 string getDescription(); 82 string getClass(); 83 string getSubClass(); 84 void setType(TemplateType type); 85 TemplateType getType(); 86 87 P<ModelData> model_data; 88 89 /*! 90 * List of ship classes that can dock with this ship. (only used for ship2ship docking) 91 */ 92 std::unordered_set<string> can_be_docked_by_class; 93 bool shares_energy_with_docked; 94 bool repair_docked; 95 bool restocks_scan_probes; 96 bool restocks_missiles_docked; 97 bool can_scan = true; 98 bool can_hack = true; 99 bool can_dock = true; 100 bool can_combat_maneuver = true; 101 bool can_self_destruct = true; 102 bool can_launch_probe = true; 103 104 float energy_storage_amount; 105 int repair_crew_count; 106 string default_ai_name; 107 BeamTemplate beams[max_beam_weapons]; 108 int weapon_tube_count; 109 TubeTemplate weapon_tube[max_weapon_tubes]; 110 float hull; 111 int shield_count; 112 float shield_level[max_shield_count]; 113 float impulse_speed, impulse_reverse_speed, turn_speed, warp_speed; 114 float impulse_acceleration, impulse_reverse_acceleration; 115 float combat_maneuver_boost_speed; 116 float combat_maneuver_strafe_speed; 117 bool has_jump_drive, has_cloaking; 118 float jump_drive_min_distance; 119 float jump_drive_max_distance; 120 int weapon_storage[MW_Count]; 121 122 string radar_trace; 123 float long_range_radar_range; 124 float short_range_radar_range; 125 string impulse_sound_file; 126 127 std::vector<ShipRoomTemplate> rooms; 128 std::vector<ShipDoorTemplate> doors; 129 130 ShipTemplate(); 131 132 void setName(string name); 133 void setLocaleName(string name); 134 void setClass(string class_name, string sub_class_name); 135 void setDescription(string description); 136 void setModel(string model_name); 137 void setDefaultAI(string default_ai_name); 138 void setDockClasses(std::vector<string> classes); 139 void setSharesEnergyWithDocked(bool enabled); 140 void setRepairDocked(bool enabled); 141 void setRestocksScanProbes(bool enabled); 142 void setRestocksMissilesDocked(bool enabled); setCanScan(bool enabled)143 void setCanScan(bool enabled) { can_scan = enabled; } setCanHack(bool enabled)144 void setCanHack(bool enabled) { can_hack = enabled; } setCanDock(bool enabled)145 void setCanDock(bool enabled) { can_dock = enabled; } setCanCombatManeuver(bool enabled)146 void setCanCombatManeuver(bool enabled) { can_combat_maneuver = enabled; } setCanSelfDestruct(bool enabled)147 void setCanSelfDestruct(bool enabled) { can_self_destruct = enabled; } setCanLaunchProbe(bool enabled)148 void setCanLaunchProbe(bool enabled) { can_launch_probe = enabled; } 149 void setMesh(string model, string color_texture, string specular_texture, string illumination_texture); 150 void setEnergyStorage(float energy_amount); 151 void setRepairCrewCount(int amount); 152 153 void setBeam(int index, float arc, float direction, float range, float cycle_time, float damage); 154 void setBeamWeapon(int index, float arc, float direction, float range, float cycle_time, float damage); 155 void setBeamWeaponTurret(int index, float arc, float direction, float rotation_rate); 156 157 /** 158 * Convenience function to set the texture of a beam by index. 159 */ 160 void setBeamTexture(int index, string texture); setBeamWeaponEnergyPerFire(int index,float energy)161 void setBeamWeaponEnergyPerFire(int index, float energy) { if (index < 0 || index >= max_beam_weapons) return; return beams[index].setEnergyPerFire(energy); } setBeamWeaponHeatPerFire(int index,float heat)162 void setBeamWeaponHeatPerFire(int index, float heat) { if (index < 0 || index >= max_beam_weapons) return; return beams[index].setHeatPerFire(heat); } 163 164 void setTubes(int amount, float load_time); 165 void setTubeLoadTime(int index, float load_time); 166 void weaponTubeAllowMissle(int index, EMissileWeapons type); 167 void weaponTubeDisallowMissle(int index, EMissileWeapons type); 168 void setWeaponTubeExclusiveFor(int index, EMissileWeapons type); 169 void setTubeSize(int index, EMissileSizes size); 170 171 void setTubeDirection(int index, float direction); setHull(float amount)172 void setHull(float amount) { hull = amount; } 173 void setShields(std::vector<float> values); 174 void setSpeed(float impulse, float turn, float acceleration, std::optional<float> reverse_speed, std::optional<float> reverse_acceleration); 175 void setCombatManeuver(float boost, float strafe); 176 void setWarpSpeed(float warp); 177 void setJumpDrive(bool enabled); setJumpDriveRange(float min,float max)178 void setJumpDriveRange(float min, float max) { jump_drive_min_distance = min; jump_drive_max_distance = max; } 179 void setCloaking(bool enabled); 180 void setWeaponStorage(EMissileWeapons weapon, int amount); 181 void addRoom(sf::Vector2i position, sf::Vector2i size); 182 void addRoomSystem(sf::Vector2i position, sf::Vector2i size, ESystem system); 183 void addDoor(sf::Vector2i position, bool horizontal); 184 void setRadarTrace(string trace); 185 void setLongRangeRadarRange(float range); 186 void setShortRangeRadarRange(float range); 187 void setImpulseSoundFile(string sound); 188 189 P<ShipTemplate> copy(string new_name); 190 191 sf::Vector2i interiorSize(); 192 ESystem getSystemAtRoom(sf::Vector2i position); 193 194 void setCollisionData(P<SpaceObject> object); 195 public: 196 static P<ShipTemplate> getTemplate(string name); 197 static std::vector<string> getAllTemplateNames(); 198 static std::vector<string> getTemplateNameList(TemplateType type); 199 }; 200 string getSystemName(ESystem system); 201 string getLocaleSystemName(ESystem system); 202 REGISTER_MULTIPLAYER_ENUM(ESystem); 203 204 /* Define script conversion function for the ShipTemplate::TemplateType enum. */ 205 template<> void convert<ShipTemplate::TemplateType>::param(lua_State* L, int& idx, ShipTemplate::TemplateType& tt); 206 #endif//SHIP_TEMPLATE_H 207