Skip to content

Commit

Permalink
Fixed bug with required optional parameters of MorphActor function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dasperal authored and coelckers committed Aug 28, 2020
1 parent 8a7d09c commit 51b7e7e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
100 changes: 100 additions & 0 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static void ActionOnCharRange(boolean write);
static void LeadingStrcpy(void);
static void LeadingPrint(void);
static void LeadingHudMessage(void);
static void LeadingMorphActor(void);
static void LeadingVarAssign(symbolNode_t *sym);
static pcd_t GetAssignPCD(tokenType_t token, symbolType_t symbol);
static void LeadingInternFunc(symbolNode_t *sym);
Expand Down Expand Up @@ -1385,6 +1386,12 @@ static boolean ProcessStatement(statement_t owner)
case TK_HUDMESSAGEBOLD:
LeadingHudMessage();
break;
case TK_MORPHACTOR:
LeadingMorphActor();
PC_AppendCmd(PCD_DROP);
TK_NextTokenMustBe(TK_SEMICOLON, ERR_MISSING_SEMICOLON);
TK_NextToken();
break;
case TK_IF:
LeadingIf();
break;
Expand Down Expand Up @@ -2523,6 +2530,95 @@ static void LeadingHudMessage(void)
TK_NextToken();
}

//==========================================================================
//
// LeadingMorphActor
//
// MorphActor(int tid, [str playerclass, [str monsterclass, [int duration, [int style, [str morphflash, [str unmorphflash]]]]]])
//
//==========================================================================

static void LeadingMorphActor(void)
{
int i;
byte strMask;

MS_Message(MSG_DEBUG, "---- LeadingMorphActor ----\n");
strMask = 0b01100110;

TK_NextTokenMustBe(TK_LPAREN, ERR_MISSING_LPAREN);
if(TK_NextToken() == TK_CONST)
{
TK_NextTokenMustBe(TK_COLON, ERR_MISSING_COLON);
ERR_Error(ERR_NO_DIRECT_VER, YES, NULL);
TK_NextToken();
}
i = 0;
if(tk_Token == TK_RPAREN)
{
ERR_Error(ERR_MISSING_PARAM, YES);
}
else
{
TK_Undo(); // Adjust for first expression
do
{
if(i == 7)
{
ERR_Error(ERR_BAD_ARG_COUNT, YES);
TK_SkipTo(TK_SEMICOLON);
TK_Undo();
return;
}
TK_NextToken();

if(tk_Token != TK_COMMA)
{
EvalExpression();
}
else
{
if(i > 0)
{
if(strMask & 1)
{
PC_AppendPushVal(STR_Find(""));
}
else
{
PC_AppendPushVal(0);
}
}
else
{
ERR_Error(ERR_MISSING_PARAM, YES);
}
}
i++;
strMask >>= 1;
} while(tk_Token == TK_COMMA);
}
while(i < 7)
{
if(strMask & 1)
{
PC_AppendPushVal(STR_Find(""));
}
else
{
PC_AppendPushVal(0);
}
i++;
strMask >>= 1;
}
if(i != 7)
{
ERR_Error(ERR_BAD_ARG_COUNT, YES);
}
TK_TokenMustBe(TK_RPAREN, ERR_MISSING_RPAREN);
PC_AppendCmd(PCD_MORPHACTOR);
}

//==========================================================================
//
// LeadingCreateTranslation
Expand Down Expand Up @@ -3822,6 +3918,10 @@ static void ExprFactor(void)
LeadingStrcpy();
TK_NextToken();
break;
case TK_MORPHACTOR:
LeadingMorphActor();
TK_NextToken();
break;
default:
ERR_Error(ERR_BAD_EXPR, YES);
TK_NextToken();
Expand Down
1 change: 0 additions & 1 deletion symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ static internFuncDef_t InternalFunctions[] =
{ "thingcountsector", PCD_NOP, PCD_THINGCOUNTSECTOR, 3, 0, 0, YES, NO },
{ "thingcountnamesector", PCD_NOP, PCD_THINGCOUNTNAMESECTOR, 3, 0, 0, YES, NO },
{ "checkplayercamera", PCD_NOP, PCD_CHECKPLAYERCAMERA, 1, 0, 0, YES, NO },
{ "morphactor", PCD_NOP, PCD_MORPHACTOR, 7, 2|4|8|16|32|64, 0, YES, NO },
{ "unmorphactor", PCD_NOP, PCD_UNMORPHACTOR, 2, 2, 0, YES, NO },
{ "getplayerinput", PCD_NOP, PCD_GETPLAYERINPUT, 2, 0, 0, YES, NO },
{ "classifyactor", PCD_NOP, PCD_CLASSIFYACTOR, 1, 0, 0, YES, NO },
Expand Down
1 change: 1 addition & 0 deletions token.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ static struct keyword_s
{ "endregion", TK_ENDREGION }, // [mxd]
{ "kill", TK_KILL }, // [JM]
{ "reopen", TK_REOPEN }, // [Nash]
{ "morphactor", TK_MORPHACTOR }, // [Dasperal]
};

#define NUM_KEYWORDS (sizeof(Keywords)/sizeof(Keywords[0]))
Expand Down
1 change: 1 addition & 0 deletions token.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ typedef enum
TK_KILL, // 'kill' [JM]
TK_REOPEN, // 'reopen' [Nash]
TK_ATSIGN, // '@'
TK_MORPHACTOR, // 'morphactor' [Dasperal]
} tokenType_t;

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
Expand Down

0 comments on commit 51b7e7e

Please sign in to comment.