5 * Management of undo records
7 * (c) 2003 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of XOR.
14 * XOR is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * XOR is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with XOR; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
33 /*----- Main code ---------------------------------------------------------*/
35 void undo_init(game_state
*g
)
37 g
->u
= g
->r
= g
->m
= 0;
40 void undo_begin(game_state
*g
)
42 undo_move
*u
= CREATE(undo_move
);
48 void undo_cell(game_state
*g
, int x
, int y
, int c
)
52 for (aa
= &g
->m
->act
; *aa
; aa
= &a
->next
) {
54 if (a
->type
== A_CELL
&& a
->u
.c
.x
== x
&& a
->u
.c
.y
== y
) {
62 if (c
== CELL(g
->l
, x
, y
)) return;
63 a
= CREATE(undo_action
);
69 a
->u
.c
.c
= CELL(g
->l
, x
, y
);
72 void undo_die(game_state
*g
, game_player
*p
)
74 undo_action
*a
= CREATE(undo_action
);
82 void undo_levelf(game_state
*g
)
84 undo_action
*a
= CREATE(undo_action
);
92 void undo_mask(game_state
*g
)
94 undo_action
*a
= CREATE(undo_action
);
102 void undo_pmove(game_state
*g
)
104 undo_action
*a
= CREATE(undo_action
);
113 void undo_switch(game_state
*g
)
115 undo_action
*a
= CREATE(undo_action
);
122 static void freelist(undo_move
**mm
)
127 for (u
= *mm
; u
; u
= uu
) {
129 for (a
= u
->act
; a
; a
= aa
) {
138 void undo_commit(game_state
*g
)
150 static int do_undo(game_state
*g
, undo_move
**m
, undo_move
**mm
)
161 for (a
= u
->act
; a
; a
= a
->next
) {
165 a
->u
.c
.c
= CELL(g
->l
, a
->u
.c
.x
, a
->u
.c
.y
);
166 CELLSET(g
->l
, a
->u
.c
.x
, a
->u
.c
.y
, c
);
169 a
->u
.p
->f
&= ~PF_DEAD
;
189 ui_track(g
->p
->u
, x
, y
);
192 a
->u
.p
->f
|= PF_DEAD
;
210 void undo(game_state
*g
)
212 if (do_undo(g
, &g
->u
, &g
->r
)) g
->l
->v
--;
216 void redo(game_state
*g
)
218 if (do_undo(g
, &g
->r
, &g
->u
)) g
->l
->v
++;
222 void undo_free(game_state
*g
)
229 /*----- That's all, folks -------------------------------------------------*/