Skip to content

Commit

Permalink
implement Value (#68)
Browse files Browse the repository at this point in the history
* parser can parse passed in string

* parser string parsing looks cleaner

* fixes #54 implement value skill and adjust slightly how nulls are calculated

* renaming and addressing magic numbers. also initial ideas on a clang-format
  • Loading branch information
danlangford authored Nov 5, 2024
1 parent 5f3e623 commit 1b6472c
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 136 deletions.
30 changes: 30 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Always
TabWidth: 4
BreakBeforeBraces: Allman
AllowShortBlocksOnASingleLine: Always

AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true

Language: Cpp

## Naming conventions
#
#Cpp:
# Naming:
# ClassCase: PascalCase
# MethodCase: PascalCase
# VariableCase: lower_case
# ParameterCase: lower_case
# MemberCase: m_lower_case
# ConstantCase: UPPER_CASE
# EnumCase: UPPER_CASE
#
## Custom prefixes
#PrefixClasses: BMC_
#PrefixStructs: BMC_
#PrefixEnums: BMC_
#PrefixUnions: BMC_
#PrefixInterfaces: BMC_
22 changes: 17 additions & 5 deletions src/BMC_Die.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,31 @@ float BMC_Die::GetScore(bool _own)
{
return 0;
}

else if (HasProperty(BME_PROPERTY_POISON) && HasProperty(BME_PROPERTY_VALUE))
{
if (_own)
return -m_value_total;
else
return -m_value_total * BMD_VALUE_OWN_DICE;
}
else if (HasProperty(BME_PROPERTY_POISON))
{
if (_own)
return -m_sides_max * 1.0f;
return -m_sides_max;
else
return -m_sides_max * 0.5f; // this is not an optional rule
return -m_sides_max * BMD_VALUE_OWN_DICE;
}
else if (HasProperty(BME_PROPERTY_VALUE))
{
if (_own)
return m_value_total * BMD_VALUE_OWN_DICE;
else
return m_value_total;
}

else
{
if (_own)
return m_sides_max * BMD_VALUE_OWN_DICE; // scoring owned dice is optional
return m_sides_max * BMD_VALUE_OWN_DICE;
else
return m_sides_max;
}
Expand Down
1 change: 1 addition & 0 deletions src/BMC_Die.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BMC_Die : public BMC_DieData
// mutators
void SetState(BME_STATE _state) { m_state = _state; }
void CheatSetValueTotal(INT _v) { m_value_total = _v; } // used for some functions
void AddProperty(BME_PROPERTY _prop) { m_properties |= _prop; }

// events
void OnDieChanged();
Expand Down
33 changes: 16 additions & 17 deletions src/BMC_Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ void BMC_Game::ApplyAttackNatureRoll(BMC_Move &_move)
}

// DESC: handle non-deterministic and capture-specific effects. This includes
// TIME_AND_SPACE, TRIP, NULL
// TIME_AND_SPACE, TRIP, NULL, VALUE
// PRE: all dice that needed to be rerolled have been rerolled
void BMC_Game::ApplyAttackNaturePost(BMC_Move &_move, bool &_extra_turn)
{
Expand All @@ -1532,6 +1532,7 @@ void BMC_Game::ApplyAttackNaturePost(BMC_Move &_move, bool &_extra_turn)
BMC_Player *target = &(m_player[m_target_player]);
BMC_Die *att_die, *tgt_die;
bool null_attacker = false;
bool value_attacker = false;
INT i;

// capture - attacker effects
Expand All @@ -1542,6 +1543,7 @@ void BMC_Game::ApplyAttackNaturePost(BMC_Move &_move, bool &_extra_turn)
{
att_die = attacker->GetDie(_move.m_attacker);
null_attacker = att_die->HasProperty(BME_PROPERTY_NULL);
value_attacker = att_die->HasProperty(BME_PROPERTY_VALUE);

// TIME AND SPACE
if (att_die->HasProperty(BME_PROPERTY_TIME_AND_SPACE) && att_die->GetValueTotal()%2==1)
Expand All @@ -1556,6 +1558,7 @@ void BMC_Game::ApplyAttackNaturePost(BMC_Move &_move, bool &_extra_turn)
continue;
att_die = attacker->GetDie(i);
null_attacker = null_attacker || att_die->HasProperty(BME_PROPERTY_NULL);
value_attacker = value_attacker || att_die->HasProperty(BME_PROPERTY_VALUE);

// TIME AND SPACE
if (att_die->HasProperty(BME_PROPERTY_TIME_AND_SPACE) && att_die->GetValueTotal()%2==1)
Expand Down Expand Up @@ -1590,14 +1593,12 @@ void BMC_Game::ApplyAttackNaturePost(BMC_Move &_move, bool &_extra_turn)
{
tgt_die = target->OnDieLost(_move.m_target);
if (null_attacker)
{
tgt_die->SetState(BME_STATE_NULLIFIED);
}
else
{
tgt_die->SetState(BME_STATE_CAPTURED);
attacker->OnDieCaptured(tgt_die);
}
tgt_die->AddProperty(BME_PROPERTY_NULL);
if (value_attacker)
tgt_die->AddProperty(BME_PROPERTY_VALUE);
tgt_die->SetState(BME_STATE_CAPTURED);
attacker->OnDieCaptured(tgt_die);

break;
}
case BME_ATTACK_TYPE_1_N:
Expand All @@ -1612,14 +1613,12 @@ void BMC_Game::ApplyAttackNaturePost(BMC_Move &_move, bool &_extra_turn)
i2 = i - removed++; // determine true index
tgt_die = target->OnDieLost(i2);
if (null_attacker)
{
tgt_die->SetState(BME_STATE_NULLIFIED);
}
else
{
tgt_die->SetState(BME_STATE_CAPTURED);
attacker->OnDieCaptured(tgt_die);
}
tgt_die->AddProperty(BME_PROPERTY_NULL);
if (value_attacker)
tgt_die->AddProperty(BME_PROPERTY_VALUE);
tgt_die->SetState(BME_STATE_CAPTURED);
attacker->OnDieCaptured(tgt_die);

}
break;
}
Expand Down
Loading

0 comments on commit 1b6472c

Please sign in to comment.