29Result<Value> nullRuntime() {
31 "combat carrier runtime must not be null",
"runtime", {},
32 "weapon.carrier.squirrel"));
35class ScriptTargetProvider final :
public IProjectileTargetProvider {
37 [[nodiscard]] Result<ProjectilePoint>
position(ecs::EntityHandle
target)
const override {
39 auto it = positions_.find(
key);
40 if (it == positions_.end())
43 "weapon.carrier.squirrel"));
48 void clear() { positions_.clear(); }
49 [[nodiscard]]
bool empty() const noexcept {
return positions_.empty(); }
52 [[nodiscard]]
static std::uint64_t keyOf(ecs::EntityHandle
target) {
53 return (
static_cast<std::uint64_t
>(
target.generation) << 32) |
target.id;
56 std::map<std::uint64_t, ProjectilePoint> positions_;
59class ScriptCircleHitProbe final :
public ICarrierHitProbe {
62 ecs::EntityHandle
id{};
67 [[nodiscard]] Result<std::vector<Contact>>
query(CarrierHandle,
const CarrierMotion&
previous,
68 const CarrierMotion&
current)
const override {
69 std::vector<Contact> contacts;
70 for (
const auto&
target : targets_) {
77 const double abx = bx - ax;
78 const double aby = by - ay;
79 const double abz = bz - az;
80 const double ab2 = abx * abx + aby * aby + abz * abz;
82 const double startDistance = ax * ax + ay * ay + az * az;
83 const double projection = ax * abx + ay * aby + az * abz;
84 if (ab2 <= 1e-12)
continue;
86 if (startDistance >= radius2 - 1e-9) {
88 if (projection >= 0.0)
continue;
89 const double discriminant = projection * projection - ab2 * (startDistance - radius2);
90 if (discriminant < 0.0)
continue;
91 t = (-projection - std::sqrt(discriminant)) / ab2;
92 if (t < -1e-9 || t > 1.0)
continue;
95 const double cx = ax + abx *
t;
96 const double cy = ay + aby *
t;
97 const double cz = az + abz *
t;
98 const double dist2 =
cx *
cx +
cy *
cy + cz * cz;
99 if (dist2 <= radius2 + 1e-9 * std::max(1.0, radius2)) {
104 const double len = std::sqrt(dist2);
108 contact.normal = {-1.0, 0.0, 0.0};
113 return Result<std::vector<Contact>>::success(std::move(contacts));
117 void clear() { targets_.clear(); }
118 [[nodiscard]]
bool empty() const noexcept {
return targets_.empty(); }
121 std::vector<Target> targets_;
126 object.emplace(
"slot",
Value(
static_cast<std::int64_t
>(
handle.slot)));
127 object.emplace(
"generation",
Value(
static_cast<std::int64_t
>(
handle.generation)));
128 return Value(std::move(
object));
158Value encodeEvent(
const CarrierEvent& event) {
160 object.emplace(
"slot",
Value(
static_cast<std::int64_t
>(event.carrier.slot)));
161 object.emplace(
"generation",
Value(
static_cast<std::int64_t
>(event.carrier.generation)));
162 object.emplace(
"recipeId",
Value(event.recipeId.format()));
163 object.emplace(
"trigger",
Value(std::string(triggerKindName(event.trigger))));
164 object.emplace(
"impact",
Value(std::string(impactKindName(event.impact))));
165 object.emplace(
"age",
Value(event.age.seconds()));
166 if (event.worldContact) {
167 const auto&
hit = *
event.worldContact;
168 object.emplace(
"bodyId",
Value(
static_cast<std::int64_t
>(
hit.bodyId)));
169 object.emplace(
"shapeId",
Value(
static_cast<std::int64_t
>(
hit.shapeId)));
170 object.emplace(
"bodyIndex",
Value(
static_cast<std::int64_t
>(
hit.identity.body & 0xffffffffu)));
171 object.emplace(
"bodyGeneration",
Value(
static_cast<std::int64_t
>(
hit.identity.body >> 32)));
172 object.emplace(
"worldIndex",
Value(
static_cast<std::int64_t
>(
hit.identity.world & 0xffffffffu)));
173 object.emplace(
"worldGeneration",
Value(
static_cast<std::int64_t
>(
hit.identity.world >> 32)));
174 object.emplace(
"fraction",
Value(
hit.fraction));
175 object.emplace(
"worldEpoch",
Value(
static_cast<std::int64_t
>(
hit.worldEpoch)));
177 object.emplace(
"damage",
Value(event.damage));
178 object.emplace(
"splashRadius",
Value(event.splashRadius));
179 object.emplace(
"damageType",
Value(event.damageType));
180 object.emplace(
"element",
Value(event.element));
181 object.emplace(
"x",
Value(event.position.x));
182 object.emplace(
"y",
Value(event.position.y));
183 object.emplace(
"z",
Value(event.position.z));
184 object.emplace(
"nx",
Value(event.normal.x));
185 object.emplace(
"ny",
Value(event.normal.y));
186 object.emplace(
"nz",
Value(event.normal.z));
187 object.emplace(
"sourceId",
Value(
static_cast<std::int64_t
>(event.source.id)));
188 object.emplace(
"sourceGeneration",
Value(
static_cast<std::int64_t
>(event.source.generation)));
189 object.emplace(
"targetId",
Value(
static_cast<std::int64_t
>(event.target.id)));
190 object.emplace(
"targetGeneration",
Value(
static_cast<std::int64_t
>(event.target.generation)));
191 return Value(std::move(
object));
197 for (
const auto&
handle :
frame.advanced) advanced.push_back(encodeHandle(
handle));
199 for (
const auto&
handle :
frame.released) released.push_back(encodeHandle(
handle));
202 object.emplace(
"advanced",
Value(std::move(advanced)));
203 object.emplace(
"released",
Value(std::move(released)));
204 object.emplace(
"events",
Value(std::move(
events)));
205 object.emplace(
"eventCount",
Value(
static_cast<std::int64_t
>(
frame.events.size())));
206 object.emplace(
"activeAdvanced",
Value(
static_cast<std::int64_t
>(
frame.advanced.size())));
207 return Value(std::move(
object));
210Value encodePlan(
const SpellCastPlan& plan) {
212 object.emplace(
"recipeId",
Value(plan.recipe.id.format()));
213 object.emplace(
"hasVolley",
Value(plan.volley.has_value()));
214 if (plan.volley.has_value()) {
215 object.emplace(
"volleyCount",
Value(
static_cast<std::int64_t
>(plan.volley->count)));
216 object.emplace(
"volleyPattern",
218 object.emplace(
"volleySpread",
Value(plan.volley->spreadDegrees));
220 return Value(std::move(
object));
223class ScriptMotionFunction final :
public ICarrierMotionFunction {
226 Result<CarrierMotion>
evaluate(
const CarrierState& before,
const CarrierMotion& proposed,
227 Duration
step)
const override {
228 const auto vm = callback_.getHandle();
229 const auto top = sq_gettop(
vm);
233 ~StackGuard() { sq_settop(
vm,
top); }
235 auto table = [
vm](
const CarrierMotion& motion) {
237 result.set(
"x",
static_cast<float>(motion.position.x));
238 result.set(
"y",
static_cast<float>(motion.position.y));
239 result.set(
"z",
static_cast<float>(motion.position.z));
240 result.set(
"vx",
static_cast<float>(motion.velocity.x));
241 result.set(
"vy",
static_cast<float>(motion.velocity.y));
242 result.set(
"vz",
static_cast<float>(motion.velocity.z));
246 state.set(
"age",
static_cast<float>(before.age.seconds()));
247 state.set(
"lifetime",
static_cast<float>(before.lifetime.seconds()));
248 state.set(
"distanceTravelled",
static_cast<float>(before.distanceTravelled));
249 state.set(
"recipeId", before.recipeId.format());
250 state.set(
"slot",
static_cast<std::int64_t
>(before.handle.slot));
251 state.set(
"generation",
static_cast<std::int64_t
>(before.handle.generation));
253 static_cast<float>(
step.seconds()))))
263 "Motion function must return null or a position/velocity table",
"motionFunction"));
264 CarrierMotion
output = proposed;
268 if (
const auto* real =
field.getIf<
double>())
270 else if (
const auto* integer =
field.getIf<std::int64_t>())
271 number =
static_cast<double>(*integer);
278 }
else if (
name ==
"y") {
281 }
else if (
name ==
"z") {
284 }
else if (
name ==
"vx") {
287 }
else if (
name ==
"vy") {
290 }
else if (
name ==
"vz") {
302 if (
positions == 3 && velocities == 3 &&
output.position.x ==
static_cast<float>(proposed.position.x) &&
303 output.position.y ==
static_cast<float>(proposed.position.y) &&
304 output.position.z ==
static_cast<float>(proposed.position.z) &&
305 output.velocity.x ==
static_cast<float>(proposed.velocity.x) &&
306 output.velocity.y ==
static_cast<float>(proposed.velocity.y) &&
307 output.velocity.z ==
static_cast<float>(proposed.velocity.z))
309 const double dt =
step.seconds();
311 output.position = {before.motion.position.x +
output.velocity.x *
dt,
312 before.motion.position.y +
output.velocity.y *
dt,
313 before.motion.position.z +
output.velocity.z *
dt};
315 output.velocity = {(
output.position.x - before.motion.position.x) /
dt,
316 (
output.position.y - before.motion.position.y) /
dt,
317 (
output.position.z - before.motion.position.z) /
dt};
322 ssq::Function callback_;
325class ScriptCombatCarrierRuntime {
327 ScriptCombatCarrierRuntime() =
default;
329 [[nodiscard]] Result<Value> configurePool(std::int64_t
capacity) {
330 if (evaluating_)
return mutationConflict();
331 if (capacity < 1 || capacity > 1048576)
333 "pool capacity must be in 1..1048576",
"capacity", {},
334 "weapon.carrier.squirrel"));
335 auto configured = runtime_.configurePool(
static_cast<std::uint32_t
>(
capacity));
338 object.emplace(
"capacity",
Value(
static_cast<std::int64_t
>(runtime_.capacity())));
342 [[nodiscard]] Result<Value> configureSimulation(
double maxStepSeconds, std::int64_t maxIterations,
343 std::int64_t maxCollisions, std::int64_t maxTriggerFirings) {
344 if (evaluating_)
return mutationConflict();
347 if (maxIterations < 1 || maxIterations > 65536 || maxCollisions < 1 || maxCollisions > 65536 ||
348 maxTriggerFirings < 1 || maxTriggerFirings > 65536)
350 "Simulation budgets must be in 1..65536",
"simulation"));
351 CarrierSimulationSettings
settings{
duration.value(),
static_cast<std::uint32_t
>(maxIterations),
352 static_cast<std::uint32_t
>(maxCollisions),
353 static_cast<std::uint32_t
>(maxTriggerFirings)};
354 auto configured = runtime_.configureSimulation(
settings);
359 [[nodiscard]] Result<Value> registerRecipeValue(
const Value&
value) {
360 if (evaluating_)
return mutationConflict();
363 CarrierRecipe
owned = std::move(
recipe).takeValue();
364 for (
const auto& op :
owned.motionOps) {
368 "SteerAvoidBody recipes are not supported by the script carrier runtime; omit avoidBody or use C++",
369 "motion", {},
"weapon.carrier.squirrel"));
372 const std::string
id =
owned.id.format();
373 auto registered = runtime_.registerRecipe(
owned);
376 object.emplace(
"recipeId",
Value(
id));
380 [[nodiscard]] Result<Value> registerRecipeJson(
const std::string& json) {
381 if (evaluating_)
return mutationConflict();
384 return registerRecipeValue(parsed.value());
387 [[nodiscard]] Result<Value> compileFragmentsValue(
const Value& fragments) {
388 if (evaluating_)
return mutationConflict();
391 return registerPlan(std::move(plan).takeValue());
394 [[nodiscard]] Result<Value> compileFragmentsJson(
const std::string& json) {
395 if (evaluating_)
return mutationConflict();
398 return registerPlan(std::move(plan).takeValue());
401 [[nodiscard]] Result<Value> castValue(
const Value& fragments,
double x,
double y,
double z,
double dx,
double dy,
402 double dz, std::int64_t
targetId, std::int64_t targetGeneration) {
403 if (evaluating_)
return mutationConflict();
406 SpellCastPlan
owned = std::move(plan).takeValue();
407 auto uniquified = uniquifyRecipeId(
owned.recipe.id);
409 owned.recipe.id = uniquified.value();
411 bool needsTarget =
false;
417 for (
const auto& trigger :
owned.
recipe.triggers) {
423 "Homing/proximity casts require castAtTarget with a positive target id",
"target", {},
424 "weapon.carrier.squirrel"));
427 auto registered = registerPlan(
owned);
428 if (!registered.ok())
return registered;
432 [[nodiscard]] Result<Value> castJson(
const std::string& json,
double x,
double y,
double z,
double dx,
double dy,
433 double dz, std::int64_t
targetId, std::int64_t targetGeneration) {
434 if (evaluating_)
return mutationConflict();
437 return castValue(parsed.value(),
x,
y,
z,
dx,
dy,
dz,
targetId, targetGeneration);
440 [[nodiscard]]
static Result<void> validateHandleParts(std::int64_t
id, std::int64_t
generation,
441 std::string_view
path) {
442 if (
id < 0 ||
generation < 0 ||
static_cast<std::uint64_t
>(
id) > std::numeric_limits<std::uint32_t>::max() ||
443 static_cast<std::uint64_t
>(
generation) > std::numeric_limits<std::uint32_t>::max()) {
445 "handle id/generation must fit in uint32", std::string(
path),
446 {},
"weapon.carrier.squirrel"));
451 [[nodiscard]]
static Result<void> validatePoint(
double x,
double y,
double z, std::string_view
path) {
452 if (!std::isfinite(
x) || !std::isfinite(
y) || !std::isfinite(
z)) {
454 "coordinates must be finite", std::string(
path), {},
455 "weapon.carrier.squirrel"));
460 [[nodiscard]] Result<Value> spawn(
const std::string& recipeId,
double x,
double y,
double z,
double dx,
double dy,
461 double dz, std::int64_t
targetId, std::int64_t targetGeneration) {
462 if (evaluating_)
return mutationConflict();
466 "recipe id must be namespace:name",
"recipeId", {},
467 "weapon.carrier.squirrel"));
474 auto handle = validateHandleParts(
targetId, targetGeneration,
"target");
478 target.generation =
static_cast<std::uint32_t
>(targetGeneration);
484 object.emplace(
"handle", encodeHandle(
spawned.value()));
485 object.emplace(
"activeCount",
Value(
static_cast<std::int64_t
>(runtime_.activeCount())));
489 [[nodiscard]] Result<Value> spawnVolley(
const std::string& recipeId,
double x,
double y,
double z,
double dx,
491 double spread, std::int64_t
targetId, std::int64_t targetGeneration) {
492 if (evaluating_)
return mutationConflict();
496 "recipe id must be namespace:name",
"recipeId", {},
497 "weapon.carrier.squirrel"));
502 volley.spreadDegrees = spread;
509 auto handle = validateHandleParts(
targetId, targetGeneration,
"target");
513 target.generation =
static_cast<std::uint32_t
>(targetGeneration);
521 object.emplace(
"handles",
Value(std::move(handles)));
522 object.emplace(
"count",
Value(
static_cast<std::int64_t
>(
spawned.value().size())));
523 object.emplace(
"activeCount",
Value(
static_cast<std::int64_t
>(runtime_.activeCount())));
527 [[nodiscard]] Result<Value> states()
const {
529 for (
const auto& state : runtime_.states()) {
531 entry.emplace(
"handle", encodeHandle(
state.handle));
532 entry.emplace(
"recipeId",
Value(
state.recipeId.format()));
533 entry.emplace(
"x",
Value(
state.motion.position.x));
534 entry.emplace(
"y",
Value(
state.motion.position.y));
535 entry.emplace(
"z",
Value(
state.motion.position.z));
536 entry.emplace(
"vx",
Value(
state.motion.velocity.x));
537 entry.emplace(
"vy",
Value(
state.motion.velocity.y));
538 entry.emplace(
"vz",
Value(
state.motion.velocity.z));
539 entry.emplace(
"age",
Value(
state.age.seconds()));
540 entry.emplace(
"distanceTravelled",
Value(
state.distanceTravelled));
541 values.emplace_back(std::move(entry));
546 [[nodiscard]] Result<Value> bindWorld3D(
const std::string&
token,
float radius, std::int64_t
category,
547 std::int64_t
mask, std::int64_t ignoredBody) {
548 if (evaluating_)
return mutationConflict();
549 if (runtime_.activeCount() != 0)
552 if (category < -1 || category > UINT32_MAX || mask < -1 || mask > UINT32_MAX || ignoredBody < -1 ||
553 ignoredBody > INT32_MAX)
555 "Invalid category, mask or ignored body",
"worldSweep"));
556 auto* factory = cap::query<IWorldSphereSweepFactory>();
561 static_cast<std::uint32_t
>(
mask),
static_cast<int>(ignoredBody)});
563 worldHits_ = std::make_unique<WorldHitProbe>(std::move(bound).takeValue());
566 [[nodiscard]] Result<Value> clearWorld3D() {
567 if (evaluating_)
return mutationConflict();
568 if (runtime_.activeCount() != 0)
575 [[nodiscard]] Result<Value> update(
double seconds) {
576 if (evaluating_)
return mutationConflict();
579 return finishFrame(runtime_.update(delta.value(), &targets_, &hits_,
nullptr, worldHits_.get()));
582 [[nodiscard]] Result<Value> updateWithMotion(
double seconds, ssq::Object
callback) {
583 if (evaluating_)
return mutationConflict();
584 if (
callback.getType() != ssq::Type::CLOSURE &&
callback.getType() != ssq::Type::NATIVECLOSURE)
586 "Motion function must be callable",
"motionFunction"));
591 ~Guard() { flag =
false; }
592 } guard{evaluating_};
596 runtime_.updateWithMotion(delta.value(),
function, &targets_, &hits_,
nullptr, worldHits_.get()));
599 [[nodiscard]] Result<Value> addHitTarget(std::int64_t
id, std::int64_t
generation,
double x,
double y,
double z,
601 if (evaluating_)
return mutationConflict();
604 auto point = validatePoint(
x,
y,
z,
"target");
608 "hit target requires positive finite radius",
"radius", {},
609 "weapon.carrier.squirrel"));
610 ScriptCircleHitProbe::Target
target;
611 target.id.id =
static_cast<std::uint32_t
>(
id);
617 object.emplace(
"count",
Value(
static_cast<std::int64_t
>(1)));
621 [[nodiscard]] Result<Value> clearHitTargets() {
622 if (evaluating_)
return mutationConflict();
627 [[nodiscard]] Result<Value> setTargetPosition(std::int64_t
id, std::int64_t
generation,
double x,
double y,
629 if (evaluating_)
return mutationConflict();
632 auto point = validatePoint(
x,
y,
z,
"target");
635 target.id =
static_cast<std::uint32_t
>(
id);
641 [[nodiscard]] Result<Value> clearTargets() {
642 if (evaluating_)
return mutationConflict();
647 [[nodiscard]] std::int64_t activeCount() const noexcept {
648 return static_cast<std::int64_t
>(runtime_.activeCount());
651 [[nodiscard]] std::int64_t
capacity() const noexcept {
return static_cast<std::int64_t
>(runtime_.capacity()); }
654 bool evaluating_ =
false;
655 [[nodiscard]]
static Result<Value> mutationConflict() {
659 [[nodiscard]] Result<Value> finishFrame(Result<CarrierFrame>
frame) {
661 lastFrame_ =
frame.value();
662 Value encoded = encodeFrame(lastFrame_);
664 object->emplace(
"activeCount",
Value(
static_cast<std::int64_t
>(runtime_.activeCount())));
668 [[nodiscard]] Result<LogicalId> uniquifyRecipeId(
const LogicalId& base) {
670 const std::string uniqueName = std::string(base.name()) +
"-c" + std::to_string(castSeq_);
672 if (!parsed.has_value())
674 "unable to allocate unique cast recipe id",
"recipeId",
675 {},
"weapon.carrier.squirrel"));
679 [[nodiscard]] Result<Value> registerPlan(SpellCastPlan plan) {
680 for (
const auto& op : plan.
recipe.motionOps) {
684 "SteerAvoidBody recipes are not supported by the script carrier runtime",
685 "motion", {},
"weapon.carrier.squirrel"));
688 for (
const auto& dependent : plan.dependentRecipes) {
689 auto registered = runtime_.registerRecipe(dependent);
692 auto registered = runtime_.registerRecipe(plan.recipe);
697 [[nodiscard]] Result<Value> spawnPlan(
const SpellCastPlan& plan,
double x,
double y,
double z,
double dx,
double dy,
698 double dz, std::int64_t
targetId, std::int64_t targetGeneration) {
699 auto spawned = plan.volley.has_value()
700 ? spawnVolley(plan.recipe.id.format(),
x,
y,
z,
dx,
dy,
dz, plan.volley->count,
707 object->emplace(
"recipeId",
Value(plan.recipe.id.format()));
712 CombatCarrierRuntime runtime_;
713 ScriptTargetProvider targets_;
714 ScriptCircleHitProbe hits_;
715 std::unique_ptr<WorldHitProbe> worldHits_;
716 CarrierFrame lastFrame_{};
717 std::uint64_t castSeq_ = 0;
726 auto runtime = std::make_unique<ScriptCombatCarrierRuntime>();
727 auto configured = runtime->configurePool(
capacity);
729 auto object = script::makeOwnedSquirrelInstance<ScriptCombatCarrierRuntime>(
vm, std::move(runtime));
732 result.set(
"value", std::move(
object).takeValue());
733 result.set(
"ownership", std::string(
"owned"));
737Result<Value> valueFromObject(
const ssq::Object&
object) {
746 auto runtime = table.addClass<ScriptCombatCarrierRuntime>(
747 "CombatCarrierRuntime", std::function<ScriptCombatCarrierRuntime*()>([] {
return nullptr; }),
true);
748 runtime.addFunc(
"ownership", [](ScriptCombatCarrierRuntime*) {
return std::string(
"owned"); });
749 runtime.addFunc(
"activeCount", [](ScriptCombatCarrierRuntime* self) {
750 return self ? self->activeCount() :
static_cast<std::int64_t
>(0);
752 runtime.addFunc(
"capacity", [](ScriptCombatCarrierRuntime* self) {
753 return self ? self->capacity() :
static_cast<std::int64_t
>(0);
755 runtime.addFunc(
"configurePool", [
vm](ScriptCombatCarrierRuntime* self, std::int64_t
capacity) {
756 return project(
vm, self ? self->configurePool(
capacity) : nullRuntime());
759 "configureSimulation", [
vm](ScriptCombatCarrierRuntime* self,
float maxStepSeconds, std::int64_t maxIterations,
760 std::int64_t maxCollisions, std::int64_t maxTriggerFirings) {
762 vm, self ? self->configureSimulation(maxStepSeconds, maxIterations, maxCollisions, maxTriggerFirings)
765 runtime.addFunc(
"registerRecipe", [
vm](ScriptCombatCarrierRuntime* self, ssq::Object
recipe) {
766 if (!self)
return project(
vm, nullRuntime());
769 return project(
vm, self->registerRecipeValue(
value.value()));
771 runtime.addFunc(
"registerRecipeJson", [
vm](ScriptCombatCarrierRuntime* self,
const std::string& json) {
772 return project(
vm, self ? self->registerRecipeJson(json) : nullRuntime());
774 runtime.addFunc(
"compileFragments", [
vm](ScriptCombatCarrierRuntime* self, ssq::Object fragments) {
775 if (!self)
return project(
vm, nullRuntime());
776 auto value = valueFromObject(fragments);
778 return project(
vm, self->compileFragmentsValue(
value.value()));
780 runtime.addFunc(
"compileFragmentsJson", [
vm](ScriptCombatCarrierRuntime* self,
const std::string& json) {
781 return project(
vm, self ? self->compileFragmentsJson(json) : nullRuntime());
783 runtime.addFunc(
"cast", [
vm](ScriptCombatCarrierRuntime* self, ssq::Object fragments,
float x,
float y,
float z,
784 float dx,
float dy,
float dz) {
785 if (!self)
return project(
vm, nullRuntime());
786 auto value = valueFromObject(fragments);
788 return project(
vm, self->castValue(
value.value(),
x,
y,
z,
dx,
dy,
dz, 0, 0));
790 runtime.addFunc(
"castAtTarget", [
vm](ScriptCombatCarrierRuntime* self, ssq::Object fragments,
float x,
float y,
792 std::int64_t targetGeneration) {
793 if (!self)
return project(
vm, nullRuntime());
794 auto value = valueFromObject(fragments);
798 runtime.addFunc(
"castJson", [
vm](ScriptCombatCarrierRuntime* self,
const std::string& json,
float x,
float y,
799 float z,
float dx,
float dy,
float dz) {
800 return project(
vm, self ? self->castJson(json,
x,
y,
z,
dx,
dy,
dz, 0, 0) : nullRuntime());
802 runtime.addFunc(
"spawn", [
vm](ScriptCombatCarrierRuntime* self,
const std::string& recipeId,
float x,
float y,
803 float z,
float dx,
float dy,
float dz) {
804 return project(
vm, self ? self->spawn(recipeId,
x,
y,
z,
dx,
dy,
dz, 0, 0) : nullRuntime());
806 runtime.addFunc(
"spawnAtTarget", [
vm](ScriptCombatCarrierRuntime* self,
const std::string& recipeId,
float x,
808 std::int64_t targetGeneration) {
809 return project(
vm, self ? self->spawn(recipeId,
x,
y,
z,
dx,
dy,
dz,
targetId, targetGeneration)
812 runtime.addFunc(
"spawnVolley", [
vm](ScriptCombatCarrierRuntime* self,
const std::string& recipeId,
float x,
float y,
813 float z,
float dx,
float dy,
float dz, std::int64_t
count,
814 const std::string&
pattern,
float spread) {
815 return project(
vm, self ? self->spawnVolley(recipeId,
x,
y,
z,
dx,
dy,
dz,
count,
pattern, spread, 0, 0)
818 runtime.addFunc(
"bindWorld3D", [
vm](ScriptCombatCarrierRuntime* self,
const std::string&
token,
float radius,
819 std::int64_t
category, std::int64_t
mask, std::int64_t ignoredBody) {
822 runtime.addFunc(
"clearWorld3D", [
vm](ScriptCombatCarrierRuntime* self) {
823 return project(
vm, self ? self->clearWorld3D() : nullRuntime());
825 runtime.addFunc(
"states", [
vm](ScriptCombatCarrierRuntime* self) {
826 return project(
vm, self ? self->states() : nullRuntime());
828 runtime.addFunc(
"update", [
vm](ScriptCombatCarrierRuntime* self,
float seconds) {
829 return project(
vm, self ? self->update(seconds) : nullRuntime());
831 runtime.addFunc(
"updateWithMotion", [
vm](ScriptCombatCarrierRuntime* self,
float seconds, ssq::Object
function) {
832 return project(
vm, self ? self->updateWithMotion(seconds, std::move(
function)) : nullRuntime());
834 runtime.addFunc(
"addHitTarget", [
vm](ScriptCombatCarrierRuntime* self, std::int64_t
id, std::int64_t
generation,
835 float x,
float y,
float z,
float radius) {
838 runtime.addFunc(
"clearHitTargets", [
vm](ScriptCombatCarrierRuntime* self) {
839 return project(
vm, self ? self->clearHitTargets() : nullRuntime());
841 runtime.addFunc(
"setTargetPosition", [
vm](ScriptCombatCarrierRuntime* self, std::int64_t
id,
843 return project(
vm, self ? self->setTargetPosition(
id,
generation,
x,
y,
z) : nullRuntime());
845 runtime.addFunc(
"clearTargets", [
vm](ScriptCombatCarrierRuntime* self) {
846 return project(
vm, self ? self->clearTargets() : nullRuntime());
856 cls.addFunc(
"newCarrierRuntimeDefault", [
vm](
Weapon*) {
return newCarrierRuntime(
vm, 256); });
Decode/encode CombatCarrier recipes from canonical eve::Value trees.
Composable combat-carrier runtime: motion ops, triggers, and impacts.
struct SQVM * HSQUIRRELVM
Stable, structured diagnostics shared by engine modules.
const GltfImportRequest & request
wgpu::PopErrorScopeStatus status
std::vector< float > positions
std::array< float, 3 > position
OceanWakeSettings settings
std::shared_ptr< const OceanSprayFrame > previous
std::vector< particles::ParticleRecordEvent > events
std::set< std::string > values
MigrationFunction function
std::optional< CarrierVolleySpec > volley
Compile Noita-style spell/modifier fragment sequences into carrier recipes.
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
Common time values and an injectable deterministic simulation clock.
Owning, renderer-independent dynamic values.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
static std::optional< LogicalId > fromParts(std::string_view namespaceName, std::string_view name)
Builds a logical ID from separate namespace and name components.
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
std::map< std::string, Value > Object
std::vector< Value > Array
static Value object(Object value)
Compatibility factory for an object value.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Snapshot project(Files files, Object::Ptr stats, std::string defaultProjectId, std::string projectDir)
Build a candidate evidence graph without touching the published snapshot.
ForceVector add(ForceVector a, ForceVector b)
std::unordered_map< std::string, SkillDefinition > & table()
SQRESULT callFunctionResult(HSQUIRRELVM vm, const HSQOBJECT &fn, const Receiver &receiver, Args &&... args)
callFunction() that keeps the return value on top for the caller to read.
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
constexpr RootTable rootTable
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.
std::vector< OnnxNamedTensor > evaluate(const ModelData &, std::span< const OnnxNamedTensor >, const std::vector< std::string > &, OnnxCompute *, OnnxRunOptions options)
Evaluate.
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
CarrierImpactKind
What happens when a matching trigger fires.
void exposeCombatCarrierModuleMethods(ssq::Class &cls)
Register Weapon module methods that create owned carrier runtimes.
Result< CarrierRecipe > decodeCarrierRecipe(const Value &value)
Decode one CarrierRecipe from an owning Value object.
CarrierTriggerKind
When an impact may fire.
void exposeCombatCarrierBindings(ssq::Table &table)
Expose CombatCarrierRuntime class bindings under the shared eve table.
Result< SpellCastPlan > compileSpellFragmentsJson(const std::string &json)
Compile a JSON array string into one cast plan.
Result< SpellCastPlan > compileSpellFragments(const Value &fragments)
Compile a fragment array Value into one cast plan.
CarrierVolleyPattern
Multi-projectile aim pattern for one salvo.