vaendryl / Sunrider

source code of the visual novel 'Sunrider'
http://sunrider-vn.com/
41 stars 21 forks source link

write proper 'restart battle' code #74

Closed vaendryl closed 9 years ago

vaendryl commented 9 years ago

currently restarting a battle is done by loading a save made from the start, but this is bad for a number of reasons. starting a battle, loading a different battle and losing and clicking retry will actually load the start of the first (different) battle. also, because it loads a save you can't add an option saying 'lower difficulty and try again'.

maybe the easiest way to deal with this is to make a copy of the player_ships and the enemy_ships list at the start of battle and use that.

DoumanAsh commented 9 years ago

@vaendryl, it saves as file or? I'm thinking of just deleting this save once battle is is won by player

vaendryl commented 9 years ago

no, it should specifically not save a file at all. instead of making a save file, make a backup of the player_ships list and the enemy_ships list with deepcopy() and restore those to reset the battle.

EnderShadow commented 9 years ago

Wouldn't that cause an aliasing problem between player_ships and the individual ship variables?

vaendryl commented 9 years ago

yes it would, but that can be fixed after the player gets defeated.

maybe... loop through the list and compare names? if ship.name == 'Sunrider': sunrider = ship

alternatively, you could just heal all the player ships and store just the missile and rocket value separately in a backup value. then you could wipe the enemies and call the init label again such as is done in the script before each battle.

if it was easy I'd have done it already :p

EnderShadow commented 9 years ago

I've been trying to work on this, but the game doesn't seem to like going into battle from the badend screen. I tried something this

renpy.hide('badend')
clean_battle_exit(True) # using true tells it to revive dead mercenaries
renpy.call('mission{}_inits'.format(BM.mission))
renpy.jump('battle_start')

but the game would just pause for a moment and then take me to the main menu.

vaendryl commented 9 years ago

sounds like some kind of silenced exception quits the game context. I should try a different approach later.

EnderShadow commented 9 years ago

Do you know if there's anyway to find out what causes the silenced exception?

vaendryl commented 9 years ago

can't really think of a good way... it's possible it's inside renpy somewhere :/

btw, I imagine you're putting that code under the tryagain label in combatlabels.rpy? you may want to try using renpy statements instead of python code. it might change how renpy handles it.

EnderShadow commented 9 years ago

I had actually put it in a class that was called when you clicked the try-again button. Maybe that way would work better. I'll test it later today and post my results.

vaendryl commented 9 years ago

I feel renpy often doesn't deal well with extensive python code trying to tell it go do all sorts of things without getting the chance to do them on its own terms - especially jumping around and changing contexts.

EnderShadow commented 9 years ago

After testing with that, It seems that the last destroyed player ship (usually the sunrider) doesn't get re-created on battle restart (unless it's created from scratch in the mission init). There also seems to be a slight highlighting bug with some units on mission restart, but I can fix that.

vaendryl commented 9 years ago

looking at the sunriders custom destroy method code, I notice it never gets added to the destroyed_ships list, but does get removed from player_ships (for whatever reason). probably because the former list didn't exist when this code was written.

seems fixable.

EnderShadow commented 9 years ago

yep. I'll try that and report back. There's also some bugs with the AI that I need to fix as well.

vaendryl commented 9 years ago

I've been messing with AI too. best leave that for after next commit.

EnderShadow commented 9 years ago

The bugs are with the player AI. mainly missing methods from some of the weapons.

EnderShadow commented 9 years ago

It seems that units added in the init methods now get duplicated on battle restart. This will be harder to deal with

vaendryl commented 9 years ago

ah, I just tried out that player AI thing. I noticed the issues and fixed them too XD that said, it's actually quite fun to set up a battle and let the AI duke it out. kind of like that game 'gratuitous space battles'.

you might want to just make a deepcopy of the enemy_ships list and use that to replace the current one (do rebuild BM.ships after). this will keep their location data intact and you don't have to call the init at all.

in fact, how are you dealing with spent CMD points, rockets, repair drones etc?

EnderShadow commented 9 years ago

... I forgot about those.

CloudiDust commented 9 years ago

Does renpy have load/save hooks? Basically to run arbitrary code before/after a load/save? If so we can use that. I think coding a separate state persisting mechanism is quite error-prone.

EnderShadow commented 9 years ago

I was thinking of modifying how the missions were initialized, but I'm waiting for Vaendryl's reply on that matter.

EnderShadow commented 9 years ago

I finished it!! finally! phew.

EnderShadow commented 9 years ago

and now I have to merge it...

EnderShadow commented 9 years ago

done.