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

Adding TTL to CWeapon #1893

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

seedship
Copy link
Contributor

@seedship seedship commented Jan 12, 2025

Added option to set ttl in SetUnitWeaponState, and added a ttl field into CWeapon. This overrides the original weaponDef->flighttime so games can set weapon ttl per weapon.

Addresses #1683

Tested with the following gadget in Zero-K:

if gadgetHandler:IsSyncedCode() then
    function gadget:AllowCommand(unitID, unitDefID, teamID)
        local ttl = 1
        print("Calling Spring Set Unit Weapon State")
        Spring.SetUnitWeaponState(unitID, 1, "ttl", ttl)
        return true
    end
end

Verified:

  • Nimbus Emg shells explode immediately
  • Emissary cannon shell explodes immediately
  • Likho bomb explodes immediately
  • Ronin rocket looks like it explodes immediately
  • Rogue rocket has no fuel and does an arc and cannot hit the rogue's max range
  • Starburst weapons (racketeer and impaler) seem to be unaffected.
  • Urchin torpedos just fall straight down and explode and cannot hit their target.

rts/Sim/Weapons/Cannon.cpp Outdated Show resolved Hide resolved
@@ -151,6 +151,7 @@ class CWeapon : public CObject
int nextSalvo; // when the next shot in the current salvo will fire
int salvoLeft; // number of shots left in current salvo
int salvoWindup; // delay before first shot (in frames)
int ttl; // flight time for missile type weapons
Copy link
Collaborator

@saurtron saurtron Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe comment should be "projectile flighttime" since it's not just for missile type weapons, also maybe should mention it refers to frames.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the comment to say projectile type weapons. It does set the ttl field in the projectile params.

@seedship
Copy link
Contributor Author

It seems Starburst weapons/projectiles are complicated and do their own thing. I will leave them alone in this PR.

@@ -39,9 +39,10 @@ void CStarburstLauncher::FireImpl(const bool scriptCall)
params.end = currentTargetPos;
params.speed = speed;
params.error = aimError;
params.ttl = 200; //???
// Projectile TTL (params.ttl) is ignored by the Starburst Projectile and it only uses the weapondef.
// I tried overriding the projectile TTL to 1 and it caused the starburst rocket to fly off into space
Copy link
Collaborator

@saurtron saurtron Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it goes up until uptime runs out, and only then is ttl evaluated, so you need to set a ttl a bit higher than uptime in that case to see an effect. Could make the logic of how ttl and uptime interact a bit more intuitive maybe, but not in scope of this pr.

@@ -39,9 +39,10 @@ void CStarburstLauncher::FireImpl(const bool scriptCall)
params.end = currentTargetPos;
params.speed = speed;
params.error = aimError;
params.ttl = 200; //???
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can make this pass ttl on and then make StarburstProjectile.cpp not overwrite it from weaponDef. That way ttl should also be controllable for starburst.

@@ -110,27 +110,27 @@ void CCannon::FireImpl(const bool scriptCall)
launchDir += (gsRNG.NextVector() * SprayAngleExperience() + SalvoErrorExperience());
launchDir.SafeNormalize();

int ttl = 0;
int thisTtl = 0;
Copy link
Collaborator

@saurtron saurtron Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like Ttl form personally, but not the only place that writes it (Ttl) like that (vs TTL). Also maybe consider myTTL or myTtl instead of thisTtl/thisTTL, I think it's more in line with style around these files.

Anyways not really an issue since it's more of a personal preference thing, you can choose any you want from thisTtl/thisTTL/myTtl/myTTL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants