View Single Post
Old Sep 3rd, 2007, 4:21 AM   #1
dr.p
Programmer
 
dr.p's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 93
Rep Power: 3 dr.p is on a distinguished road
Viscious Game Bug

Hello, folks. I need help.

The following is a function that determines the winner of a single battle in the game I'm creating, and then updates the field and stats appropriately.

The "DetermineBattleOutcome" call is what actually determines the winner.

My debug output shows that this ALWAYS returns the correct value. The "outcome" variable which stores this result is checked against the SUCCESS and FAILURE codes (values 1.00 and 0.01, respectively,) in an IF statement following the "Determine..." call.

PROBLEM IS: When I lose a battle on purpose, and the value of outcome is CORRECTLY set to MWEIGHT_FAILURE (0.01), the afore-mentioned IF statement DOES NOT evaluate "outcome == MWEIGHT_FAILURE" to true.............

It's late... and I hope I'm just missing something obvious, but this is truly perplexing.

If the debug code is too confusing, please let me know and I'll remove it.

void DoBattle (UINT attacker, UINT pos)
{
#ifdef GAME_PLAY_DEBUG_BATTLE
  Debug_CleanUp();
  char sztemp[256] = "\0";
  sprintf(sztemp, "BATTLE: a=%d p=%d", attacker, pos);
  Debug_CompyOut(sztemp);
  Delay(BATTLE_DEBUG_DELAY);
#endif

  if (attacker != COMPUTER && attacker != PLAYER) return;

  if (pos >= FIELD_SIZE) return;

  UINT defender = (attacker == COMPUTER) ? PLAYER: COMPUTER;

  float outcome = DetermineBattleOutcome(g_Field[attacker][pos], g_Field[defender][pos]);

#ifdef GAME_PLAY_DEBUG_BATTLE
  sprintf(sztemp, "BATTLE: outcome=%f", outcome);
  Debug_CompyOut(sztemp);
  Delay(BATTLE_DEBUG_DELAY);
#endif

  if (outcome == MWEIGHT_INVALID)
    return;

  BYTE suit, value, state, color;

    // if someone won the battle
  if (outcome == MWEIGHT_FAILURE || outcome == MWEIGHT_SUCCESS) {
      // set the winner and loser
    UINT winner = (outcome == MWEIGHT_SUCCESS) ? attacker: defender;
    UINT loser = (outcome == MWEIGHT_SUCCESS) ? defender: attacker;

#ifdef GAME_PLAY_DEBUG_BATTLE
    sprintf(sztemp, "BATTLE: w=%d l=%d", winner, loser);
    Debug_CompyOut(sztemp);
    Delay(BATTLE_DEBUG_DELAY);
#endif
      // get the value of the lost card
    ParseCardValue(g_Field[loser][pos], NULL, &value, NULL, NULL);
      // update the winer's states
    g_Scores[winner]->nTotalCaptured++;
    if (value > CARDROW_TENS) {
      g_Scores[winner]->nFacesCaptured++;
    }
      // and remove the lost card from the field
    g_Field[loser][pos] = 0;
  } else {
#ifdef GAME_PLAY_DEBUG_BATTLE
    sprintf(sztemp, "BATTLE: NO WINNER! %f %f", outcome, MWEIGHT_FAILURE);
    Debug_CompyOut(sztemp);
    Delay(BATTLE_DEBUG_DELAY);
#endif
  }
}
// end DoBattle
__________________
Neeley.org
dr.p is offline   Reply With Quote