/* $Csoft: main.c,v 1.20 2005/10/06 09:44:53 vedge Exp $ */ /* * Copyright (c) 2002, 2003, 2004, 2005 CubeSoft Communications, Inc. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include static void StartGame(AG_Event *event) { AG_Window *pwin = AG_PTR(1), *win; AG_Map *map; AG_Mapview *mv; AG_Perso *di; if (AG_ObjectLoad(agWorld) == -1) { AG_TextMsg(AG_MSG_ERROR, "%s", AG_GetError()); return; } if ((map = AG_ObjectFind("/Baerums")) == NULL) { AG_TextMsg(AG_MSG_ERROR, "%s", AG_GetError()); return; } AG_WindowHide(pwin); AG_ObjectPageIn(map, AG_OBJECT_DATA); win = AG_WindowNewNamed(AG_WINDOW_NOTITLE|AG_WINDOW_NOBORDERS, NULL); mv = AG_MapviewNew(win, map, AG_MAPVIEW_NO_BG, NULL, NULL); AG_WidgetFocus(mv); AG_WindowMaximize(win); AG_WindowShow(win); if ((di = AG_ObjectFind("/Tjalve")) == NULL) { AG_TextMsg(AG_MSG_ERROR, "%s", AG_GetError()); return; } AG_MapviewSetMode(mv, AG_MAPVIEW_PLAY); AG_MapviewControl(mv, _("Player one"), di); } static void quit_game(AG_Event *event) { AG_Window *win = AG_PTR(1); SDL_Event qev; AG_WindowHide(win); qev.type = SDL_QUIT; SDL_PushEvent(&qev); } #ifdef EDITION static void edit_mode(void) { extern int agObjectIgnoreDataErrors; extern int agObjectIgnoreUnknownObjs; AG_MapEditorInit(); agObjectIgnoreDataErrors = 1; agObjectIgnoreUnknownObjs = 1; if (AG_ObjectLoad(agWorld) == -1) { dprintf("world: %s\n", AG_GetError()); } agObjectIgnoreDataErrors = 0; agObjectIgnoreUnknownObjs = 0; } #endif /* EDITION */ static void EditGame(AG_Event *event) { AG_Window *win = AG_PTR(1); AG_WindowHide(win); edit_mode(); } static void PollGames(AG_Event *event) { AG_Table *t = AG_PTR(1); AG_TableBegin(t); AG_TableEnd(t); } static void LoadGameDlg(AG_Event *event) { AG_Window *pwin = AG_PTR(1); AG_Window *win; AG_Table *t; AG_ViewDetach(pwin); win = AG_WindowNewNamed(0, "load-menu"); AG_WindowSetCaption(win, _("Load saved game")); AG_WindowSetPosition(win, AG_WINDOW_CENTER, 0); t = AG_TablePolled(win, 0, PollGames, NULL); AG_TableAddCol(t, "Name", "", NULL); AG_TableAddCol(t, "Time", "", NULL); AG_TableAddCol(t, "Location", "", NULL); AG_WindowShow(win); } static void GameMenu(void) { AG_Window *win; AG_HBox *hb; AG_Button *button; win = AG_WindowNewNamed(AG_WINDOW_NORESIZE, "trek-game-menu"); AG_WindowSetCaption(win, _("Trek to the Cave")); AG_WindowSetPosition(win, AG_WINDOW_CENTER, 0); hb = AG_HBoxNew(win, AG_HBOX_HOMOGENOUS|AG_HBOX_WFILL); { button = AG_ButtonNew(hb, _("New Game")); AG_SetEvent(button, "button-pushed", StartGame, "%p", win); button = AG_ButtonNew(hb, _("Load Game")); AG_SetEvent(button, "button-pushed", LoadGameDlg, "%p", win); #ifdef EDITION button = AG_ButtonNew(hb, _("Edit Game")); AG_SetEvent(button, "button-pushed", EditGame, "%p", win); #endif } button = AG_ButtonNew(win, _("Quit Game")); AGWIDGET(button)->flags |= AG_WIDGET_WFILL; AG_SetEvent(button, "button-pushed", quit_game, "%p", win); AG_WindowShow(win); } int main(int argc, char *argv[]) { int c, i, eflag = 0; int w = -1, h = -1; int fps = -1; char *s; if (AG_InitCore("trektothecave", 0) == -1) { goto fail; } while ((c = getopt(argc, argv, "?vfFegGJw:h:t:r:l:d:s:T:")) != -1) { extern char *optarg; switch (c) { case 'v': exit(0); case 'f': AG_SetBool(agConfig, "view.full-screen", 1); break; case 'F': AG_SetBool(agConfig, "view.full-screen", 0); break; case 'e': eflag = 1; break; #ifdef HAVE_OPENGL case 'g': AG_SetBool(agConfig, "view.opengl", 1); break; case 'G': AG_SetBool(agConfig, "view.opengl", 0); break; #endif case 'J': AG_SetBool(agConfig, "input.joysticks", 0); break; case 'w': w = atoi(optarg); break; case 'h': h = atoi(optarg); break; case 't': AG_TextParseFontSpec(optarg); break; case 'r': fps = atoi(optarg); break; case 'l': AG_SetString(agConfig, "load-path", "%s", optarg); break; case 'd': AG_SetString(agConfig, "den-path", "%s", optarg); break; case 's': AG_SetString(agConfig, "save-path", "%s", optarg); break; case 'T': AG_SetString(agConfig, "font-path", "%s", optarg); break; case '?': default: printf("%s [-vfFeJ] [-w width] [-h height] [-r fps]" " [-t font,size,flags] [-l load-path]" " [-d den-path] [-s save-path] [-T font-path]", agProgName); #ifdef HAVE_OPENGL printf(" [-gG]"); #endif printf("\n"); exit(0); } } if (AG_Bool(agConfig, "initial-run") == 1) { AG_SetString(agConfig, "den-path", "%s:%s", AG_String(agConfig, "den-path"), CAVE_SHAREDIR); AG_SetString(agConfig, "load-path", "%s:%s", AG_String(agConfig, "load-path"), CAVE_SHAREDIR); AG_SetString(agConfig, "font-path", "%s:%s", AG_String(agConfig, "font-path"), CAVE_TTFDIR); AG_SetBool(agConfig, "initial-run", 0); AG_ObjectSave(agConfig); } if (AG_InitVideo(w, h, 32, AG_VIDEO_RESIZABLE) == -1 || AG_InitInput(0) == -1 || AG_InitNetwork(AG_INIT_RCS|AG_INIT_DEBUG_SERVER) == -1) { goto fail; } AG_InitGame(); AG_InitRG(); AG_InitConfigWin(AG_CONFIG_ALL); AG_BindGlobalKey(SDLK_ESCAPE, KMOD_NONE, AG_Quit); AG_BindGlobalKey(SDLK_F1, KMOD_NONE, AG_ShowSettings); AG_BindGlobalKey(SDLK_F8, KMOD_NONE, AG_ViewCapture); AG_SetRefreshRate(fps); #ifdef EDITION if (eflag) edit_mode(); else #endif GameMenu(); AG_EventLoop(); AG_Destroy(); return (0); fail: fprintf(stderr, "%s\n", AG_GetError()); return (1); }