~ubuntu-branches/ubuntu/wily/sgt-puzzles/wily

« back to all changes in this revision

Viewing changes to untangle.c

  • Committer: Package Import Robot
  • Author(s): Ben Hutchings
  • Date: 2013-06-30 03:20:16 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20130630032016-v8xqt6vtg6tgs420
Tags: 9872-1
* New upstream version
  - Add an explicit -lm to the link lines in Makefile.gtk (Closes: #713476)
  - Add Undead by Steffen Bauer, an implementation of 'Haunted Mirror Maze'
  - Add Unruly by Lennard Sprong, an implementation of a puzzle usually
    called 'Tohu wa Vohu'
* Add DEP-3 headers to patches
* pearl: Require width or height to be at least 6 for Tricky
  (Closes: #667963)
* debian/watch: Update ViewVC URL regex
* Add 'sgt-' prefix to all command names and remove 'game' suffix, but
  retain symlinks under the old names (see #684193)
* Use upstream short descriptions in English manual pages and package
  description
* Update German translation, thanks to Helge Kreutzmann

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
/*
14
14
 * TODO:
15
 
 * 
16
 
 *  - Any way we can speed up redraws on GTK? Uck.
17
 
 * 
 
15
 *
 
16
 *  - This puzzle, perhaps uniquely among the collection, could use
 
17
 *    support for non-aspect-ratio-preserving resizes. This would
 
18
 *    require some sort of fairly large redesign, unfortunately (since
 
19
 *    it would invalidate the basic assumption that puzzles' size
 
20
 *    requirements are adequately expressed by a single scalar tile
 
21
 *    size), and probably complicate the rest of the puzzles' API as a
 
22
 *    result. So I'm not sure I really want to do it.
 
23
 *
18
24
 *  - It would be nice if we could somehow auto-detect a real `long
19
25
 *    long' type on the host platform and use it in place of my
20
26
 *    hand-hacked int64s. It'd be faster and more reliable.
39
45
#define SOLVEANIM_TIME 0.50F
40
46
 
41
47
enum {
 
48
    COL_SYSBACKGROUND,
42
49
    COL_BACKGROUND,
43
50
    COL_LINE,
44
51
#ifdef SHOW_CROSSINGS
147
154
    sfree(params);
148
155
}
149
156
 
150
 
static game_params *dup_params(game_params *params)
 
157
static game_params *dup_params(const game_params *params)
151
158
{
152
159
    game_params *ret = snew(game_params);
153
160
    *ret = *params;                    /* structure copy */
159
166
    params->n = atoi(string);
160
167
}
161
168
 
162
 
static char *encode_params(game_params *params, int full)
 
169
static char *encode_params(const game_params *params, int full)
163
170
{
164
171
    char buf[80];
165
172
 
168
175
    return dupstr(buf);
169
176
}
170
177
 
171
 
static config_item *game_configure(game_params *params)
 
178
static config_item *game_configure(const game_params *params)
172
179
{
173
180
    config_item *ret;
174
181
    char buf[80];
189
196
    return ret;
190
197
}
191
198
 
192
 
static game_params *custom_params(config_item *cfg)
 
199
static game_params *custom_params(const config_item *cfg)
193
200
{
194
201
    game_params *ret = snew(game_params);
195
202
 
198
205
    return ret;
199
206
}
200
207
 
201
 
static char *validate_params(game_params *params, int full)
 
208
static char *validate_params(const game_params *params, int full)
202
209
{
203
210
    if (params->n < 4)
204
211
        return "Number of points must be at least four";
484
491
    }
485
492
}
486
493
 
487
 
static char *new_game_desc(game_params *params, random_state *rs,
 
494
static char *new_game_desc(const game_params *params, random_state *rs,
488
495
                           char **aux, int interactive)
489
496
{
490
497
    int n = params->n, i;
727
734
    return ret;
728
735
}
729
736
 
730
 
static char *validate_desc(game_params *params, char *desc)
 
737
static char *validate_desc(const game_params *params, const char *desc)
731
738
{
732
739
    int a, b;
733
740
 
796
803
        state->completed = TRUE;
797
804
}
798
805
 
799
 
static game_state *new_game(midend *me, game_params *params, char *desc)
 
806
static game_state *new_game(midend *me, const game_params *params,
 
807
                            const char *desc)
800
808
{
801
809
    int n = params->n;
802
810
    game_state *state = snew(game_state);
835
843
    return state;
836
844
}
837
845
 
838
 
static game_state *dup_game(game_state *state)
 
846
static game_state *dup_game(const game_state *state)
839
847
{
840
848
    int n = state->params.n;
841
849
    game_state *ret = snew(game_state);
872
880
    sfree(state);
873
881
}
874
882
 
875
 
static char *solve_game(game_state *state, game_state *currstate,
876
 
                        char *aux, char **error)
 
883
static char *solve_game(const game_state *state, const game_state *currstate,
 
884
                        const char *aux, char **error)
877
885
{
878
886
    int n = state->params.n;
879
887
    int matrix[4];
1018
1026
    return ret;
1019
1027
}
1020
1028
 
1021
 
static int game_can_format_as_text_now(game_params *params)
 
1029
static int game_can_format_as_text_now(const game_params *params)
1022
1030
{
1023
1031
    return TRUE;
1024
1032
}
1025
1033
 
1026
 
static char *game_text_format(game_state *state)
 
1034
static char *game_text_format(const game_state *state)
1027
1035
{
1028
1036
    return NULL;
1029
1037
}
1036
1044
    float anim_length;
1037
1045
};
1038
1046
 
1039
 
static game_ui *new_ui(game_state *state)
 
1047
static game_ui *new_ui(const game_state *state)
1040
1048
{
1041
1049
    game_ui *ui = snew(game_ui);
1042
1050
    ui->dragpoint = -1;
1049
1057
    sfree(ui);
1050
1058
}
1051
1059
 
1052
 
static char *encode_ui(game_ui *ui)
 
1060
static char *encode_ui(const game_ui *ui)
1053
1061
{
1054
1062
    return NULL;
1055
1063
}
1056
1064
 
1057
 
static void decode_ui(game_ui *ui, char *encoding)
 
1065
static void decode_ui(game_ui *ui, const char *encoding)
1058
1066
{
1059
1067
}
1060
1068
 
1061
 
static void game_changed_state(game_ui *ui, game_state *oldstate,
1062
 
                               game_state *newstate)
 
1069
static void game_changed_state(game_ui *ui, const game_state *oldstate,
 
1070
                               const game_state *newstate)
1063
1071
{
1064
1072
    ui->dragpoint = -1;
1065
1073
    ui->just_moved = ui->just_dragged;
1072
1080
    long *x, *y;
1073
1081
};
1074
1082
 
1075
 
static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
1076
 
                            int x, int y, int button)
 
