Skip to content

Commit

Permalink
some helper functions for checking coop / antiness
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonNyan committed May 27, 2024
1 parent 52d56f0 commit 6cd0154
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/game/chr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6670,3 +6670,29 @@ void chrSetDrCarollImages(struct chrdata *drcaroll, s32 imageleft, s32 imagerigh
}
}
}

// in a glorious future
// when bond and every human hench can have their own
// ai buddies (technicaly possible?)
// we can swap these PLAYERCOUNT checks
// for something smarter (like checking for buddies)
bool isChrIdMpHumanHench(u32 chrId) {
if (PLAYERCOUNT() < 2) {
return false;
}
return (chrId == CHR_COOP || chrId == CHR_ANTI || chrId == CHR_ANTI || chrId == CHR_P1P2 || chrId == CHR_P1P2_OPPOSITE);
}

bool isChrIdMpHumanCoop(u32 chrId) {
if (PLAYERCOUNT() < 2) {
return false;
}
return chrId == CHR_COOP || chrId == CHR_P1P2_OPPOSITE || chrId == CHR_P1P2;
}

bool isChrIdMpHumanAnti(u32 chrId) {
if (PLAYERCOUNT() < 2) {
return false;
}
return chrId == CHR_ANTI;
}
10 changes: 6 additions & 4 deletions src/game/chraicommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ bool aiGiveObjectToChr(void)
u32 chrId = cmd[3];
struct chrdata *chr = chrFindById(g_Vars.chrdata, cmd[3]);

if (obj && obj->prop && (chrId == CHR_COOP || chrId == CHR_ANTI || chrId == CHR_ANTI || chrId == CHR_P1P2 || chrId == CHR_P1P2_OPPOSITE)) {
if (obj && obj->prop && isChrIdMpHumanHench(chrId)) {
struct player** playerpool = getPlayerPool(chrId);
for (s32 i = 0; i < MAX_PLAYERS; i++){
u32 playernum = g_Vars.playerorder[i];
Expand Down Expand Up @@ -3569,7 +3569,7 @@ bool aiChrSetChrflag(void)
u32 flags = (cmd[4] << 16) | (cmd[5] << 8) | cmd[6] | (cmd[3] << 24);
u32 chrId = cmd[2];
struct chrdata* chr;
if (chrId == CHR_ANTI || chrId == CHR_COOP || chrId == CHR_P1P2 || chrId == CHR_P1P2_OPPOSITE) {
if (isChrIdMpHumanHench(chrId)) {
struct player** playerpool = getPlayerPool(chrId);
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (!playerpool[g_Vars.playerorder[i]]) {
Expand Down Expand Up @@ -3602,7 +3602,9 @@ bool aiChrUnsetChrflag(void)
{
u8 *cmd = g_Vars.ailist + g_Vars.aioffset;
u32 flags = (cmd[4] << 16) | (cmd[5] << 8) | cmd[6] | (cmd[3] << 24);
struct chrdata *chr = chrFindById(g_Vars.chrdata, cmd[2]);
u32 chrId = cmd[2];
struct chrdata *chr;
chr = chrFindById(g_Vars.chrdata, cmd[2]);

if (chr) {
chr->chrflags &= ~flags;
Expand Down Expand Up @@ -3640,7 +3642,7 @@ bool aiChrSetHiddenFlag(void)
u32 flags = (cmd[4] << 16) | (cmd[5] << 8) | cmd[6] | (cmd[3] << 24);
u32 chrId = cmd[2];
struct chrdata* chr;
if (chrId == CHR_ANTI || chrId == CHR_COOP || chrId == CHR_P1P2) {
if (isChrIdMpHumanHench(chrId)) {
struct player** playerpool = getPlayerPool(chrId);
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (!playerpool[g_Vars.playerorder[i]]) {
Expand Down
3 changes: 3 additions & 0 deletions src/include/game/chr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "data.h"
#include "types.h"

bool isChrIdMpHumanHench(u32 chrId);
bool isChrIdMpHumanCoop(u32 chrId);
bool isChrIdMpHumanAnti(u32 chrId);
void chrSetChrnum(struct chrdata *chr, s16 chrnum);
void chrDeregister(s32 chrnum);
void chrCalculatePushPos(struct chrdata *chr, struct coord *pos, RoomNum *rooms, bool arg3);
Expand Down

0 comments on commit 6cd0154

Please sign in to comment.