载入中...
搜索中...
未找到
WeaponSystem.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4#include "common/CrashLog.h"
8
9#include <algorithm>
10#include <cmath>
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <unordered_map>
15#include <utility>
16#include <vector>
17
18namespace eve::weapon {
19
20namespace {
21
22std::unordered_map<std::string, IWeaponLogic*>& logicRegistry() {
23 static std::unordered_map<std::string, IWeaponLogic*> registry;
24 return registry;
25}
26
27WeaponEventSink& eventSink() {
28 static WeaponEventSink sink;
29 return sink;
30}
31
32void pushEvent(const WeaponEvent& e) {
33 if (eventSink()) eventSink()(e);
34}
35
37float angleDelta(float from, float to) {
38 float d = std::fmod(to - from + 180.f, 360.f);
39 if (d < 0.f) d += 360.f;
40 return d - 180.f;
41}
42
44class HitscanLogic : public IWeaponLogic {
45public:
46 const char* name() const override { return "hitscan"; }
47 bool canFire(const WeaponEntity&) const override { return true; }
48 void fire(WeaponEntity&, const AttackRequest&) override {}
49 void update(WeaponEntity&, float) override {}
50};
51
53class ProjectileLogic : public IWeaponLogic {
54public:
55 const char* name() const override { return "projectile"; }
56 bool canFire(const WeaponEntity&) const override { return true; }
57 void fire(WeaponEntity& w, const AttackRequest& req) override {
58 if (IProjectileService* svc = eve::cap::query<IProjectileService>()) svc->spawnProjectile(w, req);
59 }
60 void update(WeaponEntity&, float) override {}
61};
62
63const WeaponDefinition* defOf(WeaponEntity& w);
64void pushFireEvent(WeaponEntity& w, const WeaponDefinition* def, const AttackRequest& req, int ammo);
65
67class MeleeLogic : public IWeaponLogic {
68public:
69 const char* name() const override { return "melee"; }
70 bool canFire(const WeaponEntity&) const override { return true; }
71 void fire(WeaponEntity&, const AttackRequest&) override {}
72 void update(WeaponEntity&, float) override {}
73};
74
75HitscanLogic gHitscan;
76ProjectileLogic gProjectile;
77MeleeLogic gMelee;
78
79const WeaponDefinition* defOf(WeaponEntity& w) { return w.definition()->def; }
80
82bool usesStageMachine(const WeaponDefinition* def) {
83 return def != nullptr && def->kind != WeaponKind::Ranged;
84}
85
86void pushFireEvent(WeaponEntity& w, const WeaponDefinition* def, const AttackRequest& req, int ammo) {
87 WeaponEvent e;
88 e.type = WeaponEventType::Fire;
89 e.weaponId = w.identity()->id;
90 e.defId = def->id;
91 e.ammoLeft = ammo;
92 e.x = req.muzzleX;
93 e.y = req.muzzleY;
94 e.z = req.muzzleZ;
95 e.arc = req.arcAngle;
96 e.aoe = req.aoeRadius;
97 e.spread = req.spread;
98 e.pellets = std::max(1, req.pelletCount);
99 e.recoilPitch = def->recoilPitch;
100 e.recoilYaw = def->recoilYaw;
101 e.damageType = def->damageType;
102 e.element = def->element;
103 pushEvent(e);
104}
105
107void updateFeel(WeaponEntity& w, const WeaponDefinition* def, float dt) {
108 auto state = w.state();
109 // 散布回稳:从当前连射散布衰减回 spreadMin。
110 if (def->spreadRecover > 0.f && state->currentSpread > def->spreadMin) {
111 state->currentSpread = std::max(def->spreadMin, state->currentSpread - def->spreadRecover * dt);
112 }
113 // 后坐回正:向 0 收敛。
114 if (def->recoilRecover > 0.f) {
115 const float p = std::min(std::fabs(state->recoilPitch), def->recoilRecover * dt);
116 state->recoilPitch += state->recoilPitch > 0.f ? -p : p;
117 const float y = std::min(std::fabs(state->recoilYaw), def->recoilRecover * dt);
118 state->recoilYaw += state->recoilYaw > 0.f ? -y : y;
119 }
120}
121
123float applyBloom(WeaponEntity& w, const WeaponDefinition* def) {
124 auto state = w.state();
125 if (def->spreadPerShot > 0.f && def->spreadMax > def->spreadMin) {
126 state->currentSpread = std::min(def->spreadMax, state->currentSpread + def->spreadPerShot);
127 }
128 return state->currentSpread;
129}
130
132int spawnPellets(WeaponEntity& w, const WeaponDefinition* def, AttackRequest& r) {
133 const int n = std::max(1, def->projectile.pelletCount);
134 r.pelletCount = n;
135 if (IWeaponLogic* logic = WeaponSystem::findLogic(def->logic)) {
136 for (int i = 0; i < n; ++i) {
137 r.pelletIndex = i;
138 logic->fire(w, r);
139 }
140 }
141 return n;
142}
143
144void pushEmptyEvent(WeaponEntity& w, const WeaponDefinition* def) {
145 WeaponEvent e;
146 e.type = WeaponEventType::Empty;
147 e.weaponId = w.identity()->id;
148 e.defId = def->id;
149 e.ammoLeft = 0;
150 pushEvent(e);
151}
152
153void pushReloadEnd(WeaponEntity& w, const WeaponDefinition* def, int ammo) {
154 WeaponEvent e;
156 e.weaponId = w.identity()->id;
157 e.defId = def->id;
158 e.ammoLeft = ammo;
159 pushEvent(e);
160}
161
162// ---------------------------------------------------------------------------
163// 热武器(ranged):成熟管线
164// ---------------------------------------------------------------------------
165
166bool canFireRanged(WeaponEntity& w, const WeaponDefinition* def) {
167 const auto state = w.state();
168 if (state->resource.reloading || state->jammed) return false;
169 if (state->cooldown > 0.f) return false;
170 if (state->resource.value <= 0.f) return false;
171 const IWeaponLogic* logic = WeaponSystem::findLogic(def->logic);
172 return logic == nullptr || logic->canFire(w);
173}
174
175bool tryFireRanged(WeaponEntity& w, const AttackRequest& req, const WeaponDefinition* def) {
176 if (!canFireRanged(w, def)) return false;
177
178 auto state = w.state();
179 state->resource.value -= 1.f;
180
181 const float effSpread = applyBloom(w, def);
182 state->recoilPitch += def->recoilPitch;
183 state->recoilYaw += def->recoilYaw;
184
185 AttackRequest r = req;
186 r.yaw = w.aim()->yaw;
187 r.pitch = w.aim()->pitch;
188 r.spread = effSpread;
189 const int pellets = spawnPellets(w, def, r);
190
191 state->cooldown = def->cooldown;
192 if (state->selector == FireMode::Burst && def->burstSize > 1) {
193 state->burstRemaining = def->burstSize - 1;
194 state->burstTimer = def->burstInterval;
195 }
196
197 r.pelletCount = pellets;
198 pushFireEvent(w, def, r, static_cast<int>(state->resource.value));
199 if (state->resource.value <= 0.f) pushEmptyEvent(w, def);
200 return true;
201}
202
203void updateRanged(WeaponEntity& w, const WeaponDefinition* def, float dt) {
204 auto state = w.state();
205 Resource& r = state->resource;
206 state->cooldown = std::max(0.f, state->cooldown - dt);
207 updateFeel(w, def, dt);
208
209 // 自动装填:弹匣打空、冷却结束且有备弹时自动开始(事件照发,游戏侧可覆盖/取消)。
210 if (!r.reloading && r.value <= 0.f && state->cooldown <= 0.f && !state->jammed) {
212 }
213
214 // 装填推进
215 if (r.reloading) {
216 r.reloadProgress += dt;
217 if (r.reloadProgress >= def->reloadTime) {
218 const int missing = static_cast<int>(r.max) - static_cast<int>(r.value);
219 if (def->reserveSize < 0) {
220 r.value = r.max;
221 } else if (AmmoPoolEntity* pool = state->ammoPool) {
222 const int take = std::min(missing, pool->state()->count);
223 r.value += static_cast<float>(take);
224 pool->state()->count -= take;
225 } else {
226 const int take = std::min(missing, r.reserve);
227 r.value += static_cast<float>(take);
228 r.reserve -= take;
229 }
230 r.reloading = false;
231 r.reloadProgress = 0.f;
232 pushReloadEnd(w, def, static_cast<int>(r.value));
233 }
234 }
235
236 // 连发续射(第一次扣弹在 tryFire,续发在这里)
237 if (!r.reloading && state->burstRemaining > 0) {
238 state->burstTimer -= dt;
239 if (state->burstTimer <= 0.f) {
240 if (r.value > 0.f) {
241 r.value -= 1.f;
242 AttackRequest req;
243 req.yaw = w.aim()->yaw;
244 req.pitch = w.aim()->pitch;
245 req.spread = applyBloom(w, def);
246 state->recoilPitch += def->recoilPitch;
247 state->recoilYaw += def->recoilYaw;
248 const int pellets = spawnPellets(w, def, req);
249 state->cooldown = def->cooldown;
250 state->burstRemaining--;
251 state->burstTimer = def->burstInterval;
252
253 req.pelletCount = pellets;
254 pushFireEvent(w, def, req, static_cast<int>(r.value));
255
256 if (r.value <= 0.f) {
257 state->burstRemaining = 0;
258 pushEmptyEvent(w, def);
259 }
260 } else {
261 state->burstRemaining = 0;
262 }
263 }
264 }
265
266 if (IWeaponLogic* logic = WeaponSystem::findLogic(def->logic)) logic->update(w, dt);
268}
269
270// ---------------------------------------------------------------------------
271// 阶段机(近战 / 法杖 / 导弹等非热武器形态)
272// ---------------------------------------------------------------------------
273
274bool canAttackStage(WeaponEntity& w, const WeaponDefinition* def) {
275 const auto state = w.state();
276 if (state->stage != AttackStage::Idle) return false;
277 if (state->jammed) return false;
278 if (state->cooldown > 0.f) return false;
279 const Resource& r = state->resource;
280 if (r.kind == ResourceKind::Mana || r.kind == ResourceKind::Stamina) {
284 if (!current) {
285 current.ignore("legacy bool canFire cannot expose weapon attribute diagnostics");
286 return false;
287 }
288 if (!r.infinite && current.value() < static_cast<double>(r.cost)) return false;
289 } else if (!r.infinite && r.value < r.cost) {
290 return false;
291 }
292 const IWeaponLogic* logic = WeaponSystem::findLogic(def->logic);
293 return logic == nullptr || logic->canFire(w);
294}
295
296bool tryAttackStage(WeaponEntity& w, const AttackRequest& req, const WeaponDefinition* def) {
297 if (!canAttackStage(w, def)) return false;
298
299 auto state = w.state();
300 Resource& r = state->resource;
301 if (r.kind == ResourceKind::Mana || r.kind == ResourceKind::Stamina) {
303 if (!consumed) {
304 consumed.ignore("legacy bool tryFire cannot expose weapon attribute diagnostics");
305 return false;
306 }
307 } else if (!r.infinite) {
308 r.value = std::max(0.f, r.value - r.cost);
309 }
310
311 state->stage = AttackStage::Windup;
312 state->stageTimer = 0.f;
313 state->lastRequest = req;
314 if (IWeaponLogic* logic = WeaponSystem::findLogic(def->logic)) logic->begin(w, req);
315
316 WeaponEvent e;
318 e.weaponId = w.identity()->id;
319 e.defId = def->id;
320 e.ammoLeft = static_cast<int>(r.value);
321 pushEvent(e);
322 return true;
323}
324
325void updateStage(WeaponEntity& w, const WeaponDefinition* def, float dt) {
326 auto state = w.state();
327 state->cooldown = std::max(0.f, state->cooldown - dt);
328 updateFeel(w, def, dt);
329
330 // 资源回复(法力 / 充能)
331 Resource& r = state->resource;
332 if (r.regen > 0.f && r.value < r.max) r.value = std::min(r.max, r.value + r.regen * dt);
333
334 const AttackStageSpec* stages = state->stages != nullptr ? state->stages : &def->stages;
335 state->stageTimer += dt;
336
337 if (state->stage == AttackStage::Windup && state->stageTimer >= stages->windupTime) {
338 // Windup → Active:命中/生效时刻
339 state->stage = AttackStage::Active;
340 state->stageTimer = 0.f;
341 AttackRequest req = state->lastRequest;
342 req.yaw = w.aim()->yaw;
343 req.pitch = w.aim()->pitch;
344 req.spread = applyBloom(w, def);
345 const int pellets = spawnPellets(w, def, req);
346 req.pelletCount = pellets;
347 pushFireEvent(w, def, req, static_cast<int>(r.value));
348 if (!r.infinite && r.value <= 0.f) pushEmptyEvent(w, def);
349 } else if (state->stage == AttackStage::Active) {
350 if (IWeaponLogic* logic = WeaponSystem::findLogic(def->logic)) logic->channel(w, state->lastRequest, dt);
351 if (state->stageTimer >= stages->activeTime) {
353 state->stageTimer = 0.f;
354 if (IWeaponLogic* logic = WeaponSystem::findLogic(def->logic)) logic->end(w, state->lastRequest);
355 WeaponEvent e;
357 e.weaponId = w.identity()->id;
358 e.defId = def->id;
359 e.ammoLeft = static_cast<int>(r.value);
360 pushEvent(e);
361 }
362 } else if (state->stage == AttackStage::Recover && state->stageTimer >= stages->recoverTime) {
363 state->stage = AttackStage::Idle;
364 state->stageTimer = 0.f;
365 }
366
367 if (IWeaponLogic* logic = WeaponSystem::findLogic(def->logic)) logic->update(w, dt);
369}
370
371} // namespace
372
374 if (logic == nullptr) return;
375 logicRegistry()[logic->name()] = logic;
376}
377
379 auto it = logicRegistry().find(name);
380 return it == logicRegistry().end() ? nullptr : it->second;
381}
382
383int WeaponSystem::logicCount() { return static_cast<int>(logicRegistry().size()); }
384
385void WeaponSystem::setEventSink(WeaponEventSink sink) { eventSink() = std::move(sink); }
386
387void WeaponSystem::emitEvent(const WeaponEvent& e) { pushEvent(e); }
388
390 const WeaponDefinition* def = defOf(w);
391 if (def == nullptr) return;
392 if (usesStageMachine(def)) {
393 updateStage(w, def, dt);
394 } else {
395 updateRanged(w, def, dt);
396 }
397}
398
400 const WeaponDefinition* def = defOf(w);
401 if (def == nullptr) return false;
402 if (usesStageMachine(def)) return tryAttackStage(w, req, def);
403 return tryFireRanged(w, req, def);
404}
405
407 const WeaponDefinition* def = defOf(w);
408 if (def == nullptr) return false;
409 if (usesStageMachine(def)) return canAttackStage(w, def);
410 return canFireRanged(w, def);
411}
412
414 const WeaponDefinition* def = defOf(w);
415 if (def == nullptr) return;
416 auto state = w.state();
417 Resource& r = state->resource;
418 if (r.reloading || r.value >= r.max) return;
419 if (AmmoPoolEntity* pool = state->ammoPool) {
420 if (pool->state()->count <= 0) return;
421 } else if (!r.infinite && (def->reserveSize == 0 || r.reserve <= 0)) {
422 return;
423 }
424
425 r.reloading = true;
426 r.reloadProgress = 0.f;
427 state->burstRemaining = 0;
428
429 WeaponEvent e;
431 e.weaponId = w.identity()->id;
432 e.defId = def->id;
433 e.ammoLeft = static_cast<int>(r.value);
434 pushEvent(e);
435}
436
438 w.state()->resource.reloading = false;
439 w.state()->resource.reloadProgress = 0.f;
440}
441
443 auto aim = w.aim();
444 if (aim->turnSpeed <= 0.f) {
445 aim->yaw = aim->desiredYaw;
446 aim->pitch = aim->desiredPitch;
447 return true;
448 }
449 const float step = aim->turnSpeed * dt;
450 const float dyaw = angleDelta(aim->yaw, aim->desiredYaw);
451 const float dpitch = aim->desiredPitch - aim->pitch;
452 aim->yaw += (std::fabs(dyaw) <= step) ? dyaw : (dyaw > 0.f ? step : -step);
453 aim->pitch += (std::fabs(dpitch) <= step) ? dpitch : (dpitch > 0.f ? step : -step);
454 return std::fabs(angleDelta(aim->yaw, aim->desiredYaw)) < 0.01f &&
455 std::fabs(aim->pitch - aim->desiredPitch) < 0.01f;
456}
457
458} // namespace eve::weapon
459
460// 静态注册内置逻辑(链接期执行,模块加载即生效)。
461namespace eve::weapon {
462namespace {
463
464struct BuiltinLogicRegistrar {
465 BuiltinLogicRegistrar() {
467 WeaponSystem::registerLogic(&gProjectile);
469 }
470};
471
472BuiltinLogicRegistrar gBuiltinRegistrar;
473
474} // namespace
475} // namespace eve::weapon
476
477// ---------------------------------------------------------------------------
478// IProjectileService 的脚本接缝(阶段 4 的第二个插座:形状与标量 sink 不同)
479// ---------------------------------------------------------------------------
480namespace eve::weapon {
481namespace {
482
499class ScriptProjectileService final : public IProjectileService {
500public:
501 explicit ScriptProjectileService(ScriptProviderHandle handle) : handle_(std::move(handle)) {}
502
504 [[nodiscard]] const ScriptProviderHandle& handle() const noexcept { return handle_; }
505
506 void spawnProjectile(const WeaponEntity& w, const AttackRequest& req) override {
507 // 接口借出的是 const 引用(提供方不该改武器),而 ECS 的组件访问器按宏设计就是
508 // 非 const(`external/ECS.hpp` 的 `COMPONENT(T,name)`)。这里只转一次、只读:
509 // 下面不写 `w` 的任何字段,并在脚本运行前把需要的值全部拷进 ScriptArg。
510 WeaponEntity& mutableWeapon = const_cast<WeaponEntity&>(w);
511 const auto identity = mutableWeapon.identity();
512
513 const ScriptArg args[] = {
515 ScriptArg::fromInteger(identity->ownerId), ScriptArg::fromNumber(double(req.yaw)),
516 ScriptArg::fromNumber(double(req.pitch)), ScriptArg::fromInteger(req.shooterId),
517 ScriptArg::fromBoolean(req.hasTarget), ScriptArg::fromNumber(double(req.targetX)),
518 ScriptArg::fromNumber(double(req.targetY)), ScriptArg::fromNumber(double(req.targetZ)),
519 ScriptArg::fromNumber(double(req.muzzleX)), ScriptArg::fromNumber(double(req.muzzleY)),
520 ScriptArg::fromNumber(double(req.muzzleZ)), ScriptArg::fromNumber(double(req.spread)),
521 ScriptArg::fromInteger(req.pelletIndex), ScriptArg::fromInteger(req.pelletCount),
522 };
523
524 auto spawned = ScriptProviderRegistry::instance().call(handle_, "spawnProjectile", args);
525 if (!spawned) {
526 // Fail visibly, once per generation: a provider that raises or declares the wrong
527 // arity means "no projectile appeared", and silence would look like a weapon that
528 // simply does not fire.
529 if (reportedGeneration_ != handle_.generation) {
530 reportedGeneration_ = handle_.generation;
531 recordLogEvent("error", "projectile provider '" + handle_.name +
532 "' failed and no projectile was spawned: " + spawned.status().describe());
533 }
534 }
535 }
536
537private:
538 ScriptProviderHandle handle_;
540 std::uint64_t reportedGeneration_ = 0;
541};
542
552struct ScriptProjectileProviders {
553 std::vector<std::unique_ptr<ScriptProjectileService>> live;
554 std::vector<std::unique_ptr<ScriptProjectileService>> retired;
555};
556
557ScriptProjectileProviders& scriptProjectileProviders() {
558 static ScriptProjectileProviders state;
559 return state;
560}
561
562} // namespace
563
565 ScriptProjectileProviders& owned = scriptProjectileProviders();
569 // 单实现槽位:`provide` 会顶掉当前实现。顶掉必须可见,否则原生提供方会
570 // "悄悄失效",而症状只是投射物不再生成。
571 if (eve::cap::query<IProjectileService>() != nullptr) {
572 recordLogEvent("warn", "script projectile provider '" + handle.name +
573 "' replaced the provider that owned IProjectileService");
574 }
575 auto adapter = std::make_unique<ScriptProjectileService>(handle);
576 ScriptProjectileService* raw = adapter.get();
577 // 先注册再交所有权:从这里起能力槽位持有裸指针,`owned.live` 是让它有效的唯一原因。
578 eve::cap::provide<IProjectileService>(raw);
579 owned.live.push_back(std::move(adapter));
581 },
583 const auto match = std::find_if(owned.live.begin(), owned.live.end(),
584 [&handle](const std::unique_ptr<ScriptProjectileService>& adapter) {
585 return adapter->handle() == handle;
586 });
587 if (match == owned.live.end()) {
588 // 幂等:后置条件是"这一代没有适配器",而模块退出时可能已经撤过了。
589 // 这里返回失败会让"再发布一次同名提供方"因为一个已经正确的状态而失败。
591 }
592 eve::cap::revoke<IProjectileService>(match->get());
593 owned.retired.push_back(std::move(*match));
594 owned.live.erase(match);
596 });
597}
598
600 ScriptProjectileProviders& owned = scriptProjectileProviders();
601 for (auto& adapter : owned.live) {
602 eve::cap::revoke<IProjectileService>(adapter.get());
603 owned.retired.push_back(std::move(adapter));
604 }
605 owned.live.clear();
606
607 // 连声明一起撤回:没有消费方了,留着接缝只会宣传一个"绑上去也永远不会被调用"的插座。
610 .ignore("module teardown may already have dropped this seam");
611}
612
613} // namespace eve::weapon
double y
float w
Definition AnimClip.cpp:738
ActiveSource owned
std::vector< std::unique_ptr< ScriptClimbingEventSink > > live
std::vector< std::unique_ptr< ScriptClimbingEventSink > > retired
Persistent, thread-safe record of engine crash and problem events.
glm::vec4 p[6]
std::string name
Definition ECS.cpp:154
double raw
std::uint32_t spawned
glm::vec3 n
Definition Grass.cpp:63
double r
std::string to
std::string from
double dt
PrimitiveHandle handle
const eve::script::BindingContractRegistry & registry
float d
std::string attribute
double current
std::string_view adapter
float step
Definition TreeMesh.cpp:451
uint64_t identity
Selective canonical mana/stamina adapter for weapons.
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
Result< void > removeCapability(std::string_view capability)
Withdraw a declared seam when its owning module goes away.
static ScriptProviderRegistry & instance()
Process-lifetime registry; clearAll is the only reset.
void declareCapability(std::string capability, ScriptCapabilityBinder binder, ScriptCapabilityUnbinder unbinder)
Declare that one native capability may be served by a script provider.
Result< void > call(const ScriptProviderHandle &handle, std::string_view method) const
Call method() on a published provider.
共享弹药池实体:多把武器共用的备用弹药,装填时从池中取。
static constexpr const char * capabilityName
Definition WeaponLogic.h:62
武器逻辑接口:注册到 WeaponSystem 的可插拔行为。
Definition WeaponLogic.h:22
virtual void end(WeaponEntity &w, const AttackRequest &req)
阶段机进入 Recover 时调用(默认空实现)。
Definition WeaponLogic.h:53
virtual const char * name() const =0
稳定名字("hitscan" / "projectile" / "melee" / 自定义名)。
static eve::Result< double > read(WeaponEntity &weapon, std::string_view attribute)
Read a selected final mana/stamina attribute.
static constexpr std::string_view manaAttribute
static constexpr std::string_view staminaAttribute
static eve::Result< void > consumeTriggerResource(WeaponEntity &weapon)
Consume the current weapon's canonical Mana/Stamina trigger cost.
武器实体:数据全部在组件里,行为在 WeaponSystem。
static void update(WeaponEntity &w, float dt)
每帧推进:冷却 / 连发 / 装填 / 炮口旋转 / 逻辑自身。
static IWeaponLogic * findLogic(const std::string &name)
按名字取逻辑;未注册返回 nullptr。
static bool canFire(WeaponEntity &w)
是否可开火(未装填/未卡壳/冷却完毕/有弹药/逻辑放行)。
static void registerLogic(IWeaponLogic *logic)
注册武器逻辑实现;同名替换。
static void setEventSink(WeaponEventSink sink)
注册事件汇(替换旧的;传 nullptr 清空)。
static void cancelReload(WeaponEntity &w)
打断装填。
static bool tryFire(WeaponEntity &w, const FireRequest &req)
尝试开火;满足条件时扣弹药、调逻辑、推事件并返回 true。
static void startReload(WeaponEntity &w)
开始装填(有备用弹药且弹匣不满时生效)。
static void emitEvent(const WeaponEvent &e)
向事件汇推一条事件(模块/脚本便捷入口)。
static bool updateAim(WeaponEntity &w, float dt)
炮口朝目标旋转;返回本帧是否到位。
static int logicCount()
已注册逻辑数量。
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
std::function< void(const WeaponEvent &)> WeaponEventSink
事件汇:由 Weapon 模块(或测试)注册,把事件写入自己的队列。
void declareScriptProjectileSeam()
声明 IProjectileService 的脚本绑定接缝。
void withdrawScriptProjectileSeam()
撤回本模块声明的脚本接缝,并卸载全部脚本提供方。
void recordLogEvent(const std::string &level, const std::string &message)
Appends a timestamped event line to the crash/error log.
Definition CrashLog.cpp:70
static ScriptArg fromInteger(std::int64_t value)
static ScriptArg fromText(std::string value)
static ScriptArg fromBoolean(bool value)
static ScriptArg fromNumber(double value)
Generation-qualified identity of one published script provider.
一次攻击请求(C++ 系统 / 脚本发起)。角度均为度。 旧名 FireRequest 保留为别名,向后兼容。
运行时触发资源(实体组件)。
武器模板(registerWeaponsFromJson 注册,进程级注册表)。
武器事件(帧缓存,脚本轮询,与 building/rpg 风格一致)。
bool consumed
Definition Graphics.cpp:201