1083
static char *interpret_move(const game_state *state, game_ui *ui,
 
1084
                            const game_drawstate *ds,
 
1085
                            int x, int y, int button)
1077
1086
{
1078
1087
    int n = state->params.n;
1079
1088
 
1145
1154
    return NULL;
1146
1155
}
1147
1156
 
1148
 
static game_state *execute_move(game_state *state, char *move)
 
1157
static game_state *execute_move(const game_state *state, const char *move)
1149
1158
{
1150
1159
    int n = state->params.n;
1151
1160
    int p, k;
1184
1193
 * Drawing routines.
1185
1194
 */
1186
1195
 
1187
 
static void game_compute_size(game_params *params, int tilesize,
1188
 
                              int *x, int *y)
 
1196
static void game_compute_size(const game_params *params, int tilesize,
 
1197
                              int *x, int *y)
1189
1198
{
1190
1199
    *x = *y = COORDLIMIT(params->n) * tilesize;
1191
1200
}
1192
1201
 
1193
1202
static void game_set_size(drawing *dr, game_drawstate *ds,
1194
 
                          game_params *params, int tilesize)
 
1203
                          const game_params *params, int tilesize)
1195
1204
{
1196
1205
    ds->tilesize = tilesize;
1197
1206
}
1200
1209
{
1201
1210
    float *ret = snewn(3 * NCOLOURS, float);
1202
1211
 
1203
 
    frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
 
1212
    /*
 
1213
     * COL_BACKGROUND is what we use as the normal background colour.
 
1214
     * Unusually, though, it isn't colour #0: COL_SYSBACKGROUND, a bit
 
1215
     * darker, takes that place. This means that if the user resizes
 
1216
     * an Untangle window so as to change its aspect ratio, the
 
1217
     * still-square playable area will be distinguished from the dead
 
1218
     * space around it.
 
1219
     */
 
1220
    game_mkhighlight(fe, ret, COL_BACKGROUND, -1, COL_SYSBACKGROUND);
1204
1221
 
1205
1222
    ret[COL_LINE * 3 + 0] = 0.0F;
1206
1223
    ret[COL_LINE * 3 + 1] = 0.0F;
1240
1257
    return ret;
1241
1258
}
1242
1259
 
