载入中...
搜索中...
未找到
Vehicle.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
10#include "common/BorrowedRef.h"
11#include "common/ECS.h"
12#include "common/Module.h"
13#include "common/Result.h"
17
18#include <string>
19#include <vector>
20
21namespace eve::weapon {
22class WeaponMountEntity;
23}
24
25namespace eve::physics {
26class World;
27class World3D;
28} // namespace eve::physics
29
30namespace eve::vehicle {
31
34public:
37 Vehicle();
39 ~Vehicle() override;
40
42 int registerVehiclesFromJson(const std::string& json);
44 void clearVehicleDefinitions();
46 int getVehicleDefinitionCount();
48 bool hasVehicleDefinition(const std::string& id);
50 std::string getVehicleDefinitionMobility(const std::string& id);
52 float getVehicleDefinitionMaxHealth(const std::string& id);
53
59 [[nodiscard]] eve::definitions::DefinitionRegistry& definitionRegistry() noexcept { return definitionRegistry_; }
60
62 static void registerMobility(IVehicleMobility* mobility);
64 static int getMobilityCount();
65
75 VehicleEntity* newVehicle(const std::string& defId, float x, float y, float heading = 0.f,
76 const std::string& faction = "");
77
79 void moveTo(VehicleEntity* v, float x, float y);
81 void attackMove(VehicleEntity* v, float x, float y);
83 void attack(VehicleEntity* v, float x, float y, int targetId = 0);
85 void stop(VehicleEntity* v);
87 void hold(VehicleEntity* v);
89 void clearOrders(VehicleEntity* v);
91 int orderCount(VehicleEntity* v);
93 std::string getCurrentOrderType(VehicleEntity* v);
94
96 void setInput(VehicleEntity* v, float throttle, float steer, float brake = 0.f, bool handbrake = false);
97
99 float getX(VehicleEntity* v);
101 float getY(VehicleEntity* v);
103 float getHeading(VehicleEntity* v);
105 float getSpeed(VehicleEntity* v);
107 void setPosition(VehicleEntity* v, float x, float y);
109 void setHeading(VehicleEntity* v, float deg);
111 bool isArrived(VehicleEntity* v);
113 float getHealth(VehicleEntity* v);
115 void setHealth(VehicleEntity* v, float hp);
117 float getMaxHealth(VehicleEntity* v);
119 std::string getFaction(VehicleEntity* v);
121 void setFaction(VehicleEntity* v, const std::string& faction);
122
128 bool attachPhysics2D(VehicleEntity* v, eve::physics::World* world);
134 bool attachPhysics3D(VehicleEntity* v, eve::physics::World3D* world, float heightY = 1.f);
136 bool detachPhysics(VehicleEntity* v);
138 bool hasPhysics(VehicleEntity* v);
140 std::string getPhysicsSpace(VehicleEntity* v);
142 float getHeight(VehicleEntity* v);
143
145 void applyDamage(VehicleEntity* v, float amount, const std::string& zone = "", int sourceId = 0);
147 float getArmorZoneMult(VehicleEntity* v, const std::string& zone);
149 bool isDestroyed(VehicleEntity* v);
150
152 int getSeatCount(VehicleEntity* v);
154 std::string getSeatName(VehicleEntity* v, int seatIndex);
156 std::string getSeatCameraMode(VehicleEntity* v, int seatIndex);
158 bool isSeatOccupied(VehicleEntity* v, int seatIndex);
160 int getSeatOccupant(VehicleEntity* v, int seatIndex);
169 eve::weapon::WeaponMountEntity* getSeatMount(VehicleEntity* v, int seatIndex);
171 bool enterSeat(VehicleEntity* v, int seatIndex, int playerId);
173 bool exitSeat(VehicleEntity* v, int seatIndex);
175 int exitSeatByPlayer(VehicleEntity* v, int playerId);
176
178 void setPlayerControls(int playerId, float throttle, float steer, float brake, bool fire, float aimYaw,
179 float aimPitch);
180
189 int getMountCount(VehicleEntity* v);
192
194 void update(float dt);
195
197 void clearEvents();
199 int getEventCount() const;
201 std::string getEventType(int index) const;
203 std::string getEventVehicleId(int index) const;
205 std::string getEventDefId(int index) const;
207 std::string getEventOrderType(int index) const;
209 float getEventX(int index) const;
211 float getEventY(int index) const;
212
213private:
214 void autoAim(VehicleEntity& v);
215 void updateSeats(VehicleEntity& v);
226 [[nodiscard]] eve::Result<VehicleDefinition> findDef(const std::string& id) const;
227
228 eve::definitions::DefinitionRegistry definitionRegistry_;
229 std::vector<ecs::EntityHandle> vehicles_;
230 std::vector<VehicleEvent> events_;
231 int nextInstance_ = 1;
232};
233
234} // namespace eve::vehicle
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
Vocabulary aliases for nullable and checked borrowed references.
std::uint64_t sourceId
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float v
World3D * world
std::uint32_t targetId
Move-only, checked operation results for the common layer.
V3 heading
Definition TreeMesh.cpp:292
uint32_t index
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity,...
Definition World.h:41
移动模型:读输入、更新运动状态。
载具实体:数据全部在组件里,行为在 VehicleSystem。
载具模块(eve.Vehicle)。
Definition Vehicle.h:33
eve::definitions::DefinitionRegistry & definitionRegistry() noexcept
Return the canonical common registry for vehicle definitions.
Definition Vehicle.h:59
武器挂点实体:可持有武器并限制旋转(炮塔 / 机枪座 / 固定挂架)。
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
驾驶者接口与玩家控制状态。
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md