Skip to content

Commit

Permalink
really fix p1p2 scheduling issues
Browse files Browse the repository at this point in the history
revert: allyplayers was a bad idea
  • Loading branch information
cylonicboom committed Aug 18, 2024
1 parent c86184a commit 3202ead
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/game/chr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4952,7 +4952,7 @@ struct prop *chrGetTargetProp(struct chrdata *chr)
struct prop *ret;

if (chr->target == -1) {
ret = g_Vars.allyplayers[chr->p1p2]->prop;
ret = g_Vars.players[chr->p1p2]->prop;
} else {
ret = g_Vars.props + chr->target;
}
Expand Down
34 changes: 15 additions & 19 deletions src/game/chraction.c
Original file line number Diff line number Diff line change
Expand Up @@ -14227,21 +14227,20 @@ s32 chrResolveId(struct chrdata *ref, s32 id)
break;
case CHR_P1P2:
{
u32 index = g_Vars.currentallyplayernum;
struct player *player = g_Vars.allyplayers[index];
if (player && player->prop && player->prop->chr) {
u32 index = g_Vars.coopplayernum >= 0 ? ref->p1p2 : g_Vars.bondplayernum;
struct player *player = g_Vars.players[index];
if (player && player->prop && player->prop->chr && !g_Vars.antiplayers[index]) {
id = player->prop->chr->chrnum;
}
}
break;
case CHR_P1P2_OPPOSITE:
u32 index = g_Vars.bondplayernum;
if (g_Vars.currentcoopplayernum != g_Vars.currentplayernum) {
index = g_Vars.currentcoopplayernum;
}
struct player *player = g_Vars.players[index];
if (player && player->prop && player->prop->chr) {
id = player->prop->chr->chrnum;
if (g_Vars.coopplayernum >= 0) {
s32 index = (MAX_PLAYERS-1)-ref->p1p2;;
struct player *player = g_Vars.players[index];
if (player && player->prop && player->prop->chr && !g_Vars.antiplayers[index]) {
id = player->prop->chr->chrnum;
}
}
break;
case CHR_TARGET:
Expand Down Expand Up @@ -14272,21 +14271,18 @@ s32 chrResolveId(struct chrdata *ref, s32 id)
break;
case CHR_P1P2:
{
u32 index = g_Vars.currentallyplayernum;
struct player *player = g_Vars.allyplayers[index];
struct player *player = g_Vars.players[g_Vars.bondplayernum];
if (player && player->prop && player->prop->chr) {
id = player->prop->chr->chrnum;
}
}
break;
case CHR_P1P2_OPPOSITE:
u32 index = g_Vars.bondplayernum;
if (g_Vars.currentcoopplayernum != g_Vars.currentplayernum) {
index = g_Vars.currentcoopplayernum;
}
struct player *player = g_Vars.players[index];
if (player && player->prop && player->prop->chr) {
id = player->prop->chr->chrnum;
if (g_Vars.coopplayernum >= 0) {
struct player *player = g_Vars.players[g_Vars.coopplayernum];
if (player && player->prop && player->prop->chr) {
id = player->prop->chr->chrnum;
}
}
break;
}
Expand Down
22 changes: 10 additions & 12 deletions src/game/chraicommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,6 @@ struct player** getPlayerPool(u32 chrId) {
playerpool = (struct player**)g_Vars.coopplayers;
break;
case CHR_P1P2:
playerpool = (struct player**)g_Vars.allyplayers;
break;
default:
playerpool = (struct player**)g_Vars.players;
break;
Expand Down Expand Up @@ -1682,7 +1680,7 @@ bool aiIfSeesSuspiciousItem(void)
*/
bool aiIfCheckFovWithTarget(void)
{
bool pass;
bool pass = 0;
u8 *cmd = g_Vars.ailist + g_Vars.aioffset;

u16 temptarget = g_Vars.chrdata->target;
Expand All @@ -1691,7 +1689,7 @@ bool aiIfCheckFovWithTarget(void)
if (cmd[3]) {
if (isChrTargetCoop(g_Vars.chrdata)) {
temptarget = g_Vars.chrdata->target;
for (s32 i = 0; i < PLAYERCOUNT(); i++) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (pass) break;
if (!g_Vars.coopplayers[i]) continue;
chrSetTargetProp(g_Vars.chrdata, g_Vars.coopplayers[i]->prop);
Expand All @@ -1702,7 +1700,7 @@ bool aiIfCheckFovWithTarget(void)
} else {
if (isChrTargetCoop(g_Vars.chrdata)) {
temptarget = g_Vars.chrdata->target;
for (s32 i = 0; i < PLAYERCOUNT(); i++) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (pass) break;
if (!g_Vars.coopplayers[i]) continue;
chrSetTargetProp(g_Vars.chrdata, g_Vars.coopplayers[i]->prop);
Expand All @@ -1714,7 +1712,7 @@ bool aiIfCheckFovWithTarget(void)
} else {
if (isChrTargetCoop(g_Vars.chrdata)) {
temptarget = g_Vars.chrdata->target;
for (s32 i = 0; i < PLAYERCOUNT(); i++) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (pass) break;
if (!g_Vars.coopplayers[i]) continue;
chrSetTargetProp(g_Vars.chrdata, g_Vars.coopplayers[i]->prop);
Expand Down Expand Up @@ -9271,10 +9269,10 @@ bool aiToggleP1P2(void)
struct chrdata *chr = chrFindById(g_Vars.chrdata, cmd[2]);

if (chr) {
if (g_Vars.allyplayers[g_Vars.currentallyplayernum]->isdead) {
chr->p1p2 = 0;
} else {
chr->p1p2 = g_Vars.currentallyplayernum;
if (chr->p1p2 == g_Vars.bondplayernum && !g_Vars.coop->isdead) {
chr->p1p2 = g_Vars.coopplayernum;
} else if (!g_Vars.bond->isdead) {
chr->p1p2 = g_Vars.bondplayernum;
}
}
}
Expand All @@ -9300,9 +9298,9 @@ bool aiChrSetP1P2(void)

if (!g_Vars.players[playernum]->isdead) {
if (chr2->prop == g_Vars.coop->prop) {
chr1->p1p2 = g_Vars.currentallyplayernum;
chr1->p1p2 = g_Vars.coopplayernum;
} else {
chr1->p1p2 = 0;
chr1->p1p2 = g_Vars.bondplayernum;
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/game/lv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,14 +1338,6 @@ Gfx *lvRender(Gfx *gdl)
gdl = nbombsRender(gdl);
}

// printf("g_Vars.currentplayernum = %d\n", g_Vars.currentplayernum);
// printf("g_Vars.currentantiplayernum = %d\n", g_Vars.currentantiplayernum);
// printf("g_Vars.currentallyplayernum = %d\n", g_Vars.currentallyplayernum);
// printf("g_Vars.currentcoopplayernum = %d\n", g_Vars.currentcoopplayernum);
// printf("p1p2 playernum: %x\n", playermgrGetPlayerNumByProp(chrFindByLiteralId(chrResolveId(0, CHR_P1P2))->prop));
// printf("p1p2_opposite_prop: %x\n",(chrFindByLiteralId(chrResolveId(0, CHR_P1P2_OPPOSITE))));
// printf("bond_prop: %x\n", g_Vars.bond->prop);

if (var80075d60 == 2) {
gdl = playerRenderHud(gdl);

Expand Down
21 changes: 5 additions & 16 deletions src/game/playermgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@ void playermgrAllocatePlayersFromRoles(void)

g_Vars.bond = g_Vars.players[g_Vars.bondplayernum];

// setup ally players here
// we'll need to update this
// when the coop list changes
s32 allyindex = 0;
g_Vars.allyplayers[0] = g_Vars.bond;
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (g_Vars.coopplayers[i]) {
g_Vars.allyplayers[++allyindex] = g_Vars.coopplayers[i];
}
}
g_Vars.currentallyplayernum = allyindex;

setCurrentPlayerNum(0); // don't think this needed for player loading but probably is there to restart the playerloop

}
Expand Down Expand Up @@ -793,6 +781,7 @@ void setCurrentCoopNum(s32 playernum)
{
if (g_Vars.coopplayers[playernum]) {
g_Vars.currentcoopplayernum = playernum;
g_Vars.currentallyplayernum = playernum % (getNumAllyPlayers() - 1);
g_Vars.coopplayernum = playernum;
g_Vars.coop = g_Vars.coopplayers[playernum];
g_Vars.antiplayernum = -1;
Expand All @@ -805,15 +794,15 @@ void setCurrentPlayerNum(s32 playernum)
g_Vars.currentplayernum = playernum;
g_Vars.currentplayer = g_Vars.players[playernum];
g_Vars.currentplayerstats = &g_Vars.playerstats[playernum];
if (g_Vars.antiplayers[playernum]) {
if (g_Vars.currentplayernum == g_Vars.bondplayernum) {
g_Vars.currentallyplayernum = g_Vars.bondplayernum;
}
else if (g_Vars.antiplayers[playernum]) {
setCurrentAntiNum(playernum);
}
else if (g_Vars.coopplayers[playernum]) {
setCurrentCoopNum(playernum);
}

g_Vars.currentallyplayernum++;
if (!g_Vars.allyplayers[g_Vars.currentallyplayernum]) g_Vars.currentallyplayernum = 0;
g_Vars.currentplayerindex = playermgrGetOrderOfPlayer(playernum);
}

Expand Down
15 changes: 0 additions & 15 deletions src/game/title.c
Original file line number Diff line number Diff line change
Expand Up @@ -2238,21 +2238,6 @@ s32 getNumAllyPlayers(void)

}

s32 getNumAntiPlayers(void)
{
s32 count = 0;
s32 i;

for (i = 0; i < MAX_PLAYERS; i++) {
if (g_Vars.playerroles[i] && g_Vars.playerroles[i] == PLAYERROLE_ANTI) {
count++;
}
}

return count;

}

s32 getNumTeamModePlayers(void)
{
s32 count = 0;
Expand Down
1 change: 0 additions & 1 deletion src/include/game/title.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void titleExitLegal(void);
s32 getNumPlayers(void);
s32 getNumTeamModePlayers(void);
s32 getNumAllyPlayers(void);
s32 getNumAntiPlayers(void);
void setNumPlayers(s32 numplayers);
void titleExitNoController(void);

Expand Down

0 comments on commit 3202ead

Please sign in to comment.