From b458e5d5c416af09939734766095965aedabfe0d Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 13 Feb 2020 01:27:05 +0100 Subject: [PATCH] moved initial player position to level structure for EM engine --- src/files.c | 14 ++++++-------- src/game_em/cave.c | 7 ++----- src/game_em/convert.c | 11 ++++++----- src/game_em/emerald.h | 5 +++-- src/game_em/export.h | 1 - src/game_em/reademc.c | 6 +++--- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/files.c b/src/files.c index 4590665e..1052d7fc 100644 --- a/src/files.c +++ b/src/files.c @@ -3516,7 +3516,6 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) }; struct LevelInfo_EM *level_em = level->native_em_level; struct LEVEL *lev = level_em->lev; - struct PLAYER **ply = level_em->ply; int i, j, x, y; lev->width = MIN(level->fieldx, MAX_PLAYFIELD_WIDTH); @@ -3591,8 +3590,8 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) for (i = 0; i < MAX_PLAYERS; i++) { - ply[i]->x_initial = -1; - ply[i]->y_initial = -1; + lev->player_x[i] = -1; + lev->player_y[i] = -1; } // initialize player positions and delete players from the playfield @@ -3602,8 +3601,8 @@ static void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) { int player_nr = GET_PLAYER_NR(level->field[x][y]); - ply[player_nr]->x_initial = x; - ply[player_nr]->y_initial = y; + lev->player_x[player_nr] = x; + lev->player_y[player_nr] = y; level_em->cave[x][y] = map_element_RND_to_EM(EL_EMPTY); } @@ -3625,7 +3624,6 @@ static void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) }; struct LevelInfo_EM *level_em = level->native_em_level; struct LEVEL *lev = level_em->lev; - struct PLAYER **ply = level_em->ply; int i, j, x, y; level->fieldx = MIN(lev->width, MAX_LEV_FIELDX); @@ -3698,8 +3696,8 @@ static void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) { // in case of all players set to the same field, use the first player int nr = MAX_PLAYERS - i - 1; - int jx = ply[nr]->x_initial; - int jy = ply[nr]->y_initial; + int jx = lev->player_x[nr]; + int jy = lev->player_y[nr]; if (jx != -1 && jy != -1) level->field[jx][jy] = EL_PLAYER_1 + nr; diff --git a/src/game_em/cave.c b/src/game_em/cave.c index 585bfd2f..7788ae70 100644 --- a/src/game_em/cave.c +++ b/src/game_em/cave.c @@ -13,10 +13,7 @@ void setLevelInfoToDefaults_EM(void) int i; native_em_level.file_version = FILE_VERSION_EM_ACTUAL; - native_em_level.lev = &lev; - for (i = 0; i < MAX_PLAYERS; i++) - native_em_level.ply[i] = &ply[i]; game_em.lev = &lev; for (i = 0; i < MAX_PLAYERS; i++) @@ -27,8 +24,8 @@ void setLevelInfoToDefaults_EM(void) for (i = 0; i < MAX_PLAYERS; i++) { - ply[i].x_initial = -1; - ply[i].y_initial = -1; + lev.player_x[i] = -1; + lev.player_y[i] = -1; } lev.lenses_cnt_initial = 0; diff --git a/src/game_em/convert.c b/src/game_em/convert.c index 4ce16111..581c93ee 100644 --- a/src/game_em/convert.c +++ b/src/game_em/convert.c @@ -83,7 +83,8 @@ void prepare_em_level(void) ply[i].exists = 0; ply[i].alive_initial = FALSE; - if (ply[i].x_initial != -1 && ply[i].y_initial != -1) + if (lev.player_x[i] != -1 && + lev.player_y[i] != -1) { ply[i].exists = 1; @@ -110,8 +111,8 @@ void prepare_em_level(void) } else { - int x = ply[i].x_initial; - int y = ply[i].y_initial; + int x = lev.player_x[i]; + int y = lev.player_y[i]; native_em_level.cave[x][y] = Xblank; @@ -130,8 +131,8 @@ void prepare_em_level(void) ply[i].dynamite_cnt = 0; ply[i].keys = 0; ply[i].anim = 0; - ply[i].oldx = ply[i].x = ply[i].x_initial + lev.left; - ply[i].oldy = ply[i].y = ply[i].y_initial + lev.top; + ply[i].oldx = ply[i].x = lev.player_x[i] + lev.left; + ply[i].oldy = ply[i].y = lev.player_y[i] + lev.top; ply[i].last_move_dir = MV_NONE; ply[i].joy_n = ply[i].joy_e = ply[i].joy_s = ply[i].joy_w = 0; ply[i].joy_snap = ply[i].joy_drop = 0; diff --git a/src/game_em/emerald.h b/src/game_em/emerald.h index 37b75c66..83944148 100644 --- a/src/game_em/emerald.h +++ b/src/game_em/emerald.h @@ -632,6 +632,9 @@ struct LEVEL int right; /* playfield right edge */ int bottom; /* playfield bottom edge */ + int player_x[MAX_PLAYERS]; /* player x pos */ + int player_y[MAX_PLAYERS]; /* player y pos */ + int time_seconds; /* available time (seconds) */ int time_initial; /* available time (initial) */ int time; /* time remaining (runtime) */ @@ -730,8 +733,6 @@ struct PLAYER int keys; int anim; - int x_initial; - int y_initial; int x; int y; int oldx; diff --git a/src/game_em/export.h b/src/game_em/export.h index acd000b5..6fac56ae 100644 --- a/src/game_em/export.h +++ b/src/game_em/export.h @@ -50,7 +50,6 @@ struct LevelInfo_EM short cave[CAVE_WIDTH][CAVE_HEIGHT]; struct LEVEL *lev; - struct PLAYER *ply[MAX_PLAYERS]; }; struct GraphicInfo_EM diff --git a/src/game_em/reademc.c b/src/game_em/reademc.c index 0c9e663e..f8f10124 100644 --- a/src/game_em/reademc.c +++ b/src/game_em/reademc.c @@ -447,8 +447,8 @@ void convert_em_level(unsigned char *src, int file_version) { temp = GET_BE16(src[2096 + i * 2]); - ply[i].x_initial = (temp & 63); - ply[i].y_initial = (temp >> 6 & 31); + lev.player_x[i] = (temp & 63); + lev.player_y[i] = (temp >> 6 & 31); } /* cave */ @@ -467,7 +467,7 @@ void convert_em_level(unsigned char *src, int file_version) /* at last, set the two players at their positions in the playfield */ /* (native EM[C] levels always have exactly two players in a level) */ for (i = 0; i < 2; i++) - native_em_level.cave[ply[i].x_initial][ply[i].y_initial] = Zplayer; + native_em_level.cave[lev.player_x[i]][lev.player_y[i]] = Zplayer; native_em_level.file_version = file_version; } -- 2.34.1