From: Holger Schemel Date: Fri, 23 Oct 2009 23:45:27 +0000 (+0200) Subject: rnd-20091024-1-src X-Git-Tag: 3.3.0.0^2~72 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=0b8567c8bcbe637936fa01d253de81254fa4fb3e;p=rocksndiamonds.git rnd-20091024-1-src --- diff --git a/src/conftime.h b/src/conftime.h index 5d237cbb..2f68db2d 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2009-10-23 00:17" +#define COMPILE_DATE_STRING "2009-10-24 01:44" diff --git a/src/files.c b/src/files.c index e71ca2a2..d0caceb5 100644 --- a/src/files.c +++ b/src/files.c @@ -4157,11 +4157,12 @@ static void LoadLevelFromFileInfo_SP(struct LevelInfo *level, void CopyNativeLevel_RND_to_SP(struct LevelInfo *level) { - LevelInfoType *header = &native_sp_level.header; + struct LevelInfo_SP *level_sp = level->native_sp_level; + LevelInfoType *header = &level_sp->header; int i, x, y; - native_sp_level.width = level->fieldx; - native_sp_level.height = level->fieldy; + level_sp->width = level->fieldx; + level_sp->height = level->fieldy; for (x = 0; x < level->fieldx; x++) { @@ -4176,9 +4177,9 @@ void CopyNativeLevel_RND_to_SP(struct LevelInfo *level) else if (element_old == EL_INVISIBLE_WALL) element_new = 0x28; else - element_new = EL_SP_HARDWARE_YELLOW; /* unknown to Supaplex engine */ + element_new = 0x20; /* map unknown elements to yellow "hardware" */ - native_sp_level.playfield[x][y] = element_new; + level_sp->playfield[x][y] = element_new; } } @@ -4195,17 +4196,18 @@ void CopyNativeLevel_RND_to_SP(struct LevelInfo *level) void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) { - LevelInfoType *header = &native_sp_level.header; + struct LevelInfo_SP *level_sp = level->native_sp_level; + LevelInfoType *header = &level_sp->header; int i, x, y; - level->fieldx = native_sp_level.width; - level->fieldy = native_sp_level.height; + level->fieldx = level_sp->width; + level->fieldy = level_sp->height; for (x = 0; x < level->fieldx; x++) { for (y = 0; y < level->fieldy; y++) { - int element_old = native_sp_level.playfield[x][y]; + int element_old = level_sp->playfield[x][y]; int element_new; if (element_old <= 0x27) @@ -4297,6 +4299,35 @@ void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) level->yamyam_content[i].e[x][y] = EL_EMPTY; } +static void setTapeInfoToDefaults(); + +static void CopyNativeTape_SP_to_RND(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + struct DemoInfo_SP *demo = &level_sp->demo; + int i; + + /* always start with reliable default values */ + setTapeInfoToDefaults(); + + tape.level_nr = demo->level_nr; /* (currently not used) */ + tape.length = demo->length - 1; /* without "end of demo" byte */ + tape.random_seed = level_sp->header.DemoRandomSeed; + + // tape.date = + + for (i = 0; i < demo->length - 1; i++) + { + int demo_action = demo->data[i] & 0x0f; + int demo_repeat = (demo->data[i] & 0xf0) >> 4; + + tape.pos[i].action[0] = map_key_SP_to_RND(demo_action); + tape.pos[i].delay = demo_repeat + 1; + } + + tape.length_seconds = GetTapeLength(); +} + /* ------------------------------------------------------------------------- */ /* functions for loading DC level */ @@ -8014,6 +8045,13 @@ void LoadSolutionTape(int nr) char *filename = getSolutionTapeFilename(nr); LoadTapeFromFilename(filename); + +#if 1 + if (TAPE_IS_EMPTY(tape) && + level.game_engine_type == GAME_ENGINE_TYPE_SP && + level.native_sp_level->demo.is_available) + CopyNativeTape_SP_to_RND(&level); +#endif } static void SaveTape_VERS(FILE *file, struct TapeInfo *tape) diff --git a/src/game_sp/BugsTerminals.c b/src/game_sp/BugsTerminals.c index 4bb27c03..952ccb62 100644 --- a/src/game_sp/BugsTerminals.c +++ b/src/game_sp/BugsTerminals.c @@ -163,7 +163,7 @@ int subRandomize() } #endif -#if 1 +#if 0 printf("::: BugsTerminals.c: ========== subRandomize()\n"); #endif diff --git a/src/game_sp/Input.c b/src/game_sp/Input.c index a846aaf6..5271795c 100644 --- a/src/game_sp/Input.c +++ b/src/game_sp/Input.c @@ -24,6 +24,37 @@ DemoBufferObject DemoBuffer; int KeyScanCode7; +int map_key_RND_to_SP(int key) +{ + if (key & KEY_BUTTON) + { + return (key & MV_UP ? keySpaceUp : + key & MV_LEFT ? keySpaceLeft : + key & MV_DOWN ? keySpaceDown : + key & MV_RIGHT ? keySpaceRight : keySpace); + } + else + { + return (key & MV_UP ? keyUp : + key & MV_LEFT ? keyLeft : + key & MV_DOWN ? keyDown : + key & MV_RIGHT ? keyRight : keyNone); + } +} + +int map_key_SP_to_RND(int key) +{ + return (key == keyUp ? MV_UP : + key == keyLeft ? MV_LEFT : + key == keyDown ? MV_DOWN : + key == keyRight ? MV_RIGHT : + key == keySpaceUp ? KEY_BUTTON | MV_UP : + key == keySpaceLeft ? KEY_BUTTON | MV_LEFT : + key == keySpaceDown ? KEY_BUTTON | MV_DOWN : + key == keySpaceRight ? KEY_BUTTON | MV_RIGHT : + key == keySpace ? KEY_BUTTON : MV_NONE); +} + void subCheckJoystick() { } @@ -45,20 +76,11 @@ int subProcessKeyboardInput(byte action) #if 1 - if (action & KEY_BUTTON) - { - DemoKeyCode = (action & MV_UP ? keySpaceUp : - action & MV_LEFT ? keySpaceLeft : - action & MV_DOWN ? keySpaceDown : - action & MV_RIGHT ? keySpaceRight : keySpace); - } - else - { - DemoKeyCode = (action & MV_UP ? keyUp : - action & MV_LEFT ? keyLeft : - action & MV_DOWN ? keyDown : - action & MV_RIGHT ? keyRight : keyNone); - } + DemoKeyCode = map_key_RND_to_SP(action); + +#if 0 + printf("::: DemoKeyCode == %d\n", DemoKeyCode); +#endif return subProcessKeyboardInput; @@ -73,6 +95,10 @@ int subProcessKeyboardInput(byte action) { subGetNextDemoKey(); +#if 0 + printf("::: DemoKeyCode == %d\n", DemoKeyCode); +#endif + if (ExitToMenuFlag != 0) return subProcessKeyboardInput; } diff --git a/src/game_sp/export.h b/src/game_sp/export.h index 552e2ecb..4438990f 100644 --- a/src/game_sp/export.h +++ b/src/game_sp/export.h @@ -84,18 +84,25 @@ struct GameInfo_SP boolean GameOver; }; +struct DemoInfo_SP +{ + boolean is_available; /* structure contains valid demo */ + + int level_nr; /* number of corresponding level */ + + int length; /* number of demo entries */ + byte data[SP_MAX_TAPE_LEN]; /* array of demo entries */ +}; + struct LevelInfo_SP { LevelInfoType header; - byte playfield[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT]; - int width, height; - boolean demo_available; + byte playfield[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT]; - byte demo[SP_MAX_TAPE_LEN]; - int demo_length; + struct DemoInfo_SP demo; }; struct GraphicInfo_SP @@ -153,4 +160,7 @@ extern void DrawGameDoorValues_SP(); extern void LoadEngineSnapshotValues_SP(); extern void SaveEngineSnapshotValues_SP(); +extern int map_key_RND_to_SP(int); +extern int map_key_SP_to_RND(int); + #endif /* GAME_SP_EXPORT_H */ diff --git a/src/game_sp/file.c b/src/game_sp/file.c index 2aa0ddf5..4e7b6bc0 100644 --- a/src/game_sp/file.c +++ b/src/game_sp/file.c @@ -43,8 +43,8 @@ void setLevelInfoToDefaults_SP() port->FreezeEnemies = 0; } - native_sp_level.demo_available = FALSE; - native_sp_level.demo_length = 0; + native_sp_level.demo.is_available = FALSE; + native_sp_level.demo.length = 0; } void copyInternalEngineVars_SP() @@ -60,7 +60,7 @@ void copyInternalEngineVars_SP() FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1; LevelMax = (FieldWidth * FieldHeight) - 1; - FileMax = FieldMax + native_sp_level.demo_length; + FileMax = FieldMax + native_sp_level.demo.length; PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax + 1 - 1); DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1); @@ -80,12 +80,14 @@ void copyInternalEngineVars_SP() } } - if (native_sp_level.demo_available) + if (native_sp_level.demo.is_available) { DemoAvailable = True; - for (i = 0; i < native_sp_level.demo_length; i++) - PlayField8[FieldMax + i + 1] = native_sp_level.demo[i]; + PlayField8[FieldMax + 1] = native_sp_level.demo.level_nr; + + for (i = 0; i < native_sp_level.demo.length; i++) + PlayField8[FieldMax + i + 2] = native_sp_level.demo.data[i]; } AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 * FieldWidth); @@ -211,11 +213,19 @@ static void LoadNativeLevelFromFileStream_SP(FILE *file, boolean demo_available) if (demo_available) { + int level_nr = getFile8Bit(file); + + level_nr &= 0x7f; /* clear highest bit */ + level_nr = (level_nr < 1 ? 1 : + level_nr > 111 ? 111 : level_nr); + + native_sp_level.demo.level_nr = level_nr; + for (i = 0; i < SP_MAX_TAPE_LEN && !feof(file); i++) { - native_sp_level.demo[i] = getFile8Bit(file); + native_sp_level.demo.data[i] = getFile8Bit(file); - if (native_sp_level.demo[i] == 0xff) /* "end of demo" byte */ + if (native_sp_level.demo.data[i] == 0xff) /* "end of demo" byte */ { i++; @@ -223,8 +233,8 @@ static void LoadNativeLevelFromFileStream_SP(FILE *file, boolean demo_available) } } - native_sp_level.demo_length = i; - native_sp_level.demo_available = (native_sp_level.demo_length > 0); + native_sp_level.demo.length = i; + native_sp_level.demo.is_available = (native_sp_level.demo.length > 0); } }