glotski-0.2/ 40775 764 764 0 7036016563 13001 5ustar oxymoronoxymoronglotski-0.2/canvas.c100664 764 764 101604 7036020167 14552 0ustar oxymoronoxymoron#include #include #include "glotski.h" #include "icon.xpm" #define MYGRAY 164 #define LIGHTEN(a) (255-(255-a)/2) #define DARKEN(a) (a/2) #define GNOMEUIINFO_ITEM_STOCK_DATA_(label, tooltip, cb, data, stock_id) { GNOME_APP_UI_ITEM, label, tooltip, (gpointer)cb, data, NULL, GNOME_APP_PIXMAP_STOCK, stock_id, 0, (GdkModifierType) 0, NULL } #define GNOMEUIINFO_TOGGLEITEM_NONE_DATA_(label, cb, data) { GNOME_APP_UI_TOGGLEITEM, label, NULL, (gpointer)cb, data, NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, (GdkModifierType) 0, NULL } static void select_file(GtkWidget *widget, pair *mypair); /* The canvas drag logic was originally based on Havoc Pennington's code from his GNOME book; however, it has been modified extensively. */ /* This shouldn't be necessary, but the rectangle item has slightly different dimensions than the equivalent polygon item, so it can look ugly. */ #define UGLY_RECTANGLE #ifdef UGLY_RECTANGLE void drawrect(GnomeCanvasGroup *group, double x1, double y1, double x2, double y2, int r, int g, int b) { GnomeCanvasPoints *ptmp = gnome_canvas_points_new(4); ptmp->coords[0] = x1; ptmp->coords[1] = y1; ptmp->coords[2] = x1; ptmp->coords[3] = y2; ptmp->coords[4] = x2; ptmp->coords[5] = y2; ptmp->coords[6] = x2; ptmp->coords[7] = y1; gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", ptmp, "fill_color_rgba", GNOME_CANVAS_COLOR(r, g, b), "width_pixels", 0, NULL); } #endif void textdisp(char *text) { gnome_ok_dialog(N_(text)); } void errordisp(char *text) { g_error(_(text)); } void moveelement(glot *myglot, int xloc, int yloc) { double xblock = myglot->parent->usize[X]*myglot->parent->zoom[X]; double yblock = myglot->parent->usize[Y]*myglot->parent->zoom[Y]; double visx = xblock*(double)myglot->loc[X]; double visy = yblock*(double)myglot->loc[Y]; double newvisx = xblock*(double)xloc; double newvisy = xblock*(double)yloc; gnome_canvas_item_move((GnomeCanvasItem *)myglot->element, newvisx - visx, newvisy - visy); glotplace(myglot, xloc, yloc, TRUE); } static gint glot_event(GnomeCanvasItem *glotitem, GdkEvent *event, glot *myglot) { static double visx, visy; /* The visible X and Y coords */ static int ipropx, ipropy; /* The proper (where item is located) X and Y */ /* Directions tested from propx and propy */ int inewx, inewy; GdkCursor *arrow; static int dragging; double mousex, mousey; /* Where the mouse is */ double newvisx, newvisy; /* Where the piece will be */ double dx, dy; static double anchorx, anchory; static int origx, origy; double xblocksize = myglot->parent->usize[X]*myglot->parent->zoom[X]; double yblocksize = myglot->parent->usize[Y]*myglot->parent->zoom[Y]; int valid = TRUE; /* Actually draggable? */ mousex = event->button.x; mousey = event->button.y; gnome_canvas_item_w2i(glotitem->parent, &mousex, &mousey); switch (event->type) { case GDK_BUTTON_PRESS: switch (myglot->type) { case IMMOBILE: arrow = gdk_cursor_new(GDK_X_CURSOR); valid = FALSE; break; case HORIZONTAL: arrow = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); break; case VERTICAL: arrow = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW); break; case BIMOBILE: arrow = gdk_cursor_new(GDK_FLEUR); break; default: arrow = NULL; break; } gnome_canvas_item_grab(glotitem, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, arrow, event->button.time); ipropx = origx = myglot->loc[X]; ipropy = origy = myglot->loc[Y]; visx = anchorx = mousex; visy = anchory = mousey; gdk_cursor_destroy(arrow); if (valid) { dragging = TRUE; if (!(myglot->parent->move && !myglot->parent->move->next && myglot == myglot->parent->move->myglot && !myglot->parent->move->goalsat)) { if (myglot->parent->move && myglot->parent->move->next) { deletemove(myglot->parent->move->next); myglot->parent->move->next = NULL; } makemove(myglot->parent); myglot->parent->move->startloc[X] = myglot->loc[X]; myglot->parent->move->startloc[Y] = myglot->loc[Y]; myglot->parent->move->myglot = myglot; myglot->parent->nummoves++; updatestatus(myglot->parent); } } break; case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { /* First, resolve the new proper location of the piece */ inewx = (COMPAT(myglot, LEFT)) ? (int)((mousex-anchorx) / xblocksize) + origx : origx; inewy = (COMPAT(myglot, UP)) ? (int)((mousey-anchory) / xblocksize) + origy : origy; if (inewx < 0) inewx = 0; if (inewx + myglot->size[X] >= myglot->parent->size[X]) inewx = myglot->parent->size[X]-myglot->size[X]; if (inewy < 0) inewy = 0; if (inewy + myglot->size[Y] >= myglot->parent->size[Y]) inewy = myglot->parent->size[Y]-myglot->size[Y]; /* if (ipropx != inewx || ipropy != inewy) printf("Attempting move from (%d, %d) [(%d, %d)] to (%d, %d)\n", ipropx, ipropy, myglot->loc[X], myglot->loc[Y], inewx, inewy); */ while (ipropx != inewx && /* First, attempts proper X location */ glotmove(myglot, XDIR(inewx, ipropx), TRUE)) { (inewx < ipropx) ? ipropx-- : ipropx++; } while (ipropy != inewy && /* Then, attempts proper Y location */ glotmove(myglot, YDIR(inewy, ipropy), TRUE)) { (inewy < ipropy) ? ipropy-- : ipropy++; } if (ipropx != myglot->loc[X] || ipropy != myglot->loc[Y]) printf("Drag error: I think (%d, %d), should be (%d, %d)\n", ipropx, ipropy, myglot->loc[X], myglot->loc[Y]); /* If the above occurs, that is bad. Next line should be redundant. */ ipropx = myglot->loc[X]; ipropy = myglot->loc[Y]; newvisx = (ipropx-origx)*xblocksize + anchorx; newvisy = (ipropy-origy)*yblocksize + anchory; /* Next, determine whether it can move into the new partial domain */ if (ipropx == inewx && newvisx != mousex && glotmove(myglot, XDIR(mousex,newvisx), FALSE)) { if (ipropy == inewy && newvisy != mousey && glotmove(myglot, YDIR(mousey, newvisy), FALSE) && glotplace(myglot, ipropx + ((mousex < newvisx) ? -1 : 1), ipropy + ((mousey < newvisy) ? -1 : 1), FALSE)) { newvisx = mousex; newvisy = mousey; } else newvisx = mousex; } else if (ipropy == inewy && newvisy != mousey && glotmove(myglot, YDIR(mousey, newvisy),FALSE)) newvisy = mousey; /* Finally, perform the move */ if ((newvisx != visx) || (newvisy != visy)) { gnome_canvas_item_move(glotitem, newvisx - visx, newvisy - visy); visx = newvisx; visy = newvisy; } } break; case GDK_BUTTON_RELEASE: gnome_canvas_item_ungrab(glotitem, event->button.time); dragging = FALSE; /* Must resolve final location */ dx = (visx - (double)((ipropx-origx)*xblocksize + anchorx))/ (double)(xblocksize); if (dx * dx > 0.25) glotmove(myglot, XDIR((int)visx, (ipropx-origx)*xblocksize + anchorx), TRUE); dy = (visy - (double)((ipropy-origy)*yblocksize + anchory))/ (double)(yblocksize); if (dy * dy > 0.25) glotmove(myglot, YDIR((int)visy, (ipropy-origy)*yblocksize + anchory), TRUE); inewx = (COMPAT(myglot, LEFT)) ? (int)((mousex-anchorx) / xblocksize) + origx : origx; inewy = (COMPAT(myglot, UP)) ? (int)((mousey-anchory) / xblocksize) + origy : origy; newvisx = (myglot->loc[X]-origx)*xblocksize + anchorx; newvisy = (myglot->loc[Y]-origy)*yblocksize + anchory; gnome_canvas_item_move(glotitem, newvisx - visx, newvisy - visy); visx = newvisx; visy = newvisy; if (myglot->parent->move->startloc[X] == myglot->loc[X] && myglot->parent->move->startloc[Y] == myglot->loc[Y]) { popmove(&(myglot->parent->move)); if (myglot->parent->move && myglot->parent->move->next) { fprintf(stderr, "glotski: Corrupt movelist\n"); exit(1); } myglot->parent->nummoves--; updatestatus(myglot->parent); } else { myglot->parent->move->endloc[X] = myglot->loc[X]; myglot->parent->move->endloc[Y] = myglot->loc[Y]; } if (goalequiv(myglot->parent)) { myglot->parent->move->goalsat = TRUE; myglot->parent->state++; updatestatus(myglot->parent); if (myglot->parent->mygoal->next) { myglot->parent->mygoal = myglot->parent->mygoal->next; redrawgoal(myglot->parent); } else if (!myglot->parent->won) { textdisp("You won!"); myglot->parent->won = TRUE; } } break; default: break; } return FALSE; } static void goalgen(GnomeCanvasGroup *group, level *mylevel) { /* Draw goalwin */ int x, y; double xblock = mylevel->usize[X]*mylevel->gzoom[X]; double yblock = mylevel->usize[Y]*mylevel->gzoom[Y]; glot *myglot; group = GNOME_CANVAS_GROUP (gnome_canvas_item_new(group, gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL)); /* OK to use rectangles because only using rectangles */ for (x = 0; x < mylevel->mygoal->size[X]; x++) for (y = 0; y < mylevel->mygoal->size[Y]; y++) { if (!(myglot = LOOKUP(mylevel->mygoal, x, y))) { gnome_canvas_item_new(group, gnome_canvas_rect_get_type(), "x1", (double)(x)*xblock, "y1", (double)(y)*yblock, "x2", (double)(x+1)*xblock, "y2", (double)(y+1)*yblock, "fill_color_rgba", GNOME_CANVAS_COLOR(MYGRAY, MYGRAY, MYGRAY), "width_pixels", 0, NULL); } else { gnome_canvas_item_new(group, gnome_canvas_rect_get_type(), "x1", (double)(x)*xblock, "y1", (double)(y)*yblock, "x2", (double)(x+1)*xblock, "y2", (double)(y+1)*yblock, "fill_color_rgba", GNOME_CANVAS_COLOR(myglot->red, myglot->green, myglot->blue), "outline_color_rgba", GNOME_CANVAS_COLOR(0,0,0), "width_pixels", 2, NULL); } } } static void glotgen(GnomeCanvasGroup *group, glot *myglot) { int x, y; int neighbor[4]; /* is neighbor present in direction */ /* dirtype order: left, up, right, down */ double xblock = myglot->parent->usize[X]*myglot->parent->zoom[X]; double yblock = myglot->parent->usize[Y]*myglot->parent->zoom[Y]; double xdelta = (xblock/6.0)*myglot->parent->scale[X]* myglot->parent->zoom[X]; double ydelta = (yblock/6.0)*myglot->parent->scale[Y]* myglot->parent->zoom[Y]; double xloc = (double)myglot->loc[X]; double yloc = (double)myglot->loc[Y]; GnomeCanvasPoints *side[4]; /* Side highights */ /* Each highlight has 4 points */ /* The first and fourth points are anchored; depending on the presence of neighbors clockwise (2) or counterclockwise (3), the other two points may change (by delta) */ GnomeCanvasPoints *ptmp; /* For generating diagonal in-bevels */ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new(group, gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL)); for (x = 0; x < myglot->size[X]; x++) for (y = 0; y < myglot->size[Y]; y++) { neighbor[UP] = neighbor[DOWN] = neighbor[LEFT] = neighbor[RIGHT] = -1; side[UP] = side[DOWN] = side[LEFT] = side[RIGHT] = NULL; /* Building phase */ /* Creation phase: [L]ower/[U]pper [L]eft/[R]ight */ if (LOOKUP(myglot, x, y)) { if (x == 0 || !LOOKUP(myglot, x-1, y)) { neighbor[LEFT] = 0; side[LEFT] = gnome_canvas_points_new(4); side[LEFT]->coords[0] = (x+xloc)*xblock; /* UL */ side[LEFT]->coords[1] = (y+yloc)*yblock; side[LEFT]->coords[2] = side[LEFT]->coords[0]+xdelta; /* UR */ side[LEFT]->coords[3] = side[LEFT]->coords[1]; side[LEFT]->coords[4] = side[LEFT]->coords[2]; /* LR */ side[LEFT]->coords[5] = side[LEFT]->coords[3]+yblock; side[LEFT]->coords[6] = side[LEFT]->coords[0]; /* LL */ side[LEFT]->coords[7] = side[LEFT]->coords[5]; } else neighbor[LEFT] = 1; if (y == 0 || !LOOKUP(myglot, x, y-1)) { neighbor[UP] = 0; side[UP] = gnome_canvas_points_new(4); side[UP]->coords[0] = (x+xloc+1.0)*xblock; /* UR */ side[UP]->coords[1] = (y+yloc)*yblock; side[UP]->coords[2] = side[UP]->coords[0]; /* LR */ side[UP]->coords[3] = side[UP]->coords[1]+ydelta; side[UP]->coords[4] = side[UP]->coords[2]-xblock; /* LL */ side[UP]->coords[5] = side[UP]->coords[3]; side[UP]->coords[6] = side[UP]->coords[4]; /* UL */ side[UP]->coords[7] = side[UP]->coords[1]; } else neighbor[UP] = 1; if (x == myglot->size[X]-1 || !LOOKUP(myglot, x+1, y)) { neighbor[RIGHT] = 0; side[RIGHT] = gnome_canvas_points_new(4); side[RIGHT]->coords[0] = (x+xloc+1.0)*xblock; /* LR */ side[RIGHT]->coords[1] = (y+yloc+1.0)*yblock; side[RIGHT]->coords[2] = side[RIGHT]->coords[0]-xdelta; /* LL */ side[RIGHT]->coords[3] = side[RIGHT]->coords[1]; side[RIGHT]->coords[4] = side[RIGHT]->coords[2]; /* UL */ side[RIGHT]->coords[5] = side[RIGHT]->coords[3]-yblock; side[RIGHT]->coords[6] = side[RIGHT]->coords[0]; /* UR */ side[RIGHT]->coords[7] = side[RIGHT]->coords[5]; } else neighbor[RIGHT] = 1; if (y == myglot->size[Y]-1 || !LOOKUP(myglot, x, y+1)) { neighbor[DOWN] = 0; side[DOWN] = gnome_canvas_points_new(4); side[DOWN]->coords[0] = (x+xloc)*xblock; /* LL */ side[DOWN]->coords[1] = (y+yloc+1.0)*yblock; side[DOWN]->coords[2] = side[DOWN]->coords[0]; /* UL */ side[DOWN]->coords[3] = side[DOWN]->coords[1]-ydelta; side[DOWN]->coords[4] = side[DOWN]->coords[2]+xblock; /* UR */ side[DOWN]->coords[5] = side[DOWN]->coords[3]; side[DOWN]->coords[6] = side[DOWN]->coords[4]; /* LR */ side[DOWN]->coords[7] = side[DOWN]->coords[1]; } else neighbor[DOWN] = 1; /* Adjustment phase */ if (!neighbor[LEFT] && !neighbor[UP]) { side[LEFT]->coords[3] += ydelta; side[UP]->coords[4] += xdelta; } if (!neighbor[UP] && !neighbor[RIGHT]) { side[UP]->coords[2] -= xdelta; side[RIGHT]->coords[5] += ydelta; } if (!neighbor[RIGHT] && !neighbor[DOWN]) { side[RIGHT]->coords[3] -= ydelta; side[DOWN]->coords[4] -= xdelta; } if (!neighbor[DOWN] && !neighbor[LEFT]) { side[DOWN]->coords[2] += xdelta; side[LEFT]->coords[5] -= ydelta; } /* Drawing phase */ /* Simple drawing phase */ #ifdef UGLY_RECTANGLE drawrect(group, (x+xloc)*xblock, (y+yloc)*yblock, (x+xloc+1.0)*xblock, (y+yloc+1.0)*yblock, myglot->red, myglot->green, myglot->blue); #else gnome_canvas_item_new(group, gnome_canvas_rect_get_type(), "x1", (x+xloc)*xblock, "y1", (y+yloc)*yblock, "x2", (x+xloc+1.0)*xblock, "y2", (y+yloc+1.0)*yblock, "fill_color_rgba", GNOME_CANVAS_COLOR(myglot->red, myglot->green, myglot->blue), "width_pixels", 0, NULL); #endif /* Outer bevel drawing phase */ if (!neighbor[LEFT]) gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", side[LEFT], "fill_color_rgba", GNOME_CANVAS_COLOR(LIGHTEN(myglot->red), LIGHTEN(myglot->green), LIGHTEN(myglot->blue)), "width_pixels", 0, NULL); if (!neighbor[UP]) gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", side[UP], "fill_color_rgba", GNOME_CANVAS_COLOR(LIGHTEN(myglot->red), LIGHTEN(myglot->green), LIGHTEN(myglot->blue)), "width_pixels", 0, NULL); if (!neighbor[RIGHT]) gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", side[RIGHT], "fill_color_rgba", GNOME_CANVAS_COLOR(DARKEN(myglot->red), DARKEN(myglot->green), DARKEN(myglot->blue)), "width_pixels", 0, NULL); if (!neighbor[DOWN]) gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", side[DOWN], "fill_color_rgba", GNOME_CANVAS_COLOR(DARKEN(myglot->red), DARKEN(myglot->green), DARKEN(myglot->blue)), "width_pixels", 0, NULL); /* Center bevel drawing phase */ if (neighbor[UP] && neighbor[LEFT] && !LOOKUP(myglot, x-1, y-1)) { #ifdef UGLY_RECTANGLE drawrect(group, (x+xloc)*xblock, (y+yloc)*yblock, (x+xloc)*xblock+xdelta, (y+yloc)*yblock+ydelta, LIGHTEN(myglot->red), LIGHTEN(myglot->green), LIGHTEN(myglot->blue)); #else gnome_canvas_item_new(group, gnome_canvas_rect_get_type(), "x1", (x+xloc)*xblock, "y1", (y+yloc)*yblock, "x2", (x+xloc)*xblock+xdelta, "y2", (y+yloc)*yblock+ydelta, "fill_color_rgba", GNOME_CANVAS_COLOR(LIGHTEN(myglot->red), LIGHTEN(myglot->green), LIGHTEN(myglot->blue)), "width_pixels", 0, NULL); #endif } if (neighbor[UP] && neighbor[RIGHT] && !LOOKUP(myglot, x+1, y-1)) { ptmp = gnome_canvas_points_new(3); ptmp->coords[0] = (x+xloc+1.0)*xblock; ptmp->coords[1] = (y+yloc)*yblock; ptmp->coords[2] = ptmp->coords[0]-xdelta; ptmp->coords[3] = ptmp->coords[1]; ptmp->coords[4] = ptmp->coords[2]; ptmp->coords[5] = ptmp->coords[1]+ydelta; gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", ptmp, "fill_color_rgba", GNOME_CANVAS_COLOR(DARKEN(myglot->red), DARKEN(myglot->green), DARKEN(myglot->blue)), "width_pixels", 0, NULL); ptmp = gnome_canvas_points_new(3); ptmp->coords[0] = (x+xloc+1.0)*xblock; ptmp->coords[1] = (y+yloc)*yblock; ptmp->coords[2] = ptmp->coords[0]; ptmp->coords[3] = ptmp->coords[1]+ydelta; ptmp->coords[4] = ptmp->coords[2]-xdelta; ptmp->coords[5] = ptmp->coords[3]; gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", ptmp, "fill_color_rgba", GNOME_CANVAS_COLOR(LIGHTEN(myglot->red), LIGHTEN(myglot->green), LIGHTEN(myglot->blue)), "width_pixels", 0, NULL); } if (neighbor[DOWN] && neighbor[RIGHT] && !LOOKUP(myglot, x+1, y+1)) { #ifdef UGLY_RECTANGLE drawrect(group, (x+xloc+1.0)*xblock-xdelta, (y+yloc+1.0)*yblock-ydelta, (x+xloc+1.0)*xblock, (y+yloc+1.0)*yblock, DARKEN(myglot->red), DARKEN(myglot->green), DARKEN(myglot->blue)); #else gnome_canvas_item_new(group, gnome_canvas_rect_get_type(), "x1", (x+xloc+1.0)*xblock-xdelta, "y1", (y+yloc+1.0)*yblock-ydelta, "x2", (x+xloc+1.0)*xblock, "y2", (y+yloc+1.0)*yblock, "fill_color_rgba", GNOME_CANVAS_COLOR(DARKEN(myglot->red), DARKEN(myglot->green), DARKEN(myglot->blue)), "width_pixels", 0, NULL); #endif } if (neighbor[DOWN] && neighbor[LEFT] && !LOOKUP(myglot, x-1, y+1)) { ptmp = gnome_canvas_points_new(3); ptmp->coords[0] = (x+xloc)*xblock; ptmp->coords[1] = (y+yloc+1.0)*yblock; ptmp->coords[2] = ptmp->coords[0]; ptmp->coords[3] = ptmp->coords[1]-ydelta; ptmp->coords[4] = ptmp->coords[2]+xdelta; ptmp->coords[5] = ptmp->coords[3]; gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", ptmp, "fill_color_rgba", GNOME_CANVAS_COLOR(DARKEN(myglot->red), DARKEN(myglot->green), DARKEN(myglot->blue)), "width_pixels", 0, NULL); ptmp = gnome_canvas_points_new(3); ptmp->coords[0] = (x+xloc)*xblock; ptmp->coords[1] = (y+yloc+1.0)*yblock; ptmp->coords[2] = ptmp->coords[0]+xdelta; ptmp->coords[3] = ptmp->coords[1]; ptmp->coords[4] = ptmp->coords[2]; ptmp->coords[5] = ptmp->coords[1]-ydelta; gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", ptmp, "fill_color_rgba", GNOME_CANVAS_COLOR(LIGHTEN(myglot->red), LIGHTEN(myglot->green), LIGHTEN(myglot->blue)), "width_pixels", 0, NULL); } } } myglot->element = (void *)GNOME_CANVAS_ITEM(group); gtk_signal_connect(GTK_OBJECT(GNOME_CANVAS_ITEM(group)), "event", (GtkSignalFunc)glot_event, myglot); } static void makebk(GnomeCanvasGroup *group, level *mylevel) { int x, y; double x1, y1, x2, y2; double xblock = mylevel->usize[X]*mylevel->zoom[X]; double yblock = mylevel->usize[Y]*mylevel->zoom[Y]; double xdelta = (xblock/12.0)*mylevel->scale[X]*mylevel->zoom[X]; double ydelta = (yblock/12.0)*mylevel->scale[Y]*mylevel->zoom[Y]; GnomeCanvasPoints *ulpoints, *lrpoints; group = GNOME_CANVAS_GROUP (gnome_canvas_item_new(group, gnome_canvas_group_get_type(), "x", 0.0, "y", 0.0, NULL)); for (y = 0; y < mylevel->size[Y]; y++) for (x = 0; x < mylevel->size[X]; x++) { x1 = (double)(x)*xblock; y1 = (double)(y)*yblock; x2 = (double)(x+1)*xblock; y2 = (double)(y+1)*yblock; ulpoints = gnome_canvas_points_new(5); /* Upper left */ ulpoints->coords[0] = x1; ulpoints->coords[1] = y1; ulpoints->coords[2] = x1; ulpoints->coords[3] = y2; ulpoints->coords[4] = x1+xdelta; ulpoints->coords[5] = y2-ydelta; ulpoints->coords[6] = x2-xdelta; ulpoints->coords[7] = y1+ydelta; ulpoints->coords[8] = x2; ulpoints->coords[9] = y1; gnome_canvas_item_new(group, /* Upper left triangle */ gnome_canvas_polygon_get_type(), "points", ulpoints, "fill_color_rgba", GNOME_CANVAS_COLOR(LIGHTEN(MYGRAY), LIGHTEN(MYGRAY), LIGHTEN(MYGRAY)), "width_pixels", 0, NULL); lrpoints = gnome_canvas_points_new(5); /* Lower right */ lrpoints->coords[0] = x2; lrpoints->coords[1] = y2; lrpoints->coords[2] = x1; lrpoints->coords[3] = y2; lrpoints->coords[4] = ulpoints->coords[4]; lrpoints->coords[5] = ulpoints->coords[5]; lrpoints->coords[6] = ulpoints->coords[6]; lrpoints->coords[7] = ulpoints->coords[7]; lrpoints->coords[8] = x2; lrpoints->coords[9] = y1; gnome_canvas_item_new(group, gnome_canvas_polygon_get_type(), "points", lrpoints, "fill_color_rgba", GNOME_CANVAS_COLOR(DARKEN(MYGRAY), DARKEN(MYGRAY), DARKEN(MYGRAY)), "width_pixels", 0, NULL); #ifdef UGLY_RECTANGLE drawrect(group, x1+xdelta, y1+ydelta, x2-xdelta, y2-ydelta, MYGRAY, MYGRAY, MYGRAY); #else gnome_canvas_item_new(group, gnome_canvas_rect_get_type(), "x1", x1+xdelta, "y1", y1+ydelta, "x2", x2-xdelta, "y2", y2-ydelta, "fill_color_rgba", GNOME_CANVAS_COLOR(MYGRAY, MYGRAY, MYGRAY), "width_pixels", 0, NULL); #endif } } static void about_cb(GtkWidget* widget, GtkWidget *app) { static GtkWidget *dialog = NULL; if (dialog != NULL) { g_assert(GTK_WIDGET_REALIZED(dialog)); gdk_window_show(dialog->window); gdk_window_raise(dialog->window); } else { const gchar *authors[] = { "Martin Hock ", NULL }; dialog = gnome_about_new (_("Glotski"), GLOTVER, "(C) 1999-2000 Martin Hock", authors, _("Drag the blocks around to reach a goal."), NULL); gtk_signal_connect(GTK_OBJECT(dialog), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog); gnome_dialog_set_parent(GNOME_DIALOG(dialog), GTK_WINDOW(app)); gtk_widget_show(dialog); } } static void cancel_file(GtkWidget *widget, level **mylevel) { if (!(*mylevel)) gtk_main_quit(); } static void open_cb(GtkWidget *widget, level **mylevel) { static pair mypair; GtkWidget *fselect = gtk_file_selection_new("Select level file"); mypair.a = (void *)fselect; mypair.b = (void *)mylevel; gtk_file_selection_set_filename(GTK_FILE_SELECTION(fselect), LEVELPATH); gtk_file_selection_complete(GTK_FILE_SELECTION(fselect), "*.lev"); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fselect)->ok_button), "clicked", GTK_SIGNAL_FUNC(select_file), &mypair); gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fselect)->cancel_button), "clicked", GTK_SIGNAL_FUNC(cancel_file), mylevel); gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fselect)->ok_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer) fselect); gtk_signal_connect_object(GTK_OBJECT (GTK_FILE_SELECTION(fselect)->cancel_button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer) fselect); gtk_widget_show(fselect); } static gint exit_cb(GtkWidget *widget, gpointer data) { gtk_main_quit(); return FALSE; } static void undo_cb(GtkWidget *widget, level **mylevel) { undo(*mylevel); } static void redo_cb(GtkWidget *widget, level **mylevel) { redo(*mylevel); } static void restart_cb(GtkWidget *widget, level **mylevel) { movelist *mymove; if ((*mylevel)->move) { do { mymove = (*mylevel)->move; undo(*mylevel); } while (mymove != (*mylevel)->move); if ((*mylevel)->move->next) { deletemove((*mylevel)->move->next); (*mylevel)->move->next = NULL; } } } void toggle_off(GtkWidget *toggle, level *mylevel, GtkWidget *window) { gtk_widget_hide(window); if (GTK_CHECK_MENU_ITEM(toggle)->active) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(toggle), FALSE); mylevel->showgoal = FALSE; } void toggle_on(GtkWidget *toggle, level *mylevel, GtkWidget *window) { gtk_widget_show(window); if (!GTK_CHECK_MENU_ITEM(toggle)->active) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(toggle), TRUE); mylevel->showgoal = TRUE; } void toggle_cb(GtkWidget *widget, level **mylevel) { if (GTK_CHECK_MENU_ITEM(widget)->active) toggle_on(widget, *mylevel, ((GtkWidget *)((*mylevel)->gelement))->parent); else toggle_off(widget, *mylevel, ((GtkWidget *)((*mylevel)->gelement))->parent); } static gint appdelete_event(GtkWidget *window, GdkEventAny *e, gpointer data) { exit_cb(window, data); return FALSE; } static gint gwindelete_event(GtkWidget *window, GdkEventAny *e, level **mylevel) { toggle_off((GtkWidget *)((*mylevel)->telement), *mylevel, window); return TRUE; } static void drawlevel(level *mylevel, GtkWidget *window) { GtkWidget *canvas; GnomeCanvasGroup *group; setuplist *mysetup; if (mylevel->lelement) gtk_widget_destroy((GtkWidget *)(mylevel->lelement)); gtk_widget_push_visual(gdk_rgb_get_visual()); gtk_widget_push_colormap(gdk_rgb_get_cmap()); canvas = gnome_canvas_new(); gtk_widget_pop_colormap(); gtk_widget_pop_visual(); gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, mylevel->usize[X]*mylevel->size[X]* mylevel->zoom[X], mylevel->usize[Y]*mylevel->size[Y]* mylevel->zoom[Y]); group = gnome_canvas_root(GNOME_CANVAS(canvas)); makebk(group, mylevel); mysetup = mylevel->setup; while (mysetup) { glotgen(group, mysetup->this); mysetup = mysetup->next; } gtk_widget_set_usize(canvas, mylevel->usize[X]*mylevel->size[X]*mylevel->zoom[X], mylevel->usize[Y]*mylevel->size[Y]*mylevel->zoom[Y]); gnome_app_set_contents(GNOME_APP(window), canvas); gtk_widget_show(canvas); updatestatus(mylevel); mylevel->lelement = (void *)canvas; } static GtkWidget *setuplevel(level **mylevel) { GtkWidget *app = gnome_app_new(GLOTNAME, GLOTNAME); GtkWidget *appbar = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_USER); GnomeUIInfo gamemenu[] = { GNOMEUIINFO_MENU_RESTART_GAME_ITEM(restart_cb, mylevel), GNOMEUIINFO_MENU_UNDO_MOVE_ITEM(undo_cb, mylevel), GNOMEUIINFO_MENU_REDO_MOVE_ITEM(redo_cb, mylevel), GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_TOGGLEITEM_NONE_DATA_(N_("_Toggle goal window"), toggle_cb, mylevel), GNOMEUIINFO_END }; GnomeUIInfo filemenu[] = { GNOMEUIINFO_MENU_OPEN_ITEM(open_cb, mylevel), GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_MENU_EXIT_ITEM(exit_cb, NULL), GNOMEUIINFO_END }; GnomeUIInfo helpmenu[] = { GNOMEUIINFO_MENU_ABOUT_ITEM(about_cb, app), GNOMEUIINFO_END }; GnomeUIInfo rootmenu[] = { GNOMEUIINFO_MENU_GAME_TREE(gamemenu), GNOMEUIINFO_MENU_FILE_TREE(filemenu), GNOMEUIINFO_MENU_HELP_TREE(helpmenu), GNOMEUIINFO_END }; GnomeUIInfo toolbar[] = { GNOMEUIINFO_ITEM_STOCK_DATA_(N_("Restart"), N_("Reset to initial state"), restart_cb, mylevel, GNOME_STOCK_PIXMAP_REFRESH), GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_ITEM_STOCK_DATA_(N_("Undo"), N_("Previous move"), undo_cb, mylevel, GNOME_STOCK_PIXMAP_UNDO), GNOMEUIINFO_ITEM_STOCK_DATA_(N_("Redo"), N_("Next move"), redo_cb, mylevel, GNOME_STOCK_PIXMAP_REDO), GNOMEUIINFO_END }; GdkPixmap *icon; GdkBitmap *mask; gtk_window_set_policy(GTK_WINDOW(app), FALSE, FALSE, TRUE); gtk_signal_connect(GTK_OBJECT(app), "delete_event", GTK_SIGNAL_FUNC(appdelete_event), NULL); gnome_app_set_statusbar(GNOME_APP(app), appbar); gnome_app_create_menus(GNOME_APP(app), rootmenu); if ((*mylevel)->showgoal) GTK_CHECK_MENU_ITEM(gamemenu[4].widget)->active = TRUE; (*mylevel)->telement = (void *)(gamemenu[4].widget); (*mylevel)->selement = (void *)appbar; gnome_app_create_toolbar(GNOME_APP(app), toolbar); drawlevel(*mylevel, app); gtk_widget_show_all(app); icon = gdk_pixmap_create_from_xpm_d(app->window, &mask, NULL, icon_xpm); gdk_window_set_icon(app->window, NULL, icon, mask); return app; } static void drawgoal(level *mylevel, GtkWidget *window) { GtkWidget *canvas; GnomeCanvasGroup *group; if (mylevel->gelement) gtk_widget_destroy((GtkWidget *)(mylevel->gelement)); gtk_widget_push_visual(gdk_rgb_get_visual()); gtk_widget_push_colormap(gdk_rgb_get_cmap()); canvas = gnome_canvas_new(); gtk_widget_pop_colormap(); gtk_widget_pop_visual(); gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, mylevel->usize[X]*mylevel->size[X]* mylevel->gzoom[X], mylevel->usize[Y]*mylevel->size[Y]* mylevel->gzoom[Y]); group = gnome_canvas_root(GNOME_CANVAS(canvas)); gtk_widget_set_usize(canvas, mylevel->usize[X]*mylevel->size[X]*mylevel->gzoom[X], mylevel->usize[Y]*mylevel->size[Y]*mylevel->gzoom[Y]); goalgen(group, mylevel); gtk_container_add(GTK_CONTAINER(window), canvas); gtk_widget_show(canvas); mylevel->gelement = (void *)canvas; } void redrawgoal(level *mylevel) { /* Assumes you've drawn before */ if (mylevel->gelement && mylevel->mygoal) drawgoal(mylevel, ((GtkWidget *)(mylevel->gelement))->parent); } static GtkWidget *setupgoal(level **mylevel) { GdkPixmap *icon; GdkBitmap *mask; GtkWidget *goalwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(goalwin), "Goal"); gtk_window_set_policy(GTK_WINDOW(goalwin), FALSE, FALSE, TRUE); gtk_signal_connect(GTK_OBJECT(goalwin), "delete_event", GTK_SIGNAL_FUNC(gwindelete_event), mylevel); drawgoal(*mylevel, goalwin); if ((*mylevel)->showgoal) gtk_widget_show_all(goalwin); icon = gdk_pixmap_create_from_xpm_d(goalwin->window, &mask, NULL, icon_xpm); gdk_window_set_icon(goalwin->window, NULL, icon, mask); return goalwin; } static void select_file(GtkWidget *widget, pair *mypair) { GtkWidget *filesel = (GtkWidget *)mypair->a; level **mylevel = (level **)mypair->b; char *text = gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel)); level *newlevel = loadlev(text, FALSE); if (!newlevel) { textdisp("Invalid filename"); open_cb(NULL, mylevel); return; } if (*mylevel) { newlevel->showgoal = (*mylevel)->showgoal; newlevel->lelement = (*mylevel)->lelement; newlevel->gelement = (*mylevel)->gelement; newlevel->telement = (*mylevel)->telement; newlevel->selement = (*mylevel)->selement; drawlevel(newlevel, ((GtkWidget *)((*mylevel)->lelement))->parent->parent->parent); drawgoal(newlevel, ((GtkWidget *)((*mylevel)->gelement))->parent); deletelevel(*mylevel); *mylevel = newlevel; } else { *mylevel = newlevel; setuplevel(mylevel); setupgoal(mylevel); } } void updatestatus(level *mylevel) { gchar stattxt[150]; gchar tmptxt[50]; if (mylevel->nummoves == 1) sprintf(stattxt, "1 move"); else sprintf(stattxt, "%d moves", mylevel->nummoves); if (mylevel->step) { sprintf(tmptxt, " (%d minimum)", mylevel->step); strcat(stattxt, tmptxt); } if (mylevel->numgoals-mylevel->state == 1) sprintf(tmptxt, ", 1 goal remaining"); else sprintf(tmptxt, ", %d goals remaining", mylevel->numgoals-mylevel->state); strcat(stattxt, tmptxt); gnome_appbar_set_status(GNOME_APPBAR((GtkWidget *)(mylevel->selement)), stattxt); } int main(int argc, char *argv[]) { static level *mylevel = NULL; static int filemode = FALSE; poptContext pctx; char **args; struct poptOption options[] = { { "file", 'f', POPT_ARG_NONE, &filemode, 0, N_("Load a file listed on the command line"), NULL }, { NULL, '\0', 0, NULL, 0, NULL, NULL } }; gnome_init_with_popt_table(GLOTNAME, GLOTVER, argc, argv, options, 0, &pctx); gdk_rgb_init(); args = poptGetArgs(pctx); if (filemode) { if (args) { if (!(mylevel = loadlev(args[0], TRUE))) { textdisp("Invalid filename; try these."); open_cb(NULL, &mylevel); } else { setuplevel(&mylevel); setupgoal(&mylevel); } } } else { if (args) { printf("Invalid argument %s\n", args[0]); return 1; } open_cb(NULL, &mylevel); } poptFreeContext(pctx); gtk_main(); return 0; } glotski-0.2/equiv.c100664 764 764 1513 7036020167 14366 0ustar oxymoronoxymoron/* Equivalence Class Implementation */ /* Implements simple single-depth union */ /* Simpler than Union-Find and better running time (constant) */ /* 0 indicates that a member is not part of a union (singleton); otherwise, the number indicates the class to which the member belongs */ #include #include "glotski.h" void eq_init(level *mylevel) { mylevel->equiv = (int *)calloc(mylevel->nextid, sizeof(int)); } int eq_equiv(int *eq, int node1, int node2) { /* Are they equivalent? */ if (node1 == node2) return 1; if (eq[node1] == 0 || eq[node2] == 0) return 0; else return eq[node1] == eq[node2]; } int eq_unite(int *eq, int *id, int parent, int node) { /* Make equiv: 0 fail, 1 succ */ if (eq[node] != 0) return 0; if (eq[parent] == 0) eq[parent] = *id++; eq[node] = eq[parent]; return 1; } glotski-0.2/glotski.c100664 764 764 16410 7036020167 14733 0ustar oxymoronoxymoron#include "glotski.h" #include #include level *makelevel(int xsize, int ysize) { /* Level constructor */ level *newlevel = (level *)calloc(1, sizeof(level)); movelist *newmove = (movelist *)calloc(1, sizeof(movelist)); glot **newfield = (glot **)calloc(xsize*ysize,sizeof(glot *)); if (!newlevel || !newfield) { fprintf(stderr, "glotski: Needed %d bytes to allocate level\n", sizeof(level) + xsize*ysize*sizeof(glot *) + 62*sizeof(int) + sizeof(movelist)); exit(1); } /* state, goal, numglots, nextid, equiv automatically set to 0 by calloc */ newlevel->usize[X] = newlevel->usize[Y] = 32.0; newlevel->scale[X] = newlevel->scale[Y] = newlevel->zoom[X] = newlevel->zoom[Y] = 1.0; newlevel->gzoom[X] = newlevel->gzoom[Y] = 0.5; newlevel->field = newfield; newlevel->size[0] = xsize; newlevel->size[1] = ysize; newlevel->uniteid = newlevel->showgoal = 1; newlevel->move = newmove; /* Placeholder to allow undo of first move */ return newlevel; } glot *makeglot(level *mylevel, int xloc, int yloc) { /* Glot constructor */ setuplist *newnode = (setuplist *)calloc(1, sizeof(setuplist)); glot *newglot = (glot *)calloc(1, sizeof(glot)); if (!newglot || !newnode) { fprintf(stderr, "glotski: Needed %d bytes to allocate glot\n", sizeof(glot) + sizeof(setuplist)); exit(1); } newnode->next = mylevel->setup; /* Prepend the glot */ mylevel->setup = newnode; newnode->this = newglot; /* field, label start as 0 */ newglot->type = BIMOBILE; newglot->red = 0; newglot->green = 127; newglot->blue = 0; newglot->loc[X] = xloc; newglot->loc[Y] = yloc; newglot->size[X] = newglot->size[Y] = 1; newglot->parent = mylevel; newglot->id = mylevel->nextid++; return newglot; } goal *makegoal(level *mylevel) { /* Goal constructor */ goal *newgoal = calloc(1, sizeof(goal)); glot **newfield = (glot **)calloc(mylevel->size[X]*mylevel->size[Y], sizeof(glot *)); if (!newgoal || !newfield) { fprintf(stderr, "glotski: Needed %d bytes to allocate goal\n", mylevel->size[X]*mylevel->size[Y]*sizeof(glot *) + sizeof(goal)); exit(1); } newgoal->next = mylevel->mygoal; /* Prepend goal: Last goal first. */ if (mylevel->mygoal) mylevel->mygoal->prev = newgoal; mylevel->mygoal = newgoal; newgoal->field = newfield; newgoal->size[X] = mylevel->size[X]; newgoal->size[Y] = mylevel->size[Y]; mylevel->numgoals++; return newgoal; } movelist *makemove(level *mylevel) { /* Move constructor */ movelist *newmove; if (mylevel->move && mylevel->move->next) return NULL; newmove = (movelist *)calloc(1, sizeof(movelist)); newmove->prev = mylevel->move; if (mylevel->move) mylevel->move->next = newmove; mylevel->move = newmove; return newmove; } void deleteglot(glot *myglot) { /* Glot destructor */ if (!myglot) return; if (myglot->field) free(myglot->field); /* if (myglot->label) free(myglot->label); */ free(myglot); } void deletegoal(goal *mygoal) { /* Goal destructor */ if (!mygoal) return; if (mygoal->next) deletegoal(mygoal->next); /* Recursive, how special */ free(mygoal->field); free(mygoal); } void popgoal(goal **mygoal) { /* Bring next goal to front */ goal *nextgoal; if (!mygoal || !(*mygoal)) return; nextgoal = (*mygoal)->next; (*mygoal)->next = NULL; deletegoal(*mygoal); *mygoal = nextgoal; } void deletesetup(setuplist *mysetup) { /* List destructor */ if (!mysetup) return; if (mysetup->next) deletesetup(mysetup->next); deleteglot(mysetup->this); free(mysetup); } void deletemove(movelist *mymove) { /* Move destructor */ if (!mymove) return; if (mymove->next) deletemove(mymove->next); free(mymove); } void popmove(movelist **mymove) { movelist *prevmove; if (!mymove || !(*mymove)) return; prevmove = (*mymove)->prev; if (prevmove) prevmove->next = (*mymove)->next; free(*mymove); *mymove = prevmove; } void deletelevel(level *mylevel) { /* Free a level and all its contents */ if (!mylevel) return; if (mylevel->field) free(mylevel->field); if (mylevel->setup) deletesetup(mylevel->setup); if (mylevel->mygoal) deletegoal(mylevel->mygoal); if (mylevel->equiv) free(mylevel->equiv); free(mylevel); } int goalequiv(level *mylevel) { /* See if a level is equivalent to its goal */ int x, y; int perfect = 1; goal *mygoal = mylevel->mygoal; glot *tmp1, *tmp2; if (!mygoal) return 0; for (x = 0; x < mylevel->size[X]; x++) { for (y = 0; y < mylevel->size[Y]; y++) { tmp1 = LOOKUP(mygoal, x, y); tmp2 = LOOKUP(mylevel, x, y); if ((!tmp2 && tmp1) || (tmp1 && tmp2 && !eq_equiv(mylevel->equiv, tmp1->id, tmp2->id))) { perfect = 0; break; } } if (perfect == 0) break; } return perfect; } int glotplace(glot *myglot, int xloc, int yloc, int perform) { int x, y; int perfect = 1; if (xloc < 0 || yloc < 0 || xloc + myglot->size[X] > myglot->parent->size[X] || yloc + myglot->size[Y] > myglot->parent->size[Y]) return 0; /* First, remove glot from current spot */ for (x = 0; x < myglot->size[X]; x++) for (y = 0; y < myglot->size[Y]; y++) if (LOOKUP(myglot, x, y)) LOOKUP(myglot->parent, x + myglot->loc[X], y + myglot->loc[Y]) = NULL; /* Then, see if glot can be placed on new spot (known in bounds) */ for (x = 0; x < myglot->size[X]; x++) { for (y = 0; y < myglot->size[Y]; y++) if (LOOKUP(myglot, x, y)) if (LOOKUP(myglot->parent, x + xloc, y + yloc) != NULL) { perfect = 0; break; } if (perfect == 0) break; } /* Now, replace it and quit if you're not supposed to perform */ if (perfect == 0 || perform == 0) { if (!glotplace(myglot, myglot->loc[X], myglot->loc[Y], 1)) { fprintf(stderr, "glotski: Unable to replace glot\n"); exit(1); } return perfect; } /* Finally, place the glot knowing it can be placed */ for (x = 0; x < myglot->size[X]; x++) for (y = 0; y < myglot->size[Y]; y++) if (LOOKUP(myglot, x, y)) LOOKUP(myglot->parent, x + xloc, y + yloc) = myglot; myglot->loc[X] = xloc; myglot->loc[Y] = yloc; return 1; } int glotmove(glot *moving, dirtype dir, int perform) { /* Move glot some dir */ int xloc, yloc; if (!COMPAT(moving, dir)) return 0; if (AXIS(dir) == X) { xloc = moving->loc[X] + 1 - 2*!SIGN(dir); yloc = moving->loc[Y]; } else { xloc = moving->loc[X]; yloc = moving->loc[Y] + 1 - 2*!SIGN(dir); } return glotplace(moving, xloc, yloc, perform); } void undo(level *mylevel) { if (mylevel->move && mylevel->move->prev) { moveelement(mylevel->move->myglot, mylevel->move->startloc[X], mylevel->move->startloc[Y]); if (mylevel->move->goalsat) { if (mylevel->state != mylevel->numgoals) mylevel->mygoal = mylevel->mygoal->prev; /* Last goal never reached */ mylevel->state--; redrawgoal(mylevel); } mylevel->move = mylevel->move->prev; mylevel->nummoves--; updatestatus(mylevel); } } void redo(level *mylevel) { if (mylevel->move && mylevel->move->next) { mylevel->move = mylevel->move->next; moveelement(mylevel->move->myglot, mylevel->move->endloc[X], mylevel->move->endloc[Y]); if (mylevel->move->goalsat) { mylevel->mygoal = mylevel->mygoal->next; mylevel->state++; redrawgoal(mylevel); } mylevel->nummoves++; updatestatus(mylevel); } } glotski-0.2/parse.c100664 764 764 21300 7036020167 14363 0ustar oxymoronoxymoron#include #include #include #include #include "glotski.h" int toint(char c) { /* if -1 then unsuccessful */ if (isdigit(c)) return c - '0'; else if (isupper(c)) return c - 'A' + 10; else if (islower(c)) return c - 'a' + 36; else if (c == '.' || c == ' ') return 62; else if (c == '#') return 63; return -1; } level *loadlev(char *levname, int usepath) { /* Assumes well-formed level */ char in; char modebuf[80]; char *bufptr = modebuf; glot *glottable[62]; glot *tmpglot; goal *tmpgoal; level *mylevel = NULL; int mode = 0; int x, y; int i, j; double id, jd; FILE *file; if (levname[0] == '\0') { printf("Filename required\n"); return NULL; } file = fopen(levname, "r"); if (file == NULL) { if (usepath) { if (strlen(LEVELPATH) + strlen(levname) >= 80) { printf("Path too long\n"); return NULL; } strcpy(modebuf, LEVELPATH); strcat(modebuf, levname); file = fopen(modebuf, "r"); } if (file == NULL) { printf("Invalid filename %s\n", levname); return NULL; } } for (i = 0; i < 62; i++) glottable[i] = NULL; while (fgets(modebuf, 80, file)) { if (modebuf[strlen(modebuf)-1] != '\n') { printf("Lines must be < 80 chars\n"); if (mylevel) deletelevel(mylevel); return NULL; } if (modebuf[0] != ';') { i = 0; while (!isspace(modebuf[i])) i++; modebuf[i] = '\0'; if (!strcmp("size", modebuf)) { if (mode != 0) { printf("Erroneous size\n"); if (mylevel) deletelevel(mylevel); return NULL; } bufptr = &(modebuf[strlen(modebuf)+1]); x = strtol(bufptr, &bufptr, 10); y = strtol(bufptr, &bufptr, 10); if (!y) { printf("Must include X and Y size\n"); if (mylevel) deletelevel(mylevel); /* Actually this won't exist */ return NULL; } mylevel = makelevel(x, y); mode = 1; } else if (!strcmp("initial", modebuf)) { if (mode != 1) { printf("Erroneous initial\n"); if (mylevel) deletelevel(mylevel); return NULL; } for (y = 0; y < mylevel->size[Y]; y++) /* First pass */ for (x = 0; x < mylevel->size[X]; x++) { /* Create, not fill */ while (isspace((in = getc(file)))) {}; if ((j = toint(in)) == -1) { printf("Parsed invalid initial char: %c (%d)\n", in, in); if (mylevel) deletelevel(mylevel); return NULL; } if (j < 62) { if (!glottable[j]) glottable[j] = makeglot(mylevel, x, y); LOOKUP(mylevel, x, y) = glottable[j]; if (glottable[j]->size[X] < x - glottable[j]->loc[X] + 1) glottable[j]->size[X] = x - glottable[j]->loc[X] + 1; if (glottable[j]->size[Y] < y - glottable[j]->loc[Y] + 1) glottable[j]->size[Y] = y - glottable[j]->loc[Y] + 1; if (y < glottable[j]->loc[Y]) { /* Correctors */ glottable[j]->size[Y] += glottable[j]->loc[Y] - y; glottable[j]->loc[Y] = y; } if (x < glottable[j]->loc[X]) { glottable[j]->size[X] += glottable[j]->loc[X] - x; glottable[j]->loc[X] = x; } if (!(mylevel->equiv = calloc(mylevel->nextid, sizeof(int)))) { printf("glotski: Unable to allocate %d bytes for equiv\n", mylevel->nextid*sizeof(int)); if (mylevel) deletelevel(mylevel); return NULL; } } /* if j == 62, space will == NULL anyway so ignore */ else if (j == 63) { /* Make a generic blocker */ tmpglot = makeglot(mylevel, x, y); tmpglot->type = IMMOBILE; tmpglot->red = 127; tmpglot->green = 127; tmpglot->blue = 127; tmpglot->field = (char *)malloc(sizeof(char)); tmpglot->field[0] = 1; LOOKUP(mylevel, x, y) = tmpglot; } } for (y = 0; y < mylevel->size[Y]; y++) /* Second pass */ for (x = 0; x < mylevel->size[X]; x++) { /* Fill the masks */ tmpglot = LOOKUP(mylevel, x, y); if (tmpglot) { if (!tmpglot->field && !(tmpglot->field = (char *)calloc(tmpglot->size[X]* tmpglot->size[Y], sizeof(char)))) { printf("glotski: Unable to allocate %d bytes for mask\n", tmpglot->size[X]*tmpglot->size[Y]*sizeof(char)); exit(1); } /* This next check should literally never fail */ if (x - tmpglot->loc[X] < 0 || y - tmpglot->loc[Y] < 0 || x - tmpglot->loc[X] >= tmpglot->size[X] || y - tmpglot->loc[Y] >= tmpglot->size[Y]) { printf("glotski: Second pass sanity check failed: %d %d\n", x - tmpglot->loc[X], y - tmpglot->loc[Y]); exit(1); } LOOKUP(tmpglot, x-tmpglot->loc[X], y-tmpglot->loc[Y]) = 1; } } mode = 2; while (isspace((in = getc(file)))) {}; ungetc(in, file); } else if (!strcmp("goal", modebuf) || !strcmp("target", modebuf)) { if (mode < 2) { printf("Erroneous goal\n"); if (mylevel) deletelevel(mylevel); return NULL; } tmpgoal = makegoal(mylevel); for (y = 0; y < mylevel->size[Y]; y++) for (x = 0; x < mylevel->size[X]; x++) { while (isspace((in = getc(file)))) {}; if ((j = toint(in)) == -1) { printf("Parsed invalid goal char: %c (%d)\n", in, in); if (mylevel) deletelevel(mylevel); return NULL; } if (j < 62) LOOKUP(tmpgoal, x, y) = glottable[j]; } while (isspace((in = getc(file)))) {}; ungetc(in, file); mode = 3; /* Parsed at least one goal */ } else if (!strcmp("color", modebuf)) { if (mode < 1) { printf("Erroneous color\n"); if (mylevel) deletelevel(mylevel); return NULL; } bufptr = &(modebuf[strlen(modebuf)+1]); in = *bufptr; if ((j = toint(in)) == -1) { printf("Parsed invalid color char: %c (%d)\n", in, in); if (mylevel) deletelevel(mylevel); return NULL; } tmpglot = glottable[j]; if (!tmpglot) { printf("Color char %c does not reference existing glot\n", in); if (mylevel) deletelevel(mylevel); return NULL; } bufptr++; /* Unsure if += sizeof(char) would be more proper */ tmpglot->red = strtol(bufptr, &bufptr, 10); tmpglot->green = strtol(bufptr, &bufptr, 10); tmpglot->blue = strtol(bufptr, &bufptr, 10); if (*bufptr == '\0') { printf("Need 3 colors (red green blue) specified\n"); if (mylevel) deletelevel(mylevel); return NULL; } } else if (!strcmp("scale", modebuf)) { if (mode < 1) { printf("Erroneous scale\n"); if (mylevel) deletelevel(mylevel); return NULL; } bufptr = &(modebuf[strlen(modebuf)+1]); id = strtod(bufptr, &bufptr); jd = strtod(bufptr, &bufptr); if (id <= 0.0 || jd <= 0.0) { printf("Erroneous scale values %f %f\n", id, jd); if (mylevel) deletelevel(mylevel); return NULL; } mylevel->usize[X] = id*32.0; mylevel->usize[Y] = jd*32.0; mylevel->scale[X] = id; mylevel->scale[Y] = jd; } else if (!strcmp("equiv", modebuf)) { if (mode < 1) { printf("Erroneous equiv\n"); if (mylevel) deletelevel(mylevel); return NULL; } i = strlen(modebuf)+1; x = toint(modebuf[i]); if (isspace(modebuf[i]) || x == -1 || x >= 62) { printf("Parsed invalid leading equiv char: %c (%d)\n", modebuf[i], modebuf[i]); if (mylevel) deletelevel(mylevel); return NULL; } i++; while (!isspace(modebuf[i])) { if ((j = toint(modebuf[i])) == -1 || j >= 62) { printf("Parsed invalid equiv char: %c (%d)\n", modebuf[i], modebuf[i]); if (mylevel) deletelevel(mylevel); return NULL; } eq_unite(mylevel->equiv, &mylevel->uniteid, x, j); i++; } } else if (!strcmp("type", modebuf)) { if (mode < 1) { printf("Erroneous type\n"); if (mylevel) deletelevel(mylevel); return NULL; } bufptr = &(modebuf[strlen(modebuf) + 1]); in = *bufptr; if ((j = toint(in)) == -1) { printf("Parsed invalid type char: %c (%d)\n", in, in); if (mylevel) deletelevel(mylevel); return NULL; } tmpglot = glottable[j]; if (!tmpglot) { printf("Type char %c does not reference existing glot\n", in); if (mylevel) deletelevel(mylevel); return NULL; } bufptr += 2; /* Should be 2*sizeof(char) ? */ switch (*bufptr) { case 'i': tmpglot->type = IMMOBILE; break; case 'h': tmpglot->type = HORIZONTAL; break; case 'v': tmpglot->type = VERTICAL; break; case 'b': tmpglot->type = BIMOBILE; break; default: printf("Type char %c not a type\n", *bufptr); if (mylevel) deletelevel(mylevel); return NULL; } } else if (!strcmp("step", modebuf)) { if (mode < 1) { printf("Erroneous step"); if (mylevel) deletelevel(mylevel); return NULL; } bufptr = &(modebuf[strlen(modebuf) + 1]); mylevel->step = strtol(bufptr, &bufptr, 10); } else if (!strcmp("end", modebuf)) { break; } else { printf("Invalid command string %s\n",modebuf); if (mylevel) deletelevel(mylevel); return NULL; } } } if (mode != 3) { printf("Requires a goal to be a valid level\n"); if (mylevel) deletelevel(mylevel); return NULL; } return mylevel; } glotski-0.2/glotski.h100664 764 764 12236 7036020167 14742 0ustar oxymoronoxymoron/* Glotski Header */ /* Defines datatypes and low-level (#define) functions */ #define GLOTNAME "Glotski" #define GLOTVER "0.2" #ifndef LEVELPATH #define LEVELPATH "/usr/share/games/glotski/" #endif enum _glottype; typedef enum _glottype glottype; enum _dirtype; typedef enum _dirtype dirtype; enum _glottype {IMMOBILE = 0, HORIZONTAL, VERTICAL, BIMOBILE}; enum _dirtype {LEFT = 0, UP, RIGHT, DOWN}; /* Harkens back to GFP */ #define X 0 #define Y 1 #define SPLIT 2 struct _pair; typedef struct _pair pair; struct _glot; typedef struct _glot glot; struct _goal; typedef struct _goal goal; struct _setuplist; typedef struct _setuplist setuplist; struct _movelist; typedef struct _movelist movelist; struct _level; typedef struct _level level; struct _pair { /* A pair of void pointers as one object */ void *a; void *b; }; struct _glot { /* A moving block, aka a glot */ glottype type; /* The type of glot */ level *parent; /* The level that the glot belongs to */ unsigned int red, green, blue; /* The glot's color */ int loc[2]; /* Location - offset of mask. Can be negative. */ int size[2]; /* Bounding box of piece */ char *field; /* Mask of piece's shape */ int id; /* The designation in the parsed file */ void *element; /* The graphical element representing the glot */ }; struct _goal { /* A doubly-linked list of goals */ glot **field; /* Pointers to necessary glots (or NULL for unnecessary) */ int size[2]; /* Redundant, kinda, but necessary for LOOKUP macro */ goal *prev; /* Previous goal satisfied */ goal *next; /* Next goal to be satisfied */ }; struct _setuplist { /* A singly-linked list of glots */ glot *this; /* The current glot */ setuplist *next; /* The glot after that */ }; struct _movelist { /* A doubly-linked list of moves */ glot *myglot; /* The piece being moved */ int startloc[2]; /* The location the piece began with */ int endloc[2]; /* The new location of the piece */ int goalsat; /* Did it satisfy a goal? */ movelist *prev; /* The previous move made (null if the first move) */ movelist *next; /* The next move made (null if the last move */ }; struct _level { /* A series of glots with a goal, aka a level*/ glot **field; /* Pointers to glots when full, null when empty */ int size[2]; /* Size of board, X and Y */ double usize[2]; /* Unit size for drawing, X and Y (start as 32) */ double scale[2]; /* Scale, X and Y (start as 1) (for bevel sizes) */ double zoom[2]; /* Zoom, X and Y (start as 1) (for resizing win)*/ double gzoom[2]; /* Goal window zoom, X and Y (start as 0.5) */ setuplist *setup; /* List of glots - the board setup */ goal *mygoal; /* Trying to bring level to this glot state */ int state; /* What goal has currently been achieved */ int numgoals; /* Total number of goals */ int *equiv; /* For the eq routines */ int nextid; /* The next identifier to be assigned: starts at 0 */ /* Also functions as number of glots on level */ int uniteid; /* The next union identifier to be assigned: starts at 1 */ movelist *move; /* The current move being made */ int nummoves; /* The number of moves made */ int step; /* The minimum number of moves needed to win */ int won; /* Beat level */ void *lelement; /* The graphical element representing the level */ void *gelement; /* The graphical element representing the goal */ void *telement; /* The UI element representing the goal toggle */ void *selement; /* The UI element representing the status */ int showgoal; /* Show the goal element? (Default: True) */ }; /* mod 2 finds axis */ /* if dirtype >= SPLIT or dirtype & SPLIT then negative, else positive */ /* if (axis + 1) & jifftype then piece can move in that direction */ #define AXIS(a) ((a) & 1) /* 0 if X axis, 1 if Y axis */ #define SIGN(a) ((a) & SPLIT) /* true if positive direction */ #define COMPAT(piece, dir) ((AXIS(dir)+1) & (piece->type)) /* true if piece can go that dir */ #define LOOKUP(w, x, y) ((w)->field[(x) + (y)*(w)->size[X]]) #define XDIR(newx, prevx) (((newx) < (prevx)) ? LEFT : RIGHT) #define YDIR(newy, prevy) (((newy) < (prevy)) ? UP : DOWN) /* From glotski.c */ level *makelevel(int xsize, int ysize); glot *makeglot(level *mylevel, int xloc, int yloc); goal *makegoal(level *mylevel); movelist *makemove(level *mylevel); void deleteglot(glot *myglot); void deletegoal(goal *mygoal); void popgoal(goal **mygoal); void deletelevel(level *mylevel); void deletemove(movelist *mymove); void popmove(movelist **mymove); int goalequiv(level *mylevel); int glotplace(glot *myglot, int xloc, int yloc, int perform); int glotmove(glot *moving, dirtype dir, int perform); void undo(level *mylevel); void redo(level *mylevel); /* From equiv.c */ void eq_init(level *mylevel); int eq_equiv(int *eq, int node1, int node2); int eq_unite(int *eq, int *id, int parent, int node); /* From parse.c */ level *loadlev(char *levname, int usepath); /* From canvas.c */ void moveelement(glot *myglot, int xloc, int yloc); void redrawgoal(level *mylevel); void updatestatus(level *mylevel); glotski-0.2/AUTHORS100664 764 764 1056 7036020167 14143 0ustar oxymoronoxymoronGlotski 0.2 (Release At Last) January 8, 2000 All content except for files ending in .lev by Martin Hock (oxymoron@cmu.edu) Copyright 1999-2000 Martin Hock. Some of the code in canvas.c was based on code by Havoc Pennington in his book _GTK+/Gnome Application Development_ published in 1999 by New Riders Publishing (ISBN 0-7357-0078-8). This is not meant to be a reproduction of the work. canvas.c also contains various pieces modified from the Gnome User Interface Library Reference Manual. Both works are available at: http://developer.gnome.org/doc/ glotski-0.2/COPYING100644 764 764 43127 7036020167 14151 0ustar oxymoronoxymoron GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. glotski-0.2/ChangeLog100664 764 764 1760 7036020167 14647 0ustar oxymoronoxymoron0.2 (January 8 2000): Release At Last. * Interface spruced up, with menu, status line * Added Goal window to show you what you're supposed to do * Many bugs fixed (Undoing previous goals, correct Gnome setup) * Still to do: add ability to resize, add ability to use pixmaps for pieces, perhaps add some antialiased effects (i.e. transparent drag), make some UI tweaks for better Gnome compliance 0.11 (January 4 2000): Post Prerelease. * Added undo/redo (may be flaky) * Switched over to proper Gnome structure (still trying to isolate Gnome to canvas.c) * Fixed a number of bugs (incl. imperfect parsing) * Changed assymptotic runtime of list append from O(n) to O(1) (I feel like an idiot, but it WAS a prerelease, right?) * Added a few more levels (still public domain things). * Still a long way to go to 1.0, but it's getting better. 0.1 (December 31 1999): Prerelease. * Many features missing. * Can load and play levels (via command line). No real interface. * Spits plenty of messages to console. glotski-0.2/INSTALL100664 764 764 1030 7036020167 14114 0ustar oxymoronoxymoronRequirements: A recent version of GNOME (October Gnome seems to work just fine) Which implies a recent version of GTK+ Which implies a recent version of GDK, and so on Directions: 1) Set up Makefile appropriately (for example -DLEVELPATH if you want a different path for your level files) 2) make 3) Copy the files where you want 'em, namely: a) Put the binary in something like /usr/local/bin b) Put icon.xpm in something like /usr/share/pixmaps c) Put the .lev files in LEVELPATH (/usr/share/games/glotski) 4) Enjoy, or something glotski-0.2/Makefile100644 764 764 720 7036020167 14506 0ustar oxymoronoxymoronCC = gcc -g -Wall -O5 LIBS = `gnome-config gnomeui --libs` OBJS = glotski.o equiv.o parse.o canvas.o INCLUDE = `gnome-config gnomeui --cflags` all: ${OBJS} ${CC} ${OBJS} ${LIBS} -o glotski glotski.o: glotski.c glotski.h ${CC} ${INCLUDE} -c glotski.c equiv.o: equiv.c glotski.h ${CC} ${INCLUDE} -c equiv.c parse.o: parse.c glotski.h ${CC} ${INCLUDE} -c parse.c canvas.o: canvas.c glotski.h ${CC} ${INCLUDE} -c canvas.c clean: rm -f *.o *~ core glotski glotski-0.2/NEWS100664 764 764 77 7036020167 13534 0ustar oxymoronoxymoronIf you are reading this, you have too much time on your hands. glotski-0.2/README100664 764 764 13440 7036020167 13773 0ustar oxymoronoxymoronGlotski 0.2 (Release At Last) January 8, 2000 All content except for files ending in .lev by Martin Hock (oxymoron@cmu.edu) Copyright 1999-2000 Martin Hock. All of this software (i.e. everything in this archive) is distributed under the GNU General Public License, version 2 or higher. It has NO WARRANTY. Please read COPYING for more info. Stated again in more words: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA INTRODUCTION: You wake up one day to realize that you have no real friends and have accomplished nothing of any real importance. You stare at yourself in the mirror and wonder why you even need to exist anymore. You begin to feel yourself slipping away from reality, slowly, almost completely unlike slipping on, say, a bar of soap. But as you begin to drift off, right before you lose your last shred of consciousness, something grabs you. Something... blocky. Yes. The blocks. You must slide them. They must be slid. No one, but you, can slide these blocks. Your life takes on meaning as you begin sliding the blocks around, and around, and around... IMPORTANT INFORMATION: Since its original release, the game has actually gotten so it resembles a real application. This is good. Of course, it is not done yet. The game is named Glotski, which rhymes with.. not free? But, as you realized, this game is entirely free (as in speech), unlike Klotski, a game for Microsoft Windows, which therefore this game obviously isn't. This game requires a relatively recent version of Gnome, one that has a canvas that actually works. HOW TO PLAY: Start the game by either running 'glotski -f ' where the argument (required) is the name of a level file, or simply running 'glotski' and using the file dialog that pops up. The level may either be present in your path or, if not, in LEVELPATH (defined at time of compile; default is /usr/local/games/glotski/). The file dialog will start in the LEVELPATH directory. A level consists of a series of square-based blocks, which may be slid around on a rectangular grid by dragging them around with the left mouse button. Blocks may not overlap. You have a series of goals in mind (usually just one). You must move the blocks around until they match each of these goal patterns. Usually the goal is as simple as "move a certain block to a certain place on the grid" but it can be more complex (like "mirror the entire playing field vertically"). Look in the little "Goal" window to see what it is you're supposed to do. It is possible to make the goal ambiguous, by having two pieces that look similar have different meanings, but then it is also possible to make the goal impossible to attain, so you must have trust in the level author. Usually these goals are fairly hard to attain. I personally am not very good at attaining them. I wrote this game because I liked the commercially sold game "Rush Hour" by Binary Arts and I wanted to create something like it. I soon realized that Rush Hour was far too specialized a case. Currently the game is a very large superset of Rush Hour. I also wrote it when I read the fabulous book _Sliding Piece Puzzles_ by L. E. Hordern and realized the wealth of sliding block puzzles that were out there. FILE FORMAT: The level file format is very similar to the file format of the puzzles found at Nick Baxter's Sliding Block Home Page at: http://www.johnrausch.com/SlidingBlockPuzzles/ Currently, I do not support textures for the blocks. I also support an additional directive, type, which takes the format: type x typename where x is one of the piece identifiers, and typename is one of: [ihvb] for immobile, horizontally movable, vertically movable, and both axes movable, respectively. Oh, and I support multiple targets (goals). This is handy for levels like "Marco Polo" (which I have not packaged). Put the goals in the order of the last one you want fulfilled first. The interface is not finalized, but I'm pretty satisfied with it. I'll probably add some more features eventually. The parser is not that great when it's given an invalid level, but it seems to work fine for valid ones. (And it will give you a bit of a clue what you did wrong if it's invalid.) Oh, and I may as well switch over to an autoconf build process (I need to learn how to use that - nobody help me this time!) A NOTE ABOUT THE PACKAGED LEVELS: I have decided to only package level files that I am as sure as I can be are in the public domain. These are levels that were either patented quite some time ago and thus the patents have expired, or were manufactured by several unrelated companies and thus have been established as generic. If someone wants to provide me with advice about this issue, I certainly would welcome it. Furthermore, if anyone makes any puzzles that they want included, contact me. (You will retain copyright, but they will be placed under the GPL.) Some "Rush Hour"-ish puzzles as well as puzzles with multiple goals would be nice; there currently are no such puzzles distributed. The more puzzles I can include, the better. The puzzles are currently all taken from Hordern's book. And that's about it for now... What, were you expecting more for free? glotski-0.2/icon.xpm100664 764 764 2356 7036020167 14555 0ustar oxymoronoxymoron/* XPM */ static char * icon_xpm[] = { "32 32 4 1", " c None", ". c #FFC283", "+ c #7B4000", "@ c #FF8108", "................................", "...............................+", "..............................++", ".............................+++", "............................++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....@@@@@@@@@@@@@@@@@@@@@@+++++", ".....+++++++++++++++++++++++++++", "....++++++++++++++++++++++++++++", "...+++++++++++++++++++++++++++++", "..++++++++++++++++++++++++++++++", ".+++++++++++++++++++++++++++++++"}; glotski-0.2/c19.lev100664 764 764 327 7036020167 14157 0ustar oxymoronoxymoron; C19 from _Sliding Piece Puzzles_ ; Move the big red square to the bottom left corner size 4 5 initial AA11 AA22 78.. 6533 6544 target .... .... .... AA.. AA.. color A 127 0 0 color 7 0 0 127 color 8 0 0 127 ; end glotski-0.2/c27a.lev100664 764 764 350 7036020167 14313 0ustar oxymoronoxymoron; C27a from _Sliding Piece Puzzles_ ; Move A to bottom center size 4 5 ; initial 1AA2 1AA2 6789 4335 4..5 ; target .... .... .... .AA. .AA. ; color A 127 0 0 color 6 0 0 127 color 7 0 0 127 color 8 0 0 127 color 9 0 0 127 ; end glotski-0.2/c27d.lev100664 764 764 350 7036020167 14316 0ustar oxymoronoxymoron; C27d from _Sliding Piece Puzzles_ ; Move A to bottom center size 4 5 ; initial 1AA2 1AA2 4335 4675 8..9 ; target .... .... .... .AA. .AA. ; color A 127 0 0 color 6 0 0 127 color 7 0 0 127 color 8 0 0 127 color 9 0 0 127 ; end glotski-0.2/d12.lev100664 764 764 560 7036020167 14150 0ustar oxymoronoxymoron; D12 from _Sliding Piece Puzzles_ ; Move big red block to lower left size 6 5 step 43 ; initial AA8b55 AA9c66 ..ad77 112334 122344 ; target ...... ...... ...... ....AA ....AA ; color A 127 0 0 color 8 0 0 127 color 9 0 0 127 color a 0 0 127 color b 0 0 127 color c 0 0 127 color d 0 0 127 color 1 0 127 127 color 2 0 127 127 color 3 0 127 127 color 4 0 127 127 ; end glotski-0.2/d13.lev100664 764 764 561 7036020167 14152 0ustar oxymoronoxymoron; D13 from _Sliding Piece Puzzles_ ; Move big red block to lower right size 6 5 step 52 ; initial AA89a. AAbcd. 556677 112334 122344 ; target ...... ...... ...... ....AA ....AA ; color A 127 0 0 color 8 0 0 127 color 9 0 0 127 color a 0 0 127 color b 0 0 127 color c 0 0 127 color d 0 0 127 color 1 0 127 127 color 2 0 127 127 color 3 0 127 127 color 4 0 127 127 ; end glotski-0.2/d23.lev100664 764 764 562 7036020167 14154 0ustar oxymoronoxymoron; D23 from _Sliding Piece Puzzles_ ; Move big red block to lower right size 6 5 step 223 ; initial .11233 .12237 89AA67 abAA64 cd5544 ; target ...... ...... ...... ....AA ....AA ; color A 127 0 0 color 8 0 0 127 color 9 0 0 127 color a 0 0 127 color b 0 0 127 color c 0 0 127 color d 0 0 127 color 1 0 127 127 color 2 0 127 127 color 3 0 127 127 color 4 0 127 127 ; end glotski-0.2/d14.lev100664 764 764 561 7036020167 14153 0ustar oxymoronoxymoron; D14 from _Sliding Piece Puzzles_ ; Move big red block to lower right size 6 5 step 58 ; initial AA8112 AA9122 55a334 66b344 77cd.. ; target ...... ...... ...... ....AA ....AA ; color A 127 0 0 color 8 0 0 127 color 9 0 0 127 color a 0 0 127 color b 0 0 127 color c 0 0 127 color d 0 0 127 color 1 0 127 127 color 2 0 127 127 color 3 0 127 127 color 4 0 127 127 ; end glotski-0.2/d18.lev100664 764 764 561 7036020167 14157 0ustar oxymoronoxymoron; D18 from _Sliding Piece Puzzles_ ; Move big red block to lower right size 6 5 step 75 ; initial AA89a. AAbcd. 551133 661234 772244 ; target ...... ...... ...... ....AA ....AA ; color A 127 0 0 color 8 0 0 127 color 9 0 0 127 color a 0 0 127 color b 0 0 127 color c 0 0 127 color d 0 0 127 color 1 0 127 127 color 2 0 127 127 color 3 0 127 127 color 4 0 127 127 ; end glotski-0.2/d19.lev100664 764 764 561 7036020167 14160 0ustar oxymoronoxymoron; D19 from _Sliding Piece Puzzles_ ; Move big red block to lower right size 6 5 step 99 ; initial AA1189 AA12ab 5522cd 66334. 77344. ; target ...... ...... ...... ....AA ....AA ; color A 127 0 0 color 8 0 0 127 color 9 0 0 127 color a 0 0 127 color b 0 0 127 color c 0 0 127 color d 0 0 127 color 1 0 127 127 color 2 0 127 127 color 3 0 127 127 color 4 0 127 127 ; end