3 * $Id: undo.c,v 1.1 2003/12/12 10:55:30 mdw Exp $
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 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 2003/12/12 10:55:30 mdw
33 * Initial checkin. Not there yet.
37 /*----- Header files ------------------------------------------------------*/
41 /*----- Main code ---------------------------------------------------------*/
43 void undo_init(game_state *g)
45 g->u = g->r = g->m = 0;
48 void undo_begin(game_state *g)
50 undo_move *u = CREATE(undo_move);
56 void undo_cell(game_state *g, int x, int y, int c)
60 for (aa = &g->m->act; *aa; aa = &a->next) {
62 if (a->type == A_CELL && a->u.c.x == x && a->u.c.y == y) {
70 if (c == CELL(g->l, x, y)) return;
71 a = CREATE(undo_action);
77 a->u.c.c = CELL(g->l, x, y);
80 void undo_die(game_state *g, game_player *p)
82 undo_action *a = CREATE(undo_action);
90 void undo_levelf(game_state *g)
92 undo_action *a = CREATE(undo_action);
100 void undo_mask(game_state *g)
102 undo_action *a = CREATE(undo_action);
110 void undo_pmove(game_state *g)
112 undo_action *a = CREATE(undo_action);
121 void undo_switch(game_state *g)
123 undo_action *a = CREATE(undo_action);
130 static void freelist(undo_move **mm)
135 for (u = *mm; u; u = uu) {
137 for (a = u->act; a; a = aa) {
146 void undo_commit(game_state *g)
158 static int do_undo(game_state *g, undo_move **m, undo_move **mm)
169 for (a = u->act; a; a = a->next) {
173 a->u.c.c = CELL(g->l, a->u.c.x, a->u.c.y);
174 CELLSET(g->l, a->u.c.x, a->u.c.y, c);
177 a->u.p->f &= ~PF_DEAD;
199 a->u.p->f |= PF_DEAD;
217 void undo(game_state *g)
219 if (do_undo(g, &g->u, &g->r)) g->l->v--;
223 void redo(game_state *g)
225 if (do_undo(g, &g->r, &g->u)) g->l->v++;
229 void undo_free(game_state *g)
236 /*----- That's all, folks -------------------------------------------------*/