载入中...
搜索中...
未找到
WarshipTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
14#include "common/ECS.h"
15
16#include <cstdint>
17#include <ostream>
18#include <string>
19#include <vector>
20
21namespace eve::warship {
22
24inline constexpr const char* kMobilitySurface = "surface";
25inline constexpr const char* kMobilitySail = "sail";
26inline constexpr const char* kMobilityCarrier = "carrier";
27inline constexpr const char* kMobilitySpace = "space";
28
30inline constexpr const char* kCategoryWarship = "warship";
31inline constexpr const char* kCategorySailship = "sailship";
32inline constexpr const char* kCategoryCarrier = "carrier";
33inline constexpr const char* kCategoryStarship = "starship";
34
38 std::string functionId;
39};
40
43 int cols = 1;
44 int rows = 1;
45 int decks = 1;
46
48 [[nodiscard]] int cellCount() const noexcept { return cols * rows * decks; }
49
54 [[nodiscard]] int indexOf(int deck, int row, int col) const noexcept {
55 if (deck < 0 || deck >= decks || row < 0 || row >= rows || col < 0 || col >= cols) return -1;
56 return (deck * rows + row) * cols + col;
57 }
58};
59
61struct LayoutSeed {
62 int deck = 0;
63 int row = 0;
64 int col = 0;
65 std::string functionId;
66};
67
75 std::string id;
76 std::string displayName;
78 float powerDraw = 0.f;
80 float powerProvide = 0.f;
82 float thrustBonus = 0.f;
88 int crewCapacity = 0;
90 float sailPower = 0.f;
91 std::vector<std::string> tags;
92};
93
96 std::string id;
102 float length = 120.f;
104 float beam = 28.f;
105 float maxSpeed = 40.f;
106 float accel = 12.f;
107 float turnRate = 25.f; // degrees / second
108 float maxHealth = 1000.f;
110 std::vector<LayoutSeed> defaultLayout;
111 std::vector<std::string> tags;
112};
113
116 float powerNet = 0.f;
117 float thrustMul = 1.f;
121 float sailPower = 0.f;
123 bool underpowered = false;
124};
125
127enum class WarshipEventType : uint8_t {
128 Arrived,
130 Damaged,
131 Destroyed,
133};
134
144
145inline std::ostream& operator<<(std::ostream& stream, WarshipEventType type) {
146 return stream << warshipEventTypeName(type);
147}
148
152 std::string warshipId;
153 std::string defId;
154 float x = 0.f;
155 float y = 0.f;
156 std::string detail;
157};
158
161public:
162 virtual ~IWarshipMobility() = default;
171 virtual const char* name() const = 0;
179 virtual void update(class WarshipEntity& ship, float dt) = 0;
180};
181
188class EVENGINE_API_DOMAINS WarshipEntity : public ecs::Entity {
189public:
190 ENTITY(WarshipEntity, ecs::Entity)
191
192 void release() override { ecs::DestroyEntity(this); }
193
195 struct Identity {
196 std::string id;
197 std::string defId;
198 std::string faction;
199 std::string category;
200 };
201
203 struct Definition {
204 const WarshipDefinition* def = nullptr;
205 };
206
208 struct Input {
209 float throttle = 0.f; // -1..1
210 float steer = 0.f; // -1..1
211 };
212
214 struct Motion {
215 float x = 0.f;
216 float y = 0.f;
217 float heading = 0.f;
218 float speed = 0.f;
219 bool arrived = false;
220 float targetX = 0.f;
221 float targetY = 0.f;
222 bool hasMove = false;
223 float arriveRadius = 24.f;
224 };
225
227 struct Health {
228 float hp = 0.f;
229 float maxHp = 0.f;
230 };
231
233 struct Hull {
234 float length = 0.f;
235 float beam = 0.f;
236 int decks = 1;
237 };
238
240 struct Layout {
242 std::vector<CompartmentCell> cells;
243 };
244
249 std::uint64_t revision = 0;
250 };
251
253 struct Flags {
254 bool destroyed = false;
255 };
256
257 COMPONENT(Identity, identity)
258 COMPONENT(Definition, definition)
259 COMPONENT(Input, input)
260 COMPONENT(Motion, motion)
261 COMPONENT(Health, health)
262 COMPONENT(Hull, hull)
263 COMPONENT(Layout, layout)
264 COMPONENT(Capabilities, capabilities)
265 COMPONENT(Flags, stateFlags)
266
267
274 [[nodiscard]] static WarshipEntity* createWarship();
275};
276
277} // namespace eve::warship
double y
double x
std::uint64_t revision
EnvironmentTest definition
EvpackChunkInput input
Definition Evpack.cpp:170
#define EVENGINE_API_DOMAINS
Definition Export.h:110
std::string layout
float length
double dt
float targetX
V3 heading
Definition TreeMesh.cpp:429
uint64_t identity
Pluggable hull mobility (surface / sail / carrier / space / custom).
virtual ~IWarshipMobility()=default
virtual void update(class WarshipEntity &ship, float dt)=0
Integrate motion for one simulation step.
virtual const char * name() const =0
Registry key matching WarshipDefinition::mobility.
Warship short-root entity: huge hull + rearrangeable compartments.
Warship module entry (eve.Warship): hull/function catalogues, spawn, compartment remodel,...
Definition Warship.cpp:17
constexpr const char * kMobilitySpace
constexpr const char * kMobilityCarrier
constexpr const char * kCategoryCarrier
constexpr const char * kMobilitySail
constexpr const char * kCategorySailship
constexpr const char * kCategoryStarship
std::ostream & operator<<(std::ostream &stream, WarshipEventType type)
constexpr const char * kCategoryWarship
Documented hull category conventions (free string; not an enum).
constexpr const char * kMobilitySurface
Built-in mobility model names used by hull definitions.
const char * warshipEventTypeName(WarshipEventType type)
Stable event type protocol name.
WarshipEventType
Frame-buffered warship events for script polling.
One cell of a hull's compartment grid.
std::string functionId
Registered compartment function id; empty means vacant.
Compartment function catalogue entry.
float powerDraw
Power drawn from the ship net (positive = consumer).
int weaponBayCount
Hardpoint / weapon-bay count contributed by this cell.
int hangarCapacity
Hangar craft capacity contributed by this cell.
std::vector< std::string > tags
float powerProvide
Power contributed to the ship net (reactors / generators).
int crewCapacity
Crew berths contributed by this cell.
float thrustBonus
Additive thrust multiplier contribution (0.1 = +10%).
float sailPower
Sail / wind capture contribution (sailships).
Rectangular compartment grid owned by a hull definition / entity.
int cellCount() const noexcept
Total cell count (cols * rows * decks).
int indexOf(int deck, int row, int col) const noexcept
Flat index for (deck, row, col).
One default layout entry applied when a hull is spawned.
Aggregated capabilities projected from the live compartment layout.
bool underpowered
True when powerNet < 0 (underpowered; thrust is reduced).
Hull template registered through Warship::registerHullsFromJson.
std::string category
Convention: warship / sailship / carrier / starship / custom.
float length
Hull length in world units (large relative to typical vehicles).
std::vector< std::string > tags
std::string mobility
IWarshipMobility registry name; default surface.
std::vector< LayoutSeed > defaultLayout
float beam
Hull beam (width) in world units.
Cached projection of Layout through the function catalogue.
Borrowed definition pointer (registry owns the template).
Physical envelope (copied from definition at spawn).
Stable instance id / template id / faction / category.
Live compartment occupancy; authoritative owner of layout cells.
std::vector< CompartmentCell > cells
2D kinematic motion (world XY, heading in degrees).
One warship event (frame cache).