From 2f5368f25e34c02cb5ff7a012aa96198442231cb Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 8 Dec 2003 02:06:49 +0100 Subject: [PATCH] rnd-20031208-1-src --- src/conftime.h | 2 +- src/editor.c | 8 ++--- src/events.c | 80 +++++++++++++++++++++++++++++++++------------ src/files.c | 7 ++++ src/files.h | 1 + src/libgame/setup.c | 62 +++++++++++++++++++++++++---------- src/libgame/setup.h | 1 + src/tape.c | 15 ++++++++- src/tape.h | 1 + src/tools.c | 30 +++++++++++++---- 10 files changed, 158 insertions(+), 49 deletions(-) diff --git a/src/conftime.h b/src/conftime.h index d64adaeb..b31b5061 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-12-07 03:11]" +#define COMPILE_DATE_STRING "[2003-12-08 02:04]" diff --git a/src/editor.c b/src/editor.c index 843eb19b..68a0680a 100644 --- a/src/editor.c +++ b/src/editor.c @@ -5015,7 +5015,7 @@ static void CopyCustomElementPropertiesToGame(int element) if (level.use_custom_template) { - if (Request("Copy and modify level tem- plate ?", REQ_ASK)) + if (Request("Copy and modify level template ?", REQ_ASK)) { level.use_custom_template = FALSE; ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE], @@ -7196,11 +7196,11 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi) boolean new_template = (!LevelFileExists(-1)); if (new_template || - Request("Save this tem- plate and kill the old ?", REQ_ASK)) + Request("Save this template and kill the old ?", REQ_ASK)) SaveLevelTemplate(); if (new_template) - Request("Tem- plate saved !", REQ_CONFIRM); + Request("Template saved !", REQ_CONFIRM); } else if (type_id == ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE && custom_element.num_change_pages < MAX_CHANGE_PAGES) @@ -7283,7 +7283,7 @@ static void HandleCheckbuttons(struct GadgetInfo *gi) { if (level.use_custom_template && !LevelFileExists(-1)) { - Request("No level tem- plate found !", REQ_CONFIRM); + Request("No level template found !", REQ_CONFIRM); level.use_custom_template = FALSE; ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END); diff --git a/src/events.c b/src/events.c index de4583dc..19c47763 100644 --- a/src/events.c +++ b/src/events.c @@ -449,6 +449,63 @@ void HandleButton(int mx, int my, int button) } } +static boolean is_string_suffix(char *string, char *suffix) +{ + int string_len = strlen(string); + int suffix_len = strlen(suffix); + + if (suffix_len > string_len) + return FALSE; + + return (strcmp(&string[string_len - suffix_len], suffix) == 0); +} + +#define MAX_CHEAT_INPUT_LEN 32 + +static void HandleKeysCheating(Key key) +{ + static char cheat_input[2 * MAX_CHEAT_INPUT_LEN + 1] = ""; + char letter = getCharFromKey(key); + int cheat_input_len = strlen(cheat_input); + int i; + + if (letter == 0) + return; + + if (cheat_input_len >= 2 * MAX_CHEAT_INPUT_LEN) + { + for (i = 0; i < MAX_CHEAT_INPUT_LEN + 1; i++) + cheat_input[i] = cheat_input[MAX_CHEAT_INPUT_LEN + i]; + + cheat_input_len = MAX_CHEAT_INPUT_LEN; + } + + cheat_input[cheat_input_len++] = letter; + cheat_input[cheat_input_len] = '\0'; + +#if 0 + printf("::: '%s' [%d]\n", cheat_input, cheat_input_len); +#endif + +#if 1 + if (is_string_suffix(cheat_input, ":insert solution tape")) + InsertSolutionTape(); +#else + if (is_string_suffix(cheat_input, ":ist")) + InsertSolutionTape(); +#endif + +#ifdef DEBUG + else if (is_string_suffix(cheat_input, ":dump tape")) + DumpTape(&tape); + else if (is_string_suffix(cheat_input, ".q")) + for (i = 0; i < MAX_INVENTORY_SIZE; i++) + if (local_player->inventory_size < MAX_INVENTORY_SIZE) + local_player->inventory_element[local_player->inventory_size++] = + EL_DYNAMITE; +#endif +} + void HandleKey(Key key, int key_status) { int joy = 0; @@ -575,6 +632,8 @@ void HandleKey(Key key, int key_status) TapeQuickLoad(); else if (key == setup.shortcut.toggle_pause) TapeTogglePause(TAPE_TOGGLE_MANUAL); + + HandleKeysCheating(key); } if (HandleGadgetsKeyInput(key)) @@ -633,12 +692,6 @@ void HandleKey(Key key, int key_status) HandleInfoScreen(0,0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK); break; -#ifdef DEBUG - case KSYM_t: - DumpTape(&tape); - break; -#endif - default: break; } @@ -782,20 +835,6 @@ void HandleKey(Key key, int key_status) printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize); break; - case KSYM_Q: - case KSYM_q: - { - int i; - - for (i = 0; i < MAX_INVENTORY_SIZE; i++) - if (local_player->inventory_size < MAX_INVENTORY_SIZE) - local_player->inventory_element[local_player->inventory_size++] = - EL_DYNAMITE; - } - - break; - - #if 0 case KSYM_z: @@ -822,6 +861,7 @@ void HandleKey(Key key, int key_status) } break; } + default: if (key == KSYM_Escape) { diff --git a/src/files.c b/src/files.c index 8c268a7b..b7d62ce7 100644 --- a/src/files.c +++ b/src/files.c @@ -2011,6 +2011,13 @@ void LoadTape(int level_nr) LoadTapeFromFilename(filename); } +void LoadSolutionTape(int level_nr) +{ + char *filename = getSolutionTapeFilename(level_nr); + + LoadTapeFromFilename(filename); +} + static void SaveTape_VERS(FILE *file, struct TapeInfo *tape) { putFileVersion(file, tape->file_version); diff --git a/src/files.h b/src/files.h index 7f87399c..aa9c03e3 100644 --- a/src/files.h +++ b/src/files.h @@ -29,6 +29,7 @@ void DumpLevel(struct LevelInfo *); void LoadTapeFromFilename(char *); void LoadTape(int); +void LoadSolutionTape(int); void SaveTape(int); void DumpTape(struct TapeInfo *); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 65ba26c7..b1e3b443 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -108,23 +108,6 @@ static char *getUserLevelDir(char *level_subdir) return userlevel_dir; } -static char *getTapeDir(char *level_subdir) -{ - static char *tape_dir = NULL; - char *data_dir = getUserDataDir(); - char *tape_subdir = TAPES_DIRECTORY; - - if (tape_dir) - free(tape_dir); - - if (level_subdir != NULL) - tape_dir = getPath3(data_dir, tape_subdir, level_subdir); - else - tape_dir = getPath2(data_dir, tape_subdir); - - return tape_dir; -} - static char *getScoreDir(char *level_subdir) { static char *score_dir = NULL; @@ -180,6 +163,37 @@ static char *getCurrentLevelDir() return getLevelDirFromTreeInfo(leveldir_current); } +static char *getTapeDir(char *level_subdir) +{ + static char *tape_dir = NULL; + char *data_dir = getUserDataDir(); + char *tape_subdir = TAPES_DIRECTORY; + + if (tape_dir) + free(tape_dir); + + if (level_subdir != NULL) + tape_dir = getPath3(data_dir, tape_subdir, level_subdir); + else + tape_dir = getPath2(data_dir, tape_subdir); + + return tape_dir; +} + +static char *getSolutionTapeDir() +{ + static char *tape_dir = NULL; + char *data_dir = getCurrentLevelDir(); + char *tape_subdir = TAPES_DIRECTORY; + + if (tape_dir) + free(tape_dir); + + tape_dir = getPath2(data_dir, tape_subdir); + + return tape_dir; +} + static char *getDefaultGraphicsDir(char *graphics_subdir) { static char *graphics_dir = NULL; @@ -379,6 +393,20 @@ char *getTapeFilename(int nr) return filename; } +char *getSolutionTapeFilename(int nr) +{ + static char *filename = NULL; + char basename[MAX_FILENAME_LEN]; + + if (filename != NULL) + free(filename); + + sprintf(basename, "%03d.%s", nr, TAPEFILE_EXTENSION); + filename = getPath2(getSolutionTapeDir(), basename); + + return filename; +} + char *getScoreFilename(int nr) { static char *filename = NULL; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 807351d3..1f46cc20 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -196,6 +196,7 @@ typedef struct hashtable SetupFileHash; char *setLevelArtworkDir(TreeInfo *); char *getLevelFilename(int); char *getTapeFilename(int); +char *getSolutionTapeFilename(int); char *getScoreFilename(int); char *getSetupFilename(void); char *getEditorSetupFilename(void); diff --git a/src/tape.c b/src/tape.c index 880c4f9e..51dcd8a2 100644 --- a/src/tape.c +++ b/src/tape.c @@ -687,6 +687,19 @@ void TapeQuickLoad() } } +void InsertSolutionTape() +{ + if (!TAPE_IS_EMPTY(tape)) + return; + + LoadSolutionTape(level_nr); + + if (TAPE_IS_EMPTY(tape)) + Request("No solution tape for this level !", REQ_CONFIRM); + + DrawCompleteVideoDisplay(); +} + /* ------------------------------------------------------------------------- * * tape autoplay functions @@ -768,7 +781,7 @@ void AutoPlayTape() continue; } - LoadTape(level_nr); + LoadSolutionTape(level_nr); if (TAPE_IS_EMPTY(tape)) { printf("(no tape)\n"); diff --git a/src/tape.h b/src/tape.h index f32ad694..03cc3d24 100644 --- a/src/tape.h +++ b/src/tape.h @@ -99,6 +99,7 @@ void TapeErase(void); unsigned int GetTapeLength(void); void TapeQuickSave(void); void TapeQuickLoad(void); +void InsertSolutionTape(void); void AutoPlayTape(void); diff --git a/src/tools.c b/src/tools.c index 106d251e..cb473ce7 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2003,13 +2003,31 @@ void WaitForEventToContinue() } #define MAX_REQUEST_LINES 13 -#define MAX_REQUEST_LINE_LEN 7 +#define MAX_REQUEST_LINE_FONT1_LEN 7 +#define MAX_REQUEST_LINE_FONT2_LEN 10 boolean Request(char *text, unsigned int req_state) { int mx, my, ty, result = -1; unsigned int old_door_state; int last_game_status = game_status; /* save current game status */ + int max_request_line_len = MAX_REQUEST_LINE_FONT1_LEN; + int font_nr = FONT_TEXT_2; + int max_word_len = 0; + char *text_ptr; + + for (text_ptr = text; *text_ptr; text_ptr++) + { + max_word_len = (*text_ptr != ' ' ? max_word_len + 1 : 0); + + if (max_word_len > MAX_REQUEST_LINE_FONT1_LEN) + { + max_request_line_len = MAX_REQUEST_LINE_FONT2_LEN; + font_nr = FONT_LEVEL_NUMBER; + + break; + } + } #if 1 SetMouseCursor(CURSOR_DEFAULT); @@ -2049,13 +2067,13 @@ boolean Request(char *text, unsigned int req_state) /* write text for request */ for (ty = 0; ty < MAX_REQUEST_LINES; ty++) { - char text_line[MAX_REQUEST_LINE_LEN + 1]; + char text_line[max_request_line_len + 1]; int tx, tl, tc; if (!*text) break; - for (tl = 0, tx = 0; tx < MAX_REQUEST_LINE_LEN; tl++, tx++) + for (tl = 0, tx = 0; tx < max_request_line_len; tl++, tx++) { tc = *(text + tx); if (!tc || tc == ' ') @@ -2072,9 +2090,9 @@ boolean Request(char *text, unsigned int req_state) strncpy(text_line, text, tl); text_line[tl] = 0; - DrawText(DX + (DXSIZE - tl * getFontWidth(FONT_TEXT_2)) / 2, - DY + 8 + ty * (getFontHeight(FONT_TEXT_2) + 2), - text_line, FONT_TEXT_2); + DrawText(DX + (DXSIZE - tl * getFontWidth(font_nr)) / 2, + DY + 8 + ty * (getFontHeight(font_nr) + 2), + text_line, font_nr); text += tl + (tc == ' ' ? 1 : 0); } -- 2.34.1