Projectile lua powerful enough for savegame.

Projectile lua powerful enough for savegame.

Requests for features in the spring code.

Moderator: Moderators

Post Reply
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Projectile lua powerful enough for savegame.

Post by Google_Frog »

I would like to implement lua savegame with projectile saving/loading. It may be infeasible to save and load every projectile but I want to save the important ones. Players should not have the temptation to cheat by saving and loading the game when a nuke is launched at them.

For loading games Spring.SpawnProjectile and Spring.SetProjectileTarget look like they will be almost sufficient. Apparently projectile spawning can take many parameters which seem vital for spawning in flight projectiles (namely team and time to live). SetProjectileTarget will work for unit targets because CreateUnit can take a unitID as a parameter, unfortunately it will not work for interceptors because SpawnProjectile does not take a projectileID.

Spring.SpawnProjectile needs to take a projectileID as an optional parameter.

Extra functions are required for saving games because none of the useful parameters which can be set in Spring.SpawnProjectile can be read. Time to live and team are important, others may be important too but I have not discovered what they all do. There is also no Spring.GetAllProjectiles function, this would be nice to have as the current alternative is Spring.GetProjectilesInRectangle.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Projectile lua powerful enough for savegame.

Post by gajop »

Google_Frog wrote: There is also no Spring.GetAllProjectiles function, this would be nice to have as the current alternative is Spring.GetProjectilesInRectangle.
What about this? (Not entirely sure if projectiles outside of map range matter)

Code: Select all

for _, projectileId in pairs(Spring.GetProjectilesInRectangle(0, 0, Game.mapSizeX,  Game.mapSizeZ)) do
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Projectile lua powerful enough for savegame.

Post by Google_Frog »

Sure that works but it is not nice.
8611
XTA Developer
Posts: 242
Joined: 29 Dec 2014, 08:22

Re: Projectile lua powerful enough for savegame.

Post by 8611 »

Those could be useful for other stuff too:
- Spring.GetProjectileTeam(projectileID) -> returns teamID that this proj. belongs to
- Spring.GetProjectileShooter (projectileID) -> returns unitID that shot the proj.
- Spring.SpawnProjectile - take projectileID as parameter
-Spring.GetProjectilesIn[Cylinder, Sphere,..] - as for units/features
- ways to read/set all the other states or projectiles. (if StarBustLauncher proj. is in "raising up" phase or aiming (weaponTimer), the remaining bounces of a weapon with numBounce, ...)
It may be infeasible to save and load every projectile
If the concern is about about projectiles amount, it might be okayish: Even a fast-firing units like BA's flash rarely has more than 10 projectiles in the air at once. Most units fire much slower or are not firing at same time or are unarmed.

Another useless trick that as un-nice as GetProjectilesInRectangle(0, 0, Game.mapSizeX, Game.mapSizeZ) is using the projectileID returned by SpawnProjectile() as target-arguement in SetProjectileTarget() of a spawned interceptor weapon.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Projectile lua powerful enough for savegame.

Post by Google_Frog »

Done. https://github.com/spring/spring/pull/172

With this I am able to save and load antinuke-nuke-interceptor systems without adverse effects. Everything else I want to do with projectiles is simpler than that.
Post Reply

Return to “Feature Requests”