diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index 649cebdc6..a8f382a8d 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -15,10 +15,10 @@ typedef enum GAME_TYPE_MOMIR, GAME_TYPE_RANDOM1, GAME_TYPE_RANDOM2, - GAME_TYPE_RANDOM3, - GAME_TYPE_RANDOM5, - GAME_TYPE_HORDE, - GAME_TYPE_SET_LIMITED, + GAME_TYPE_RANDOM3, + GAME_TYPE_RANDOM5, + GAME_TYPE_HORDE, + GAME_TYPE_SET_LIMITED, GAME_TYPE_STORY, GAME_TYPE_DEMO, GAME_TYPE_STONEHEWER, diff --git a/projects/mtg/include/Rules.h b/projects/mtg/include/Rules.h index 4959a432e..5c86cef33 100644 --- a/projects/mtg/include/Rules.h +++ b/projects/mtg/include/Rules.h @@ -43,9 +43,9 @@ protected: Player * loadPlayerMomir(GameObserver* observer, int isAI); Player * loadPlayerRandom(GameObserver* observer, int isAI, int mode); Player * loadPlayerRandomThree(GameObserver* observer, int isAI); - Player * loadPlayerRandomFive(GameObserver* observer, int isAI); - Player * loadPlayerHorde(GameObserver* observer, int isAI); - Player * loadRandomSetLimited(GameObserver* observer, int isAI); + Player * loadPlayerRandomFive(GameObserver* observer, int isAI); + Player * loadPlayerHorde(GameObserver* observer, int isAI); + Player * loadRandomSetLimited(GameObserver* observer, int isAI); Player * initPlayer(GameObserver *observer, int playerId); MTGDeck * buildDeck(int playerId); GameType strToGameMode(string s); diff --git a/projects/mtg/include/Wagic_Version.h b/projects/mtg/include/Wagic_Version.h index 62e70ff91..103413ecd 100644 --- a/projects/mtg/include/Wagic_Version.h +++ b/projects/mtg/include/Wagic_Version.h @@ -31,5 +31,3 @@ Author: Michael Nguyen #define WAGIC_RESOURCE_URL "https://github.com/WagicProject/wagic/releases/download/" WAGIC_RELEASE_NAME "/" WAGIC_RESOURCE_NAME #endif - - diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index 990763a1f..be0524a25 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -46,15 +46,15 @@ int OrderedAIAction::getEfficiency(AADamager * aad) return 0; } - if(p && target) - if(p == target->controller()) - return 0; + if(p && target) + if(p == target->controller()) + return 0; if (dTarget && aad && (aad->getDamage() == dTarget->toughness)) return 100; else if (dTarget && aad && (aad->getDamage() > dTarget->toughness)) return 10 * (10 - (aad->getDamage() - dTarget->toughness)); //less eff the more dmg above toughness - else + else return 10; return 0; @@ -131,7 +131,7 @@ int OrderedAIAction::getEfficiency() { efficiency = 95; } - //TODO If the card is the target of a damage spell + //TODO If the card is the target of a damage spell break; } case MTGAbility::STANDARD_PREVENT: @@ -273,7 +273,7 @@ int OrderedAIAction::getEfficiency() } case MTGAbility::STANDARD_PUMP: { - efficiency = 0; + efficiency = 0; if(!coreAbilityCardTarget) break; if(!target && !dynamic_cast (a) && (((MTGCardInstance *)a->source)->hasSubtype(Subtypes::TYPE_AURA) || ((MTGCardInstance *)a->source)->hasSubtype(Subtypes::TYPE_EQUIPMENT))) @@ -282,10 +282,10 @@ int OrderedAIAction::getEfficiency() coreAbilityCardTarget = a->source->target; //TODO use intermediate value? target = a->source; } - else //if(how to know cards like Basking Rootwalla that pump themselves) - { - target = a->source; - } + else //if(how to know cards like Basking Rootwalla that pump themselves) + { + target = a->source; + } if (!target && !dynamic_cast (a)) break; if(dynamic_cast (a) && !target) @@ -297,9 +297,9 @@ int OrderedAIAction::getEfficiency() int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); //i do not set a starting eff. on this ability, this allows Ai to sometimes randomly do it as it normally does. int currentPhase = g->getCurrentGamePhase(); - if ((currentPhase == MTG_PHASE_COMBATBLOCKERS) || (currentPhase == MTG_PHASE_COMBATATTACKERS)) + if ((currentPhase == MTG_PHASE_COMBATBLOCKERS) || (currentPhase == MTG_PHASE_COMBATATTACKERS)) { - if (suggestion == BAKA_EFFECT_GOOD && target->controller() == p) + if (suggestion == BAKA_EFFECT_GOOD && target->controller() == p) { if(coreAbilityCardTarget->defenser || coreAbilityCardTarget->blockers.size()) { @@ -332,41 +332,41 @@ int OrderedAIAction::getEfficiency() { if(!coreAbilityCardTarget) break; - // It used to skip most effects, with no other condition efficiency is -1 - // Becomes is generally good so setting a value, but don't want to spam it - if (coreAbilityCardTarget && !coreAbilityCardTarget->isLand()) - { - // Bonus if almost no cards in hand - if (p->game->hand->nb_cards <= 1) - { - efficiency = 50; - } - else efficiency = 30; - } + // It used to skip most effects, with no other condition efficiency is -1 + // Becomes is generally good so setting a value, but don't want to spam it + if (coreAbilityCardTarget && !coreAbilityCardTarget->isLand()) + { + // Bonus if almost no cards in hand + if (p->game->hand->nb_cards <= 1) + { + efficiency = 50; + } + else efficiency = 30; + } //nothing huge here, just ensuring that Ai makes his noncreature becomers into creatures during first main, so it can actually use them in combat. - if (coreAbilityCardTarget && !coreAbilityCardTarget->isCreature() && !coreAbilityCardTarget->isTapped() && currentPhase == MTG_PHASE_FIRSTMAIN) + if (coreAbilityCardTarget && !coreAbilityCardTarget->isCreature() && !coreAbilityCardTarget->isTapped() && currentPhase == MTG_PHASE_FIRSTMAIN) { efficiency = 50; - } + } break; } case MTGAbility::MANA_PRODUCER://only way to hit this condition is nested manaabilities, ai skips manaproducers by defualt when finding an ability to use. { - AManaProducer * manamaker = dynamic_cast(a); - GenericActivatedAbility * GAA = dynamic_cast(ability); - if(GAA) - { - AForeach * forMana = dynamic_cast(GAA->ability); - if (manamaker && forMana) - { - int outPut = forMana->checkActivation(); - if (ability->getCost() && outPut > int(ability->getCost()->getConvertedCost() +1) && currentPhase == MTG_PHASE_FIRSTMAIN && ability->source->controller()->game->hand->nb_cards > 1) - efficiency = 60;//might be a bit random, but better than never using them. - } - } - else - efficiency = 0; - break; + AManaProducer * manamaker = dynamic_cast(a); + GenericActivatedAbility * GAA = dynamic_cast(ability); + if(GAA) + { + AForeach * forMana = dynamic_cast(GAA->ability); + if (manamaker && forMana) + { + int outPut = forMana->checkActivation(); + if (ability->getCost() && outPut > int(ability->getCost()->getConvertedCost() +1) && currentPhase == MTG_PHASE_FIRSTMAIN && ability->source->controller()->game->hand->nb_cards > 1) + efficiency = 60;//might be a bit random, but better than never using them. + } + } + else + efficiency = 0; + break; } case MTGAbility::STANDARDABILITYGRANT: { @@ -446,7 +446,7 @@ int OrderedAIAction::getEfficiency() case MTGAbility::LIFER: { //use life abilities whenever possible. Well yes, but actually no - //limits mana and in case of Zuran Orb it just sacrifices all lands + //limits mana and in case of Zuran Orb it just sacrifices all lands AALifer * alife = (AALifer *) a; Targetable * _t = alife->getTarget(); @@ -587,10 +587,10 @@ int OrderedAIAction::getEfficiency() if (z == p->game->hand) efficiency = 10 + (owner->getRandomGenerator()->random() % 10);//random chance to bounce their own card; } - // We don't want to return cards in play to own hand, save rare combos - else if(target->currentZone == p->game->inPlay) + // We don't want to return cards in play to own hand, save rare combos + else if(target->currentZone == p->game->inPlay) { - if (z == p->game->hand || z == p->game->library) + if (z == p->game->hand || z == p->game->library) efficiency = (owner->getRandomGenerator()->random() % 10);//random chance to bounce their own card; } else @@ -600,10 +600,10 @@ int OrderedAIAction::getEfficiency() } else { - // We don't want to return the ability source cards that are in play to own hand, save rare combos - // cards like Blinking Spirit used to be auto lose for AI - if(z == p->game->hand || z == p->game->library) - efficiency = 1; + // We don't want to return the ability source cards that are in play to own hand, save rare combos + // cards like Blinking Spirit used to be auto lose for AI + if(z == p->game->hand || z == p->game->library) + efficiency = 1; else efficiency = 50; //may abilities target the source until thier nested ability is activated, so 50% chance to use this //mover, until we can come up with something more elegent.... @@ -682,11 +682,11 @@ int OrderedAIAction::getEfficiency() for(unsigned int i = 0; i < ec->costs.size();i++) { ExtraCost * tapper = dynamic_cast(ec->costs[i]); - ExtraCost * sacrifice = dynamic_cast(ec->costs[i]); + ExtraCost * sacrifice = dynamic_cast(ec->costs[i]); if(tapper) - continue; + continue; else if(sacrifice) - efficiency = efficiency / 3; + efficiency = efficiency / 3; else efficiency = efficiency / 2; } @@ -706,20 +706,20 @@ int OrderedAIAction::getEfficiency() efficiency += 55; } - if (ability->source) - { - if(ability->source->hasType(Subtypes::TYPE_PLANESWALKER)) - efficiency += 40; - else if(ability->source->hasType(Subtypes::TYPE_LAND)) - { // probably a shockland, don't pay life if hand is empty - if (p->life<=2) - // check that's not a manland(like Celestial Colonnade) - if(efficiency < 50) - efficiency = 0; - } - } + if (ability->source) + { + if(ability->source->hasType(Subtypes::TYPE_PLANESWALKER)) + efficiency += 40; + else if(ability->source->hasType(Subtypes::TYPE_LAND)) + { // probably a shockland, don't pay life if hand is empty + if (p->life<=2) + // check that's not a manland(like Celestial Colonnade) + if(efficiency < 50) + efficiency = 0; + } + } - SAFE_DELETE(transAbility); + SAFE_DELETE(transAbility); return efficiency; } @@ -2374,9 +2374,9 @@ int AIPlayerBaka::chooseTarget(TargetChooser * _tc, Player * forceTarget,MTGCard cardEffect = af.abilityEfficiency(withoutGuessing,this,MODE_TARGET,tc,NULL); delete withoutGuessing; } - // Don't really like it but green mana producing auras targeting the player is one of the most reported bugs - if(cardEffect == BAKA_EFFECT_DONTKNOW && tc->source->hasSubtype(Subtypes::TYPE_AURA) && tc->source->hasColor(Constants::MTG_COLOR_GREEN)) - cardEffect = BAKA_EFFECT_GOOD; + // Don't really like it but green mana producing auras targeting the player is one of the most reported bugs + if(cardEffect == BAKA_EFFECT_DONTKNOW && tc->source->hasSubtype(Subtypes::TYPE_AURA) && tc->source->hasColor(Constants::MTG_COLOR_GREEN)) + cardEffect = BAKA_EFFECT_GOOD; if (cardEffect != BAKA_EFFECT_GOOD) { @@ -2560,7 +2560,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty { nextCardToPlay = comboCards.back(); gotPayments.clear(); - if((!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->getKicker() || nextCardToPlay->getManaCost()->getBestow())) + if((!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->getKicker() || nextCardToPlay->getManaCost()->getBestow())) gotPayments = canPayMana(nextCardToPlay,nextCardToPlay->getManaCost()); DebugTrace("ai is doing a combo:" << nextCardToPlay->getName()); comboCards.pop_back(); @@ -2574,175 +2574,175 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty card = NULL; gotPayments = vector(); //canplayfromgraveyard - while ((card = cd.nextmatch(game->graveyard, card))) + while ((card = cd.nextmatch(game->graveyard, card))) { - bool hasFlashback = false; + bool hasFlashback = false; - if(card->getManaCost()) - if(card->getManaCost()->getFlashback()) - hasFlashback = true; + if(card->getManaCost()) + if(card->getManaCost()->getFlashback()) + hasFlashback = true; - if( card->has(Constants::CANPLAYFROMGRAVEYARD) || card->has(Constants::TEMPFLASHBACK) || hasFlashback ) - { - if (!CanHandleCost(card->getManaCost(),card)) - continue; + if( card->has(Constants::CANPLAYFROMGRAVEYARD) || card->has(Constants::TEMPFLASHBACK) || hasFlashback ) + { + if (!CanHandleCost(card->getManaCost(),card)) + continue; - if (hasFlashback && !CanHandleCost(card->getManaCost()->getFlashback(),card)) - continue; + if (hasFlashback && !CanHandleCost(card->getManaCost()->getFlashback(),card)) + continue; - // Case were manacost is equal to flashback cost, if they are different the AI hangs - if (hasFlashback && (card->getManaCost() != card->getManaCost()->getFlashback()) ) - continue; + // Case were manacost is equal to flashback cost, if they are different the AI hangs + if (hasFlashback && (card->getManaCost() != card->getManaCost()->getFlashback()) ) + continue; - if (card->hasType(Subtypes::TYPE_LAND)) - { - if (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY) - continue; - } - else - { - if (game->playRestrictions->canPutIntoZone(card, game->stack) == PlayRestriction::CANT_PLAY) - continue; - } + if (card->hasType(Subtypes::TYPE_LAND)) + { + if (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY) + continue; + } + else + { + if (game->playRestrictions->canPutIntoZone(card, game->stack) == PlayRestriction::CANT_PLAY) + continue; + } - if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name)) - continue; - //glimmervoid alias to avoid ai stalling the game as the hint combo is stuck - //next card to play was galvanic blast but on activate combo it clashes with glimmervoid... - if ((card->alias == 48132) && (card->controller()->game->inPlay->countByType("artifact") < 1)) - continue; + if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name)) + continue; + //glimmervoid alias to avoid ai stalling the game as the hint combo is stuck + //next card to play was galvanic blast but on activate combo it clashes with glimmervoid... + if ((card->alias == 48132) && (card->controller()->game->inPlay->countByType("artifact") < 1)) + continue; - if (card->has(Constants::TREASON) && observer->getCurrentGamePhase() != MTG_PHASE_FIRSTMAIN) - continue; + if (card->has(Constants::TREASON) && observer->getCurrentGamePhase() != MTG_PHASE_FIRSTMAIN) + continue; - if (card->hasType(Subtypes::TYPE_PLANESWALKER) && card->types.size() > 0 && game->inPlay->hasTypeSpecificInt(Subtypes::TYPE_PLANESWALKER,card->types[1])) - continue; + if (card->hasType(Subtypes::TYPE_PLANESWALKER) && card->types.size() > 0 && game->inPlay->hasTypeSpecificInt(Subtypes::TYPE_PLANESWALKER,card->types[1])) + continue; - if(hints && hints->HintSaysItsForCombo(observer,card)) - { - if(hints->canWeCombo(observer,card,this)) - { - AbilityFactory af(observer); - int canPlay = af.parseCastRestrictions(card,card->controller(),card->getRestrictions()); - if(!canPlay) - continue; - nextCardToPlay = card; - gotPayments.clear(); - if((!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->getKicker())) - gotPayments = canPayMana(nextCardToPlay,nextCardToPlay->getManaCost()); - return activateCombo(); - } - else - { - nextCardToPlay = NULL; - continue; - } - } - int currentCost = card->getManaCost()->getConvertedCost(); - int hasX = card->getManaCost()->hasX(); - gotPayments.clear(); - if((!pMana->canAfford(card->getManaCost()) || card->getManaCost()->getKicker())) - gotPayments = canPayMana(card,card->getManaCost()); - //for preformence reason we only look for specific mana if the payment couldn't be made with pmana. - if ((currentCost > maxCost || hasX) && (gotPayments.size() || pMana->canAfford(card->getManaCost()))) - { - TargetChooserFactory tcf(observer); - TargetChooser * tc = tcf.createTargetChooser(card); - int shouldPlayPercentage = 0; - if (tc) - { - int hasTarget = chooseTarget(tc,NULL,NULL,true); - if( - (tc->maxtargets > hasTarget && tc->maxtargets > 1 && !tc->targetMin && tc->maxtargets != TargetChooser::UNLITMITED_TARGETS) ||//target=<3>creature - (tc->maxtargets == TargetChooser::UNLITMITED_TARGETS && hasTarget < 1)//target=creatures - ) - hasTarget = 0; - if (!hasTarget)//single target covered here. - { - SAFE_DELETE(tc); - continue; - } - shouldPlayPercentage = 90; - if(tc->targetMin && hasTarget < tc->maxtargets) - shouldPlayPercentage = 0; - if(tc->maxtargets > 1 && tc->maxtargets != TargetChooser::UNLITMITED_TARGETS && hasTarget <= tc->maxtargets) - { - int maxA = hasTarget-tc->maxtargets; - shouldPlayPercentage += (10*maxA);//reduce the chances of playing multitarget if we are not above max targets. - } - if(tc->maxtargets == TargetChooser::UNLITMITED_TARGETS) - { - shouldPlayPercentage = 40 + (10*hasTarget); - int totalCost = pMana->getConvertedCost()-currentCost; - int totalTargets = hasTarget+hasTarget; - if(hasX && totalCost <= totalTargets)// {x} spell with unlimited targeting tend to divide damage, we want atleast 1 damage per target before casting. - { - shouldPlayPercentage = 0; - } - } - SAFE_DELETE(tc); - } - else - { - // Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW - // If it is a land, play it - if (card->isLand()) - { - shouldPlayPercentage = 90; - } - else { - int shouldPlay = effectBadOrGood(card); - if (shouldPlay == BAKA_EFFECT_GOOD) { - shouldPlayPercentage = 90; - } - else if (BAKA_EFFECT_DONTKNOW == shouldPlay) { - //previously shouldPlayPercentage = 80;, I found this a little to high - //for cards which AI had no idea how to use. - shouldPlayPercentage = 60; - } - else { - // shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance. - shouldPlayPercentage = 10; - } - } - } - //Reduce the chances of playing a spell with X cost if available mana is low - if (hasX) - { - int xDiff = pMana->getConvertedCost() - currentCost; - if (xDiff < 0) - xDiff = 0; - shouldPlayPercentage = shouldPlayPercentage - static_cast ((shouldPlayPercentage * 1.9f) / (1 + xDiff)); - } - if(card->getManaCost() && card->getManaCost()->getKicker() && card->getManaCost()->getKicker()->isMulti) - { - shouldPlayPercentage = 10* size_t(gotPayments.size())/int(1+(card->getManaCost()->getConvertedCost()+card->getManaCost()->getKicker()->getConvertedCost())); - if(shouldPlayPercentage <= 10) - shouldPlayPercentage = shouldPlayPercentage/3; - } - DebugTrace("Should I play from grave " << (card ? card->name : "Nothing" ) << "?" << endl - <<"shouldPlayPercentage = "<< shouldPlayPercentage); - if(card->getRestrictions().size()) - { - AbilityFactory af(observer); - int canPlay = af.parseCastRestrictions(card,card->controller(),card->getRestrictions()); - if(!canPlay) - continue; - } - int randomChance = randomGenerator.random(); - int chance = randomChance % 100; - if (chance > shouldPlayPercentage) - continue; - if(shouldPlayPercentage <= 10) - { - DebugTrace("shouldPlayPercentage was less than 10 this was a lottery roll on RNG"); - } - nextCardToPlay = card; - maxCost = currentCost; - if (hasX) - maxCost = pMana->getConvertedCost(); - } - } + if(hints && hints->HintSaysItsForCombo(observer,card)) + { + if(hints->canWeCombo(observer,card,this)) + { + AbilityFactory af(observer); + int canPlay = af.parseCastRestrictions(card,card->controller(),card->getRestrictions()); + if(!canPlay) + continue; + nextCardToPlay = card; + gotPayments.clear(); + if((!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->getKicker())) + gotPayments = canPayMana(nextCardToPlay,nextCardToPlay->getManaCost()); + return activateCombo(); + } + else + { + nextCardToPlay = NULL; + continue; + } + } + int currentCost = card->getManaCost()->getConvertedCost(); + int hasX = card->getManaCost()->hasX(); + gotPayments.clear(); + if((!pMana->canAfford(card->getManaCost()) || card->getManaCost()->getKicker())) + gotPayments = canPayMana(card,card->getManaCost()); + //for preformence reason we only look for specific mana if the payment couldn't be made with pmana. + if ((currentCost > maxCost || hasX) && (gotPayments.size() || pMana->canAfford(card->getManaCost()))) + { + TargetChooserFactory tcf(observer); + TargetChooser * tc = tcf.createTargetChooser(card); + int shouldPlayPercentage = 0; + if (tc) + { + int hasTarget = chooseTarget(tc,NULL,NULL,true); + if( + (tc->maxtargets > hasTarget && tc->maxtargets > 1 && !tc->targetMin && tc->maxtargets != TargetChooser::UNLITMITED_TARGETS) ||//target=<3>creature + (tc->maxtargets == TargetChooser::UNLITMITED_TARGETS && hasTarget < 1)//target=creatures + ) + hasTarget = 0; + if (!hasTarget)//single target covered here. + { + SAFE_DELETE(tc); + continue; + } + shouldPlayPercentage = 90; + if(tc->targetMin && hasTarget < tc->maxtargets) + shouldPlayPercentage = 0; + if(tc->maxtargets > 1 && tc->maxtargets != TargetChooser::UNLITMITED_TARGETS && hasTarget <= tc->maxtargets) + { + int maxA = hasTarget-tc->maxtargets; + shouldPlayPercentage += (10*maxA);//reduce the chances of playing multitarget if we are not above max targets. + } + if(tc->maxtargets == TargetChooser::UNLITMITED_TARGETS) + { + shouldPlayPercentage = 40 + (10*hasTarget); + int totalCost = pMana->getConvertedCost()-currentCost; + int totalTargets = hasTarget+hasTarget; + if(hasX && totalCost <= totalTargets)// {x} spell with unlimited targeting tend to divide damage, we want atleast 1 damage per target before casting. + { + shouldPlayPercentage = 0; + } + } + SAFE_DELETE(tc); + } + else + { + // Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW + // If it is a land, play it + if (card->isLand()) + { + shouldPlayPercentage = 90; + } + else { + int shouldPlay = effectBadOrGood(card); + if (shouldPlay == BAKA_EFFECT_GOOD) { + shouldPlayPercentage = 90; + } + else if (BAKA_EFFECT_DONTKNOW == shouldPlay) { + //previously shouldPlayPercentage = 80;, I found this a little to high + //for cards which AI had no idea how to use. + shouldPlayPercentage = 60; + } + else { + // shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance. + shouldPlayPercentage = 10; + } + } + } + //Reduce the chances of playing a spell with X cost if available mana is low + if (hasX) + { + int xDiff = pMana->getConvertedCost() - currentCost; + if (xDiff < 0) + xDiff = 0; + shouldPlayPercentage = shouldPlayPercentage - static_cast ((shouldPlayPercentage * 1.9f) / (1 + xDiff)); + } + if(card->getManaCost() && card->getManaCost()->getKicker() && card->getManaCost()->getKicker()->isMulti) + { + shouldPlayPercentage = 10* size_t(gotPayments.size())/int(1+(card->getManaCost()->getConvertedCost()+card->getManaCost()->getKicker()->getConvertedCost())); + if(shouldPlayPercentage <= 10) + shouldPlayPercentage = shouldPlayPercentage/3; + } + DebugTrace("Should I play from grave " << (card ? card->name : "Nothing" ) << "?" << endl + <<"shouldPlayPercentage = "<< shouldPlayPercentage); + if(card->getRestrictions().size()) + { + AbilityFactory af(observer); + int canPlay = af.parseCastRestrictions(card,card->controller(),card->getRestrictions()); + if(!canPlay) + continue; + } + int randomChance = randomGenerator.random(); + int chance = randomChance % 100; + if (chance > shouldPlayPercentage) + continue; + if(shouldPlayPercentage <= 10) + { + DebugTrace("shouldPlayPercentage was less than 10 this was a lottery roll on RNG"); + } + nextCardToPlay = card; + maxCost = currentCost; + if (hasX) + maxCost = pMana->getConvertedCost(); + } + } } //canplayfromexile while ((card = cd.nextmatch(game->exile, card))&& card->has(Constants::CANPLAYFROMEXILE)) @@ -2841,26 +2841,26 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty else { // Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW - // If it is a land, play it + // If it is a land, play it if (card->isLand()) { shouldPlayPercentage = 90; } else { - int shouldPlay = effectBadOrGood(card); - if (shouldPlay == BAKA_EFFECT_GOOD) { - shouldPlayPercentage = 90; - } - else if (BAKA_EFFECT_DONTKNOW == shouldPlay) { - //previously shouldPlayPercentage = 80;, I found this a little to high - //for cards which AI had no idea how to use. - shouldPlayPercentage = 60; - } - else { - // shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance. - shouldPlayPercentage = 10; - } - } + int shouldPlay = effectBadOrGood(card); + if (shouldPlay == BAKA_EFFECT_GOOD) { + shouldPlayPercentage = 90; + } + else if (BAKA_EFFECT_DONTKNOW == shouldPlay) { + //previously shouldPlayPercentage = 80;, I found this a little to high + //for cards which AI had no idea how to use. + shouldPlayPercentage = 60; + } + else { + // shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance. + shouldPlayPercentage = 10; + } + } } //Reduce the chances of playing a spell with X cost if available mana is low if (hasX) @@ -2925,7 +2925,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty if (card->has(Constants::TREASON) && observer->getCurrentGamePhase() != MTG_PHASE_FIRSTMAIN) continue; - //PLaneswalkers are now legendary so this is redundant + //PLaneswalkers are now legendary so this is redundant //if (card->hasType(Subtypes::TYPE_PLANESWALKER) && card->types.size() > 0 && game->inPlay->hasTypeSpecificInt(Subtypes::TYPE_PLANESWALKER,card->types[1])) //continue; @@ -2995,27 +2995,27 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty } else { - // Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW - // If it is a land, play it + // Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW + // If it is a land, play it if (card->isLand()) { shouldPlayPercentage = 90; } else { - int shouldPlay = effectBadOrGood(card); - if (shouldPlay == BAKA_EFFECT_GOOD) { - shouldPlayPercentage = 90; - } - else if (BAKA_EFFECT_DONTKNOW == shouldPlay) { - //previously shouldPlayPercentage = 80;, I found this a little to high - //for cards which AI had no idea how to use. - shouldPlayPercentage = 60; - } - else { - // shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance. - shouldPlayPercentage = 10; - } - } + int shouldPlay = effectBadOrGood(card); + if (shouldPlay == BAKA_EFFECT_GOOD) { + shouldPlayPercentage = 90; + } + else if (BAKA_EFFECT_DONTKNOW == shouldPlay) { + //previously shouldPlayPercentage = 80;, I found this a little to high + //for cards which AI had no idea how to use. + shouldPlayPercentage = 60; + } + else { + // shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance. + shouldPlayPercentage = 10; + } + } } //Reduce the chances of playing a spell with X cost if available mana is low if (hasX) @@ -3458,16 +3458,16 @@ int AIPlayerBaka::getCreaturesInfo(Player * player, int neededInfo, int untapMod int AIPlayerBaka::chooseAttackers() { - int myCreatures = getCreaturesInfo(this, INFO_NBCREATURES, -1, 1); - if (myCreatures < 1) - return 0; + int myCreatures = getCreaturesInfo(this, INFO_NBCREATURES, -1, 1); + if (myCreatures < 1) + return 0; //Attack with all creatures //How much damage can the other player do during his next Attack ? int opponentForce = getCreaturesInfo(opponent(), INFO_CREATURESPOWER); int opponentCreatures = getCreaturesInfo(opponent(), INFO_NBCREATURES); int myForce = getCreaturesInfo(this, INFO_CREATURESPOWER, -1, 1); - if(opponent()->life < 5) - agressivity += 31; + if(opponent()->life < 5) + agressivity += 31; bool attack = ((myCreatures > opponentCreatures) || (myForce > opponentForce) || (myForce > 2 * opponent()->life)); if (agressivity > 80 && !attack && life > opponentForce) @@ -3485,7 +3485,7 @@ int AIPlayerBaka::chooseAttackers() MTGCardInstance * card = NULL; while ((card = cd.nextmatch(game->inPlay, card))) { - if ((hints && hints->HintSaysAlwaysAttack(observer, card)) || card->has(Constants::UNBLOCKABLE)) + if ((hints && hints->HintSaysAlwaysAttack(observer, card)) || card->has(Constants::UNBLOCKABLE)) { if (!card->isAttacker()) { diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 1e0fea9db..df134ed29 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -417,11 +417,11 @@ ManaCost* CardPrimitive::getManaCost() bool CardPrimitive::hasType(int _type) { - if (types.size() > 400) {return false;} // Null pointer? - for (size_t i = 0; i < types.size(); i++) - if (types[i] == _type) - return true; - return false; + if (types.size() > 400) {return false;} // Null pointer? + for (size_t i = 0; i < types.size(); i++) + if (types[i] == _type) + return true; + return false; } bool CardPrimitive::hasSubtype(int _subtype) diff --git a/projects/mtg/src/DeckEditorMenu.cpp b/projects/mtg/src/DeckEditorMenu.cpp index 6adc707fe..790f6476d 100644 --- a/projects/mtg/src/DeckEditorMenu.cpp +++ b/projects/mtg/src/DeckEditorMenu.cpp @@ -24,7 +24,7 @@ DeckEditorMenu::DeckEditorMenu(int id, JGuiListener* listener, int fontId, const #if defined PSP titleX = (SCREEN_WIDTH_F/2.f) + 10; #else - titleX = (SCREEN_WIDTH_F/2.f); + titleX = (SCREEN_WIDTH_F/2.f); #endif titleY = 13; } @@ -69,7 +69,7 @@ void DeckEditorMenu::Render() #if defined PSP mainFont->DrawString(deckTitle.c_str(), (SCREEN_WIDTH_F / 2)-modt+10, (statsHeight / 2)+4, JGETEXT_CENTER); #else - mainFont->DrawString(deckTitle.c_str(), (SCREEN_WIDTH_F / 2)-modt, (statsHeight / 2)+4, JGETEXT_CENTER); + mainFont->DrawString(deckTitle.c_str(), (SCREEN_WIDTH_F / 2)-modt, (statsHeight / 2)+4, JGETEXT_CENTER); #endif mainFont->SetColor(currentColor); } diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index a51569998..563544012 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -104,9 +104,9 @@ JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsSc float boxStartX = detailedInfoBoxX - stringWidth / 2 + 20; //dismiss button? #if defined PSP - dismissButton = NEW InteractiveButton( this, DeckMenuConst::kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX+25, detailedInfoBoxY-10.0f, JGE_BTN_CANCEL); + dismissButton = NEW InteractiveButton( this, DeckMenuConst::kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX+25, detailedInfoBoxY-10.0f, JGE_BTN_CANCEL); #else - dismissButton = NEW InteractiveButton( this, DeckMenuConst::kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX+30, detailedInfoBoxY+4.5f, JGE_BTN_CANCEL); + dismissButton = NEW InteractiveButton( this, DeckMenuConst::kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX+30, detailedInfoBoxY+4.5f, JGE_BTN_CANCEL); #endif JGuiController::Add(dismissButton, true); diff --git a/projects/mtg/src/DeckView.cpp b/projects/mtg/src/DeckView.cpp index e6f4bcff7..de674b049 100644 --- a/projects/mtg/src/DeckView.cpp +++ b/projects/mtg/src/DeckView.cpp @@ -133,7 +133,7 @@ void DeckView::renderCard(int index, int alpha, bool asThumbnail, bool griddeckv } else { - int mode = !options[Options::DISABLECARDS].number ? DrawMode::kNormal : DrawMode::kText; + int mode = !options[Options::DISABLECARDS].number ? DrawMode::kNormal : DrawMode::kText; Pos pos = Pos(cardPosition.x, cardPosition.y, cardPosition.scale * 285 / 250, 0.0, 255); CardGui::DrawCard(cardPosition.card, pos, mode, asThumbnail, true); } diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 738c9b184..eb12d2a8a 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -237,7 +237,7 @@ void GameApp::Create() WResourceManager::Instance()->RetrieveTexture("backdropframe.png", RETRIEVE_MANAGE); #else WResourceManager::Instance()->RetrieveTexture("pspbackdrop.jpg", RETRIEVE_MANAGE); - WResourceManager::Instance()->RetrieveTexture("pspbackdropframe.png", RETRIEVE_MANAGE); + WResourceManager::Instance()->RetrieveTexture("pspbackdropframe.png", RETRIEVE_MANAGE); #endif WResourceManager::Instance()->RetrieveTexture("handback.png", RETRIEVE_MANAGE); WResourceManager::Instance()->RetrieveTexture("shadows.png", RETRIEVE_MANAGE); diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 7eb96cf09..3735d5422 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -770,9 +770,9 @@ void GameStateDuel::Update(float dt) musictrack = "ai_baka_music_momir.mp3"; else if (mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2) musictrack = "ai_baka_music_random.mp3"; - else if (mParent->gameType == GAME_TYPE_RANDOM3 || mParent->gameType == GAME_TYPE_RANDOM5) musictrack + else if (mParent->gameType == GAME_TYPE_RANDOM3 || mParent->gameType == GAME_TYPE_RANDOM5) musictrack = "ai_baka_music_random.mp3"; - else if (mParent->gameType == GAME_TYPE_HORDE || mParent->gameType == GAME_TYPE_SET_LIMITED) musictrack + else if (mParent->gameType == GAME_TYPE_HORDE || mParent->gameType == GAME_TYPE_SET_LIMITED) musictrack = "ai_baka_music_momir.mp3"; if (!MusicExist(musictrack)) musictrack = "ai_baka_music.mp3"; diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 22d3c53fd..437b4f800 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1835,8 +1835,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG tc->targetter = NULL; } else - if (tc->targetter) - tc->targetter->bypassTC = false; + if (tc->targetter) + tc->targetter->bypassTC = false; sWithoutTc = splitTarget[0]; sWithoutTc.append(splitTarget[2]); } @@ -3513,7 +3513,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //produce additional mana when a mana is engaged if (s.find("producecolor:") != string::npos) - { + { return NEW AEngagedManaAbility(observer, id, card,s.substr(13)); } @@ -4102,7 +4102,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG MTGAbility * a = NEW AAProliferate(observer, id, card, target); a->oneShot = 1; a->canBeInterrupted = false; - ((AAProliferate*)a)->allcounters = true; + ((AAProliferate*)a)->allcounters = true; return a; } //proliferate all counters @@ -4547,10 +4547,10 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode, Targ return BAKA_EFFECT_BAD; if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_BAD; - if (dynamic_cast (a)) - return BAKA_EFFECT_GOOD; + if (dynamic_cast (a)) + return BAKA_EFFECT_GOOD; // Equipment that gets immediately attached. Todo: check the abilities associated with Equip, to make sure they're good (for now it seems to be the majority of the cases)? if (dynamic_cast (a)) @@ -4574,12 +4574,12 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode, Targ if (AAMover * aam = dynamic_cast(a)) { MTGGameZone * z = aam->destinationZone(target); - if ((tc && tc->targetsZone(p->game->library)) || (tc && tc->targetsZone(p->game->graveyard)) || (tc && tc->targetsZone(p->game->hand))) + if ((tc && tc->targetsZone(p->game->library)) || (tc && tc->targetsZone(p->game->graveyard)) || (tc && tc->targetsZone(p->game->hand))) { if (z == p->game->hand || z == p->game->inPlay) return BAKA_EFFECT_GOOD; } - return BAKA_EFFECT_BAD; //TODO + return BAKA_EFFECT_BAD; //TODO } if (dynamic_cast (a)) @@ -4604,33 +4604,33 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode, Targ return BAKA_EFFECT_GOOD; if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_BAD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_GOOD; - if (dynamic_cast (a)) + if (dynamic_cast (a)) return BAKA_EFFECT_BAD; if (PTInstant * abi = dynamic_cast(a)) @@ -4663,8 +4663,8 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode, Targ badAbilities[(int)Constants::NOLIFEGAINOPPONENT] = true; badAbilities[(int)Constants::MUSTBLOCK] = true; badAbilities[(int)Constants::FLYERSONLY] = true; - badAbilities[(int)Constants::TREASON] = true; - badAbilities[(int)Constants::SHACKLER] = true; + badAbilities[(int)Constants::TREASON] = true; + badAbilities[(int)Constants::SHACKLER] = true; if (AInstantBasicAbilityModifierUntilEOT * abi = dynamic_cast(a)) { @@ -4731,7 +4731,7 @@ int AbilityFactory::getAbilities(vector * v, Spell * spell, MTGCar card->exileEffects = true; break; } - if (dest == zones->library) + if (dest == zones->library) { magicText = card->magicTexts["library"]; break; @@ -4925,11 +4925,11 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int } return result; - } - catch(exception) { - DebugTrace("MAGIC TEST ERROR: Parser returned NULL"); - } - return 0; + } + catch(exception) { + DebugTrace("MAGIC TEST ERROR: Parser returned NULL"); + } + return 0; } void AbilityFactory::addAbilities(int _id, Spell * spell) diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index a679365e8..18190b8d6 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -1353,8 +1353,8 @@ int MTGCardInstance::DangerRanking() result += 1; } } - // Even at 60(danger=3) the AI is hasty to play removal on a simple creature - // a vanilla 2 mana, 2/2 used to be eff = 60 + // Even at 60(danger=3) the AI is hasty to play removal on a simple creature + // a vanilla 2 mana, 2/2 used to be eff = 60 if (result > 2) danger += 1; if (result > 4) diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index 98a8d7586..7f8aefd5e 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -1291,7 +1291,7 @@ void MTGDeck::printDetailedDeckText(std::ofstream& file ) } ss_creatures << numberOfCreatures; ss_spells << numberOfSpells; - ss_lands << numberOfLands; + ss_lands << numberOfLands; file << getCardBlockText( "Creatures x" + ss_creatures.str(), creatures.str() ) ; file << getCardBlockText( "Spells x" + ss_spells.str(), spells.str() ) ; diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 8d2348dc7..c2828e82f 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -505,16 +505,16 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card) } delete withKickerCost; } - if (card->getManaCost()->getBestow()) + if (card->getManaCost()->getBestow()) { ManaCost * withBestowCost= NEW ManaCost(card->getManaCost()); - withBestowCost->add(withBestowCost->getBestow()); + withBestowCost->add(withBestowCost->getBestow()); - DebugTrace("AltCost BESTOW " << withBestowCost); + DebugTrace("AltCost BESTOW " << withBestowCost); if (previousManaPool->canAfford(withBestowCost)) { - player->getManaPool()->pay(card->getManaCost()->getBestow()); - payResult = ManaCost::MANA_PAID_WITH_BESTOW; + player->getManaPool()->pay(card->getManaCost()->getBestow()); + payResult = ManaCost::MANA_PAID_WITH_BESTOW; } delete withBestowCost; } @@ -667,16 +667,16 @@ int MTGKickerRule::reactToClick(MTGCardInstance * card) } delete withKickerCost; } - // Handles bestow,also has to go in isExtraPaymentSet - if (card->getManaCost()->getBestow()) + // Handles bestow,also has to go in isExtraPaymentSet + if (card->getManaCost()->getBestow()) { ManaCost * withBestowCost= NEW ManaCost(card->getManaCost()); - withBestowCost->add(withBestowCost->getBestow()); + withBestowCost->add(withBestowCost->getBestow()); if (previousManaPool->canAfford(withBestowCost)) { - player->getManaPool()->pay(card->getManaCost()->getBestow()); - payResult = ManaCost::MANA_PAID_WITH_BESTOW; + player->getManaPool()->pay(card->getManaCost()->getBestow()); + payResult = ManaCost::MANA_PAID_WITH_BESTOW; } delete withBestowCost; } @@ -3513,7 +3513,7 @@ PermanentAbility(observer, _id) } int MTGNewPlaneswalker::receiveEvent(WEvent * e) -{ +{ if(game->getCurrentTargetChooser() || game->mLayers->actionLayer()->isWaitingForAnswer()) return 0; if (WEventZoneChange* ev1 = dynamic_cast(e)) @@ -3591,7 +3591,7 @@ int MTGNewPlaneswalker::CheckPW(MTGCardInstance * card) return 1; } void MTGNewPlaneswalker::MovePW(MTGCardInstance * card) -{ +{ game->LPWeffect = true; vectorselection; MTGCardInstance * myClone = NEW MTGCardInstance(card, card->controller()->game); @@ -3709,7 +3709,7 @@ ListMaintainerAbility(observer, _id) int MTGPlaneWalkerRule::canBeInList(MTGCardInstance * card) { - if(card->isPhased) + if(card->isPhased) return 0; if (card->hasType(Subtypes::TYPE_LEGENDARY) && card->controller()->game->inPlay->hasCard(card)) { @@ -3723,7 +3723,7 @@ int MTGPlaneWalkerRule::canBeInList(MTGCardInstance * card) int MTGPlaneWalkerRule::added(MTGCardInstance * card) { - map::iterator it; + map::iterator it; int destroy = 0; vectoroldCards; for (it = cards.begin(); it != cards.end(); it++) diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 654539691..769c54f8b 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -579,8 +579,8 @@ int ManaCost::hasAnotherCost() if(kicker) result = 1; //kicker is the only one ai knows for now, later hasAnotherCost() can be used to determine other cost types. - if(Retrace || BuyBack || alternative || FlashBack || morph || suspend || Bestow) - result = 1; + if(Retrace || BuyBack || alternative || FlashBack || morph || suspend || Bestow) + result = 1; return result; } diff --git a/projects/mtg/src/Rules.cpp b/projects/mtg/src/Rules.cpp index 9803c3c18..226f4923b 100644 --- a/projects/mtg/src/Rules.cpp +++ b/projects/mtg/src/Rules.cpp @@ -168,10 +168,10 @@ void Rules::addExtraRules(GameObserver* g) difficultyRating = 0; else if(g->mRules->gamemode == GAME_TYPE_RANDOM1 || g->mRules->gamemode == GAME_TYPE_RANDOM2) difficultyRating = 0; - else if(g->mRules->gamemode == GAME_TYPE_RANDOM3 || g->mRules->gamemode == GAME_TYPE_RANDOM5) - difficultyRating = 0; - else if(g->mRules->gamemode == GAME_TYPE_HORDE || g->mRules->gamemode == GAME_TYPE_SET_LIMITED) - difficultyRating = 0; + else if(g->mRules->gamemode == GAME_TYPE_RANDOM3 || g->mRules->gamemode == GAME_TYPE_RANDOM5) + difficultyRating = 0; + else if(g->mRules->gamemode == GAME_TYPE_HORDE || g->mRules->gamemode == GAME_TYPE_SET_LIMITED) + difficultyRating = 0; else if (g->mRules->gamemode == GAME_TYPE_STORY) difficultyRating = 0; else if (a->aType == MTGAbility::STANDARD_DRAW) @@ -200,8 +200,8 @@ void Rules::addExtraRules(GameObserver* g) a->resolve(); else if(g->mRules->gamemode == GAME_TYPE_RANDOM1 || g->mRules->gamemode == GAME_TYPE_RANDOM2) a->resolve(); - else if(g->mRules->gamemode == GAME_TYPE_RANDOM3 || g->mRules->gamemode == GAME_TYPE_RANDOM5) - a->resolve(); + else if(g->mRules->gamemode == GAME_TYPE_RANDOM3 || g->mRules->gamemode == GAME_TYPE_RANDOM5) + a->resolve(); else if (g->mRules->gamemode == GAME_TYPE_STORY) a->resolve(); else//stupid protections to keep this out of momir and other game modes. @@ -313,35 +313,35 @@ Player * Rules::loadPlayerRandom(GameObserver* observer, int isAI, int mode) Player * Rules::loadRandomSetLimited(GameObserver* observer, int isAI) { - //Random sets - int setId[] = { observer->getRandomGenerator()->random() % setlist.size(), observer->getRandomGenerator()->random() % setlist.size() }; - int nbSet = sizeof(setId)/sizeof(setId[0]); + //Random sets + int setId[] = { observer->getRandomGenerator()->random() % setlist.size(), observer->getRandomGenerator()->random() % setlist.size() }; + int nbSet = sizeof(setId)/sizeof(setId[0]); - int color1 = 1 + observer->getRandomGenerator()->random() % 5; + int color1 = 1 + observer->getRandomGenerator()->random() % 5; int color2 = 1 + observer->getRandomGenerator()->random() % 5; int colors[] = { color1, color2 }; int nbcolors = 2; string lands[] = { "", "forest", "island", "mountain", "swamp", "plains" }; - MTGDeck * tempDeck = NEW MTGDeck(MTGCollection()); - // Try to add basic lands from that set - tempDeck->addRandomCards(8, setId, nbSet, -1, lands[color1].c_str()); + MTGDeck * tempDeck = NEW MTGDeck(MTGCollection()); + // Try to add basic lands from that set + tempDeck->addRandomCards(8, setId, nbSet, -1, lands[color1].c_str()); tempDeck->addRandomCards(8, setId, nbSet, -1, lands[color2].c_str()); tempDeck->addRandomCards(2, setId, nbSet, -1, "land"); - // If lands < 18 add from any set - int missingLands = 18 - tempDeck->totalCards(); - if (missingLands > 0) - { - tempDeck->addRandomCards(missingLands/2, 0, 0, -1, lands[color1].c_str()); - tempDeck->addRandomCards(missingLands/2, 0, 0, -1, lands[color2].c_str()); - } - // Lone artifact and creatures. - tempDeck->addRandomCards(1, setId, nbSet, -1, "artifact"); - tempDeck->addRandomCards(12, setId, nbSet, -1, "creature", colors, nbcolors); - // Want the deck to be 40 cards, take any card from the set in the colors - int missingCards = 40 - tempDeck->totalCards(); - if (missingCards > 0) - tempDeck->addRandomCards(missingCards, setId, nbSet, -1, "", colors, nbcolors); + // If lands < 18 add from any set + int missingLands = 18 - tempDeck->totalCards(); + if (missingLands > 0) + { + tempDeck->addRandomCards(missingLands/2, 0, 0, -1, lands[color1].c_str()); + tempDeck->addRandomCards(missingLands/2, 0, 0, -1, lands[color2].c_str()); + } + // Lone artifact and creatures. + tempDeck->addRandomCards(1, setId, nbSet, -1, "artifact"); + tempDeck->addRandomCards(12, setId, nbSet, -1, "creature", colors, nbcolors); + // Want the deck to be 40 cards, take any card from the set in the colors + int missingCards = 40 - tempDeck->totalCards(); + if (missingCards > 0) + tempDeck->addRandomCards(missingCards, setId, nbSet, -1, "", colors, nbcolors); string deckFile = "random"; string deckFileSmall = "random"; @@ -359,7 +359,7 @@ Player * Rules::loadPlayerRandomThree(GameObserver* observer, int isAI) { int color1 = 1 + observer->getRandomGenerator()->random() % 5; int color2 = 1 + observer->getRandomGenerator()->random() % 5; - int color3 = 1 + observer->getRandomGenerator()->random() % 5; + int color3 = 1 + observer->getRandomGenerator()->random() % 5; int color0 = Constants::MTG_COLOR_ARTIFACT; int colors[] = { color1, color2, color3, color0 }; @@ -370,21 +370,21 @@ Player * Rules::loadPlayerRandomThree(GameObserver* observer, int isAI) MTGDeck * tempDeck = NEW MTGDeck(MTGCollection()); tempDeck->addRandomCards(1, 0, 0, -1, lands[color1].c_str()); tempDeck->addRandomCards(1, 0, 0, -1, lands[color2].c_str()); - tempDeck->addRandomCards(1, 0, 0, -1, lands[color3].c_str()); - tempDeck->addRandomCards(6, 0, 0, 'R', lands[color1].c_str()); + tempDeck->addRandomCards(1, 0, 0, -1, lands[color3].c_str()); + tempDeck->addRandomCards(6, 0, 0, 'R', lands[color1].c_str()); tempDeck->addRandomCards(6, 0, 0, 'R', lands[color2].c_str()); - tempDeck->addRandomCards(6, 0, 0, 'R', lands[color3].c_str()); - tempDeck->addRandomCards(3, 0, 0, -1, "land"); + tempDeck->addRandomCards(6, 0, 0, 'R', lands[color3].c_str()); + tempDeck->addRandomCards(3, 0, 0, -1, "land"); tempDeck->addRandomCards(1, 0, 0, 'U', "land"); tempDeck->addRandomCards(1, 0, 0, 'R', "land"); tempDeck->addRandomCards(18, 0, 0, -1, "creature", colors, nbcolors); - tempDeck->addRandomCards(1, 0, 0, 'R', "creature", colors, nbcolors); - tempDeck->addRandomCards(1, 0, 0, 'M', "creature", colors, nbcolors); + tempDeck->addRandomCards(1, 0, 0, 'R', "creature", colors, nbcolors); + tempDeck->addRandomCards(1, 0, 0, 'M', "creature", colors, nbcolors); tempDeck->addRandomCards(3, 0, 0, -1, "sorcery", colors, nbcolors); tempDeck->addRandomCards(3, 0, 0, -1, "enchantment", colors, nbcolors); tempDeck->addRandomCards(3, 0, 0, -1, "instant", colors, nbcolors); tempDeck->addRandomCards(4, 0, 0, -1, "artifact", colors, nbcolors); - tempDeck->addRandomCards(1, 0, 0, -1, "planeswalker", colors, nbcolors); + tempDeck->addRandomCards(1, 0, 0, -1, "planeswalker", colors, nbcolors); string deckFile = "random"; string deckFileSmall = "random"; @@ -403,9 +403,9 @@ Player * Rules::loadPlayerRandomFive(GameObserver* observer, int isAI) MTGDeck * tempDeck = NEW MTGDeck(MTGCollection()); tempDeck->addRandomCards(20, 0, 0, -1, "land"); - tempDeck->addRandomCards(20, 0, 0, -1, "creature"); - tempDeck->addRandomCards(20, 0, 0, -1, ""); - + tempDeck->addRandomCards(20, 0, 0, -1, "creature"); + tempDeck->addRandomCards(20, 0, 0, -1, ""); + string deckFile = "random"; string deckFileSmall = "random"; @@ -419,59 +419,59 @@ Player * Rules::loadPlayerRandomFive(GameObserver* observer, int isAI) } Player * Rules::loadPlayerHorde(GameObserver* observer, int isAI) -{ - int nbColors = 1; - string randomTribe = ""; - int tribeColor[] = { observer->getRandomGenerator()->random() % 6 }; +{ + int nbColors = 1; + string randomTribe = ""; + int tribeColor[] = { observer->getRandomGenerator()->random() % 6 }; - string lands[] = { "land", "forest", "island", "mountain", "swamp", "plains" }; + string lands[] = { "land", "forest", "island", "mountain", "swamp", "plains" }; - const char* const multicolorTribes[] = { "Ally", "Eldrazi", "Elemental", "Golem", "Hound", "Human", "Knight", - "Myr", "Samurai", "Shaman", "Shapeshifter", "Sliver", "Soldier", "Spellshaper", "Spirit", "Warrior", "Wizard" }; - const char* const whiteTribes[] = { "Angel", "Bird", "Cat", "cleric", "Griffin", "Kithkin", "Knight", "Soldier", "Spirit", "Wizard" }; - const char* const blueTribes[] = { "Artificer", "Bird", "Drake", "Faerie", "Illusion", "Merfolk", "Spirit", "Vedalken", "Wizard", "Zombie" }; - const char* const blackTribes[] = { "Cleric", "Demon", "Faerie", "Horror", "Pirate", "Rat", "Rogue", "Shade", "Skeleton", "Vampire", "Wizard", "Zombie" }; - const char* const redTribes[] = { "Barbarian", "Berserker"," Cat", "Devil", "Dragon", "Goblin", "Minotaur", "Ogre", "Werewolf", "Wizard" }; - const char* const greenTribes[] = { "Beast", "Cat", "Centaur", "Dinosaur", "Druid", "Elf", "Fungus", "Snake", "Spider", "Treefolk", "Werewolf", "Wizard" }; + const char* const multicolorTribes[] = { "Ally", "Eldrazi", "Elemental", "Golem", "Hound", "Human", "Knight", + "Myr", "Samurai", "Shaman", "Shapeshifter", "Sliver", "Soldier", "Spellshaper", "Spirit", "Warrior", "Wizard" }; + const char* const whiteTribes[] = { "Angel", "Bird", "Cat", "cleric", "Griffin", "Kithkin", "Knight", "Soldier", "Spirit", "Wizard" }; + const char* const blueTribes[] = { "Artificer", "Bird", "Drake", "Faerie", "Illusion", "Merfolk", "Spirit", "Vedalken", "Wizard", "Zombie" }; + const char* const blackTribes[] = { "Cleric", "Demon", "Faerie", "Horror", "Pirate", "Rat", "Rogue", "Shade", "Skeleton", "Vampire", "Wizard", "Zombie" }; + const char* const redTribes[] = { "Barbarian", "Berserker"," Cat", "Devil", "Dragon", "Goblin", "Minotaur", "Ogre", "Werewolf", "Wizard" }; + const char* const greenTribes[] = { "Beast", "Cat", "Centaur", "Dinosaur", "Druid", "Elf", "Fungus", "Snake", "Spider", "Treefolk", "Werewolf", "Wizard" }; - int multicolorTribesSize = sizeof(multicolorTribes)/sizeof(multicolorTribes[0]); - int whiteTribesSize = sizeof(whiteTribes)/sizeof(whiteTribes[0]); - int blueTribesSize = sizeof(blueTribes)/sizeof(blueTribes[0]); - int blackTribesSize = sizeof(blackTribes)/sizeof(blackTribes[0]); - int redTribesSize = sizeof(redTribes)/sizeof(redTribes[0]); - int greenTribesSize = sizeof(greenTribes)/sizeof(greenTribes[0]); + int multicolorTribesSize = sizeof(multicolorTribes)/sizeof(multicolorTribes[0]); + int whiteTribesSize = sizeof(whiteTribes)/sizeof(whiteTribes[0]); + int blueTribesSize = sizeof(blueTribes)/sizeof(blueTribes[0]); + int blackTribesSize = sizeof(blackTribes)/sizeof(blackTribes[0]); + int redTribesSize = sizeof(redTribes)/sizeof(redTribes[0]); + int greenTribesSize = sizeof(greenTribes)/sizeof(greenTribes[0]); - switch (tribeColor[0]) - { - case Constants::MTG_COLOR_ARTIFACT : - randomTribe = multicolorTribes[observer->getRandomGenerator()->random() % multicolorTribesSize]; - nbColors = 0; - break; - case Constants::MTG_COLOR_WHITE : - randomTribe = whiteTribes[observer->getRandomGenerator()->random() % whiteTribesSize]; - break; - case Constants::MTG_COLOR_BLUE : - randomTribe = blueTribes[observer->getRandomGenerator()->random() % blueTribesSize]; - break; - case Constants::MTG_COLOR_BLACK : - randomTribe = blackTribes[observer->getRandomGenerator()->random() % blackTribesSize]; - break; - case Constants::MTG_COLOR_RED : - randomTribe = redTribes[observer->getRandomGenerator()->random() % redTribesSize]; - break; - case Constants::MTG_COLOR_GREEN : - randomTribe = greenTribes[observer->getRandomGenerator()->random() % greenTribesSize]; - break; - } + switch (tribeColor[0]) + { + case Constants::MTG_COLOR_ARTIFACT : + randomTribe = multicolorTribes[observer->getRandomGenerator()->random() % multicolorTribesSize]; + nbColors = 0; + break; + case Constants::MTG_COLOR_WHITE : + randomTribe = whiteTribes[observer->getRandomGenerator()->random() % whiteTribesSize]; + break; + case Constants::MTG_COLOR_BLUE : + randomTribe = blueTribes[observer->getRandomGenerator()->random() % blueTribesSize]; + break; + case Constants::MTG_COLOR_BLACK : + randomTribe = blackTribes[observer->getRandomGenerator()->random() % blackTribesSize]; + break; + case Constants::MTG_COLOR_RED : + randomTribe = redTribes[observer->getRandomGenerator()->random() % redTribesSize]; + break; + case Constants::MTG_COLOR_GREEN : + randomTribe = greenTribes[observer->getRandomGenerator()->random() % greenTribesSize]; + break; + } - MTGDeck * tempDeck = NEW MTGDeck(MTGCollection()); - tempDeck->addRandomCards(16, 0, 0, -1, lands[tribeColor[0]].c_str()); + MTGDeck * tempDeck = NEW MTGDeck(MTGCollection()); + tempDeck->addRandomCards(16, 0, 0, -1, lands[tribeColor[0]].c_str()); tempDeck->addRandomCards(4, 0, 0, 'R', lands[tribeColor[0]].c_str()); tempDeck->addRandomCards(4, 0, 0, -1, "land"); - tempDeck->addRandomCards(21, 0, 0, -1, randomTribe); + tempDeck->addRandomCards(21, 0, 0, -1, randomTribe); tempDeck->addRandomCards(5, 0, 0, -1, "enchantment", tribeColor, nbColors); tempDeck->addRandomCards(5, 0, 0, -1, "instant", tribeColor, nbColors); - tempDeck->addRandomCards(5, 0, 0, -1, "sorcery", tribeColor, nbColors); + tempDeck->addRandomCards(5, 0, 0, -1, "sorcery", tribeColor, nbColors); string deckFile = "random"; string deckFileSmall = "random"; @@ -502,14 +502,14 @@ Player * Rules::initPlayer(GameObserver *g, int playerId) return loadPlayerRandom(g, isAI, GAME_TYPE_RANDOM1); case GAME_TYPE_RANDOM2: return loadPlayerRandom(g, isAI, GAME_TYPE_RANDOM2); - case GAME_TYPE_RANDOM3: + case GAME_TYPE_RANDOM3: return loadPlayerRandomThree(g, isAI); - case GAME_TYPE_RANDOM5: + case GAME_TYPE_RANDOM5: return loadPlayerRandomFive(g, isAI); - case GAME_TYPE_HORDE: + case GAME_TYPE_HORDE: return loadPlayerHorde(g, isAI); - case GAME_TYPE_SET_LIMITED: - return loadRandomSetLimited(g, isAI); + case GAME_TYPE_SET_LIMITED: + return loadRandomSetLimited(g, isAI); default: return NULL; } @@ -815,10 +815,10 @@ GameType Rules::strToGameMode(string s) if (s.compare("momir") == 0) return GAME_TYPE_MOMIR; if (s.compare("random1") == 0) return GAME_TYPE_RANDOM1; if (s.compare("random2") == 0) return GAME_TYPE_RANDOM2; - if (s.compare("random3") == 0) return GAME_TYPE_RANDOM3; - if (s.compare("random5") == 0) return GAME_TYPE_RANDOM5; - if (s.compare("horde") == 0) return GAME_TYPE_HORDE; - if (s.compare("set_limited") == 0) return GAME_TYPE_SET_LIMITED; + if (s.compare("random3") == 0) return GAME_TYPE_RANDOM3; + if (s.compare("random5") == 0) return GAME_TYPE_RANDOM5; + if (s.compare("horde") == 0) return GAME_TYPE_HORDE; + if (s.compare("set_limited") == 0) return GAME_TYPE_SET_LIMITED; if (s.compare("story") == 0) return GAME_TYPE_STORY; if (s.compare("stonehewer") == 0) return GAME_TYPE_STONEHEWER; if (s.compare("hermit") == 0) return GAME_TYPE_HERMIT; diff --git a/projects/mtg/src/TranslateKeys.cpp b/projects/mtg/src/TranslateKeys.cpp index 6ab460138..b5025750f 100644 --- a/projects/mtg/src/TranslateKeys.cpp +++ b/projects/mtg/src/TranslateKeys.cpp @@ -31,7 +31,7 @@ const KeyRep& translateKey(LocalKeySym key) #elif defined (SDL_CONFIG) str = (char*)SDL_GetKeyName(key); #elif defined (QT_CONFIG) - str = (char*)QKeySequence(key).toString().toUtf8().constData(); + str = (char*)QKeySequence(key).toString().toUtf8().constData(); #endif if (!str) {