Adds weekly challenge seed play and leaderboard saving

This commit is contained in:
Linus Probert 2019-02-20 19:45:55 +01:00
parent 1212b1a88a
commit 72c3817927
6 changed files with 51 additions and 9 deletions

View File

@ -86,7 +86,7 @@ build_script:
# Build # Build
- |- - |-
cmake --version cmake --version
cmake -DCMAKE_PREFIX_PATH="%PREFIX%" -DCMAKE_C_COMPILER=mingw32-gcc.exe -DCMAKE_MAKE_PROGRAM=mingw32-make.exe -G "MinGW Makefiles" cmake -DCMAKE_PREFIX_PATH="%PREFIX%" -DCMAKE_C_COMPILER=mingw32-gcc.exe -DCMAKE_MAKE_PROGRAM=mingw32-make.exe -G "MinGW Makefiles" .
- |- - |-
mingw32-make mingw32-make

View File

@ -339,6 +339,11 @@ startGame(void)
else else
cLevel = 1; cLevel = 1;
if (weeklyGame)
set_random_seed((unsigned int) time_get_weekly_seed());
else
set_random_seed(0);
gGameState = PLAYING; gGameState = PLAYING;
if (gPlayer) if (gPlayer)
player_destroy(gPlayer); player_destroy(gPlayer);
@ -430,7 +435,6 @@ startWeeklyGame(void *unused)
{ {
quickGame = true; quickGame = true;
weeklyGame = true; weeklyGame = true;
set_random_seed((unsigned int) time_get_weekly_seed());
goToCharacterMenu(unused); goToCharacterMenu(unused);
} }
#endif #endif
@ -649,6 +653,8 @@ init(void)
error("%s needs to be started through Steam", GAME_TITLE); error("%s needs to be started through Steam", GAME_TITLE);
return false; return false;
} }
#else
steam_init();
#endif #endif
#endif // STEAM_BUILD #endif // STEAM_BUILD
@ -1046,7 +1052,7 @@ register_scores(void)
(int32_t*) &details, 1); (int32_t*) &details, 1);
} }
if (weeklyGame) { if (weeklyGame) {
//steam_register_weekly_score((int) gPlayer->gold, (int32_t*) &details, 1); steam_register_weekly_score((int) gPlayer->gold, (int32_t*) &details, 1);
} }
if (arcadeGame) { if (arcadeGame) {
steam_register_arcade_score((int)gPlayer->gold, steam_register_arcade_score((int)gPlayer->gold,
@ -1088,8 +1094,6 @@ run_game(void)
gGameState = GAME_OVER; gGameState = GAME_OVER;
createInGameGameOverMenu(); createInGameGameOverMenu();
hiscore_register(gPlayer, cLevel); hiscore_register(gPlayer, cLevel);
if (weeklyGame)
set_random_seed(0);
#ifdef STEAM_BUILD #ifdef STEAM_BUILD
register_scores(); register_scores();
#endif // STEAM_BUILD #endif // STEAM_BUILD
@ -1105,8 +1109,6 @@ run_game(void)
gui_log("Your break is over!"); gui_log("Your break is over!");
gui_event_message("Well done!"); gui_event_message("Well done!");
end_game_details(); end_game_details();
if (weeklyGame)
set_random_seed(0);
#ifdef STEAM_BUILD #ifdef STEAM_BUILD
if (cLevel >= 20 && !arcadeGame) if (cLevel >= 20 && !arcadeGame)
steam_set_achievement(BACK_TO_WORK); steam_set_achievement(BACK_TO_WORK);

View File

@ -6,6 +6,7 @@
#include "../defines.h" #include "../defines.h"
#include "../gui.h" #include "../gui.h"
#include "../timer.h" #include "../timer.h"
#include "../time.h"
static const char *LB_HIGHSCORE = "Highscore"; static const char *LB_HIGHSCORE = "Highscore";
static const char *LB_QUICKPLAY_HIGHSCORE = "Quickplay Highscore"; static const char *LB_QUICKPLAY_HIGHSCORE = "Quickplay Highscore";
@ -13,6 +14,7 @@ static const char *LB_ARCADE_HIGHSCORE = "Arcade Highscore";
static const char *LB_ROGUE_HIGHSCORE = "Rogue Highscore"; static const char *LB_ROGUE_HIGHSCORE = "Rogue Highscore";
static const char *LB_WARRIOR_HIGHSCORE = "Warrior Highscore"; static const char *LB_WARRIOR_HIGHSCORE = "Warrior Highscore";
static const char *LB_KILLS = "Most Kills"; static const char *LB_KILLS = "Most Kills";
static char *lb_weekly = NULL;
static Achievement g_Achievements[] = { static Achievement g_Achievements[] = {
_ACH_ID(BAD_DOG, "Bad Dog"), _ACH_ID(BAD_DOG, "Bad Dog"),
@ -33,6 +35,7 @@ static Sint64 m_hArcadeHighscoreLeaderboard = 0;
static Sint64 m_hKillsLeaderboard = 0; static Sint64 m_hKillsLeaderboard = 0;
static Sint64 m_hRogueHighscore = 0; static Sint64 m_hRogueHighscore = 0;
static Sint64 m_hWarriorHighscore = 0; static Sint64 m_hWarriorHighscore = 0;
static Sint64 m_hWeeklyHighscore = 0;
static Timer *requestDataTimer = NULL; static Timer *requestDataTimer = NULL;
@ -73,6 +76,8 @@ leaderboard_received(Sint64 hLeaderboard, const char *name)
m_hQpHighscoreLeaderboard = hLeaderboard; m_hQpHighscoreLeaderboard = hLeaderboard;
else if (strcmp(LB_ARCADE_HIGHSCORE, name) == 0) else if (strcmp(LB_ARCADE_HIGHSCORE, name) == 0)
m_hArcadeHighscoreLeaderboard = hLeaderboard; m_hArcadeHighscoreLeaderboard = hLeaderboard;
else if (strcmp(lb_weekly, name) == 0)
m_hWeeklyHighscore = hLeaderboard;
} }
bool bool
@ -86,6 +91,7 @@ steam_init()
{ {
m_AppID = c_SteamAPI_Init(); m_AppID = c_SteamAPI_Init();
m_Initiated = m_AppID != 0; m_Initiated = m_AppID != 0;
lb_weekly = time_get_weekly_lb_name();
if (m_Initiated) if (m_Initiated)
c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received); c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received);
requestDataTimer = _timer_create(); requestDataTimer = _timer_create();
@ -95,6 +101,8 @@ void steam_shutdown(void)
{ {
c_SteamAPI_Shutdown(); c_SteamAPI_Shutdown();
timer_destroy(requestDataTimer); timer_destroy(requestDataTimer);
if (lb_weekly)
free(lb_weekly);
} }
static void static void
@ -118,6 +126,8 @@ request_data_queue_run(void)
c_SteamUserStats_FindLeaderboard(LB_ROGUE_HIGHSCORE); c_SteamUserStats_FindLeaderboard(LB_ROGUE_HIGHSCORE);
else if (!m_hWarriorHighscore) else if (!m_hWarriorHighscore)
c_SteamUserStats_FindLeaderboard(LB_WARRIOR_HIGHSCORE); c_SteamUserStats_FindLeaderboard(LB_WARRIOR_HIGHSCORE);
else if (!m_hWeeklyHighscore)
c_SteamUserStats_FindLeaderboard(lb_weekly);
timer_start(requestDataTimer); timer_start(requestDataTimer);
} }
@ -133,6 +143,9 @@ void steam_run_callbacks(void)
void steam_set_achievement(EAchievement eAch) void steam_set_achievement(EAchievement eAch)
{ {
if (!m_Initiated)
return;
for (Uint8 i = 0; i < numAchievements; ++i) { for (Uint8 i = 0; i < numAchievements; ++i) {
Achievement *a = &g_Achievements[i]; Achievement *a = &g_Achievements[i];
if (a->m_eAchievementID == eAch && !a->m_bAchieved) { if (a->m_eAchievementID == eAch && !a->m_bAchieved) {
@ -156,6 +169,13 @@ void steam_register_qp_score(Sint32 nScore, const int32_t *details, int32_t nDet
c_SteamUserStats_UploadLeaderboardScore(m_hQpHighscoreLeaderboard, nScore, details, nDetails); c_SteamUserStats_UploadLeaderboardScore(m_hQpHighscoreLeaderboard, nScore, details, nDetails);
} }
void steam_register_weekly_score(Sint32 nScore, const int32_t *details, int32_t nDetails)
{
if (!m_hWeeklyHighscore)
return;
c_SteamUserStats_UploadLeaderboardScore(m_hWeeklyHighscore, nScore, details, nDetails);
}
void steam_register_arcade_score(Sint32 nScore, const int32_t * details, int32_t nDetails) void steam_register_arcade_score(Sint32 nScore, const int32_t * details, int32_t nDetails)
{ {
if (!m_hArcadeHighscoreLeaderboard) if (!m_hArcadeHighscoreLeaderboard)

View File

@ -41,6 +41,8 @@ void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetail
void steam_register_qp_score(Sint32 nScore, const int32_t *details, int32_t nDetails); void steam_register_qp_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
void steam_register_weekly_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
void steam_register_arcade_score(Sint32 nScore, const int32_t *details, int32_t nDetails); void steam_register_arcade_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
void steam_register_warrior_score(Sint32 nScore, const int32_t *details, int32_t nDetails); void steam_register_warrior_score(Sint32 nScore, const int32_t *details, int32_t nDetails);

View File

@ -23,7 +23,22 @@ time_get_weekly_seed(void)
unsigned int dayOfWeek = tm->tm_wday; unsigned int dayOfWeek = tm->tm_wday;
now -= (dayOfWeek == 0 ? 6 : dayOfWeek - 1) * SECONDS_PER_DAY; now -= (dayOfWeek == 0 ? 6 : dayOfWeek - 1) * SECONDS_PER_DAY;
info("Monday: %s", ctime(&now));
return now; return now;
} }
// Example: 190225_weekly
char *
time_get_weekly_lb_name(void)
{
time_t seed = time_get_weekly_seed();
struct tm *tm = localtime(&seed);
char *name = ec_malloc(sizeof(char) * 15);
m_sprintf(name,
15,
"%u%.2u%.2u_weekly",
tm->tm_year % 100,
tm->tm_mon + 1,
tm->tm_mday
);
return name;
}

View File

@ -4,3 +4,6 @@
time_t time_t
time_get_weekly_seed(void); time_get_weekly_seed(void);
char *
time_get_weekly_lb_name(void);