- The AI can now use May Abilities
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-07-25 11:43:36 +00:00
parent 760910709a
commit 8cc2fc9d52
9 changed files with 83 additions and 58 deletions
+27 -11
View File
@@ -76,7 +76,7 @@ void AIPlayer::tapLandsForMana(ManaCost * potentialMana, ManaCost * cost){
//Make sure we can use the ability
MTGAbility * a = ((MTGAbility *)g->mLayers->actionLayer()->mObjects[i]);
AManaProducer * amp = dynamic_cast<AManaProducer*>(a);
if (amp){
if (amp && canHandleCost(amp)){
MTGCardInstance * card = amp->source;
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost()==1){
used[card] = true;
@@ -108,7 +108,7 @@ ManaCost * AIPlayer::getPotentialMana(){
//Make sure we can use the ability
MTGAbility * a = ((MTGAbility *)g->mLayers->actionLayer()->mObjects[i]);
AManaProducer * amp = dynamic_cast<AManaProducer*>(a);
if (amp){
if (amp && canHandleCost(amp)){
MTGCardInstance * card = amp->source;
if (!used[card] && amp->isReactingToClick(card) && amp->output->getConvertedCost()==1){
potentialMana->add(amp->output);
@@ -125,6 +125,19 @@ int AIPlayer::getEfficiency(AIAction * action){
return action->getEfficiency();
}
int AIPlayer::canHandleCost(MTGAbility * ability){
//Can't handle sacrifice costs that require a target yet :(
if (ability->cost){
ExtraCosts * ec = ability->cost->extraCosts;
if (ec){
for (size_t i = 0; i < ec->costs.size(); i++){
if (ec->costs[i]->tc) return 0;
}
}
}
return 1;
}
int AIAction::getEfficiency(){
//TODO add multiplier according to what the player wants
if (efficiency != -1) return efficiency;
@@ -146,15 +159,8 @@ int AIAction::getEfficiency(){
return 0;
}
//Can't handle sacrifice costs that require a target yet :(
if (ability->cost){
ExtraCosts * ec = ability->cost->extraCosts;
if (ec){
for (size_t i = 0; i < ec->costs.size(); i++){
if (ec->costs[i]->tc) return 0;
}
}
}
if (!((AIPlayer *)p)->canHandleCost(ability)) return 0;
switch (a->aType){
case MTGAbility::DAMAGER:
{
@@ -634,6 +640,10 @@ int AIPlayerBaka::computeActions(){
GameObserver * g = GameObserver::GetInstance();
Player * p = g->currentPlayer;
if (!(g->currentlyActing() == this)) return 0;
if (g->mLayers->actionLayer()->menuObject){
g->mLayers->actionLayer()->doReactTo(0);
return 1;
}
if (chooseTarget()) return 1;
int currentGamePhase = g->getCurrentGamePhase();
if (g->isInterrupting == this){ // interrupting
@@ -709,6 +719,12 @@ int AIPlayerBaka::computeActions(){
int AIPlayerBaka::Act(float dt){
GameObserver * g = GameObserver::GetInstance();
if (!(g->currentlyActing() == this)){
OutputDebugString("Cannot interrupt\n");
return 0;
}
int currentGamePhase = g->getCurrentGamePhase();
if (currentGamePhase == Constants::MTG_PHASE_CLEANUP && currentGamePhase != oldGamePhase){
+10 -3
View File
@@ -115,12 +115,19 @@ TargetChooser * ActionLayer::getCurrentTargetChooser(){
return NULL;
}
int ActionLayer::isWaitingForAnswer(){
int ActionLayer::cancelCurrentAction(){
ActionElement * ae = isWaitingForAnswer();
if (!ae) return 0;
ae->waitingForAnswer = 0; //TODO MOVE THIS IS ActionElement
return 1;
}
ActionElement * ActionLayer::isWaitingForAnswer(){
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return 1;
if(currentAction->waitingForAnswer) return currentAction;
}
return 0;
return NULL;
}
int ActionLayer::stillInUse(MTGCardInstance * card){
+20 -43
View File
@@ -515,29 +515,6 @@ void ActionStack::repackDamageStacks(){
}
if (!found) ++iter;
}
/*
for (int i = mCount-1; i >=0; i--){
Interruptible * action = ((Interruptible *)mObjects[i]);
if (action->type == ACTION_DAMAGE){
Damage * damage = (Damage *) action;
for (int j = 0; j < mCount; j++){
Interruptible * action2 = ((Interruptible *)mObjects[j]);
if (action2->type == ACTION_DAMAGES){
DamageStack * ds = (DamageStack *) action2;
for (int k = 0; k< ds->mCount; k++){
Damage * dsdamage = ((Damage *)ds->mObjects[k]);
if (dsdamage==damage){
//Remove(damage);
mObjects[i] = mObjects[mCount-1];
mCount--;
}
}
}
}
}
}
*/
}
void ActionStack::Update(float dt){
@@ -580,27 +557,27 @@ void ActionStack::Update(float dt){
if (getLatest(NOT_RESOLVED)){
int currentPlayerId = 0;
int otherPlayerId = 1;
if (game->currentPlayer != game->players[0]){
currentPlayerId = 1;
otherPlayerId = 0;
}
if (interruptDecision[currentPlayerId] == 0){
askIfWishesToInterrupt = game->players[currentPlayerId];
game->isInterrupting = game->players[currentPlayerId];
modal = 1;
}else if (interruptDecision[currentPlayerId] == -1){
game->isInterrupting = game->players[currentPlayerId];
if (game->currentlyActing() != game->players[0]){
currentPlayerId = 1;
otherPlayerId = 0;
}
if (interruptDecision[currentPlayerId] == 0){
askIfWishesToInterrupt = game->players[currentPlayerId];
game->isInterrupting = game->players[currentPlayerId];
modal = 1;
}else if (interruptDecision[currentPlayerId] == -1){
game->isInterrupting = game->players[currentPlayerId];
}else{
if (interruptDecision[otherPlayerId] == 0){
askIfWishesToInterrupt = game->players[otherPlayerId];
game->isInterrupting = game->players[otherPlayerId];
modal = 1;
}else if (interruptDecision[otherPlayerId] == -1){
game->isInterrupting = game->players[otherPlayerId];
}else{
resolve();
}
}else{
if (interruptDecision[otherPlayerId] == 0){
askIfWishesToInterrupt = game->players[otherPlayerId];
game->isInterrupting = game->players[otherPlayerId];
modal = 1;
}else if (interruptDecision[otherPlayerId] == -1){
game->isInterrupting = game->players[otherPlayerId];
}else{
resolve();
}
}
}
}else if (mode == ACTIONSTACK_TARGET){
+1
View File
@@ -142,6 +142,7 @@ void GameObserver::nextGamePhase(){
int GameObserver::cancelCurrentAction(){
SAFE_DELETE(targetChooser);
mLayers->actionLayer()->cancelCurrentAction();
return 1;
}