1243
 
static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
 
1260
static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
1244
1261
{
1245
1262
    struct game_drawstate *ds = snew(struct game_drawstate);
1246
1263
    int i;
1274
1291
    return ret;
1275
1292
}
1276
1293
 
1277
 
static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
1278
 
                        game_state *state, int dir, game_ui *ui,
1279
 
                        float animtime, float flashtime)
 
1294
static void game_redraw(drawing *dr, game_drawstate *ds,
 
1295
                        const game_state *oldstate, const game_state *state,
 
1296
                        int dir, const game_ui *ui,
 
1297
                        float animtime, float flashtime)
1280
1298
{
1281
1299
    int w, h;
1282
1300
    edge *e;
1391
1409
    draw_update(dr, 0, 0, w, h);
1392
1410
}
1393
1411
 
1394
 
static float game_anim_length(game_state *oldstate, game_state *newstate,
1395
 
                              int dir, game_ui *ui)
 
1412
static float game_anim_length(const game_state *oldstate,
 
1413
                              const game_state *newstate, int dir, game_ui *ui)
1396
1414
{
1397
1415
    if (ui->just_moved)
1398
1416
        return 0.0F;
1403
1421
    return ui->anim_length;
1404
1422
}
1405
1423
 
1406
 
static float game_flash_length(game_state *oldstate, game_state *newstate,
1407
 
                               int dir, game_ui *ui)
 
1424
static float game_flash_length(const game_state *oldstate,
 
1425
                               const game_state *newstate, int dir, game_ui *ui)
1408
1426
{
1409
1427
    if (!oldstate->completed && newstate->completed &&
1410
1428
        !oldstate->cheated && !newstate->cheated)
1412
1430
    return 0.0F;
1413
1431
}
1414
1432
 
1415
 
static int game_status(game_state *state)
 
1433
static int game_status(const game_state *state)
1416
1434
{
1417
1435
    return state->completed ? +1 : 0;
1418
1436
}
1419
1437
 
1420
 
static int game_timing_state(game_state *state, game_ui *ui)
 
1438
static int game_timing_state(const game_state *state, game_ui *ui)
1421
1439
{
1422
1440
    return TRUE;
1423
1441
}
1424
1442
 
1425
 
static void game_print_size(game_params *params, float *x, float *y)
 
1443
static void game_print_size(const game_params *params, float *x, float *y)
1426
1444
{
1427
1445
}
1428
1446
 
1429
 
static void game_print(drawing *dr, game_state *state, int tilesize)
 
1447
static void game_print(drawing *dr, const game_state *state, int tilesize)
1430
1448
{
1431
1449
}
1432
1450