Skip to content

Commit

Permalink
submit deaths better
Browse files Browse the repository at this point in the history
  • Loading branch information
coolwanglu committed May 6, 2015
1 parent f23530c commit 17917fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/end.c
Expand Up @@ -531,6 +531,10 @@ winid endwin;
}
}

#ifdef WEB_GRAPHICS
void BrowserHack_report(const char *, int);
#endif

/* Be careful not to call panic from here! */
void
done(how)
Expand Down Expand Up @@ -611,6 +615,11 @@ int how;
*/

die:
#ifdef WEB_GRAPHICS
if(how == ASCENDED) BrowserHack_report("ascended", 1);
else if(how == ESCAPED) BrowserHack_report("escaped", 1);
else if(how <= GENOCIDED) BrowserHack_report("died", 1);
#endif
program_state.gameover = 1;
/* in case of a subsequent panic(), there's no point trying to save */
program_state.something_worth_saving = 0;
Expand Down
8 changes: 5 additions & 3 deletions win/web/nethack_lib.js
Expand Up @@ -1073,22 +1073,20 @@ var LibraryNetHack = {
});
},

BrowserHack_update_stats_helper: function(s_gold, s_level, s_turn, s_depth, s_hp, s_armorclass, s_have_amulet, s_have_candelabrum, s_have_quest_artifact, s_quest_completed, s_entered_gehennom, s_killed_wizard, s_ascended) {
BrowserHack_update_stats_helper: function(s_gold, s_level, s_turn, s_depth, s_armorclass, s_have_amulet, s_have_candelabrum, s_have_quest_artifact, s_quest_completed, s_entered_gehennom, s_killed_wizard) {
if(!window.parent.kongregate) return;
var stats = {
gold: s_gold,
level: s_level,
turn: s_turn,
depth: (s_depth < 1) ? (100 - s_depth) : s_depth, //s_depth < 1 for Elemental Planes
death: (s_hp <= 0) ? 1 : 0,
armorclass: 10 - s_armorclass, // armor class range from 10 to -infinity
have_amulet: s_have_amulet,
have_candelabrum: s_have_candelabrum,
have_quest_artifact: s_have_quest_artifact,
quest_completed: s_quest_completed,
entered_gehennom: s_entered_gehennom,
killed_wizard: s_killed_wizard,
ascended: s_ascended
};
if(!nethack.last_kongregate_stats) nethack.last_kongregate_stats = {};
for(var n in stats) {
Expand All @@ -1099,6 +1097,10 @@ var LibraryNetHack = {
}
},

BrowserHack_UI_report: function(str, value) {
window.parent.kongregate.stats.submit(Pointer_stringify(str), v);
},

Web_create_nhwindow: function(type) {
switch(type) {
case nethack.NHW_MESSAGE:
Expand Down
6 changes: 2 additions & 4 deletions win/web/web.c
Expand Up @@ -9,7 +9,7 @@ extern const char *killed_by_prefix[];

static int in_player_selection = 0;

void BrowserHack_update_stats_helper(int s_gold, int s_level, int s_turn, int s_depth, int s_hp, int s_armorclass, int s_have_amulet, int s_have_candelabrum, int s_have_quest_artifact, int s_quest_completed, int s_entered_gehennom, int s_killed_wizard, int s_ascended); // in JS
void BrowserHack_update_stats_helper(int s_gold, int s_level, int s_turn, int s_depth, int s_armorclass, int s_have_amulet, int s_have_candelabrum, int s_have_quest_artifact, int s_quest_completed, int s_entered_gehennom, int s_killed_wizard); // in JS
void BrowserHack_update_stats() {
if(in_player_selection) return; // should not report anything in player_selection(), at which moment the stats are invalid
BrowserHack_update_stats_helper(
Expand All @@ -21,7 +21,6 @@ void BrowserHack_update_stats() {
u.ulevel,
moves,
depth(&u.uz),
(Upolyd ? u.mh : u.uhp),
u.uac,

u.uhave.amulet,
Expand All @@ -30,8 +29,7 @@ void BrowserHack_update_stats() {

u.uevent.qcompleted,
u.uevent.gehennom_entered,
u.uevent.udemigod,
u.uevent.ascended
u.uevent.udemigod
);
}

Expand Down

0 comments on commit 17917fc

Please sign in to comment.