Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidityC committed Sep 3, 2018
2 parents b962d55 + 280b073 commit e000580
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .clang_complete
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-DDEBUG
-DSTEAM_BUILD
-include ./steamworks_c_api/sdk/public/steam/steam_api.h
-I./steamworks_c_api/src/
-I./src/steam/
-I./build/config.h
Expand Down
3 changes: 2 additions & 1 deletion .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ nnoremap <F4> :ter ++close ./_build/breakhack<cr>
packadd termdebug
let g:termdebug_wide = 1
let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src', 'steamworks_c_wrapper/sdk/public/steam' ]
let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src' ]
let g:syntastic_cpp_include_dirs = [ 'steamworks_c_wrapper/sdk/public/steam' ]
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(breakhack C)
set(breakhack_GAME_TITLE "BreakHack")
set(breakhack_MAJOR_VERSION 1)
set(breakhack_MINOR_VERSION 0)
set(breakhack_PATCH_VERSION 2)
set(breakhack_PATCH_VERSION 3)
set(breakhack_RELEASE_TYPE "")

include(FindLua)
Expand Down
18 changes: 18 additions & 0 deletions data/monstergen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ bosses[1] = concat({ texturePaths.dog0, texturePaths.dog1 }, bosses[1])
bosses[2] = concat({ texturePaths.humanoid0, texturePaths.humanoid1 }, bosses[2])
bosses[3] = concat({ texturePaths.undead0, texturePaths.undead1 }, bosses[3])

local eastereggs = {
{ stats.misc, 6*16, 1*16, "Linus, the Developer", behaviour.passive },
{ stats.misc, 4*16, 1*16, "Scanlan, the Bard", behaviour.passive },
{ stats.misc, 2*16, 4*16, "Vax, the Twin", behaviour.passive },
{ stats.misc, 2*16, 3*16, "Vex, the Twin", behaviour.passive },
{ stats.misc, 0*16,10*16, "Grog, the Barbarian", behaviour.passive },
{ stats.misc, 3*16, 4*16, "Percy, the Gunslinger", behaviour.passive },
{ stats.misc, 4*16, 0*16, "Pike, the Cleric", behaviour.passive },
{ stats.misc, 6*16, 7*16, "Keyleth, the Druid", behaviour.passive },
}
for i=1,#eastereggs do
eastereggs[i] = concat({ texturePaths.player0, texturePaths.player1 }, eastereggs[i])
end

local platino = {
{
texturePaths.reptile0,
Expand Down Expand Up @@ -313,6 +327,10 @@ if(CURRENT_LEVEL > 0) then
end
end

if random(100) == 1 then
enemies[#enemies+1] = eastereggs[random(#eastereggs)]
end

if random(100) == 1 then
enemies = concat(enemies, platino)
end
Expand Down
7 changes: 4 additions & 3 deletions src/item_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ create_treasure(int current_level)
unsigned int value;

amt = (unsigned int) 1 + get_random(5*current_level) % 40;
amt = amt == 0 ? 1 : amt;

if (current_level > 9) {
highest_treasure = TREASURE_COUNT;
} else if (current_level > 3) {
highest_treasure = PLATINUM;
} else {
} else if (current_level > 3) {
highest_treasure = GOLD;
} else {
highest_treasure = SILVER;
}

value = get_random(highest_treasure);
Expand Down
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,9 @@ run_game(void)
createInGameGameOverMenu();
hiscore_register(gPlayer, cLevel);
#ifdef STEAM_BUILD
steam_register_score((int)hiscore_get_top_gold());
steam_register_kills((int) gPlayer->stat_data.kills);
uint8_t details[4] = { (uint8_t) gPlayer->stats.lvl, (uint8_t) cLevel, 0, 0 };
steam_register_score((int) gPlayer->gold, (int32_t*) &details, 1);
steam_register_kills((int) gPlayer->stat_data.kills, (int32_t*) &details, 1);
#endif // STEAM_BUILD

} else {
Expand Down
34 changes: 15 additions & 19 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ action_spent(Player *p)
}
}

static void
player_step(Player *p)
{
action_spent(p);
}

static void
on_monster_collision(Player *player,
Monster *monster,
Expand Down Expand Up @@ -267,7 +261,7 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction)
player->sprite->pos.y += TILE_DIMENSION * (int) direction.y;

if (!has_collided(player, matrix, direction)) {
player_step(player);
action_spent(player);
}
}

