From: Holger Schemel Date: Tue, 26 Jan 1999 18:40:10 +0000 (+0100) Subject: rnd-19990126-3 X-Git-Tag: 1.3.0^2~12 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=63ee0a61e7a4b4ec02c93d9647488f70784a6516;p=rocksndiamonds.git rnd-19990126-3 --- diff --git a/src/editor.c b/src/editor.c index dcb2f6e6..a5a57ee9 100644 --- a/src/editor.c +++ b/src/editor.c @@ -47,10 +47,6 @@ /* how many steps can be cancelled */ #define NUM_UNDO_STEPS (10 + 1) -/* values for random placement */ -#define RANDOM_USE_PERCENTAGE 0 -#define RANDOM_USE_NUM_OBJECTS 1 - /* values for elements with score */ #define MIN_SCORE 0 #define MAX_SCORE 255 @@ -150,6 +146,14 @@ #define ED_SCROLL_VERTICAL_XSIZE ED_SCROLLBUTTON_XSIZE #define ED_SCROLL_VERTICAL_YSIZE (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE) +/* values for checkbutton gadgets */ +#define ED_CHECKBUTTON_XSIZE ED_BUTTON_COUNT_XSIZE +#define ED_CHECKBUTTON_YSIZE ED_BUTTON_COUNT_YSIZE +#define ED_CHECKBUTTON_UNCHECKED_XPOS ED_BUTTON_MINUS_XPOS +#define ED_CHECKBUTTON_UNCHECKED_YPOS ED_BUTTON_MINUS_YPOS +#define ED_CHECKBUTTON_CHECKED_XPOS ED_BUTTON_PLUS_XPOS +#define ED_CHECKBUTTON_CHECKED_YPOS ED_BUTTON_PLUS_YPOS + /* control button identifiers */ #define GADGET_ID_NONE -1 @@ -234,7 +238,16 @@ #define GADGET_ID_ELEMENTLIST_FIRST 66 #define GADGET_ID_ELEMENTLIST_LAST 105 -#define NUM_EDITOR_GADGETS 106 +/* checkbuttons for level settings */ +#define GADGET_ID_RANDOM_PERCENTAGE 106 +#define GADGET_ID_RANDOM_QUANTITY 107 + +#define NUM_EDITOR_GADGETS 108 + +/* radio button numbers */ +#define RADIO_NR_NONE 0 +#define RADIO_NR_DRAWING_TOOLBOX 1 +#define RADIO_NR_RANDOM_ELEMENTS 2 /* values for counter gadgets */ #define ED_COUNTER_ID_ELEM_SCORE 0 @@ -270,16 +283,22 @@ #define ED_NUM_TEXTINPUT 2 +/* values for checkbutton gadgets */ +#define ED_CHECKBUTTON_PERCENTAGE 0 +#define ED_CHECKBUTTON_QUANTITY 1 + +#define ED_NUM_CHECKBUTTONS 2 + /* values for CopyLevelToUndoBuffer() */ #define UNDO_IMMEDIATE 0 #define UNDO_ACCUMULATE 1 /* values for ClearEditorGadgetInfoText() and HandleGadgetInfoText() */ -#define INFOTEXT_XPOS SX -#define INFOTEXT_YPOS (SY + SYSIZE - MINI_TILEX + 2) -#define INFOTEXT_XSIZE SXSIZE -#define INFOTEXT_YSIZE MINI_TILEX -#define MAX_INFOTEXT_LEN (SXSIZE / FONT2_XSIZE) +#define INFOTEXT_XPOS SX +#define INFOTEXT_YPOS (SY + SYSIZE - MINI_TILEX + 2) +#define INFOTEXT_XSIZE SXSIZE +#define INFOTEXT_YSIZE MINI_TILEX +#define MAX_INFOTEXT_LEN (SXSIZE / FONT2_XSIZE) static struct { @@ -365,11 +384,11 @@ static struct }, { ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(2), - 0, 100, + 1, 100, GADGET_ID_LEVEL_RANDOM_DOWN, GADGET_ID_LEVEL_RANDOM_UP, GADGET_ID_LEVEL_RANDOM_TEXT, &gadget_level_random_value, - "number of random elements" + "random elements" }, { ED_LEVELINFO_XPOS, ED_COUNTER_YPOS(3), @@ -394,7 +413,7 @@ static struct GADGET_ID_LEVEL_TIMESCORE_TEXT, &gadget_level_timescore_value, "score for each 10 seconds left" - }, + } }; static struct @@ -490,18 +509,46 @@ static struct GD_TYPE_SCROLLBAR_VERTICAL, GADGET_ID_SCROLL_VERTICAL, "scroll level editing area vertically" + } +}; + +/* values for random placement */ +#define RANDOM_USE_PERCENTAGE 0 +#define RANDOM_USE_QUANTITY 1 + +static int random_placement_value = 10; +static int random_placement_method = RANDOM_USE_QUANTITY; + +static struct +{ + int x, y; + int gadget_id; + int radio_button_nr; + int *value; + int checked_value; + char *text, *infotext; +} checkbutton_info[ED_NUM_CHECKBUTTONS] = +{ + { + ED_LEVELINFO_XPOS + 160, ED_COUNTER_YPOS(2), + GADGET_ID_RANDOM_PERCENTAGE, + RADIO_NR_RANDOM_ELEMENTS, + &random_placement_method, RANDOM_USE_PERCENTAGE, + "percentage", "use percentage for random elements" }, + { + ED_LEVELINFO_XPOS + 340, ED_COUNTER_YPOS(2), + GADGET_ID_RANDOM_QUANTITY, + RADIO_NR_RANDOM_ELEMENTS, + &random_placement_method, RANDOM_USE_QUANTITY, + "quantity", "use quantity for random elements" + } }; /* maximal size of level editor drawing area */ #define MAX_ED_FIELDX (2 * SCR_FIELDX) #define MAX_ED_FIELDY (2 * SCR_FIELDY - 1) -/* -#define ED_FIELDX (2 * SCR_FIELDX - 1) -#define ED_FIELDY (2 * SCR_FIELDY - 2) -*/ - /* actual size of level editor drawing area */ static int ed_fieldx = MAX_ED_FIELDX - 1, ed_fieldy = MAX_ED_FIELDY - 1; @@ -510,6 +557,15 @@ static int level_xpos = -1, level_ypos = -1; #define IN_ED_FIELD(x,y) ((x)>=0 && (x)=0 &&(y)= num_free_positions) { - for(x=0; x 0) { - int elements_left = random_placement_num_objects; + x = RND(lev_fieldx); + y = RND(lev_fieldy); - while (elements_left > 0) + /* don't place element at the same position twice */ + if (free_position[x][y]) { - x = RND(lev_fieldx); - y = RND(lev_fieldy); - - if (Feld[x][y] != new_element) - { - Feld[x][y] = new_element; - elements_left--; - } + free_position[x][y] = FALSE; + Feld[x][y] = new_element; + num_elements--; } } @@ -2877,8 +2852,8 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) boolean button_release_event; boolean inside_drawing_area = !gi->event.off_borders; boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL); - int new_element; int button = gi->event.button; + int new_element = BUTTON_ELEMENT(button); int sx = gi->event.x, sy = gi->event.y; int min_sx = 0, min_sy = 0; int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1; @@ -2929,10 +2904,6 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (!button && !button_release_event) return; - new_element = (button == 1 ? new_element1 : - button == 2 ? new_element2 : - button == 3 ? new_element3 : 0); - #if 0 if (button_release_event) @@ -3233,15 +3204,11 @@ static void HandleControlButtons(struct GadgetInfo *gi) int id = gi->custom_id; int button = gi->event.button; int step = (button == 1 ? 1 : button == 2 ? 5 : 10); - int new_element; + int new_element = BUTTON_ELEMENT(button); int player_present = FALSE; int level_changed = FALSE; int i, x, y; - new_element = (button == 1 ? new_element1 : - button == 2 ? new_element2 : - button == 3 ? new_element3 : 0); - if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT) DrawLevelText(0, 0, 0, TEXT_END); @@ -3403,7 +3370,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) break; case GADGET_ID_RANDOM_PLACEMENT: - RandomPlacement(button); + RandomPlacement(new_element); break; case GADGET_ID_PROPERTIES: @@ -3577,6 +3544,16 @@ static void HandleControlButtons(struct GadgetInfo *gi) } break; + case GADGET_ID_RANDOM_PERCENTAGE: + *checkbutton_info[ED_CHECKBUTTON_PERCENTAGE].value = + checkbutton_info[ED_CHECKBUTTON_PERCENTAGE].checked_value; + break; + + case GADGET_ID_RANDOM_QUANTITY: + *checkbutton_info[ED_CHECKBUTTON_QUANTITY].value = + checkbutton_info[ED_CHECKBUTTON_QUANTITY].checked_value; + break; + default: if (id >= GADGET_ID_ELEMENTLIST_FIRST && id <= GADGET_ID_ELEMENTLIST_LAST) @@ -3595,13 +3572,13 @@ static void HandleControlButtons(struct GadgetInfo *gi) } #ifdef DEBUG else if (gi->event.type == GD_EVENT_PRESSED) - printf("default: HandleControlButtons: GD_EVENT_PRESSED\n"); + printf("default: HandleControlButtons: GD_EVENT_PRESSED(%d)\n", id); else if (gi->event.type == GD_EVENT_RELEASED) - printf("default: HandleControlButtons: GD_EVENT_RELEASED\n"); + printf("default: HandleControlButtons: GD_EVENT_RELEASED(%d)\n", id); else if (gi->event.type == GD_EVENT_MOVING) - printf("default: HandleControlButtons: GD_EVENT_MOVING\n"); + printf("default: HandleControlButtons: GD_EVENT_MOVING(%d)\n", id); else - printf("default: HandleControlButtons: ?\n"); + printf("default: HandleControlButtons: ? (id == %d)\n", id); #endif break; } diff --git a/src/files.c b/src/files.c index 77585d6c..fb9f9603 100644 --- a/src/files.c +++ b/src/files.c @@ -270,6 +270,27 @@ static void InitUserLevelDirectory(char *level_subdir) } } +static void getFileChunk(FILE *file, char *chunk_buffer, int *chunk_length) +{ + fgets(chunk_buffer, CHUNK_ID_LEN + 1, file); + + *chunk_length = + (fgetc(file) << 24) | + (fgetc(file) << 16) | + (fgetc(file) << 8) | + (fgetc(file) << 0); +} + +static void putFileChunk(FILE *file, char *chunk_name, int chunk_length) +{ + fputs(chunk_name, file); + + fputc((chunk_length >> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); +} + static void setLevelInfoToDefaults() { int i, x, y; @@ -290,6 +311,11 @@ static void setLevelInfoToDefaults() level.high_speed = FALSE; + for(i=0; i= FILE_VERSION_1_2) { - /* first check header chunk identifier and chunk length */ - fgets(chunk, CHUNK_ID_LEN + 1, file); - chunk_length = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + getFileChunk(file, chunk, &chunk_length); if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); @@ -397,7 +418,7 @@ void LoadLevel(int level_nr) for(i=0; i= FILE_VERSION_1_2) { - fgets(chunk, CHUNK_ID_LEN + 1, file); - chunk_length = - (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file); + getFileChunk(file, chunk, &chunk_length); + + /* look for optional author chunk */ + if (strcmp(chunk, "AUTH") == 0 && chunk_length == MAX_LEVEL_AUTHOR_LEN) + { + for(i=0; i> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); + putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE); fputc(level.fieldx, file); fputc(level.fieldy, file); @@ -528,14 +548,12 @@ void SaveLevel(int level_nr) for(i=0; i> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); + putFileChunk(file, "CONT", 4 + 8 * 3 * 3); fputc(EL_MAMPFER, file); fputc(MampferMax, file); @@ -547,13 +565,7 @@ void SaveLevel(int level_nr) for(x=0; x<3; x++) fputc(level.mampfer_inhalt[i][x][y], file); - fputs("BODY", file); /* chunk identifier for file body */ - chunk_length = lev_fieldx * lev_fieldy; - - fputc((chunk_length >> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); + putFileChunk(file, "BODY", lev_fieldx * lev_fieldy); for(y=0; y