From 9a4ed71ba0d44c3f71fd9eaed9990d90cc55ddb5 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Wed, 9 Oct 2024 18:16:41 -0500 Subject: [PATCH] Add `isFlying` JS field to Droid objects Co-authored-by: DARwins1 --- doc/js-objects.md | 1 + src/action.cpp | 2 +- src/combat.cpp | 2 +- src/droid.cpp | 3 +-- src/move.cpp | 2 +- src/projectile.cpp | 2 +- src/quickjs_backend.cpp | 2 ++ 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/js-objects.md b/doc/js-objects.md index 6b2f6acd601..3543ab9673e 100644 --- a/doc/js-objects.md +++ b/doc/js-objects.md @@ -95,6 +95,7 @@ the action directly, but it may be interesting to look at what it currently is. * ```experience``` Amount of experience this droid has, based on damage it has dealt to enemies. * ```cost``` What it would cost to build the droid. (3.2+ only) * ```isVTOL``` True if the droid is VTOL. (3.2+ only) +* ```isFlying``` True if the droid is currently flying. (4.5.4+ only) * ```canHitAir``` True if the droid has anti-air capabilities. (3.2+ only) * ```canHitGround``` True if the droid has anti-ground capabilities. (3.2+ only) * ```isSensor``` True if the droid has sensor ability. (3.2+ only) diff --git a/src/action.cpp b/src/action.cpp index 2452cb95cf0..1fa9e62c558 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -586,7 +586,7 @@ static bool actionRemoveDroidsFromBuildPos(unsigned player, Vector2i pos, uint16 } Vector2i delta = map_coord(droid->pos.xy()) - b.map; - if (delta.x < 0 || delta.x >= b.size.x || delta.y < 0 || delta.y >= b.size.y || droid->isFlying()) + if (delta.x < 0 || delta.x >= b.size.x || delta.y < 0 || delta.y >= b.size.y || droid->isFlying() || droid->isTransporter()) { continue; // Droid not under new structure (just near it). } diff --git a/src/combat.cpp b/src/combat.cpp index a7da53cf35b..0a63af10106 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -262,7 +262,7 @@ bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, in } predict += Vector3i(iSinCosR(psDroid->sMove.moveDir, psDroid->sMove.speed * flightTime / GAME_TICKS_PER_SEC), 0); - if (!psDroid->isFlying()) + if (!psDroid->isFlying() && !psDroid->isTransporter()) { predict.z = map_Height(predict.xy()); // Predict that the object will be on the ground. } diff --git a/src/droid.cpp b/src/droid.cpp index e3e0ed75179..3f899da3434 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -2911,8 +2911,7 @@ bool DROID::isVtol() const /* returns true if the droid has lift propulsion and is moving */ bool DROID::isFlying() const { - return getPropulsionStats()->propulsionType == PROPULSION_TYPE_LIFT - && (sMove.Status != MOVEINACTIVE || isTransporter()); + return getPropulsionStats()->propulsionType == PROPULSION_TYPE_LIFT && sMove.Status != MOVEINACTIVE; } // true if a droid is retreating for repair diff --git a/src/move.cpp b/src/move.cpp index e7638085b22..6807167ef91 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -897,7 +897,7 @@ static void moveOpenGates(DROID *psDroid, Vector2i tile) return; } MAPTILE *psTile = mapTile(tile); - if (!psDroid->isFlying() && psTile && psTile->psObject && psTile->psObject->type == OBJ_STRUCTURE && aiCheckAlliances(psTile->psObject->player, psDroid->player)) + if (!psDroid->isFlying() && !psDroid->isTransporter() && psTile && psTile->psObject && psTile->psObject->type == OBJ_STRUCTURE && aiCheckAlliances(psTile->psObject->player, psDroid->player)) { requestOpenGate((STRUCTURE *)psTile->psObject); // If it's a friendly gate, open it. (It would be impolite to open an enemy gate.) } diff --git a/src/projectile.cpp b/src/projectile.cpp index 46d2800c9ab..5adbc32ec80 100644 --- a/src/projectile.cpp +++ b/src/projectile.cpp @@ -892,7 +892,7 @@ static PROJECTILE* proj_InFlightFunc(PROJECTILE *psProj) else if (!(psStats->surfaceToAir & SHOOT_ON_GROUND) && (psTempObj->type == OBJ_STRUCTURE || psTempObj->type == OBJ_FEATURE || - (psTempObj->type == OBJ_DROID && !((DROID*)psTempObj)->isFlying()) + (psTempObj->type == OBJ_DROID && !((DROID*)psTempObj)->isTransporter() && !((DROID*)psTempObj)->isFlying()) )) { // AA weapons should not hit buildings and non-vtol droids diff --git a/src/quickjs_backend.cpp b/src/quickjs_backend.cpp index f83159c84fc..72a9f455d15 100644 --- a/src/quickjs_backend.cpp +++ b/src/quickjs_backend.cpp @@ -953,6 +953,7 @@ JSValue convFeature(const FEATURE *psFeature, JSContext *ctx) //;; * ```experience``` Amount of experience this droid has, based on damage it has dealt to enemies. //;; * ```cost``` What it would cost to build the droid. (3.2+ only) //;; * ```isVTOL``` True if the droid is VTOL. (3.2+ only) +//;; * ```isFlying``` True if the droid is currently flying. (4.5.4+ only) //;; * ```canHitAir``` True if the droid has anti-air capabilities. (3.2+ only) //;; * ```canHitGround``` True if the droid has anti-ground capabilities. (3.2+ only) //;; * ```isSensor``` True if the droid has sensor ability. (3.2+ only) @@ -1028,6 +1029,7 @@ JSValue convDroid(const DROID *psDroid, JSContext *ctx) QuickJS_DefinePropertyValue(ctx, value, "canHitAir", JS_NewBool(ctx, aa), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "canHitGround", JS_NewBool(ctx, ga), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "isVTOL", JS_NewBool(ctx, psDroid->isVtol()), JS_PROP_ENUMERABLE); + QuickJS_DefinePropertyValue(ctx, value, "isFlying", JS_NewBool(ctx, psDroid->isFlying()), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "droidType", JS_NewInt32(ctx, (int)type), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "experience", JS_NewFloat64(ctx, (double)psDroid->experience / 65536.0), JS_PROP_ENUMERABLE); QuickJS_DefinePropertyValue(ctx, value, "health", JS_NewFloat64(ctx, 100.0 / (double)psDroid->originalBody * (double)psDroid->body), JS_PROP_ENUMERABLE);