Expand Down Expand Up @@ -340,7 +334,7 @@ use_skill(Skill *skill, SkillData *skillData)
skill->active = false;
skill->use(skill, skillData);
if (skill->actionRequired)
player_step(skillData->player);
action_spent(skillData->player);
skill->resetCountdown = skill->resetTime;
}

Expand Down Expand Up @@ -518,24 +512,26 @@ player_monster_kill_check(Player *player, Monster *monster)
if (!monster)
return;

#ifdef STEAM_BUILD
if (strcmp("The Shadow", monster->label) == 0)
steam_set_achievement(LIGHTS_ON);
else if (strcmp("The Hell Hound", monster->label) == 0)
steam_set_achievement(BAD_DOG);
else if (strcmp("Platino", monster->label) == 0)
steam_set_achievement(DRAGON_SLAYER);
else if (strcmp("The Cleric", monster->label) == 0)
steam_set_achievement(THE_DOCTOR_IS_OUT);
#endif // STEAM_BUILD

if (monster->stats.hp <= 0) {
unsigned int gained_xp = 5 * monster->stats.lvl;
player->stat_data.kills += 1;
mixer_play_effect(DEATH);
gui_log("You killed %s and gained %d xp",
monster->lclabel, gained_xp);
player_gain_xp(player, gained_xp);

#ifdef STEAM_BUILD
if (strcmp("The Shadow", monster->label) == 0)
steam_set_achievement(LIGHTS_ON);
else if (strcmp("The Hell Hound", monster->label) == 0)
steam_set_achievement(BAD_DOG);
else if (strcmp("Platino", monster->label) == 0)
steam_set_achievement(DRAGON_SLAYER);
else if (strcmp("The Cleric", monster->label) == 0)
steam_set_achievement(THE_DOCTOR_IS_OUT);
else if (strcmp("Linus, the Developer", monster->label) == 0)
steam_set_achievement(BUGGFIXER);
#endif // STEAM_BUILD
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/steam/steamworks_api_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ void steam_set_achievement(EAchievement eAch)
}
}

void steam_register_score(Sint32 nScore)
void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails)
{
if (!m_hHighscoreLeaderboard)
return;
c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore);
c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore, details, nDetails);
}

void steam_register_kills(Sint32 nKills)
void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails)
{
if (!m_hKillsLeaderboard)
return;
c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills);
c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills, details, nDetails);
}
7 changes: 4 additions & 3 deletions src/steam/steamworks_api_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ typedef enum EAchievement
THE_DOCTOR_IS_OUT = 1,
LIGHTS_ON = 2,
BACK_TO_WORK = 5,
DRAGON_SLAYER = 6
DRAGON_SLAYER = 6,
BUGGFIXER = 7
} EAchievement;


Expand All @@ -31,6 +32,6 @@ void steam_run_callbacks(void);

void steam_set_achievement(EAchievement eAch);

void steam_register_score(Sint32 nScore);
void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails);

void steam_register_kills(Sint32 nKills);
void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails);
1 change: 1 addition & 0 deletions steamworks_c_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ else ()
SHARED
src/steamworks_c_wrapper
src/CallbackHandler
src/CSteamLeaderboard
)
endif()

Expand Down
83 changes: 83 additions & 0 deletions steamworks_c_wrapper/src/CSteamLeaderboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <iostream>
#include "CSteamLeaderboard.h"

CSteamLeaderboard::CSteamLeaderboard() : m_hCurrentLeaderboard(0)
{
// Nothing yet
}

void
CSteamLeaderboard::SetCurrent(SteamLeaderboard_t hCurrentLeaderboard)
{
m_hCurrentLeaderboard = hCurrentLeaderboard;
}

void
CSteamLeaderboard::FindLeaderboard(const char *pchLeaderboardName )
{

SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(pchLeaderboardName);
m_callResultFindLeaderboard.Set(hSteamAPICall,
this,
&CSteamLeaderboard::OnFindLeaderboard);
}

