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.
Projectile lua powerful enough for savegame.
Moderator: Moderators
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Projectile lua powerful enough for savegame.
What about this? (Not entirely sure if projectiles outside of map range matter)Google_Frog wrote: There is also no Spring.GetAllProjectiles function, this would be nice to have as the current alternative is Spring.GetProjectilesInRectangle.
Code: Select all
for _, projectileId in pairs(Spring.GetProjectilesInRectangle(0, 0, Game.mapSizeX, Game.mapSizeZ)) do
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Projectile lua powerful enough for savegame.
Sure that works but it is not nice.
Re: Projectile lua powerful enough for savegame.
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, ...)
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.
- 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, ...)
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.It may be infeasible to save and load every projectile
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.
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Projectile lua powerful enough for savegame.
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.
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.