Match gamework.c

Also tried to split up and name gamework struct bitfields.
This commit is contained in:
gamemasterplc 2023-12-09 23:29:26 -06:00
parent 0137cf8783
commit fd44616c86
11 changed files with 551 additions and 70 deletions

362
src/game/gamework.c Normal file
View file

@ -0,0 +1,362 @@
#include "common.h"
#include "string.h"
#include "game/gamework.h"
GameStat GWGameStatDefault;
GameStat GWGameStat;
SystemState GWSystem;
PlayerState GWPlayer[4];
PlayerConfig GWPlayerCfg[4];
static inline void GWErase(void)
{
memset(GWPlayerCfg, 0, sizeof(GWPlayerCfg));
memset(GWPlayer, 0, sizeof(GWPlayer));
memset(&GWSystem, 0, sizeof(GWSystem));
}
static inline void InitPlayerConfig(void)
{
PlayerConfig *config;
s32 i;
for(i=0; i<4; i++) {
config = &GWPlayerCfg[i];
config->character = i;
config->pad_idx = i;
config->diff = 0;
config->group = i;
if(!HuPadStatGet(i)) {
config->iscom = 0;
} else {
config->iscom = 1;
}
}
}
static inline void ResetBoardSettings(void)
{
GWGameStat.rumble = 1;
GWSystem.explain_mg = 1;
GWSystem.show_com_mg = 1;
GWSystem.mess_speed = 1;
GWSystem.mess_delay = 32;
GWSystem.save_mode = 0;
}
void GWInit(void)
{
GWResetGameStat();
_InitFlag();
GWErase();
InitPlayerConfig();
GWGameStat.language = 1;
ResetBoardSettings();
}
static inline void ResetMGRecord(GameStat *game_stat)
{
game_stat->mg_record[0] = 18000;
game_stat->mg_record[1] = 80;
game_stat->mg_record[2] = 3600;
game_stat->mg_record[3] = 7200;
game_stat->mg_record[4] = 0;
game_stat->mg_record[5] = 3600;
game_stat->mg_record[6] = 18000;
game_stat->mg_record[7] = 18000;
game_stat->mg_record[8] = 18000;
game_stat->mg_record[9] = 0;
game_stat->mg_record[10] = 300;
game_stat->mg_record[11] = 0;
game_stat->mg_record[12] = 0;
game_stat->mg_record[13] = 0;
game_stat->mg_record[14] = 0;
}
static inline void ResetBoardRecord(GameStat *game_stat)
{
s32 i;
s32 j;
for(i=0; i<9; i++) {
for(j=0; j<8; j++) {
game_stat->board_win_count[i][j] = 0;
}
game_stat->board_play_count[i] = 0;
game_stat->board_max_stars[i] = 0;
game_stat->board_max_coins[i] = 0;
}
}
static inline void ResetPresent(GameStat *game_stat)
{
s32 i;
for(i=0; i<60; i++) {
game_stat->present[i] = 0;
}
(void)i; //HACK to match GWResetGameStat
}
static inline void ResetFlag(GameStat *game_stat)
{
game_stat->story_continue = 0;
game_stat->party_continue = 0;
game_stat->open_w06 = 0;
game_stat->field10E_bit4 = 0;
game_stat->field10E_bit5 = 0;
game_stat->field10E_bit6 = 0;
game_stat->field10F_bit0 = game_stat->field110_bit0 = 1;
game_stat->field10F_bit1 = game_stat->field110_bit1 = 1;
game_stat->field10F_bit2 = game_stat->field110_bit2 = 0;
game_stat->field10F_bit4 = game_stat->field110_bit4 = 1;
game_stat->field10F_bit6 = game_stat->field110_bit6 = 0;
}
void GWResetGameStat(void)
{
GameStat *game_stat = &GWGameStatDefault;
memset(game_stat, 0, sizeof(GameStat));
game_stat->unk_00 = 0;
game_stat->language = 1;
game_stat->sound_mode = 1;
game_stat->rumble = 1;
game_stat->total_stars = 0;
game_stat->create_time = 0;
game_stat->mg_custom[0] = 0;
game_stat->mg_custom[1] = 0;
game_stat->mg_avail[0] = 0;
game_stat->mg_avail[1] = 0;
ResetMGRecord(game_stat);
ResetBoardRecord(game_stat);
ResetPresent(game_stat);
ResetFlag(game_stat);
memcpy(&GWGameStat, &GWGameStatDefault, sizeof(GameStat));
ResetBoardSettings();
}
s16 GWGetMessSpeed(void)
{
if(GWSystem.mess_delay > 48) {
GWSystem.mess_speed = 1;
GWSystem.mess_delay = 32;
}
return GWSystem.mess_delay;
}
void GWSetMGRecord(int index, s32 value)
{
if(!_CheckFlag(0x1000C)) {
GWGameStat.mg_record[index] = value;
}
}
s32 GWGetMGRecord(int index)
{
return GWGameStat.mg_record[index];
}
void GWGetCharColor(int character, GXColor *color)
{
GXColor char_color[] = {
{ 227, 67, 67, 255 },
{ 68, 67, 227, 255 },
{ 241, 158, 220, 255 },
{ 67, 228, 68, 255 },
{ 138, 60, 180, 255 },
{ 146, 85, 55, 255 },
{ 227, 228, 68, 255 },
{ 40, 40, 40, 255 }
};
*color = char_color[character];
}
void GWSetBoardPlayCount(int board, u8 value)
{
if(value > 99) {
value = 99;
}
GWGameStat.board_play_count[board] = value;
}
void GWAddBoardPlayCount(int board, u8 value)
{
value += GWGameStat.board_play_count[board];
if(value > 99) {
value = 99;
}
GWGameStat.board_play_count[board] = value;
}
u8 GWGetBoardPlayCount(int board)
{
return GWGameStat.board_play_count[board];
}
void GWSetBoardMaxStars(int board, int value)
{
GWGameStat.board_max_stars[board] = value;
}
u16 GWGetBoardMaxStars(int board)
{
return GWGameStat.board_max_stars[board];
}
void GWSetBoardMaxCoins(int board, int value)
{
GWGameStat.board_max_coins[board] = value;
}
u16 GWGetBoardMaxCoins(int board)
{
return GWGameStat.board_max_coins[board];
}
int GWIncBoardWinCount(int character, int board)
{
int win_count = GWGameStat.board_win_count[board][character]+1;
if(win_count > 99) {
win_count = 99;
}
GWGameStat.board_win_count[board][character] = win_count;
return win_count;
}
int GWGetBoardWinCount(int character, int board)
{
return GWGameStat.board_win_count[board][character];
}
void GWSetBoardWinCount(int character, int board, int value)
{
GWGameStat.board_win_count[board][character] = value;
}
int GWGetMGAvail(int id)
{
int word;
int bit;
id -= 401;
word = id >> 5;
bit = id % 32;
if(GWGameStat.mg_avail[word] & (1 << bit)) {
return 1;
} else {
return 0;
}
}
int GWSetMGAvail(int id)
{
int word;
int bit;
id -= 401;
word = id >> 5;
bit = id % 32;
GWGameStat.mg_avail[word] |= (1 << bit);
}
int GWGetMGCustom(int id)
{
int word;
int bit;
id -= 401;
word = id >> 5;
bit = id % 32;
if(GWGameStat.mg_custom[word] & (1 << bit)) {
return 1;
} else {
return 0;
}
}
int GWSetMGCustom(int id)
{
int word;
int bit;
id -= 401;
word = id >> 5;
bit = id % 32;
GWGameStat.mg_custom[word] |= (1 << bit);
}
int GWResetMGCustom(int id)
{
int word;
int bit;
id -= 401;
word = id >> 5;
bit = id % 32;
GWGameStat.mg_custom[word] &= ~(1 << bit);
}
s16 GWGetCoins(int player)
{
return GWPlayer[player].coins;
}
void GWSetCoins(int player, s16 value)
{
if(!_CheckFlag(0x1000C)) {
if(value < 0) {
value = 0;
}
if(value > 999) {
value = 999;
}
if(value > GWPlayer[player].coins_max) {
GWPlayer[player].coins_max = value;
}
GWPlayer[player].coins = value;
}
}
void GWAddCoins(int player, s16 amount)
{
GWSetCoins(player, GWPlayer[player].coins+amount);
}
void GWSetStars(int player, s16 value)
{
if(value < 0) {
value = 0;
}
if(value > 999) {
value = 999;
}
if(value > GWPlayer[player].stars_max) {
GWPlayer[player].stars_max = value;
}
GWPlayer[player].stars = value;
}
void GWAddStars(int player, s16 amount)
{
GWSetStars(player, GWPlayer[player].stars+amount);
}
s16 GWGetStars(int player)
{
return GWPlayer[player].stars;
}
void GWSetTotalStars(s16 value)
{
if(value < 0) {
value = 0;
}
if(value > 10000) {
value = 10000;
}
GWGameStat.total_stars = value;
}
void GWAddTotalStars(s16 amount)
{
GWSetTotalStars(GWGameStat.total_stars+amount);
}
u16 GWGetTotalStars(void)
{
return GWGameStat.total_stars;
}