bool
CSteamLeaderboard::UploadScore(int score, const int *details, int nDetails)
{
if (!m_hCurrentLeaderboard)
return false;

SteamAPICall_t hSteamAPICall = SteamUserStats()->UploadLeaderboardScore(m_hCurrentLeaderboard,
k_ELeaderboardUploadScoreMethodKeepBest,
score,
details,
nDetails);
m_callResultUploadScore.Set(hSteamAPICall, this, &CSteamLeaderboard::OnUploadScore);
return true;
}

bool
CSteamLeaderboard::DownloadScores()
{
if (!m_hCurrentLeaderboard) return false;
SteamAPICall_t hSteamAPICall = SteamUserStats()->DownloadLeaderboardEntries( m_hCurrentLeaderboard,
k_ELeaderboardDataRequestGlobalAroundUser,
-4,
5);

m_callResultDownloadScores.Set(hSteamAPICall, this, &CSteamLeaderboard::OnDownloadScores);
return true;
}

void
CSteamLeaderboard::OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure)
{
if (!pCallback->m_bLeaderboardFound || bIOFailiure) {
std::cerr << "Leaderboard could not be found" << std::endl;
return;
}
m_hCurrentLeaderboard = pCallback->m_hSteamLeaderboard;
}

void
CSteamLeaderboard::OnUploadScore(LeaderboardScoreUploaded_t *pCallback, bool bIOFailiure)
{
if (!pCallback->m_bSuccess || bIOFailiure)
std::cerr << "Score could not be uploaded" << std::endl;
}

void
CSteamLeaderboard::OnDownloadScores(LeaderboardScoresDownloaded_t *pCallback, bool bIOFailiure)
{
if (!bIOFailiure) {
m_nLeaderboardEntries = std::min(pCallback->m_cEntryCount, 10);
for (int index = 0; index < m_nLeaderboardEntries; index++) {
SteamUserStats()->GetDownloadedLeaderboardEntry( pCallback->m_hSteamLeaderboardEntries,
index,
&m_leaderboardEntries[index],
NULL,
0);
}
}
}
29 changes: 29 additions & 0 deletions steamworks_c_wrapper/src/CSteamLeaderboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <steam_api.h>

class CSteamLeaderboard
{
private:
SteamLeaderboard_t m_hCurrentLeaderboard;
LeaderboardEntry_t m_leaderboardEntries[10];
int m_nLeaderboardEntries = 0;

public:
CSteamLeaderboard();

void SetCurrent(SteamLeaderboard_t hCurrentLeaderboard);

void FindLeaderboard(const char *pchLeaderboardName );
bool UploadScore(int score, const int *details, int nDetails);
bool DownloadScores();

void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure);
CCallResult<CSteamLeaderboard, LeaderboardFindResult_t> m_callResultFindLeaderboard;

void OnUploadScore(LeaderboardScoreUploaded_t *pCallback, bool bIOFailiure);
CCallResult<CSteamLeaderboard, LeaderboardScoreUploaded_t> m_callResultUploadScore;

void OnDownloadScores(LeaderboardScoresDownloaded_t *pCallback, bool bIOFailiure);
CCallResult<CSteamLeaderboard, LeaderboardScoresDownloaded_t> m_callResultDownloadScores;
};
2 changes: 1 addition & 1 deletion steamworks_c_wrapper/src/CallbackHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ void CallbackHandler::OnFindLeaderboard(LeaderboardFindResult_t * pCallback, boo

if (leaderboardReceivedCb)
leaderboardReceivedCb(pCallback->m_hSteamLeaderboard, SteamUserStats()->GetLeaderboardName(pCallback->m_hSteamLeaderboard));
}
}
4 changes: 2 additions & 2 deletions steamworks_c_wrapper/src/steamworks_c_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ c_SteamUserStats_FindLeaderboard(const char * name)
m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard);
}

extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore)
extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, const int32_t *details, int32_t nDetails)
{
if (!hLeaderboard || !m_Initiated)
return;

SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, nullptr, 0);
SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, details, nDetails);
}
4 changes: 2 additions & 2 deletions steamworks_c_wrapper/src/steamworks_c_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void
c_SteamUserStats_FindLeaderboard(const char *name);

void
c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore);
c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, const int32_t *details, int32_t nDetails);

void
c_SteamAPI_Shutdown(void);
c_SteamAPI_Shutdown(void);

0 comments on commit e000580

Please sign in to comment.