- Fixed empty ActionStack "interrupt" messages
- If no attackers are declared, go straight to Combat end phase
- Once First strike damage is declared, attacking player needs to "actively" request a next phase event to go to the next damage step
- Second Damage step is called "Combat Damage (2)"
- UserRequestNextPhase is to be used knowing that it might not succeed
- Step change for GuiCombat is now computed at GameObserver::nextGamePhase

Note: Combat damage to creatures is not assigned when AI attacks. As this seems to be a problem with the previous SVN version, I4m still committing this change
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-09-13 12:42:18 +00:00
parent 1f67998d7a
commit 7ce2c563e1
29 changed files with 130 additions and 128 deletions
+2 -2
View File
@@ -497,8 +497,9 @@ int AIPlayer::chooseBlockers(){
int AIPlayer::orderBlockers(){
GameObserver * g = GameObserver::GetInstance();
if (BLOCKERS == g->combatStep && g->currentPlayer==this)
if (ORDER == g->combatStep && g->currentPlayer==this)
{
OutputDebugString("AIPLAYER: order blockers\n");
g->userRequestNextGamePhase(); //TODO clever rank of blockers
return 1;
}
@@ -747,7 +748,6 @@ int AIPlayerBaka::Act(float dt){
}
initTimer();
if (combatDamages()){
OutputDebugString("Damages and NOTHING ELSE\n");
return 0;
}
interruptIfICan();
+10 -5
View File
@@ -12,25 +12,30 @@
#include "../include/TargetChooser.h"
#include "../include/CardGui.h"
#include "../include/Translate.h"
/*
NextGamePhase requested by user
*/
int NextGamePhase::resolve(){
GameObserver::GetInstance()->userRequestNextGamePhase();
GameObserver::GetInstance()->nextGamePhase();
return 1;
}
void NextGamePhase::Render(){
int nextPhase = (GameObserver::GetInstance()->getCurrentGamePhase() + 1) % Constants::MTG_PHASE_CLEANUP;
GameObserver * g = GameObserver::GetInstance();
int nextPhase = (g->getCurrentGamePhase() + 1) % Constants::MTG_PHASE_CLEANUP;
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
char buffer[200];
int playerId = 1;
if (GameObserver::GetInstance()->currentActionPlayer == GameObserver::GetInstance()->players[1]) playerId = 2;
sprintf(buffer, "%s %i : -> %s", _("Player").c_str(), playerId, _(Constants::MTGPhaseNames[nextPhase]).c_str());
if (g->currentActionPlayer == GameObserver::GetInstance()->players[1]) playerId = 2;
sprintf(buffer, "%s %i : -> %s", _("Player").c_str(), playerId, _(PhaseRing::phaseName(nextPhase)).c_str());
mFont->DrawString(buffer, x + 30 , y, JGETEXT_LEFT);
}
+4
View File
@@ -71,6 +71,10 @@ ActionStack * DuelLayers::stackLayer(){
return stack;
}
GuiCombat * DuelLayers::combatLayer(){
return combat;
}
ActionLayer * DuelLayers::actionLayer(){
return action;
}
+27 -5
View File
@@ -81,11 +81,28 @@ void GameObserver::nextPlayer(){
combatStep = BLOCKERS;
}
void GameObserver::nextGamePhase(){
Phase * cPhaseOld = phaseRing->getCurrentPhase();
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE)
if (FIRST_STRIKE == combatStep || END_FIRST_STRIKE == combatStep || DAMAGE == combatStep) {
nextCombatStep(); return;
}
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS)
if (BLOCKERS == combatStep) { nextCombatStep(); return; }
phaseRing->forward();
//Go directly to end of combat if no attackers
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATATTACKERS && !(currentPlayer->game->inPlay->getNextAttacker(NULL))){
phaseRing->forward();
phaseRing->forward();
}
Phase * cPhase = phaseRing->getCurrentPhase();
currentGamePhase = cPhase->id;
if (Constants::MTG_PHASE_COMBATDAMAGE == currentGamePhase)
nextCombatStep();
if (currentPlayer != cPhase->player) nextPlayer();
@@ -152,11 +169,16 @@ void GameObserver::userRequestNextGamePhase(){
if (mLayers->stackLayer()->getNext(NULL,0,NOT_RESOLVED)) return;
if (getCurrentTargetChooser()) return;
Phase * cPhaseOld = phaseRing->getCurrentPhase();
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE)
if (FIRST_STRIKE == combatStep || END_FIRST_STRIKE == combatStep || DAMAGE == combatStep) { nextCombatStep(); return; }
if (cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS)
if (BLOCKERS == combatStep) { nextCombatStep(); return; }
nextGamePhase();
if ((cPhaseOld->id == Constants::MTG_PHASE_COMBATBLOCKERS && combatStep == ORDER) ||
cPhaseOld->id == Constants::MTG_PHASE_COMBATDAMAGE ||
opponent()->isAI() ||
options[GameOptions::phaseInterrupts[currentGamePhase]].number)
mLayers->stackLayer()->AddNextGamePhase();
else
nextGamePhase();
}
int GameObserver::forceShuffleLibraries(){
+30 -17
View File
@@ -81,7 +81,7 @@ void GuiCombat::validateDamage()
switch (step)
{
case FIRST_STRIKE : resolve(); go->nextCombatStep(); break;
case DAMAGE : resolve(); go->userRequestNextGamePhase(); break;
case DAMAGE : resolve(); go->nextGamePhase(); break;
default: cout << "COMBAT : Cannot validate damage in this phase" << endl; break;
}
}
@@ -117,6 +117,19 @@ void GuiCombat::removeOne(DefenserDamaged* blocker, CombatStep step)
if (!(*it)->hasLethalDamage()) { (*it)->addDamage(1, activeAtk); break; }
}
bool GuiCombat::clickOK(){
switch (step)
{
case BLOCKERS : assert(false); return false; // that should not happen
case ORDER : go->nextGamePhase(); return true;
case FIRST_STRIKE : return false;
case DAMAGE : validateDamage(); return true;
case END_FIRST_STRIKE : return false;
case END_DAMAGE : return false; // nothing;
}
return false;
}
bool GuiCombat::CheckUserInput(u32 key)
{
if (NONE == cursor_pos) return false;
@@ -147,15 +160,7 @@ bool GuiCombat::CheckUserInput(u32 key)
}
else if (OK == cursor_pos)
{
switch (step)
{
case BLOCKERS : assert(false); break; // that should not happen
case ORDER : go->userRequestNextGamePhase(); break;
case FIRST_STRIKE :
case DAMAGE : validateDamage(); break;
case END_FIRST_STRIKE :
case END_DAMAGE : break; // nothing;
}
clickOK();
}
break;
case PSP_CTRL_TRIANGLE:
@@ -297,9 +302,13 @@ int GuiCombat::resolve() // Returns the number of damage objects dealt this turn
for (vector<Damage>::iterator d = (*it)->damages.begin(); d != (*it)->damages.end(); ++d)
stack->Add(NEW Damage(*d));
}
go->mLayers->stackLayer()->Add(stack);
int v = stack->mCount;
if (v > 0) go->mLayers->stackLayer()->resolve(); // This will delete the damage stack which will in turn delete the Damage it contains
if (v > 0){
go->mLayers->stackLayer()->Add(stack);
go->mLayers->stackLayer()->resolve(); // This will delete the damage stack which will in turn delete the Damage it contains
}else{
SAFE_DELETE(stack);
}
return v;
}
@@ -434,7 +443,7 @@ int GuiCombat::receiveEventMinus(WEvent* e)
step = ORDER;
}
else
go->userRequestNextGamePhase();
go->nextGamePhase();
return 1;
}
case FIRST_STRIKE:
@@ -449,12 +458,15 @@ int GuiCombat::receiveEventMinus(WEvent* e)
autoaffectDamage(*attacker, FIRST_STRIKE);
if (0 == resolve())
go->nextCombatStep();
else
go->mLayers->stackLayer()->AddNextGamePhase();
//else go->mLayers->stackLayer()->AddNextGamePhase(); //uncomment to add "interrupt" offer after first strike, rather than giving priority to current player
return 1;
case DAMAGE: DAMAGE:
step = event->step;
if (!go->currentPlayer->displayStack()) { resolve(); go->userRequestNextGamePhase(); return 1; }
if (!go->currentPlayer->displayStack()) {
//resolve();
go->nextGamePhase();
return 1;
}
for (inner_iterator attacker = attackers.begin(); attacker != attackers.end(); ++attacker)
autoaffectDamage(*attacker, step);
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
@@ -474,7 +486,8 @@ int GuiCombat::receiveEventMinus(WEvent* e)
return 1;
case END_DAMAGE:
step = END_DAMAGE;
if (resolve()) go->userRequestNextGamePhase();
if (0 == resolve())
go->nextGamePhase();
return 1;
}
return 0;
+11 -8
View File
@@ -103,16 +103,19 @@ int MTGAttackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana){
return 0;
}
void MTGAttackRule::Update(float dt){
if (currentPhase != newPhase && currentPhase == Constants::MTG_PHASE_COMBATATTACKERS){
Player * p = game->currentPlayer;
MTGGameZone * z = p->game->inPlay;
for (int i= 0; i < z->nb_cards; i++){
MTGCardInstance * card = z->cards[i];
if (!card->isAttacker() && card->has(Constants::MUSTATTACK)) reactToClick(card);
int MTGAttackRule::receiveEvent(WEvent *e){
if (WEventPhaseChange* event = dynamic_cast<WEventPhaseChange*>(e)) {
if (Constants::MTG_PHASE_COMBATATTACKERS == event->from->id) {
Player * p = game->currentPlayer;
MTGGameZone * z = p->game->inPlay;
for (int i= 0; i < z->nb_cards; i++){
MTGCardInstance * card = z->cards[i];
if (!card->isAttacker() && card->has(Constants::MUSTATTACK)) reactToClick(card);
}
return 1;
}
}
MTGAbility::Update(dt);
return 0;
}
int MTGAttackRule::reactToClick(MTGCardInstance * card){
+20
View File
@@ -24,6 +24,26 @@ PhaseRing::~PhaseRing(){
}
}
//This needs to be controlled either by GameObserver or PhaseRing in the future
bool PhaseRing::extraDamagePhase(int id){
GameObserver * g = GameObserver::GetInstance();
if (id != Constants::MTG_PHASE_COMBATEND) return false;
if (g->combatStep != END_FIRST_STRIKE) return false;
MTGGameZone * z = g->currentPlayer->game->inPlay;
for (int i= 0; i < z->nb_cards; ++i){
MTGCardInstance * card = z->cards[i];
if (card->isAttacker() && !(card->has(Constants::FIRSTSTRIKE) || card->has(Constants::DOUBLESTRIKE))) return true;
}
return false;
}
const char * PhaseRing::phaseName(int id){
if (extraDamagePhase(id)) return "Combat Damage (2)";
return Constants::MTGPhaseNames[id];
}
Phase * PhaseRing::getCurrentPhase(){
if (current == ring.end()){
current = ring.begin();
+6 -2
View File
@@ -3,6 +3,7 @@
#include "../include/MTGAbility.h"
#include "../include/MTGRules.h"
#include "../include/ActionLayer.h"
#include "../include/GuiCombat.h"
#include <string>
using std::string;
@@ -100,8 +101,11 @@ int TestSuiteAI::Act(float dt){
humanMode = 1;
return 1;
}
else if (action.compare("next")==0)
g->userRequestNextGamePhase();
else if (action.compare("next")==0){
GuiCombat * gc = g->mLayers->combatLayer();
if (ORDER == g->combatStep || DAMAGE == g->combatStep) gc->clickOK();
else g->userRequestNextGamePhase();
}
else if (action.compare("yes")==0)
g->mLayers->stackLayer()->setIsInterrupting(this);
else if (action.compare("endinterruption")==0)