Skip to content

Commit

Permalink
Merge pull request #578 from akaAgar/exact-rts-condition-prefix
Browse files Browse the repository at this point in the history
Added "EXACT_" optional prefix to RTS's ON_CONDITION flag
  • Loading branch information
dashodanger authored Oct 5, 2023
2 parents 591bb65 + 4e0e4f7 commit 994bf15
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source_files/ddf/thing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,7 @@ bool DDF_MainParseCondition(const char *info, condition_check_t *cond)
const char *pos;

cond->negate = false;
cond->exact = false;
cond->cond_type = COND_NONE;
cond->amount = 1;

Expand Down Expand Up @@ -2200,6 +2201,12 @@ bool DDF_MainParseCondition(const char *info, condition_check_t *cond)
t_off = 4;
}

if (epi::prefix_case_cmp(typebuf, "EXACT_") == 0)
{
cond->exact = true;
t_off = 6;
}

if (ConditionTryAmmo(typebuf + t_off, sub_buf, cond) ||
ConditionTryInventory(typebuf + t_off, sub_buf, cond) ||
ConditionTryCounter(typebuf + t_off, sub_buf, cond) ||
Expand Down
3 changes: 3 additions & 0 deletions source_files/ddf/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ typedef struct condition_check_s
// negate the condition
bool negate = false;

// condition is looking for an exact value (not "greater than" or "smaller than")
bool exact = false;

// condition typing. -ACB- 2003/05/15: Made an integer to hold condition_check_type_e enumeration
int cond_type = 0;

Expand Down
23 changes: 23 additions & 0 deletions source_files/edge/e_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ bool G_CheckConditions(mobj_t *mo, condition_check_t *cond)
switch (cond->cond_type)
{
case COND_Health:
if (cond->exact)
return (mo->health == cond->amount);

temp = (mo->health >= cond->amount);

if ((!cond->negate && !temp) || (cond->negate && temp))
Expand All @@ -610,6 +613,14 @@ bool G_CheckConditions(mobj_t *mo, condition_check_t *cond)
if (!p)
return false;

if (cond->exact)
{
if (cond->sub.type == ARMOUR_Total)
return (p->totalarmour == i_amount);
else
return (p->armours[cond->sub.type] == i_amount);
}

if (cond->sub.type == ARMOUR_Total)
temp = (p->totalarmour >= i_amount);
else
Expand Down Expand Up @@ -656,6 +667,9 @@ bool G_CheckConditions(mobj_t *mo, condition_check_t *cond)
if (!p)
return false;

if (cond->exact)
return (p->powers[cond->sub.type] == cond->amount);

temp = (p->powers[cond->sub.type] > cond->amount);

if ((!cond->negate && !temp) || (cond->negate && temp))
Expand All @@ -667,6 +681,9 @@ bool G_CheckConditions(mobj_t *mo, condition_check_t *cond)
if (!p)
return false;

if (cond->exact)
return (p->ammo[cond->sub.type].num == i_amount);

temp = (p->ammo[cond->sub.type].num >= i_amount);

if ((!cond->negate && !temp) || (cond->negate && temp))
Expand All @@ -678,6 +695,9 @@ bool G_CheckConditions(mobj_t *mo, condition_check_t *cond)
if (!p)
return false;

if (cond->exact)
return (p->inventory[cond->sub.type].num == i_amount);

temp = (p->inventory[cond->sub.type].num >= i_amount);

if ((!cond->negate && !temp) || (cond->negate && temp))
Expand All @@ -689,6 +709,9 @@ bool G_CheckConditions(mobj_t *mo, condition_check_t *cond)
if (!p)
return false;

if (cond->exact)
return (p->counters[cond->sub.type].num == i_amount);

temp = (p->counters[cond->sub.type].num >= i_amount);

if ((!cond->negate && !temp) || (cond->negate && temp))
Expand Down

0 comments on commit 994bf15

Please sign in to comment.