Merge pull request #7196 from furo321/add-optional-arguments

Add optional argument to movement commands
This commit is contained in:
Robert Müller 2023-09-20 15:04:54 +00:00 committed by GitHub
commit 2c7df07fd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View file

@ -36,10 +36,10 @@ CONSOLE_COMMAND("deep", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConDeep, this, "Puts
CONSOLE_COMMAND("undeep", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnDeep, this, "Puts you out of deep freeze") CONSOLE_COMMAND("undeep", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnDeep, this, "Puts you out of deep freeze")
CONSOLE_COMMAND("livefreeze", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConLiveFreeze, this, "Makes you live frozen") CONSOLE_COMMAND("livefreeze", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConLiveFreeze, this, "Makes you live frozen")
CONSOLE_COMMAND("unlivefreeze", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnLiveFreeze, this, "Puts you out of live freeze") CONSOLE_COMMAND("unlivefreeze", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnLiveFreeze, this, "Puts you out of live freeze")
CONSOLE_COMMAND("left", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoLeft, this, "Makes you move 1 tile left") CONSOLE_COMMAND("left", "?i[tiles]", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoLeft, this, "Makes you move 1 tile left")
CONSOLE_COMMAND("right", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoRight, this, "Makes you move 1 tile right") CONSOLE_COMMAND("right", "?i[tiles]", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoRight, this, "Makes you move 1 tile right")
CONSOLE_COMMAND("up", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoUp, this, "Makes you move 1 tile up") CONSOLE_COMMAND("up", "?i[tiles]", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoUp, this, "Makes you move 1 tile up")
CONSOLE_COMMAND("down", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoDown, this, "Makes you move 1 tile down") CONSOLE_COMMAND("down", "?i[tiles]", CFGFLAG_SERVER | CMDFLAG_TEST, ConGoDown, this, "Makes you move 1 tile down")
CONSOLE_COMMAND("move", "i[x] i[y]", CFGFLAG_SERVER | CMDFLAG_TEST, ConMove, this, "Moves to the tile with x/y-number ii") CONSOLE_COMMAND("move", "i[x] i[y]", CFGFLAG_SERVER | CMDFLAG_TEST, ConMove, this, "Moves to the tile with x/y-number ii")
CONSOLE_COMMAND("move_raw", "i[x] i[y]", CFGFLAG_SERVER | CMDFLAG_TEST, ConMoveRaw, this, "Moves to the point with x/y-coordinates ii") CONSOLE_COMMAND("move_raw", "i[x] i[y]", CFGFLAG_SERVER | CMDFLAG_TEST, ConMoveRaw, this, "Moves to the point with x/y-coordinates ii")

View file

@ -15,33 +15,41 @@ bool CheckClientID(int ClientID);
void CGameContext::ConGoLeft(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConGoLeft(IConsole::IResult *pResult, void *pUserData)
{ {
CGameContext *pSelf = (CGameContext *)pUserData; CGameContext *pSelf = (CGameContext *)pUserData;
int Tiles = pResult->NumArguments() == 1 ? pResult->GetInteger(0) : 1;
if(!CheckClientID(pResult->m_ClientID)) if(!CheckClientID(pResult->m_ClientID))
return; return;
pSelf->MoveCharacter(pResult->m_ClientID, -1, 0); pSelf->MoveCharacter(pResult->m_ClientID, -1 * Tiles, 0);
} }
void CGameContext::ConGoRight(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConGoRight(IConsole::IResult *pResult, void *pUserData)
{ {
CGameContext *pSelf = (CGameContext *)pUserData; CGameContext *pSelf = (CGameContext *)pUserData;
int Tiles = pResult->NumArguments() == 1 ? pResult->GetInteger(0) : 1;
if(!CheckClientID(pResult->m_ClientID)) if(!CheckClientID(pResult->m_ClientID))
return; return;
pSelf->MoveCharacter(pResult->m_ClientID, 1, 0); pSelf->MoveCharacter(pResult->m_ClientID, Tiles, 0);
} }
void CGameContext::ConGoDown(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConGoDown(IConsole::IResult *pResult, void *pUserData)
{ {
CGameContext *pSelf = (CGameContext *)pUserData; CGameContext *pSelf = (CGameContext *)pUserData;
int Tiles = pResult->NumArguments() == 1 ? pResult->GetInteger(0) : 1;
if(!CheckClientID(pResult->m_ClientID)) if(!CheckClientID(pResult->m_ClientID))
return; return;
pSelf->MoveCharacter(pResult->m_ClientID, 0, 1); pSelf->MoveCharacter(pResult->m_ClientID, 0, Tiles);
} }
void CGameContext::ConGoUp(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConGoUp(IConsole::IResult *pResult, void *pUserData)
{ {
CGameContext *pSelf = (CGameContext *)pUserData; CGameContext *pSelf = (CGameContext *)pUserData;
int Tiles = pResult->NumArguments() == 1 ? pResult->GetInteger(0) : 1;
if(!CheckClientID(pResult->m_ClientID)) if(!CheckClientID(pResult->m_ClientID))
return; return;
pSelf->MoveCharacter(pResult->m_ClientID, 0, -1); pSelf->MoveCharacter(pResult->m_ClientID, 0, -1 * Tiles);
} }
void CGameContext::ConMove(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConMove(IConsole::IResult *pResult, void *pUserData)