Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "isFlying" JS field to Droid objects #3830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/js-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
}
Expand Down
2 changes: 1 addition & 1 deletion src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
3 changes: 1 addition & 2 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
}
Expand Down
2 changes: 1 addition & 1 deletion src/projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/quickjs_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Loading