Erwan
- The AI can now use May Abilities
This commit is contained in:
@@ -103,6 +103,7 @@ keldon_warlord2.txt
|
||||
kird_ape.txt
|
||||
kraken_eye.txt
|
||||
kraken_eye2.txt
|
||||
kraken_eye3.txt
|
||||
kudzu.txt
|
||||
kudzu2.txt
|
||||
lhurgoyf.txt
|
||||
|
||||
20
projects/mtg/bin/Res/test/kraken_eye3.txt
Normal file
20
projects/mtg/bin/Res/test/kraken_eye3.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
#Kraken eye works ok if spell cast by opponent ?
|
||||
[INIT]
|
||||
FIRSTMAIN
|
||||
[PLAYER1]
|
||||
hand:air elemental
|
||||
manapool:{3}{U}{U}
|
||||
[PLAYER2]
|
||||
inplay:kraken's eye
|
||||
[DO]
|
||||
air elemental
|
||||
choice 0
|
||||
[ASSERT]
|
||||
FIRSTMAIN
|
||||
[PLAYER1]
|
||||
inplay:air elemental
|
||||
life:20
|
||||
[PLAYER2]
|
||||
inplay:kraken's eye
|
||||
life:21
|
||||
[END]
|
||||
@@ -71,6 +71,7 @@ class AIPlayer: public Player{
|
||||
virtual int chooseTarget(TargetChooser * tc = NULL);
|
||||
virtual int Act(float dt);
|
||||
int isAI(){return 1;};
|
||||
int canHandleCost(MTGAbility * ability);
|
||||
int selectAbility();
|
||||
int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, map<AIAction *, int,CmpAbilities> * ranking);
|
||||
int useAbility();
|
||||
|
||||
@@ -27,7 +27,8 @@ class ActionLayer: public GuiLayer, public JGuiListener{
|
||||
bool CheckUserInput(u32 key);
|
||||
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL; stuffHappened = 0;};
|
||||
~ActionLayer();
|
||||
int isWaitingForAnswer();
|
||||
int cancelCurrentAction();
|
||||
ActionElement * isWaitingForAnswer();
|
||||
int isReactingToTargetClick(Targetable * card);
|
||||
int receiveEvent(WEvent * event);
|
||||
int reactToTargetClick(Targetable * card);
|
||||
|
||||
@@ -140,6 +140,7 @@ public:
|
||||
if (!triggered){
|
||||
triggered = 1;
|
||||
game->mLayers->actionLayer()->setMenuObject(source);
|
||||
game->mLayers->stackLayer()->setIsInterrupting(source->controller());
|
||||
OutputDebugString("SetMenuObject!\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -142,6 +142,7 @@ void GameObserver::nextGamePhase(){
|
||||
|
||||
int GameObserver::cancelCurrentAction(){
|
||||
SAFE_DELETE(targetChooser);
|
||||
mLayers->actionLayer()->cancelCurrentAction();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user