Adds weekly challenge seed play and leaderboard saving
This commit is contained in:
parent
1212b1a88a
commit
72c3817927
|
@ -86,7 +86,7 @@ build_script:
|
|||
# Build
|
||||
- |-
|
||||
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
|
||||
|
|
14
src/main.c
14
src/main.c
|
@ -339,6 +339,11 @@ startGame(void)
|
|||
else
|
||||
cLevel = 1;
|
||||
|
||||
if (weeklyGame)
|
||||
set_random_seed((unsigned int) time_get_weekly_seed());
|
||||
else
|
||||
set_random_seed(0);
|
||||
|
||||
gGameState = PLAYING;
|
||||
if (gPlayer)
|
||||
player_destroy(gPlayer);
|
||||
|
@ -430,7 +435,6 @@ startWeeklyGame(void *unused)
|
|||
{
|
||||
quickGame = true;
|
||||
weeklyGame = true;
|
||||
set_random_seed((unsigned int) time_get_weekly_seed());
|
||||
goToCharacterMenu(unused);
|
||||
}
|
||||
#endif
|
||||
|
@ -649,6 +653,8 @@ init(void)
|
|||
error("%s needs to be started through Steam", GAME_TITLE);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
steam_init();
|
||||
#endif
|
||||
#endif // STEAM_BUILD
|
||||
|
||||
|
@ -1046,7 +1052,7 @@ register_scores(void)
|
|||
(int32_t*) &details, 1);
|
||||
}
|
||||
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) {
|
||||
steam_register_arcade_score((int)gPlayer->gold,
|
||||
|
@ -1088,8 +1094,6 @@ run_game(void)
|
|||
gGameState = GAME_OVER;
|
||||
createInGameGameOverMenu();
|
||||
hiscore_register(gPlayer, cLevel);
|
||||
if (weeklyGame)
|
||||
set_random_seed(0);
|
||||
#ifdef STEAM_BUILD
|
||||
register_scores();
|
||||
#endif // STEAM_BUILD
|
||||
|
@ -1105,8 +1109,6 @@ run_game(void)
|
|||
gui_log("Your break is over!");
|
||||
gui_event_message("Well done!");
|
||||
end_game_details();
|
||||
if (weeklyGame)
|
||||
set_random_seed(0);
|
||||
#ifdef STEAM_BUILD
|
||||
if (cLevel >= 20 && !arcadeGame)
|
||||
steam_set_achievement(BACK_TO_WORK);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "../defines.h"
|
||||
#include "../gui.h"
|
||||
#include "../timer.h"
|
||||
#include "../time.h"
|
||||
|
||||
static const char *LB_HIGHSCORE = "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_WARRIOR_HIGHSCORE = "Warrior Highscore";
|
||||
static const char *LB_KILLS = "Most Kills";
|
||||
static char *lb_weekly = NULL;
|
||||
|
||||
static Achievement g_Achievements[] = {
|
||||
_ACH_ID(BAD_DOG, "Bad Dog"),
|
||||
|
@ -33,6 +35,7 @@ static Sint64 m_hArcadeHighscoreLeaderboard = 0;
|
|||
static Sint64 m_hKillsLeaderboard = 0;
|
||||
static Sint64 m_hRogueHighscore = 0;
|
||||
static Sint64 m_hWarriorHighscore = 0;
|
||||
static Sint64 m_hWeeklyHighscore = 0;
|
||||
|
||||
static Timer *requestDataTimer = NULL;
|
||||
|
||||
|
@ -73,6 +76,8 @@ leaderboard_received(Sint64 hLeaderboard, const char *name)
|
|||
m_hQpHighscoreLeaderboard = hLeaderboard;
|
||||
else if (strcmp(LB_ARCADE_HIGHSCORE, name) == 0)
|
||||
m_hArcadeHighscoreLeaderboard = hLeaderboard;
|
||||
else if (strcmp(lb_weekly, name) == 0)
|
||||
m_hWeeklyHighscore = hLeaderboard;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -86,6 +91,7 @@ steam_init()
|
|||
{
|
||||
m_AppID = c_SteamAPI_Init();
|
||||
m_Initiated = m_AppID != 0;
|
||||
lb_weekly = time_get_weekly_lb_name();
|
||||
if (m_Initiated)
|
||||
c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received);
|
||||
requestDataTimer = _timer_create();
|
||||
|
@ -95,6 +101,8 @@ void steam_shutdown(void)
|
|||
{
|
||||
c_SteamAPI_Shutdown();
|
||||
timer_destroy(requestDataTimer);
|
||||
if (lb_weekly)
|
||||
free(lb_weekly);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -118,6 +126,8 @@ request_data_queue_run(void)
|
|||
c_SteamUserStats_FindLeaderboard(LB_ROGUE_HIGHSCORE);
|
||||
else if (!m_hWarriorHighscore)
|
||||
c_SteamUserStats_FindLeaderboard(LB_WARRIOR_HIGHSCORE);
|
||||
else if (!m_hWeeklyHighscore)
|
||||
c_SteamUserStats_FindLeaderboard(lb_weekly);
|
||||
|
||||
timer_start(requestDataTimer);
|
||||
}
|
||||
|
@ -133,6 +143,9 @@ void steam_run_callbacks(void)
|
|||
|
||||
void steam_set_achievement(EAchievement eAch)
|
||||
{
|
||||
if (!m_Initiated)
|
||||
return;
|
||||
|
||||
for (Uint8 i = 0; i < numAchievements; ++i) {
|
||||
Achievement *a = &g_Achievements[i];
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!m_hArcadeHighscoreLeaderboard)
|
||||
|
|
|
@ -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_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_warrior_score(Sint32 nScore, const int32_t *details, int32_t nDetails);
|
||||
|
|
19
src/time.c
19
src/time.c
|
@ -23,7 +23,22 @@ time_get_weekly_seed(void)
|
|||
unsigned int dayOfWeek = tm->tm_wday;
|
||||
now -= (dayOfWeek == 0 ? 6 : dayOfWeek - 1) * SECONDS_PER_DAY;
|
||||
|
||||
info("Monday: %s", ctime(&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;
|
||||
}
|
||||
|
|
|
@ -4,3 +4,6 @@
|
|||
|
||||
time_t
|
||||
time_get_weekly_seed(void);
|
||||
|
||||
char *
|
||||
time_get_weekly_lb_name(void);
|
||||
|
|
Loading…
Reference in New Issue