1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Use the enum type instead of Sint32 with the buttons

This commit is contained in:
Mathieu Schroeter 2017-08-11 20:01:49 +02:00
parent 1cd4885fc8
commit 41ae39d1dc
6 changed files with 122 additions and 149 deletions

View File

@ -775,14 +775,14 @@ void CDecor::ListFlush (Sint32 rank)
Sint32 i; Sint32 i;
for (i = 0; i < MAXLIST; i++) for (i = 0; i < MAXLIST; i++)
m_blupi[rank].listButton[i] = -1; m_blupi[rank].listButton[i] = BUTTON_NONE;
m_blupi[rank].repeatLevelHope = -1; m_blupi[rank].repeatLevelHope = -1;
m_blupi[rank].repeatLevel = -1; m_blupi[rank].repeatLevel = -1;
} }
// Retourne le paramètre associé à une action. // Retourne le paramètre associé à une action.
Sint32 CDecor::ListGetParam (Sint32 rank, Sint32 button, POINT cel) Sint32 CDecor::ListGetParam (Sint32 rank, Buttons button, POINT cel)
{ {
Sint32 icon; Sint32 icon;
@ -806,7 +806,7 @@ Sint32 CDecor::ListGetParam (Sint32 rank, Sint32 button, POINT cel)
// Ajoute une action dans la liste. // Ajoute une action dans la liste.
bool CDecor::ListPut (Sint32 rank, Sint32 button, POINT cel, POINT cMem) bool CDecor::ListPut (Sint32 rank, Buttons button, POINT cel, POINT cMem)
{ {
Sint32 i, last; Sint32 i, last;
@ -863,7 +863,7 @@ void CDecor::ListRemove (Sint32 rank)
m_blupi[rank].listParam[i] = m_blupi[rank].listParam[i + 1]; m_blupi[rank].listParam[i] = m_blupi[rank].listParam[i + 1];
} }
m_blupi[rank].listButton[MAXLIST - 1] = -1; m_blupi[rank].listButton[MAXLIST - 1] = BUTTON_NONE;
} }
// Cherche une action à répéter dans la liste. // Cherche une action à répéter dans la liste.
@ -871,7 +871,7 @@ void CDecor::ListRemove (Sint32 rank)
// Retourne -1 si aucune répétiton n'est possible. // Retourne -1 si aucune répétiton n'est possible.
Sint32 CDecor::ListSearch ( Sint32 CDecor::ListSearch (
Sint32 rank, Sint32 button, POINT cel, const char *& textForButton) Sint32 rank, Buttons button, POINT cel, const char *& textForButton)
{ {
Sint32 i, j, param, nb; Sint32 i, j, param, nb;
@ -1329,12 +1329,13 @@ Sint32 table_multi_goal[16 * 2] = {
bool CDecor::GoalNextOp (Sint32 rank, Sint16 * pTable) bool CDecor::GoalNextOp (Sint32 rank, Sint16 * pTable)
{ {
Sint32 op, x, y; Sint32 op, x, y;
Sint32 action, direct, channel, icon, mchannel, micon; Sint32 action, direct, channel, icon, mchannel, micon;
Sint32 total, step, delai, first, last, first2, last2, flag, i; Sint32 total, step, delai, first, last, first2, last2, flag, i;
Sint32 button, param; Sint32 param;
POINT pos, cel, cMem, destCel; Buttons button;
bool bOK, bError = true; POINT pos, cel, cMem, destCel;
bool bOK, bError = true;
pos = ConvCelToPos (m_blupi[rank].cel); pos = ConvCelToPos (m_blupi[rank].cel);
@ -2103,7 +2104,7 @@ error:
GoalStop (rank, bError, i == -1); GoalStop (rank, bError, i == -1);
if (i != -1) // répétition en cours ? if (i != -1) // répétition en cours ?
{ {
button = m_blupi[rank].listButton[i]; button = static_cast<Buttons> (m_blupi[rank].listButton[i]);
cMem = m_blupi[rank].listCel[i]; cMem = m_blupi[rank].listCel[i];
param = m_blupi[rank].listParam[i]; param = m_blupi[rank].listParam[i];
cel = cMem; cel = cMem;
@ -3651,10 +3652,11 @@ void CDecor::BlupiDrawHili ()
// Est utilisé pour trouver que faire lors d'un clic // Est utilisé pour trouver que faire lors d'un clic
// avec le bouton de droite. // avec le bouton de droite.
Sint32 CDecor::GetDefButton (POINT cel) Buttons CDecor::GetDefButton (POINT cel)
{ {
Sint32 button, rank, channel, icon; Buttons button;
POINT iCel; Sint32 rank, channel, icon;
POINT iCel;
iCel = cel; iCel = cel;
cel.x = (cel.x / 2) * 2; cel.x = (cel.x / 2) * 2;
@ -3662,7 +3664,7 @@ Sint32 CDecor::GetDefButton (POINT cel)
GetObject (cel, channel, icon); GetObject (cel, channel, icon);
if (m_nbBlupiHili == 0) if (m_nbBlupiHili == 0)
return -1; return BUTTON_NONE;
if (m_nbBlupiHili > 1) if (m_nbBlupiHili > 1)
return BUTTON_GO; return BUTTON_GO;
@ -3736,20 +3738,20 @@ Sint32 CDecor::GetDefButton (POINT cel)
m_blupi[rank].takeChannel != -1) && m_blupi[rank].takeChannel != -1) &&
(button == BUTTON_ABAT || button == BUTTON_CARRY || button == BUTTON_ROC || (button == BUTTON_ABAT || button == BUTTON_CARRY || button == BUTTON_ROC ||
button == BUTTON_CULTIVE)) button == BUTTON_CULTIVE))
return -1; return BUTTON_NONE;
if (m_blupi[rank].energy > (MAXENERGY / 4) * 3 && button == BUTTON_EAT) if (m_blupi[rank].energy > (MAXENERGY / 4) * 3 && button == BUTTON_EAT)
button = BUTTON_CARRY; button = BUTTON_CARRY;
if (m_buttonExist[button] == 0) // bouton existe ? if (m_buttonExist[button] == 0) // bouton existe ?
return -1; return BUTTON_NONE;
return button; return button;
} }
// Indique un but visé à Sint32 terme, pour un blupi donné. // Indique un but visé à Sint32 terme, pour un blupi donné.
bool CDecor::BlupiGoal (Sint32 rank, Sint32 button, POINT cel, POINT cMem) bool CDecor::BlupiGoal (Sint32 rank, Buttons button, POINT cel, POINT cMem)
{ {
POINT goalHili, goalHili2, goal, test; POINT goalHili, goalHili2, goal, test;
Sint32 i, action, channel, icon, error, direct, step; Sint32 i, action, channel, icon, error, direct, step;
@ -4012,7 +4014,7 @@ bool CDecor::BlupiGoal (Sint32 rank, Sint32 button, POINT cel, POINT cMem)
// Indique un but visé à Sint32 terme, pour tous les blupi // Indique un but visé à Sint32 terme, pour tous les blupi
// sélectionnés. // sélectionnés.
void CDecor::BlupiGoal (POINT cel, Sint32 button) void CDecor::BlupiGoal (POINT cel, Buttons button)
{ {
POINT bPos, avg; POINT bPos, avg;
Sint32 rank, nb, nbHili; Sint32 rank, nb, nbHili;
@ -4277,87 +4279,60 @@ bool CDecor::IsWorkBlupi (Sint32 rank)
// pour le blupi sélectionné. // pour le blupi sélectionné.
void CDecor::BlupiGetButtons ( void CDecor::BlupiGetButtons (
POINT pos, Sint32 & nb, Sint32 * pButtons, Errors * pErrors, POINT pos, Sint32 & nb, Buttons * pButtons, Errors * pErrors,
std::unordered_map<Sint32, const char *> & texts, Sint32 & perso) std::unordered_map<Sint32, const char *> & texts, Sint32 & perso)
{ {
Sint32 * pB = pButtons; Buttons * pB = pButtons;
Errors * pE = pErrors; Errors * pE = pErrors;
POINT cel, cel2; POINT cel, cel2;
Sint32 i, rank, button, channel, icon; Sint32 i, rank, channel, icon;
Errors error; Errors error;
Buttons button;
bool bBuild = false; bool bBuild = false;
bool bPut; bool bPut;
const char * textForButton; const char * textForButton;
static Sint32 table_buttons[] = {BUTTON_GO, static struct {
0, Buttons button;
BUTTON_DJEEP, Sint32 icon;
0, } table_buttons[] = {
BUTTON_DARMOR, //
0, {BUTTON_GO, 0}, //
BUTTON_EAT, {BUTTON_DJEEP, 0}, //
0, {BUTTON_DARMOR, 0}, //
BUTTON_BOIT, {BUTTON_EAT, 0}, //
0, {BUTTON_BOIT, 0}, //
BUTTON_CARRY, {BUTTON_CARRY, 0}, //
0, {BUTTON_DEPOSE, 0}, //
BUTTON_DEPOSE, {BUTTON_LABO, 0}, //
0, {BUTTON_ABAT, 0}, //
BUTTON_LABO, {BUTTON_ABATn, 0}, //
0, {BUTTON_ROC, 0}, //
BUTTON_ABAT, {BUTTON_ROCn, 0}, //
0, {BUTTON_CULTIVE, 0}, //
BUTTON_ABATn, {BUTTON_FLOWER, 0}, //
0, {BUTTON_FLOWERn, 0}, //
BUTTON_ROC, {BUTTON_DYNAMITE, 0}, //
0, {BUTTON_FLAG, 0}, //
BUTTON_ROCn, {BUTTON_EXTRAIT, 0}, //
0, {BUTTON_FABJEEP, 0}, //
BUTTON_CULTIVE, {BUTTON_FABMINE, 0}, //
0, {BUTTON_FABDISC, 0}, //
BUTTON_FLOWER, {BUTTON_MAKEARMOR, 0}, //
0, {BUTTON_BUILD1, 36}, // si planches (cabane)
BUTTON_FLOWERn, {BUTTON_BUILD2, 36}, // si planches (nurserie)
0, {BUTTON_BUILD4, 36}, // si planches (mine)
BUTTON_DYNAMITE, {BUTTON_PALIS, 36}, // si planches
0, {BUTTON_BRIDGE, 36}, // si planches
BUTTON_FLAG, {BUTTON_BOAT, 36}, // si planches
0, {BUTTON_BUILD6, 36}, // si planches (téléporteur)
BUTTON_EXTRAIT, {BUTTON_BUILD3, 44}, // si pierres (laboratoire)
0, {BUTTON_BUILD5, 44}, // si pierres (usine)
BUTTON_FABJEEP, {BUTTON_WALL, 44}, // si pierres
0, {BUTTON_TOWER, 44}, // si pierres
BUTTON_FABMINE, {BUTTON_STOP, 0}, //
0, {BUTTON_NONE, 0} //
BUTTON_FABDISC, };
0,
BUTTON_MAKEARMOR,
0,
BUTTON_BUILD1,
36, // si planches (cabane)
BUTTON_BUILD2,
36, // si planches (nurserie)
BUTTON_BUILD4,
36, // si planches (mine)
BUTTON_PALIS,
36, // si planches
BUTTON_BRIDGE,
36, // si planches
BUTTON_BOAT,
36, // si planches
BUTTON_BUILD6,
36, // si planches (téléporteur)
BUTTON_BUILD3,
44, // si pierres (laboratoire)
BUTTON_BUILD5,
44, // si pierres (usine)
BUTTON_WALL,
44, // si pierres
BUTTON_TOWER,
44, // si pierres
BUTTON_STOP,
0,
-1};
nb = 0; nb = 0;
perso = 0; perso = 0;
@ -4425,13 +4400,12 @@ void CDecor::BlupiGetButtons (
} }
// Met les différentes actions. // Met les différentes actions.
i = 0; for (size_t i = 0; i < countof (table_buttons); ++i)
while (table_buttons[i] != -1)
{ {
button = table_buttons[i]; button = table_buttons[i].button;
if (m_buttonExist[button] == 0) if (m_buttonExist[button] == 0)
goto next; continue;
error = CelOkForAction (cel, table_actions[button], m_rankBlupiHili); error = CelOkForAction (cel, table_actions[button], m_rankBlupiHili);
@ -4441,14 +4415,14 @@ void CDecor::BlupiGetButtons (
bPut = false; bPut = false;
if ( if (
bBuild && table_buttons[i + 1] != 0 && // toujours présent si matière ? bBuild && table_buttons[i].icon != 0 && // toujours présent si matière ?
(m_rankBlupiHili < 0 || (m_rankBlupiHili < 0 ||
m_blupi[m_rankBlupiHili].perso != 8 || // pas disciple ? m_blupi[m_rankBlupiHili].perso != 8 || // pas disciple ?
table_buttons[i + 1] != 44)) // ni pierres ? table_buttons[i].icon != 44)) // ni pierres ?
{ {
GetObject (cel2, channel, icon); GetObject (cel2, channel, icon);
if ( if (
channel == CHOBJECT && icon == table_buttons[i + 1] && // matière ? channel == CHOBJECT && icon == table_buttons[i].icon && // matière ?
cel.x % 2 == 1 && cel.y % 2 == 1) cel.x % 2 == 1 && cel.y % 2 == 1)
{ {
bPut = true; // bouton présent, mais disable ! bPut = true; // bouton présent, mais disable !
@ -4461,9 +4435,6 @@ void CDecor::BlupiGetButtons (
*pE++ = error; *pE++ = error;
nb++; nb++;
} }
next:
i += 2;
} }
// Si le premier bouton est "abat", ajoute "va" devant ! // Si le premier bouton est "abat", ajoute "va" devant !

View File

@ -269,45 +269,45 @@ public:
void BlupiInitAction (Sint32 rank, Sint32 action, Sint32 direct = -1); void BlupiInitAction (Sint32 rank, Sint32 action, Sint32 direct = -1);
void BlupiChangeAction (Sint32 rank, Sint32 action, Sint32 direct = -1); void BlupiChangeAction (Sint32 rank, Sint32 action, Sint32 direct = -1);
void ListFlush (Sint32 rank); void ListFlush (Sint32 rank);
Sint32 ListGetParam (Sint32 rank, Sint32 button, POINT cel); Sint32 ListGetParam (Sint32 rank, Buttons button, POINT cel);
bool ListPut (Sint32 rank, Sint32 button, POINT cel, POINT cMem); bool ListPut (Sint32 rank, Buttons button, POINT cel, POINT cMem);
void ListRemove (Sint32 rank); void ListRemove (Sint32 rank);
Sint32 ListSearch ( Sint32 ListSearch (
Sint32 rank, Sint32 button, POINT cel, const char *& textForButton); Sint32 rank, Buttons button, POINT cel, const char *& textForButton);
bool RepeatAdjust ( bool RepeatAdjust (
Sint32 rank, Sint32 button, POINT & cel, POINT & cMem, Sint32 param, Sint32 rank, Sint32 button, POINT & cel, POINT & cMem, Sint32 param,
Sint32 list); Sint32 list);
void GoalStart (Sint32 rank, Sint32 action, POINT cel); void GoalStart (Sint32 rank, Sint32 action, POINT cel);
bool GoalNextPhase (Sint32 rank); bool GoalNextPhase (Sint32 rank);
void SetTotalTime (Sint32 total); void SetTotalTime (Sint32 total);
Sint32 GetTotalTime (); Sint32 GetTotalTime ();
void GoalInitJauge (Sint32 rank); void GoalInitJauge (Sint32 rank);
void GoalInitPassCel (Sint32 rank); void GoalInitPassCel (Sint32 rank);
void GoalAdjustCel (Sint32 rank, Sint32 & x, Sint32 & y); void GoalAdjustCel (Sint32 rank, Sint32 & x, Sint32 & y);
bool GoalNextOp (Sint32 rank, Sint16 * pTable); bool GoalNextOp (Sint32 rank, Sint16 * pTable);
void GoalUnwork (Sint32 rank); void GoalUnwork (Sint32 rank);
void GoalStop (Sint32 rank, bool bError = false, bool bSound = true); void GoalStop (Sint32 rank, bool bError = false, bool bSound = true);
bool BlupiIsGoalUsed (POINT cel); bool BlupiIsGoalUsed (POINT cel);
void BlupiStartStopRayon (Sint32 rank, POINT startCel, POINT endCel); void BlupiStartStopRayon (Sint32 rank, POINT startCel, POINT endCel);
bool BlupiRotate (Sint32 rank); bool BlupiRotate (Sint32 rank);
bool BlupiNextAction (Sint32 rank); bool BlupiNextAction (Sint32 rank);
void BlupiNextGoal (Sint32 rank); void BlupiNextGoal (Sint32 rank);
void BlupiStep (bool bFirst); void BlupiStep (bool bFirst);
void BlupiGetRect (Sint32 rank, RECT & rect); void BlupiGetRect (Sint32 rank, RECT & rect);
Sint32 GetTargetBlupi (POINT pos); Sint32 GetTargetBlupi (POINT pos);
void BlupiDeselect (); void BlupiDeselect ();
void BlupiDeselect (Sint32 rank); void BlupiDeselect (Sint32 rank);
void BlupiSetArrow (Sint32 rank, bool bArrow); void BlupiSetArrow (Sint32 rank, bool bArrow);
void InitOutlineRect (); void InitOutlineRect ();
void BlupiHiliDown (POINT pos, bool bAdd = false); void BlupiHiliDown (POINT pos, bool bAdd = false);
void BlupiHiliMove (POINT pos); void BlupiHiliMove (POINT pos);
void BlupiHiliUp (POINT pos); void BlupiHiliUp (POINT pos);
void BlupiDrawHili (); void BlupiDrawHili ();
Sint32 GetDefButton (POINT cel); Buttons GetDefButton (POINT cel);
bool BlupiGoal (Sint32 rank, Sint32 button, POINT cel, POINT cMem); bool BlupiGoal (Sint32 rank, Buttons button, POINT cel, POINT cMem);
void BlupiGoal (POINT cel, Sint32 button); void BlupiGoal (POINT cel, Buttons button);
void BlupiDestCel (Sint32 rank); void BlupiDestCel (Sint32 rank);
bool IsTracksHere (POINT cel, bool bSkipInMove); bool IsTracksHere (POINT cel, bool bSkipInMove);
bool IsBlupiHereEx (POINT cel1, POINT cel2, Sint32 exRank, bool bSkipInMove); bool IsBlupiHereEx (POINT cel1, POINT cel2, Sint32 exRank, bool bSkipInMove);
bool IsBlupiHereEx (POINT cel, Sint32 exRank, bool bSkipInMove); bool IsBlupiHereEx (POINT cel, Sint32 exRank, bool bSkipInMove);
bool IsBlupiHere (POINT cel, bool bSkipInMove); bool IsBlupiHere (POINT cel, bool bSkipInMove);
@ -315,7 +315,7 @@ public:
void GetLevelJauge (Sint32 * pLevels, Sint32 * pTypes); void GetLevelJauge (Sint32 * pLevels, Sint32 * pTypes);
bool IsWorkBlupi (Sint32 rank); bool IsWorkBlupi (Sint32 rank);
void BlupiGetButtons ( void BlupiGetButtons (
POINT pos, Sint32 & nb, Sint32 * pButtons, Errors * pErrors, POINT pos, Sint32 & nb, Buttons * pButtons, Errors * pErrors,
std::unordered_map<Sint32, const char *> & texts, Sint32 & perso); std::unordered_map<Sint32, const char *> & texts, Sint32 & perso);
void TerminatedInit (); void TerminatedInit ();
Sint32 IsTerminated (); Sint32 IsTerminated ();

View File

@ -3438,10 +3438,11 @@ bool CEvent::IsShift ()
bool CEvent::PlayDown (POINT pos, const SDL_Event & event) bool CEvent::PlayDown (POINT pos, const SDL_Event & event)
{ {
bool bDecor = false; bool bDecor = false;
bool bMap = false; bool bMap = false;
Sint32 rank, button, h; Sint32 rank, h;
POINT cel; Buttons button;
POINT cel;
m_pDecor->BlupiSetArrow (0, false); // enlève toutes les flèches m_pDecor->BlupiSetArrow (0, false); // enlève toutes les flèches
@ -3613,9 +3614,10 @@ void CEvent::SetLanguage ()
void CEvent::ChangeButtons (Sint32 message) void CEvent::ChangeButtons (Sint32 message)
{ {
Sint32 button, state, volume, max; Buttons button;
char * pButtonExist; Sint32 state, volume, max;
Term * pTerm; char * pButtonExist;
Term * pTerm;
if (m_phase == EV_PHASE_PLAY) if (m_phase == EV_PHASE_PLAY)
{ {

View File

@ -200,7 +200,7 @@ protected:
bool m_bMenu; bool m_bMenu;
POINT m_menuPos; POINT m_menuPos;
Sint32 m_menuNb; Sint32 m_menuNb;
Sint32 m_menuButtons[MAXBUTTON]; Buttons m_menuButtons[MAXBUTTON];
Errors m_menuErrors[MAXBUTTON]; Errors m_menuErrors[MAXBUTTON];
std::unordered_map<Sint32, const char *> m_menuTexts; std::unordered_map<Sint32, const char *> m_menuTexts;
Sint32 m_menuPerso; Sint32 m_menuPerso;

View File

@ -154,7 +154,7 @@ CMenu::~CMenu ()
bool CMenu::Create ( bool CMenu::Create (
CPixmap * pPixmap, CSound * pSound, CEvent * pEvent, POINT pos, Sint32 nb, CPixmap * pPixmap, CSound * pSound, CEvent * pEvent, POINT pos, Sint32 nb,
Sint32 * pButtons, Errors * pErrors, Buttons * pButtons, Errors * pErrors,
std::unordered_map<Sint32, const char *> & texts, Sint32 perso) std::unordered_map<Sint32, const char *> & texts, Sint32 perso)
{ {
pos.x -= DIMBUTTONX / 2; pos.x -= DIMBUTTONX / 2;
@ -197,7 +197,7 @@ bool CMenu::Create (
// Met à jour le menu. // Met à jour le menu.
void CMenu::Update ( void CMenu::Update (
Sint32 nb, Sint32 * pButtons, Errors * pErrors, Sint32 nb, Buttons * pButtons, Errors * pErrors,
std::unordered_map<Sint32, const char *> & texts) std::unordered_map<Sint32, const char *> & texts)
{ {
Sint32 i; Sint32 i;

View File

@ -34,10 +34,10 @@ public:
bool Create ( bool Create (
CPixmap * pPixmap, CSound * pSound, CEvent * pEvent, POINT pos, Sint32 nb, CPixmap * pPixmap, CSound * pSound, CEvent * pEvent, POINT pos, Sint32 nb,
Sint32 * pButtons, Errors * pErrors, Buttons * pButtons, Errors * pErrors,
std::unordered_map<Sint32, const char *> & texts, Sint32 perso); std::unordered_map<Sint32, const char *> & texts, Sint32 perso);
void Update ( void Update (
Sint32 nb, Sint32 * pButtons, Errors * pErrors, Sint32 nb, Buttons * pButtons, Errors * pErrors,
std::unordered_map<Sint32, const char *> & texts); std::unordered_map<Sint32, const char *> & texts);
void Delete (); void Delete ();
void Draw (); void Draw ();