#include "tools.h"
#include "tape.h"
#include "config.h"
+#include "api.h"
#define ENABLE_UNUSED_CODE 0 // currently unused functions
#define ENABLE_HISTORIC_CHUNKS 0 // only for historic reference
// (element number only)
#define LEVEL_CHUNK_GRPX_UNCHANGED 2
+#define LEVEL_CHUNK_EMPX_UNCHANGED 2
#define LEVEL_CHUNK_NOTE_UNCHANGED 2
// (nothing at all if unchanged)
#define TAPE_CHUNK_VERS_SIZE 8 // size of file version chunk
#define TAPE_CHUNK_HEAD_SIZE 20 // size of tape file header
-#define TAPE_CHUNK_HEAD_UNUSED 1 // unused tape header bytes
#define TAPE_CHUNK_SCRN_SIZE 2 // size of screen size chunk
#define SCORE_CHUNK_VERS_SIZE 8 // size of file version chunk
CONF_CONTENT_NUM_BYTES : 1)
#define CONF_ELEMENT_BYTE_POS(i) ((i) * CONF_ELEMENT_NUM_BYTES)
-#define CONF_ELEMENTS_ELEMENT(b,i) ((b[CONF_ELEMENT_BYTE_POS(i)] << 8) | \
+#define CONF_ELEMENTS_ELEMENT(b, i) ((b[CONF_ELEMENT_BYTE_POS(i)] << 8) | \
(b[CONF_ELEMENT_BYTE_POS(i) + 1]))
#define CONF_CONTENT_ELEMENT_POS(c,x,y) ((c) * CONF_CONTENT_NUM_ELEMENTS + \
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
&li.mm_time_bomb, 75
},
+
{
EL_MM_GRAY_BALL, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
&li.mm_time_ball, 75
},
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_INTEGER, CONF_VALUE_8_BIT(1),
+ &li.mm_ball_choice_mode, ANIM_RANDOM
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_ELEMENT_LIST, CONF_VALUE_BYTES(1),
+ &li.mm_ball_content, EL_EMPTY, NULL,
+ &li.num_mm_ball_contents, 8, MAX_MM_BALL_CONTENTS
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(3),
+ &li.rotate_mm_ball_content, TRUE
+ },
+ {
+ EL_MM_GRAY_BALL, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(2),
+ &li.explode_mm_ball, FALSE
+ },
+
{
EL_MM_STEEL_BLOCK, -1,
TYPE_INTEGER, CONF_VALUE_16_BIT(1),
}
};
+static struct LevelFileConfigInfo chunk_config_EMPX[] =
+{
+ {
+ -1, -1,
+ TYPE_BOOLEAN, CONF_VALUE_8_BIT(1),
+ &xx_ei.use_gfx_element, FALSE
+ },
+ {
+ -1, -1,
+ TYPE_ELEMENT, CONF_VALUE_16_BIT(1),
+ &xx_ei.gfx_element_initial, EL_EMPTY_SPACE
+ },
+
+ {
+ -1, -1,
+ -1, -1,
+ NULL, -1
+ }
+};
+
static struct LevelFileConfigInfo chunk_config_CONF[] = // (OBSOLETE)
{
{
setConfigToDefaultsFromConfigList(chunk_config_INFO);
*level = li; // copy temporary buffer back to level data
+ setLevelInfoToDefaults_BD();
setLevelInfoToDefaults_EM();
setLevelInfoToDefaults_SP();
setLevelInfoToDefaults_MM();
+ level->native_bd_level = &native_bd_level;
level->native_em_level = &native_em_level;
level->native_sp_level = &native_sp_level;
level->native_mm_level = &native_mm_level;
int element = i;
struct ElementInfo *ei = &element_info[element];
+ if (element == EL_MM_GRAY_BALL)
+ {
+ struct LevelInfo_MM *level_mm = level->native_mm_level;
+ int j;
+
+ for (j = 0; j < level->num_mm_ball_contents; j++)
+ level->mm_ball_content[j] =
+ map_element_MM_to_RND(level_mm->ball_content[j]);
+ }
+
// never initialize clipboard elements after the very first time
// (to be able to use clipboard elements between several levels)
if (IS_CLIPBOARD_ELEMENT(element) && clipboard_elements_initialized)
setElementChangeInfoToDefaults(ei->change);
if (IS_CUSTOM_ELEMENT(element) ||
- IS_GROUP_ELEMENT(element) ||
- IS_INTERNAL_ELEMENT(element))
+ IS_GROUP_ELEMENT(element))
{
setElementDescriptionToDefault(ei);
*group = xx_group;
}
+
+ if (IS_EMPTY_ELEMENT(element) ||
+ IS_INTERNAL_ELEMENT(element))
+ {
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ setConfigToDefaultsFromConfigList(chunk_config_EMPX);
+
+ *ei = xx_ei;
+ }
}
clipboard_elements_initialized = TRUE;
for (x = 0; x < 3; x++)
ei->content.e[x][y] = getMappedElement(getFile16BitBE(file));
+ // bits 0 - 31 of "has_event[]"
event_bits = getFile32BitBE(file);
- for (j = 0; j < NUM_CHANGE_EVENTS; j++)
- if (event_bits & (1 << j))
+ for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
+ if (event_bits & (1u << j))
ei->change->has_event[j] = TRUE;
ei->change->target_element = getMappedElement(getFile16BitBE(file));
ei->change->delay_random = getFile16BitBE(file);
ei->change->delay_frames = getFile16BitBE(file);
- ei->change->initial_trigger_element= getMappedElement(getFile16BitBE(file));
+ ei->change->initial_trigger_element = getMappedElement(getFile16BitBE(file));
ei->change->explode = getFile8Bit(file);
ei->change->use_target_content = getFile8Bit(file);
// bits 0 - 31 of "has_event[]" ...
event_bits = getFile32BitBE(file);
for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
- if (event_bits & (1 << j))
+ if (event_bits & (1u << j))
change->has_event[j] = TRUE;
change->target_element = getMappedElement(getFile16BitBE(file));
// ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible)
event_bits = getFile8Bit(file);
for (j = 32; j < NUM_CHANGE_EVENTS; j++)
- if (event_bits & (1 << (j - 32)))
+ if (event_bits & (1u << (j - 32)))
change->has_event[j] = TRUE;
}
value = getMappedElement(value);
if (data_type == TYPE_BOOLEAN)
- *(boolean *)(conf[i].value) = value;
+ *(boolean *)(conf[i].value) = (value ? TRUE : FALSE);
else
*(int *) (conf[i].value) = value;
while (!checkEndOfFile(file))
{
+ // level file might contain invalid change page number
+ if (xx_current_change_page >= ei->num_change_pages)
+ break;
+
struct ElementChangeInfo *change = &ei->change_page[xx_current_change_page];
xx_change = *change; // copy change data into temporary buffer
struct ElementInfo *ei = &element_info[element];
struct ElementGroupInfo *group = ei->group;
+ if (group == NULL)
+ return -1;
+
xx_ei = *ei; // copy element data into temporary buffer
xx_group = *group; // copy group data into temporary buffer
return real_chunk_size;
}
+static int LoadLevel_EMPX(File *file, int chunk_size, struct LevelInfo *level)
+{
+ int element = getMappedElement(getFile16BitBE(file));
+ int real_chunk_size = 2;
+ struct ElementInfo *ei = &element_info[element];
+
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ while (!checkEndOfFile(file))
+ {
+ real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_EMPX,
+ -1, element);
+
+ if (real_chunk_size >= chunk_size)
+ break;
+ }
+
+ *ei = xx_ei;
+
+ level->file_has_custom_elements = TRUE;
+
+ return real_chunk_size;
+}
+
static void LoadLevelFromFileInfo_RND(struct LevelInfo *level,
struct LevelFileInfo *level_file_info,
boolean level_info_only)
{ "NOTE", -1, LoadLevel_NOTE },
{ "CUSX", -1, LoadLevel_CUSX },
{ "GRPX", -1, LoadLevel_GRPX },
+ { "EMPX", -1, LoadLevel_EMPX },
{ NULL, 0, NULL }
};
int chunk_size_expected =
(chunk_info[i].loader)(file, chunk_size, level);
+ if (chunk_size_expected < 0)
+ {
+ Warn("error reading chunk '%s' in level file '%s'",
+ chunk_name, filename);
+
+ break;
+ }
+
// the size of some chunks cannot be checked before reading other
// chunks first (like "HEAD" and "BODY") that contain some header
// information, so check them here
{
Warn("wrong size (%d) of chunk '%s' in level file '%s'",
chunk_size, chunk_name, filename);
+
+ break;
}
}
}
}
+// ----------------------------------------------------------------------------
+// functions for loading BD level
+// ----------------------------------------------------------------------------
+
+static void CopyNativeLevel_RND_to_BD(struct LevelInfo *level)
+{
+ struct LevelInfo_BD *level_bd = level->native_bd_level;
+
+ level_bd->width = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH);
+ level_bd->height = MIN(level->fieldy, MAX_PLAYFIELD_HEIGHT);
+}
+
+static void CopyNativeLevel_BD_to_RND(struct LevelInfo *level)
+{
+ struct LevelInfo_BD *level_bd = level->native_bd_level;
+
+ level->fieldx = MIN(level_bd->width, MAX_LEV_FIELDX);
+ level->fieldy = MIN(level_bd->height, MAX_LEV_FIELDY);
+}
+
+
// ----------------------------------------------------------------------------
// functions for loading EM level
// ----------------------------------------------------------------------------
cav->lenses_time = level->lenses_time;
cav->magnify_time = level->magnify_time;
+ cav->wind_time = 9999;
cav->wind_direction =
map_direction_RND_to_EM(level->wind_direction_initial);
// initialize player positions and delete players from the playfield
for (y = 0; y < cav->height; y++) for (x = 0; x < cav->width; x++)
{
- if (ELEM_IS_PLAYER(level->field[x][y]))
+ if (IS_PLAYER_ELEMENT(level->field[x][y]))
{
int player_nr = GET_PLAYER_NR(level->field[x][y]);
static void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
{
struct LevelInfo_MM *level_mm = level->native_mm_level;
- int x, y;
+ int i, x, y;
level_mm->fieldx = MIN(level->fieldx, MM_MAX_PLAYFIELD_WIDTH);
level_mm->fieldy = MIN(level->fieldy, MM_MAX_PLAYFIELD_HEIGHT);
level_mm->kettles_needed = level->gems_needed;
level_mm->auto_count_kettles = level->auto_count_gems;
- level_mm->laser_red = level->mm_laser_red;
- level_mm->laser_green = level->mm_laser_green;
- level_mm->laser_blue = level->mm_laser_blue;
+ level_mm->mm_laser_red = level->mm_laser_red;
+ level_mm->mm_laser_green = level->mm_laser_green;
+ level_mm->mm_laser_blue = level->mm_laser_blue;
+
+ level_mm->df_laser_red = level->df_laser_red;
+ level_mm->df_laser_green = level->df_laser_green;
+ level_mm->df_laser_blue = level->df_laser_blue;
strcpy(level_mm->name, level->name);
strcpy(level_mm->author, level->author);
level_mm->time_ball = level->mm_time_ball;
level_mm->time_block = level->mm_time_block;
+ level_mm->num_ball_contents = level->num_mm_ball_contents;
+ level_mm->ball_choice_mode = level->mm_ball_choice_mode;
+ level_mm->rotate_ball_content = level->rotate_mm_ball_content;
+ level_mm->explode_ball = level->explode_mm_ball;
+
+ for (i = 0; i < level->num_mm_ball_contents; i++)
+ level_mm->ball_content[i] =
+ map_element_RND_to_MM(level->mm_ball_content[i]);
+
for (x = 0; x < level->fieldx; x++)
for (y = 0; y < level->fieldy; y++)
Ur[x][y] =
static void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
{
struct LevelInfo_MM *level_mm = level->native_mm_level;
- int x, y;
+ int i, x, y;
level->fieldx = MIN(level_mm->fieldx, MAX_LEV_FIELDX);
level->fieldy = MIN(level_mm->fieldy, MAX_LEV_FIELDY);
level->gems_needed = level_mm->kettles_needed;
level->auto_count_gems = level_mm->auto_count_kettles;
- level->mm_laser_red = level_mm->laser_red;
- level->mm_laser_green = level_mm->laser_green;
- level->mm_laser_blue = level_mm->laser_blue;
+ level->mm_laser_red = level_mm->mm_laser_red;
+ level->mm_laser_green = level_mm->mm_laser_green;
+ level->mm_laser_blue = level_mm->mm_laser_blue;
+
+ level->df_laser_red = level_mm->df_laser_red;
+ level->df_laser_green = level_mm->df_laser_green;
+ level->df_laser_blue = level_mm->df_laser_blue;
strcpy(level->name, level_mm->name);
level->mm_time_ball = level_mm->time_ball;
level->mm_time_block = level_mm->time_block;
+ level->num_mm_ball_contents = level_mm->num_ball_contents;
+ level->mm_ball_choice_mode = level_mm->ball_choice_mode;
+ level->rotate_mm_ball_content = level_mm->rotate_ball_content;
+ level->explode_mm_ball = level_mm->explode_ball;
+
+ for (i = 0; i < level->num_mm_ball_contents; i++)
+ level->mm_ball_content[i] =
+ map_element_MM_to_RND(level_mm->ball_content[i]);
+
for (x = 0; x < level->fieldx; x++)
for (y = 0; y < level->fieldy; y++)
level->field[x][y] = map_element_MM_to_RND(level_mm->field[x][y]);
return getMappedElement(element);
}
-static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level,
- int nr)
+static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level)
{
byte header[DC_LEVEL_HEADER_SIZE];
int envelope_size;
}
}
- LoadLevelFromFileStream_DC(file, level, level_file_info->nr);
+ LoadLevelFromFileStream_DC(file, level);
closeFile(file);
}
return EL_UNDEFINED;
}
+static void SetLevelSettings_SB(struct LevelInfo *level)
+{
+ // time settings
+ level->time = 0;
+ level->use_step_counter = TRUE;
+
+ // score settings
+ level->score[SC_TIME_BONUS] = 0;
+ level->time_score_base = 1;
+ level->rate_time_over_score = TRUE;
+
+ // game settings
+ level->auto_exit_sokoban = TRUE;
+}
+
static void LoadLevelFromFileInfo_SB(struct LevelInfo *level,
struct LevelFileInfo *level_file_info,
boolean level_info_only)
}
// set special level settings for Sokoban levels
-
- level->time = 0;
- level->use_step_counter = TRUE;
+ SetLevelSettings_SB(level);
if (load_xsb_to_ces)
{
// special global settings can now be set in level template
-
level->use_custom_template = TRUE;
}
}
void CopyNativeLevel_RND_to_Native(struct LevelInfo *level)
{
- if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
+ if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
+ CopyNativeLevel_RND_to_BD(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
CopyNativeLevel_RND_to_EM(level);
else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
CopyNativeLevel_RND_to_SP(level);
void CopyNativeLevel_Native_to_RND(struct LevelInfo *level)
{
- if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
+ if (level->game_engine_type == GAME_ENGINE_TYPE_BD)
+ CopyNativeLevel_BD_to_RND(level);
+ else if (level->game_engine_type == GAME_ENGINE_TYPE_EM)
CopyNativeLevel_EM_to_RND(level);
else if (level->game_engine_type == GAME_ENGINE_TYPE_SP)
CopyNativeLevel_SP_to_RND(level);
level->keep_walkable_ce = TRUE;
}
+static void LoadLevel_InitSettings_SB(struct LevelInfo *level)
+{
+ boolean is_sokoban_level = TRUE; // unless non-Sokoban elements found
+ int x, y;
+
+ // check if this level is (not) a Sokoban level
+ for (y = 0; y < level->fieldy; y++)
+ for (x = 0; x < level->fieldx; x++)
+ if (!IS_SB_ELEMENT(Tile[x][y]))
+ is_sokoban_level = FALSE;
+
+ if (is_sokoban_level)
+ {
+ // set special level settings for Sokoban levels
+ SetLevelSettings_SB(level);
+ }
+}
+
+static void LoadLevel_InitSettings(struct LevelInfo *level)
+{
+ // adjust level settings for (non-native) Sokoban-style levels
+ LoadLevel_InitSettings_SB(level);
+
+ // rename levels with title "nameless level" or if renaming is forced
+ if (leveldir_current->empty_level_name != NULL &&
+ (strEqual(level->name, NAMELESS_LEVEL_NAME) ||
+ leveldir_current->force_level_name))
+ snprintf(level->name, MAX_LEVEL_NAME_LEN + 1,
+ leveldir_current->empty_level_name, level_nr);
+}
+
static void LoadLevel_InitStandardElements(struct LevelInfo *level)
{
int i, x, y;
LoadLevel_InitVersion(&level_template);
LoadLevel_InitElements(&level_template);
+ LoadLevel_InitSettings(&level_template);
ActivateLevelTemplate();
}
LoadLevel_InitVersion(&level);
LoadLevel_InitElements(&level);
LoadLevel_InitPlayfield(&level);
+ LoadLevel_InitSettings(&level);
LoadLevel_InitNativeEngines(&level);
}
event_bits = 0;
for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++)
if (change->has_event[j])
- event_bits |= (1 << j);
+ event_bits |= (1u << j);
putFile32BitBE(file, event_bits);
putFile16BitBE(file, change->target_element);
event_bits = 0;
for (j = 32; j < NUM_CHANGE_EVENTS; j++)
if (change->has_event[j])
- event_bits |= (1 << (j - 32));
+ event_bits |= (1u << (j - 32));
putFile8Bit(file, event_bits);
}
}
return chunk_size;
}
+static int SaveLevel_EMPX(FILE *file, struct LevelInfo *level, int element)
+{
+ struct ElementInfo *ei = &element_info[element];
+ int chunk_size = 0;
+ int i;
+
+ chunk_size += putFile16BitBE(file, element);
+
+ xx_ei = *ei; // copy element data into temporary buffer
+
+ for (i = 0; chunk_config_EMPX[i].data_type != -1; i++)
+ chunk_size += SaveLevel_MicroChunk(file, &chunk_config_EMPX[i], FALSE);
+
+ return chunk_size;
+}
+
static void SaveLevelFromFilename(struct LevelInfo *level, char *filename,
boolean save_as_template)
{
SaveLevel_GRPX(file, level, element);
}
}
+
+ for (i = 0; i < NUM_EMPTY_ELEMENTS_ALL; i++)
+ {
+ int element = GET_EMPTY_ELEMENT(i);
+
+ chunk_size = SaveLevel_EMPX(NULL, level, element);
+ if (chunk_size > LEVEL_CHUNK_EMPX_UNCHANGED) // save if changed
+ {
+ putFileChunkBE(file, "EMPX", chunk_size);
+ SaveLevel_EMPX(file, level, element);
+ }
+ }
}
fclose(file);
Print("use step counter: %s\n", (level->use_step_counter ? "yes" : "no"));
Print("rate time over score: %s\n", (level->rate_time_over_score ? "yes" : "no"));
+ if (options.debug)
+ {
+ int i, j;
+
+ for (i = 0; i < NUM_ENVELOPES; i++)
+ {
+ char *text = level->envelope[i].text;
+ int text_len = strlen(text);
+ boolean has_text = FALSE;
+
+ for (j = 0; j < text_len; j++)
+ if (text[j] != ' ' && text[j] != '\n')
+ has_text = TRUE;
+
+ if (has_text)
+ {
+ Print("\n");
+ Print("Envelope %d:\n'%s'\n", i + 1, text);
+ }
+ }
+ }
+
PrintLine("-", 79);
}
tape.level_nr = level_nr;
tape.counter = 0;
tape.changed = FALSE;
+ tape.solved = FALSE;
tape.recording = FALSE;
tape.playing = FALSE;
tape.scr_fieldx = SCR_FIELDX_DEFAULT;
tape.scr_fieldy = SCR_FIELDY_DEFAULT;
+ tape.no_info_chunk = TRUE;
tape.no_valid_file = FALSE;
}
setTapeActionFlags(tape, getFile8Bit(file));
tape->property_bits = getFile8Bit(file);
-
- ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED);
+ tape->solved = getFile8Bit(file);
engine_version = getFileVersion(file);
if (engine_version > 0)
int level_identifier_size;
int i;
+ tape->no_info_chunk = FALSE;
+
level_identifier_size = getFile16BitBE(file);
level_identifier = checked_malloc(level_identifier_size);
byte action = tape->pos[i].action[0];
int k, num_moves = 0;
- for (k = 0; k<4; k++)
+ for (k = 0; k < 4; k++)
{
if (action & joy_dir[k])
{
CopyNativeTape_SP_to_RND(&level);
}
+void LoadScoreTape(char *score_tape_basename, int nr)
+{
+ char *filename = getScoreTapeFilename(score_tape_basename, nr);
+
+ LoadTapeFromFilename(filename);
+}
+
+void LoadScoreCacheTape(char *score_tape_basename, int nr)
+{
+ char *filename = getScoreCacheTapeFilename(score_tape_basename, nr);
+
+ LoadTapeFromFilename(filename);
+}
+
static boolean checkSaveTape_SCRN(struct TapeInfo *tape)
{
// chunk required for team mode tapes with non-default screen size
putFile8Bit(file, getTapeActionValue(tape));
putFile8Bit(file, tape->property_bits);
-
- // unused bytes not at the end here for 4-byte alignment of engine_version
- WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED);
+ putFile8Bit(file, tape->solved);
putFileVersion(file, tape->engine_version);
}
}
PrintLine("-", 79);
+
Print("Tape of Level %03d (file version %08d, game version %08d)\n",
tape->level_nr, tape->file_version, tape->game_version);
Print(" (effective engine version %08d)\n",
tape->engine_version);
Print("Level series identifier: '%s'\n", tape->level_identifier);
+
+ Print("Solution tape: %s\n",
+ tape->solved ? "yes" :
+ tape->game_version < VERSION_IDENT(4,3,2,3) ? "unknown" : "no");
+
+ Print("Special tape properties: ");
+ if (tape->property_bits == TAPE_PROPERTY_NONE)
+ Print("[none]");
+ if (tape->property_bits & TAPE_PROPERTY_EM_RANDOM_BUG)
+ Print("[em_random_bug]");
+ if (tape->property_bits & TAPE_PROPERTY_GAME_SPEED)
+ Print("[game_speed]");
+ if (tape->property_bits & TAPE_PROPERTY_PAUSE_MODE)
+ Print("[pause]");
+ if (tape->property_bits & TAPE_PROPERTY_SINGLE_STEP)
+ Print("[single_step]");
+ if (tape->property_bits & TAPE_PROPERTY_SNAPSHOT)
+ Print("[snapshot]");
+ if (tape->property_bits & TAPE_PROPERTY_REPLAYED)
+ Print("[replayed]");
+ if (tape->property_bits & TAPE_PROPERTY_TAS_KEYS)
+ Print("[tas_keys]");
+ if (tape->property_bits & TAPE_PROPERTY_SMALL_GRAPHICS)
+ Print("[small_graphics]");
+ Print("\n");
+
+ int year2 = tape->date / 10000;
+ int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
+ int month_index_raw = (tape->date / 100) % 100;
+ int month_index = month_index_raw % 12; // prevent invalid index
+ int month = month_index + 1;
+ int day = tape->date % 100;
+
+ Print("Tape date: %04d-%02d-%02d\n", year4, month, day);
+
PrintLine("-", 79);
tape_frame_counter = 0;
strcpy(scores->entry[i].name, EMPTY_PLAYER_NAME);
scores->entry[i].score = 0;
scores->entry[i].time = 0;
+
+ scores->entry[i].id = -1;
+ strcpy(scores->entry[i].tape_date, UNKNOWN_NAME);
+ strcpy(scores->entry[i].platform, UNKNOWN_NAME);
+ strcpy(scores->entry[i].version, UNKNOWN_NAME);
+ strcpy(scores->entry[i].country_name, UNKNOWN_NAME);
+ strcpy(scores->entry[i].country_code, "??");
}
scores->num_entries = 0;
scores->last_added_local = -1;
scores->updated = FALSE;
+ scores->uploaded = FALSE;
+ scores->tape_downloaded = FALSE;
scores->force_last_added = FALSE;
+
+ // The following values are intentionally not reset here:
+ // - last_level_nr
+ // - last_entry_nr
+ // - next_level_nr
+ // - continue_playing
+ // - continue_on_return
}
static void setScoreInfoToDefaults(void)
return chunk_size;
}
+static int LoadScore_SC4R(File *file, int chunk_size, struct ScoreInfo *scores)
+{
+ int i;
+
+ for (i = 0; i < scores->num_entries; i++)
+ scores->entry[i].score = getFile32BitBE(file);
+
+ chunk_size = scores->num_entries * 4;
+
+ return chunk_size;
+}
+
static int LoadScore_TIME(File *file, int chunk_size, struct ScoreInfo *scores)
{
int i;
{ "INFO", -1, LoadScore_INFO },
{ "NAME", -1, LoadScore_NAME },
{ "SCOR", -1, LoadScore_SCOR },
+ { "SC4R", -1, LoadScore_SC4R },
{ "TIME", -1, LoadScore_TIME },
{ "TAPE", -1, LoadScore_TAPE },
putFile16BitBE(file, scores->entry[i].score);
}
+static void SaveScore_SC4R(FILE *file, struct ScoreInfo *scores)
+{
+ int i;
+
+ for (i = 0; i < scores->num_entries; i++)
+ putFile32BitBE(file, scores->entry[i].score);
+}
+
static void SaveScore_TIME(FILE *file, struct ScoreInfo *scores)
{
int i;
int info_chunk_size;
int name_chunk_size;
int scor_chunk_size;
+ int sc4r_chunk_size;
int time_chunk_size;
int tape_chunk_size;
+ boolean has_large_score_values;
+ int i;
if (!(file = fopen(filename, MODE_WRITE)))
{
info_chunk_size = 2 + (strlen(scores.level_identifier) + 1) + 2 + 2;
name_chunk_size = scores.num_entries * MAX_PLAYER_NAME_LEN;
scor_chunk_size = scores.num_entries * 2;
+ sc4r_chunk_size = scores.num_entries * 4;
time_chunk_size = scores.num_entries * 4;
tape_chunk_size = scores.num_entries * MAX_SCORE_TAPE_BASENAME_LEN;
+ has_large_score_values = FALSE;
+ for (i = 0; i < scores.num_entries; i++)
+ if (scores.entry[i].score > 0xffff)
+ has_large_score_values = TRUE;
+
putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
putFileChunkBE(file, "SCOR", CHUNK_SIZE_NONE);
putFileChunkBE(file, "NAME", name_chunk_size);
SaveScore_NAME(file, &scores);
- putFileChunkBE(file, "SCOR", scor_chunk_size);
- SaveScore_SCOR(file, &scores);
+ if (has_large_score_values)
+ {
+ putFileChunkBE(file, "SC4R", sc4r_chunk_size);
+ SaveScore_SC4R(file, &scores);
+ }
+ else
+ {
+ putFileChunkBE(file, "SCOR", scor_chunk_size);
+ SaveScore_SCOR(file, &scores);
+ }
putFileChunkBE(file, "TIME", time_chunk_size);
SaveScore_TIME(file, &scores);
SaveScoreToFilename(filename);
}
-static void ExecuteAsThread(SDL_ThreadFunction function, char *name, int data,
- char *error)
-{
- static int data_static;
-
- data_static = data;
-
- SDL_Thread *thread = SDL_CreateThread(function, name, &data_static);
-
- if (thread != NULL)
- SDL_DetachThread(thread);
- else
- Error("Cannot create thread to %s!", error);
-
- // nasty kludge to lower probability of intermingled thread error messages
- Delay(1);
-}
-
-static void DownloadServerScoreToCacheExt(struct HttpRequest *request,
- struct HttpResponse *response,
- int nr)
+static void LoadServerScoreFromCache(int nr)
{
- request->hostname = setup.api_server_hostname;
- request->port = API_SERVER_PORT;
- request->method = API_SERVER_METHOD;
- request->uri = API_SERVER_URI_GET;
-
- snprintf(request->body, MAX_HTTP_BODY_SIZE,
- "{\n"
- " \"levelset_identifier\": \"%s\",\n"
- " \"level_nr\": \"%d\",\n"
- " \"rate_time_over_score\": \"%d\"\n"
- "}\n",
- levelset.identifier, nr, level.rate_time_over_score);
-
- if (!DoHttpRequest(request, response))
+ struct ScoreEntry score_entry;
+ struct
{
- Error("HTTP request failed: %s", GetHttpError());
-
- return;
+ void *value;
+ boolean is_string;
+ int string_size;
}
-
- if (!HTTP_SUCCESS(response->status_code))
+ score_mapping[] =
{
- Error("server failed to handle request: %d %s",
- response->status_code,
- response->status_text);
+ { &score_entry.score, FALSE, 0 },
+ { &score_entry.time, FALSE, 0 },
+ { score_entry.name, TRUE, MAX_PLAYER_NAME_LEN },
+ { score_entry.tape_basename, TRUE, MAX_FILENAME_LEN },
+ { score_entry.tape_date, TRUE, MAX_ISO_DATE_LEN },
+ { &score_entry.id, FALSE, 0 },
+ { score_entry.platform, TRUE, MAX_PLATFORM_TEXT_LEN },
+ { score_entry.version, TRUE, MAX_VERSION_TEXT_LEN },
+ { score_entry.country_code, TRUE, MAX_COUNTRY_CODE_LEN },
+ { score_entry.country_name, TRUE, MAX_COUNTRY_NAME_LEN },
- return;
- }
+ { NULL, FALSE, 0 }
+ };
+ char *filename = getScoreCacheFilename(nr);
+ SetupFileHash *score_hash = loadSetupFileHash(filename);
+ int i, j;
- if (response->body_size == 0)
- {
- // no scores available for this level
+ server_scores.num_entries = 0;
+ if (score_hash == NULL)
return;
- }
- ConvertHttpResponseBodyToClientEncoding(response);
-
- char *filename = getScoreCacheFilename(nr);
- FILE *file;
- int i;
-
- // used instead of "leveldir_current->subdir" (for network games)
- InitScoreCacheDirectory(levelset.identifier);
-
- if (!(file = fopen(filename, MODE_WRITE)))
+ for (i = 0; i < MAX_SCORE_ENTRIES; i++)
{
- Warn("cannot save score cache file '%s'", filename);
+ score_entry = server_scores.entry[i];
- return;
- }
+ for (j = 0; score_mapping[j].value != NULL; j++)
+ {
+ char token[10];
- for (i = 0; i < response->body_size; i++)
- fputc(response->body[i], file);
-
- fclose(file);
-
- SetFilePermissions(filename, PERMS_PRIVATE);
-
- server_scores.updated = TRUE;
-}
-
-static void DownloadServerScoreToCache(int nr)
-{
- struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
- struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
-
- DownloadServerScoreToCacheExt(request, response, nr);
-
- checked_free(request);
- checked_free(response);
-}
-
-static int DownloadServerScoreToCacheThread(void *data)
-{
- DownloadServerScoreToCache(*(int *)data);
-
- return 0;
-}
-
-static void DownloadServerScoreToCacheAsThread(int nr)
-{
- ExecuteAsThread(DownloadServerScoreToCacheThread,
- "DownloadServerScoreToCache", nr,
- "download scores from server");
-}
-
-static void LoadServerScoreFromCache(int nr)
-{
- struct ScoreEntry score_entry;
- struct
- {
- void *value;
- boolean is_string;
- int string_size;
- }
- score_mapping[] =
- {
- { &score_entry.score, FALSE, 0 },
- { &score_entry.time, FALSE, 0 },
- { score_entry.name, TRUE, MAX_PLAYER_NAME_LEN },
- { score_entry.tape_basename, TRUE, MAX_FILENAME_LEN },
-
- { NULL, FALSE, 0 }
- };
- char *filename = getScoreCacheFilename(nr);
- SetupFileHash *score_hash = loadSetupFileHash(filename);
- int i, j;
-
- server_scores.num_entries = 0;
-
- if (score_hash == NULL)
- return;
-
- for (i = 0; i < MAX_SCORE_ENTRIES; i++)
- {
- score_entry = server_scores.entry[i];
-
- for (j = 0; score_mapping[j].value != NULL; j++)
- {
- char token[10];
-
- sprintf(token, "%02d.%d", i, j);
+ sprintf(token, "%02d.%d", i, j);
char *value = getHashEntry(score_hash, token);
void LoadServerScore(int nr, boolean download_score)
{
- if (!setup.api_server)
+ if (!setup.use_api_server)
return;
// always start with reliable default values
// (this should prevent reading it while the thread is writing to it)
LoadServerScoreFromCache(nr);
- if (download_score && runtime.api_server)
+ if (download_score && runtime.use_api_server)
{
// 2nd step: download server scores from score server to cache file
// (as thread, as it might time out if the server is not reachable)
- DownloadServerScoreToCacheAsThread(nr);
+ ApiGetScoreAsThread(nr);
}
}
-static char *get_file_base64(char *filename)
+void PrepareScoreTapesForUpload(char *leveldir_subdir)
{
- struct stat file_status;
+ MarkTapeDirectoryUploadsAsIncomplete(leveldir_subdir);
- if (stat(filename, &file_status) != 0)
- {
- Error("cannot stat file '%s'\n", filename);
-
- return NULL;
- }
-
- int buffer_size = file_status.st_size;
- byte *buffer = checked_malloc(buffer_size);
- FILE *file;
- int i;
-
- if (!(file = fopen(filename, MODE_READ)))
- {
- Error("cannot open file '%s'\n", filename);
-
- checked_free(buffer);
-
- return NULL;
- }
-
- for (i = 0; i < buffer_size; i++)
- {
- int c = fgetc(file);
-
- if (c == EOF)
- {
- Error("cannot read from input file '%s'\n", filename);
+ // if score tape not uploaded, ask for uploading missing tapes later
+ if (!setup.has_remaining_tapes)
+ setup.ask_for_remaining_tapes = TRUE;
- fclose(file);
- checked_free(buffer);
+ setup.provide_uploading_tapes = TRUE;
+ setup.has_remaining_tapes = TRUE;
- return NULL;
- }
-
- buffer[i] = (byte)c;
- }
-
- fclose(file);
-
- int buffer_encoded_size = base64_encoded_size(buffer_size);
- char *buffer_encoded = checked_malloc(buffer_encoded_size);
-
- base64_encode(buffer_encoded, buffer, buffer_size);
-
- checked_free(buffer);
-
- return buffer_encoded;
+ SaveSetup_ServerSetup();
}
-static void UploadScoreToServerExt(struct HttpRequest *request,
- struct HttpResponse *response,
- int nr)
+void SaveServerScore(int nr, boolean tape_saved)
{
- struct ScoreEntry *score_entry = &scores.entry[scores.last_added];
-
- request->hostname = setup.api_server_hostname;
- request->port = API_SERVER_PORT;
- request->method = API_SERVER_METHOD;
- request->uri = API_SERVER_URI_ADD;
-
- char *tape_filename = getScoreTapeFilename(score_entry->tape_basename, nr);
- char *tape_base64 = get_file_base64(tape_filename);
-
- if (tape_base64 == NULL)
+ if (!runtime.use_api_server)
{
- Error("loading and base64 encoding score tape file failed");
+ PrepareScoreTapesForUpload(leveldir_current->subdir);
return;
}
- snprintf(request->body, MAX_HTTP_BODY_SIZE,
- "{\n"
- " \"game_version\": \"%s\",\n"
- " \"levelset_identifier\": \"%s\",\n"
- " \"levelset_name\": \"%s\",\n"
- " \"levelset_author\": \"%s\",\n"
- " \"levelset_num_levels\": \"%d\",\n"
- " \"levelset_first_level\": \"%d\",\n"
- " \"level_nr\": \"%d\",\n"
- " \"player_name\": \"%s\",\n"
- " \"score\": \"%d\",\n"
- " \"time\": \"%d\",\n"
- " \"tape_basename\": \"%s\",\n"
- " \"tape\": \"%s\"\n"
- "}\n",
- getProgramRealVersionString(),
- leveldir_current->identifier,
- leveldir_current->name,
- leveldir_current->author,
- leveldir_current->levels,
- leveldir_current->first_level,
- level_nr,
- score_entry->name,
- score_entry->score,
- score_entry->time,
- score_entry->tape_basename,
- tape_base64);
-
- checked_free(tape_base64);
-
- ConvertHttpRequestBodyToServerEncoding(request);
-
- if (!DoHttpRequest(request, response))
- {
- Error("HTTP request failed: %s", GetHttpError());
-
- return;
- }
-
- if (!HTTP_SUCCESS(response->status_code))
- {
- Error("server failed to handle request: %d %s",
- response->status_code,
- response->status_text);
-
- return;
- }
-}
-
-static void UploadScoreToServer(int nr)
-{
- struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest));
- struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
-
- UploadScoreToServerExt(request, response, nr);
-
- checked_free(request);
- checked_free(response);
-}
-
-static int UploadScoreToServerThread(void *data)
-{
- UploadScoreToServer(*(int *)data);
-
- return 0;
+ ApiAddScoreAsThread(nr, tape_saved, NULL);
}
-static void UploadScoreToServerAsThread(int nr)
+void SaveServerScoreFromFile(int nr, boolean tape_saved,
+ char *score_tape_filename)
{
- ExecuteAsThread(UploadScoreToServerThread,
- "UploadScoreToServer", nr,
- "upload score to server");
-}
-
-void SaveServerScore(int nr)
-{
- if (!runtime.api_server)
+ if (!runtime.use_api_server)
return;
- UploadScoreToServerAsThread(nr);
+ ApiAddScoreAsThread(nr, tape_saved, score_tape_filename);
}
void LoadLocalAndServerScore(int nr, boolean download_score)
{
int last_added_local = scores.last_added_local;
+ boolean force_last_added = scores.force_last_added;
- LoadScore(nr);
+ // needed if only showing server scores
+ setScoreInfoToDefaults();
+
+ if (!strEqual(setup.scores_in_highscore_list, STR_SCORES_TYPE_SERVER_ONLY))
+ LoadScore(nr);
// restore last added local score entry (before merging server scores)
scores.last_added = scores.last_added_local = last_added_local;
- if (setup.api_server && !setup.only_show_local_scores)
+ if (setup.use_api_server &&
+ !strEqual(setup.scores_in_highscore_list, STR_SCORES_TYPE_LOCAL_ONLY))
{
// load server scores from cache file and trigger update from server
LoadServerScore(nr, download_score);
// merge local scores with scores from server
MergeServerScore();
}
+
+ if (force_last_added)
+ scores.force_last_added = force_last_added;
}
TYPE_SWITCH,
&setup.toons, "toons"
},
+ {
+ TYPE_SWITCH,
+ &setup.global_animations, "global_animations"
+ },
{
TYPE_SWITCH,
&setup.scroll_delay, "scroll_delay"
TYPE_SWITCH,
&setup.autorecord, "automatic_tape_recording"
},
+ {
+ TYPE_SWITCH,
+ &setup.autorecord_after_replay, "autorecord_after_replay"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.auto_pause_on_start, "auto_pause_on_start"
+ },
{
TYPE_SWITCH,
&setup.show_titlescreen, "show_titlescreen"
},
{
TYPE_SWITCH,
- &setup.show_snapshot_buttons, "show_snapshot_buttons"
+ &setup.show_load_save_buttons, "show_load_save_buttons"
},
{
TYPE_SWITCH,
- &setup.only_show_local_scores, "only_show_local_scores"
+ &setup.show_undo_redo_buttons, "show_undo_redo_buttons"
+ },
+ {
+ TYPE_STRING,
+ &setup.scores_in_highscore_list, "scores_in_highscore_list"
},
{
TYPE_STRING,
TYPE_STRING,
&setup.network_server_hostname, "network_server_hostname"
},
- {
- TYPE_SWITCH,
- &setup.api_server, "api_server"
- },
- {
- TYPE_STRING,
- &setup.api_server_hostname, "api_server_hostname"
- },
{
TYPE_STRING,
&setup.touch.control_type, "touch.control_type"
TYPE_INTEGER,
&setup.touch.grid_ysize[1], "touch.virtual_buttons.1.ysize"
},
+ {
+ TYPE_SWITCH,
+ &setup.touch.overlay_buttons, "touch.overlay_buttons"
+ },
};
static struct TokenInfo auto_setup_tokens[] =
},
};
+static struct TokenInfo server_setup_tokens[] =
+{
+ {
+ TYPE_STRING,
+ &setup.player_uuid, "player_uuid"
+ },
+ {
+ TYPE_INTEGER,
+ &setup.player_version, "player_version"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.use_api_server, TEST_PREFIX "use_api_server"
+ },
+ {
+ TYPE_STRING,
+ &setup.api_server_hostname, TEST_PREFIX "api_server_hostname"
+ },
+ {
+ TYPE_STRING,
+ &setup.api_server_password, TEST_PREFIX "api_server_password"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_for_uploading_tapes, TEST_PREFIX "ask_for_uploading_tapes"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_for_remaining_tapes, TEST_PREFIX "ask_for_remaining_tapes"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.provide_uploading_tapes, TEST_PREFIX "provide_uploading_tapes"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.ask_for_using_api_server,TEST_PREFIX "ask_for_using_api_server"
+ },
+ {
+ TYPE_SWITCH,
+ &setup.has_remaining_tapes, TEST_PREFIX "has_remaining_tapes"
+ },
+};
+
static struct TokenInfo editor_setup_tokens[] =
{
{
TYPE_SWITCH,
&setup.editor_cascade.el_ge, "editor.cascade.el_ge"
},
+ {
+ TYPE_SWITCH,
+ &setup.editor_cascade.el_es, "editor.cascade.el_es"
+ },
{
TYPE_SWITCH,
&setup.editor_cascade.el_ref, "editor.cascade.el_ref"
TYPE_KEY_X11,
&setup.shortcut.load_game, "shortcut.load_game"
},
+ {
+ TYPE_KEY_X11,
+ &setup.shortcut.restart_game, "shortcut.restart_game"
+ },
+ {
+ TYPE_KEY_X11,
+ &setup.shortcut.pause_before_end, "shortcut.pause_before_end"
+ },
{
TYPE_KEY_X11,
&setup.shortcut.toggle_pause, "shortcut.toggle_pause"
TYPE_BOOLEAN,
&setup.internal.create_user_levelset, "create_user_levelset"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_screens_from_main, "info_screens_from_main"
+ },
{
TYPE_BOOLEAN,
&setup.internal.menu_game, "menu_game"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_engines, "menu_engines"
+ },
{
TYPE_BOOLEAN,
&setup.internal.menu_editor, "menu_editor"
TYPE_BOOLEAN,
&setup.internal.menu_save_and_exit, "menu_save_and_exit"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_various, "menu_shortcuts_various"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_focus, "menu_shortcuts_focus"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_tape, "menu_shortcuts_tape"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_sound, "menu_shortcuts_sound"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.menu_shortcuts_snap, "menu_shortcuts_snap"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_title, "info_title"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_elements, "info_elements"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_music, "info_music"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_credits, "info_credits"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_program, "info_program"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_version, "info_version"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_levelset, "info_levelset"
+ },
+ {
+ TYPE_BOOLEAN,
+ &setup.internal.info_exit, "info_exit"
+ },
};
static struct TokenInfo debug_setup_tokens[] =
TYPE_BOOLEAN,
&setup.options.verbose, "options.verbose"
},
+ {
+ TYPE_BOOLEAN,
+ &setup.options.debug, "options.debug"
+ },
+ {
+ TYPE_STRING,
+ &setup.options.debug_mode, "options.debug_mode"
+ },
};
static void setSetupInfoToDefaults(struct SetupInfo *si)
si->sound_music = TRUE;
si->sound_simple = TRUE;
si->toons = TRUE;
+ si->global_animations = TRUE;
si->scroll_delay = TRUE;
si->forced_scroll_delay = FALSE;
si->scroll_delay_value = STD_SCROLL_DELAY;
si->engine_snapshot_memory = SNAPSHOT_MEMORY_DEFAULT;
si->fade_screens = TRUE;
si->autorecord = TRUE;
+ si->autorecord_after_replay = TRUE;
+ si->auto_pause_on_start = FALSE;
si->show_titlescreen = TRUE;
si->quick_doors = FALSE;
si->team_mode = FALSE;
si->game_frame_delay = GAME_FRAME_DELAY;
si->sp_show_border_elements = FALSE;
si->small_game_graphics = FALSE;
- si->show_snapshot_buttons = FALSE;
- si->only_show_local_scores = FALSE;
+ si->show_load_save_buttons = FALSE;
+ si->show_undo_redo_buttons = FALSE;
+ si->scores_in_highscore_list = getStringCopy(STR_SCORES_TYPE_DEFAULT);
si->graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR);
si->sounds_set = getStringCopy(SND_CLASSIC_SUBDIR);
si->network_player_nr = 0; // first player
si->network_server_hostname = getStringCopy(STR_NETWORK_AUTO_DETECT);
- si->api_server = TRUE;
- si->api_server_hostname = getStringCopy(API_SERVER_HOSTNAME);
-
si->touch.control_type = getStringCopy(TOUCH_CONTROL_DEFAULT);
si->touch.move_distance = TOUCH_MOVE_DISTANCE_DEFAULT; // percent
si->touch.drop_distance = TOUCH_DROP_DISTANCE_DEFAULT; // percent
si->touch.grid_initialized = video.initialized;
+ si->touch.overlay_buttons = FALSE;
+
si->editor.el_boulderdash = TRUE;
si->editor.el_emerald_mine = TRUE;
si->editor.el_emerald_mine_club = TRUE;
si->shortcut.save_game = DEFAULT_KEY_SAVE_GAME;
si->shortcut.load_game = DEFAULT_KEY_LOAD_GAME;
+ si->shortcut.restart_game = DEFAULT_KEY_RESTART_GAME;
+ si->shortcut.pause_before_end = DEFAULT_KEY_PAUSE_BEFORE_END;
si->shortcut.toggle_pause = DEFAULT_KEY_TOGGLE_PAUSE;
si->shortcut.focus_player[0] = DEFAULT_KEY_FOCUS_PLAYER_1;
for (i = 0; i < MAX_PLAYERS; i++)
{
si->input[i].use_joystick = FALSE;
- si->input[i].joy.device_name=getStringCopy(getDeviceNameFromJoystickNr(i));
+ si->input[i].joy.device_name = getStringCopy(getDeviceNameFromJoystickNr(i));
si->input[i].joy.xleft = JOYSTICK_XLEFT;
si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
si->input[i].joy.xright = JOYSTICK_XRIGHT;
si->internal.choose_from_top_leveldir = FALSE;
si->internal.show_scaling_in_title = TRUE;
si->internal.create_user_levelset = TRUE;
+ si->internal.info_screens_from_main = FALSE;
si->internal.default_window_width = WIN_XSIZE_DEFAULT;
si->internal.default_window_height = WIN_YSIZE_DEFAULT;
si->debug.xsn_percent = 0;
si->options.verbose = FALSE;
+ si->options.debug = FALSE;
+ si->options.debug_mode = getStringCopy(ARG_UNDEFINED_STRING);
#if defined(PLATFORM_ANDROID)
si->fullscreen = TRUE;
+ si->touch.overlay_buttons = TRUE;
#endif
setHideSetupEntry(&setup.debug.xsn_mode);
si->auto_setup.editor_zoom_tilesize = MINI_TILESIZE;
}
+static void setSetupInfoToDefaults_ServerSetup(struct SetupInfo *si)
+{
+ si->player_uuid = NULL; // (will be set later)
+ si->player_version = 1; // (will be set later)
+
+ si->use_api_server = TRUE;
+ si->api_server_hostname = getStringCopy(API_SERVER_HOSTNAME);
+ si->api_server_password = getStringCopy(UNDEFINED_PASSWORD);
+ si->ask_for_uploading_tapes = TRUE;
+ si->ask_for_remaining_tapes = FALSE;
+ si->provide_uploading_tapes = TRUE;
+ si->ask_for_using_api_server = TRUE;
+ si->has_remaining_tapes = FALSE;
+}
+
static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si)
{
si->editor_cascade.el_bd = TRUE;
si->editor_cascade.el_steel_chars = FALSE;
si->editor_cascade.el_ce = FALSE;
si->editor_cascade.el_ge = FALSE;
+ si->editor_cascade.el_es = FALSE;
si->editor_cascade.el_ref = FALSE;
si->editor_cascade.el_user = FALSE;
si->editor_cascade.el_dynamic = FALSE;
token_info[token_nr].text);
}
-static void decodeSetupFileHash(SetupFileHash *setup_file_hash)
+static void decodeSetupFileHash_Default(SetupFileHash *setup_file_hash)
{
int i, pnr;
auto_setup_tokens[i].text));
}
+static void decodeSetupFileHash_ServerSetup(SetupFileHash *setup_file_hash)
+{
+ int i;
+
+ if (!setup_file_hash)
+ return;
+
+ for (i = 0; i < ARRAY_SIZE(server_setup_tokens); i++)
+ setSetupInfo(server_setup_tokens, i,
+ getHashEntry(setup_file_hash,
+ server_setup_tokens[i].text));
+}
+
static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash)
{
int i;
if (setup_file_hash)
{
- decodeSetupFileHash(setup_file_hash);
+ decodeSetupFileHash_Default(setup_file_hash);
freeSetupFileHash(setup_file_hash);
}
MIN(MAX(MIN_SCROLL_DELAY, setup.scroll_delay_value), MAX_SCROLL_DELAY);
}
-void LoadSetup(void)
+void LoadSetup_Default(void)
{
char *filename;
// try to load setup values from default setup file
filename = getDefaultSetupFilename();
+ if (fileExists(filename))
+ LoadSetupFromFilename(filename);
+
+ // try to load setup values from platform setup file
+ filename = getPlatformSetupFilename();
+
if (fileExists(filename))
LoadSetupFromFilename(filename);
free(filename);
}
+void LoadSetup_ServerSetup(void)
+{
+ char *filename = getPath2(getSetupDir(), SERVERSETUP_FILENAME);
+ SetupFileHash *setup_file_hash = NULL;
+
+ // always start with reliable default values
+ setSetupInfoToDefaults_ServerSetup(&setup);
+
+ setup_file_hash = loadSetupFileHash(filename);
+
+ if (setup_file_hash)
+ {
+ decodeSetupFileHash_ServerSetup(setup_file_hash);
+
+ freeSetupFileHash(setup_file_hash);
+ }
+
+ free(filename);
+
+ if (setup.player_uuid == NULL)
+ {
+ // player UUID does not yet exist in setup file
+ setup.player_uuid = getStringCopy(getUUID());
+ setup.player_version = 2;
+
+ SaveSetup_ServerSetup();
+ }
+}
+
void LoadSetup_EditorCascade(void)
{
char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME);
free(filename);
}
+void LoadSetup(void)
+{
+ LoadSetup_Default();
+ LoadSetup_AutoSetup();
+ LoadSetup_ServerSetup();
+ LoadSetup_EditorCascade();
+}
+
static void addGameControllerMappingToHash(SetupFileHash *mappings_hash,
char *mapping_line)
{
fclose(file);
}
-void SaveSetup(void)
+void SaveSetup_Default(void)
{
char *filename = getSetupFilename();
FILE *file;
global_setup_tokens[i].value == &setup.graphics_set ||
global_setup_tokens[i].value == &setup.volume_simple ||
global_setup_tokens[i].value == &setup.network_mode ||
- global_setup_tokens[i].value == &setup.api_server ||
global_setup_tokens[i].value == &setup.touch.control_type ||
global_setup_tokens[i].value == &setup.touch.grid_xsize[0] ||
global_setup_tokens[i].value == &setup.touch.grid_xsize[1])
setup.debug.xsn_mode != AUTO)
fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i));
- fprintf(file, "\n");
- for (i = 0; i < ARRAY_SIZE(options_setup_tokens); i++)
- fprintf(file, "%s\n", getSetupLine(options_setup_tokens, "", i));
+ fprintf(file, "\n");
+ for (i = 0; i < ARRAY_SIZE(options_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(options_setup_tokens, "", i));
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+}
+
+void SaveSetup_AutoSetup(void)
+{
+ char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME);
+ FILE *file;
+ int i;
+
+ InitUserDataDirectory();
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Warn("cannot write auto setup file '%s'", filename);
+
+ free(filename);
+
+ return;
+ }
+
+ fprintFileHeader(file, AUTOSETUP_FILENAME);
+
+ for (i = 0; i < ARRAY_SIZE(auto_setup_tokens); i++)
+ fprintf(file, "%s\n", getSetupLine(auto_setup_tokens, "", i));
fclose(file);
SetFilePermissions(filename, PERMS_PRIVATE);
+
+ free(filename);
}
-void SaveSetup_AutoSetup(void)
+void SaveSetup_ServerSetup(void)
{
- char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME);
+ char *filename = getPath2(getSetupDir(), SERVERSETUP_FILENAME);
FILE *file;
int i;
if (!(file = fopen(filename, MODE_WRITE)))
{
- Warn("cannot write auto setup file '%s'", filename);
+ Warn("cannot write server setup file '%s'", filename);
free(filename);
return;
}
- fprintFileHeader(file, AUTOSETUP_FILENAME);
+ fprintFileHeader(file, SERVERSETUP_FILENAME);
- for (i = 0; i < ARRAY_SIZE(auto_setup_tokens); i++)
- fprintf(file, "%s\n", getSetupLine(auto_setup_tokens, "", i));
+ for (i = 0; i < ARRAY_SIZE(server_setup_tokens); i++)
+ {
+ // just to make things nicer :)
+ if (server_setup_tokens[i].value == &setup.use_api_server)
+ fprintf(file, "\n");
+
+ fprintf(file, "%s\n", getSetupLine(server_setup_tokens, "", i));
+ }
fclose(file);
free(filename);
}
+void SaveSetup(void)
+{
+ SaveSetup_Default();
+ SaveSetup_AutoSetup();
+ SaveSetup_ServerSetup();
+ SaveSetup_EditorCascade();
+}
+
static void SaveSetup_WriteGameControllerMappings(SetupFileHash *mappings_hash,
char *filename)
{
char next_char = s[strlen(s_contained)];
// check if next character is delimiter or whitespace
- return (next_char == ',' || next_char == '\0' ||
- next_char == ' ' || next_char == '\t' ? TRUE : FALSE);
+ if (next_char == ',' || next_char == '\0' ||
+ next_char == ' ' || next_char == '\t')
+ return TRUE;
}
// check if string contains another parameter string after a comma
return string_has_parameter(substring, s_contained);
}
+static int get_anim_parameter_value_ce(char *s)
+{
+ char *s_ptr = s;
+ char *pattern_1 = "ce_change:custom_";
+ char *pattern_2 = ".page_";
+ int pattern_1_len = strlen(pattern_1);
+ char *matching_char = strstr(s_ptr, pattern_1);
+ int result = ANIM_EVENT_NONE;
+
+ if (matching_char == NULL)
+ return ANIM_EVENT_NONE;
+
+ result = ANIM_EVENT_CE_CHANGE;
+
+ s_ptr = matching_char + pattern_1_len;
+
+ // check for custom element number ("custom_X", "custom_XX" or "custom_XXX")
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ {
+ int gic_ce_nr = (*s_ptr++ - '0');
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ {
+ gic_ce_nr = 10 * gic_ce_nr + (*s_ptr++ - '0');
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ gic_ce_nr = 10 * gic_ce_nr + (*s_ptr++ - '0');
+ }
+
+ if (gic_ce_nr < 1 || gic_ce_nr > NUM_CUSTOM_ELEMENTS)
+ return ANIM_EVENT_NONE;
+
+ // custom element stored as 0 to 255
+ gic_ce_nr--;
+
+ result |= gic_ce_nr << ANIM_EVENT_CE_BIT;
+ }
+ else
+ {
+ // invalid custom element number specified
+
+ return ANIM_EVENT_NONE;
+ }
+
+ // check for change page number ("page_X" or "page_XX") (optional)
+ if (strPrefix(s_ptr, pattern_2))
+ {
+ s_ptr += strlen(pattern_2);
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ {
+ int gic_page_nr = (*s_ptr++ - '0');
+
+ if (*s_ptr >= '0' && *s_ptr <= '9')
+ gic_page_nr = 10 * gic_page_nr + (*s_ptr++ - '0');
+
+ if (gic_page_nr < 1 || gic_page_nr > MAX_CHANGE_PAGES)
+ return ANIM_EVENT_NONE;
+
+ // change page stored as 1 to 32 (0 means "all change pages")
+
+ result |= gic_page_nr << ANIM_EVENT_PAGE_BIT;
+ }
+ else
+ {
+ // invalid animation part number specified
+
+ return ANIM_EVENT_NONE;
+ }
+ }
+
+ // discard result if next character is neither delimiter nor whitespace
+ if (!(*s_ptr == ',' || *s_ptr == '\0' ||
+ *s_ptr == ' ' || *s_ptr == '\t'))
+ return ANIM_EVENT_NONE;
+
+ return result;
+}
+
static int get_anim_parameter_value(char *s)
{
int event_value[] =
int result = ANIM_EVENT_NONE;
int i;
+ result = get_anim_parameter_value_ce(s);
+
+ if (result != ANIM_EVENT_NONE)
+ return result;
+
for (i = 0; i < ARRAY_SIZE(event_value); i++)
{
matching_char = strstr(s_ptr, pattern_1[i]);
result = -(int)key;
}
+ if (result == -1)
+ {
+ if (isURL(token))
+ {
+ result = get_hash_from_key(token); // unsigned int => int
+ result = ABS(result); // may be negative now
+ result += (result < MAX_IMAGE_FILES ? MAX_IMAGE_FILES : 0);
+
+ setHashEntry(anim_url_hash, int2str(result, 0), token);
+ }
+ }
+
if (result == -1)
result = ANIM_EVENT_ACTION_NONE;
strEqual(value, "lower") ? POS_LOWER :
strEqual(value, "bottom") ? POS_BOTTOM :
strEqual(value, "any") ? POS_ANY :
+ strEqual(value, "ce") ? POS_CE :
+ strEqual(value, "ce_trigger") ? POS_CE_TRIGGER :
strEqual(value, "last") ? POS_LAST : POS_UNDEFINED);
}
else if (strEqual(suffix, ".align"))
string_has_parameter(value, "pingpong") ? ANIM_PINGPONG :
string_has_parameter(value, "pingpong2") ? ANIM_PINGPONG2 :
string_has_parameter(value, "random") ? ANIM_RANDOM :
+ string_has_parameter(value, "random_static") ? ANIM_RANDOM_STATIC :
string_has_parameter(value, "ce_value") ? ANIM_CE_VALUE :
string_has_parameter(value, "ce_score") ? ANIM_CE_SCORE :
string_has_parameter(value, "ce_delay") ? ANIM_CE_DELAY :
string_has_parameter(value, "vertical") ? ANIM_VERTICAL :
string_has_parameter(value, "centered") ? ANIM_CENTERED :
string_has_parameter(value, "all") ? ANIM_ALL :
+ string_has_parameter(value, "tiled") ? ANIM_TILED :
+ string_has_parameter(value, "level_nr") ? ANIM_LEVEL_NR :
ANIM_DEFAULT);
if (string_has_parameter(value, "once"))
if (string_has_parameter(value, "multiple_actions"))
result |= STYLE_MULTIPLE_ACTIONS;
+
+ if (string_has_parameter(value, "consume_ce_event"))
+ result |= STYLE_CONSUME_CE_EVENT;
}
else if (strEqual(suffix, ".fade_mode"))
{
result = (string_has_parameter(value, "none") ? FADE_MODE_NONE :
string_has_parameter(value, "fade") ? FADE_MODE_FADE :
+ string_has_parameter(value, "fade_in") ? FADE_MODE_FADE_IN :
+ string_has_parameter(value, "fade_out") ? FADE_MODE_FADE_OUT :
string_has_parameter(value, "crossfade") ? FADE_MODE_CROSSFADE :
string_has_parameter(value, "melt") ? FADE_MODE_MELT :
string_has_parameter(value, "curtain") ? FADE_MODE_CURTAIN :
return get_parameter_value(value_raw, suffix, TYPE_INTEGER);
}
-void InitMenuDesignSettings_Static(void)
+void InitMenuDesignSettings_FromHash(SetupFileHash *setup_file_hash,
+ boolean ignore_defaults)
{
int i;
- // always start with reliable default values from static default config
for (i = 0; image_config_vars[i].token != NULL; i++)
{
- char *value = getHashEntry(image_config_hash, image_config_vars[i].token);
+ char *value = getHashEntry(setup_file_hash, image_config_vars[i].token);
+
+ // (ignore definitions set to "[DEFAULT]" which are already initialized)
+ if (ignore_defaults && strEqual(value, ARG_DEFAULT))
+ continue;
if (value != NULL)
*image_config_vars[i].value =
}
}
+void InitMenuDesignSettings_Static(void)
+{
+ // always start with reliable default values from static default config
+ InitMenuDesignSettings_FromHash(image_config_hash, FALSE);
+}
+
static void InitMenuDesignSettings_SpecialPreProcessing(void)
{
int i;
vp_playfield->width = MIN(vp_playfield->width, vp_playfield->max_width);
if (vp_playfield->max_height != -1)
- vp_playfield->height = MIN(vp_playfield->height,vp_playfield->max_height);
+ vp_playfield->height = MIN(vp_playfield->height, vp_playfield->max_height);
// adjust playfield position according to specified alignment
}
}
+static void InitMenuDesignSettings_PreviewPlayers_Ext(SetupFileHash *hash,
+ boolean initialize)
+{
+ // special case: check if network and preview player positions are redefined,
+ // to compare this later against the main menu level preview being redefined
+ struct TokenIntPtrInfo menu_config_players[] =
+ {
+ { "main.network_players.x", &menu.main.network_players.redefined },
+ { "main.network_players.y", &menu.main.network_players.redefined },
+ { "main.preview_players.x", &menu.main.preview_players.redefined },
+ { "main.preview_players.y", &menu.main.preview_players.redefined },
+ { "preview.x", &preview.redefined },
+ { "preview.y", &preview.redefined }
+ };
+ int i;
+
+ if (initialize)
+ {
+ for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
+ *menu_config_players[i].value = FALSE;
+ }
+ else
+ {
+ for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
+ if (getHashEntry(hash, menu_config_players[i].token) != NULL)
+ *menu_config_players[i].value = TRUE;
+ }
+}
+
+static void InitMenuDesignSettings_PreviewPlayers(void)
+{
+ InitMenuDesignSettings_PreviewPlayers_Ext(NULL, TRUE);
+}
+
+static void InitMenuDesignSettings_PreviewPlayers_FromHash(SetupFileHash *hash)
+{
+ InitMenuDesignSettings_PreviewPlayers_Ext(hash, FALSE);
+}
+
static void LoadMenuDesignSettingsFromFilename(char *filename)
{
static struct TitleFadingInfo tfi;
{
{ "menu.draw_xoffset.INFO", &menu.draw_xoffset_info[i] },
{ "menu.draw_yoffset.INFO", &menu.draw_yoffset_info[i] },
- { "menu.list_size.INFO", &menu.list_size_info[i] }
+ { "menu.list_size.INFO", &menu.list_size_info[i] },
+ { "menu.list_entry_size.INFO", &menu.list_entry_size_info[i] },
+ { "menu.tile_size.INFO", &menu.tile_size_info[i] }
};
for (j = 0; j < ARRAY_SIZE(menu_config); j++)
struct TokenIntPtrInfo menu_config[] =
{
{ "menu.left_spacing.INFO", &menu.left_spacing_info[i] },
+ { "menu.middle_spacing.INFO", &menu.middle_spacing_info[i] },
{ "menu.right_spacing.INFO", &menu.right_spacing_info[i] },
{ "menu.top_spacing.INFO", &menu.top_spacing_info[i] },
{ "menu.bottom_spacing.INFO", &menu.bottom_spacing_info[i] },
}
}
- // special case: check if network and preview player positions are redefined,
- // to compare this later against the main menu level preview being redefined
- struct TokenIntPtrInfo menu_config_players[] =
- {
- { "main.network_players.x", &menu.main.network_players.redefined },
- { "main.network_players.y", &menu.main.network_players.redefined },
- { "main.preview_players.x", &menu.main.preview_players.redefined },
- { "main.preview_players.y", &menu.main.preview_players.redefined },
- { "preview.x", &preview.redefined },
- { "preview.y", &preview.redefined }
- };
-
- for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
- *menu_config_players[i].value = FALSE;
-
- for (i = 0; i < ARRAY_SIZE(menu_config_players); i++)
- if (getHashEntry(setup_file_hash, menu_config_players[i].token) != NULL)
- *menu_config_players[i].value = TRUE;
-
// read (and overwrite with) values that may be specified in config file
- for (i = 0; image_config_vars[i].token != NULL; i++)
- {
- char *value = getHashEntry(setup_file_hash, image_config_vars[i].token);
+ InitMenuDesignSettings_FromHash(setup_file_hash, TRUE);
- // (ignore definitions set to "[DEFAULT]" which are already initialized)
- if (value != NULL && !strEqual(value, ARG_DEFAULT))
- *image_config_vars[i].value =
- get_token_parameter_value(image_config_vars[i].token, value);
- }
+ // special case: check if network and preview player positions are redefined
+ InitMenuDesignSettings_PreviewPlayers_FromHash(setup_file_hash);
freeSetupFileHash(setup_file_hash);
}
InitMenuDesignSettings_Static();
InitMenuDesignSettings_SpecialPreProcessing();
+ InitMenuDesignSettings_PreviewPlayers();
if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_GRAPHICS))
{
InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics();
}
+void InitSoundSettings_FromHash(SetupFileHash *setup_file_hash,
+ boolean ignore_defaults)
+{
+ int i;
+
+ for (i = 0; sound_config_vars[i].token != NULL; i++)
+ {
+ char *value = getHashEntry(setup_file_hash, sound_config_vars[i].token);
+
+ // (ignore definitions set to "[DEFAULT]" which are already initialized)
+ if (ignore_defaults && strEqual(value, ARG_DEFAULT))
+ continue;
+
+ if (value != NULL)
+ *sound_config_vars[i].value =
+ get_token_parameter_value(sound_config_vars[i].token, value);
+ }
+}
+
+void InitSoundSettings_Static(void)
+{
+ // always start with reliable default values from static default config
+ InitSoundSettings_FromHash(sound_config_hash, FALSE);
+}
+
+static void LoadSoundSettingsFromFilename(char *filename)
+{
+ SetupFileHash *setup_file_hash;
+
+ if ((setup_file_hash = loadSetupFileHash(filename)) == NULL)
+ return;
+
+ // read (and overwrite with) values that may be specified in config file
+ InitSoundSettings_FromHash(setup_file_hash, TRUE);
+
+ freeSetupFileHash(setup_file_hash);
+}
+
+void LoadSoundSettings(void)
+{
+ char *filename_base = UNDEFINED_FILENAME, *filename_local;
+
+ InitSoundSettings_Static();
+
+ if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_SOUNDS))
+ {
+ // first look for special settings configured in level series config
+ filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+ if (fileExists(filename_base))
+ LoadSoundSettingsFromFilename(filename_base);
+ }
+
+ filename_local = getCustomArtworkConfigFilename(ARTWORK_TYPE_SOUNDS);
+
+ if (filename_local != NULL && !strEqual(filename_base, filename_local))
+ LoadSoundSettingsFromFilename(filename_local);
+}
+
void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
{
char *filename = getEditorSetupFilename();
{ "artist_header", &tmp_music_file_info.artist_header },
{ "album_header", &tmp_music_file_info.album_header },
{ "year_header", &tmp_music_file_info.year_header },
+ { "played_header", &tmp_music_file_info.played_header },
{ "title", &tmp_music_file_info.title },
{ "artist", &tmp_music_file_info.artist },
{ "album", &tmp_music_file_info.album },
{ "year", &tmp_music_file_info.year },
+ { "played", &tmp_music_file_info.played },
{ NULL, NULL },
};
void LoadMusicInfo(void)
{
- char *music_directory = getCustomMusicDirectory();
+ int num_music_noconf = getMusicListSize_NoConf();
int num_music = getMusicListSize();
- int num_music_noconf = 0;
int num_sounds = getSoundListSize();
- Directory *dir;
- DirectoryEntry *dir_entry;
struct FileInfo *music, *sound;
struct MusicFileInfo *next, **new;
+
int i;
while (music_file_info != NULL)
checked_free(music_file_info->artist_header);
checked_free(music_file_info->album_header);
checked_free(music_file_info->year_header);
+ checked_free(music_file_info->played_header);
checked_free(music_file_info->title);
checked_free(music_file_info->artist);
checked_free(music_file_info->album);
checked_free(music_file_info->year);
+ checked_free(music_file_info->played);
free(music_file_info);
new = &music_file_info;
- for (i = 0; i < num_music; i++)
+ // get (configured or unconfigured) music file info for all levels
+ for (i = leveldir_current->first_level;
+ i <= leveldir_current->last_level; i++)
{
- music = getMusicListEntry(i);
+ int music_nr;
- if (music->filename == NULL)
- continue;
+ if (levelset.music[i] != MUS_UNDEFINED)
+ {
+ // get music file info for configured level music
+ music_nr = levelset.music[i];
+ }
+ else if (num_music_noconf > 0)
+ {
+ // get music file info for unconfigured level music
+ int level_pos = i - leveldir_current->first_level;
- if (strEqual(music->filename, UNDEFINED_FILENAME))
+ music_nr = MAP_NOCONF_MUSIC(level_pos % num_music_noconf);
+ }
+ else
+ {
continue;
+ }
- // a configured file may be not recognized as music
- if (!FileIsMusic(music->filename))
+ char *basename = getMusicInfoEntryFilename(music_nr);
+
+ if (basename == NULL)
continue;
- if (!music_info_listed(music_file_info, music->filename))
+ if (!music_info_listed(music_file_info, basename))
{
- *new = get_music_file_info(music->filename, i);
+ *new = get_music_file_info(basename, music_nr);
if (*new != NULL)
new = &(*new)->next;
}
}
- if ((dir = openDirectory(music_directory)) == NULL)
- {
- Warn("cannot read music directory '%s'", music_directory);
-
- return;
- }
-
- while ((dir_entry = readDirectory(dir)) != NULL) // loop all entries
+ // get music file info for all remaining configured music files
+ for (i = 0; i < num_music; i++)
{
- char *basename = dir_entry->basename;
- boolean music_already_used = FALSE;
- int i;
-
- // skip all music files that are configured in music config file
- for (i = 0; i < num_music; i++)
- {
- music = getMusicListEntry(i);
-
- if (music->filename == NULL)
- continue;
+ music = getMusicListEntry(i);
- if (strEqual(basename, music->filename))
- {
- music_already_used = TRUE;
- break;
- }
- }
+ if (music->filename == NULL)
+ continue;
- if (music_already_used)
+ if (strEqual(music->filename, UNDEFINED_FILENAME))
continue;
- if (!FileIsMusic(dir_entry->filename))
+ // a configured file may be not recognized as music
+ if (!FileIsMusic(music->filename))
continue;
- if (!music_info_listed(music_file_info, basename))
+ if (!music_info_listed(music_file_info, music->filename))
{
- *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf));
+ *new = get_music_file_info(music->filename, i);
if (*new != NULL)
new = &(*new)->next;
}
-
- num_music_noconf++;
}
- closeDirectory(dir);
-
+ // get sound file info for all configured sound files
for (i = 0; i < num_sounds; i++)
{
sound = getSoundListEntry(i);
new = &(*new)->next;
}
}
+
+ // add pointers to previous list nodes
+
+ struct MusicFileInfo *node = music_file_info;
+
+ while (node != NULL)
+ {
+ if (node->next)
+ node->next->prev = node;
+
+ node = node->next;
+ }
}
static void add_helpanim_entry(int element, int action, int direction,
Print("converting level ... ");
+#if 0
+ // special case: conversion of some EMC levels as requested by ACME
+ level.game_engine_type = GAME_ENGINE_TYPE_RND;
+#endif
+
level_filename = getDefaultLevelFilename(level_nr);
new_level = !fileExists(level_filename);
int dst_width = anim_width * 2;
int dst_height = anim_height * num_collect_images / 2;
Bitmap *dst_bitmap = CreateBitmap(dst_width, dst_height, DEFAULT_DEPTH);
- char *basename = "RocksCollect.bmp";
- char *filename = getPath2(global.create_collect_images_dir, basename);
+ char *basename_bmp = "RocksCollect.bmp";
+ char *basename_png = "RocksCollect.png";
+ char *filename_bmp = getPath2(global.create_collect_images_dir, basename_bmp);
+ char *filename_png = getPath2(global.create_collect_images_dir, basename_png);
+ int len_filename_bmp = strlen(filename_bmp);
+ int len_filename_png = strlen(filename_png);
+ int max_command_len = MAX_FILENAME_LEN + len_filename_bmp + len_filename_png;
+ char cmd_convert[max_command_len];
+
+ snprintf(cmd_convert, max_command_len, "convert \"%s\" \"%s\"",
+ filename_bmp,
+ filename_png);
+
+ // force using RGBA surface for destination bitmap
+ SDL_SetColorKey(dst_bitmap->surface, SET_TRANSPARENT_PIXEL,
+ SDL_MapRGB(dst_bitmap->surface->format, 0x00, 0x00, 0x00));
+
+ dst_bitmap->surface =
+ SDL_ConvertSurfaceFormat(dst_bitmap->surface, SDL_PIXELFORMAT_ARGB8888, 0);
for (i = 0; i < MAX_NUM_ELEMENTS; i++)
{
BlitBitmap(src_bitmap, tmp_bitmap, src_x, src_y,
tile_size, tile_size, 0, 0);
+ // force using RGBA surface for temporary bitmap (using transparent black)
+ SDL_SetColorKey(tmp_bitmap->surface, SET_TRANSPARENT_PIXEL,
+ SDL_MapRGB(tmp_bitmap->surface->format, 0x00, 0x00, 0x00));
+
+ tmp_bitmap->surface =
+ SDL_ConvertSurfaceFormat(tmp_bitmap->surface, SDL_PIXELFORMAT_ARGB8888, 0);
+
tmp_bitmap->surface_masked = tmp_bitmap->surface;
for (j = 0; j < anim_frames; j++)
frame_bitmap = half_bitmap;
}
- BlitBitmap(frame_bitmap, dst_bitmap, 0, 0,
- frame_size_final, frame_size_final,
- dst_x + j * tile_size + offset, dst_y + offset);
+ BlitBitmapMasked(frame_bitmap, dst_bitmap, 0, 0,
+ frame_size_final, frame_size_final,
+ dst_x + j * tile_size + offset, dst_y + offset);
FreeBitmap(frame_bitmap);
}
pos_collect_images++;
}
- if (SDL_SaveBMP(dst_bitmap->surface, filename) != 0)
- Fail("cannot save element collecting image file '%s'", filename);
+ if (SDL_SaveBMP(dst_bitmap->surface, filename_bmp) != 0)
+ Fail("cannot save element collecting image file '%s'", filename_bmp);
FreeBitmap(dst_bitmap);
+ Info("Converting image file from BMP to PNG ...");
+
+ if (system(cmd_convert) != 0)
+ Fail("converting image file failed");
+
+ unlink(filename_bmp);
+
Info("Done.");
CloseAllAndExit(0);