More incremental work of converting code to use DebugTrace().

This commit is contained in:
wrenczes@gmail.com
2010-10-10 07:30:18 +00:00
parent 2d86e86603
commit 33e45c9635
10 changed files with 69 additions and 117 deletions

View File

@@ -1,6 +1,7 @@
#ifndef _CARDS_H_
#define _CARDS_H_
#include "../include/DebugRoutines.h"
#include "MTGAbility.h"
#include "ManaCost.h"
#include "CardDescriptor.h"
@@ -314,7 +315,6 @@ public:
}
game->mLayers->actionLayer()->setMenuObject(source,must);
game->mLayers->stackLayer()->setIsInterrupting(source->controller());
OutputDebugString("ALLABILITIES SetMenuObject!\n");
}
}
@@ -2968,7 +2968,7 @@ class APreventAllCombatDamage:public MTGAbility{
int addToGame(){
if (re) {
OutputDebugString("FATAL:re shouldn't be already set in APreventAllCombatDAMAGE\n");
DebugTrace("FATAL:re shouldn't be already set in APreventAllCombatDAMAGE\n");
return 0;
}
TargetChooserFactory tcf;
@@ -3730,9 +3730,7 @@ class AKudzu: public TargetAbility{
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL){
MTGCardInstance * _target = (MTGCardInstance *)target;
if (card == source && (!_target || !_target->isInPlay())){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Kudzu Reacts to click !\n");
#endif
DebugTrace("Kudzu Reacts to click !");
return 1;
}
return 0;

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/AIPlayer.h"
#include "../include/CardDescriptor.h"
#include "../include/AIStats.h"
@@ -67,10 +68,9 @@ int AIPlayer::Act(float dt){
void AIPlayer::tapLandsForMana(ManaCost * cost,MTGCardInstance * target){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("tapping land for mana\n");
#endif
if (!cost) return;
DebugTrace(" AI tapping land for mana");
ManaCost * pMana = getPotentialMana(target);
ManaCost * diff = pMana->Diff(cost);
delete(pMana);
@@ -158,7 +158,7 @@ int AIAction::getEfficiency(){
MTGAbility * a = AbilityFactory::getCoreAbility(ability);
if (!a){
OutputDebugString("FATAL: Ability is NULL in AIAction::getEfficiency()");
DebugTrace("FATAL: Ability is NULL in AIAction::getEfficiency()");
return 0;
}
@@ -279,7 +279,7 @@ int AIPlayer::selectAbility(){
if (getEfficiency(a) < chance){
a = NULL;
}else{
OutputDebugString("AIPlayer:Using Activated ability\n");
DebugTrace("AIPlayer:Using Activated ability");
tapLandsForMana(a->ability->cost,a->click);
clickstream.push(a);
}
@@ -531,7 +531,7 @@ int AIPlayer::orderBlockers(){
GameObserver * g = GameObserver::GetInstance();
if (ORDER == g->combatStep && g->currentPlayer==this)
{
OutputDebugString("AIPLAYER: order blockers\n");
DebugTrace("AIPLAYER: order blockers");
g->userRequestNextGamePhase(); //TODO clever rank of blockers
return 1;
}
@@ -578,7 +578,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op
if (deckid == GameStateDuel::MENUITEM_EVIL_TWIN){ //Evil twin
sprintf(deckFile, "%s", opponent->deckFile.c_str());
OutputDebugString(opponent->deckFile.c_str());
DebugTrace(opponent->deckFile);
sprintf(avatarFile, "%s", "baka.jpg");
sprintf(deckFileSmall, "%s", "ai_baka_eviltwin");
}else{
@@ -795,7 +795,7 @@ int AIPlayerBaka::Act(float dt){
}
interruptIfICan();
if (!(g->currentlyActing() == this)){
OutputDebugString("Cannot interrupt\n");
DebugTrace("Cannot interrupt");
return 0;
}
if (clickstream.empty()) computeActions();

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/ActionLayer.h"
#include "../include/GameObserver.h"
#include "../include/Targetable.h"
@@ -218,7 +219,7 @@ int ActionLayer::reactToClick(MTGCardInstance * card){
void ActionLayer::setMenuObject(Targetable * object, bool must){
if (!object){
OutputDebugString("FATAL: ActionLayer::setMenuObject\n");
DebugTrace("FATAL: ActionLayer::setMenuObject");
return;
}
menuObject = object;
@@ -242,9 +243,7 @@ void ActionLayer::doReactTo(int menuIndex){
if (menuObject){
int controlid = abilitiesMenu->mObjects[menuIndex]->GetId();
char buf[4096];
sprintf(buf, "ACTIONLAYER doReact To %i\n",controlid);
OutputDebugString(buf);
DebugTrace("ActionLayer::doReactTo " << controlid);
ButtonPressed(0,controlid);
}
}

View File

@@ -1,3 +1,4 @@
#include "../include/DebugRoutines.h"
#include "../include/ExtraCost.h"
#include "../include/TargetChooser.h"
#include "../include/MTGCardInstance.h"
@@ -751,10 +752,6 @@ ExtraCosts::~ExtraCosts(){
}
void ExtraCosts::Dump(){
#ifdef WIN32
char buf[4096];
OutputDebugString("=====\nDumping ExtraCosts=====\n");
sprintf(buf, "NbElements : %i\n", costs.size());
OutputDebugString(buf);
#endif
DebugTrace("=====\nDumping ExtraCosts=====\n");
DebugTrace("NbElements: " << costs.size());
}

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include <JGE.h>
#include <JRenderer.h>
#if defined (WIN32) || defined (LINUX)
@@ -81,7 +82,7 @@ void GameApp::Create()
#if defined (WIN32)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#elif not defined (LINUX)
pspfpu_set_enable(0); //disable FPU Exceptions until we find where the FPU errors come from
pspFpuSetEnable(0); //disable FPU Exceptions until we find where the FPU errors come from
#endif
//_CrtSetBreakAlloc(368);
LOG("starting Game");
@@ -211,12 +212,9 @@ void GameApp::Create()
JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number);
JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number);
char buf[512];
sprintf(buf, "size of MTGCard : %llu\n", (long long unsigned int)sizeof(MTGCard));
OutputDebugString(buf);
DebugTrace("size of MTGCard: "<< sizeof(MTGCard));
DebugTrace("size of CardPrimitive: "<< sizeof(CardPrimitive));
sprintf(buf, "size of CardPrimitive : %llu\n" , (long long unsigned int)sizeof(CardPrimitive));
OutputDebugString(buf);
LOG("Game Creation Done.");
}

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/GameStateDuel.h"
#include "../include/GameOptions.h"
#include "../include/utils.h"
@@ -193,9 +194,7 @@ void GameStateDuel::loadTestSuitePlayers(){
void GameStateDuel::End()
{
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Ending GamestateDuel\n");
#endif
DebugTrace("Ending GameStateDuel");
SAFE_DELETE(deckmenu);
JRenderer::GetInstance()->EnableVSync(false);

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/Logger.h"
#ifdef DOLOG
@@ -17,11 +18,8 @@ void Logger::Log(const char * text){
file << "\n";
file.close();
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString(text);
OutputDebugString("\n");
#endif
DebugTrace(text);
}
#endif

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/MTGAbility.h"
#include "../include/ManaCost.h"
#include "../include/MTGGameZones.h"
@@ -11,27 +12,32 @@
#include "../include/ThisDescriptor.h"
int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option){
int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option)
{
int result = 0;
GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2 ; i++){
for (int i = 0; i < 2 ; i++)
{
if (player && player!= game->players[i]) continue;
MTGGameZone * zones[] = {game->players[i]->game->inPlay,game->players[i]->game->graveyard,game->players[i]->game->hand};
for (int k = 0; k < 3; k++){
for (int j = zones[k]->nb_cards-1; j >=0 ; j--){
MTGCardInstance * current = zones[k]->cards[j];
if (tc->canTarget(current)){
switch (option){
case COUNT_POWER:
result+= current->power;
break;
default:
result++;
break;
}
}
}
}
MTGGameZone * zones[] = {game->players[i]->game->inPlay,game->players[i]->game->graveyard,game->players[i]->game->hand};
for (int k = 0; k < 3; k++)
{
for (int j = zones[k]->nb_cards-1; j >=0 ; j--)
{
MTGCardInstance * current = zones[k]->cards[j];
if (tc->canTarget(current))
{
switch (option){
case COUNT_POWER:
result+= current->power;
break;
default:
result++;
break;
}
}
}
}
}
return result;
}
@@ -241,17 +247,7 @@ MTGAbility * AbilityFactory::getCoreAbility(MTGAbility * a){
MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated, int forceUEOT, int oneShot,int forceFOREVER, MTGGameZone * dest){
size_t found;
string whitespaces (" \t\f\v\n\r");
found=s.find_last_not_of(whitespaces);
if (found!=string::npos)
s.erase(found+1);
else return NULL;
found=s.find_first_not_of(whitespaces);
if (found!=string::npos)
s.erase(0,found);
else return NULL;
trim(s);
//TODO This block redundant with calling function
if (!card && spell) card = spell->source;
@@ -305,9 +301,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
MTGAbility * a = parseMagicLine(s1, id, spell, card, 1);
if (!a){
OutputDebugString("ABILITYFACTORY Error parsing:");
OutputDebugString(sWithoutTc.c_str());
OutputDebugString("\n");
DebugTrace("ABILITYFACTORY Error parsing: " << sWithoutTc);
return NULL;
}
@@ -473,9 +467,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
ThisDescriptor * td = tdf.createThisDescriptor(thisDescriptorString);
if (!td){
OutputDebugString("MTGABILITY: Parsing Error:");
OutputDebugString(s.c_str());
OutputDebugString("\n");
DebugTrace("MTGABILITY: Parsing Error:" << s);
return NULL;
}
@@ -540,9 +532,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
TargetChooser * lordTargets = tcf.createTargetChooser(lordTargetsString, card);
if (!lordTargets){
OutputDebugString("MTGABILITY: Parsing Error:");
OutputDebugString(s.c_str());
OutputDebugString("\n");
DebugTrace("MTGABILITY: Parsing Error: " << s);
return NULL;
}
@@ -589,9 +579,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
MTGAbility * a = parseMagicLine(sWithoutTc, id, spell, card);
if (!a){
OutputDebugString("ABILITYFACTORY Error parsing:");
OutputDebugString(s.c_str());
OutputDebugString("\n");
DebugTrace("ABILITYFACTORY Error parsing: " << s);
return NULL;
}
a = NEW GenericTargetAbility(id,card,tc,a);
@@ -621,9 +609,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
ManaCost * cost = ManaCost::parseManaCost(s1);
if (!cost){
OutputDebugString("MTGABILITY: Parsing Error:");
OutputDebugString(s.c_str());
OutputDebugString("\n");
DebugTrace("MTGABILITY: Parsing Error: " << s);
return NULL;
}
@@ -631,9 +617,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
MTGAbility * a = parseMagicLine(sAbility,id,spell,card);
if (!a){
OutputDebugString("MTGABILITY: Parsing Error:");
OutputDebugString(s.c_str());
OutputDebugString("\n");
DebugTrace("MTGABILITY: Parsing Error: " << s);
delete(cost);
return NULL;
}
@@ -1479,7 +1463,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
v->push_back(a);
result++;
}else{
OutputDebugString("ABILITYFACTORY ERROR: Parser returned NULL\n");
DebugTrace("ABILITYFACTORY ERROR: Parser returned NULL");
}
}
return result;
@@ -1518,7 +1502,7 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int
a->addToGame();
}
}else{
OutputDebugString("ABILITYFACTORY ERROR: Parser returned NULL\n");
DebugTrace("ABILITYFACTORY ERROR: Parser returned NULL");
}
}
return result;

View File

@@ -3,6 +3,7 @@
#include <string>
#include <sstream>
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/MTGDeck.h"
#include "../include/utils.h"
#include "../include/Subtypes.h"
@@ -38,11 +39,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
if ('#' == s[0]) return 0;
size_t i = s.find_first_of('=');
if (i == string::npos || 0 == i){
#if defined (_DEBUG)
char buffer[4096];
sprintf(buffer, "MTGDECK: Bad Line:\n %s\n", s.c_str());
OutputDebugString(buffer);
#endif
DebugTrace("MTGDECK: Bad Line:\n\t" << s);
return 0;
}
@@ -226,8 +223,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
break;
default:
string error = "MTGDECK Parsing Error:" + s + "\n";
OutputDebugString(error.c_str());
DebugTrace("MTGDECK Parsing Error: " << s);
break;
}
@@ -403,11 +399,9 @@ bool MTGAllCards::addCardToCollection(MTGCard * card, int setId){
int newId = card->getId();
if (collection.find(newId) != collection.end()){
#if defined (_DEBUG)
char outBuf[4096];
string cardName = card->data ? card->data->name : card->getImageName();
string setName = setId != -1 ? setlist.getInfo( setId ) -> getName() : "";
sprintf(outBuf,"warning, card id collision! : %i -> %s (%s) \n", newId, cardName.c_str(), setName.c_str());
OutputDebugString(outBuf);
string setName = setId != -1 ? setlist.getInfo(setId)->getName() : "";
DebugTrace("warning, card id collision! : " << newId << " -> " << cardName << "(" << setName << ")");
#endif
SAFE_DELETE(card);
return false;
@@ -444,11 +438,7 @@ CardPrimitive * MTGAllCards::addPrimitive(CardPrimitive * primitive, MTGCard * c
if (primitives.find(key) != primitives.end()){
//ERROR
//Todo move the deletion somewhere else ?
#ifdef _DEBUG
OutputDebugString("MTGDECK: primitives conflict:");
OutputDebugString(key.c_str());
OutputDebugString("\n");
#endif
DebugTrace("MTGDECK: primitives conflict: "<< key);
SAFE_DELETE(primitive);
return NULL;
}
@@ -577,9 +567,7 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
add(card);
}
} else {
OutputDebugString("could not find Card matching name:");
OutputDebugString(s.c_str());
OutputDebugString("\n");
DebugTrace("could not find Card matching name: " << s);
}
}
}
@@ -742,9 +730,7 @@ int MTGDeck::save(){
std::ofstream file(tmp.c_str());
char writer[512];
if (file){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("saving");
#endif
DebugTrace("Saving Deck");
if (meta_name.size()){
file << "#NAME:" << meta_name << '\n';
}

View File

@@ -1,4 +1,5 @@
#include "../include/config.h"
#include "../include/DebugRoutines.h"
#include "../include/MTGRules.h"
#include "../include/Translate.h"
#include "../include/Subtypes.h"
@@ -783,11 +784,7 @@ int MTGBlockRule::reactToClick(MTGCardInstance * card){
int candefend = 0;
while (!result){
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Defenser Toggle %s \n", card->getName().c_str());
OutputDebugString(buf);
#endif
DebugTrace("Defenser Toggle: " << card->getName());
candefend = card->toggleDefenser(currentOpponent);
result = (candefend || currentOpponent == NULL);
}
@@ -894,11 +891,7 @@ int MTGMomirRule::genRandomCreatureId(int convertedCost){
int total_cards = 0;
int i = convertedCost;
while (!total_cards && i >=0){
#ifdef WIN32
char buf[4096];
sprintf(buf,"Converted Cost in momir: %i\n", i);
OutputDebugString(buf);
#endif
DebugTrace("Converted Cost in momir: " << i);
total_cards = pool[i].size();
convertedCost = i;
i--;