Undo button

For what's not in 'Top Priority Game Design'. Post your ideas, visions, suggestions for the game, rules, modifications, etc.

Moderator: Oberlus

Post Reply
Message
Author
User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Undo button

#1 Post by Dilvish »

some discussion about the Continue feature has led to discussion about an undo button, which I think should be in it's own thread, so...
Morlic wrote:A player wants to move fleet A to system Alpha but mistakenly had fleet B selected which was on its way to system Beta.
The easiest way for him to correct this mistake is to press an undo button especially if he forgot what the previous order for fleet B was (e.g. fleet B is one of many colonization ships sent to a lot of different systems).
biza wrote:Thank you Morlic, that was exactly my thoughts.
OK, well, that's a rather different kind of thing, which I think could be supported but in a different kind of way. I was talking about recording orders as you go, during a turn, so that if the computer rebooted or the game crashed those orders could still be read back and repeated without the player having to make all those determinations again (a fairly rare need and not a big deal, but could be nice to have). That wouldn't really do much to support this kind of 'undo' button that you are talking about though, not particularly well anyways-- yes you could keep the full sequence of all orders (or at least all fleet movement orders) and then search for the second-most-recent move order for that particular fleet, and then perhaps just try reapplying that same original order, or better yet try to determine where in that move path you might now be and just reapply the remaining portion of it, but that seems to get a bit messy and uncertain.

I think that really if you were wanting to support an undo button then by far the best approach would be more focused on specifically saving state information which could be referenced for an undo. You could have the MapWnd keep a record related to the most recent order (or perhaps even the most recent N orders), wherein it would store all the necessary information to properly undo that order. For fleet path orders it would be the specifics of the fleet ID and preexisting path, for ship-transfer / fleet-merge orders it would be info on the fleets and ship lists, etc. I think it could even could be made to work for undoing the deletion of a production queue item, though that would probably be one of the trickier ones. Maintaining this info purely in the MapWnd would mean that the undo records would be erased at the start of each new turn and upon any savegame file load, but that seems pretty consistent with typical undo abilities to me.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Undo button

#2 Post by Geoff the Medio »

Dilvish wrote:...saving state information which could be referenced for an undo. You could have the MapWnd keep a record related to the most recent order (or perhaps even the most recent N orders), wherein it would store all the necessary information to properly undo that order.
Orders are stored in the OrderSet indexed by numbers that increment in the order (NPI) they are issued, so there doesn't need to be any storage of orders or the order in which they were issued. This info is necessarily saved when saving a game and restored when loading.
For fleet path orders it would be the specifics of the fleet ID and preexisting path
It shouldn't be difficult to add a record to a FleetMoveOrder to keep track of what the destination was before the order was executed.
...for ship-transfer / fleet-merge orders it would be info on the fleets and ship lists, etc.
It already stores the ship ids as part of the order, so would just need to keep track of the fleet they were in before the order was executed.
I think it could even could be made to work for undoing the deletion of a production queue item, though that would probably be one of the trickier ones.
ProductionQueueOrder is already a bit of a mess, and would probably be best split into ~8 distinct order types which can attempt to store the relevant queue indices and/or production queue element info necessary to undo all the variations of that order.

A bit more tricky is the reworking of the OrderSet to allow redoing orders that have been undone.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: Undo button

#3 Post by Dilvish »

Hmm, I had been thinking that for an undo button it would be simpler to simply store with the UI the info needed specifically for the undo, rather than increasing the information that gets sent back and forth to server and saved with games, but on thinking about it more I agree it does sound better to primarily rely on expanding the existing support for cancel/undo within the Order classes.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Post Reply