Skip to content

Commit

Permalink
Support milestones in multiplayer
Browse files Browse the repository at this point in the history
Additionally, some reformatting.
  • Loading branch information
MrAlaux committed Mar 29, 2024
1 parent bf2f5ba commit 7234f47
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Changes

None.
- **Support for _Milestone Completion Announcements_ in multiplayer**

## Bug Fixes

Expand Down
48 changes: 35 additions & 13 deletions src/p_inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,16 +687,28 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher)
return; // killough 12/98: suppress error message
}

if (special->flags & MF_COUNTITEM) {
if (special->flags & MF_COUNTITEM)
{
player->itemcount++;

// [Nugget] Announce milestone completion
if (!(complete_milestones & MILESTONE_ITEMS)
&& (player->itemcount >= totalitems))
if (!(complete_milestones & MILESTONE_ITEMS))
{
complete_milestones |= MILESTONE_ITEMS;
if (announce_milestones) {
player->secretmessage = "All items acquired!";
S_StartSound(NULL, sfx_secret);
int itemcount = 0;

for (int pl = 0; pl < MAXPLAYERS; ++pl) {
if (playeringame[pl])
{ itemcount += players[pl].itemcount; }
}

if (itemcount >= totalitems)
{
complete_milestones |= MILESTONE_ITEMS;

if (announce_milestones) {
players[displayplayer].secretmessage = "All items acquired!";
S_StartSound(NULL, sfx_secret);
}
}
}
}
Expand Down Expand Up @@ -864,13 +876,23 @@ static void P_KillMobj(mobj_t *source, mobj_t *target, method_t mod)
#endif

// [Nugget] Announce milestone completion
if (!(complete_milestones & MILESTONE_KILLS)
&& ((players->killcount - players->maxkilldiscount) >= max_kill_requirement))
if (!(complete_milestones & MILESTONE_KILLS))
{
complete_milestones |= MILESTONE_KILLS;
if (announce_milestones) {
players->secretmessage = "All enemies killed!";
S_StartSound(NULL, sfx_secret);
int killcount = 0;

for (int pl = 0; pl < MAXPLAYERS; ++pl) {
if (playeringame[pl])
{ killcount += players[pl].killcount - players[pl].maxkilldiscount; }
}

if (killcount >= max_kill_requirement)
{
complete_milestones |= MILESTONE_KILLS;

if (announce_milestones) {
players[displayplayer].secretmessage = "All enemies killed!";
S_StartSound(NULL, sfx_secret);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,16 @@ void P_LoadThings (int lump)
P_SpawnMapThing (mt);
}

// [Nugget] Reset milestones
// [Nugget] Reset milestones / ---------------------------------------------

if (totalkills) { complete_milestones &= ~MILESTONE_KILLS; }
else { complete_milestones |= MILESTONE_KILLS; }

if (totalitems) { complete_milestones &= ~MILESTONE_ITEMS; }
else { complete_milestones |= MILESTONE_ITEMS; }

// [Nugget] ---------------------------------------------------------------/

Z_Free (data);
}

Expand Down
32 changes: 20 additions & 12 deletions src/p_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,28 +2161,36 @@ int disable_nuke; // killough 12/98: nukage disabling cheat

static void P_SecretRevealed(player_t *player)
{
if (player == &players[consoleplayer])
// [Nugget] Announce milestone completion
if (!(complete_milestones & MILESTONE_SECRETS))
{
// [Nugget] Announce milestone completion
if (!(complete_milestones & MILESTONE_SECRETS)
&& player->secretcount >= totalsecret)
int secretcount = 0;

for (int pl = 0; pl < MAXPLAYERS; ++pl) {
if (playeringame[pl])
{ secretcount += players[pl].secretcount; }
}

if (secretcount >= totalsecret)
{
complete_milestones |= MILESTONE_SECRETS;

if (announce_milestones) {
player->secretmessage = "All secrets revealed!";
players[displayplayer].secretmessage = "All secrets revealed!";
S_StartSound(NULL, sfx_secret);
return; // Skip the normal "Secret revealed" message
}
}
}

if (hud_secret_message) {
// [Nugget] Secret count in secret revealed message, from Crispy Doom
static char str_count[32];
M_snprintf(str_count, sizeof(str_count), "Secret %d of %d revealed!", player->secretcount, totalsecret);
if (hud_secret_message && player == &players[consoleplayer])
{
// [Nugget] Secret count in secret revealed message, from Crispy Doom
static char str_count[32];
M_snprintf(str_count, sizeof(str_count), "Secret %d of %d revealed!", player->secretcount, totalsecret);

player->secretmessage = (hud_secret_message == secretmessage_count) ? str_count : s_HUSTR_SECRETFOUND;
S_StartSound(NULL, sfx_secret);
}
player->secretmessage = (hud_secret_message == secretmessage_count) ? str_count : s_HUSTR_SECRETFOUND;
S_StartSound(NULL, sfx_secret);
}
}

Expand Down

0 comments on commit 7234f47

Please sign in to comment.