Skip to content

Commit

Permalink
Added parser code for compression rifle. #12
Browse files Browse the repository at this point in the history
  • Loading branch information
GSIO01 committed Aug 15, 2014
1 parent 1415d7a commit a7baa55
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions code/game/bg_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef enum {
LSYM_WCONF_DAMAGE,
LSYM_WCONF_VARIATION,
LSYM_WCONF_RADIUS,
LSYM_WCONF_SIZE,
LSYM_POINT,

LSYM_UNKNOWN
Expand Down
4 changes: 4 additions & 0 deletions code/game/bg_lex.lex
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@ bgLexSymbol bgLex_textToSymbol(char* text) {
return LSYM_WCONF_RADIUS;
}

if(strcmp("size", text) == 0) {
return LSYM_WCONF_SIZE;
}

return LSYM_UNKNOWN;
}

Expand Down
4 changes: 4 additions & 0 deletions code/game/bg_lex.yy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,10 @@ bgLexSymbol bgLex_textToSymbol(char* text) {
return LSYM_WCONF_RADIUS;
}

if(strcmp("size", text) == 0) {
return LSYM_WCONF_SIZE;
}

return LSYM_UNKNOWN;
}

Expand Down
104 changes: 102 additions & 2 deletions code/game/g_weapon.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static qboolean G_Weapon_ParseWeaponConfig(bgLex* lexer) {
return qfalse;
}
break;
default:
default:
G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
Expand Down Expand Up @@ -199,7 +199,107 @@ static qboolean G_Weapon_ParseWeaponConfig(bgLex* lexer) {
}
break;
case LSYM_WCONF_CRIFLE:

while (bgLex_lex(lexer) != 0) {
if (lexer->morphem.type != LMT_SYMBOL) {
G_Logger(LL_ERROR, "Unexpected token at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
} else {
if (lexer->morphem.data.symbol == LSYM_WCONF_PRIMARY) {
bgLex_lex(lexer);
if (lexer->morphem.type != LMT_SYMBOL || lexer->morphem.data.symbol != LSYM_POINT) {
G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
bgLex_lex(lexer);
if (lexer->morphem.type != LMT_SYMBOL) {
G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
switch (lexer->morphem.data.symbol) {
case LSYM_WCONF_DAMAGE:
bgLex_lex(lexer);
if (lexer->morphem.type == LMT_INT) {
weaponConfig.crifle.primary.damage = lexer->morphem.data.numInteger;
} else {
G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
break;
case LSYM_WCONF_RANGE:
bgLex_lex(lexer);
if (lexer->morphem.type == LMT_DOUBLE) {
weaponConfig.crifle.primary.range = lexer->morphem.data.numDouble;
} else {
G_Logger(LL_ERROR, "Expected double value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
break;
default:
G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
} else if (lexer->morphem.data.symbol == LSYM_WCONF_SECONDARY) {
bgLex_lex(lexer);
if (lexer->morphem.type != LMT_SYMBOL || lexer->morphem.data.symbol != LSYM_POINT) {
G_Logger(LL_ERROR, "Expected '.' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
bgLex_lex(lexer);
if (lexer->morphem.type != LMT_SYMBOL) {
G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
switch (lexer->morphem.data.symbol) {
case LSYM_WCONF_DAMAGE:
bgLex_lex(lexer);
if (lexer->morphem.type == LMT_INT) {
weaponConfig.crifle.secondary.damage = lexer->morphem.data.numInteger;
} else {
G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
break;
case LSYM_WCONF_RANGE:
bgLex_lex(lexer);
if (lexer->morphem.type == LMT_DOUBLE) {
weaponConfig.crifle.secondary.range = lexer->morphem.data.numDouble;
} else {
G_Logger(LL_ERROR, "Expected double value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
break;
case LSYM_WCONF_SIZE:
bgLex_lex(lexer);
if (lexer->morphem.type == LMT_INT) {
weaponConfig.crifle.secondary.size = lexer->morphem.data.numInteger;
} else {
G_Logger(LL_ERROR, "Expected integer value at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
break;
default:
G_Logger(LL_ERROR, "Unexpected token at weapons.cfg.%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
} else {
G_Logger(LL_ERROR, "Expected 'primary' or 'secondary' at weapons.cfg:%d:%d!\n", lexer->morphem.line, lexer->morphem.column);
G_LogFuncEnd();
return qfalse;
}
}
}
break;
case LSYM_WCONF_DISRUPTOR:

Expand Down

0 comments on commit a7baa55

Please sign in to comment.